summaryrefslogtreecommitdiff
path: root/src/node_util.cc
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2015-11-23 14:58:18 -0500
committercjihrig <cjihrig@gmail.com>2015-11-24 15:49:50 -0500
commit5169311bf9f3ca0a601f9af2e3e732e250dd984b (patch)
tree2b9c33bb5d70a0824da1175cafddedd0f64d39ca /src/node_util.cc
parent658842280dcbb91576fc0d568c49a9c9e3fb40c2 (diff)
downloadandroid-node-v8-5169311bf9f3ca0a601f9af2e3e732e250dd984b.tar.gz
android-node-v8-5169311bf9f3ca0a601f9af2e3e732e250dd984b.tar.bz2
android-node-v8-5169311bf9f3ca0a601f9af2e3e732e250dd984b.zip
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>
Diffstat (limited to 'src/node_util.cc')
-rw-r--r--src/node_util.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/node_util.cc b/src/node_util.cc
index 19c3e3240a..a520b8d5f3 100644
--- a/src/node_util.cc
+++ b/src/node_util.cc
@@ -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