1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibJS: More Interpreter::global_object() removal

Also let's settle on calling the operation of fetching the "this" value
from the Interpreter and converting it to a specific Object pointer
typed_this() since consistency is nice.
This commit is contained in:
Andreas Kling 2020-06-20 16:25:12 +02:00
parent a9e4babdaf
commit cd14ebb11f
7 changed files with 55 additions and 55 deletions

View file

@ -49,7 +49,7 @@ Array::~Array()
{
}
Array* array_from(Interpreter& interpreter, GlobalObject& global_object)
Array* Array::typed_this(Interpreter& interpreter, GlobalObject& global_object)
{
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
@ -63,7 +63,7 @@ Array* array_from(Interpreter& interpreter, GlobalObject& global_object)
JS_DEFINE_NATIVE_GETTER(Array::length_getter)
{
auto* array = array_from(interpreter, interpreter.global_object());
auto* array = typed_this(interpreter, global_object);
if (!array)
return {};
return Value(static_cast<i32>(array->indexed_properties().array_like_size()));
@ -71,7 +71,7 @@ JS_DEFINE_NATIVE_GETTER(Array::length_getter)
JS_DEFINE_NATIVE_SETTER(Array::length_setter)
{
auto* array = array_from(interpreter, global_object);
auto* array = typed_this(interpreter, global_object);
if (!array)
return;
auto length = value.to_number(interpreter);

View file

@ -30,8 +30,6 @@
namespace JS {
Array* array_from(Interpreter&, GlobalObject&);
class Array final : public Object {
public:
static Array* create(GlobalObject&);
@ -39,6 +37,8 @@ public:
explicit Array(Object& prototype);
virtual ~Array() override;
static Array* typed_this(Interpreter&, GlobalObject&);
private:
virtual const char* class_name() const override { return "Array"; }
virtual bool is_array() const override { return true; }

View file

@ -213,7 +213,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift)
{
auto* array = array_from(interpreter, global_object);
auto* array = Array::typed_this(interpreter, global_object);
if (!array)
return {};
for (size_t i = 0; i < interpreter.argument_count(); ++i)
@ -252,7 +252,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift)
{
auto* array = array_from(interpreter, global_object);
auto* array = Array::typed_this(interpreter, global_object);
if (!array)
return {};
if (array->indexed_properties().is_empty())
@ -340,7 +340,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
{
auto* array = array_from(interpreter, global_object);
auto* array = Array::typed_this(interpreter, global_object);
if (!array)
return {};
@ -366,7 +366,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice)
{
auto* array = array_from(interpreter, global_object);
auto* array = Array::typed_this(interpreter, global_object);
if (!array)
return {};
@ -560,7 +560,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse)
{
auto* array = array_from(interpreter, global_object);
auto* array = Array::typed_this(interpreter, global_object);
if (!array)
return {};

View file

@ -36,9 +36,9 @@
namespace JS {
static Date* this_date_from_interpreter(Interpreter& interpreter)
static Date* typed_this(Interpreter& interpreter, GlobalObject& global_object)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return nullptr;
if (!this_object->is_date()) {
@ -76,7 +76,7 @@ DatePrototype::~DatePrototype()
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto date = this_object->datetime().day();
@ -85,7 +85,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto day = this_object->datetime().weekday();
@ -94,7 +94,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto full_year = this_object->datetime().year();
@ -103,7 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto hours = this_object->datetime().hour();
@ -112,7 +112,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto milliseconds = this_object->milliseconds();
@ -121,7 +121,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto minutes = this_object->datetime().minute();
@ -130,7 +130,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto months = this_object->datetime().month() - 1;
@ -139,7 +139,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto seconds = this_object->datetime().second();
@ -148,7 +148,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto seconds = this_object->datetime().timestamp();
@ -158,7 +158,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto string = this_object->date_string();
@ -167,7 +167,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto string = this_object->time_string();
@ -176,7 +176,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string)
{
auto* this_object = this_date_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto string = this_object->string();

View file

@ -35,9 +35,9 @@
namespace JS {
static ScriptFunction* script_function_from(Interpreter& interpreter)
static ScriptFunction* typed_this(Interpreter& interpreter, GlobalObject& global_object)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return nullptr;
if (!this_object->is_function()) {
@ -132,7 +132,7 @@ Value ScriptFunction::construct(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter)
{
auto* function = script_function_from(interpreter);
auto* function = typed_this(interpreter, global_object);
if (!function)
return {};
return Value(static_cast<i32>(function->m_function_length));
@ -140,7 +140,7 @@ JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter)
JS_DEFINE_NATIVE_GETTER(ScriptFunction::name_getter)
{
auto* function = script_function_from(interpreter);
auto* function = typed_this(interpreter, global_object);
if (!function)
return {};
return js_string(interpreter, function->name().is_null() ? "" : function->name());

View file

@ -39,9 +39,9 @@
namespace JS {
static StringObject* string_object_from(Interpreter& interpreter)
static StringObject* typed_this(Interpreter& interpreter, GlobalObject& global_object)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return nullptr;
if (!this_object->is_string_object()) {
@ -51,9 +51,9 @@ static StringObject* string_object_from(Interpreter& interpreter)
return static_cast<StringObject*>(this_object);
}
static String string_from(Interpreter& interpreter)
static String ak_string_from(Interpreter& interpreter, GlobalObject& global_object)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
return Value(this_object).to_string(interpreter);
@ -94,7 +94,7 @@ StringPrototype::~StringPrototype()
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
i32 index = 0;
@ -110,7 +110,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
if (!interpreter.argument_count())
@ -133,7 +133,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
if (!interpreter.argument_count())
@ -160,7 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
auto needle = interpreter.argument(0).to_string(interpreter);
@ -171,7 +171,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
return js_string(interpreter, string.to_lowercase());
@ -179,7 +179,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
return js_string(interpreter, string.to_uppercase());
@ -187,7 +187,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase)
JS_DEFINE_NATIVE_GETTER(StringPrototype::length_getter)
{
auto* string_object = string_object_from(interpreter);
auto* string_object = typed_this(interpreter, global_object);
if (!string_object)
return {};
return Value((i32)string_object->primitive_string().string().length());
@ -195,7 +195,7 @@ JS_DEFINE_NATIVE_GETTER(StringPrototype::length_getter)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_string)
{
auto* string_object = string_object_from(interpreter);
auto* string_object = typed_this(interpreter, global_object);
if (!string_object)
return {};
return js_string(interpreter, string_object->primitive_string().string());
@ -237,7 +237,7 @@ static Value pad_string(Interpreter& interpreter, const String& string, PadPlace
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_start)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
return pad_string(interpreter, string, PadPlacement::Start);
@ -245,7 +245,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_start)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_end)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
return pad_string(interpreter, string, PadPlacement::End);
@ -253,7 +253,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_end)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
return js_string(interpreter, string.trim_whitespace(String::TrimMode::Both));
@ -261,7 +261,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_start)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
return js_string(interpreter, string.trim_whitespace(String::TrimMode::Left));
@ -269,7 +269,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_start)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_end)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
return js_string(interpreter, string.trim_whitespace(String::TrimMode::Right));
@ -277,7 +277,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_end)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
StringBuilder builder;
@ -293,7 +293,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
if (interpreter.argument_count() == 0)
@ -328,7 +328,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
auto search_string = interpreter.argument(0).to_string(interpreter);
@ -354,7 +354,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};
@ -397,7 +397,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of)
{
auto string = string_from(interpreter);
auto string = ak_string_from(interpreter, global_object);
if (string.is_null())
return {};

View file

@ -56,9 +56,9 @@ SymbolPrototype::~SymbolPrototype()
{
}
static SymbolObject* this_symbol_from_interpreter(Interpreter& interpreter)
static SymbolObject* typed_this(Interpreter& interpreter, GlobalObject& global_object)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return nullptr;
if (!this_object->is_symbol_object()) {
@ -70,7 +70,7 @@ static SymbolObject* this_symbol_from_interpreter(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter)
{
auto* this_object = this_symbol_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
return js_string(interpreter, this_object->description());
@ -78,7 +78,7 @@ JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter)
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string)
{
auto* this_object = this_symbol_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
auto string = this_object->primitive_symbol().to_string();
@ -87,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string)
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::value_of)
{
auto* this_object = this_symbol_from_interpreter(interpreter);
auto* this_object = typed_this(interpreter, global_object);
if (!this_object)
return {};
return this_object->value_of();