Re: [v8-users] ArrayBuffer size is 0

23 views
Skip to first unread message

Simon Zünd

unread,
Sep 2, 2019, 1:31:08 AM9/2/19
to 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<ArrayBuffer> array_buffer = Local<ArrayBuffer>::cast(args[0]);
size_t size = array_buffer->ByteLength();


On Mon, Sep 2, 2019 at 12:50 AM Jonathan Doster <jbdo...@gmail.com> 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<v8::Value> &args)
{
CHECK_ARGS(args, args[0]->IsArrayBuffer());
uint32_t size = args[0]->Uint32Value();
}


--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/ed43b406-af94-49f1-94c2-47c09673379d%40googlegroups.com.

Jonathan Doster

unread,
Sep 2, 2019, 11:53:42 AM9/2/19
to v8-u...@googlegroups.com
Simon,

Thank you so much for your answer!
That makes perfect sense

--
Jonathan Doster 909.839.3432 Jbdo...@gmail.com Please disregard any spelling errors, this message was sent via mobile.
Reply all
Reply to author
Forward
0 new messages