void PersistentDisposeContext::CallDisposeOnV8Thread() { DBG("PersistentDisposeContext::CallDisposeOnV8Thread"); Nan::Persistent<v8::Value>* handle = (Nan::Persistent<v8::Value>*)ptr.ToPointer(); handle->Reset(); delete handle; }
void initTestContext() { Handle<ObjectTemplate> global = Nan::New<ObjectTemplate>(); global->Set(Nan::New("a").ToLocalChecked(), Nan::New("1234567890").ToLocalChecked()); global->Set(Nan::New("b").ToLocalChecked(), Nan::New("234567890").ToLocalChecked()); global->Set(Nan::New("c").ToLocalChecked(), Nan::New("34567890").ToLocalChecked()); v8::Handle<v8::Context> context = Nan::New<Context>((ExtensionConfiguration*)(NULL), global); Context::Scope context_scope(context); testContext.Reset(context); Handle<Script> script = Nan::CompileScript(Nan::New("({ a: a, b: b, c: c })").ToLocalChecked()).ToLocalChecked(); testScript.Reset(script); }
void CoreClrNodejsFuncInvokeContext::InvokeCallback(void* data) { DBG("CoreClrNodejsFuncInvokeContext::InvokeCallback"); CoreClrNodejsFuncInvokeContext* context = (CoreClrNodejsFuncInvokeContext*) data; v8::Local<v8::Value> v8Payload = CoreClrFunc::MarshalCLRToV8(context->Payload, context->PayloadType); static Nan::Persistent<v8::Function> callbackFactory; static Nan::Persistent<v8::Function> callbackFunction; Nan::HandleScope scope; // See https://github.com/tjanczuk/edge/issues/125 for context if (callbackFactory.IsEmpty()) { v8::Local<v8::Function> v8FuncCallbackFunction = Nan::New<v8::FunctionTemplate>(coreClrV8FuncCallback)->GetFunction(); callbackFunction.Reset(v8FuncCallbackFunction); v8::Local<v8::String> code = Nan::New<v8::String>( "(function (cb, ctx) { return function (e, d) { return cb(e, d, ctx); }; })").ToLocalChecked(); v8::Local<v8::Function> callbackFactoryFunction = v8::Local<v8::Function>::Cast(v8::Script::Compile(code)->Run()); callbackFactory.Reset(callbackFactoryFunction); } v8::Local<v8::Value> factoryArgv[] = { Nan::New(callbackFunction), Nan::New<v8::External>((void*)context) }; v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast( Nan::New(callbackFactory)->Call(Nan::GetCurrentContext()->Global(), 2, factoryArgv)); v8::Local<v8::Value> argv[] = { v8Payload, callback }; TryCatch tryCatch; DBG("CoreClrNodejsFuncInvokeContext::InvokeCallback - Calling JavaScript function"); Nan::Call(Nan::New(*(context->FunctionContext->Func)), Nan::GetCurrentContext()->Global(), 2, argv); DBG("CoreClrNodejsFuncInvokeContext::InvokeCallback - Called JavaScript function"); if (tryCatch.HasCaught()) { DBG("CoreClrNodejsFuncInvokeContext::InvokeCallback - Caught JavaScript exception"); void* exceptionData; CoreClrFunc::MarshalV8ExceptionToCLR(tryCatch.Exception(), &exceptionData); DBG("CoreClrNodejsFuncInvokeContext::InvokeCallback - Exception message is: %s", (char*)exceptionData); context->Complete(TaskStatusFaulted, exceptionData, V8TypeException); } else { // Kick the next tick CallbackHelper::KickNextTick(); } }
static void Init(v8::Local<v8::Object> target) { v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New); hash_constructor.Reset(tpl); tpl->SetClassName(Nan::New<v8::String>("Hash").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); Nan::SetPrototypeMethod(tpl, "update", Update); Nan::SetPrototypeMethod(tpl, "digest", Digest); Nan::SetPrototypeMethod(tpl, "copy", Copy); target->Set(Nan::New("Hash").ToLocalChecked(), tpl->GetFunction()); }
static NAN_MODULE_INIT(Init) { Nan::HandleScope scope; v8::Local<v8::FunctionTemplate> t = Nan::New<v8::FunctionTemplate>(OscQueryServer::New); s_ct.Reset(t); t->SetClassName(Nan::New<v8::String>("OscQueryServer").ToLocalChecked()); t->InstanceTemplate()->SetInternalFieldCount(1); target->Set(Nan::New<v8::String>("OscQueryServer").ToLocalChecked(), t->GetFunction()); }
void MeCab_Tagger::Init(v8::Local<v8::Object> exports) { v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New); tpl->SetClassName(Nan::New("Tagger").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); Nan::SetPrototypeMethod(tpl, "parse", Parse); Nan::SetPrototypeMethod(tpl, "parseToNode", ParseToNode); Nan::SetPrototypeMethod(tpl, "dictionaryInfo", DictionaryInfo); constructor.Reset(tpl->GetFunction()); exports->Set(Nan::New("Tagger").ToLocalChecked(), tpl->GetFunction()); }
static NAN_MODULE_INIT(Init) { Nan::HandleScope scope; v8::Local<v8::FunctionTemplate> t = Nan::New<v8::FunctionTemplate>(Device::New); s_ct.Reset(t); t->SetClassName(Nan::New<v8::String>("Device").ToLocalChecked()); t->InstanceTemplate()->SetInternalFieldCount(1); Nan::SetPrototypeMethod(t, "getRootNode", GetRootNode); target->Set(Nan::New<v8::String>("Device").ToLocalChecked(), t->GetFunction()); }
static void Initialize(Handle<Object> target) { Local<String> name = Nan::New<String>("XXHash64").ToLocalChecked(); Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(name); Nan::SetPrototypeMethod(tpl, "update", Update); Nan::SetPrototypeMethod(tpl, "digest", Digest); Nan::SetMethod(tpl, "hash", StaticHash); target->Set(name, tpl->GetFunction()); constructor_64.Reset(tpl); }
void NativeProtobuf::Init(Local<Object> exports) { // constructor Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New); tpl->SetClassName(Nan::New<String>("NativeProtobuf").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); // prototype Nan::SetPrototypeMethod(tpl, "parse", NativeProtobuf::Parse); Nan::SetPrototypeMethod(tpl, "parseWithUnknown", NativeProtobuf::ParseWithUnknown); Nan::SetPrototypeMethod(tpl, "serialize", NativeProtobuf::Serialize); Nan::SetPrototypeMethod(tpl, "info", NativeProtobuf::Info); constructor.Reset(tpl->GetFunction()); exports->Set(Nan::New<String>("native").ToLocalChecked(), tpl->GetFunction()); }
static NAN_MODULE_INIT(init) { Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(IRF::New); tpl->SetClassName(Nan::New("IRF").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); Nan::SetPrototypeMethod(tpl, "add", add); Nan::SetPrototypeMethod(tpl, "remove", remove); Nan::SetPrototypeMethod(tpl, "classify", classify); Nan::SetPrototypeMethod(tpl, "classifyPartial", classifyPartial); Nan::SetPrototypeMethod(tpl, "asJSON", asJSON); Nan::SetPrototypeMethod(tpl, "statsJSON", statsJSON); Nan::SetPrototypeMethod(tpl, "each", each); Nan::SetPrototypeMethod(tpl, "commit", commit); Nan::SetPrototypeMethod(tpl, "toBuffer", toBuffer); constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked()); Nan::Set(target, Nan::New("IRF").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked()); }
void SerialportPoller::Init(Handle<Object> target) { Nan::HandleScope scope; // Prepare constructor template Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New); tpl->SetClassName(Nan::New<String>("SerialportPoller").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype // SerialportPoller.close() Nan::SetPrototypeTemplate(tpl, "close", Nan::GetFunction(Nan::New<FunctionTemplate>(Close)).ToLocalChecked()); // SerialportPoller.start() Nan::SetPrototypeTemplate(tpl, "start", Nan::GetFunction(Nan::New<FunctionTemplate>(Start)).ToLocalChecked()); serialportpoller_constructor.Reset(tpl); Nan::Set(target, Nan::New<String>("SerialportPoller").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked()); }