mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 03:57:35 +00:00
LibJS+LibWeb: Move native JS functions into dedicated member functions
Instead of implementing every native function as a lambda function, use static member functions instead. This makes it easier to navigate the code + backtraces look nicer. :^)
This commit is contained in:
parent
7c4e53f31e
commit
56936b97d0
20 changed files with 233 additions and 149 deletions
|
@ -13,17 +13,10 @@ namespace JS {
|
|||
|
||||
GlobalObject::GlobalObject()
|
||||
{
|
||||
put_native_function("gc", gc);
|
||||
put_native_function("isNaN", is_nan);
|
||||
|
||||
put("console", heap().allocate<ConsoleObject>());
|
||||
put_native_function("gc", [](Interpreter& interpreter) -> Value {
|
||||
dbg() << "Forced garbage collection requested!";
|
||||
interpreter.heap().collect_garbage();
|
||||
return js_undefined();
|
||||
});
|
||||
put_native_function("isNaN", [](Interpreter& interpreter) -> Value {
|
||||
if (interpreter.call_frame().arguments.size() < 1)
|
||||
return js_undefined();
|
||||
return Value(interpreter.call_frame().arguments[0].to_number().is_nan());
|
||||
});
|
||||
put("Math", heap().allocate<MathObject>());
|
||||
put("Object", heap().allocate<ObjectConstructor>());
|
||||
}
|
||||
|
@ -32,4 +25,18 @@ GlobalObject::~GlobalObject()
|
|||
{
|
||||
}
|
||||
|
||||
Value GlobalObject::gc(Interpreter& interpreter)
|
||||
{
|
||||
dbg() << "Forced garbage collection requested!";
|
||||
interpreter.heap().collect_garbage();
|
||||
return js_undefined();
|
||||
}
|
||||
|
||||
Value GlobalObject::is_nan(Interpreter& interpreter)
|
||||
{
|
||||
if (interpreter.call_frame().arguments.size() < 1)
|
||||
return js_undefined();
|
||||
return Value(interpreter.call_frame().arguments[0].to_number().is_nan());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue