Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/inspector/debugger/wasm-imports.js

Issue 2891213002: [inspector] Refactor protocol-test.js (Closed)
Patch Set: comments addressed Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 let {session, contextGroup, Protocol} = InspectorTest.start('Tests imports in wa sm');
6
5 utils.load('test/mjsunit/wasm/wasm-constants.js'); 7 utils.load('test/mjsunit/wasm/wasm-constants.js');
6 utils.load('test/mjsunit/wasm/wasm-module-builder.js'); 8 utils.load('test/mjsunit/wasm/wasm-module-builder.js');
7 9
8 // Build two modules A and B. A defines function func, which contains a 10 // Build two modules A and B. A defines function func, which contains a
9 // breakpoint. This function is then imported by B and called via main. The 11 // breakpoint. This function is then imported by B and called via main. The
10 // breakpoint must be hit. 12 // breakpoint must be hit.
11 // This failed before (http://crbug.com/v8/5971). 13 // This failed before (http://crbug.com/v8/5971).
12 14
13 var builder_a = new WasmModuleBuilder(); 15 var builder_a = new WasmModuleBuilder();
14 var func_idx = builder_a.addFunction('func', kSig_v_v) 16 var func_idx = builder_a.addFunction('func', kSig_v_v)
(...skipping 17 matching lines...) Expand all
32 } 34 }
33 35
34 var module = new WebAssembly.Module(buffer); 36 var module = new WebAssembly.Module(buffer);
35 // Add to global instances array. 37 // Add to global instances array.
36 instances.push(new WebAssembly.Instance(module, imp)); 38 instances.push(new WebAssembly.Instance(module, imp));
37 } 39 }
38 40
39 var evalWithUrl = (code, url) => Protocol.Runtime.evaluate( 41 var evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
40 {'expression': code + '\n//# sourceURL=v8://test/' + url}); 42 {'expression': code + '\n//# sourceURL=v8://test/' + url});
41 43
42 InspectorTest.setupScriptMap(); 44 session.setupScriptMap();
43 45
44 // Main promise chain: 46 // Main promise chain:
45 Protocol.Debugger.enable() 47 Protocol.Debugger.enable()
46 .then(() => InspectorTest.log('Installing code and global variable.')) 48 .then(() => InspectorTest.log('Installing code and global variable.'))
47 .then( 49 .then(
48 () => evalWithUrl( 50 () => evalWithUrl(
49 'var instances = [];\n' + instantiate.toString(), 'setup')) 51 'var instances = [];\n' + instantiate.toString(), 'setup'))
50 .then(() => InspectorTest.log('Calling instantiate function for module A.')) 52 .then(() => InspectorTest.log('Calling instantiate function for module A.'))
51 .then( 53 .then(
52 () => 54 () =>
53 (evalWithUrl( 55 (evalWithUrl(
54 'instantiate(' + JSON.stringify(module_a_bytes) + ')', 56 'instantiate(' + JSON.stringify(module_a_bytes) + ')',
55 'instantiateA'), 57 'instantiateA'),
56 0)) 58 0))
57 .then(() => InspectorTest.log('Waiting for wasm script to be parsed.')) 59 .then(() => InspectorTest.log('Waiting for wasm script to be parsed.'))
58 .then(waitForWasmScript) 60 .then(waitForWasmScript)
59 .then(url => (InspectorTest.log('Setting breakpoint in line 1:'), url)) 61 .then(url => (InspectorTest.log('Setting breakpoint in line 1:'), url))
60 .then( 62 .then(
61 url => 63 url =>
62 Protocol.Debugger.setBreakpointByUrl({lineNumber: 1, url: url})) 64 Protocol.Debugger.setBreakpointByUrl({lineNumber: 1, url: url}))
63 .then(printFailure) 65 .then(printFailure)
64 .then(msg => InspectorTest.logSourceLocations(msg.result.locations)) 66 .then(msg => session.logSourceLocations(msg.result.locations))
65 .then(() => InspectorTest.log('Calling instantiate function for module B.')) 67 .then(() => InspectorTest.log('Calling instantiate function for module B.'))
66 .then( 68 .then(
67 () => 69 () =>
68 (evalWithUrl( 70 (evalWithUrl(
69 'instantiate(' + JSON.stringify(module_b_bytes) + 71 'instantiate(' + JSON.stringify(module_b_bytes) +
70 ', {imp: {f: instances[0].exports.func}})', 72 ', {imp: {f: instances[0].exports.func}})',
71 'instantiateB'), 73 'instantiateB'),
72 0)) 74 0))
73 .then(() => InspectorTest.log('Calling main function on module B.')) 75 .then(() => InspectorTest.log('Calling main function on module B.'))
74 .then(() => evalWithUrl('instances[1].exports.main()', 'runWasm')) 76 .then(() => evalWithUrl('instances[1].exports.main()', 'runWasm'))
75 .then(() => InspectorTest.log('exports.main returned.')) 77 .then(() => InspectorTest.log('exports.main returned.'))
76 .then(() => InspectorTest.log('Finished.')) 78 .then(() => InspectorTest.log('Finished.'))
77 .then(InspectorTest.completeTest); 79 .then(InspectorTest.completeTest);
78 80
79 // Separate promise chain for the asynchronous pause: 81 // Separate promise chain for the asynchronous pause:
80 Protocol.Debugger.oncePaused() 82 Protocol.Debugger.oncePaused()
81 .then(msg => msg.params.callFrames[0].location) 83 .then(msg => msg.params.callFrames[0].location)
82 .then( 84 .then(
83 loc => 85 loc =>
84 (InspectorTest.log( 86 (InspectorTest.log(
85 'Paused at ' + loc.lineNumber + ':' + loc.columnNumber + '.'), 87 'Paused at ' + loc.lineNumber + ':' + loc.columnNumber + '.'),
86 loc)) 88 loc))
87 .then(InspectorTest.logSourceLocation) 89 .then(session.logSourceLocation.bind(session))
88 .then( 90 .then(
89 () => InspectorTest.log( 91 () => InspectorTest.log(
90 'Getting current stack trace via "new Error().stack".')) 92 'Getting current stack trace via "new Error().stack".'))
91 .then(() => evalWithUrl('new Error().stack', 'getStack')) 93 .then(() => evalWithUrl('new Error().stack', 'getStack'))
92 .then(msg => InspectorTest.log(msg.result.result.value)) 94 .then(msg => InspectorTest.log(msg.result.result.value))
93 .then(Protocol.Debugger.resume); 95 .then(Protocol.Debugger.resume);
94 96
95 function printFailure(message) { 97 function printFailure(message) {
96 if (!message.result) { 98 if (!message.result) {
97 InspectorTest.logMessage(message); 99 InspectorTest.logMessage(message);
98 } 100 }
99 return message; 101 return message;
100 } 102 }
101 103
102 function waitForWasmScript(msg) { 104 function waitForWasmScript(msg) {
103 if (!msg || !msg.params.url.startsWith('wasm://')) { 105 if (!msg || !msg.params.url.startsWith('wasm://')) {
104 return Protocol.Debugger.onceScriptParsed().then(waitForWasmScript); 106 return Protocol.Debugger.onceScriptParsed().then(waitForWasmScript);
105 } 107 }
106 InspectorTest.log('Got wasm script!'); 108 InspectorTest.log('Got wasm script!');
107 return Promise.resolve(msg.params.url); 109 return Promise.resolve(msg.params.url);
108 } 110 }
OLDNEW
« no previous file with comments | « test/inspector/debugger/wasm-get-breakable-locations-expected.txt ('k') | test/inspector/debugger/wasm-imports-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698