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

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

Issue 2084573002: Upgrade Wasm JS API, step 1 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Separate test refactorings Created 4 years, 6 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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 kReturnValue = 117; 10 let kReturnValue = 117;
11 11
12 var module = (function Build() { 12 let buffer = (() => {
13 var builder = new WasmModuleBuilder(); 13 let builder = new WasmModuleBuilder();
14
15 builder.addMemory(1, 1, true); 14 builder.addMemory(1, 1, true);
16 builder.addFunction("main", kSig_i) 15 builder.addFunction("main", kSig_i)
17 .addBody([kExprI8Const, kReturnValue]) 16 .addBody([kExprI8Const, kReturnValue])
18 .exportFunc(); 17 .exportFunc();
19 18
20 return builder.instantiate(); 19 return builder.toBuffer();
21 })(); 20 })()
22 21
23 // Check the module exists. 22 function CheckInstance(instance) {
24 assertFalse(module === undefined); 23 assertFalse(instance === undefined);
25 assertFalse(module === null); 24 assertFalse(instance === null);
26 assertFalse(module === 0); 25 assertFalse(instance === 0);
27 assertEquals("object", typeof module); 26 assertEquals("object", typeof instance);
28 27
29 // Check the memory is an ArrayBuffer. 28 // Check the memory is an ArrayBuffer.
30 var mem = module.exports.memory; 29 var mem = instance.exports.memory;
31 assertFalse(mem === undefined); 30 assertFalse(mem === undefined);
32 assertFalse(mem === null); 31 assertFalse(mem === null);
33 assertFalse(mem === 0); 32 assertFalse(mem === 0);
34 assertEquals("object", typeof mem); 33 assertEquals("object", typeof mem);
35 assertTrue(mem instanceof ArrayBuffer); 34 assertTrue(mem instanceof ArrayBuffer);
36 for (var i = 0; i < 4; i++) { 35 for (let i = 0; i < 4; i++) {
37 module.exports.memory = 0; // should be ignored 36 instance.exports.memory = 0; // should be ignored
38 assertEquals(mem, module.exports.memory); 37 assertSame(mem, instance.exports.memory);
38 }
39
40 assertEquals(65536, instance.exports.memory.byteLength);
41
42 // Check the properties of the main function.
43 let main = instance.exports.main;
44 assertFalse(main === undefined);
45 assertFalse(main === null);
46 assertFalse(main === 0);
47 assertEquals("function", typeof main);
48
49 assertEquals(kReturnValue, main());
39 } 50 }
40 51
41 assertEquals(65536, module.exports.memory.byteLength); 52 // Deprecated experimental API.
53 CheckInstance(Wasm.instantiateModule(buffer));
42 54
43 // Check the properties of the main function. 55 // Official API
44 var main = module.exports.main; 56 let module = new WebAssembly.Module(buffer);
45 assertFalse(main === undefined); 57 CheckInstance(new WebAssembly.Instance(module));
46 assertFalse(main === null);
47 assertFalse(main === 0);
48 assertEquals("function", typeof main);
49 58
50 assertEquals(kReturnValue, main()); 59 let promise = WebAssembly.compile(buffer);
60 promise.then(module => CheckInstance(new WebAssembly.Instance(module)));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698