node::Buffer::Data assertion after upgrading to v8 version 8.4.371

97 views
Skip to first unread message

Will Lucas

unread,
Aug 19, 2021, 10:28:28 PM8/19/21
to v8-users
Hi all!

I've been trying to upgrade our C++ backend to use the Node.js LTS 14.15.5. Previously, I would store and retrieve a Buffer object with a simple byte buffer as follows:

Storing the data:
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Local<v8::Object> matObj = v8::Object::New(isolate);

v8::Local<v8::Object> buffer = node::Buffer::Copy(isolate, reinterpret_cast<const char*>(source.data), source.total()).ToLocalChecked();
matObj->Set(context, v8::String::NewFromUtf8Literal(isolate, "data"), buffer).Check();

Retrieving the data:
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Local<v8::Object> inputObj = input->ToObject(context).ToLocalChecked();
v8::Local<v8::Value> dataValue = inputObj->Get(context, v8::String::NewFromUtf8Literal(isolate, "data")).ToLocalChecked();

char* data = node::Buffer::Data(dataValue);

Unfortunately, this now results in an assertion trying to check that dataValue is an ArrayBufferView:
node[451684]: ../src/node_buffer.cc:243:char* node::Buffer::Data(v8::Local<v8::Value>): Assertion `val->IsArrayBufferView()' failed.
 1: 0xa25510 node::Abort() [node]
 2: 0xa2558e  [node]
 3: 0x9fd3fa node::Buffer::Data(v8::Local<v8::Value>) [node]
 4: 0x7fa42d0320ae  [/home/wlucas/CLionProjects/test.node]
 5: 0xc066ab  [node]
 6: 0xc07c56  [node]
 7: 0xc082d6 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
 8: 0x14269f9  [node]
Aborted (core dumped)

Is there some type of casting required now, or should I be using the BackingStore with Uint8Array now instead of Buffer?

Thanks for any advice!
Will




Will Lucas

unread,
Aug 20, 2021, 3:12:32 PM8/20/21
to v8-users
Scratch that, the issue was higher up in our SWIG layer. v8 is all good :D
Reply all
Reply to author
Forward
0 new messages