diff options
author | Evan Lucas <evanlucas@me.com> | 2015-09-29 14:30:22 -0500 |
---|---|---|
committer | Evan Lucas <evanlucas@me.com> | 2015-10-05 20:24:08 -0500 |
commit | 88533881dd296236a44ad36aa7afb8336298540f (patch) | |
tree | 781f8a0c3dcb24a6f9794129e78a6bdddb3efdc4 /src/node_util.cc | |
parent | 089d6886178864b56fdd5dc2bcfc8f207aa4326c (diff) | |
download | android-node-v8-88533881dd296236a44ad36aa7afb8336298540f.tar.gz android-node-v8-88533881dd296236a44ad36aa7afb8336298540f.tar.bz2 android-node-v8-88533881dd296236a44ad36aa7afb8336298540f.zip |
util: correctly inspect Map/Set Iterators
Previously, a MapIterator or SetIterator would
not be inspected properly. This change makes it possible
to inspect them by creating a Debug Mirror and previewing
the iterators to not consume the actual iterator that
we are trying to inspect.
This change also adds a node_util binding that uses
v8's Value::IsSetIterator and Value::IsMapIterator
to verify that the values passed in are actual iterators.
Fixes: https://github.com/nodejs/node/issues/3107
PR-URL: https://github.com/nodejs/node/pull/3119
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/node_util.cc')
-rw-r--r-- | src/node_util.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/node_util.cc b/src/node_util.cc new file mode 100644 index 0000000000..cc86478e09 --- /dev/null +++ b/src/node_util.cc @@ -0,0 +1,38 @@ +#include "node.h" +#include "v8.h" +#include "env.h" +#include "env-inl.h" + +namespace node { +namespace util { + +using v8::Context; +using v8::FunctionCallbackInfo; +using v8::Local; +using v8::Object; +using v8::Value; + +static void IsMapIterator(const FunctionCallbackInfo<Value>& args) { + CHECK_EQ(1, args.Length()); + args.GetReturnValue().Set(args[0]->IsMapIterator()); +} + + +static void IsSetIterator(const FunctionCallbackInfo<Value>& args) { + CHECK_EQ(1, args.Length()); + args.GetReturnValue().Set(args[0]->IsSetIterator()); +} + + +void Initialize(Local<Object> target, + Local<Value> unused, + Local<Context> context) { + Environment* env = Environment::GetCurrent(context); + env->SetMethod(target, "isMapIterator", IsMapIterator); + env->SetMethod(target, "isSetIterator", IsSetIterator); +} + +} // namespace util +} // namespace node + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(util, node::util::Initialize) |