Retrieve void* from TypedArray using Object::GetIndexedPropertiesExternalArrayData()

164 views
Skip to first unread message

Trevor Norris

unread,
Nov 17, 2014, 2:26:28 PM11/17/14
to v8-...@googlegroups.com
It was recently brought to my attention that the void* from an ArrayBuffer
created in JS can be retrieved from a TypedArray using
Object::GetIndexedPropertiesExternalArrayData(). Here's an example:


// JS side
var ui = new Uint8Array(new ArrayBuffer(16));
fillArray(ui);


// C++ side
void FillArray(const FunctionCallbackInfo<Value>& args) {
    Local<Object> o = args[0].As<Object>();
    char* data = static_cast<char*>(o->GetIndexedPropertiesExternalArrayData());
    // Now have a pointer to the data
}


Wanted to check if this was intentional or just a side-effect of some internal
implementation details. Also whether it is "safe" to use or not.

Reply all
Reply to author
Forward
0 new messages