summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm/enter-debug-state.js
blob: 3b184ebc41dc27dbc977de85ac3d56dea43503d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2019 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: --allow-natives-syntax

d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');

const num_functions = 200;

function create_builder(delta = 0) {
  const builder = new WasmModuleBuilder();
  for (let i = 0; i < num_functions; ++i) {
    builder.addFunction('f' + i, kSig_i_v)
        .addBody(wasmI32Const(i + delta))
        .exportFunc();
  }
  return builder;
}

function checkForDebugCode(instance) {
  for (let i = 0; i < num_functions; ++i) {
    // Call the function once because of lazy compilation.
    instance.exports['f' + i]();
    assertTrue(%IsWasmDebugFunction(instance.exports['f' + i]));
  }
}

function check(instance) {
  %WasmEnterDebugging();
  checkForDebugCode(instance);

  for (let i = 0; i < num_functions; ++i) {
    %WasmTierUpFunction(instance.exports['f' + i]);
  }
  checkForDebugCode(instance);
}

(function testTierDownToLiftoff() {
  print(arguments.callee.name);
  const instance = create_builder().instantiate();
  check(instance);
})();

// Use slightly different module for this test to avoid sharing native module.
async function testTierDownToLiftoffAsync() {
  print(arguments.callee.name);
  const instance = await create_builder(num_functions).asyncInstantiate();
  check(instance);
}

assertPromiseResult(testTierDownToLiftoffAsync());