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

Side by Side Diff: test/mjsunit/wasm/test-wasm-compilation-control.js

Issue 2701413002: Revert of [wasm] Embedder can control what buffers wasm compilation works on. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --allow-natives-syntax --validate-asm
6
7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js");
9
10 let buffer = (() => {
11 var builder = new WasmModuleBuilder();
12 builder.addFunction("f", kSig_i_v)
13 .addBody([kExprI32Const, 42])
14 .exportAs("f");
15 return builder.toBuffer();
16 })();
17
18 // allow up to the buffer size
19 %SetWasmCompileControls(buffer.byteLength, true);
20 %SetWasmInstantiateControls();
21 var m = new WebAssembly.Module(buffer);
22 var i = new WebAssembly.Instance(m);
23 assertEquals(i.exports.f(), 42);
24
25 // the buffer can't compile synchronously, but we allow async compile
26 %SetWasmCompileControls(buffer.byteLength - 1, true);
27 // test first that we can't sync-instantiate this module anymore
28 try {
29 i = new WebAssembly.Instance(m);
30 } catch (e) {
31 assertTrue(e instanceof RangeError);
32 }
33
34 //...but we can async-instantiate it
35
36 WebAssembly.instantiate(m)
37 .then(instance => i = instance,
38 assertUnreachable);
39 %RunMicrotasks();
40 assertTrue(i instanceof WebAssembly.Instance);
41
42 try {
43 m = new WebAssembly.Module(buffer);
44 assertUnreachable();
45 } catch (e) {
46 assertTrue(e instanceof RangeError);
47 }
48
49 WebAssembly.compile(buffer)
50 .then(res => m = res,
51 m = null);
52
53 %RunMicrotasks();
54 assertTrue(m instanceof WebAssembly.Module)
55
56 WebAssembly.instantiate(buffer)
57 .then(res => m = res.module,
58 m = null);
59
60 %RunMicrotasks();
61 assertTrue(m instanceof WebAssembly.Module);
62
63 // not even async compile works.
64 var ex;
65 %SetWasmCompileControls(buffer.byteLength - 1, false);
66 WebAssembly.compile(buffer)
67 .then(ex = null,
68 e => ex = e);
69
70 %RunMicrotasks();
71 assertTrue(ex instanceof RangeError);
72
73 WebAssembly.instantiate(buffer)
74 .then(ex = null,
75 e => ex = e);
76 %RunMicrotasks();
77 assertTrue(ex instanceof RangeError);
78
79
80 // For asm-wasm, these controls are ignored.
81 %SetWasmCompileControls(0, false);
82 function assertValidAsm(func) {
83 assertTrue(%IsAsmWasmCode(func));
84 }
85
86 function assertWasm(expected, func) {
87 assertEquals(
88 expected, func(undefined, undefined, new ArrayBuffer(1024)).caller());
89 assertValidAsm(func);
90 }
91
92 function TestAsmWasmIsUnaffected() {
93 "use asm";
94 function caller() {
95 return 43;
96 }
97
98 return {caller: caller};
99 }
100
101 assertWasm(43, TestAsmWasmIsUnaffected);
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698