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

Side by Side Diff: test/mjsunit/wasm/table.js

Issue 2628203003: Reland of [wasm] Enforce that function bodies end with the \"end\" opcode. (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
« no previous file with comments | « test/mjsunit/wasm/incrementer.wasm ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5 // Flags: --expose-wasm
6 6
7 'use strict'; 7 'use strict';
8 8
9 load("test/mjsunit/wasm/wasm-constants.js"); 9 load("test/mjsunit/wasm/wasm-constants.js");
10 load("test/mjsunit/wasm/wasm-module-builder.js"); 10 load("test/mjsunit/wasm/wasm-module-builder.js");
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 145 }
146 for (let key of [-1, table.length, table.length * 10]) { 146 for (let key of [-1, table.length, table.length * 10]) {
147 assertThrows(() => table.get(key), RangeError); 147 assertThrows(() => table.get(key), RangeError);
148 } 148 }
149 assertThrows(() => table.get(Symbol()), TypeError); 149 assertThrows(() => table.get(Symbol()), TypeError);
150 assertThrows(() => WebAssembly.Table.prototype.get.call([], 0), TypeError); 150 assertThrows(() => WebAssembly.Table.prototype.get.call([], 0), TypeError);
151 })(); 151 })();
152 152
153 (function TestSet() { 153 (function TestSet() {
154 let builder = new WasmModuleBuilder; 154 let builder = new WasmModuleBuilder;
155 builder.addExport("wasm", builder.addFunction("", kSig_v_v)); 155 builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
156 builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); 156 builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
157 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; 157 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
158 158
159 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); 159 let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
160 160
161 for (let f of [wasm, host]) { 161 for (let f of [wasm, host]) {
162 for (let i = 0; i < table.length; ++i) table.set(i, null); 162 for (let i = 0; i < table.length; ++i) table.set(i, null);
163 for (let i = 0; i < table.length; ++i) { 163 for (let i = 0; i < table.length; ++i) {
164 assertSame(null, table.get(i)); 164 assertSame(null, table.get(i));
165 assertSame(undefined, table.set(i, f)); 165 assertSame(undefined, table.set(i, f));
(...skipping 27 matching lines...) Expand all
193 193
194 assertThrows(() => table.set(Symbol(), f), TypeError); 194 assertThrows(() => table.set(Symbol(), f), TypeError);
195 assertThrows(() => WebAssembly.Table.prototype.set.call([], 0, f), 195 assertThrows(() => WebAssembly.Table.prototype.set.call([], 0, f),
196 TypeError); 196 TypeError);
197 } 197 }
198 })(); 198 })();
199 199
200 200
201 (function TestIndexing() { 201 (function TestIndexing() {
202 let builder = new WasmModuleBuilder; 202 let builder = new WasmModuleBuilder;
203 builder.addExport("wasm", builder.addFunction("", kSig_v_v)); 203 builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
204 builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); 204 builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
205 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; 205 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
206 206
207 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); 207 let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
208 208
209 for (let f of [wasm, host, () => {}, 5, {}, ""]) { 209 for (let f of [wasm, host, () => {}, 5, {}, ""]) {
210 for (let i = 0; i < table.length; ++i) table[i] = f; 210 for (let i = 0; i < table.length; ++i) table[i] = f;
211 for (let i = 0; i < table.length; ++i) { 211 for (let i = 0; i < table.length; ++i) {
212 assertSame(null, table.get(i)); 212 assertSame(null, table.get(i));
213 assertSame(f, table[i]); 213 assertSame(f, table[i]);
214 } 214 }
215 215
216 for (let key of [0.4, "", NaN, {}, [], () => {}]) { 216 for (let key of [0.4, "", NaN, {}, [], () => {}]) {
217 assertSame(f, table[key] = f); 217 assertSame(f, table[key] = f);
218 assertSame(f, table[key]); 218 assertSame(f, table[key]);
219 assertSame(null, table.get(key)); 219 assertSame(null, table.get(key));
220 } 220 }
221 } 221 }
222 })(); 222 })();
223 223
224 (function TestGrow() { 224 (function TestGrow() {
225 let builder = new WasmModuleBuilder; 225 let builder = new WasmModuleBuilder;
226 builder.addExport("wasm", builder.addFunction("", kSig_v_v)); 226 builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([]));
227 builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); 227 builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
228 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; 228 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
229 229
230 function init(table) { 230 function init(table) {
231 for (let i = 0; i < 5; ++i) table.set(i, wasm); 231 for (let i = 0; i < 5; ++i) table.set(i, wasm);
232 for (let i = 15; i < 20; ++i) table.set(i, host); 232 for (let i = 15; i < 20; ++i) table.set(i, host);
233 } 233 }
234 function check(table) { 234 function check(table) {
235 for (let i = 0; i < 5; ++i) assertSame(wasm, table.get(i)); 235 for (let i = 0; i < 5; ++i) assertSame(wasm, table.get(i));
236 for (let i = 6; i < 15; ++i) assertSame(null, table.get(i)); 236 for (let i = 6; i < 15; ++i) assertSame(null, table.get(i));
(...skipping 17 matching lines...) Expand all
254 check(table); 254 check(table);
255 table.grow(5); 255 table.grow(5);
256 check(table); 256 check(table);
257 table.grow(0); 257 table.grow(0);
258 check(table); 258 check(table);
259 assertThrows(() => table.grow(1), RangeError); 259 assertThrows(() => table.grow(1), RangeError);
260 assertThrows(() => table.grow(-10), RangeError); 260 assertThrows(() => table.grow(-10), RangeError);
261 261
262 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); 262 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError);
263 })(); 263 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/incrementer.wasm ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698