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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/wasm/js-api.js
diff --git a/test/mjsunit/wasm/js-api.js b/test/mjsunit/wasm/js-api.js
index 1106853b43b8cf1c8fef8af5d9b7f20471de83d5..05b7d6146eb25f3116f96ca54c5ee59e701ff1d7 100644
--- a/test/mjsunit/wasm/js-api.js
+++ b/test/mjsunit/wasm/js-api.js
@@ -14,6 +14,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
function assertEq(val, expected) {
assertEquals(expected, val);
}
+function assertArrayBuffer(val, expected) {
+ assertTrue(val instanceof ArrayBuffer);
+ assertEq(expected.length, val.byteLength);
+ var input = new Int8Array(val);
+ for (var i = 0; i < expected.length; i++) {
+ assertEq(expected[i], input[i]);
+ }
+}
function wasmIsSupported() {
return (typeof WebAssembly.Module) == "function";
}
@@ -244,6 +252,41 @@ assertEq(arr[2].name, "c");
assertEq(arr[3].kind, "global");
assertEq(arr[3].name, "x");
+// 'WebAssembly.Module.customSections' data property
+let moduleCustomSectionsDesc = Object.getOwnPropertyDescriptor(Module, 'customSections');
+assertEq(typeof moduleCustomSectionsDesc.value, "function");
+assertEq(moduleCustomSectionsDesc.writable, true);
+assertEq(moduleCustomSectionsDesc.enumerable, false);
+assertEq(moduleCustomSectionsDesc.configurable, true);
+
+let moduleCustomSections = moduleCustomSectionsDesc.value;
+assertEq(moduleCustomSections.length, 1);
+assertErrorMessage(() => moduleCustomSections(), TypeError, /requires more than 0 arguments/);
+assertErrorMessage(() => moduleCustomSections(undefined), TypeError, /first argument must be a WebAssembly.Module/);
+assertErrorMessage(() => moduleCustomSections({}), TypeError, /first argument must be a WebAssembly.Module/);
+var arr = moduleCustomSections(emptyModule);
+assertEq(arr instanceof Array, true);
+assertEq(arr.length, 0);
+
+let customSectionModuleBinary2 = (() => {
+ let builder = new WasmModuleBuilder();
+ builder.addExplicitSection([kUnknownSectionCode, 3, 1,
+ 'x'.charCodeAt(0), 2]);
+ builder.addExplicitSection([kUnknownSectionCode, 6, 3,
+ 'f'.charCodeAt(0),
+ 'o'.charCodeAt(0),
+ 'o'.charCodeAt(0),
+ 66, 77]);
+ return new Int8Array(builder.toBuffer());
+})();
+var arr = moduleCustomSections(new Module(customSectionModuleBinary2));
+assertEq(arr instanceof Array, true);
+assertEq(arr.length, 2);
+assertEq(arr[0].name, "x");
+assertArrayBuffer(arr[0].data, [2]);
+assertEq(arr[1].name, "foo");
+assertArrayBuffer(arr[1].data, [66, 77]);
+
// 'WebAssembly.Instance' data property
let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance');
assertEq(typeof instanceDesc.value, "function");

Powered by Google App Engine
This is Rietveld 408576698