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

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

Issue 2626263004: [wasm] Implement WebAssembly.Module.customSections. (Closed)
Patch Set: 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
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 assertEq(arr.length, 4); 245 assertEq(arr.length, 4);
238 assertEq(arr[0].kind, "function"); 246 assertEq(arr[0].kind, "function");
239 assertEq(arr[0].name, "a"); 247 assertEq(arr[0].name, "a");
240 assertEq(arr[1].kind, "memory"); 248 assertEq(arr[1].kind, "memory");
241 assertEq(arr[1].name, "b"); 249 assertEq(arr[1].name, "b");
242 assertEq(arr[2].kind, "table"); 250 assertEq(arr[2].kind, "table");
243 assertEq(arr[2].name, "c"); 251 assertEq(arr[2].name, "c");
244 assertEq(arr[3].kind, "global"); 252 assertEq(arr[3].kind, "global");
245 assertEq(arr[3].name, "x"); 253 assertEq(arr[3].name, "x");
246 254
255 // 'WebAssembly.Module.customSections' data property
256 let moduleCustomSectionsDesc = Object.getOwnPropertyDescriptor(Module, 'customSe ctions');
257 assertEq(typeof moduleCustomSectionsDesc.value, "function");
258 assertEq(moduleCustomSectionsDesc.writable, true);
259 assertEq(moduleCustomSectionsDesc.enumerable, false);
260 assertEq(moduleCustomSectionsDesc.configurable, true);
261
262 let moduleCustomSections = moduleCustomSectionsDesc.value;
263 assertEq(moduleCustomSections.length, 1);
264 assertErrorMessage(() => moduleCustomSections(), TypeError, /requires more than 0 arguments/);
265 assertErrorMessage(() => moduleCustomSections(undefined), TypeError, /first argu ment must be a WebAssembly.Module/);
266 assertErrorMessage(() => moduleCustomSections({}), TypeError, /first argument mu st be a WebAssembly.Module/);
267 var arr = moduleCustomSections(emptyModule);
268 assertEq(arr instanceof Array, true);
269 assertEq(arr.length, 0);
270
271 let customSectionModuleBinary2 = (() => {
272 let builder = new WasmModuleBuilder();
273 builder.addExplicitSection([kUnknownSectionCode, 3, 1,
274 'x'.charCodeAt(0), 2]);
275 builder.addExplicitSection([kUnknownSectionCode, 6, 3,
276 'f'.charCodeAt(0),
277 'o'.charCodeAt(0),
278 'o'.charCodeAt(0),
279 66, 77]);
280 return new Int8Array(builder.toBuffer());
281 })();
282 var arr = moduleCustomSections(new Module(customSectionModuleBinary2));
283 assertEq(arr instanceof Array, true);
284 assertEq(arr.length, 2);
285 assertEq(arr[0].name, "x");
286 assertArrayBuffer(arr[0].data, [2]);
287 assertEq(arr[1].name, "foo");
288 assertArrayBuffer(arr[1].data, [66, 77]);
289
247 // 'WebAssembly.Instance' data property 290 // 'WebAssembly.Instance' data property
248 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance'); 291 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance');
249 assertEq(typeof instanceDesc.value, "function"); 292 assertEq(typeof instanceDesc.value, "function");
250 assertEq(instanceDesc.writable, true); 293 assertEq(instanceDesc.writable, true);
251 assertEq(instanceDesc.enumerable, false); 294 assertEq(instanceDesc.enumerable, false);
252 assertEq(instanceDesc.configurable, true); 295 assertEq(instanceDesc.configurable, true);
253 296
254 // 'WebAssembly.Instance' constructor function 297 // 'WebAssembly.Instance' constructor function
255 let Instance = WebAssembly.Instance; 298 let Instance = WebAssembly.Instance;
256 assertEq(Instance, instanceDesc.value); 299 assertEq(Instance, instanceDesc.value);
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 assertEq(result.instance instanceof Instance, true); 651 assertEq(result.instance instanceof Instance, true);
609 } 652 }
610 } 653 }
611 assertInstantiateSuccess(emptyModule); 654 assertInstantiateSuccess(emptyModule);
612 assertInstantiateSuccess(emptyModuleBinary); 655 assertInstantiateSuccess(emptyModuleBinary);
613 assertInstantiateSuccess(emptyModuleBinary.buffer); 656 assertInstantiateSuccess(emptyModuleBinary.buffer);
614 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}}); 657 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}});
615 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); 658 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}});
616 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); 659 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}});
617 } 660 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698