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

Receiver parameter for CallAsFunction should be Local<Value> #497

Closed
cscott opened this issue Oct 21, 2015 · 14 comments
Closed

Receiver parameter for CallAsFunction should be Local<Value> #497

cscott opened this issue Oct 21, 2015 · 14 comments

Comments

@cscott
Copy link

cscott commented Oct 21, 2015

The receiver can be null, so the receiver parameter for Nan::CallAsFunction should be Local<Value> not Local<Object>. The parameter is declared as Local<Value> in v8, it's just Nan which has the overly-restrictive type.

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 21, 2015

No.

On October 21, 2015 9:47:07 AM GMT+03:00, "C. Scott Ananian" notifications@github.com wrote:

The receiver can be null, so the receiver parameter for
Nan::CallAsFunction should be Local<Value> not Local<Object>.
The parameter is declared as Local<Value> in v8, it's just Nan which
has the overly-restrictive type.


Reply to this email directly or view it on GitHub:
#497

@kkoopa kkoopa closed this as completed Oct 21, 2015
@cscott
Copy link
Author

cscott commented Oct 21, 2015

Hm. JavaScript has changed since the node 0.8.x days.

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 21, 2015

Try telling that to the holdouts who refuse to upgrade. Here I am, seemingly stuck with supporting outdated software until the heat death of the universe. The same goes for 0.10.

@bnoordhuis
Copy link
Member

It would be possible to emulate it for older versions with something like this:

Local<Value> recv = /* ... */;
Local<Object> recv_obj;
if (recv->IsUndefined() || recv->IsNull()) {
  recv_obj = Context::Global();
} else {
  recv_obj = recv->ToObject();
}

The IsUndefined() and IsNull() checks are cheap, probably cheaper than putting in an extra if (recv->IsObject()) for the common case.

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 21, 2015

Interesting. Would this apply to all the other function-related stuff which has
the same problem?

On Wednesday 21 October 2015 02:47:00 Ben Noordhuis wrote:

It would be possible to emulate it for older versions with something like
this:

Local<Value> recv = /* ... */;
Local<Object> recv_obj;
if (recv->IsUndefined() || recv->IsNull()) {
  recv_obj = Context::Global();
} else {
  recv_obj = recv->ToObject();
}

The IsUndefined() and IsNull() checks are cheap, probably cheaper than
putting in an extra if (recv->IsObject()) for the common case.


Reply to this email directly or view it on GitHub:
#497 (comment)

@bnoordhuis
Copy link
Member

What function-related stuff is that? My comment was mostly in the context of Function::Call().

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 21, 2015

I seem to remember a couple other places where there has been a change from Object to Value. Some in V8 some in Node. Maybe MakeCallback? I think there was a bunch of stuff that eventually boiled down to Function::Call.

On October 21, 2015 12:58:33 PM GMT+03:00, Ben Noordhuis notifications@github.com wrote:

What function-related stuff is that? My comment was mostly in the
context of Function::Call().


Reply to this email directly or view it on GitHub:
#497 (comment)

@bnoordhuis
Copy link
Member

Oh, like that. Yes, for consistency the nan wrapper for node::MakeCallback() should get the same treatment.

@kkoopa kkoopa reopened this Oct 21, 2015
@kkoopa
Copy link
Collaborator

kkoopa commented Oct 21, 2015

After grepping for v8::Object it seems these are the ones that need updating:
CallAsFunction
MakeCallback
Callback::Call
Callback::operator()
Call #496

@cscott
Copy link
Author

cscott commented Oct 21, 2015

It would be nice to ensure that (5).toString() works as well -- I'm not sure if ToObject (as @bnoordhuis wrote above) does the full object conversion for primitives.

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 21, 2015

Primitive is-a Value which is where ToObject is defined. It's a v8 bug if it does not work.

@bnoordhuis
Copy link
Member

I'm not sure if ToObject (as @bnoordhuis wrote above) does the full object conversion for primitives.

It does (or should - like @kkoopa said, it's a V8 bug if it doesn't.)

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 21, 2015

@kkoopa
Copy link
Collaborator

kkoopa commented Nov 14, 2015

Could not come up with a way to handle the differences between strict and sloppy mode correctly, so this cannot be done until 0.10 support is dropped.

@kkoopa kkoopa closed this as completed Nov 14, 2015
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

Successfully merging a pull request may close this issue.

3 participants