12cdb31b2f
*and* report all "virtual" wasm scripts right when the wasm script is registered at the inspector. WasmScript is a subtype of Script, with the cast checking that it is actually a wasm script. This layout makes it quite easy to implement functionality that is only available for wasm scripts, and allows to later directly use the WasmCompiledModule instead of the i::Script for backing the debug::WasmScript. We might also add virtual methods to provide different implementations for GetSourcePosition, Source and others. DisassembleWasmFunction now also becomes a method of this class instead of a static function on the DebugInterface. The WasmTranslation now uses the new WasmScript type instead of the Script wrapper, and also registers all virtual wasm scripts immediately when the wasm script is made public to the inspector (when the wasm module is created). R=yangguo@chromium.org,dgozman@chromium.org,titzer@chromium.org BUG=chromium:613110,chromium:659715 Review-Url: https://codereview.chromium.org/2531163010 Cr-Commit-Position: refs/heads/master@{#41519}
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
// Copyright 2016 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.
|
|
|
|
// Flags: --expose-wasm
|
|
|
|
load('test/mjsunit/wasm/wasm-constants.js');
|
|
load('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
// Add two empty functions. Both should be registered as individual scripts at
|
|
// module creation time.
|
|
var builder = new WasmModuleBuilder();
|
|
builder.addFunction('nopFunction', kSig_v_v).addBody([kExprNop]);
|
|
builder.addFunction('main', kSig_v_v)
|
|
.addBody([kExprBlock, kAstStmt, kExprI32Const, 2, kExprDrop, kExprEnd])
|
|
.exportAs('main');
|
|
var module_bytes = builder.toArray();
|
|
|
|
function testFunction(bytes) {
|
|
var buffer = new ArrayBuffer(bytes.length);
|
|
var view = new Uint8Array(buffer);
|
|
for (var i = 0; i < bytes.length; i++) {
|
|
view[i] = bytes[i] | 0;
|
|
}
|
|
|
|
// Compilation triggers registration of wasm scripts.
|
|
new WebAssembly.Module(buffer);
|
|
}
|
|
|
|
InspectorTest.addScriptWithUrl(
|
|
testFunction.toString(), 'v8://test/testFunction');
|
|
InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes));
|
|
|
|
Protocol.Debugger.enable();
|
|
Protocol.Debugger.onScriptParsed(handleScriptParsed);
|
|
InspectorTest.log(
|
|
'Check that inspector gets two wasm scripts at module creation time.');
|
|
Protocol.Runtime
|
|
.evaluate({
|
|
'expression': '//# sourceURL=v8://test/runTestRunction\n' +
|
|
'testFunction(module_bytes)'
|
|
})
|
|
.then(checkFinished);
|
|
|
|
var num_scripts = 0;
|
|
var missing_sources = 0;
|
|
|
|
function checkFinished() {
|
|
if (missing_sources == 0)
|
|
InspectorTest.completeTest();
|
|
}
|
|
|
|
function handleScriptParsed(messageObject)
|
|
{
|
|
var url = messageObject.params.url;
|
|
InspectorTest.log("Script #" + num_scripts + " parsed. URL: " + url);
|
|
++num_scripts;
|
|
|
|
if (url.startsWith("wasm://")) {
|
|
++missing_sources;
|
|
function dumpScriptSource(message) {
|
|
InspectorTest.log("Source for " + url + ":");
|
|
InspectorTest.log(message.result.scriptSource);
|
|
--missing_sources;
|
|
}
|
|
|
|
Protocol.Debugger.getScriptSource({scriptId: messageObject.params.scriptId})
|
|
.then(dumpScriptSource.bind(null))
|
|
.then(checkFinished);
|
|
}
|
|
}
|