mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 08:36:15 +00:00
LibJS: Pass Interpreter& to Value::to_number() et al.
This patch is unfortunately rather large and might make some things feel
bloated, but it is necessary to fix a few flaws in LibJS, primarily
blindly coercing values to numbers without exception checks - i.e.
interpreter.argument(0).to_i32(); // can fail!!!
Some examples where the interpreter would actually crash:
var o = { toString: () => { throw Error() } };
+o;
o - 1;
"foo".charAt(o);
"bar".repeat(o);
To fix this, we now have the following...
to_double(Interpreter&)
to_i32()
to_i32(Interpreter&)
to_size_t()
to_size_t(Interpreter&)
...and a whole lot of exception checking.
There's intentionally no to_double(), use as_double() directly instead.
This way we still can use these convenient utility functions but don't
need to check for exceptions if we are sure the value already is a
number.
Fixes #2267.
This commit is contained in:
committed by
Andreas Kling
parent
1a1394f7a2
commit
476094922b
@@ -941,11 +941,12 @@ Value UpdateExpression::execute(Interpreter& interpreter) const
|
||||
auto reference = m_argument->to_reference(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
||||
auto old_value = reference.get(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
old_value = old_value.to_number();
|
||||
old_value = old_value.to_number(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
||||
int op_result = 0;
|
||||
switch (m_op) {
|
||||
|
||||
Reference in New Issue
Block a user