#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::String; 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()); } static void IsPromise(const FunctionCallbackInfo& args) { CHECK_EQ(1, args.Length()); args.GetReturnValue().Set(args[0]->IsPromise()); } static void GetHiddenValue(const FunctionCallbackInfo& 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 obj = args[0].As(); Local name = args[1].As(); args.GetReturnValue().Set(obj->GetHiddenValue(name)); } void Initialize(Local target, Local unused, Local context) { Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "isMapIterator", IsMapIterator); env->SetMethod(target, "isSetIterator", IsSetIterator); env->SetMethod(target, "isPromise", IsPromise); env->SetMethod(target, "getHiddenValue", GetHiddenValue); } } // namespace util } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(util, node::util::Initialize)