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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/js-api.js
diff --git a/test/mjsunit/wasm/js-api.js b/test/mjsunit/wasm/js-api.js
index 9279234761767f576de59fb0fa21c09acdbb7c23..128c20451b088de90142daeb6358d814fbb4fd25 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";
}
@@ -250,6 +258,68 @@ 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, 2);
+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, 'x');
+assertEq(arr instanceof Array, true);
+assertEq(arr.length, 0);
+
+assertErrorMessage(
+ () => moduleCustomSections(1), TypeError,
+ 'first argument must be a WebAssembly.Module');
+assertErrorMessage(
+ () => moduleCustomSections(emptyModule), TypeError,
+ 'second argument must be a String');
+assertErrorMessage(
+ () => moduleCustomSections(emptyModule, 3), TypeError,
+ 'second argument must be a String');
+
+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
+ ]);
+ builder.addExplicitSection([
+ kUnknownSectionCode, 7, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
+ 'o'.charCodeAt(0), 91, 92, 93
+ ]);
+ builder.addExplicitSection([
+ kUnknownSectionCode, 7, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
+ 'x'.charCodeAt(0), 99, 99, 99
+ ]);
+ return new Int8Array(builder.toBuffer());
+})();
+var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'x');
+assertEq(arr instanceof Array, true);
+assertEq(arr.length, 1);
+assertArrayBuffer(arr[0], [2]);
+var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'foo');
+assertEq(arr instanceof Array, true);
+assertEq(arr.length, 2);
+assertArrayBuffer(arr[0], [66, 77]);
+assertArrayBuffer(arr[1], [91, 92, 93]);
+var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'bar');
+assertEq(arr instanceof Array, true);
+assertEq(arr.length, 0);
+
// 'WebAssembly.Instance' data property
let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance');
assertEq(typeof instanceDesc.value, "function");
« 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