Commit b886e153 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[inspector] Add internal property to identify detached ArrayBuffers.

This adds an internal property [[IsDetached]] to the inspector preview
of ArrayBuffer instances, which indicates whether the ArrayBuffer was
detached (i.e. transfered via `postMessage`). Previously it was rather
impossible to tell whether an ArrayBuffer was detached, you had to know
that V8 violates the ECMAScript specification and simply sets the
byteLength accessor to 0 upon detaching an ArrayBuffer (but even then it
was still impossible to tell whether that ArrayBuffer wasn't simply an
empty one from the get go).

Before: https://imgur.com/UcOF83c
After: https://imgur.com/WjmTehZ

Fixed: chromium:1109102
Change-Id: I8fb6e2be2fbfe5c62b05dc9d2a0f18378eb4de6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2316075
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69034}
parent 734c34e5
......@@ -304,6 +304,15 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
result->set(0, *primitive_value);
result->set(1, js_value->value());
return factory->NewJSArrayWithElements(result);
} else if (object->IsJSArrayBuffer()) {
Handle<JSArrayBuffer> js_array_buffer = Handle<JSArrayBuffer>::cast(object);
Handle<FixedArray> result = factory->NewFixedArray(1 * 2);
Handle<String> is_detached_str =
factory->NewStringFromAsciiChecked("[[IsDetached]]");
result->set(0, *is_detached_str);
result->set(1, isolate->heap()->ToBoolean(js_array_buffer->was_detached()));
return factory->NewJSArrayWithElements(result);
}
return factory->NewJSArray(0);
}
......
......@@ -87,3 +87,5 @@ Running test: testArrayBufferWithBrokenUintCtor
[[Int8Array]] own object undefined
[[Uint8Array]] own object undefined
__proto__ own object undefined
Internal properties
[[IsDetached]] boolean false
......@@ -102,6 +102,7 @@ Running test: testArrayBuffer
0 own number 16843009
1 own number 16843009
__proto__ own object undefined
[[IsDetached]] false
Running test: testDetachedArrayBuffer
[[Int8Array]]
......@@ -112,8 +113,11 @@ Running test: testDetachedArrayBuffer
__proto__ own object undefined
[[Int32Array]]
__proto__ own object undefined
[[IsDetached]] true
Running test: testArrayBufferWithBrokenUintCtor
[[Int8Array]] own object undefined
[[Uint8Array]] own object undefined
__proto__ own object undefined
Internal properties
[[IsDetached]] boolean false
......@@ -50,6 +50,9 @@ InspectorTest.runAsyncTestSuite([
InspectorTest.log(prop.name);
await logGetPropertiesResult(prop.value.objectId);
}
for (let prop of props.result.internalProperties) {
InspectorTest.log(prop.name + ' ' + prop.value.value);
}
},
async function testDetachedArrayBuffer() {
......@@ -65,6 +68,9 @@ InspectorTest.runAsyncTestSuite([
InspectorTest.log(prop.name);
await logGetPropertiesResult(prop.value.objectId);
}
for (let prop of props.result.internalProperties) {
InspectorTest.log(prop.name + ' ' + prop.value.value);
}
},
async function testArrayBufferWithBrokenUintCtor() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment