Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecation warnings when used with node v6.0.0 #558

Closed
mdouglass opened this issue Apr 26, 2016 · 9 comments
Closed

deprecation warnings when used with node v6.0.0 #558

mdouglass opened this issue Apr 26, 2016 · 9 comments

Comments

@mdouglass
Copy link

The default use of Nan::SetPrototypeMethod is giving warnings under node 6.0. I had to change from:

Nan::SetPrototypeMethod(tpl, "flood", Flood);

to:

tpl->PrototypeTemplate()->Set(Nan::New<v8::String>("flood").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(QuadTree::Flood));

in order to bypass the warning. It would be nice if SetPrototypeMethod was updated to do this internally.

@kkoopa
Copy link
Collaborator

kkoopa commented Apr 26, 2016

The proper fix will require changing the rest of the template setters, removing functionality, which will entail backwards incompatibility, requiring a new major version. I wish they had not introduced this warning, as the functionality is still available until Node 7. I shall think of something soon enough, but will hold off until more reports have arrived about other possible issues, since one can't publish new major versions all the time.

cc @bnoordhuis

@MylesBorins
Copy link

cc @nodejs/ctc

@bnoordhuis
Copy link
Member

The fixes in #559 and #560 are really all that's needed to address this. Instead of setting a v8::Function property (which is per-context), you now set a v8::FunctionTemplate and the v8::Function is instantiated on demand.

@kkoopa
Copy link
Collaborator

kkoopa commented Apr 26, 2016

But Nan::SetTemplate, Nan::SetInstanceTemplate and Nan::SetPropertyTemplate all accept a v8::Data argument, which will no longer work if only v8::Primitives and v8::FunctionTemplates are allowed, since it would be possible to pass e.g. a v8::Object to any of said functions.

@kkoopa
Copy link
Collaborator

kkoopa commented Apr 26, 2016

However, it does seem like the signature still takes a v8::Data argument as of V8 5.2.146. If that is not going to be changed, I guess the modifications need not break compatibility.

@bnoordhuis
Copy link
Member

Well, 5.2 enforces through an assert that the value is not an object, so sooner or later people will have to update their code.

It's possible to work around that to some extent using v8::Template::SetNativeDataProperty() but it takes a v8::Value, not a v8::Data. We could perhaps add an overload.

@kkoopa
Copy link
Collaborator

kkoopa commented Apr 26, 2016

Yes, an overload might work. That is probably the best option for keeping consistency between versions, as I don't think v8::Template::SetNativeDataProperty() is available in old versions, and thus ought not to be directly exposed through NAN. I can put something together by tomorrow and push out a new minor version of NAN with explicit Node 6 support if no other issues arise by then.

@kkoopa
Copy link
Collaborator

kkoopa commented Apr 26, 2016

Using v8::Template::SetNativeDataProperty() is not as easy as it sounds, since it would require storing the value somewhere accessible to the getter and setter. Using internal fields for this only works for object instances. It is easier to say caveat emptor and leave it up to the user not to misuse the template setting functions if they want full compatibility. However, there will then be no way of setting arbitrary values on templates in future versions without using v8::Template::SetNativeDataProperty() directly, and that causes further problems, as it takes a v8::AccessorGetterCallback and not a Nan::AccessorGetterCallback.

@zakdances
Copy link

It's not mentioned here, so I just want to note that this issues appears to be fixed since 2.3.2.

Thanks to kkoopa for the relevant commits (here and here and elsewhere) and to everyone else reporting in.

agnat added a commit that referenced this issue May 2, 2016
Latest v8 disallows setting non-primitive values on v8::Template and
derived types. So we no longer can assign v8::Functions directly since
it results in a v8 runtime warning reported in #558 [0]. Instead we
assign v8::FunctionTemplates. The initial approach of using a bunch of
overloads does not cover all cases as was reported in #564 [1] which
also discusses the technical reason behind this regression.

The new approach employs two auxiliary functions that take an
additional argument to discriminate v8::Templates from non-templates.
It deals with derived types correctly since the discriminating argument
(a pointer) is subject to "normal" conversion rules.

The entry point SetMethod(...) "peels off" the handle type using a
template-template parameter. This gives access to the "inner type" T.
It also deals nicely with the Local<> vs. Handle<> schism which is
still an issue with historic node/v8 versions.

It also adds tests for both the runtime warning in #558 and the
regression from #564. Finally, it tunes "npm test" to show v8 runtime
deprecation warnings.

This closes #564.

[0] #558
[1] #564
kkoopa pushed a commit that referenced this issue May 3, 2016
Latest v8 disallows setting non-primitive values on v8::Template and
derived types. So we no longer can assign v8::Functions directly since
it results in a v8 runtime warning reported in #558 [0]. Instead we
assign v8::FunctionTemplates. The initial approach of using a bunch of
overloads does not cover all cases as was reported in #564 [1] which
also discusses the technical reason behind this regression.

The new approach employs two auxiliary functions that take an
additional argument to discriminate v8::Templates from non-templates.
It deals with derived types correctly since the discriminating argument
(a pointer) is subject to "normal" conversion rules.

The entry point SetMethod(...) "peels off" the handle type using a
template-template parameter. This gives access to the "inner type" T.
It also deals nicely with the Local<> vs. Handle<> schism which is
still an issue with historic node/v8 versions.

It also adds tests for both the runtime warning in #558 and the
regression from #564. Finally, it tunes "npm test" to show v8 runtime
deprecation warnings.

This closes #564.

[0] #558
[1] #564
amitparida added a commit to amitparida/npm-nan that referenced this issue Oct 3, 2024
Latest v8 disallows setting non-primitive values on v8::Template and
derived types. So we no longer can assign v8::Functions directly since
it results in a v8 runtime warning reported in #558 [0]. Instead we
assign v8::FunctionTemplates. The initial approach of using a bunch of
overloads does not cover all cases as was reported in #564 [1] which
also discusses the technical reason behind this regression.

The new approach employs two auxiliary functions that take an
additional argument to discriminate v8::Templates from non-templates.
It deals with derived types correctly since the discriminating argument
(a pointer) is subject to "normal" conversion rules.

The entry point SetMethod(...) "peels off" the handle type using a
template-template parameter. This gives access to the "inner type" T.
It also deals nicely with the Local<> vs. Handle<> schism which is
still an issue with historic node/v8 versions.

It also adds tests for both the runtime warning in #558 and the
regression from #564. Finally, it tunes "npm test" to show v8 runtime
deprecation warnings.

This closes #564.

[0] nodejs/nan#558
[1] nodejs/nan#564
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants