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

Unified Diff: test/mjsunit/wasm/memory.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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | test/mjsunit/wasm/table.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/memory.js
diff --git a/test/mjsunit/wasm/memory.js b/test/mjsunit/wasm/memory.js
index a90d44c41ad8607c166d853ea69be316f7e7f8b4..e86825bd27c7000a88c047e5b392d1e9e386b377 100644
--- a/test/mjsunit/wasm/memory.js
+++ b/test/mjsunit/wasm/memory.js
@@ -8,6 +8,13 @@
var outOfUint32RangeValue = 1e12;
+function assertMemoryIsValid(memory) {
+ assertSame(WebAssembly.Memory.prototype, memory.__proto__);
+ assertSame(WebAssembly.Memory, memory.constructor);
+ assertTrue(memory instanceof Object);
+ assertTrue(memory instanceof WebAssembly.Memory);
+}
+
(function TestConstructor() {
assertTrue(WebAssembly.Memory instanceof Function);
assertSame(WebAssembly.Memory, WebAssembly.Memory.prototype.constructor);
@@ -28,18 +35,53 @@ var outOfUint32RangeValue = 1e12;
assertThrows(() => new WebAssembly.Memory({initial: 10, maximum: 9}), RangeError);
let memory = new WebAssembly.Memory({initial: 1});
- assertSame(WebAssembly.Memory.prototype, memory.__proto__);
- assertSame(WebAssembly.Memory, memory.constructor);
- assertTrue(memory instanceof Object);
- assertTrue(memory instanceof WebAssembly.Memory);
+ assertMemoryIsValid(memory);
})();
(function TestConstructorWithMaximum() {
let memory = new WebAssembly.Memory({initial: 1, maximum: 10});
- assertSame(WebAssembly.Memory.prototype, memory.__proto__);
- assertSame(WebAssembly.Memory, memory.constructor);
- assertTrue(memory instanceof Object);
- assertTrue(memory instanceof WebAssembly.Memory);
+ assertMemoryIsValid(memory);
+})();
+
+(function TestInitialIsUndefined() {
+ // New memory with initial = undefined, which means initial = 0.
+ let memory = new WebAssembly.Memory({initial: undefined});
+ assertMemoryIsValid(memory);
+})();
+
+(function TestMaximumIsUndefined() {
+ // New memory with maximum = undefined, which means maximum = 0.
+ let memory = new WebAssembly.Memory({initial: 0, maximum: undefined});
+ assertMemoryIsValid(memory);
+})();
+
+(function TestMaximumIsReadOnce() {
+ var a = true;
+ var desc = {initial: 10};
+ Object.defineProperty(desc, 'maximum', {get: function() {
+ if (a) {
+ a = false;
+ return 16;
+ }
+ else {
+ // Change the return value on the second call so it throws.
+ return -1;
+ }
+ }});
+ let memory = new WebAssembly.Memory(desc);
+ assertMemoryIsValid(memory);
+})();
+
+(function TestMaximumDoesHasProperty() {
+ var hasPropertyWasCalled = false;
+ var desc = {initial: 10};
+ var proxy = new Proxy({maximum: 16}, {
+ has: function(target, name) { hasPropertyWasCalled = true; }
+ });
+ Object.setPrototypeOf(desc, proxy);
+ let memory = new WebAssembly.Memory(desc);
+ assertMemoryIsValid(memory);
+ assertTrue(hasPropertyWasCalled);
})();
(function TestBuffer() {
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | test/mjsunit/wasm/table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698