Commit 1dcaea82 authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

[wasm] Adopt compatible naming for functions

We want to be consistent with wasdk/wasmparser.

Unnamed function's name would be func#

Doc: https://docs.google.com/document/d/1XoXWONLBgZWQ9dhtoMpQPvD0fnnWA50OorsuSXfME3g
Bug: v8:10242
Change-Id: I12222eef38a57242e9f606007d0ffa76b8e2a4af
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2084052
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarKim-Anh Tran <kimanh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66667}
parent 126f1ee1
......@@ -256,7 +256,8 @@ Handle<String> WasmModuleObject::GetFunctionName(
GetFunctionNameOrNull(isolate, module_object, func_index);
if (!name.is_null()) return name.ToHandleChecked();
EmbeddedVector<char, 32> buffer;
int length = SNPrintF(buffer, "wasm-function[%u]", func_index);
DCHECK_GE(func_index, module_object->module()->num_imported_functions);
int length = SNPrintF(buffer, "func%u", func_index);
return isolate->factory()
->NewStringFromOneByte(Vector<uint8_t>::cast(buffer.SubVector(0, length)))
.ToHandleChecked();
......
......@@ -170,7 +170,7 @@ class WasmModuleObject : public JSObject {
uint32_t func_index);
// Get the function name of the function identified by the given index.
// Returns "wasm-function[func_index]" if the function is unnamed or the
// Returns "func[func_index]" if the function is unnamed or the
// name is not a valid UTF-8 string.
static Handle<String> GetFunctionName(Isolate*, Handle<WasmModuleObject>,
uint32_t func_index);
......
Tests unnamed function in wasm scripts
Running testFunction with generated wasm bytes...
Paused on 'debugger;'
Number of frames: 5
- [0] call_debugger
- [1] func1
- [2] func2
- [3] testFunction
- [4]
Finished!
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} =
InspectorTest.start('Tests unnamed function in wasm scripts');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var imported_idx = builder.addImport('mode', 'import_func', kSig_v_v);
// Unnamed non export function.
var function_idx = builder.addFunction(undefined, kSig_v_v)
.addBody([kExprCallFunction, imported_idx])
.index;
// Unnamed export function.
builder.addFunction(undefined, kSig_v_v)
.addBody([kExprCallFunction, function_idx])
.exportAs('main');
var module_bytes = builder.toArray();
function testFunction(bytes) {
function call_debugger() {
debugger;
}
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; i++) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
var instance =
new WebAssembly.Instance(module, {mode: {import_func: call_debugger}});
instance.exports.main();
}
contextGroup.addScript(testFunction.toString());
(async function test() {
await Protocol.Debugger.enable();
Protocol.Debugger.onPaused(handleDebuggerPaused);
InspectorTest.log('Running testFunction with generated wasm bytes...');
await Protocol.Runtime.evaluate(
{'expression': 'testFunction(' + JSON.stringify(module_bytes) + ')'});
InspectorTest.log('Finished!');
InspectorTest.completeTest();
})();
function logStackTrace(messageObject) {
var frames = messageObject.params.callFrames;
InspectorTest.log('Number of frames: ' + frames.length);
for (var i = 0; i < frames.length; ++i) {
InspectorTest.log(' - [' + i + '] ' + frames[i].functionName);
}
}
function handleDebuggerPaused(messageObject) {
InspectorTest.log('Paused on \'debugger;\'');
logStackTrace(messageObject);
Protocol.Debugger.resume();
}
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