forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.js
More file actions
102 lines (96 loc) · 2.33 KB
/
debugger.js
File metadata and controls
102 lines (96 loc) · 2.33 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
//-------------------------------------------------------------------------------------------------------
// 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("-v") !== -1) {
WScript.Echo = print = console.log = realPrint;
}
function attach() {
return new Promise(r => WScript.Attach(() => {
print("attached");
r();
}));
}
function detach() {
return new Promise(r => WScript.Detach(() => {
print("detached");
r();
}));
}
const buf = readbuffer("debugger.wasm");
const {exports: {a, b, c}} = new WebAssembly.Instance(new WebAssembly.Module(buf), {test: {
foo: function(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() {
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}} = new WebAssembly.Instance(new WebAssembly.Module(buf), {test: {
foo: function(val) {
testValue = val;
}
}});
newC(15);
if (testValue !== 15) {
realPrint("Invalid assignment through import under debugger");
}
})
.then(detach)
.then(() => realPrint("PASSED"), realPrint);