void CRF::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); if (args.IsConstructCall()) { // Invoked as constructor: `new CRF(...)` CRF* obj = new CRF(); CRFPP::Tagger* tag = CRFPP::createTagger(get(args[0])); if(!tag){ isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, (const char *) CRFPP::getTaggerError()))); return; } v8::Local<v8::External> handle = v8::External::New(isolate, tag); v8::Persistent<v8::External, v8::CopyablePersistentTraits<v8::External> > tagger(isolate, handle); obj -> tagger = tagger; obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { const int argc = 1; Local<Value> argv[argc] = { args[0] }; Local<Function> cons = Local<Function>::New(isolate, constructor); args.GetReturnValue().Set(cons->NewInstance(argc, argv)); } }
void BookWrap::Each(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); Book* book = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book; if (args.Length() == 1) { if (args[0]->IsFunction()) { Local<Function> fun = Local<Function>::Cast(args[0]); for(uint32_t i = 0; i < book->size(); ++i) { Local<Object> pw = PersonWrap::New(isolate, book, i); Local<Value> argv[1] = { pw }; fun->Call(Null(isolate), 1, argv); } args.GetReturnValue().SetUndefined(); return; } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Function expected"))); args.GetReturnValue().SetUndefined(); return; } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected"))); args.GetReturnValue().SetUndefined(); return; } }
void ABPFilterParserWrap::Serialize(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); ABPFilterParserWrap* obj = ObjectWrap::Unwrap<ABPFilterParserWrap>(args.Holder()); int totalSize = 0; // Serialize data char* data = obj->serialize(&totalSize); if (nullptr == data) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Could not serialize"))); return; } MaybeLocal<Object> buffer = node::Buffer::New(isolate, totalSize); Local<Object> localBuffer; if (!buffer.ToLocal(&localBuffer)) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Could not convert MaybeLocal to Local"))); return; } memcpy(node::Buffer::Data(localBuffer), data, totalSize); delete[] data; args.GetReturnValue().Set(localBuffer); }
void ParseAsync(const Nan::FunctionCallbackInfo<Value> &args) { Isolate *isolate = args.GetIsolate(); int args_length = args.Length(); if (args_length < 2) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))); return; } Local<Value> input = args[0]; if (!ValidateInput(input, isolate)) { return; } if (!args[1]->IsFunction()) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second parameter must be a callback"))); return; } Nan::Callback *callback = new Nan::Callback(args[1].As<Function>()); anitomyJs::Worker *worker = new anitomyJs::Worker(callback); if (args_length >= 3) { Local<Value> options = args[2]; if (!ValidateOptions(options, isolate) || !worker->GetAnitomy()->SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) { return; } } worker->GetAnitomy()->SetInput(input, isolate); Nan::AsyncQueueWorker(worker); args.GetReturnValue().Set(Nan::Undefined()); }
void BookWrap::Lookup(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); if (args.Length() == 1) { if (args[0]->IsString()) { const String::Utf8Value s(args[0]->ToString()); Book* b = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book; try { Person* p = b->lookup(*s); Local<Object> obj = PersonWrap::NewInstance(); PersonWrap* pw = ObjectWrap::Unwrap<PersonWrap>(obj); pw->m_person = p; args.GetReturnValue().Set(obj); } catch (...) { isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Not found"))); args.GetReturnValue().SetUndefined(); } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "String expected"))); args.GetReturnValue().SetUndefined(); } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected"))); args.GetReturnValue().SetUndefined(); } }
/* * Prototype: * Module.enumerateImports(name, callback) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_module_on_enumerate_imports ( const FunctionCallbackInfo<Value> & info) { GumV8Module * self = static_cast<GumV8Module *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); GumV8ImportsContext ctx; ctx.self = self; ctx.isolate = isolate; Local<Value> name_val = info[0]; if (!name_val->IsString ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 ( isolate, "Module.enumerateImports: first argument must be " "a string specifying a module name whose imports to enumerate"))); return; } String::Utf8Value name_str (name_val); Local<Value> callbacks_value = info[1]; if (!callbacks_value->IsObject ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 ( isolate, "Module.enumerateImports: second argument must be " "a callback object"))); return; } Local<Object> callbacks = Local<Object>::Cast (callbacks_value); if (!_gum_v8_callbacks_get (callbacks, "onMatch", &ctx.on_match, ctx.self->core)) { return; } if (!_gum_v8_callbacks_get (callbacks, "onComplete", &ctx.on_complete, ctx.self->core)) { return; } ctx.receiver = info.This (); ctx.imp = eternal_imp.Get (isolate); ctx.type = eternal_type.Get (isolate); ctx.name = eternal_name.Get (isolate); ctx.module = eternal_module.Get (isolate); ctx.address = eternal_address.Get (isolate); ctx.variable = eternal_variable.Get (isolate); gum_module_enumerate_imports (*name_str, gum_v8_module_handle_import_match, &ctx); ctx.on_complete->Call (ctx.receiver, 0, 0); }
void BookWrap::Setter(uint32_t index, Local<Value> value, const PropertyCallbackInfo<Value>& info) { Isolate* isolate = info.GetIsolate(); HandleScope scope(isolate); BookWrap* bw = ObjectWrap::Unwrap<BookWrap>(info.This()); Book* b = bw->m_book; if (value->IsArray()) { if (index < b->size()) { Local<v8::Array> arr = Local<v8::Array>::Cast(value); if (arr->Length() == 3) { const String::Utf8Value firstname(arr->Get(0)->ToString()); const String::Utf8Value lastname(arr->Get(1)->ToString()); const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue()); Person *p = (*b)[index]; p->firstname(*firstname); p->lastname(*lastname); p->birthday(birthday); } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected"))); info.GetReturnValue().SetUndefined(); return; } } if (index == b->size()) { Local<v8::Array> arr = Local<v8::Array>::Cast(value); if (arr->Length() == 3) { const String::Utf8Value firstname(arr->Get(0)->ToString()); const String::Utf8Value lastname(arr->Get(1)->ToString()); const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue()); Person *p = new Person(); p->firstname(*firstname); p->lastname(*lastname); p->birthday(birthday); b->add(p); } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected"))); info.GetReturnValue().SetUndefined(); return; } } else { isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Invalid index"))); info.GetReturnValue().SetUndefined(); return; } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Object expected"))); info.GetReturnValue().SetUndefined(); return; } info.GetReturnValue().SetUndefined(); }
/* * Prototype: * Module.findExportByName(module_name, symbol_name) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_module_on_find_export_by_name ( const FunctionCallbackInfo<Value> & info) { GumV8Module * self = static_cast<GumV8Module *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); Local<Value> module_name_val = info[0]; gchar * module_name; if (module_name_val->IsString ()) { String::Utf8Value module_name_utf8 (module_name_val); module_name = g_strdup (*module_name_utf8); } else if (module_name_val->IsNull ()) { module_name = NULL; } else { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Module.findExportByName: first argument must be a string " "specifying module name, or null"))); return; } Local<Value> symbol_name_val = info[1]; if (!symbol_name_val->IsString ()) { g_free (module_name); isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Module.findExportByName: second argument must be a string " "specifying name of exported symbol"))); return; } String::Utf8Value symbol_name (symbol_name_val); GumAddress raw_address = gum_module_find_export_by_name (module_name, *symbol_name); if (raw_address != 0) { info.GetReturnValue ().Set ( _gum_v8_native_pointer_new (GSIZE_TO_POINTER (raw_address), self->core)); } else { info.GetReturnValue ().SetNull (); } g_free (module_name); }
void GeoJSONReader::Read(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); GeoJSONReader* reader = ObjectWrap::Unwrap<GeoJSONReader>(args.This()); try { geos::geom::Geometry* g = reader->read(args[0]); args.GetReturnValue().Set(Geometry::New(g)); } catch (const char* e) { isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, e))); } catch (geos::util::GEOSException e) { isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, e.what()))); } }
Handle<Value> VException(const char *msg) { Isolate *isolate = Isolate::GetCurrent(); HandleScope scope(isolate); return isolate->ThrowException(ErrorException(msg)); }
Handle<Value> ManagedRef::SetPropertyValue(Local<String> name, Local<Value> value) { Handle<Value> res; String::Value s(name); #ifdef DEBUG_TRACE_API std::cout << "SetPropertyValue" << std::endl; #endif Isolate* isolate = Isolate::GetCurrent(); jsvalue v = engine_->AnyFromV8(value); jsvalue r = engine_->CallSetPropertyValue(contextId_, id_, *s, v); if (r.type == JSVALUE_TYPE_MANAGED_ERROR) isolate->ThrowException(engine_->AnyToV8(r, contextId_));//0.12.x //res = ThrowException(engine_->AnyToV8(r, contextId_));//0.10.x else res = engine_->AnyToV8(r, contextId_); #ifdef DEBUG_TRACE_API std::cout << "cleaning up result from setproperty value" << std::endl; #endif // We don't need the jsvalues anymore and the CLR side never reuse them. jsvalue_dispose(v); jsvalue_dispose(r); return res; }
void UiWindow::Move(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.Length() != 2 && args.Length() != 4) { isolate->ThrowException(String::NewFromUtf8(isolate, "arg")); return; } UiWindow* _this = Unwrap<UiWindow>(args.This()); WindowRect rect = _this->GetWindowRect(); if (args[0]->IsNumber()) { rect.Left = args[0]->Int32Value(); } if (args[1]->IsNumber()) { rect.Top = args[1]->Int32Value(); } if (args.Length() == 4) { if (args[2]->IsNumber()) { rect.Width = args[2]->Int32Value(); } if (args[3]->IsNumber()) { rect.Height = args[3]->Int32Value(); } } _this->SetWindowRect(rect); }
/* * Prototype: * Stalker.addCallProbe(target_address, callback) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_stalker_on_add_call_probe (const FunctionCallbackInfo<Value> & info) { GumV8Stalker * self = static_cast<GumV8Stalker *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); GumV8CallProbe * probe; GumProbeId id; gpointer target_address; if (!_gum_v8_native_pointer_get (info[0], &target_address, self->core)) return; Local<Value> callback_value = info[1]; if (!callback_value->IsFunction ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Stalker.addCallProbe: second argument must be a function"))); return; } Local<Function> callback = Local<Function>::Cast (callback_value); probe = g_slice_new (GumV8CallProbe); probe->parent = self; probe->callback = new GumPersistent<Function>::type (isolate, callback); probe->receiver = new GumPersistent<Value>::type (isolate, info.This ()); id = gum_stalker_add_call_probe (_gum_v8_stalker_get (self), target_address, gum_v8_call_probe_fire, probe, reinterpret_cast<GDestroyNotify> (gum_v8_call_probe_free)); info.GetReturnValue ().Set (id); }
void ParseSync(const Nan::FunctionCallbackInfo<Value> &args) { Isolate *isolate = args.GetIsolate(); int args_length = args.Length(); if (args_length < 1) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))); return; } Local<Value> input = args[0]; if (!ValidateInput(input, isolate)) { return; } anitomyJs::AnitomyJs anitomy; if (args_length >= 2) { Local<Value> options = args[1]; if (!ValidateOptions(options, isolate) || !anitomy.SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) { return; } } anitomy.SetInput(input, isolate); anitomy.Parse(); args.GetReturnValue().Set(anitomy.ParsedResult(isolate)); }
int DeviceNode::getIntParameter(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = Isolate::GetCurrent(); if (args.Length() < 1) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong number of arguments"))); throw "Wrong number of arguments"; } if (!args[0]->IsNumber()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments"))); throw "Wrong arguments"; } return args[0]->NumberValue(); }
/* * Prototype: * Module.findBaseAddress(module_name) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_module_on_find_base_address ( const FunctionCallbackInfo<Value> & info) { GumV8Module * self = static_cast<GumV8Module *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); Local<Value> module_name_val = info[0]; if (!module_name_val->IsString ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Module.findBaseAddress: argument must be a string " "specifying module name"))); return; } String::Utf8Value module_name (module_name_val); GumAddress raw_address = gum_module_find_base_address (*module_name); if (raw_address != 0) { info.GetReturnValue ().Set ( _gum_v8_native_pointer_new (GSIZE_TO_POINTER (raw_address), self->core)); } else { info.GetReturnValue ().SetNull (); } }
/** * TJSオブジェクトのオーバライド処理 * @param args 引数 * @return 結果 */ void TJSInstance::tjsOverride(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant instance; if (getVariant(isolate, instance, args.This())) { if (args.Length() > 0) { Local<Value> func = args.Length() > 1 ? args[1] : args.This()->Get(args[0]); if (func->IsFunction()) { tTJSVariant value = toVariant(isolate, func->ToObject(), args.This()); String::Value methodName(args[0]); tjs_error error; if (TJS_FAILED(error = instance.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *methodName, NULL, &value, NULL))) { args.GetReturnValue().Set(ERROR_KRKR(isolate, error)); return; } args.GetReturnValue().Set(Undefined(isolate)); return; } } args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "not function"))); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
static void gum_v8_file_on_new_file (const FunctionCallbackInfo<Value> & info) { GumV8File * self = static_cast<GumV8File *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = self->core->isolate; if (!info.IsConstructCall ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 ( isolate, "Use `new File()` to create a new instance"))); return; } Local<Value> filename_val = info[0]; if (!filename_val->IsString ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "File: first argument must be a string specifying filename"))); return; } String::Utf8Value filename (filename_val); Local<Value> mode_val = info[1]; if (!mode_val->IsString ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "File: second argument must be a string specifying mode"))); return; } String::Utf8Value mode (mode_val); FILE * handle = fopen (*filename, *mode); if (handle == NULL) { gchar * message = g_strdup_printf ("File: failed to open file (%s)", strerror (errno)); isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, message))); g_free (message); return; } Local<Object> instance (info.Holder ()); GumFile * file = gum_file_new (instance, handle, self); instance->SetAlignedPointerInInternalField (0, file); }
void Factorial(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.Length() != 1) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong number of arguments"))); return; } if (!args[0]->IsNumber()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments"))); return; } double value = Factorial(args[0]->NumberValue()); Local<Number> num = Number::New(isolate, value); args.GetReturnValue().Set(num); }
void SayHello(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.Length() > 1) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Too many arguments"))); return; } else if (args.Length() == 0) { args.GetReturnValue().Set(String::NewFromUtf8(isolate, "Hello World")); } else { if (!args[0]->IsString()) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments type"))); } else { string argument(*String::Utf8Value(args[0]->ToString())); args.GetReturnValue().Set(String::NewFromUtf8(isolate, argument.c_str())); } } }
void NodeOSXTheme::SetMode(const FunctionCallbackInfo<Value>& iArgs) { Isolate* isolate = iArgs.GetIsolate(); if (iArgs.Length() < 1) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong number of arguments"))); return; } if (!iArgs[0]->IsString()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments"))); return; } std::string test = *String::Utf8Value(iArgs[0]); OSXTheme::SetMode(test); }
void Solve(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); if (args.Length() < 1) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments."))); return; } if (!args[0]->IsArray()) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Expected array."))); return; } Local<Array> grid = Local<Array>::Cast(args[0]); int gridLength = grid->Length(); if (gridLength != N * N) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong grid given - invalid length."))); return; } int *xgrid = new int[gridLength]; int i; for (i = 0; i < gridLength; i++) { *(xgrid + i) = grid->Get(i)->Uint32Value(); } int result = sudoku_solve(xgrid); if (!result) { delete[] xgrid; isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Invalid board given."))); return; } for (i = 0; i < gridLength; i++) { grid->Set(i, Uint32::New(isolate, *(xgrid + i))); } delete[] xgrid; args.GetReturnValue().Set(grid); }
/* * Prototype: * File.write(data_val) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_file_on_file_write (const FunctionCallbackInfo<Value> & info) { GumFile * file = static_cast<GumFile *> ( info.Holder ()->GetAlignedPointerFromInternalField (0)); Isolate * isolate = info.GetIsolate (); gpointer data = NULL; gint data_length = 0; Local<Value> data_val = info[0]; if (data_val->IsArrayBuffer ()) { ArrayBuffer::Contents contents = Handle<ArrayBuffer>::Cast (data_val)->GetContents (); data = contents.Data (); data_length = (gint) contents.ByteLength (); } else if (!data_val->IsString ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "File.write: argument must be a string or ArrayBuffer"))); return; } if (gum_file_is_open (file)) { if (data == NULL) { String::Utf8Value utf_val (data_val); fwrite (*utf_val, utf_val.length (), 1, file->handle); } else { fwrite (data, data_length, 1, file->handle); } } else { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "File.write: file is closed"))); } }
/** * 吉里吉里クラスから Javascript クラスを生成 * @param args 引数 * @return 結果 */ void TJSInstance::createTJSClass(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); if (args.Length() < 1) { args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "invalid param"))); return; } // TJSクラス情報取得 String::Value tjsClassName(args[0]); tTJSVariant tjsClassObj; TVPExecuteExpression(*tjsClassName, &tjsClassObj); if (tjsClassObj.Type() != tvtObject || TJS_FAILED(tjsClassObj.AsObjectClosureNoAddRef().IsInstanceOf(0,NULL,NULL,L"Class",NULL))) { args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "invalid param"))); return; } // クラステンプレートを生成 Local<FunctionTemplate> classTemplate = FunctionTemplate::New(isolate, tjsConstructor, TJSObject::toJSObject(isolate, tjsClassObj)); classTemplate->SetClassName(args[0]->ToString()); // 表示名 // メンバ登録処理 for (int i=args.Length()-1;i>=0;i--) { String::Value className(args[i]); tTJSVariant classObj; TVPExecuteExpression(*className, &classObj); if (classObj.Type() == tvtObject && TJS_SUCCEEDED(classObj.AsObjectClosureNoAddRef().IsInstanceOf(0,NULL,NULL,L"Class",NULL))) { MemberRegister *caller = new MemberRegister(isolate, classTemplate); tTJSVariantClosure closure(caller); classObj.AsObjectClosureNoAddRef().EnumMembers(TJS_IGNOREPROP, &closure, NULL); caller->Release(); } } // TJS機能メソッドを登録 Local<ObjectTemplate> protoTemplate = classTemplate->PrototypeTemplate(); protoTemplate->Set(String::NewFromUtf8(isolate, "tjsIsValid"), FunctionTemplate::New(isolate, tjsIsValid)); protoTemplate->Set(String::NewFromUtf8(isolate, "tjsOverride"), FunctionTemplate::New(isolate, tjsOverride)); args.GetReturnValue().Set(classTemplate->GetFunction()); }
void TempWrapper::New(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); uint8_t _addr = 0x00, _port = 0x01; // If there are two params: First Param => i2c address, second => Port number // - Only one Param, this means that the given param is the Port Number, // printf("Args Count: %d\n",args.Length()); TempWrapper* obj; uint8_t _argc = args.Length(); if(args.IsConstructCall()){ // Invoked as constructor: `new MyObject(...)` switch(_argc){ case 1: // Only the BCMWrapper is passed _port = (uint8_t) args[0]->NumberValue(); obj = new TempWrapper(_port); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); break; case 2: _port = (uint8_t) args[0]->NumberValue(); _addr = (uint8_t) args[1]->NumberValue(); obj = new TempWrapper(_port,_addr); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); break; default: isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments..."))); } }else{ // Invoked as plain function `MyObject(...)`, turn into construct call. if(_argc > 2){ isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments..."))); } Local<Value>* argv = new Local<Value>[_argc]; for(uint8_t i = 0; i < _argc; i++){ argv[i] = args[i]; } Local<Function> cons = Local<Function>::New(isolate, constructor); args.GetReturnValue().Set(cons->NewInstance(_argc, argv)); } }
void DeviceNode::Dim(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); try { int value = getIntParameter(args); getDeviceBinding(args)->_device->dim(value); } catch (const char* msg) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, msg))); } }
void JSZAttribute::jsIsReadOnly(const v8::FunctionCallbackInfo<v8::Value> &info) { Isolate *isolate = info.GetIsolate(); try { Local<External> wrap = Local<External>::Cast(info.Holder()->GetInternalField(0)); ZCLAttribute *attribute = (ZCLAttribute *) wrap->Value(); info.GetReturnValue().Set(attribute->isReadOnly()); } catch (std::exception &excp) { v8::Local<v8::String> errorMsg = v8::String::NewFromUtf8(isolate, excp.what()); isolate->ThrowException(errorMsg); } }
void Factorial(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.Length() != 2) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))); } else { if (!(args[0]->IsNumber() && args[1]->IsFunction())) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments type"))); } else { int result = factorial(args[0]->Int32Value()); Local<Function> callbackFunction = Local<Function>::Cast(args[1]); const unsigned argc = 1; Local<Value> argv[argc] = { Number::New(isolate, result) }; callbackFunction->Call(isolate->GetCurrentContext()->Global(), argc, argv); } } }
void Initialize(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.Length() < 1){ isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "init() requires an object"))); return; } Local<Object> o = args[0].As<Object>(); char* appName = NULL; char* tempDirPath = NULL; Local<String> appKey = String::NewFromUtf8(isolate, "appName"); Local<String> tempDirKey = String::NewFromUtf8(isolate, "tempDir"); if (o->Has(appKey)){ String::Utf8Value v(o->Get(appKey)->ToString()); size_t len = strlen(*v) + 1; appName = new char[len]; sprintf(appName, "%s", *v); } if (o->Has(tempDirKey)){ String::Utf8Value v(o->Get(tempDirKey)->ToString()); size_t len = strlen(*v) + 1; tempDirPath = new char[len]; sprintf(tempDirPath, "%s", *v); } if (appName == NULL || tempDirPath == NULL){ isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "init() requires 'appName' and 'tempDir'"))); return; } WindowsToastNotification::InitSystemProps(appName, tempDirPath); DELETE_IF(appName); DELETE_IF(tempDirPath); }
void LCDWrapper::SetCursor(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); LCDWrapper* temp_obj = ObjectWrap::Unwrap<LCDWrapper>(args.Holder()); uint8_t _argc = args.Length(), col, row; // printf("Args Count: %d\n",_argc); if(_argc != 2){ isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments to set cursor in the LCD Module..."))); } row = (uint8_t) (args[0]->NumberValue() - 1); col = (uint8_t) (args[1]->NumberValue() - 1); if(col > 39 or row > 1){ isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments to set cursor in the LCD Module..."))); } temp_obj->lcd->setCursor(row,col); // args.GetReturnValue().Set(Number::New(isolate,temp_obj->lcd->message(_msg))); }