summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-20 16:25:12 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-20 17:50:48 +0200
commitcd14ebb11f9875b3b1768727a558c8ddbe26eba4 (patch)
treefb918ff2a0597c0c7bb1f73425843508a4ef1648 /Libraries
parenta9e4babdaf7401ca83ddaea48eb9671d7b3d5e86 (diff)
downloadserenity-cd14ebb11f9875b3b1768727a558c8ddbe26eba4.zip
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.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/Array.cpp6
-rw-r--r--Libraries/LibJS/Runtime/Array.h4
-rw-r--r--Libraries/LibJS/Runtime/ArrayPrototype.cpp10
-rw-r--r--Libraries/LibJS/Runtime/DatePrototype.cpp28
-rw-r--r--Libraries/LibJS/Runtime/ScriptFunction.cpp8
-rw-r--r--Libraries/LibJS/Runtime/StringPrototype.cpp44
-rw-r--r--Libraries/LibJS/Runtime/SymbolPrototype.cpp10
7 files changed, 55 insertions, 55 deletions
diff --git a/Libraries/LibJS/Runtime/Array.cpp b/Libraries/LibJS/Runtime/Array.cpp
index 950334b721..7efe39e23d 100644
--- a/Libraries/LibJS/Runtime/Array.cpp
+++ b/Libraries/LibJS/Runtime/Array.cpp
@@ -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);
diff --git a/Libraries/LibJS/Runtime/Array.h b/Libraries/LibJS/Runtime/Array.h
index 999098f26d..3abf4262ae 100644
--- a/Libraries/LibJS/Runtime/Array.h
+++ b/Libraries/LibJS/Runtime/Array.h
@@ -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; }
diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp
index b9bbe260ea..4b8d4b1396 100644
--- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp
+++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp
@@ -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 {};
diff --git a/Libraries/LibJS/Runtime/DatePrototype.cpp b/Libraries/LibJS/Runtime/DatePrototype.cpp
index 8aae092237..a762245947 100644
--- a/Libraries/LibJS/Runtime/DatePrototype.cpp
+++ b/Libraries/LibJS/Runtime/DatePrototype.cpp
@@ -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();
diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp
index 2962f60148..48291e693f 100644
--- a/Libraries/LibJS/Runtime/ScriptFunction.cpp
+++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp
@@ -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());
diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp
index 9139e482d6..017f98cebf 100644
--- a/Libraries/LibJS/Runtime/StringPrototype.cpp
+++ b/Libraries/LibJS/Runtime/StringPrototype.cpp
@@ -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 {};
diff --git a/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Libraries/LibJS/Runtime/SymbolPrototype.cpp
index 7edf874009..d0660196ad 100644
--- a/Libraries/LibJS/Runtime/SymbolPrototype.cpp
+++ b/Libraries/LibJS/Runtime/SymbolPrototype.cpp
@@ -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();