Chromium Code Reviews| 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); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 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({element: "anyfunc", initial: -1}), R angeError); |
| 45 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUi nt32RangeValue}), RangeError); | 47 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUi nt32RangeValue}), RangeError); |
| 46 | 48 |
| 47 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max imum: -1}), RangeError); | 49 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max imum: -1}), RangeError); |
| 48 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max imum: outOfUint32RangeValue}), RangeError); | 50 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); | 51 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 10, max imum: 9}), RangeError); |
| 50 | 52 |
| 51 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi mum: int32ButOob})); | |
| 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 assertEquals(undefined, table[0]); |
| 59 | 59 |
| 60 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); | 60 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); |
| 61 assertTableIsValid(table); | 61 assertTableIsValid(table); |
| 62 assertEquals(2, table.length); | 62 assertEquals(2, table.length); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 87 assertTableIsValid(table); | 87 assertTableIsValid(table); |
| 88 assertEquals(0, table.length); | 88 assertEquals(0, table.length); |
| 89 | 89 |
| 90 table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { retur n "10" }}}); | 90 table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { retur n "10" }}}); |
| 91 assertTableIsValid(table); | 91 assertTableIsValid(table); |
| 92 assertEquals(0, table.length); | 92 assertEquals(0, table.length); |
| 93 | 93 |
| 94 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefi ned}); | 94 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefi ned}); |
| 95 assertTableIsValid(table); | 95 assertTableIsValid(table); |
| 96 assertEquals(0, table.length); | 96 assertEquals(0, table.length); |
| 97 | |
| 98 table = new WebAssembly.Table({element: "anyfunc", maximum: kMaxUint32}); | |
| 99 assertTableIsValid(table); | |
| 100 assertEquals(0, table.length); | |
| 101 | |
| 102 table = new WebAssembly.Table({element: "anyfunc", maximum: kV8MaxWasmTableSiz e + 1}); | |
| 103 assertTableIsValid(table); | |
| 104 assertEquals(0, table.length); | |
| 97 })(); | 105 })(); |
| 98 | 106 |
| 99 (function TestMaximumIsReadOnce() { | 107 (function TestMaximumIsReadOnce() { |
| 100 var a = true; | 108 var a = true; |
| 101 var desc = {element: "anyfunc", initial: 10}; | 109 var desc = {element: "anyfunc", initial: 10}; |
| 102 Object.defineProperty(desc, 'maximum', {get: function() { | 110 Object.defineProperty(desc, 'maximum', {get: function() { |
| 103 if (a) { | 111 if (a) { |
| 104 a = false; | 112 a = false; |
| 105 return 16; | 113 return 16; |
| 106 } | 114 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 table.grow(0); | 261 table.grow(0); |
| 254 check(table); | 262 check(table); |
| 255 table.grow(5); | 263 table.grow(5); |
| 256 check(table); | 264 check(table); |
| 257 table.grow(0); | 265 table.grow(0); |
| 258 check(table); | 266 check(table); |
| 259 assertThrows(() => table.grow(1), RangeError); | 267 assertThrows(() => table.grow(1), RangeError); |
| 260 assertThrows(() => table.grow(-10), RangeError); | 268 assertThrows(() => table.grow(-10), RangeError); |
| 261 | 269 |
| 262 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); | 270 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); |
| 271 | |
| 272 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: kV8Max WasmTableSize}); | |
|
rossberg
2017/01/17 14:22:06
Nit: line length
titzer
2017/01/17 16:47:18
Done.
| |
| 273 table.grow(kV8MaxWasmTableSize); | |
| 274 assertThrows(() => table.grow(1), RangeError); | |
| 263 })(); | 275 })(); |
| OLD | NEW |