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

Unified Diff: test/mjsunit/wasm/memory.js

Issue 2350643003: [wasm] Set up Table and Memory constructors (Closed)
Patch Set: Address comments 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 | « test/common/wasm/wasm-module-runner.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
new file mode 100644
index 0000000000000000000000000000000000000000..a90d44c41ad8607c166d853ea69be316f7e7f8b4
--- /dev/null
+++ b/test/mjsunit/wasm/memory.js
@@ -0,0 +1,51 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-wasm
+
+// Basic tests.
+
+var outOfUint32RangeValue = 1e12;
+
+(function TestConstructor() {
+ assertTrue(WebAssembly.Memory instanceof Function);
+ assertSame(WebAssembly.Memory, WebAssembly.Memory.prototype.constructor);
+ assertTrue(WebAssembly.Memory.prototype.grow instanceof Function);
+ let desc = Object.getOwnPropertyDescriptor(WebAssembly.Memory.prototype, 'buffer');
+ assertTrue(desc.get instanceof Function);
+ assertSame(undefined, desc.set);
+
+ assertThrows(() => new WebAssembly.Memory(), TypeError);
+ assertThrows(() => new WebAssembly.Memory(1), TypeError);
+ assertThrows(() => new WebAssembly.Memory(""), TypeError);
+
+ assertThrows(() => new WebAssembly.Memory({initial: -1}), RangeError);
+ assertThrows(() => new WebAssembly.Memory({initial: outOfUint32RangeValue}), RangeError);
+
+ assertThrows(() => new WebAssembly.Memory({initial: 10, maximum: -1}), RangeError);
+ assertThrows(() => new WebAssembly.Memory({initial: 10, maximum: outOfUint32RangeValue}), RangeError);
+ 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);
+})();
+
+(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);
+})();
+
+(function TestBuffer() {
+ let memory = new WebAssembly.Memory({initial: 1});
+ assertTrue(memory.buffer instanceof Object);
+ assertTrue(memory.buffer instanceof ArrayBuffer);
+ assertThrows(() => {'use strict'; memory.buffer = memory.buffer}, TypeError)
+ assertThrows(() => ({__proto__: memory}).buffer, TypeError)
+})();
« no previous file with comments | « test/common/wasm/wasm-module-runner.cc ('k') | test/mjsunit/wasm/table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698