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

Side by Side Diff: test/mjsunit/wasm/test-wasm-module-builder.js

Issue 2591753002: [wasm] Implement correct 2-level namespace for imports. (Closed)
Patch Set: Fix debug tests Created 4 years 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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 // Flags: --expose-wasm 5 // Flags: --expose-wasm
6 6
7 load('test/mjsunit/wasm/wasm-constants.js'); 7 load('test/mjsunit/wasm/wasm-constants.js');
8 load('test/mjsunit/wasm/wasm-module-builder.js'); 8 load('test/mjsunit/wasm/wasm-module-builder.js');
9 9
10 var debug = true; 10 var debug = true;
11 11
12 function instantiate(buffer, ffi) { 12 function instantiate(buffer, ffi) {
13 return new WebAssembly.Instance(WebAssembly.Module(buffer), ffi); 13 return new WebAssembly.Instance(WebAssembly.Module(buffer), ffi);
14 } 14 }
15 15
16 (function BasicTest() { 16 (function BasicTest() {
17 let builder = new WasmModuleBuilder(); 17 let builder = new WasmModuleBuilder();
18 builder.addMemory(1, 2, false); 18 builder.addMemory(1, 2, false);
19 builder.addFunction("foo", kSig_i_v) 19 builder.addFunction("foo", kSig_i_v)
20 .addBody([kExprI8Const, 11]) 20 .addBody([kExprI8Const, 11])
21 .exportAs("blarg"); 21 .exportAs("blarg");
22 22
23 var buffer = builder.toBuffer(debug); 23 var buffer = builder.toBuffer(debug);
24 var instance = instantiate(buffer); 24 var instance = instantiate(buffer);
25 assertEquals(11, instance.exports.blarg()); 25 assertEquals(11, instance.exports.blarg());
26 })(); 26 })();
27 27
28 (function ImportTest() { 28 (function ImportTest() {
29 let builder = new WasmModuleBuilder(); 29 let builder = new WasmModuleBuilder();
30 var index = builder.addImport("print", makeSig_v_x(kAstI32)); 30 var index = builder.addImport("", "print", makeSig_v_x(kAstI32));
31 builder.addFunction("foo", kSig_v_v) 31 builder.addFunction("foo", kSig_v_v)
32 .addBody([kExprI8Const, 13, kExprCallFunction, index]) 32 .addBody([kExprI8Const, 13, kExprCallFunction, index])
33 .exportAs("main"); 33 .exportAs("main");
34 34
35 var buffer = builder.toBuffer(debug); 35 var buffer = builder.toBuffer(debug);
36 var instance = instantiate(buffer, {print: print}); 36 var instance = instantiate(buffer, {"": {print: print}});
37 print("should print 13! "); 37 print("should print 13! ");
38 instance.exports.main(); 38 instance.exports.main();
39 })(); 39 })();
40 40
41 (function LocalsTest() { 41 (function LocalsTest() {
42 let builder = new WasmModuleBuilder(); 42 let builder = new WasmModuleBuilder();
43 builder.addFunction(undefined, kSig_i_i) 43 builder.addFunction(undefined, kSig_i_i)
44 .addLocals({i32_count: 1}) 44 .addLocals({i32_count: 1})
45 .addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1]) 45 .addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
46 .exportAs("main"); 46 .exportAs("main");
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 var array2 = new Uint8Array(buffer2, kPad, buffer.byteLength); 138 var array2 = new Uint8Array(buffer2, kPad, buffer.byteLength);
139 for (var i = 0; i < array2.byteLength; i++) { 139 for (var i = 0; i < array2.byteLength; i++) {
140 array2[i] = array[i]; 140 array2[i] = array[i];
141 } 141 }
142 var instance = instantiate(array2); 142 var instance = instantiate(array2);
143 assertEquals(17, instance.exports.blarg()); 143 assertEquals(17, instance.exports.blarg());
144 })(); 144 })();
145 145
146 (function ImportTestTwoLevel() { 146 (function ImportTestTwoLevel() {
147 let builder = new WasmModuleBuilder(); 147 let builder = new WasmModuleBuilder();
148 var index = builder.addImportWithModule("mod", "print", makeSig_v_x(kAstI32) ); 148 var index = builder.addImport("mod", "print", makeSig_v_x(kAstI32));
149 builder.addFunction("foo", kSig_v_v) 149 builder.addFunction("foo", kSig_v_v)
150 .addBody([kExprI8Const, 19, kExprCallFunction, index]) 150 .addBody([kExprI8Const, 19, kExprCallFunction, index])
151 .exportAs("main"); 151 .exportAs("main");
152 152
153 var buffer = builder.toBuffer(debug); 153 var buffer = builder.toBuffer(debug);
154 var instance = instantiate(buffer, {mod: {print: print}}); 154 var instance = instantiate(buffer, {mod: {print: print}});
155 print("should print 19! "); 155 print("should print 19! ");
156 instance.exports.main(); 156 instance.exports.main();
157 })(); 157 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/test-import-export-wrapper.js ('k') | test/mjsunit/wasm/unicode-validation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698