nodejs/deps/v8/test/mjsunit/wasm/grow-huge-memory-resizable-buffer.js
Michaël Zasso 918fe04351
deps: update V8 to 13.6.233.8
PR-URL: https://github.com/nodejs/node/pull/58070
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2025-05-02 15:06:53 +02:00

47 lines
1.6 KiB
JavaScript

// Copyright 2025 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.
// Save some memory on Linux; other platforms ignore this flag.
// Flags: --multi-mapped-mock-allocator --experimental-wasm-rab-integration
// Test that we can grow memories to sizes beyond 2GB.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
function GetMemoryPages(memory) {
return memory.buffer.byteLength >>> 16;
}
(function TestGrowFromJSMemory() {
let mem = new WebAssembly.Memory({initial: 200, maximum: 50000});
mem.toResizableBuffer();
mem.grow(40000);
assertEquals(40200, GetMemoryPages(mem));
})();
(function TestGrowFromJSSAB() {
let mem = new WebAssembly.Memory({initial: 200, maximum: 50000});
let buf = mem.toResizableBuffer();
buf.resize(buf.byteLength + 40000 * kPageSize);
assertEquals(40200, GetMemoryPages(mem));
})();
(function TestGrowFromWasm() {
let builder = new WasmModuleBuilder();
builder.addMemory(200, 50000);
builder.exportMemoryAs("memory");
builder.addFunction("grow", kSig_i_v)
.addBody([
...wasmI32Const(40000), // Number of pages to grow by.
kExprMemoryGrow, kMemoryZero, // Grow memory.
kExprDrop, // Drop result of grow (old pages).
kExprMemorySize, kMemoryZero // Get the memory size.
]).exportFunc();
let instance = builder.instantiate();
instance.exports.memory.toResizableBuffer();
assertEquals(40200, instance.exports.grow());
assertEquals(40200, GetMemoryPages(instance.exports.memory));
})();