Commit 82bb7c93 authored by Eric Leese's avatar Eric Leese Committed by Commit Bot

Add internal properties [[ArrayBufferData]] and [[ArrayBufferByteLength]]

New internal properties expose the byte length of an ArrayBuffer as well
as the pointer to the backing store, which will serve as a unique ID
to show when SharedArrayBuffers in different workers are the same buffer.

Bug: chromium:1163800
Change-Id: I49930765cb38f75ba5c6cee5a0a6827f4fec42d5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2618242
Commit-Queue: Eric Leese <leese@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72000}
parent 85b1d24b
......@@ -324,7 +324,8 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
kExternalInt16Array,
kExternalInt32Array,
};
Handle<FixedArray> result = factory->NewFixedArray(arraysize(kTypes) * 2);
Handle<FixedArray> result =
factory->NewFixedArray((2 + arraysize(kTypes)) * 2);
int index = 0;
for (auto type : kTypes) {
switch (type) {
......@@ -346,6 +347,23 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
UNREACHABLE();
}
}
Handle<String> byte_length_str =
factory->NewStringFromAsciiChecked("[[ArrayBufferByteLength]]");
result->set(index++, *byte_length_str);
Handle<Object> byte_length_obj = factory->NewNumberFromSize(byte_length);
result->set(index++, *byte_length_obj);
Handle<String> buffer_data_str =
factory->NewStringFromAsciiChecked("[[ArrayBufferData]]");
result->set(index++, *buffer_data_str);
// Use the backing store pointer as a unique ID
EmbeddedVector<char, 32> buffer_data_vec;
int len =
SNPrintF(buffer_data_vec, V8PRIxPTR_FMT,
reinterpret_cast<Address>(js_array_buffer->backing_store()));
Handle<String> buffer_id =
factory->InternalizeUtf8String(buffer_data_vec.SubVector(0, len));
result->set(index++, *buffer_id);
return factory->NewJSArrayWithElements(result, PACKED_ELEMENTS, index);
} else if (object->IsWasmModuleObject()) {
auto module_object = Handle<WasmModuleObject>::cast(object);
......
......@@ -56,5 +56,7 @@ Running test: testArrayBuffer
Running test: testArrayBufferWithBrokenUintCtor
__proto__ own object undefined
Internal properties
[[ArrayBufferByteLength]] number 7
[[ArrayBufferData]] string 0x...
[[Int8Array]] object undefined
[[Uint8Array]] object undefined
......@@ -98,7 +98,11 @@ let { Protocol } = InspectorTest.start('Checks Runtime.getProperties method whil
for (var i = 0; i < internalPropertyArray.length; i++) {
var p = internalPropertyArray[i];
var v = p.value;
InspectorTest.log(` ${p.name} ${v.type} ${v.value}`);
if (p.name === "[[ArrayBufferData]]")
// Hex value for pointer is non-deterministic
InspectorTest.log(` ${p.name} ${v.type} ${v.value.substr(0, 2)}...`);
else
InspectorTest.log(` ${p.name} ${v.type} ${v.value}`);
}
}
......
......@@ -102,6 +102,8 @@ Running test: testArrayBuffer
0 own number 16843009
1 own number 16843009
__proto__ own object undefined
[[ArrayBufferByteLength]]
[[ArrayBufferData]]
Running test: testDetachedArrayBuffer
[[IsDetached]] true
......@@ -109,5 +111,7 @@ Running test: testDetachedArrayBuffer
Running test: testArrayBufferWithBrokenUintCtor
__proto__ own object undefined
Internal properties
[[ArrayBufferByteLength]] number 7
[[ArrayBufferData]] string 0x...
[[Int8Array]] object undefined
[[Uint8Array]] object undefined
......@@ -52,7 +52,8 @@ InspectorTest.runAsyncTestSuite([
}
for (let prop of props.result.internalProperties) {
InspectorTest.log(prop.name);
await logGetPropertiesResult(prop.value.objectId);
if (prop.value.objectId)
await logGetPropertiesResult(prop.value.objectId);
}
},
......@@ -112,7 +113,7 @@ async function logGetPropertiesResult(objectId, flags = { ownProperties: true })
var v = p.value;
var own = p.isOwn ? "own" : "inherited";
if (v)
InspectorTest.log(" " + p.name + " " + own + " " + v.type + " " + v.value);
InspectorTest.log(` ${p.name} ${own} ${v.type} ${v.value}`);
else
InspectorTest.log(" " + p.name + " " + own + " no value" +
(hasGetterSetter(p, "get") ? ", getter" : "") + (hasGetterSetter(p, "set") ? ", setter" : ""));
......@@ -125,7 +126,11 @@ async function logGetPropertiesResult(objectId, flags = { ownProperties: true })
for (var i = 0; i < array.length; i++) {
var p = array[i];
var v = p.value;
InspectorTest.log(' ' + p.name + ' ' + v.type + ' ' + v.value);
if (p.name == "[[ArrayBufferData]]")
// Hex value for pointer is non-deterministic
InspectorTest.log(` ${p.name} ${v.type} ${v.value.substr(0, 2)}...`);
else
InspectorTest.log(` ${p.name} ${v.type} ${v.value}`);
}
}
......
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