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

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

Issue 2529573002: Revert of [wasm] WebAssembly.Memory object can be referenced by multiple Instance objects. (Closed)
Patch Set: Created 4 years, 1 month 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-objects.cc ('k') | test/mjsunit/wasm/instantiate-module-basic.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/import-memory.js
diff --git a/test/mjsunit/wasm/import-memory.js b/test/mjsunit/wasm/import-memory.js
index 3b70332f97bc5eb95d2dbd81135df3a89204d0c2..845da91d1d17bca6545d322edaeb05ef6ed9f49e 100644
--- a/test/mjsunit/wasm/import-memory.js
+++ b/test/mjsunit/wasm/import-memory.js
@@ -39,6 +39,7 @@
let instance = builder.instantiate({garg: memory});
assertSame(memory, instance.exports.daggle);
})();
+
(function TestImportExport() {
print("TestImportExport");
@@ -228,141 +229,3 @@
}
assertEquals(-1, instance.exports.grow(1));
})();
-
-(function TestMemoryGrowWebAssemblyInstances() {
- print("TestMemoryGrowWebAssemblyInstances");
- let memory = new WebAssembly.Memory({initial: 1, maximum: 15});
- var builder = new WasmModuleBuilder();
- builder.addImportedMemory("imported_mem");
- builder.addFunction("mem_size", kSig_i_v)
- .addBody([kExprMemorySize, kMemoryZero])
- .exportAs("mem_size");
- builder.addFunction("grow", kSig_i_i)
- .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
- .exportFunc();
- var module = new WebAssembly.Module(builder.toBuffer());
- var instances = [];
- for (var i = 0; i < 6; i++) {
- instances.push(new WebAssembly.Instance(module, {imported_mem: memory}));
- }
- function verify_mem_size(expected_pages) {
- assertEquals(expected_pages*kPageSize,
- memory.buffer.byteLength);
- for (var i = 0; i < 6; i++) {
- assertEquals(expected_pages, instances[i].exports.mem_size());
- }
- }
-
- // Verify initial memory size
- verify_mem_size(1);
-
- // Verify memory size with interleaving calls to Memory.grow,
- // GrowMemory opcode.
- var current_mem_size = 1;
- for (var i = 0; i < 5; i++) {
- function grow(pages) { return instances[i].exports.grow(pages); }
- assertEquals(current_mem_size, memory.grow(1));
- verify_mem_size(++current_mem_size);
- assertEquals(current_mem_size, instances[i].exports.grow(1));
- verify_mem_size(++current_mem_size);
- }
-
- assertThrows(() => memory.grow(5));
-})();
-
-(function TestImportedMemoryGrowMultipleInstances() {
- print("TestImportMemoryMultipleInstances");
- let memory = new WebAssembly.Memory({initial: 5, maximum: 100});
- var builder = new WasmModuleBuilder();
- builder.addImportedMemory("imported_mem");
- builder.addFunction("mem_size", kSig_i_v)
- .addBody([kExprMemorySize, kMemoryZero])
- .exportFunc();
- builder.addFunction("grow", kSig_i_i)
- .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
- .exportFunc();
- var instances = [];
- for (var i = 0; i < 5; i++) {
- instances.push(builder.instantiate({imported_mem: memory}));
- }
- function grow_instance_0(pages) { return instances[0].exports.grow(pages); }
- function grow_instance_1(pages) { return instances[1].exports.grow(pages); }
- function grow_instance_2(pages) { return instances[2].exports.grow(pages); }
- function grow_instance_3(pages) { return instances[3].exports.grow(pages); }
- function grow_instance_4(pages) { return instances[4].exports.grow(pages); }
-
- function verify_mem_size(expected_pages) {
- assertEquals(expected_pages*kPageSize, memory.buffer.byteLength);
- for (var i = 0; i < 5; i++) {
- assertEquals(expected_pages, instances[i].exports.mem_size());
- }
- }
-
- // Verify initial memory size
- verify_mem_size(5);
-
- // Grow instance memory and buffer memory out of order and verify memory is
- // updated correctly.
- assertEquals(5, grow_instance_0(7));
- verify_mem_size(12);
-
- assertEquals(12, memory.grow(4));
- verify_mem_size(16);
-
- assertEquals(16, grow_instance_4(1));
- verify_mem_size(17);
-
- assertEquals(17, grow_instance_1(6));
- verify_mem_size(23);
-
- assertEquals(23, grow_instance_3(2));
- verify_mem_size(25);
-
- assertEquals(25, memory.grow(10));
- verify_mem_size(35);
-
- assertEquals(35, grow_instance_2(15));
- verify_mem_size(50);
- assertThrows(() => memory.grow(51));
-})();
-
-(function TestExportImportedMemoryGrowMultipleInstances() {
- // TODO(gdeepti):Exported memory objects currently do not take max_size
- // into account so this can grow past the maximum specified in the exported
- // memory object. Assert that growing past maximum for exported objects fails.
- print("TestExportImportedMemoryGrowMultipleInstances");
- var instance;
- {
- let builder = new WasmModuleBuilder();
- builder.addMemory(1, 11, true);
- builder.exportMemoryAs("exported_mem");
- builder.addFunction("mem_size", kSig_i_v)
- .addBody([kExprMemorySize, kMemoryZero])
- .exportFunc();
- instance = builder.instantiate();
- }
- var builder = new WasmModuleBuilder();
- builder.addImportedMemory("imported_mem");
- builder.addFunction("mem_size", kSig_i_v)
- .addBody([kExprMemorySize, kMemoryZero])
- .exportFunc();
- builder.addFunction("grow", kSig_i_i)
- .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
- .exportFunc();
- var instances = [];
- for (var i = 0; i < 10; i++) {
- instances.push(builder.instantiate({
- imported_mem: instance.exports.exported_mem}));
- }
- function verify_mem_size(expected_pages) {
- for (var i = 0; i < 10; i++) {
- assertEquals(expected_pages, instances[i].exports.mem_size());
- }
- }
- var current_mem_size = 1;
- for (var i = 0; i < 10; i++) {
- function grow(pages) { return instances[i].exports.grow(pages); }
- assertEquals(current_mem_size, instances[i].exports.grow(1));
- verify_mem_size(++current_mem_size);
- }
-})();
« no previous file with comments | « src/wasm/wasm-objects.cc ('k') | test/mjsunit/wasm/instantiate-module-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698