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

Side by Side Diff: test/mjsunit/wasm/import-memory.js

Issue 2410763002: [wasm] GrowMemory should use maximum size declared in WebAssembly.Memory (Closed)
Patch Set: Fix trybots, Brad's review 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 | « src/wasm/wasm-module.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 load("test/mjsunit/wasm/wasm-constants.js"); 7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js"); 8 load("test/mjsunit/wasm/wasm-module-builder.js");
9 9
10 (function TestOne() { 10 (function TestOne() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 for (var j = 0; j < 10; j++) { 75 for (var j = 0; j < 10; j++) {
76 var val = i + 99077 + j; 76 var val = i + 99077 + j;
77 i32[j] = val; 77 i32[j] = val;
78 assertEquals(val | 0, i1.exports.foo(j * 4)); 78 assertEquals(val | 0, i1.exports.foo(j * 4));
79 assertEquals(val | 0, i2.exports.bar(j * 4)); 79 assertEquals(val | 0, i2.exports.bar(j * 4));
80 } 80 }
81 } 81 }
82 })(); 82 })();
83 83
84 (function ValidateBoundsCheck() { 84 (function ValidateBoundsCheck() {
85 print("Validate bounds check"); 85 print("ValidateBoundsCheck");
86 let memory = new WebAssembly.Memory({initial: 1, maximum: 5}); 86 let memory = new WebAssembly.Memory({initial: 1, maximum: 5});
87 assertEquals(kPageSize, memory.buffer.byteLength); 87 assertEquals(kPageSize, memory.buffer.byteLength);
88 let i32 = new Int32Array(memory.buffer); 88 let i32 = new Int32Array(memory.buffer);
89 let builder = new WasmModuleBuilder(); 89 let builder = new WasmModuleBuilder();
90 // builder.addImportedMemory("mine"); 90 // builder.addImportedMemory("mine");
91 builder.addImportedMemory("mine"); 91 builder.addImportedMemory("mine");
92 builder.addFunction("load", kSig_i_i) 92 builder.addFunction("load", kSig_i_i)
93 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) 93 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
94 .exportFunc(); 94 .exportFunc();
95 builder.addFunction("store", kSig_i_ii) 95 builder.addFunction("store", kSig_i_ii)
96 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0, 96 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0,
97 kExprGetLocal, 1]) 97 kExprGetLocal, 1])
98 .exportFunc(); 98 .exportFunc();
99 var offset; 99 var offset;
100 let instance = builder.instantiate({mine: memory}); 100 let instance = builder.instantiate({mine: memory});
101 function load() { return instance.exports.load(offset); } 101 function load() { return instance.exports.load(offset); }
102 function store(value) { return instance.exports.store(offset, value); } 102 function store(value) { return instance.exports.store(offset, value); }
103 103
104 for (offset = 0; offset < kPageSize -3; offset+=4) { 104 for (offset = 0; offset < kPageSize - 3; offset+=4) {
105 store(offset); 105 store(offset);
106 } 106 }
107 for (offset = 0; offset < kPageSize - 3; offset+=4) { 107 for (offset = 0; offset < kPageSize - 3; offset+=4) {
108 assertEquals(offset, load()); 108 assertEquals(offset, load());
109 } 109 }
110 for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) { 110 for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) {
111 assertTraps(kTrapMemOutOfBounds, load); 111 assertTraps(kTrapMemOutOfBounds, load);
112 } 112 }
113 })(); 113 })();
114
115 (function TestGrowMemoryMaxDesc() {
116 print("MaximumDescriptor");
117 let memory = new WebAssembly.Memory({initial: 1, maximum: 5});
118 assertEquals(kPageSize, memory.buffer.byteLength);
119 let i32 = new Int32Array(memory.buffer);
120 let builder = new WasmModuleBuilder();
121 builder.addImportedMemory("mine", "", 0, 20);
122 builder.addFunction("load", kSig_i_i)
123 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
124 .exportFunc();
125 builder.addFunction("store", kSig_i_ii)
126 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0,
127 kExprGetLocal, 1])
128 .exportFunc();
129 var offset;
130 let instance = builder.instantiate({mine: memory});
131 function load() { return instance.exports.load(offset); }
132 function store(value) { return instance.exports.store(offset, value); }
133
134 for (var i = 1; i < 5; i++) {
135 for (offset = (i - 1) * kPageSize; offset < i * kPageSize - 3; offset+=4) {
136 store(offset * 2);
137 }
138 assertEquals(i, memory.grow(1));
139 assertEquals((i + 1) * kPageSize, memory.buffer.byteLength);
140 }
141 for (offset = 4 * kPageSize; offset < 5 * kPageSize - 3; offset+=4) {
142 store(offset * 2);
143 }
144 for (offset = 0; offset < 5 * kPageSize - 3; offset+=4) {
145 assertEquals(offset * 2, load());
146 }
147 for (offset = 5 * kPageSize; offset < 5 * kPageSize + 4; offset++) {
148 assertThrows(load);
149 }
150 assertThrows(() => memory.grow(1));
151 })();
152
153 (function TestGrowMemoryZeroInitialMemory() {
154 print("ZeroInitialMemory");
155 let memory = new WebAssembly.Memory({initial: 0});
156 assertEquals(0, memory.buffer.byteLength);
157 let i32 = new Int32Array(memory.buffer);
158 let builder = new WasmModuleBuilder();
159 builder.addImportedMemory("mine");
160 builder.addFunction("load", kSig_i_i)
161 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
162 .exportFunc();
163 builder.addFunction("store", kSig_i_ii)
164 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0,
165 kExprGetLocal, 1])
166 .exportFunc();
167 var offset;
168 let instance = builder.instantiate({mine: memory});
169 function load() { return instance.exports.load(offset); }
170 function store(value) { return instance.exports.store(offset, value); }
171
172 for (var i = 1; i < 5; i++) {
173 assertEquals(i - 1, memory.grow(1));
174 assertEquals(i * kPageSize, memory.buffer.byteLength);
175 for (offset = (i - 1) * kPageSize; offset < i * kPageSize - 3; offset++) {
176 store(offset * 2);
177 }
178 }
179 for (offset = 5 * kPageSize; offset < 5 * kPageSize + 4; offset++) {
180 assertThrows(load);
181 }
182 assertThrows(() => memory.grow(16381));
183 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698