LibWeb: Throw range error when initial is greater than maximum

When constructing WebAssembly.Memory if initial is greater than maximum
a range error will be thrown.

Fixes "Initial value exceeds maximum" in
https://wpt.fyi/results/wasm/jsapi/memory/constructor.any.worker.html?product=ladybird
This commit is contained in:
me-it-is
2025-09-07 17:34:45 -07:00
committed by Ali Mohammad Pur
parent 6d3fd2b543
commit 62fe795c9b
Notes: github-actions[bot] 2025-09-10 03:24:12 +00:00
4 changed files with 189 additions and 0 deletions

View File

@@ -23,6 +23,11 @@ WebIDL::ExceptionOr<GC::Ref<Memory>> Memory::construct_impl(JS::Realm& realm, Me
auto& vm = realm.vm();
// https://webassembly.github.io/threads/js-api/index.html#dom-memory-memory
// 3. If maximum is not empty and maximum < initial, throw a RangeError exception.
if (descriptor.maximum.has_value() && descriptor.maximum.value() < descriptor.initial) {
return vm.throw_completion<JS::RangeError>("Initial is larger than maximum."sv);
}
// 4. Let share be shared if descriptor["shared"] is true and unshared otherwise.
// 5. If share is shared and maximum is empty, throw a TypeError exception.
auto shared = descriptor.shared.value_or(false);