forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger_basic.js
More file actions
130 lines (124 loc) · 3.16 KB
/
debugger_basic.js
File metadata and controls
130 lines (124 loc) · 3.16 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
const realPrint = print;
WScript.Echo = print = console.log = () => {};
if (WScript.Arguments.indexOf("--verbose") !== -1) {
WScript.Echo = print = console.log = realPrint;
}
let isAttached = WScript.Arguments.indexOf("debuglaunch") !== -1;
function attach() {
if (isAttached) return Promise.resolve();
return new Promise(r => WScript.Attach(() => {
isAttached = true;
print("attached");
r();
}));
}
function detach() {
if (!isAttached) return Promise.resolve();
return new Promise(r => WScript.Detach(() => {
isAttached = false;
print("detached");
r();
}));
}
const buf = WebAssembly.wabt.convertWast2Wasm(`(module
(import "test" "mem" (memory 1))
(import "test" "table" (table 15 anyfunc))
(import "test" "foo" (func $foo (param i32)))
(func (export "a") (param i32)
(call $foo (get_local 0))
)
(func $b (export "b") (param i32)
(call $foo (get_local 0))
)
(func $c (export "c") (param i32)
(call $d (get_local 0))
)
(func $d (param i32)
(call $b (get_local 0))
)
)`);
function makeInstance(foo) {
const mem = new WebAssembly.Memory({initial: 1});
const table = new WebAssembly.Table({initial: 15, element: "anyfunc"});
const module = new WebAssembly.Module(buf);
const instance = new WebAssembly.Instance(module, {test: {mem, table, foo}});
debugger;
return instance;
}
const {exports: {a, b, c}} = makeInstance(val => {
print(val);
// causes exception
return val.b.c;
});
let id = 0;
function runTest(fn) {
print(fn.name);
fn(id++|0);
}
function caught(e) {
if (!(e instanceof TypeError)) {
realPrint(`Unexpected error: ${e.stack}`);
}
}
function runA() {
debugger;
try {runTest(a);} catch (e) {caught(e);}
}
function runB() {
try {runTest(b);} catch (e) {caught(e);}
}
function runC() {
try {runTest(c);} catch (e) {caught(e);}
}
// preparse b
runB();
attach()
.then(runA)
.then(detach)
.then(runA)
.then(attach)
.then(runB)
.then(detach)
.then(runB)
.then(() => {
let p = Promise.resolve();
for (let i = 0; i < 20; ++i) {
p = p
.then(attach)
.then(runB)
.then(detach);
if (i % 4 < 2) {
p = p.then(runB);
}
}
return p;
})
.then(() => {
for (let i = 0; i < 20; ++i) {
runC();
}
})
.then(attach)
.then(() => {
for (let i = 0; i < 20; ++i) {
runC();
}
})
.then(() => {
let testValue = 0;
const {exports: {c: newC}} = makeInstance(val => {
debugger;
testValue = val;
});
debugger;
newC(15);
if (testValue !== 15) {
realPrint("Invalid assignment through import under debugger");
}
})
.then(detach)
.then(() => realPrint("PASSED"), realPrint);