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

Unified Diff: test/mjsunit/wasm/test-wasm-compilation-control.js

Issue 2699843003: [wasm] Embedder can control what buffers wasm compilation works on. (Closed)
Patch Set: RangeError Created 3 years, 10 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
« src/wasm/wasm-js.cc ('K') | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/test-wasm-compilation-control.js
diff --git a/test/mjsunit/wasm/test-wasm-compilation-control.js b/test/mjsunit/wasm/test-wasm-compilation-control.js
new file mode 100644
index 0000000000000000000000000000000000000000..7b0e5d3fb66267da63d6d215bf428117f330b925
--- /dev/null
+++ b/test/mjsunit/wasm/test-wasm-compilation-control.js
@@ -0,0 +1,101 @@
+// Copyright 2017 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --allow-natives-syntax --validate-asm
+
+load("test/mjsunit/wasm/wasm-constants.js");
+load("test/mjsunit/wasm/wasm-module-builder.js");
+
+let buffer = (() => {
+ var builder = new WasmModuleBuilder();
bradnelson 2017/02/18 00:28:43 Some reason this ended up indented by 4 (should be
Mircea Trofin 2017/02/18 00:41:47 huh... no idea. Emacs?
+ builder.addFunction("f", kSig_i_v)
+ .addBody([kExprI32Const, 42])
+ .exportAs("f");
+ return builder.toBuffer();
+})();
+
+// allow up to the buffer size
+%SetWasmCompileControls(buffer.byteLength, true);
+%SetWasmInstantiateControls();
+var m = new WebAssembly.Module(buffer);
+var i = new WebAssembly.Instance(m);
+assertEquals(i.exports.f(), 42);
+
+// the buffer can't compile synchrnously, but we allow async compile
bradnelson 2017/02/18 00:28:42 typo
Mircea Trofin 2017/02/18 00:41:47 Acknowledged.
+%SetWasmCompileControls(buffer.byteLength - 1, true);
+// test first that we can't sync-instantiate this module anymore
+try {
+ i = new WebAssembly.Instance(m);
+} catch (e) {
+ assertTrue(e instanceof RangeError);
+}
+
+//...but we can async-instantiate it
+
+WebAssembly.instantiate(m)
+ .then(instance => i = instance,
+ assertUnreachable);
+%RunMicrotasks();
+assertTrue(i instanceof WebAssembly.Instance);
+
+try {
+ m = new WebAssembly.Module(buffer);
+ assertUnreachable();
+} catch (e) {
+ assertTrue(e instanceof RangeError);
+}
+
+WebAssembly.compile(buffer)
+ .then(res => m = res,
+ m = null);
+
+%RunMicrotasks();
+assertTrue(m instanceof WebAssembly.Module)
+
+WebAssembly.instantiate(buffer)
+ .then(res => m = res.module,
+ m = null);
+
+%RunMicrotasks();
+assertTrue(m instanceof WebAssembly.Module);
+
+// not even async compile works.
+var ex;
+%SetWasmCompileControls(buffer.byteLength - 1, false);
+WebAssembly.compile(buffer)
+ .then(ex = null,
+ e => ex = e);
+
+%RunMicrotasks();
+assertTrue(ex instanceof RangeError);
+
+WebAssembly.instantiate(buffer)
+ .then(ex = null,
+ e => ex = e);
+%RunMicrotasks();
+assertTrue(ex instanceof RangeError);
+
+
+// For asm-wasm, these controls are ignored.
+%SetWasmCompileControls(0, false);
+function assertValidAsm(func) {
+ assertTrue(%IsAsmWasmCode(func));
+}
+
+function assertWasm(expected, func) {
+ assertEquals(
+ expected, func(undefined, undefined, new ArrayBuffer(1024)).caller());
+ assertValidAsm(func);
+}
+
+function TestReturnInBlock() {
bradnelson 2017/02/18 00:28:42 Leftover?
Mircea Trofin 2017/02/18 00:41:47 No! Intended. See comment above: we're making sure
+ "use asm";
+ function caller() {
+ return 43;
+ }
+
+ return {caller: caller};
+}
+
+assertWasm(43, TestReturnInBlock);
« src/wasm/wasm-js.cc ('K') | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698