-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
LibWeb: Throw range error when initial is greater than maximum #6122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alimpfard
merged 1 commit into
LadybirdBrowser:master
from
me-it-is:fix-construct-out-of-range
Sep 10, 2025
+189
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Tests/LibWeb/Text/expected/wpt-import/wasm/jsapi/memory/constructor.any.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Harness status: OK | ||
|
||
Found 24 tests | ||
|
||
24 Pass | ||
Pass name | ||
Pass length | ||
Pass No arguments | ||
Pass Calling | ||
Pass Invalid descriptor argument | ||
Pass Undefined initial value in descriptor | ||
Pass Out-of-range initial value in descriptor: NaN | ||
Pass Out-of-range maximum value in descriptor: NaN | ||
Pass Out-of-range initial value in descriptor: Infinity | ||
Pass Out-of-range maximum value in descriptor: Infinity | ||
Pass Out-of-range initial value in descriptor: -Infinity | ||
Pass Out-of-range maximum value in descriptor: -Infinity | ||
Pass Out-of-range initial value in descriptor: -1 | ||
Pass Out-of-range maximum value in descriptor: -1 | ||
Pass Out-of-range initial value in descriptor: 4294967296 | ||
Pass Out-of-range maximum value in descriptor: 4294967296 | ||
Pass Out-of-range initial value in descriptor: 68719476736 | ||
Pass Out-of-range maximum value in descriptor: 68719476736 | ||
Pass Initial value exceeds maximum | ||
Pass Proxy descriptor | ||
Pass Order of evaluation for descriptor | ||
Pass Zero initial | ||
Pass Non-zero initial | ||
Pass Stray argument |
16 changes: 16 additions & 0 deletions
16
Tests/LibWeb/Text/input/wpt-import/wasm/jsapi/memory/constructor.any.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!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/assertions.js"></script> | ||
<script src="../../../wasm/jsapi/memory/assertions.js"></script> | ||
<div id=log></div> | ||
<script src="../../../wasm/jsapi/memory/constructor.any.js"></script> |
139 changes: 139 additions & 0 deletions
139
Tests/LibWeb/Text/input/wpt-import/wasm/jsapi/memory/constructor.any.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// META: global=window,dedicatedworker,jsshell,shadowrealm | ||
// META: script=/wasm/jsapi/assertions.js | ||
// META: script=/wasm/jsapi/memory/assertions.js | ||
|
||
test(() => { | ||
assert_function_name(WebAssembly.Memory, "Memory", "WebAssembly.Memory"); | ||
}, "name"); | ||
|
||
test(() => { | ||
assert_function_length(WebAssembly.Memory, 1, "WebAssembly.Memory"); | ||
}, "length"); | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => new WebAssembly.Memory()); | ||
}, "No arguments"); | ||
|
||
test(() => { | ||
const argument = { "initial": 0 }; | ||
assert_throws_js(TypeError, () => WebAssembly.Memory(argument)); | ||
}, "Calling"); | ||
|
||
test(() => { | ||
const invalidArguments = [ | ||
undefined, | ||
null, | ||
false, | ||
true, | ||
"", | ||
"test", | ||
Symbol(), | ||
1, | ||
NaN, | ||
{}, | ||
]; | ||
for (const invalidArgument of invalidArguments) { | ||
assert_throws_js(TypeError, | ||
() => new WebAssembly.Memory(invalidArgument), | ||
`new Memory(${format_value(invalidArgument)})`); | ||
} | ||
}, "Invalid descriptor argument"); | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => new WebAssembly.Memory({ "initial": undefined })); | ||
}, "Undefined initial value in descriptor"); | ||
|
||
const outOfRangeValues = [ | ||
NaN, | ||
Infinity, | ||
-Infinity, | ||
-1, | ||
0x100000000, | ||
0x1000000000, | ||
]; | ||
|
||
for (const value of outOfRangeValues) { | ||
test(() => { | ||
assert_throws_js(TypeError, () => new WebAssembly.Memory({ "initial": value })); | ||
}, `Out-of-range initial value in descriptor: ${format_value(value)}`); | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => new WebAssembly.Memory({ "initial": 0, "maximum": value })); | ||
}, `Out-of-range maximum value in descriptor: ${format_value(value)}`); | ||
} | ||
|
||
test(() => { | ||
assert_throws_js(RangeError, () => new WebAssembly.Memory({ "initial": 10, "maximum": 9 })); | ||
}, "Initial value exceeds maximum"); | ||
|
||
test(() => { | ||
const proxy = new Proxy({}, { | ||
has(o, x) { | ||
assert_unreached(`Should not call [[HasProperty]] with ${x}`); | ||
}, | ||
get(o, x) { | ||
// Due to the requirement not to supply both minimum and initial, we need to ignore one of them. | ||
switch (x) { | ||
case "shared": | ||
return false; | ||
case "initial": | ||
case "maximum": | ||
return 0; | ||
default: | ||
return undefined; | ||
} | ||
}, | ||
}); | ||
new WebAssembly.Memory(proxy); | ||
}, "Proxy descriptor"); | ||
|
||
test(() => { | ||
const order = []; | ||
|
||
new WebAssembly.Memory({ | ||
get maximum() { | ||
order.push("maximum"); | ||
return { | ||
valueOf() { | ||
order.push("maximum valueOf"); | ||
return 1; | ||
}, | ||
}; | ||
}, | ||
|
||
get initial() { | ||
order.push("initial"); | ||
return { | ||
valueOf() { | ||
order.push("initial valueOf"); | ||
return 1; | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
assert_array_equals(order, [ | ||
"initial", | ||
"initial valueOf", | ||
"maximum", | ||
"maximum valueOf", | ||
]); | ||
}, "Order of evaluation for descriptor"); | ||
|
||
test(() => { | ||
const argument = { "initial": 0 }; | ||
const memory = new WebAssembly.Memory(argument); | ||
assert_Memory(memory, { "size": 0 }); | ||
}, "Zero initial"); | ||
|
||
test(() => { | ||
const argument = { "initial": 4 }; | ||
const memory = new WebAssembly.Memory(argument); | ||
assert_Memory(memory, { "size": 4 }); | ||
}, "Non-zero initial"); | ||
|
||
test(() => { | ||
const argument = { "initial": 0 }; | ||
const memory = new WebAssembly.Memory(argument, {}); | ||
assert_Memory(memory, { "size": 0 }); | ||
}, "Stray argument"); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.