Adding Signature to my FunctionTemplate but "derived types" calling functions get Illegal Invocation errors

32 views
Skip to first unread message

Zac Hansen

unread,
May 28, 2017, 1:27:01 PM5/28/17
to v8-users
I create a "constructor" FunctionTemplate, create a signature from that FunctionTemplate, then on that FunctionTemplate's PrototypeObject ObjectTemplate, I create a bunch of FunctionTemplate's using the signature I generated before.  

I can call the function with objects created directly from the "constructor" FunctionTemplate.  But if I call it from an object with that object in the prototype chain, it doesn't work.

base = new MyType();
derived = Object.create(base);  // setting .__proto__ has the same behavior

base.some_native_function(); <== works

derived.some_native_function(); <== TypeError: Illegal invocation



Anyone know what I might be doing wrong?  If I remove the signature, everything works fine, but then holder == this when calling with derived, which isn't what I want.

--Zac

Jochen Eisinger

unread,
May 29, 2017, 2:57:42 AM5/29/17
to v8-users
A signature requires the object either be constructed from the same FunctionTemplate (as e.g. new MyType() does), or from a FunctionTemplate that inherited from the signature's FunctionTemplate.

Note however that the "info.Holder" would still point at the receiver, and not the prototype with the matching signature :/

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zac Hansen

unread,
May 29, 2017, 3:01:21 AM5/29/17
to v8-u...@googlegroups.com
In this thread: https://groups.google.com/forum/#!topic/v8-users/Axf4hF_RfZo

it says: 

If your function has a signature that says that it must be called on a 
particular type v8 will search the prototype chain for an object of 
that type when the function is called.


Given my code, I don't understand why making an object that directly sets its prototype as an object capable of calling a function with a signature wouldn't be able to call that same function.   

Is that thread I linked wrong?   Or am I misunderstanding something?

To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/dR8oI0ZwzG0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

Zac Hansen

unread,
May 29, 2017, 3:08:02 AM5/29/17
to v8-u...@googlegroups.com
My understanding is that the signature picking out the object in the prototype chain was the difference between info.This and info.Holder.  Mostly from reading the thread I linked previously.  

Also, this is from the doxygen docs for signature:   

> A receiver matches a given signature if the receiver (or any of its hidden prototypes) was created from the signature's FunctionTemplate, or from a FunctionTemplate that inherits directly or indirectly from the signature's FunctionTemplate.

Jochen Eisinger

unread,
May 29, 2017, 4:18:14 AM5/29/17
to v8-u...@googlegroups.com
I recently updated the documentation for Info.Holder() and Info.This() - they only differ if you use a hidden prototype.

The comment on Signature you quoted is correct - your example code doesn't use inheritance of the FunctionTemplate but JS inheritance.

To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/dR8oI0ZwzG0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages