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

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

Issue 1767203002: [wasm] Allow Uint8Array in _WASMEXP_.instantiateModule() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = false; 10 var debug = false;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 module.addMemory(1, 1, false); 81 module.addMemory(1, 1, false);
82 module.addFunction("load", [kAstI32, kAstI32]) 82 module.addFunction("load", [kAstI32, kAstI32])
83 .addBody([kExprI32LoadMem, 0, kExprGetLocal, 0]) 83 .addBody([kExprI32LoadMem, 0, kExprGetLocal, 0])
84 .exportAs("load"); 84 .exportAs("load");
85 module.addDataSegment(0, [9, 9, 9, 9], true); 85 module.addDataSegment(0, [9, 9, 9, 9], true);
86 86
87 var buffer = module.toBuffer(debug); 87 var buffer = module.toBuffer(debug);
88 var instance = _WASMEXP_.instantiateModule(buffer); 88 var instance = _WASMEXP_.instantiateModule(buffer);
89 assertEquals(151587081, instance.exports.load(0)); 89 assertEquals(151587081, instance.exports.load(0));
90 })(); 90 })();
91
92
93 (function BasicTestWithUint8Array() {
94 var module = new WasmModuleBuilder();
95 module.addMemory(1, 2, false);
96 module.addFunction("foo", [kAstI32])
97 .addBody([kExprI8Const, 17])
98 .exportAs("blarg");
99
100 var buffer = module.toBuffer(debug);
101 var array = new Uint8Array(buffer);
102 var instance = _WASMEXP_.instantiateModule(array);
103 assertEquals(17, instance.exports.blarg());
104
105 var kPad = 5;
106 var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad);
107 var whole = new Uint8Array(buffer2);
108 for (var i = 0; i < whole.byteLength; i++) {
109 whole[i] = 0xff;
110 }
111 var array2 = new Uint8Array(buffer2, kPad, buffer.byteLength);
112 for (var i = 0; i < array2.byteLength; i++) {
113 array2[i] = array[i];
114 }
115 var instance = _WASMEXP_.instantiateModule(array2);
116 assertEquals(17, instance.exports.blarg());
117 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698