From 409d4133631ca2580488deba317eb1a0d55bcd55 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 11 Mar 2015 13:41:32 +0100 Subject: [PATCH] doc: remove uses of v8::Isolate::GetCurrent() v8::Isolate::GetCurrent() is slated for deprecation. Replace its uses in the addons documentation with v8::Object::GetIsolate(), etc. PR-URL: https://github.com/iojs/io.js/pull/1125 Reviewed-By: Rod Vagg Reviewed-By: Trevor Norris --- doc/api/addons.markdown | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/doc/api/addons.markdown b/doc/api/addons.markdown index 5c77c7f..d47b630 100644 --- a/doc/api/addons.markdown +++ b/doc/api/addons.markdown @@ -44,7 +44,7 @@ First we create a file `hello.cc`: using namespace v8; void Method(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world")); } @@ -145,7 +145,7 @@ function calls and return a result. This is the main and only needed source using namespace v8; void Add(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); if (args.Length() < 2) { @@ -191,7 +191,7 @@ there. Here's `addon.cc`: using namespace v8; void RunCallback(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); Local cb = Local::Cast(args[0]); @@ -233,7 +233,7 @@ the string passed to `createObject()`: using namespace v8; void CreateObject(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); Local obj = Object::New(isolate); @@ -269,13 +269,13 @@ wraps a C++ function: using namespace v8; void MyFunction(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world")); } void CreateFunction(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); Local tpl = FunctionTemplate::New(isolate, MyFunction); @@ -363,7 +363,7 @@ prototype: } void MyObject::Init(Handle exports) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = exports->GetIsolate(); // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); @@ -379,7 +379,7 @@ prototype: } void MyObject::New(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); if (args.IsConstructCall()) { @@ -398,7 +398,7 @@ prototype: } void MyObject::PlusOne(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); MyObject* obj = ObjectWrap::Unwrap(args.Holder()); @@ -435,13 +435,13 @@ Let's register our `createObject` method in `addon.cc`: using namespace v8; void CreateObject(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); MyObject::NewInstance(args); } void InitAll(Handle exports, Handle module) { - MyObject::Init(); + MyObject::Init(exports->GetIsolate()); NODE_SET_METHOD(module, "exports", CreateObject); } @@ -460,7 +460,7 @@ care of instantiating the object (i.e. it does the job of `new` in JavaScript): class MyObject : public node::ObjectWrap { public: - static void Init(); + static void Init(v8::Isolate* isolate); static void NewInstance(const v8::FunctionCallbackInfo& args); private: @@ -491,8 +491,7 @@ The implementation is similar to the above in `myobject.cc`: MyObject::~MyObject() { } - void MyObject::Init() { - Isolate* isolate = Isolate::GetCurrent(); + void MyObject::Init(Isolate* isolate) { // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); @@ -505,7 +504,7 @@ The implementation is similar to the above in `myobject.cc`: } void MyObject::New(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); if (args.IsConstructCall()) { @@ -524,7 +523,7 @@ The implementation is similar to the above in `myobject.cc`: } void MyObject::NewInstance(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); const unsigned argc = 1; @@ -536,7 +535,7 @@ The implementation is similar to the above in `myobject.cc`: } void MyObject::PlusOne(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); MyObject* obj = ObjectWrap::Unwrap(args.Holder()); @@ -576,13 +575,13 @@ In the following `addon.cc` we introduce a function `add()` that can take on two using namespace v8; void CreateObject(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); MyObject::NewInstance(args); } void Add(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); MyObject* obj1 = node::ObjectWrap::Unwrap( @@ -595,7 +594,7 @@ In the following `addon.cc` we introduce a function `add()` that can take on two } void InitAll(Handle exports) { - MyObject::Init(); + MyObject::Init(exports->GetIsolate()); NODE_SET_METHOD(exports, "createObject", CreateObject); NODE_SET_METHOD(exports, "add", Add); @@ -615,7 +614,7 @@ can probe private values after unwrapping the object: class MyObject : public node::ObjectWrap { public: - static void Init(); + static void Init(v8::Isolate* isolate); static void NewInstance(const v8::FunctionCallbackInfo& args); inline double value() const { return value_; } @@ -646,9 +645,7 @@ The implementation of `myobject.cc` is similar as before: MyObject::~MyObject() { } - void MyObject::Init() { - Isolate* isolate = Isolate::GetCurrent(); - + void MyObject::Init(Isolate* isolate) { // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); @@ -658,7 +655,7 @@ The implementation of `myobject.cc` is similar as before: } void MyObject::New(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); if (args.IsConstructCall()) { @@ -677,7 +674,7 @@ The implementation of `myobject.cc` is similar as before: } void MyObject::NewInstance(const FunctionCallbackInfo& args) { - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); const unsigned argc = 1; -- 2.7.4