3b21b6d31d
In contrast to wasm modules, asm.js modules have an empty source URL. Thus loosen a DCHECK and handle the nullptr source_url correctly. Also add regression tests that check that we don't crash. Those can later be extended to check that the profile looks as expected; for now they only check that we terminate. R=bmeurer@chromium.org Bug: chromium:1185919 Change-Id: I6b879f540a2c3647920ad2970efcf7c94712d8c7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2745895 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#73313}
95 lines
2.8 KiB
JavaScript
95 lines
2.8 KiB
JavaScript
// Copyright 2021 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('Test console profiles for asm.js.');
|
|
|
|
function compile(bytes) {
|
|
let buffer = new ArrayBuffer(bytes.length);
|
|
let view = new Uint8Array(buffer);
|
|
for (var i = 0; i < bytes.length; i++) {
|
|
view[i] = bytes[i] | 0;
|
|
}
|
|
let module = new WebAssembly.Module(buffer);
|
|
let fib = undefined;
|
|
function imp(i) { return fib(i); }
|
|
let instance = new WebAssembly.Instance(module, {q: {f: imp}});
|
|
fib = instance.exports.fib;
|
|
return instance;
|
|
}
|
|
|
|
function checkError(message) {
|
|
if (!message.error) return;
|
|
InspectorTest.log('Error: ');
|
|
InspectorTest.logMessage(message);
|
|
InspectorTest.completeTest();
|
|
}
|
|
|
|
// When build asm.js modules, include a sentinel such that the module will not
|
|
// be reused from the cache.
|
|
let sentinel = 0;
|
|
|
|
function AsmModule(stdlib, foreign, heap) {
|
|
"use asm";
|
|
function f() {
|
|
return sentinel;
|
|
}
|
|
return {f: f};
|
|
}
|
|
|
|
async function compileAsmJs() {
|
|
InspectorTest.log(`Compiling asm.js module with sentinel ${sentinel}.`);
|
|
let code = AsmModule.toString().replace('sentinel', sentinel.toString());
|
|
++sentinel;
|
|
checkError(await Protocol.Runtime.evaluate({expression: `(${code})().f()`}));
|
|
}
|
|
|
|
async function testEnableProfilerEarly() {
|
|
InspectorTest.log(arguments.callee.name);
|
|
checkError(await Protocol.Profiler.enable());
|
|
checkError(await Protocol.Profiler.start());
|
|
await compileAsmJs();
|
|
checkError(await Protocol.Profiler.disable());
|
|
}
|
|
|
|
async function testEnableProfilerLate() {
|
|
InspectorTest.log(arguments.callee.name);
|
|
await compileAsmJs();
|
|
checkError(await Protocol.Profiler.enable());
|
|
checkError(await Protocol.Profiler.start());
|
|
checkError(await Protocol.Profiler.disable());
|
|
}
|
|
|
|
async function testEnableProfilerAfterDebugger() {
|
|
InspectorTest.log(arguments.callee.name);
|
|
checkError(await Protocol.Debugger.enable());
|
|
await compileAsmJs();
|
|
checkError(await Protocol.Profiler.enable());
|
|
checkError(await Protocol.Profiler.start());
|
|
checkError(await Protocol.Profiler.disable());
|
|
checkError(await Protocol.Debugger.disable());
|
|
}
|
|
|
|
async function testEnableProfilerBeforeDebugger() {
|
|
InspectorTest.log(arguments.callee.name);
|
|
await compileAsmJs();
|
|
await Protocol.Profiler.enable();
|
|
await Protocol.Debugger.enable();
|
|
checkError(await Protocol.Profiler.start());
|
|
await Protocol.Debugger.disable();
|
|
await Protocol.Profiler.disable();
|
|
}
|
|
|
|
(async function test() {
|
|
try {
|
|
await testEnableProfilerEarly();
|
|
await testEnableProfilerLate();
|
|
await testEnableProfilerAfterDebugger();
|
|
await testEnableProfilerBeforeDebugger();
|
|
} catch (e) {
|
|
InspectorTest.log('caught: ' + e);
|
|
}
|
|
})().catch(e => InspectorTest.log('caught: ' + e))
|
|
.finally(InspectorTest.completeTest);
|