Skip to content

Commit

Permalink
src: remove calls to deprecated ArrayBuffer methods
Browse files Browse the repository at this point in the history
v8::ArrayBuffer::IsExternal and v8::ArrayBuffer::Externalize are
no longer necessary.

PR-URL: #32358
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
  • Loading branch information
targos committed Mar 21, 2020
1 parent 2061c33 commit d23eed2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
6 changes: 0 additions & 6 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2720,9 +2720,6 @@ napi_status napi_create_external_arraybuffer(napi_env env,
nullptr);
v8::Local<v8::ArrayBuffer> buffer =
v8::ArrayBuffer::New(isolate, std::move(backing));
// TODO(thangktran): drop this check when V8 is pumped to 8.0 .
if (!buffer->IsExternal())
buffer->Externalize(buffer->GetBackingStore());
v8::Maybe<bool> marked = env->mark_arraybuffer_as_untransferable(buffer);
CHECK_MAYBE_NOTHING(env, marked, napi_generic_failure);

Expand Down Expand Up @@ -3184,9 +3181,6 @@ napi_status napi_detach_arraybuffer(napi_env env, napi_value arraybuffer) {
env, value->IsArrayBuffer(), napi_arraybuffer_expected);

v8::Local<v8::ArrayBuffer> it = value.As<v8::ArrayBuffer>();
// TODO(addaleax): Remove the first condition once we have V8 8.0.
RETURN_STATUS_IF_FALSE(
env, it->IsExternal(), napi_detachable_arraybuffer_expected);
RETURN_STATUS_IF_FALSE(
env, it->IsDetachable(), napi_detachable_arraybuffer_expected);

Expand Down
6 changes: 0 additions & 6 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,6 @@ MaybeLocal<Object> New(Environment* env,
nullptr);
Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(),
std::move(backing));
// TODO(thangktran): drop this check when V8 is pumped to 8.0 .
if (!ab->IsExternal())
ab->Externalize(ab->GetBackingStore());
if (ab->SetPrivate(env->context(),
env->arraybuffer_untransferable_private_symbol(),
True(env->isolate())).IsNothing()) {
Expand Down Expand Up @@ -1212,9 +1209,6 @@ void Initialize(Local<Object> target,
nullptr);
Local<ArrayBuffer> array_buffer =
ArrayBuffer::New(env->isolate(), std::move(backing));
// TODO(thangktran): drop this check when V8 is pumped to 8.0 .
if (!array_buffer->IsExternal())
array_buffer->Externalize(array_buffer->GetBackingStore());
array_buffer->SetPrivate(
env->context(),
env->arraybuffer_untransferable_private_symbol(),
Expand Down
3 changes: 0 additions & 3 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ Maybe<bool> Message::Serialize(Environment* env,
for (Local<ArrayBuffer> ab : array_buffers) {
// If serialization succeeded, we render it inaccessible in this Isolate.
std::shared_ptr<BackingStore> backing_store = ab->GetBackingStore();
// TODO(addaleax): This can/should be dropped once we have V8 8.0.
if (!ab->IsExternal())
ab->Externalize(backing_store);
ab->Detach();

array_buffers_.emplace_back(std::move(backing_store));
Expand Down
8 changes: 5 additions & 3 deletions test/js-native-api/test_typedarray/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ nonByteArrayTypes.forEach((currentType) => {
// Test detaching
arrayTypes.forEach((currentType) => {
const buffer = Reflect.construct(currentType, [8]);
assert.throws(
() => test_typedarray.Detach(buffer),
/A detachable arraybuffer was expected/);
assert.strictEqual(buffer.length, 8);
assert.ok(!test_typedarray.IsDetached(buffer.buffer));
test_typedarray.Detach(buffer);
assert.ok(test_typedarray.IsDetached(buffer.buffer));
assert.strictEqual(buffer.length, 0);
});
{
const buffer = test_typedarray.External();
Expand Down

0 comments on commit d23eed2

Please sign in to comment.