mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
util,src: allow lookup of hidden values
This commit adds an internal util method that makes hidden values in the C++ layer visible in JS. PR-URL: https://github.com/nodejs/node/pull/3988 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
a863e8d667
commit
c584c3e08f
3 files changed
+54
No files matched your search
@@ -10,6 +10,7 @@ using v8::Context;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Local;
|
||||
using v8::Object;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
static void IsMapIterator(const FunctionCallbackInfo<Value>& args) {
|
||||
@@ -28,6 +29,23 @@ static void IsPromise(const FunctionCallbackInfo<Value>& args) {
|
||||
args.GetReturnValue().Set(args[0]->IsPromise());
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
|
||||
Local<Object> obj = args[0].As<Object>();
|
||||
Local<String> name = args[1].As<String>();
|
||||
|
||||
args.GetReturnValue().Set(obj->GetHiddenValue(name));
|
||||
}
|
||||
|
||||
|
||||
void Initialize(Local<Object> target,
|
||||
Local<Value> unused,
|
||||
Local<Context> context) {
|
||||
@@ -35,6 +53,7 @@ void Initialize(Local<Object> target,
|
||||
env->SetMethod(target, "isMapIterator", IsMapIterator);
|
||||
env->SetMethod(target, "isSetIterator", IsSetIterator);
|
||||
env->SetMethod(target, "isPromise", IsPromise);
|
||||
env->SetMethod(target, "getHiddenValue", GetHiddenValue);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
Reference in new issue
Block a user