V8 version: 7.6.303.29
OS: Linux
Arch: x64

On Thursday, August 29, 2019 at 11:25:24 AM UTC+8, cgsdfc wrote:
>
> I had this problem with I was writing simple v8 demo. Basically, I want to 
> bind a C++ `Point` class to javascript so that the following code should 
> work:
> var p = new Point; // Point is function implemented in C++.
> print(p.x);
>
> The `Point` object is expected to have a readonly property `x`.
> To achieve that,  I performed the following steps:
>
>    1. Create a `FunctionTemplate` and set its callback to a C++ function. 
>    This serves as the `Point` constructor. The callback uses `External` to 
>    associate a C++ Point to the JS object.
>    2. set internal field count to 1 on the `InstanceTemplate` of the 
>    above `FunctionTemplate`.
>    3. Attach getter callback implemented in C++ to the point constructor 
>    with `SetAccessor`. The callback uses the `Holder()` method of a 
>    `PropertyCallbackInfo` to get the receiver and then get the C++ Point 
>    object.
>    4. Write the above JS code in a C++ string and compile and run it.
>
> And this will produce an "Internal Field Count Out of Range" error.
> Meanwhile, I experimented with the combination of using `Holder` or 
> `This`  and `SetAccessor` or `SetAccessorProperty` and found interesting 
> results.
> The results are:
>
>    1. SetAccessorProperty works with both `This` and `Holder`.
>    2. SetAccessor only works with `This`.
>    
> As I made no use of `Signature`, aren't This and Holder  the same thing? 
> But why it makes a difference w.r.t `SetAccessorProperty` and `SetAccessor`?
> In the attachment, I present the code to reproduce this problem and the 
> modified main BUILD.gn to configure the build.
> Anyone who can shed some light on this problem will be greatly appreciated!
>
> [image: Screenshot from 2019-08-29 11-17-58.png]
>

-- 
-- 
v8-users mailing list
v8-users@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/e39f31d1-477d-4881-9392-8858d22c16f0%40googlegroups.com.

Reply via email to