| 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"); |
| 11 | 11 |
| 12 // Basic tests. | 12 // Basic tests. |
| 13 | 13 |
| 14 var outOfUint32RangeValue = 1e12; | 14 var outOfUint32RangeValue = 1e12; |
| 15 var int32ButOob = 1073741824; | 15 var int32ButOob = 1073741824; |
| 16 var kMaxUint32 = (4 * 1024 * 1024 * 1024) - 1; |
| 17 var kV8MaxWasmTableSize = 10000000; |
| 16 | 18 |
| 17 function assertTableIsValid(table) { | 19 function assertTableIsValid(table) { |
| 18 assertSame(WebAssembly.Table.prototype, table.__proto__); | 20 assertSame(WebAssembly.Table.prototype, table.__proto__); |
| 19 assertSame(WebAssembly.Table, table.constructor); | 21 assertSame(WebAssembly.Table, table.constructor); |
| 20 assertTrue(table instanceof Object); | 22 assertTrue(table instanceof Object); |
| 21 assertTrue(table instanceof WebAssembly.Table); | 23 assertTrue(table instanceof WebAssembly.Table); |
| 22 } | 24 } |
| 23 | 25 |
| 24 (function TestConstructor() { | 26 (function TestConstructor() { |
| 25 assertTrue(WebAssembly.Table instanceof Function); | 27 assertTrue(WebAssembly.Table instanceof Function); |
| 26 assertSame(WebAssembly.Table, WebAssembly.Table.prototype.constructor); | 28 assertSame(WebAssembly.Table, WebAssembly.Table.prototype.constructor); |
| 27 assertTrue(WebAssembly.Table.prototype.grow instanceof Function); | 29 assertTrue(WebAssembly.Table.prototype.grow instanceof Function); |
| 28 assertTrue(WebAssembly.Table.prototype.get instanceof Function); | 30 assertTrue(WebAssembly.Table.prototype.get instanceof Function); |
| 29 assertTrue(WebAssembly.Table.prototype.set instanceof Function); | 31 assertTrue(WebAssembly.Table.prototype.set instanceof Function); |
| 30 let desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, 'lengt
h'); | 32 let desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, 'lengt
h'); |
| 31 assertTrue(desc.get instanceof Function); | 33 assertTrue(desc.get instanceof Function); |
| 32 assertSame(undefined, desc.set); | 34 assertSame(undefined, desc.set); |
| 33 | 35 |
| 34 assertThrows(() => new WebAssembly.Table(), TypeError); | 36 assertThrows(() => new WebAssembly.Table(), TypeError); |
| 35 assertThrows(() => new WebAssembly.Table(1), TypeError); | 37 assertThrows(() => new WebAssembly.Table(1), TypeError); |
| 36 assertThrows(() => new WebAssembly.Table(""), TypeError); | 38 assertThrows(() => new WebAssembly.Table(""), TypeError); |
| 37 | 39 |
| 38 assertThrows(() => new WebAssembly.Table({}), TypeError); | 40 assertThrows(() => new WebAssembly.Table({}), TypeError); |
| 39 assertThrows(() => new WebAssembly.Table({initial: 10}), TypeError); | 41 assertThrows(() => new WebAssembly.Table({initial: 10}), TypeError); |
| 40 | 42 |
| 41 assertThrows(() => new WebAssembly.Table({element: 0, initial: 10}), TypeError
); | 43 assertThrows(() => new WebAssembly.Table({element: 0, initial: 10}), TypeError
); |
| 42 assertThrows(() => new WebAssembly.Table({element: "any", initial: 10}), TypeE
rror); | 44 assertThrows(() => new WebAssembly.Table({element: "any", initial: 10}), TypeE
rror); |
| 43 | 45 |
| 44 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: -1}), R
angeError); | 46 assertThrows(() => new WebAssembly.Table( |
| 45 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUi
nt32RangeValue}), RangeError); | 47 {element: "anyfunc", initial: -1}), RangeError); |
| 48 assertThrows(() => new WebAssembly.Table( |
| 49 {element: "anyfunc", initial: outOfUint32RangeValue}), RangeError); |
| 46 | 50 |
| 47 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: -1}), RangeError); | 51 assertThrows(() => new WebAssembly.Table( |
| 48 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: outOfUint32RangeValue}), RangeError); | 52 {element: "anyfunc", initial: 10, maximum: -1}), RangeError); |
| 49 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: 9}), RangeError); | 53 assertThrows(() => new WebAssembly.Table( |
| 50 | 54 {element: "anyfunc", initial: 10, maximum: outOfUint32RangeValue}), RangeErr
or); |
| 51 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi
mum: int32ButOob})); | 55 assertThrows(() => new WebAssembly.Table( |
| 56 {element: "anyfunc", initial: 10, maximum: 9}), RangeError); |
| 52 | 57 |
| 53 let table; | 58 let table; |
| 54 table = new WebAssembly.Table({element: "anyfunc", initial: 1}); | 59 table = new WebAssembly.Table({element: "anyfunc", initial: 1}); |
| 55 assertTableIsValid(table); | 60 assertTableIsValid(table); |
| 56 assertEquals(1, table.length); | 61 assertEquals(1, table.length); |
| 57 assertEquals(null, table.get(0)); | 62 assertEquals(null, table.get(0)); |
| 58 assertEquals(undefined, table[0]); | 63 assertEquals(undefined, table[0]); |
| 59 | 64 |
| 60 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); | 65 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); |
| 61 assertTableIsValid(table); | 66 assertTableIsValid(table); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 87 assertTableIsValid(table); | 92 assertTableIsValid(table); |
| 88 assertEquals(0, table.length); | 93 assertEquals(0, table.length); |
| 89 | 94 |
| 90 table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { retur
n "10" }}}); | 95 table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { retur
n "10" }}}); |
| 91 assertTableIsValid(table); | 96 assertTableIsValid(table); |
| 92 assertEquals(0, table.length); | 97 assertEquals(0, table.length); |
| 93 | 98 |
| 94 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefi
ned}); | 99 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefi
ned}); |
| 95 assertTableIsValid(table); | 100 assertTableIsValid(table); |
| 96 assertEquals(0, table.length); | 101 assertEquals(0, table.length); |
| 102 |
| 103 table = new WebAssembly.Table({element: "anyfunc", maximum: kMaxUint32}); |
| 104 assertTableIsValid(table); |
| 105 assertEquals(0, table.length); |
| 106 |
| 107 table = new WebAssembly.Table({element: "anyfunc", maximum: kV8MaxWasmTableSiz
e + 1}); |
| 108 assertTableIsValid(table); |
| 109 assertEquals(0, table.length); |
| 97 })(); | 110 })(); |
| 98 | 111 |
| 99 (function TestMaximumIsReadOnce() { | 112 (function TestMaximumIsReadOnce() { |
| 100 var a = true; | 113 var a = true; |
| 101 var desc = {element: "anyfunc", initial: 10}; | 114 var desc = {element: "anyfunc", initial: 10}; |
| 102 Object.defineProperty(desc, 'maximum', {get: function() { | 115 Object.defineProperty(desc, 'maximum', {get: function() { |
| 103 if (a) { | 116 if (a) { |
| 104 a = false; | 117 a = false; |
| 105 return 16; | 118 return 16; |
| 106 } | 119 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 table.grow(0); | 266 table.grow(0); |
| 254 check(table); | 267 check(table); |
| 255 table.grow(5); | 268 table.grow(5); |
| 256 check(table); | 269 check(table); |
| 257 table.grow(0); | 270 table.grow(0); |
| 258 check(table); | 271 check(table); |
| 259 assertThrows(() => table.grow(1), RangeError); | 272 assertThrows(() => table.grow(1), RangeError); |
| 260 assertThrows(() => table.grow(-10), RangeError); | 273 assertThrows(() => table.grow(-10), RangeError); |
| 261 | 274 |
| 262 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); | 275 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); |
| 276 |
| 277 table = new WebAssembly.Table( |
| 278 {element: "anyfunc", initial: 0, maximum: kV8MaxWasmTableSize}); |
| 279 table.grow(kV8MaxWasmTableSize); |
| 280 assertThrows(() => table.grow(1), RangeError); |
| 263 })(); | 281 })(); |
| OLD | NEW |