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

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

Issue 2977543002: [wasm] Allow full u32 range for table maximum in WebAssembly.Table constructor. (Closed)
Patch Set: [wasm] Allow full u32 range for table maximum in WebAssembly.Table constructor. Created 3 years, 5 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-objects.cc ('k') | no next file » | 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"); 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; 16 var kMaxUint32 = (4 * 1024 * 1024 * 1024) - 1;
17 var kMaxUint31 = (2 * 1024 * 1024 * 1024) - 1;
17 var kV8MaxWasmTableSize = 10000000; 18 var kV8MaxWasmTableSize = 10000000;
18 19
19 function assertTableIsValid(table) { 20 function assertTableIsValid(table, length) {
20 assertSame(WebAssembly.Table.prototype, table.__proto__); 21 assertSame(WebAssembly.Table.prototype, table.__proto__);
21 assertSame(WebAssembly.Table, table.constructor); 22 assertSame(WebAssembly.Table, table.constructor);
22 assertTrue(table instanceof Object); 23 assertTrue(table instanceof Object);
23 assertTrue(table instanceof WebAssembly.Table); 24 assertTrue(table instanceof WebAssembly.Table);
25 assertEquals(length, table.length);
24 } 26 }
25 27
26 (function TestConstructor() { 28 (function TestConstructor() {
27 assertTrue(WebAssembly.Table instanceof Function); 29 assertTrue(WebAssembly.Table instanceof Function);
28 assertSame(WebAssembly.Table, WebAssembly.Table.prototype.constructor); 30 assertSame(WebAssembly.Table, WebAssembly.Table.prototype.constructor);
29 assertTrue(WebAssembly.Table.prototype.grow instanceof Function); 31 assertTrue(WebAssembly.Table.prototype.grow instanceof Function);
30 assertTrue(WebAssembly.Table.prototype.get instanceof Function); 32 assertTrue(WebAssembly.Table.prototype.get instanceof Function);
31 assertTrue(WebAssembly.Table.prototype.set instanceof Function); 33 assertTrue(WebAssembly.Table.prototype.set instanceof Function);
32 let desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, 'lengt h'); 34 let desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, 'lengt h');
33 assertTrue(desc.get instanceof Function); 35 assertTrue(desc.get instanceof Function);
(...skipping 16 matching lines...) Expand all
50 52
51 assertThrows(() => new WebAssembly.Table( 53 assertThrows(() => new WebAssembly.Table(
52 {element: "anyfunc", initial: 10, maximum: -1}), RangeError); 54 {element: "anyfunc", initial: 10, maximum: -1}), RangeError);
53 assertThrows(() => new WebAssembly.Table( 55 assertThrows(() => new WebAssembly.Table(
54 {element: "anyfunc", initial: 10, maximum: outOfUint32RangeValue}), RangeErr or); 56 {element: "anyfunc", initial: 10, maximum: outOfUint32RangeValue}), RangeErr or);
55 assertThrows(() => new WebAssembly.Table( 57 assertThrows(() => new WebAssembly.Table(
56 {element: "anyfunc", initial: 10, maximum: 9}), RangeError); 58 {element: "anyfunc", initial: 10, maximum: 9}), RangeError);
57 59
58 let table; 60 let table;
59 table = new WebAssembly.Table({element: "anyfunc", initial: 1}); 61 table = new WebAssembly.Table({element: "anyfunc", initial: 1});
60 assertTableIsValid(table); 62 assertTableIsValid(table, 1);
61 assertEquals(1, table.length);
62 assertEquals(null, table.get(0)); 63 assertEquals(null, table.get(0));
63 assertEquals(undefined, table[0]); 64 assertEquals(undefined, table[0]);
64 65
65 table = new WebAssembly.Table({element: "anyfunc", initial: "2"}); 66 table = new WebAssembly.Table({element: "anyfunc", initial: "2"});
66 assertTableIsValid(table); 67 assertTableIsValid(table, 2);
67 assertEquals(2, table.length);
68 assertEquals(null, table.get(0)); 68 assertEquals(null, table.get(0));
69 assertEquals(null, table.get(1)); 69 assertEquals(null, table.get(1));
70 assertEquals(undefined, table[0]); 70 assertEquals(undefined, table[0]);
71 assertEquals(undefined, table[1]); 71 assertEquals(undefined, table[1]);
72 72
73 table = new WebAssembly.Table({element: "anyfunc", initial: {valueOf() { retur n "1" }}}); 73 table = new WebAssembly.Table({element: "anyfunc", initial: {valueOf() { retur n "1" }}});
74 assertTableIsValid(table); 74 assertTableIsValid(table, 1);
75 assertEquals(1, table.length);
76 assertEquals(null, table.get(0)); 75 assertEquals(null, table.get(0));
77 assertEquals(undefined, table[0]); 76 assertEquals(undefined, table[0]);
78 77
79 table = new WebAssembly.Table({element: "anyfunc", initial: undefined}); 78 table = new WebAssembly.Table({element: "anyfunc", initial: undefined});
80 assertTableIsValid(table); 79 assertTableIsValid(table, 0);
81 assertEquals(0, table.length);
82 80
83 table = new WebAssembly.Table({element: "anyfunc"}); 81 table = new WebAssembly.Table({element: "anyfunc"});
84 assertTableIsValid(table); 82 assertTableIsValid(table, 0);
85 assertEquals(0, table.length);
86 83
87 table = new WebAssembly.Table({element: "anyfunc", maximum: 10}); 84 table = new WebAssembly.Table({element: "anyfunc", maximum: 10});
88 assertTableIsValid(table); 85 assertTableIsValid(table, 0);
89 assertEquals(0, table.length);
90 86
91 table = new WebAssembly.Table({element: "anyfunc", maximum: "10"}); 87 table = new WebAssembly.Table({element: "anyfunc", maximum: "10"});
92 assertTableIsValid(table); 88 assertTableIsValid(table, 0);
93 assertEquals(0, table.length);
94 89
95 table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { retur n "10" }}}); 90 table = new WebAssembly.Table({element: "anyfunc", maximum: {valueOf() { retur n "10" }}});
96 assertTableIsValid(table); 91 assertTableIsValid(table, 0);
97 assertEquals(0, table.length);
98 92
99 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefi ned}); 93 table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: undefi ned});
100 assertTableIsValid(table); 94 assertTableIsValid(table, 0);
101 assertEquals(0, table.length); 95
96 table = new WebAssembly.Table({element: "anyfunc", maximum: kMaxUint31});
97 assertTableIsValid(table, 0);
102 98
103 table = new WebAssembly.Table({element: "anyfunc", maximum: kMaxUint32}); 99 table = new WebAssembly.Table({element: "anyfunc", maximum: kMaxUint32});
104 assertTableIsValid(table); 100 assertTableIsValid(table, 0);
105 assertEquals(0, table.length);
106 101
107 table = new WebAssembly.Table({element: "anyfunc", maximum: kV8MaxWasmTableSiz e + 1}); 102 table = new WebAssembly.Table({element: "anyfunc", maximum: kV8MaxWasmTableSiz e + 1});
108 assertTableIsValid(table); 103 assertTableIsValid(table, 0);
109 assertEquals(0, table.length);
110 })(); 104 })();
111 105
112 (function TestMaximumIsReadOnce() { 106 (function TestMaximumIsReadOnce() {
113 var a = true; 107 var a = true;
114 var desc = {element: "anyfunc", initial: 10}; 108 var desc = {element: "anyfunc", initial: 10};
115 Object.defineProperty(desc, 'maximum', {get: function() { 109 Object.defineProperty(desc, 'maximum', {get: function() {
116 if (a) { 110 if (a) {
117 a = false; 111 a = false;
118 return 16; 112 return 16;
119 } 113 }
120 else { 114 else {
121 // Change the return value on the second call so it throws. 115 // Change the return value on the second call so it throws.
122 return -1; 116 return -1;
123 } 117 }
124 }}); 118 }});
125 let table = new WebAssembly.Table(desc); 119 let table = new WebAssembly.Table(desc);
126 assertTableIsValid(table); 120 assertTableIsValid(table, 10);
127 })(); 121 })();
128 122
129 (function TestMaximumDoesHasProperty() { 123 (function TestMaximumDoesHasProperty() {
130 var hasPropertyWasCalled = false; 124 var hasPropertyWasCalled = false;
131 var desc = {element: "anyfunc", initial: 10}; 125 var desc = {element: "anyfunc", initial: 10};
132 var proxy = new Proxy({maximum: 16}, { 126 var proxy = new Proxy({maximum: 16}, {
133 has: function(target, name) { hasPropertyWasCalled = true; } 127 has: function(target, name) { hasPropertyWasCalled = true; }
134 }); 128 });
135 Object.setPrototypeOf(desc, proxy); 129 Object.setPrototypeOf(desc, proxy);
136 let table = new WebAssembly.Table(desc); 130 let table = new WebAssembly.Table(desc);
137 assertTableIsValid(table); 131 assertTableIsValid(table, 10);
138 })(); 132 })();
139 133
140 (function TestLength() { 134 (function TestLength() {
141 for (let i = 0; i < 10; ++i) { 135 for (let i = 0; i < 10; ++i) {
142 let table = new WebAssembly.Table({element: "anyfunc", initial: i}); 136 let table = new WebAssembly.Table({element: "anyfunc", initial: i});
143 assertEquals(i, table.length); 137 assertEquals(i, table.length);
144 } 138 }
145 139
146 assertThrows(() => WebAssembly.Table.prototype.length.call([]), TypeError); 140 assertThrows(() => WebAssembly.Table.prototype.length.call([]), TypeError);
147 })(); 141 })();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 assertThrows(() => table.grow(1), RangeError); 266 assertThrows(() => table.grow(1), RangeError);
273 assertThrows(() => table.grow(-10), RangeError); 267 assertThrows(() => table.grow(-10), RangeError);
274 268
275 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError); 269 assertThrows(() => WebAssembly.Table.prototype.grow.call([], 0), TypeError);
276 270
277 table = new WebAssembly.Table( 271 table = new WebAssembly.Table(
278 {element: "anyfunc", initial: 0, maximum: kV8MaxWasmTableSize}); 272 {element: "anyfunc", initial: 0, maximum: kV8MaxWasmTableSize});
279 table.grow(kV8MaxWasmTableSize); 273 table.grow(kV8MaxWasmTableSize);
280 assertThrows(() => table.grow(1), RangeError); 274 assertThrows(() => table.grow(1), RangeError);
281 })(); 275 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698