1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00
serenity/Libraries/LibJS
Linus Groh 476094922b 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.
2020-05-18 09:39:55 +02:00
..
Heap LibJS: Be a bit more explicit about sizeof(buf) / sizeof(FlatPtr) 2020-05-08 21:02:47 +02:00
Runtime LibJS: Pass Interpreter& to Value::to_number() et al. 2020-05-18 09:39:55 +02:00
Tests LibJS: Pass Interpreter& to Value::to_number() et al. 2020-05-18 09:39:55 +02:00
AST.cpp LibJS: Pass Interpreter& to Value::to_number() et al. 2020-05-18 09:39:55 +02:00
AST.h LibJS: Check AssignmentExpression LHS in parser 2020-05-13 01:15:29 +02:00
CMakeLists.txt LibJS: Add symbol objects 2020-05-17 18:05:15 +02:00
Console.cpp LibJS: Add side-effect-free version of Value::to_string() 2020-05-15 13:50:42 +02:00
Console.h LibJS: Implement ConsoleClient 2020-05-05 09:15:16 +02:00
Forward.h LibJS: Add symbol objects 2020-05-17 18:05:15 +02:00
Interpreter.cpp LibJS: Add symbol objects 2020-05-17 18:05:15 +02:00
Interpreter.h LibJS: Add some helpers and use them to re-implement Console functions 2020-05-05 09:15:16 +02:00
Lexer.cpp LibJS: Remove syntax errors from lexer 2020-05-15 09:53:52 +02:00
Lexer.h LibJS: Remove syntax errors from lexer 2020-05-15 09:53:52 +02:00
Parser.cpp LibJS: Let parser keep track of errors 2020-05-15 09:53:52 +02:00
Parser.h LibJS: Let parser keep track of errors 2020-05-15 09:53:52 +02:00
Token.cpp LibJS: Add template literals 2020-05-04 16:46:31 +02:00
Token.h LibJS: Add missing keywords/tokens 2020-05-12 18:47:38 +02:00