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

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

Issue 2595733003: [wasm] Remove non-standard kExprI8Const bytecode (Closed)
Patch Set: Remove regression test Created 3 years, 11 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 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([kExprI32Const, 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(kWasmI32)); 30 var index = builder.addImport("", "print", makeSig_v_x(kWasmI32));
31 builder.addFunction("foo", kSig_v_v) 31 builder.addFunction("foo", kSig_v_v)
32 .addBody([kExprI8Const, 13, kExprCallFunction, index]) 32 .addBody([kExprI32Const, 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();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 var buffer = builder.toBuffer(debug); 114 var buffer = builder.toBuffer(debug);
115 var instance = instantiate(buffer); 115 var instance = instantiate(buffer);
116 assertEquals(151587081, instance.exports.load(0)); 116 assertEquals(151587081, instance.exports.load(0));
117 })(); 117 })();
118 118
119 119
120 (function BasicTestWithUint8Array() { 120 (function BasicTestWithUint8Array() {
121 let builder = new WasmModuleBuilder(); 121 let builder = new WasmModuleBuilder();
122 builder.addMemory(1, 2, false); 122 builder.addMemory(1, 2, false);
123 builder.addFunction("foo", kSig_i_v) 123 builder.addFunction("foo", kSig_i_v)
124 .addBody([kExprI8Const, 17]) 124 .addBody([kExprI32Const, 17])
125 .exportAs("blarg"); 125 .exportAs("blarg");
126 126
127 var buffer = builder.toBuffer(debug); 127 var buffer = builder.toBuffer(debug);
128 var array = new Uint8Array(buffer); 128 var array = new Uint8Array(buffer);
129 var instance = instantiate(array); 129 var instance = instantiate(array);
130 assertEquals(17, instance.exports.blarg()); 130 assertEquals(17, instance.exports.blarg());
131 131
132 var kPad = 5; 132 var kPad = 5;
133 var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad); 133 var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad);
134 var whole = new Uint8Array(buffer2); 134 var whole = new Uint8Array(buffer2);
135 for (var i = 0; i < whole.byteLength; i++) { 135 for (var i = 0; i < whole.byteLength; i++) {
136 whole[i] = 0xff; 136 whole[i] = 0xff;
137 } 137 }
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.addImport("mod", "print", makeSig_v_x(kWasmI32)); 148 var index = builder.addImport("mod", "print", makeSig_v_x(kWasmI32));
149 builder.addFunction("foo", kSig_v_v) 149 builder.addFunction("foo", kSig_v_v)
150 .addBody([kExprI8Const, 19, kExprCallFunction, index]) 150 .addBody([kExprI32Const, 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

Powered by Google App Engine
This is Rietveld 408576698