summaryrefslogtreecommitdiff
path: root/src/node_util.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2016-05-31 19:58:31 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2016-06-01 09:29:49 +0200
commit334ef4f19dc0bbdf9a9fde9f4a6e7042a6c6e2a3 (patch)
tree971e0c8186631f180ac87878eda73ec68991e51d /src/node_util.cc
parentc3cd453cbae84ff6d639a2b8d7776a15b3e3431b (diff)
downloadandroid-node-v8-334ef4f19dc0bbdf9a9fde9f4a6e7042a6c6e2a3.tar.gz
android-node-v8-334ef4f19dc0bbdf9a9fde9f4a6e7042a6c6e2a3.tar.bz2
android-node-v8-334ef4f19dc0bbdf9a9fde9f4a6e7042a6c6e2a3.zip
lib,src: drop dependency on v8::Private::ForApi()
Said function requires that a v8::Context has been entered first, introducing a chicken-and-egg problem when creating the first context. PR-URL: https://github.com/nodejs/node/pull/7082 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src/node_util.cc')
-rw-r--r--src/node_util.cc38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/node_util.cc b/src/node_util.cc
index 9fc94acf09..5089188d50 100644
--- a/src/node_util.cc
+++ b/src/node_util.cc
@@ -9,11 +9,11 @@ namespace util {
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
+using v8::Integer;
using v8::Local;
using v8::Object;
using v8::Private;
using v8::Proxy;
-using v8::String;
using v8::Value;
@@ -53,18 +53,28 @@ static void GetProxyDetails(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(ret);
}
+inline Local<Private> IndexToPrivateSymbol(Environment* env, uint32_t index) {
+#define V(name, _) &Environment::name,
+ static Local<Private> (Environment::*const methods[])() const = {
+ PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)
+ };
+#undef V
+ CHECK_LT(index, arraysize(methods));
+ return (env->*methods[index])();
+}
+
static void GetHiddenValue(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
if (!args[0]->IsObject())
return env->ThrowTypeError("obj must be an object");
- if (!args[1]->IsString())
- return env->ThrowTypeError("name must be a string");
+ if (!args[1]->IsUint32())
+ return env->ThrowTypeError("index must be an uint32");
Local<Object> obj = args[0].As<Object>();
- Local<String> name = args[1].As<String>();
- auto private_symbol = Private::ForApi(env->isolate(), name);
+ auto index = args[1]->Uint32Value(env->context()).FromJust();
+ auto private_symbol = IndexToPrivateSymbol(env, index);
auto maybe_value = obj->GetPrivate(env->context(), private_symbol);
args.GetReturnValue().Set(maybe_value.ToLocalChecked());
@@ -76,12 +86,12 @@ static void SetHiddenValue(const FunctionCallbackInfo<Value>& args) {
if (!args[0]->IsObject())
return env->ThrowTypeError("obj must be an object");
- if (!args[1]->IsString())
- return env->ThrowTypeError("name must be a string");
+ if (!args[1]->IsUint32())
+ return env->ThrowTypeError("index must be an uint32");
Local<Object> obj = args[0].As<Object>();
- Local<String> name = args[1].As<String>();
- auto private_symbol = Private::ForApi(env->isolate(), name);
+ auto index = args[1]->Uint32Value(env->context()).FromJust();
+ auto private_symbol = IndexToPrivateSymbol(env, index);
auto maybe_value = obj->SetPrivate(env->context(), private_symbol, args[2]);
args.GetReturnValue().Set(maybe_value.FromJust());
@@ -97,6 +107,16 @@ void Initialize(Local<Object> target,
VALUE_METHOD_MAP(V)
#undef V
+#define V(name, _) \
+ target->Set(context, \
+ FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
+ Integer::NewFromUnsigned(env->isolate(), index++));
+ {
+ uint32_t index = 0;
+ PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)
+ }
+#undef V
+
env->SetMethod(target, "getHiddenValue", GetHiddenValue);
env->SetMethod(target, "setHiddenValue", SetHiddenValue);
env->SetMethod(target, "getProxyDetails", GetProxyDetails);