本文整理汇总了C++中Isolate::ThrowException方法的典型用法代码示例。如果您正苦于以下问题:C++ Isolate::ThrowException方法的具体用法?C++ Isolate::ThrowException怎么用?C++ Isolate::ThrowException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Isolate
的用法示例。
在下文中一共展示了Isolate::ThrowException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Serialize
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);
}
示例2: Lookup
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();
}
}
示例3: ParseAsync
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());
}
示例4: Each
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;
}
}
示例5:
/*
* 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);
}
示例6: Setter
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();
}
示例7: if
/*
* 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);
}
示例8: Read
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())));
}
}
示例9: scope
Handle<Value>
VException(const char *msg) {
Isolate *isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
return isolate->ThrowException(ErrorException(msg));
}
示例10: s
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;
}
示例11: Move
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);
}
示例12: ParseSync
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));
}
示例13:
/*
* 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);
}
示例14: New
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));
}
}
示例15: getIntParameter
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();
}