| 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 // Basic tests. | 7 // Basic tests. |
| 8 | 8 |
| 9 var outOfUint32RangeValue = 1e12; | 9 var outOfUint32RangeValue = 1e12; |
| 10 var int32ButOob = 1073741824; | 10 var int32ButOob = 1073741824; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: -1}), R
angeError); | 39 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: -1}), R
angeError); |
| 40 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUi
nt32RangeValue}), RangeError); | 40 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUi
nt32RangeValue}), RangeError); |
| 41 | 41 |
| 42 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: -1}), RangeError); | 42 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: -1}), RangeError); |
| 43 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: outOfUint32RangeValue}), RangeError); | 43 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: outOfUint32RangeValue}), RangeError); |
| 44 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: 9}), RangeError); | 44 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max
imum: 9}), RangeError); |
| 45 | 45 |
| 46 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi
mum: int32ButOob})); | 46 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi
mum: int32ButOob})); |
| 47 | 47 |
| 48 let table = new WebAssembly.Table({element: "anyfunc", initial: 1}); | 48 let table; |
| 49 table = new WebAssembly.Table({element: "anyfunc", initial: 1}); |
| 49 assertTableIsValid(table); | 50 assertTableIsValid(table); |
| 50 })(); | 51 assertEquals(1, table.length); |
| 52 assertEquals(null, table.get(0)); |
| 51 | 53 |
| 52 (function TestConstructorWithMaximum() { | 54 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); |
| 53 let table = new WebAssembly.Table({element: "anyfunc", maximum: 10}); | |
| 54 assertTableIsValid(table); | 55 assertTableIsValid(table); |
| 55 })(); | 56 assertEquals(2, table.length); |
| 57 assertEquals(null, table.get(0)); |
| 58 assertEquals(null, table.get(1)); |
| 56 | 59 |
| 57 (function TestInitialIsUndefined() { | 60 table = new WebAssembly.Table({element: "anyfunc", initial: {valueOf() { retur
n "1" }}}); |
| 58 // New memory with initial = undefined, which means initial = 0. | |
| 59 let table = new WebAssembly.Table({element: "anyfunc", initial: undefined}); | |
| 60 assertTableIsValid(table); | 61 assertTableIsValid(table); |
| 61 })(); | 62 assertEquals(1, table.length); |
| 63 assertEquals(null, table.get(0)); |
| 62 | 64 |
| 63 (function TestMaximumIsUndefined() { | 65 table = new WebAssembly.Table({element: "anyfunc", initial: undefined}); |
| 64 // New memory with maximum = undefined, which means maximum = 0. | |
| 65 let table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: un
defined}); | |
| 66 assertTableIsValid(table); | 66 assertTableIsValid(table); |
| 67 assertEquals(0, table.length); |
| 68 |
| 69 table = new WebAssembly.Table({element: "anyfunc"}); |
| 70 assertTableIsValid(table); |
| 71 assertEquals(0, table.length); |
| 72 |
| 73 table = new WebAssembly.Table({element: "anyfunc", maximum: 10}); |
| 74 assertTableIsValid(table); |
| 75 assertEquals(0, table.length); |
| 76 |
| 77 table = new WebAssembly.Table({element: "anyfunc", maximum: "10"}); |
| 78 assertTableIsValid(table); |
| 79 assertEquals(0, table.length); |
| 80 |
| 81 table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { retur
n "10" }}}); |
| 82 assertTableIsValid(table); |
| 83 assertEquals(0, table.length); |
| 84 |
| 85 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefi
ned}); |
| 86 assertTableIsValid(table); |
| 87 assertEquals(0, table.length); |
| 67 })(); | 88 })(); |
| 68 | 89 |
| 69 (function TestMaximumIsReadOnce() { | 90 (function TestMaximumIsReadOnce() { |
| 70 var a = true; | 91 var a = true; |
| 71 var desc = {element: "anyfunc", initial: 10}; | 92 var desc = {element: "anyfunc", initial: 10}; |
| 72 Object.defineProperty(desc, 'maximum', {get: function() { | 93 Object.defineProperty(desc, 'maximum', {get: function() { |
| 73 if (a) { | 94 if (a) { |
| 74 a = false; | 95 a = false; |
| 75 return 16; | 96 return 16; |
| 76 } | 97 } |
| 77 else { | 98 else { |
| 78 // Change the return value on the second call so it throws. | 99 // Change the return value on the second call so it throws. |
| 79 return -1; | 100 return -1; |
| 80 } | 101 } |
| 81 }}); | 102 }}); |
| 82 let table = new WebAssembly.Table(desc); | 103 let table = new WebAssembly.Table(desc); |
| 83 assertTableIsValid(table); | 104 assertTableIsValid(table); |
| 84 })(); | 105 })(); |
| 85 | 106 |
| 86 (function TestMaximumDoesHasProperty() { | 107 (function TestMaximumDoesHasProperty() { |
| 87 var hasPropertyWasCalled = false; | 108 var hasPropertyWasCalled = false; |
| 88 var desc = {element: "anyfunc", initial: 10}; | 109 var desc = {element: "anyfunc", initial: 10}; |
| 89 var proxy = new Proxy({maximum: 16}, { | 110 var proxy = new Proxy({maximum: 16}, { |
| 90 has: function(target, name) { hasPropertyWasCalled = true; } | 111 has: function(target, name) { hasPropertyWasCalled = true; } |
| 91 }); | 112 }); |
| 92 Object.setPrototypeOf(desc, proxy); | 113 Object.setPrototypeOf(desc, proxy); |
| 93 let table = new WebAssembly.Table(desc); | 114 let table = new WebAssembly.Table(desc); |
| 94 assertTableIsValid(table); | 115 assertTableIsValid(table); |
| 95 })(); | 116 })(); |
| 117 |
| 118 (function TestLength() { |
| 119 for (let i = 0; i < 10; ++i) { |
| 120 let table = new WebAssembly.Table({element: "anyfunc", initial: i}); |
| 121 assertEquals(i, table.length); |
| 122 } |
| 123 |
| 124 assertThrows(() => WebAssembly.Table.prototype.length.call([]), TypeError); |
| 125 })(); |
| 126 |
| 127 (function TestGet() { |
| 128 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); |
| 129 |
| 130 for (let i = 0; i < 10; ++i) { |
| 131 assertEquals(null, table.get(i)); |
| 132 assertEquals(null, table.get(String(i))); |
| 133 } |
| 134 assertEquals(null, table.get("")); |
| 135 assertEquals(null, table.get(NaN)); |
| 136 assertEquals(null, table.get({})); |
| 137 assertEquals(null, table.get([])); |
| 138 assertEquals(null, table.get(() => {})); |
| 139 |
| 140 assertEquals(undefined, table.get(10)); |
| 141 assertEquals(undefined, table.get(-1)); |
| 142 |
| 143 assertThrows(() => table.get(Symbol()), TypeError); |
| 144 assertThrows(() => WebAssembly.Table.prototype.get.call([], 0), TypeError); |
| 145 })(); |
| OLD | NEW |