From 88533881dd296236a44ad36aa7afb8336298540f Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Tue, 29 Sep 2015 14:30:22 -0500 Subject: 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 --- src/node_util.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/node_util.cc (limited to 'src/node_util.cc') 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& args) { + CHECK_EQ(1, args.Length()); + args.GetReturnValue().Set(args[0]->IsMapIterator()); +} + + +static void IsSetIterator(const FunctionCallbackInfo& args) { + CHECK_EQ(1, args.Length()); + args.GetReturnValue().Set(args[0]->IsSetIterator()); +} + + +void Initialize(Local target, + Local unused, + Local 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) -- cgit v1.2.3