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

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

Issue 2414053002: [wasm] Implement Table#set and Table#grow (Closed)
Patch Set: Avoid lossy int conversion Created 4 years, 2 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') | 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");
10 load("test/mjsunit/wasm/wasm-module-builder.js");
11
9 // Basic tests. 12 // Basic tests.
10 13
11 var outOfUint32RangeValue = 1e12; 14 var outOfUint32RangeValue = 1e12;
12 var int32ButOob = 1073741824; 15 var int32ButOob = 1073741824;
13 16
14 function assertTableIsValid(table) { 17 function assertTableIsValid(table) {
15 assertSame(WebAssembly.Table.prototype, table.__proto__); 18 assertSame(WebAssembly.Table.prototype, table.__proto__);
16 assertSame(WebAssembly.Table, table.constructor); 19 assertSame(WebAssembly.Table, table.constructor);
17 assertTrue(table instanceof Object); 20 assertTrue(table instanceof Object);
18 assertTrue(table instanceof WebAssembly.Table); 21 assertTrue(table instanceof WebAssembly.Table);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 let table = new WebAssembly.Table({element: "anyfunc", initial: i}); 125 let table = new WebAssembly.Table({element: "anyfunc", initial: i});
123 assertEquals(i, table.length); 126 assertEquals(i, table.length);
124 } 127 }
125 128
126 assertThrows(() => WebAssembly.Table.prototype.length.call([]), TypeError); 129 assertThrows(() => WebAssembly.Table.prototype.length.call([]), TypeError);
127 })(); 130 })();
128 131
129 (function TestGet() { 132 (function TestGet() {
130 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); 133 let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
131 134
132 for (let i = 0; i < 10; ++i) { 135 for (let i = 0; i < table.length; ++i) {
133 assertEquals(null, table.get(i)); 136 assertEquals(null, table.get(i));
134 assertEquals(null, table.get(String(i))); 137 assertEquals(null, table.get(String(i)));
135 } 138 }
136 assertEquals(null, table.get("")); 139 for (let key of [0.4, "", NaN, {}, [], () => {}]) {
137 assertEquals(null, table.get(NaN)); 140 assertEquals(null, table.get(key));
138 assertEquals(null, table.get({})); 141 }
139 assertEquals(null, table.get([])); 142 for (let key of [-1, table.length, table.length * 10]) {
140 assertEquals(null, table.get(() => {})); 143 assertThrows(() => table.get(key), RangeError);
141 144 }
142 assertEquals(undefined, table.get(10));
143 assertEquals(undefined, table.get(-1));
144
145 assertThrows(() => table.get(Symbol()), TypeError); 145 assertThrows(() => table.get(Symbol()), TypeError);
146 assertThrows(() => WebAssembly.Table.prototype.get.call([], 0), TypeError); 146 assertThrows(() => WebAssembly.Table.prototype.get.call([], 0), TypeError);
147 })(); 147 })();
148
149 (function TestSet() {
150 let builder = new WasmModuleBuilder;
151 builder.addExport("wasm", builder.addFunction("", kSig_v_v));
152 builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v));
153 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
154
155 let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
156
157 for (let f of [wasm, host]) {
158 for (let i = 0; i < table.length; ++i) table.set(i, null);
159 for (let i = 0; i < table.length; ++i) {
160 assertSame(null, table.get(i));
161 assertSame(undefined, table.set(i, f));
162 assertSame(f, table.get(i));
163 }
164
165 for (let i = 0; i < table.length; ++i) table.set(i, null);
166 for (let i = 0; i < table.length; ++i) {
167 assertSame(null, table.get(i));
168 assertSame(undefined, table.set(String(i), f));
169 assertSame(f, table.get(i));
170 }
171
172 for (let key of [0.4, "", NaN, {}, [], () => {}]) {
173 assertSame(undefined, table.set(0, null));
174 assertSame(undefined, table.set(key, f));
175 assertSame(f, table.get(0));
176 }
177
178 for (let key of [-1, table.length, table.length * 10]) {
179 assertThrows(() => table.set(key, f), RangeError);
180 }
181
182 assertThrows(() => table.set(0), TypeError);
183 for (let val of [undefined, 0, "", {}, [], () => {}]) {
184 assertThrows(() => table.set(0, val), TypeError);
185 }
186
187 assertThrows(() => table.set(Symbol(), f), TypeError);
188 assertThrows(() => WebAssembly.Table.prototype.set.call([], 0, f),
189 TypeError);
190 }
191 })();
192
193 (function TestGrow() {
194 let builder = new WasmModuleBuilder;
195 builder.addExport("wasm", builder.addFunction("", kSig_v_v));
196 builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v));
197 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
198
199 function init(table) {
200 for (let i = 0; i < 5; ++i) table.set(i, wasm);
201 for (let i = 15; i < 20; ++i) table.set(i, host);
202 }
203 function check(table) {
204 for (let i = 0; i < 5; ++i) assertSame(wasm, table.get(i));
205 for (let i = 6; i < 15; ++i) assertSame(null, table.get(i));
206 for (let i = 15; i < 20; ++i) assertSame(host, table.get(i));
207 for (let i = 21; i < table.length; ++i) assertSame(null, table.get(i));
208 }
209
210 let table = new WebAssembly.Table({element: "anyfunc", initial: 20});
211 init(table);
212 check(table);
213 table.grow(0);
214 check(table);
215 table.grow(10);
216 check(table);
217 assertThrows(() => table.grow(-10), RangeError);
218
219 table = new WebAssembly.Table({element: "anyfunc", initial: 20, maximum: 25});
220 init(table);
221 check(table);
222 table.grow(0);
223 check(table);
224 table.grow(5);
225 check(table);
226 table.grow(0);
227 check(table);
228 assertThrows(() => table.grow(1), RangeError);
229 assertThrows(() => table.grow(-10), RangeError);
230
231 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError);
232 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698