mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibJS: Return undefined in Array.prototype.{pop,shift} for empty values
This commit is contained in:
parent
a220236cde
commit
d4ec38097f
Notes:
sideshowbarker
2024-07-19 07:11:59 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/d4ec38097f8 Pull-request: https://github.com/SerenityOS/serenity/pull/2012
3 changed files with 6 additions and 2 deletions
|
@ -207,7 +207,7 @@ Value ArrayPrototype::pop(Interpreter& interpreter)
|
|||
return {};
|
||||
if (array->elements().is_empty())
|
||||
return js_undefined();
|
||||
return array->elements().take_last();
|
||||
return array->elements().take_last().value_or(js_undefined());
|
||||
}
|
||||
|
||||
Value ArrayPrototype::shift(Interpreter& interpreter)
|
||||
|
@ -217,7 +217,7 @@ Value ArrayPrototype::shift(Interpreter& interpreter)
|
|||
return {};
|
||||
if (array->elements().is_empty())
|
||||
return js_undefined();
|
||||
return array->elements().take_first();
|
||||
return array->elements().take_first().value_or(js_undefined());
|
||||
}
|
||||
|
||||
static Value join_array_with_separator(Interpreter& interpreter, const Array& array, StringView separator)
|
||||
|
|
|
@ -13,6 +13,8 @@ try {
|
|||
assert(value === undefined);
|
||||
assert(a.length === 0);
|
||||
|
||||
assert([,].pop() === undefined);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
|
|
|
@ -13,6 +13,8 @@ try {
|
|||
assert(value === undefined);
|
||||
assert(a.length === 0);
|
||||
|
||||
assert([,].shift() === undefined);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
|
|
Loading…
Add table
Reference in a new issue