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

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

Issue 2626693002: [wasm] add WebAssembly.instantiate (Closed)
Patch Set: 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
« 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 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 let kReturnValue = 17; 10 let kReturnValue = 17;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 let main = instance.exports.main; 50 let main = instance.exports.main;
51 assertFalse(main === undefined); 51 assertFalse(main === undefined);
52 assertFalse(main === null); 52 assertFalse(main === null);
53 assertFalse(main === 0); 53 assertFalse(main === 0);
54 assertEquals("function", typeof main); 54 assertEquals("function", typeof main);
55 55
56 assertEquals(kReturnValue, main()); 56 assertEquals(kReturnValue, main());
57 } 57 }
58 58
59 // Official API 59 // Official API
60 let module = new WebAssembly.Module(buffer); 60 (function BasicJSAPITest() {
61 CheckInstance(new WebAssembly.Instance(module)); 61 print("sync module compile...");
62 let module = new WebAssembly.Module(buffer);
63 print("sync module instantiate...");
64 CheckInstance(new WebAssembly.Instance(module));
62 65
63 let promise = WebAssembly.compile(buffer); 66 print("async module compile...");
64 promise.then(module => CheckInstance(new WebAssembly.Instance(module))); 67 let promise = WebAssembly.compile(buffer);
68 promise.then(module => CheckInstance(new WebAssembly.Instance(module)));
69
70 print("async instantiate...");
71 let instance_promise = WebAssembly.instantiate(buffer);
72 instance_promise.then(CheckInstance);
73 })();
65 74
66 // Check that validate works correctly for a module. 75 // Check that validate works correctly for a module.
67 assertTrue(WebAssembly.validate(buffer)); 76 assertTrue(WebAssembly.validate(buffer));
68 assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); 77 assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
69 78
70 // Negative tests. 79 // Negative tests.
71 (function InvalidModules() { 80 (function InvalidModules() {
72 print("InvalidModules..."); 81 print("InvalidModules...");
73 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}]; 82 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}];
74 let len = invalid_cases.length; 83 let len = invalid_cases.length;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 assertEquals(1, i1.exports.f()); 228 assertEquals(1, i1.exports.f());
220 assertEquals(1000, i2.exports.f()); 229 assertEquals(1000, i2.exports.f());
221 })(); 230 })();
222 231
223 (function MustBeMemory() { 232 (function MustBeMemory() {
224 print("MustBeMemory..."); 233 print("MustBeMemory...");
225 var memory = new ArrayBuffer(65536); 234 var memory = new ArrayBuffer(65536);
226 var module = new WebAssembly.Module(buffer); 235 var module = new WebAssembly.Module(buffer);
227 assertThrows(() => new WebAssembly.Instance(module, null, memory), TypeError); 236 assertThrows(() => new WebAssembly.Instance(module, null, memory), TypeError);
228 })(); 237 })();
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