Commit 6d08c94c authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm][debug] Provide WebAssembly Table entries to DevTools

With this CL, V8 adds an internal field to the WebAssembly Table object
that is sent to DevTools to also show table entries. As WebAssembly
Tables get initialized lazily, V8 only shows the name of the function
instead of the function object itself.

Screenshot before change: https://imgur.com/a/XFvy3lA
Screenshot after change: https://imgur.com/kT84kst
R=kimanh@chromium.org

Change-Id: I56a0b07785ff3484f1447419fe39ae5ec3f93247
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2897097Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarKim-Anh Tran <kimanh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74690}
parent e90c366b
......@@ -1113,5 +1113,24 @@ Handle<ArrayList> AddWasmModuleObjectInternalProperties(
return result;
}
Handle<ArrayList> AddWasmTableObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result, Handle<WasmTableObject> table) {
int length = table->current_length();
Handle<FixedArray> entries = isolate->factory()->NewFixedArray(length);
for (int i = 0; i < length; ++i) {
entries->set(i, *WasmTableObject::Get(isolate, table, i));
}
Handle<JSArray> final_entries = isolate->factory()->NewJSArrayWithElements(
entries, i::PACKED_ELEMENTS, length);
JSObject::SetPrototype(final_entries, isolate->factory()->null_value(), false,
kDontThrow)
.Check();
result = ArrayList::Add(
isolate, result,
isolate->factory()->NewStringFromStaticChars("[[Entries]]"),
final_entries);
return result;
}
} // namespace internal
} // namespace v8
......@@ -32,6 +32,7 @@ class ArrayList;
class WasmFrame;
class WasmInstanceObject;
class WasmModuleObject;
class WasmTableObject;
class WasmValueObject : public JSObject {
public:
......@@ -76,10 +77,14 @@ Handle<String> GetWasmFunctionDebugName(Isolate* isolate,
Handle<ArrayList> AddWasmInstanceObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result,
Handle<WasmInstanceObject> instance);
Handle<ArrayList> AddWasmModuleObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result,
Handle<WasmModuleObject> module_object);
Handle<ArrayList> AddWasmTableObjectInternalProperties(
Isolate* isolate, Handle<ArrayList> result, Handle<WasmTableObject> table);
} // namespace internal
} // namespace v8
......
......@@ -359,6 +359,9 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
} else if (object->IsWasmModuleObject()) {
result = AddWasmModuleObjectInternalProperties(
isolate, result, Handle<WasmModuleObject>::cast(object));
} else if (object->IsWasmTableObject()) {
result = AddWasmTableObjectInternalProperties(
isolate, result, Handle<WasmTableObject>::cast(object));
#endif // V8_ENABLE_WEBASSEMBLY
}
return isolate->factory()->NewJSArrayWithElements(
......
......@@ -87,6 +87,7 @@ async function getScopeValues(name, value) {
return value.description;
if (name === 'instance') return dumpInstanceProperties(value);
if (name === 'module') return value.description;
if (name === 'tables') return dumpTables(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printIfFailure(msg);
......@@ -137,3 +138,26 @@ async function dumpInstanceProperties(instanceObj) {
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
async function dumpTables(tablesObj) {
let msg =
await Protocol.Runtime.getProperties({objectId: tablesObj.objectId});
let tables_str = [];
for (let table of msg.result.result) {
let table_content =
await Protocol.Runtime.getProperties({objectId: table.value.objectId});
let entries_object = table_content.result.internalProperties.filter(
p => p.name === '[[Entries]]')[0];
entries = await Protocol.Runtime.getProperties(
{objectId: entries_object.value.objectId});
let functions = [];
for (let entry of entries.result.result) {
if (entry.name === 'length') continue;
functions.push(`${entry.name}: ${entry.value.description}`);
}
const functions_str = functions.join(', ');
tables_str.push(` ${table.name}: ${functions_str}`);
}
return '\n' + tables_str.join('\n');
}
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