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

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

Issue 2384513002: [wasm] Implement WebAssembly.validate() (Closed)
Patch Set: Address review comments. Created 4 years, 2 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-module.cc ('k') | test/mjsunit/wasm/wasm-object-api.js » ('j') | 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 = 117; 10 let kReturnValue = 117;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // Deprecated experimental API. 55 // Deprecated experimental API.
56 CheckInstance(Wasm.instantiateModule(buffer)); 56 CheckInstance(Wasm.instantiateModule(buffer));
57 57
58 // Official API 58 // Official API
59 let module = new WebAssembly.Module(buffer); 59 let module = new WebAssembly.Module(buffer);
60 CheckInstance(new WebAssembly.Instance(module)); 60 CheckInstance(new WebAssembly.Instance(module));
61 61
62 let promise = WebAssembly.compile(buffer); 62 let promise = WebAssembly.compile(buffer);
63 promise.then(module => CheckInstance(new WebAssembly.Instance(module))); 63 promise.then(module => CheckInstance(new WebAssembly.Instance(module)));
64 64
65 // Check that validate works correctly for a module.
66 assertTrue(WebAssembly.validate(buffer));
67 assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
68
65 // Negative tests. 69 // Negative tests.
66 (function InvalidModules() { 70 (function InvalidModules() {
67 print("InvalidModules..."); 71 print("InvalidModules...");
68 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}]; 72 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}];
69 let len = invalid_cases.length; 73 let len = invalid_cases.length;
70 for (var i = 0; i < len; ++i) { 74 for (var i = 0; i < len; ++i) {
71 try { 75 try {
72 let instance = new WebAssembly.Instance(1); 76 let instance = new WebAssembly.Instance(invalid_cases[i]);
73 assertUnreachable("should not be able to instantiate invalid modules."); 77 assertUnreachable("should not be able to instantiate invalid modules.");
74 } catch (e) { 78 } catch (e) {
75 assertContains("Argument 0", e.toString()); 79 assertContains("Argument 0", e.toString());
76 } 80 }
77 } 81 }
78 })(); 82 })();
79 83
80 // Compile async an invalid blob. 84 // Compile async an invalid blob.
81 (function InvalidBinaryAsyncCompilation() { 85 (function InvalidBinaryAsyncCompilation() {
82 print("InvalidBinaryAsyncCompilation..."); 86 print("InvalidBinaryAsyncCompilation...");
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 view_1[0] = 1; 209 view_1[0] = 1;
206 view_2[0] = 1000; 210 view_2[0] = 1000;
207 211
208 var module = new WebAssembly.Module(builder.toBuffer()); 212 var module = new WebAssembly.Module(builder.toBuffer());
209 var i1 = new WebAssembly.Instance(module, null, mem_1); 213 var i1 = new WebAssembly.Instance(module, null, mem_1);
210 var i2 = new WebAssembly.Instance(module, null, mem_2); 214 var i2 = new WebAssembly.Instance(module, null, mem_2);
211 215
212 assertEquals(1, i1.exports.f()); 216 assertEquals(1, i1.exports.f());
213 assertEquals(1000, i2.exports.f()); 217 assertEquals(1000, i2.exports.f());
214 })(); 218 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/wasm-object-api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698