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

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

Issue 2367673003: [wasm] Do a proper HasProperty() check in the memory and table setup. (Closed)
Patch Set: Added tests also to table.js Created 4 years, 2 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 | « test/mjsunit/wasm/memory.js ('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 // Basic tests. 7 // Basic tests.
8 8
9 var outOfUint32RangeValue = 1e12; 9 var outOfUint32RangeValue = 1e12;
10 var int32ButOob = 1073741824; 10 var int32ButOob = 1073741824;
11 11
12 function assertTableIsValid(table) {
13 assertSame(WebAssembly.Table.prototype, table.__proto__);
14 assertSame(WebAssembly.Table, table.constructor);
15 assertTrue(table instanceof Object);
16 assertTrue(table instanceof WebAssembly.Table);
17 }
18
12 (function TestConstructor() { 19 (function TestConstructor() {
13 assertTrue(WebAssembly.Table instanceof Function); 20 assertTrue(WebAssembly.Table instanceof Function);
14 assertSame(WebAssembly.Table, WebAssembly.Table.prototype.constructor); 21 assertSame(WebAssembly.Table, WebAssembly.Table.prototype.constructor);
15 assertTrue(WebAssembly.Table.prototype.grow instanceof Function); 22 assertTrue(WebAssembly.Table.prototype.grow instanceof Function);
16 assertTrue(WebAssembly.Table.prototype.get instanceof Function); 23 assertTrue(WebAssembly.Table.prototype.get instanceof Function);
17 assertTrue(WebAssembly.Table.prototype.set instanceof Function); 24 assertTrue(WebAssembly.Table.prototype.set instanceof Function);
18 let desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, 'lengt h'); 25 let desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, 'lengt h');
19 assertTrue(desc.get instanceof Function); 26 assertTrue(desc.get instanceof Function);
20 assertSame(undefined, desc.set); 27 assertSame(undefined, desc.set);
21 28
(...skipping 10 matching lines...) Expand all
32 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: -1}), R angeError); 39 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: -1}), R angeError);
33 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUi nt32RangeValue}), RangeError); 40 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: outOfUi nt32RangeValue}), RangeError);
34 41
35 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);
36 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);
37 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);
38 45
39 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi mum: int32ButOob})); 46 assertThrows(() => new WebAssembly.Table({element: "anyfunc", initial: 0, maxi mum: int32ButOob}));
40 47
41 let table = new WebAssembly.Table({element: "anyfunc", initial: 1}); 48 let table = new WebAssembly.Table({element: "anyfunc", initial: 1});
42 assertSame(WebAssembly.Table.prototype, table.__proto__); 49 assertTableIsValid(table);
43 assertSame(WebAssembly.Table, table.constructor);
44 assertTrue(table instanceof Object);
45 assertTrue(table instanceof WebAssembly.Table);
46 })(); 50 })();
47 51
48 (function TestConstructorWithMaximum() { 52 (function TestConstructorWithMaximum() {
49 let table = new WebAssembly.Table({element: "anyfunc", initial: 1, maximum: 10 }); 53 let table = new WebAssembly.Table({element: "anyfunc", maximum: 10});
50 assertSame(WebAssembly.Table.prototype, table.__proto__); 54 assertTableIsValid(table);
51 assertSame(WebAssembly.Table, table.constructor);
52 assertTrue(table instanceof Object);
53 assertTrue(table instanceof WebAssembly.Table);
54 })(); 55 })();
56
57 (function TestInitialIsUndefined() {
58 // New memory with initial = undefined, which means initial = 0.
59 let table = new WebAssembly.Table({element: "anyfunc", initial: undefined});
60 assertTableIsValid(table);
61 })();
62
63 (function TestMaximumIsUndefined() {
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);
67 })();
68
69 (function TestMaximumIsReadOnce() {
70 var a = true;
71 var desc = {element: "anyfunc", initial: 10};
72 Object.defineProperty(desc, 'maximum', {get: function() {
73 if (a) {
74 a = false;
75 return 16;
76 }
77 else {
78 // Change the return value on the second call so it throws.
79 return -1;
80 }
81 }});
82 let table = new WebAssembly.Table(desc);
83 assertTableIsValid(table);
84 })();
85
86 (function TestMaximumDoesHasProperty() {
87 var hasPropertyWasCalled = false;
88 var desc = {element: "anyfunc", initial: 10};
89 var proxy = new Proxy({maximum: 16}, {
90 has: function(target, name) { hasPropertyWasCalled = true; }
91 });
92 Object.setPrototypeOf(desc, proxy);
93 let table = new WebAssembly.Table(desc);
94 assertTableIsValid(table);
95 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/memory.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698