| OLD | NEW |
| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: outOfUint32RangeValue}), RangeError); | 48 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: outOfUint32RangeValue}), RangeError); |
| 49 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: 9}), RangeError); | 49 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: 9}), RangeError); |
| 50 | 50 |
| 51 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi
mum: int32ButOob})); | 51 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi
mum: int32ButOob})); |
| 52 | 52 |
| 53 let table; | 53 let table; |
| 54 table = new WebAssembly.Table({element: "anyfunc", initial: 1}); | 54 table = new WebAssembly.Table({element: "anyfunc", initial: 1}); |
| 55 assertTableIsValid(table); | 55 assertTableIsValid(table); |
| 56 assertEquals(1, table.length); | 56 assertEquals(1, table.length); |
| 57 assertEquals(null, table.get(0)); | 57 assertEquals(null, table.get(0)); |
| 58 assertEquals(undefined, table[0]); |
| 58 | 59 |
| 59 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); | 60 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); |
| 60 assertTableIsValid(table); | 61 assertTableIsValid(table); |
| 61 assertEquals(2, table.length); | 62 assertEquals(2, table.length); |
| 62 assertEquals(null, table.get(0)); | 63 assertEquals(null, table.get(0)); |
| 63 assertEquals(null, table.get(1)); | 64 assertEquals(null, table.get(1)); |
| 65 assertEquals(undefined, table[0]); |
| 66 assertEquals(undefined, table[1]); |
| 64 | 67 |
| 65 table = new WebAssembly.Table({element: "anyfunc", initial: {valueOf() { retur
n "1" }}}); | 68 table = new WebAssembly.Table({element: "anyfunc", initial: {valueOf() { retur
n "1" }}}); |
| 66 assertTableIsValid(table); | 69 assertTableIsValid(table); |
| 67 assertEquals(1, table.length); | 70 assertEquals(1, table.length); |
| 68 assertEquals(null, table.get(0)); | 71 assertEquals(null, table.get(0)); |
| 72 assertEquals(undefined, table[0]); |
| 69 | 73 |
| 70 table = new WebAssembly.Table({element: "anyfunc", initial: undefined}); | 74 table = new WebAssembly.Table({element: "anyfunc", initial: undefined}); |
| 71 assertTableIsValid(table); | 75 assertTableIsValid(table); |
| 72 assertEquals(0, table.length); | 76 assertEquals(0, table.length); |
| 73 | 77 |
| 74 table = new WebAssembly.Table({element: "anyfunc"}); | 78 table = new WebAssembly.Table({element: "anyfunc"}); |
| 75 assertTableIsValid(table); | 79 assertTableIsValid(table); |
| 76 assertEquals(0, table.length); | 80 assertEquals(0, table.length); |
| 77 | 81 |
| 78 table = new WebAssembly.Table({element: "anyfunc", maximum: 10}); | 82 table = new WebAssembly.Table({element: "anyfunc", maximum: 10}); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; | 157 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; |
| 154 | 158 |
| 155 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); | 159 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); |
| 156 | 160 |
| 157 for (let f of [wasm, host]) { | 161 for (let f of [wasm, host]) { |
| 158 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); |
| 159 for (let i = 0; i < table.length; ++i) { | 163 for (let i = 0; i < table.length; ++i) { |
| 160 assertSame(null, table.get(i)); | 164 assertSame(null, table.get(i)); |
| 161 assertSame(undefined, table.set(i, f)); | 165 assertSame(undefined, table.set(i, f)); |
| 162 assertSame(f, table.get(i)); | 166 assertSame(f, table.get(i)); |
| 167 assertSame(undefined, table[i]); |
| 163 } | 168 } |
| 164 | 169 |
| 165 for (let i = 0; i < table.length; ++i) table.set(i, null); | 170 for (let i = 0; i < table.length; ++i) table.set(i, null); |
| 166 for (let i = 0; i < table.length; ++i) { | 171 for (let i = 0; i < table.length; ++i) { |
| 167 assertSame(null, table.get(i)); | 172 assertSame(null, table.get(i)); |
| 168 assertSame(undefined, table.set(String(i), f)); | 173 assertSame(undefined, table.set(String(i), f)); |
| 169 assertSame(f, table.get(i)); | 174 assertSame(f, table.get(i)); |
| 175 assertSame(undefined, table[i]); |
| 170 } | 176 } |
| 171 | 177 |
| 172 for (let key of [0.4, "", NaN, {}, [], () => {}]) { | 178 for (let key of [0.4, "", NaN, {}, [], () => {}]) { |
| 173 assertSame(undefined, table.set(0, null)); | 179 assertSame(undefined, table.set(0, null)); |
| 174 assertSame(undefined, table.set(key, f)); | 180 assertSame(undefined, table.set(key, f)); |
| 175 assertSame(f, table.get(0)); | 181 assertSame(f, table.get(0)); |
| 182 assertSame(undefined, table[key]); |
| 176 } | 183 } |
| 177 | 184 |
| 178 for (let key of [-1, table.length, table.length * 10]) { | 185 for (let key of [-1, table.length, table.length * 10]) { |
| 179 assertThrows(() => table.set(key, f), RangeError); | 186 assertThrows(() => table.set(key, f), RangeError); |
| 180 } | 187 } |
| 181 | 188 |
| 182 assertThrows(() => table.set(0), TypeError); | 189 assertThrows(() => table.set(0), TypeError); |
| 183 for (let val of [undefined, 0, "", {}, [], () => {}]) { | 190 for (let val of [undefined, 0, "", {}, [], () => {}]) { |
| 184 assertThrows(() => table.set(0, val), TypeError); | 191 assertThrows(() => table.set(0, val), TypeError); |
| 185 } | 192 } |
| 186 | 193 |
| 187 assertThrows(() => table.set(Symbol(), f), TypeError); | 194 assertThrows(() => table.set(Symbol(), f), TypeError); |
| 188 assertThrows(() => WebAssembly.Table.prototype.set.call([], 0, f), | 195 assertThrows(() => WebAssembly.Table.prototype.set.call([], 0, f), |
| 189 TypeError); | 196 TypeError); |
| 190 } | 197 } |
| 191 })(); | 198 })(); |
| 192 | 199 |
| 200 |
| 201 (function TestIndexing() { |
| 202 let builder = new WasmModuleBuilder; |
| 203 builder.addExport("wasm", builder.addFunction("", kSig_v_v)); |
| 204 builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v)); |
| 205 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; |
| 206 |
| 207 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); |
| 208 |
| 209 for (let f of [wasm, host, () => {}, 5, {}, ""]) { |
| 210 for (let i = 0; i < table.length; ++i) table[i] = f; |
| 211 for (let i = 0; i < table.length; ++i) { |
| 212 assertSame(null, table.get(i)); |
| 213 assertSame(f, table[i]); |
| 214 } |
| 215 |
| 216 for (let key of [0.4, "", NaN, {}, [], () => {}]) { |
| 217 assertSame(f, table[key] = f); |
| 218 assertSame(f, table[key]); |
| 219 assertSame(null, table.get(key)); |
| 220 } |
| 221 } |
| 222 })(); |
| 223 |
| 193 (function TestGrow() { | 224 (function TestGrow() { |
| 194 let builder = new WasmModuleBuilder; | 225 let builder = new WasmModuleBuilder; |
| 195 builder.addExport("wasm", builder.addFunction("", kSig_v_v)); | 226 builder.addExport("wasm", builder.addFunction("", kSig_v_v)); |
| 196 builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v)); | 227 builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v)); |
| 197 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; | 228 let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; |
| 198 | 229 |
| 199 function init(table) { | 230 function init(table) { |
| 200 for (let i = 0; i < 5; ++i) table.set(i, wasm); | 231 for (let i = 0; i < 5; ++i) table.set(i, wasm); |
| 201 for (let i = 15; i < 20; ++i) table.set(i, host); | 232 for (let i = 15; i < 20; ++i) table.set(i, host); |
| 202 } | 233 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 223 check(table); | 254 check(table); |
| 224 table.grow(5); | 255 table.grow(5); |
| 225 check(table); | 256 check(table); |
| 226 table.grow(0); | 257 table.grow(0); |
| 227 check(table); | 258 check(table); |
| 228 assertThrows(() => table.grow(1), RangeError); | 259 assertThrows(() => table.grow(1), RangeError); |
| 229 assertThrows(() => table.grow(-10), RangeError); | 260 assertThrows(() => table.grow(-10), RangeError); |
| 230 | 261 |
| 231 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); | 262 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); |
| 232 })(); | 263 })(); |
| OLD | NEW |