Skip to content

Commit

Permalink
Don't use deprecated v8::Template::Set() in SetMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed Apr 27, 2016
1 parent 7acd8ca commit a90951e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 6 additions & 3 deletions doc/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,12 @@ Sets a method with a given name directly on a JavaScript object where the method
Signature:

```c++
template<typename T> void Nan::SetMethod(const T &recv,
const char *name,
Nan::FunctionCallback callback)
void Nan::SetMethod(v8::Local<v8::Object> recv,
const char *name,
Nan::FunctionCallback callback)
void Nan::SetMethod(v8::Local<v8::Template> templ,
const char *name,
Nan::FunctionCallback callback)
```
<a name="api_nan_set_prototype_method"></a>
Expand Down
14 changes: 12 additions & 2 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1850,9 +1850,8 @@ NAN_INLINE void SetInstanceTemplate(
SetTemplate(templ->InstanceTemplate(), name, value, attributes);
}

template<typename T>
NAN_INLINE void SetMethod(
const T &recv
v8::Local<v8::Object> recv
, const char *name
, FunctionCallback callback) {
HandleScope scope;
Expand All @@ -1863,6 +1862,17 @@ NAN_INLINE void SetMethod(
recv->Set(fn_name, fn);
}

NAN_INLINE void SetMethod(
v8::Local<v8::Template> templ
, const char *name
, FunctionCallback callback) {
HandleScope scope;
v8::Local<v8::FunctionTemplate> t = New<v8::FunctionTemplate>(callback);
v8::Local<v8::String> fn_name = New(name).ToLocalChecked();
t->SetClassName(fn_name);
templ->Set(fn_name, t);
}

NAN_INLINE void SetPrototypeMethod(
v8::Local<v8::FunctionTemplate> recv
, const char* name, FunctionCallback callback) {
Expand Down

5 comments on commit a90951e

@springmeyer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkoopa just an fyi. This triggers for me:

../src/mapnik_image.cpp:118:5: error: call to 'SetMethod' is ambiguous
    Nan::SetMethod(lcons->GetFunction(),

at https://github.com/mapnik/node-mapnik/blob/master/src/mapnik_image.cpp#L117-L120. It looks like my usage is non-standard, so I'm working on finding a workaround.

@kkoopa
Copy link
Collaborator Author

@kkoopa kkoopa commented on a90951e Apr 29, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@springmeyer
Copy link
Contributor

@springmeyer springmeyer commented on a90951e Apr 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, do you recommend a better workaround than another? So far I confirmed that Nan::SetMethod(lcons->GetFunction()->ToObject(), works.

@kkoopa
Copy link
Collaborator Author

@kkoopa kkoopa commented on a90951e Apr 29, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@springmeyer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkoopa - thanks As<v8::Object>() also works. I've also created a ticket at #564.

Please sign in to comment.