summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/debugger/wasm-reset-context-group.js
blob: c1353da86b892835752cf2d5b407336d6d93fc47 (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
53
54
55
56
57
58
59
60
61
62
// Copyright 2018 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.

InspectorTest.log('Checks resetting context group with wasm.');

utils.load('test/mjsunit/wasm/wasm-module-builder.js');

var builder = new WasmModuleBuilder();

// wasm_B calls wasm_A <param0> times.
builder.addFunction('wasm_func', kSig_i_i)
    .addBody([
      // clang-format off
        kExprGetLocal, 0,
        kExprI32Const, 1,
        kExprI32Sub,
      // clang-format on
    ])
    .exportAs('main');


var module_bytes = builder.toArray();

function instantiate(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;
  }

  var module = new WebAssembly.Module(buffer);
  // Set global variable.
  instance = new WebAssembly.Instance(module);
}

var contextGroup1 = new InspectorTest.ContextGroup();
var session1 = contextGroup1.connect();
session1.setupScriptMap();

let contextGroup2 = new InspectorTest.ContextGroup();
let session2 = contextGroup2.connect();
session2.setupScriptMap();

(async function test() {
  await session1.Protocol.Debugger.enable();
  await session2.Protocol.Debugger.enable();

  session1.Protocol.Runtime.evaluate({
    expression: `var instance;(${instantiate.toString()})(${JSON.stringify(module_bytes)})`});

  session2.Protocol.Runtime.evaluate({
    expression: `var instance;(${instantiate.toString()})(${JSON.stringify(module_bytes)})`});

  contextGroup2.reset();

  await session1.Protocol.Debugger.onceScriptParsed(2);
  InspectorTest.logMessage(await session1.Protocol.Runtime.evaluate({expression: 'instance.exports.main(4)'}));
  InspectorTest.logMessage(await session2.Protocol.Runtime.evaluate({expression: 'instance.exports.main(5)'}));

  InspectorTest.completeTest();
})();