Re: [v8-users] ArrayBuffer size is 0

2019-09-01 Thread 'Simon Zünd' via v8-users
Hey,

You are not accessing the "size" property, but treat "args[0]" as if it
were a number (which it is not, it's a ArrayBuffer). Since you have
established that args[0] is an ArrayBuffer, you can use cast, which would
look roughly like this:

Local array_buffer = Local::cast(args[0]);
size_t size = array_buffer->ByteLength();


On Mon, Sep 2, 2019 at 12:50 AM Jonathan Doster  wrote:

> Hey everyone!
>
> I am trying to pass an ArrayBuffer from JS to C++, and when I debug the
> "size" variable is 0.
> I do not understand what I am doing wrong, ultimately my goal is to be
> able to read and write the buffer, copy, etc.
> Thank you!!
>
> var api = require('../src/public/api')
> api.Method(new ArrayBuffer([1, 2, 3, 4]))
>
> void Method(const v8::FunctionCallbackInfo )
> {
> CHECK_ARGS(args, args[0]->IsArrayBuffer());
> uint32_t size = args[0]->Uint32Value();
> }
>
>
> --
> --
> 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/ed43b406-af94-49f1-94c2-47c09673379d%40googlegroups.com
> 
> .
>

-- 
-- 
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/CACswSC1LA6dT66X12EOTNTrG29St8tnnHYp8uqhwARtid4ijcA%40mail.gmail.com.


[v8-users] ArrayBuffer size is 0

2019-09-01 Thread Jonathan Doster
Hey everyone!

I am trying to pass an ArrayBuffer from JS to C++, and when I debug the 
"size" variable is 0. 
I do not understand what I am doing wrong, ultimately my goal is to be able 
to read and write the buffer, copy, etc.
Thank you!!

var api = require('../src/public/api')
api.Method(new ArrayBuffer([1, 2, 3, 4]))

void Method(const v8::FunctionCallbackInfo )
{
CHECK_ARGS(args, args[0]->IsArrayBuffer());
uint32_t size = args[0]->Uint32Value();
}


-- 
-- 
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/ed43b406-af94-49f1-94c2-47c09673379d%40googlegroups.com.