return;
}
- Local<Number> num = Number::New(args[0]->NumberValue() +
- args[1]->NumberValue());
+ double value = args[0]->NumberValue() + args[1]->NumberValue();
+ Local<Number> num = Number::New(isolate, value);
args.GetReturnValue().Set(num);
}
Local<Function> cb = Local<Function>::Cast(args[0]);
const unsigned argc = 1;
Local<Value> argv[argc] = { String::NewFromUtf8(isolate, "hello world") };
- cb->Call(Context::GetCurrent()->Global(), argc, argv);
+ cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}
void Init(Handle<Object> exports, Handle<Object> module) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
- Local<Object> obj = Object::New();
+ Local<Object> obj = Object::New(isolate);
obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString());
args.GetReturnValue().Set(obj);
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
- Local<FunctionTemplate> tpl = FunctionTemplate::New(MyFunction);
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
Local<Function> fn = tpl->GetFunction();
// omit this to make it anonymous
Isolate* isolate = Isolate::GetCurrent();
// Prepare constructor template
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.This());
obj->value_ += 1;
- args.GetReturnValue().Set(Number::New(obj->value_));
+ args.GetReturnValue().Set(Number::New(isolate, obj->value_));
}
Test it with:
void MyObject::Init() {
Isolate* isolate = Isolate::GetCurrent();
// Prepare constructor template
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.This());
obj->value_ += 1;
- args.GetReturnValue().Set(Number::New(obj->value_));
+ args.GetReturnValue().Set(Number::New(isolate, obj->value_));
}
Test it with:
args[1]->ToObject());
double sum = obj1->value() + obj2->value();
- args.GetReturnValue().Set(Number::New(sum));
+ args.GetReturnValue().Set(Number::New(isolate, sum));
}
void InitAll(Handle<Object> exports) {
Isolate* isolate = Isolate::GetCurrent();
// Prepare constructor template
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
inline void MakeWeak(void) {
- persistent().MakeWeak(this, WeakCallback);
+ persistent().SetWeak(this, WeakCallback);
persistent().MarkIndependent();
}
int refs_; // ro
private:
- static void WeakCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Object>* pobj,
- ObjectWrap* wrap) {
+ static void WeakCallback(
+ const v8::WeakCallbackData<v8::Object, ObjectWrap>& data) {
+ v8::Isolate* isolate = data.GetIsolate();
v8::HandleScope scope(isolate);
+ ObjectWrap* wrap = data.GetParameter();
assert(wrap->refs_ == 0);
- assert(*pobj == wrap->persistent());
- assert((*pobj).IsNearDeath());
+ assert(wrap->handle_.IsNearDeath());
+ assert(
+ data.GetValue() == v8::Local<v8::Object>::New(isolate, wrap->handle_));
+ wrap->handle_.Reset();
delete wrap;
}
HandleScope scope(isolate);
async_req* req = reinterpret_cast<async_req*>(r->data);
- Handle<Value> argv[2] = { Null(), Integer::New(req->output) };
+ Handle<Value> argv[2] = {
+ Null(isolate),
+ Integer::New(isolate, req->output)
+ };
TryCatch try_catch;
Local<Function> callback = Local<Function>::New(isolate, req->callback);
- callback->Call(Context::GetCurrent()->Global(), 2, argv);
+ callback->Call(isolate->GetCurrentContext()->Global(), 2, argv);
// cleanup
- req->callback.Dispose();
+ req->callback.Reset();
delete req;
if (try_catch.HasCaught()) {