mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibWeb: Import tests for resizable/growable ArrayBuffer Wasm memories
We pass to-fixed-length-buffer.any.html and to-resizable-buffer.any.html but not to-resizable-buffer-shared.any.html, because LibJS doesn't have growable SharedArrayBuffers implemented...
This commit is contained in:
committed by
Ali Mohammad Pur
parent
d0d5bffb2d
commit
7575beafcb
Notes:
github-actions[bot]
2025-08-23 06:27:35 +00:00
Author: https://github.com/CountBleck Commit: https://github.com/LadybirdBrowser/ladybird/commit/7575beafcb0 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5889 Reviewed-by: https://github.com/alimpfard ✅
@@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
|
||||
<script>
|
||||
self.GLOBAL = {
|
||||
isWindow: function() { return true; },
|
||||
isWorker: function() { return false; },
|
||||
isShadowRealm: function() { return false; },
|
||||
};
|
||||
</script>
|
||||
<script src="../../../resources/testharness.js"></script>
|
||||
<script src="../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../wasm/jsapi/wasm-module-builder.js"></script>
|
||||
<div id=log></div>
|
||||
<script src="../../../wasm/jsapi/memory/to-fixed-length-buffer.any.js"></script>
|
||||
@@ -0,0 +1,42 @@
|
||||
// META: global=window,dedicatedworker,jsshell
|
||||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
|
||||
test(() => {
|
||||
const thisValues = [
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
"",
|
||||
Symbol(),
|
||||
1,
|
||||
{},
|
||||
WebAssembly.Memory,
|
||||
WebAssembly.Memory.prototype,
|
||||
];
|
||||
|
||||
const desc = Object.getOwnPropertyDescriptor(WebAssembly.Memory.prototype, "toFixedLengthBuffer");
|
||||
assert_equals(typeof desc, "object");
|
||||
|
||||
const fun = desc.value;
|
||||
assert_equals(typeof desc.value, "function");
|
||||
|
||||
for (const thisValue of thisValues) {
|
||||
assert_throws_js(TypeError, () => fun.call(thisValue), `this=${format_value(thisValue)}`);
|
||||
}
|
||||
}, "API surface");
|
||||
|
||||
test(() => {
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: 1 });
|
||||
const buffer1 = memory.buffer;
|
||||
|
||||
assert_false(buffer1.resizable, "By default the AB is initially not resizable");
|
||||
|
||||
const buffer2 = memory.toFixedLengthBuffer();
|
||||
assert_equals(buffer1, buffer2, "Not changing resizability does not make a new object");
|
||||
|
||||
const buffer3 = memory.toResizableBuffer();
|
||||
assert_not_equals(buffer2, buffer3, "Changing resizability makes a new object");
|
||||
assert_true(buffer3.resizable);
|
||||
assert_true(buffer2.detached);
|
||||
assert_equals(memory.buffer, buffer3);
|
||||
}, "toFixedLengthBuffer caching behavior");
|
||||
@@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
|
||||
<script>
|
||||
self.GLOBAL = {
|
||||
isWindow: function() { return true; },
|
||||
isWorker: function() { return false; },
|
||||
isShadowRealm: function() { return false; },
|
||||
};
|
||||
</script>
|
||||
<script src="../../../resources/testharness.js"></script>
|
||||
<script src="../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../wasm/jsapi/wasm-module-builder.js"></script>
|
||||
<div id=log></div>
|
||||
<script src="../../../wasm/jsapi/memory/to-resizable-buffer-shared.any.js"></script>
|
||||
@@ -0,0 +1,36 @@
|
||||
// META: global=window,dedicatedworker,jsshell
|
||||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
|
||||
test(() => {
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: 4, shared: true });
|
||||
const buffer1 = memory.buffer;
|
||||
|
||||
assert_false(buffer1.growable, "By default the SAB is initially not growable");
|
||||
|
||||
const buffer2 = memory.toResizableBuffer();
|
||||
assert_true(buffer2.growable);
|
||||
assert_not_equals(buffer1, buffer2, "Changing resizability makes a new object");
|
||||
assert_equals(memory.buffer, buffer2, "The buffer created by the most recent toFooBuffer call is cached");
|
||||
|
||||
const buffer3 = memory.toResizableBuffer();
|
||||
assert_equals(buffer2, buffer3, "toResizableBuffer does nothing if buffer is already resizable")
|
||||
assert_equals(memory.buffer, buffer3);
|
||||
}, "toResizableBuffer caching behavior");
|
||||
|
||||
test(() => {
|
||||
const maxNumPages = 4;
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: maxNumPages, shared: true });
|
||||
const buffer = memory.toResizableBuffer();
|
||||
assert_equals(buffer.maxByteLength, kPageSize * maxNumPages, "Memory maximum is same as maxByteLength");
|
||||
}, "toResizableBuffer max size");
|
||||
|
||||
test(() => {
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: 4, shared: true });
|
||||
const buffer = memory.toResizableBuffer();
|
||||
|
||||
assert_equals(buffer.byteLength, 0);
|
||||
buffer.grow(2 * kPageSize);
|
||||
assert_equals(buffer.byteLength, 2 * kPageSize);
|
||||
|
||||
assert_throws_js(RangeError, () => buffer.grow(3 * kPageSize - 1), "Can only grow by page multiples");
|
||||
}, "Resizing a Memory's resizable buffer");
|
||||
@@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
|
||||
<script>
|
||||
self.GLOBAL = {
|
||||
isWindow: function() { return true; },
|
||||
isWorker: function() { return false; },
|
||||
isShadowRealm: function() { return false; },
|
||||
};
|
||||
</script>
|
||||
<script src="../../../resources/testharness.js"></script>
|
||||
<script src="../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../wasm/jsapi/wasm-module-builder.js"></script>
|
||||
<div id=log></div>
|
||||
<script src="../../../wasm/jsapi/memory/to-resizable-buffer.any.js"></script>
|
||||
@@ -0,0 +1,72 @@
|
||||
// META: global=window,dedicatedworker,jsshell
|
||||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
|
||||
test(() => {
|
||||
const thisValues = [
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
"",
|
||||
Symbol(),
|
||||
1,
|
||||
{},
|
||||
WebAssembly.Memory,
|
||||
WebAssembly.Memory.prototype,
|
||||
];
|
||||
|
||||
const desc = Object.getOwnPropertyDescriptor(WebAssembly.Memory.prototype, "toResizableBuffer");
|
||||
assert_equals(typeof desc, "object");
|
||||
|
||||
const fun = desc.value;
|
||||
assert_equals(typeof desc.value, "function");
|
||||
|
||||
for (const thisValue of thisValues) {
|
||||
assert_throws_js(TypeError, () => fun.call(thisValue), `this=${format_value(thisValue)}`);
|
||||
}
|
||||
}, "API surface");
|
||||
|
||||
test(() => {
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: 1 });
|
||||
const buffer1 = memory.buffer;
|
||||
|
||||
assert_false(buffer1.resizable, "By default the AB is initially not resizable");
|
||||
|
||||
const buffer2 = memory.toResizableBuffer();
|
||||
assert_true(buffer2.resizable);
|
||||
assert_not_equals(buffer1, buffer2, "Changing resizability makes a new object");
|
||||
assert_true(buffer1.detached);
|
||||
assert_equals(memory.buffer, buffer2, "The buffer created by the most recent toFooBuffer call is cached");
|
||||
|
||||
const buffer3 = memory.toResizableBuffer();
|
||||
assert_equals(buffer2, buffer3, "toResizableBuffer does nothing if buffer is already resizable")
|
||||
assert_equals(memory.buffer, buffer3);
|
||||
|
||||
}, "toResizableBuffer caching behavior");
|
||||
|
||||
test(() => {
|
||||
{
|
||||
const maxNumPages = 4;
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: maxNumPages });
|
||||
const buffer = memory.toResizableBuffer();
|
||||
assert_equals(buffer.maxByteLength, kPageSize * maxNumPages, "Memory maximum is same as maxByteLength");
|
||||
}
|
||||
}, "toResizableBuffer max size");
|
||||
|
||||
test(() => {
|
||||
const maxNumPages = 4;
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: maxNumPages });
|
||||
const buffer = memory.toResizableBuffer();
|
||||
|
||||
assert_equals(buffer.byteLength, 0);
|
||||
buffer.resize(2 * kPageSize);
|
||||
assert_equals(buffer.byteLength, 2 * kPageSize);
|
||||
|
||||
assert_throws_js(RangeError, () => buffer.resize(3 * kPageSize - 1), "Can only grow by page multiples");
|
||||
assert_throws_js(RangeError, () => buffer.resize(1 * kPageSize), "Cannot shrink");
|
||||
}, "Resizing a Memory's resizable buffer");
|
||||
|
||||
test(() => {
|
||||
const memory = new WebAssembly.Memory({ initial: 0, maximum: 1 });
|
||||
const buffer = memory.toResizableBuffer();
|
||||
assert_throws_js(TypeError, () => buffer.transfer(), "Cannot be detached by JS");
|
||||
}, "Resizable buffers from Memory cannot be detached by JS");
|
||||
Reference in New Issue
Block a user