本文整理汇总了C++中MyObject::Wrap方法的典型用法代码示例。如果您正苦于以下问题:C++ MyObject::Wrap方法的具体用法?C++ MyObject::Wrap怎么用?C++ MyObject::Wrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyObject
的用法示例。
在下文中一共展示了MyObject::Wrap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NAN_METHOD
static NAN_METHOD(New) {
if (info.IsConstructCall()) {
double value = info[0]->IsUndefined() ? 0 : info[0]->NumberValue();
MyObject *obj = new MyObject(value);
obj->Wrap(info.This());
info.GetReturnValue().Set(info.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = {info[0]};
v8::Local<v8::Function> cons = Nan::New(constructor);
info.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}
示例2: NAN_METHOD
static NAN_METHOD(New) {
if (info.IsConstructCall()) {
double value = info[0]->IsNumber() ? To<double>(info[0]).FromJust() : 0;
MyObject * obj = new MyObject(value);
obj->Wrap(info.This());
info.GetReturnValue().Set(info.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = {info[0]};
v8::Local<v8::Function> cons = Nan::New(constructor());
info.GetReturnValue().Set(
Nan::NewInstance(cons, argc, argv).ToLocalChecked());
}
}
示例3: NAN_METHOD
static NAN_METHOD(New) {
NanScope();
if (args.IsConstructCall()) {
double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
MyObject *obj = new MyObject(value);
obj->Wrap(args.This());
NanReturnThis();
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = {args[0]};
v8::Local<v8::Function> cons = NanNew(constructor);
NanReturnValue(cons->NewInstance(argc, argv));
}
}
示例4: New
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.IsConstructCall()) {
// Invoked as constructor: `new MyObject(...)`
double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
MyObject* obj = new MyObject(value);
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
// Invoked as plain function `MyObject(...)`, turn into construct call.
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));
}
}