summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-12-31 00:59:25 +0100
committerAnna Henningsen <anna@addaleax.net>2019-01-02 14:46:13 +0100
commit112ee2ab071da24390515b3a91588c1590872498 (patch)
treee173534964a2ee8344524c4f7c88751d834379f6 /src/util.h
parent2370bc7143211d860fc14e710cc8400fb4004bed (diff)
downloadandroid-node-v8-112ee2ab071da24390515b3a91588c1590872498.tar.gz
android-node-v8-112ee2ab071da24390515b3a91588c1590872498.tar.bz2
android-node-v8-112ee2ab071da24390515b3a91588c1590872498.zip
src: improve ToV8Value() functions
- Cache the `isolate` value between calls - Introduce an overload for dealing with integers/numbers - Use the vectored `v8::Array::New` constructor + `MaybeStackBuffer` for faster array creation PR-URL: https://github.com/nodejs/node/pull/25288 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/util.h b/src/util.h
index 2db87c18b0..ffa5a308a7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -35,6 +35,7 @@
#include <string.h>
#include <functional> // std::function
+#include <limits>
#include <set>
#include <string>
#include <array>
@@ -519,13 +520,21 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
std::set<std::string> ParseCommaSeparatedSet(const std::string& in);
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
- const std::string& str);
+ const std::string& str,
+ v8::Isolate* isolate = nullptr);
+template <typename T, typename test_for_number =
+ typename std::enable_if<std::numeric_limits<T>::is_specialized, bool>::type>
+inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
+ const T& number,
+ v8::Isolate* isolate = nullptr);
template <typename T>
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
- const std::vector<T>& vec);
+ const std::vector<T>& vec,
+ v8::Isolate* isolate = nullptr);
template <typename T, typename U>
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
- const std::unordered_map<T, U>& map);
+ const std::unordered_map<T, U>& map,
+ v8::Isolate* isolate = nullptr);
// These macros expects a `Isolate* isolate` and a `Local<Context> context`
// to be in the scope.