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

Side by Side Diff: test/mjsunit/wasm/js-api.js

Issue 2626263004: [wasm] Implement WebAssembly.Module.customSections. (Closed)
Patch Set: Remove DCHECKs again 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-module.cc ('k') | test/unittests/wasm/module-decoder-unittest.cc » ('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 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 --allow-natives-syntax 5 // Flags: --expose-wasm --allow-natives-syntax
6 6
7 if ((typeof drainJobQueue) != "function") { 7 if ((typeof drainJobQueue) != "function") {
8 drainJobQueue = () => { %RunMicrotasks() }; 8 drainJobQueue = () => { %RunMicrotasks() };
9 } 9 }
10 10
11 load("test/mjsunit/wasm/wasm-constants.js"); 11 load("test/mjsunit/wasm/wasm-constants.js");
12 load("test/mjsunit/wasm/wasm-module-builder.js"); 12 load("test/mjsunit/wasm/wasm-module-builder.js");
13 13
14 function assertEq(val, expected) { 14 function assertEq(val, expected) {
15 assertEquals(expected, val); 15 assertEquals(expected, val);
16 } 16 }
17 function assertArrayBuffer(val, expected) {
18 assertTrue(val instanceof ArrayBuffer);
19 assertEq(expected.length, val.byteLength);
20 var input = new Int8Array(val);
21 for (var i = 0; i < expected.length; i++) {
22 assertEq(expected[i], input[i]);
23 }
24 }
17 function wasmIsSupported() { 25 function wasmIsSupported() {
18 return (typeof WebAssembly.Module) == "function"; 26 return (typeof WebAssembly.Module) == "function";
19 } 27 }
20 function assertErrorMessage(func, type, msg) { 28 function assertErrorMessage(func, type, msg) {
21 //TODO assertThrows(func, type, msg); 29 //TODO assertThrows(func, type, msg);
22 assertThrows(func, type); 30 assertThrows(func, type);
23 } 31 }
24 32
25 let emptyModuleBinary = (() => { 33 let emptyModuleBinary = (() => {
26 var builder = new WasmModuleBuilder(); 34 var builder = new WasmModuleBuilder();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 assertEq(arr.length, 4); 251 assertEq(arr.length, 4);
244 assertEq(arr[0].kind, "function"); 252 assertEq(arr[0].kind, "function");
245 assertEq(arr[0].name, "a"); 253 assertEq(arr[0].name, "a");
246 assertEq(arr[1].kind, "memory"); 254 assertEq(arr[1].kind, "memory");
247 assertEq(arr[1].name, "b"); 255 assertEq(arr[1].name, "b");
248 assertEq(arr[2].kind, "table"); 256 assertEq(arr[2].kind, "table");
249 assertEq(arr[2].name, "c"); 257 assertEq(arr[2].name, "c");
250 assertEq(arr[3].kind, "global"); 258 assertEq(arr[3].kind, "global");
251 assertEq(arr[3].name, "x"); 259 assertEq(arr[3].name, "x");
252 260
261 // 'WebAssembly.Module.customSections' data property
262 let moduleCustomSectionsDesc =
263 Object.getOwnPropertyDescriptor(Module, 'customSections');
264 assertEq(typeof moduleCustomSectionsDesc.value, 'function');
265 assertEq(moduleCustomSectionsDesc.writable, true);
266 assertEq(moduleCustomSectionsDesc.enumerable, false);
267 assertEq(moduleCustomSectionsDesc.configurable, true);
268
269 let moduleCustomSections = moduleCustomSectionsDesc.value;
270 assertEq(moduleCustomSections.length, 2);
271 assertErrorMessage(
272 () => moduleCustomSections(), TypeError, /requires more than 0 arguments/);
273 assertErrorMessage(
274 () => moduleCustomSections(undefined), TypeError,
275 /first argument must be a WebAssembly.Module/);
276 assertErrorMessage(
277 () => moduleCustomSections({}), TypeError,
278 /first argument must be a WebAssembly.Module/);
279 var arr = moduleCustomSections(emptyModule, 'x');
280 assertEq(arr instanceof Array, true);
281 assertEq(arr.length, 0);
282
283 assertErrorMessage(
284 () => moduleCustomSections(1), TypeError,
285 'first argument must be a WebAssembly.Module');
286 assertErrorMessage(
287 () => moduleCustomSections(emptyModule), TypeError,
288 'second argument must be a String');
289 assertErrorMessage(
290 () => moduleCustomSections(emptyModule, 3), TypeError,
291 'second argument must be a String');
292
293 let customSectionModuleBinary2 = (() => {
294 let builder = new WasmModuleBuilder();
295 builder.addExplicitSection([kUnknownSectionCode, 3, 1, 'x'.charCodeAt(0), 2]);
296 builder.addExplicitSection([
297 kUnknownSectionCode, 6, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
298 'o'.charCodeAt(0), 66, 77
299 ]);
300 builder.addExplicitSection([
301 kUnknownSectionCode, 7, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
302 'o'.charCodeAt(0), 91, 92, 93
303 ]);
304 builder.addExplicitSection([
305 kUnknownSectionCode, 7, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
306 'x'.charCodeAt(0), 99, 99, 99
307 ]);
308 return new Int8Array(builder.toBuffer());
309 })();
310 var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'x');
311 assertEq(arr instanceof Array, true);
312 assertEq(arr.length, 1);
313 assertArrayBuffer(arr[0], [2]);
314 var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'foo');
315 assertEq(arr instanceof Array, true);
316 assertEq(arr.length, 2);
317 assertArrayBuffer(arr[0], [66, 77]);
318 assertArrayBuffer(arr[1], [91, 92, 93]);
319 var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'bar');
320 assertEq(arr instanceof Array, true);
321 assertEq(arr.length, 0);
322
253 // 'WebAssembly.Instance' data property 323 // 'WebAssembly.Instance' data property
254 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance'); 324 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance');
255 assertEq(typeof instanceDesc.value, "function"); 325 assertEq(typeof instanceDesc.value, "function");
256 assertTrue(instanceDesc.writable); 326 assertTrue(instanceDesc.writable);
257 assertFalse(instanceDesc.enumerable); 327 assertFalse(instanceDesc.enumerable);
258 assertTrue(instanceDesc.configurable); 328 assertTrue(instanceDesc.configurable);
259 329
260 // 'WebAssembly.Instance' constructor function 330 // 'WebAssembly.Instance' constructor function
261 let Instance = WebAssembly.Instance; 331 let Instance = WebAssembly.Instance;
262 assertEq(Instance, instanceDesc.value); 332 assertEq(Instance, instanceDesc.value);
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 assertTrue(result.instance instanceof Instance); 700 assertTrue(result.instance instanceof Instance);
631 } 701 }
632 } 702 }
633 assertInstantiateSuccess(emptyModule); 703 assertInstantiateSuccess(emptyModule);
634 assertInstantiateSuccess(emptyModuleBinary); 704 assertInstantiateSuccess(emptyModuleBinary);
635 assertInstantiateSuccess(emptyModuleBinary.buffer); 705 assertInstantiateSuccess(emptyModuleBinary.buffer);
636 assertInstantiateSuccess(importingModule, {'': {f: () => {}}}); 706 assertInstantiateSuccess(importingModule, {'': {f: () => {}}});
637 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); 707 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}});
638 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); 708 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}});
639 assertInstantiateSuccess(memoryImportingModuleBinary, {"": {"my_memory": scratch _memory}}); 709 assertInstantiateSuccess(memoryImportingModuleBinary, {"": {"my_memory": scratch _memory}});
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/unittests/wasm/module-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698