Skip to content

Commit

Permalink
doc: replace v8::Handle<T> with v8::Local<T>
Browse files Browse the repository at this point in the history
v8::Handle is on its way out, to be replaced with v8::Local.  Update the
addons documentation accordingly.

PR-URL: #1125
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed Mar 21, 2015
1 parent 2f1b783 commit c4e1b82
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions doc/api/addons.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ First we create a file `hello.cc`:
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}

void init(Handle<Object> exports) {
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}

NODE_MODULE(addon, init)

Note that all io.js addons must export an initialization function:

void Initialize (Handle<Object> exports);
void Initialize(Local<Object> exports);
NODE_MODULE(module_name, Initialize)

There is no semi-colon after `NODE_MODULE` as it's not a function (see
Expand Down Expand Up @@ -164,7 +164,7 @@ function calls and return a result. This is the main and only needed source
args.GetReturnValue().Set(num);
}

void Init(Handle<Object> exports) {
void Init(Local<Object> exports) {
NODE_SET_METHOD(exports, "add", Add);
}

Expand Down Expand Up @@ -196,7 +196,7 @@ there. Here's `addon.cc`:
cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}

void Init(Handle<Object> exports, Handle<Object> module) {
void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", RunCallback);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ the string passed to `createObject()`:
args.GetReturnValue().Set(obj);
}

void Init(Handle<Object> exports, Handle<Object> module) {
void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", CreateObject);
}

Expand Down Expand Up @@ -280,7 +280,7 @@ wraps a C++ function:
args.GetReturnValue().Set(fn);
}

void Init(Handle<Object> exports, Handle<Object> module) {
void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", CreateFunction);
}

Expand All @@ -307,7 +307,7 @@ module `addon.cc`:

using namespace v8;

void InitAll(Handle<Object> exports) {
void InitAll(Local<Object> exports) {
MyObject::Init(exports);
}

Expand All @@ -324,7 +324,7 @@ Then in `myobject.h` make your wrapper inherit from `node::ObjectWrap`:

class MyObject : public node::ObjectWrap {
public:
static void Init(v8::Handle<v8::Object> exports);
static void Init(v8::Local<v8::Object> exports);

private:
explicit MyObject(double value = 0);
Expand Down Expand Up @@ -355,7 +355,7 @@ prototype:
MyObject::~MyObject() {
}

void MyObject::Init(Handle<Object> exports) {
void MyObject::Init(Local<Object> exports) {
Isolate* isolate = exports->GetIsolate();

// Prepare constructor template
Expand Down Expand Up @@ -429,7 +429,7 @@ Let's register our `createObject` method in `addon.cc`:
MyObject::NewInstance(args);
}

void InitAll(Handle<Object> exports, Handle<Object> module) {
void InitAll(Local<Object> exports, Local<Object> module) {
MyObject::Init(exports->GetIsolate());

NODE_SET_METHOD(module, "exports", CreateObject);
Expand Down Expand Up @@ -514,7 +514,7 @@ The implementation is similar to the above in `myobject.cc`:
Isolate* isolate = args.GetIsolate();

const unsigned argc = 1;
Handle<Value> argv[argc] = { args[0] };
Local<Value> argv[argc] = { args[0] };
Local<Function> cons = Local<Function>::New(isolate, constructor);
Local<Object> instance = cons->NewInstance(argc, argv);

Expand Down Expand Up @@ -576,7 +576,7 @@ In the following `addon.cc` we introduce a function `add()` that can take on two
args.GetReturnValue().Set(Number::New(isolate, sum));
}

void InitAll(Handle<Object> exports) {
void InitAll(Local<Object> exports) {
MyObject::Init(exports->GetIsolate());

NODE_SET_METHOD(exports, "createObject", CreateObject);
Expand Down Expand Up @@ -659,7 +659,7 @@ The implementation of `myobject.cc` is similar as before:
Isolate* isolate = args.GetIsolate();

const unsigned argc = 1;
Handle<Value> argv[argc] = { args[0] };
Local<Value> argv[argc] = { args[0] };
Local<Function> cons = Local<Function>::New(isolate, constructor);
Local<Object> instance = cons->NewInstance(argc, argv);

Expand Down

0 comments on commit c4e1b82

Please sign in to comment.