diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-20 13:55:34 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-20 15:45:07 +0200 |
commit | e4add199153bd32a7a4ccbe32751c799aaacaea9 (patch) | |
tree | 5d326c1635f94eadf6d53861be17186a21865085 /Libraries/LibJS/Runtime | |
parent | 4aa98052caa728da0de4c3960d312d8cf92f1be7 (diff) | |
download | serenity-e4add199153bd32a7a4ccbe32751c799aaacaea9.zip |
LibJS: Pass GlobalObject& to native functions and property accessors
More work towards supporting multiple global objects. Native C++ code
now get a GlobalObject& and don't have to ask the Interpreter for it.
I've added macros for declaring and defining native callbacks since
this was pretty tedious and this makes it easier next time we want to
change any of these signatures.
Diffstat (limited to 'Libraries/LibJS/Runtime')
55 files changed, 378 insertions, 376 deletions
diff --git a/Libraries/LibJS/Runtime/Array.cpp b/Libraries/LibJS/Runtime/Array.cpp index fdd2e0ac03..1c58dacc05 100644 --- a/Libraries/LibJS/Runtime/Array.cpp +++ b/Libraries/LibJS/Runtime/Array.cpp @@ -61,7 +61,7 @@ Array* array_from(Interpreter& interpreter, GlobalObject& global_object) return static_cast<Array*>(this_object); } -Value Array::length_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(Array::length_getter) { auto* array = array_from(interpreter, interpreter.global_object()); if (!array) @@ -69,9 +69,9 @@ Value Array::length_getter(Interpreter& interpreter) return Value(static_cast<i32>(array->indexed_properties().array_like_size())); } -void Array::length_setter(Interpreter& interpreter, Value value) +JS_DEFINE_NATIVE_SETTER(Array::length_setter) { - auto* array = array_from(interpreter, interpreter.global_object()); + auto* array = array_from(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 7a62080287..999098f26d 100644 --- a/Libraries/LibJS/Runtime/Array.h +++ b/Libraries/LibJS/Runtime/Array.h @@ -43,8 +43,8 @@ private: virtual const char* class_name() const override { return "Array"; } virtual bool is_array() const override { return true; } - static Value length_getter(Interpreter&); - static void length_setter(Interpreter&, Value); + JS_DECLARE_NATIVE_GETTER(length_getter); + JS_DECLARE_NATIVE_SETTER(length_setter); }; } diff --git a/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 1a250dce50..c72a36299b 100644 --- a/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -78,15 +78,15 @@ Value ArrayConstructor::construct(Interpreter& interpreter) return call(interpreter); } -Value ArrayConstructor::is_array(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array) { auto value = interpreter.argument(0); return Value(value.is_array()); } -Value ArrayConstructor::of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of) { - auto* array = Array::create(interpreter.global_object()); + auto* array = Array::create(global_object); for (size_t i = 0; i < interpreter.argument_count(); ++i) array->indexed_properties().append(interpreter.argument(i)); return array; diff --git a/Libraries/LibJS/Runtime/ArrayConstructor.h b/Libraries/LibJS/Runtime/ArrayConstructor.h index 14e5f30665..b2b666aa4b 100644 --- a/Libraries/LibJS/Runtime/ArrayConstructor.h +++ b/Libraries/LibJS/Runtime/ArrayConstructor.h @@ -42,8 +42,8 @@ private: virtual bool has_constructor() const override { return true; } virtual const char* class_name() const override { return "ArrayConstructor"; } - static Value is_array(Interpreter&); - static Value of(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(is_array); + JS_DECLARE_NATIVE_FUNCTION(of); }; } diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 199c2df72b..febf120773 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -139,10 +139,10 @@ static void for_each_item(Interpreter& interpreter, GlobalObject& global_object, } } -Value ArrayPrototype::filter(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter) { - auto* new_array = Array::create(interpreter.global_object()); - for_each_item(interpreter, interpreter.global_object(), "filter", [&](auto, auto value, auto callback_result) { + auto* new_array = Array::create(global_object); + for_each_item(interpreter, global_object, "filter", [&](auto, auto value, auto callback_result) { if (callback_result.to_boolean()) new_array->indexed_properties().append(value); return IterationDecision::Continue; @@ -150,25 +150,25 @@ Value ArrayPrototype::filter(Interpreter& interpreter) return Value(new_array); } -Value ArrayPrototype::for_each(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::for_each) { - for_each_item(interpreter, interpreter.global_object(), "forEach", [](auto, auto, auto) { + for_each_item(interpreter, global_object, "forEach", [](auto, auto, auto) { return IterationDecision::Continue; }); return js_undefined(); } -Value ArrayPrototype::map(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map) { - 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 {}; auto initial_length = get_length(interpreter, *this_object); if (interpreter.exception()) return {}; - auto* new_array = Array::create(interpreter.global_object()); + auto* new_array = Array::create(global_object); new_array->indexed_properties().set_array_like_size(initial_length); - for_each_item(interpreter, interpreter.global_object(), "map", [&](auto index, auto, auto callback_result) { + for_each_item(interpreter, global_object, "map", [&](auto index, auto, auto callback_result) { new_array->put(index, callback_result); if (interpreter.exception()) return IterationDecision::Break; @@ -177,9 +177,9 @@ Value ArrayPrototype::map(Interpreter& interpreter) return Value(new_array); } -Value ArrayPrototype::push(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push) { - 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 {}; if (this_object->is_array()) { @@ -207,9 +207,9 @@ Value ArrayPrototype::push(Interpreter& interpreter) return new_length_value; } -Value ArrayPrototype::unshift(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift) { - auto* array = array_from(interpreter, interpreter.global_object()); + auto* array = array_from(interpreter, global_object); if (!array) return {}; for (size_t i = 0; i < interpreter.argument_count(); ++i) @@ -217,9 +217,9 @@ Value ArrayPrototype::unshift(Interpreter& interpreter) return Value(static_cast<i32>(array->indexed_properties().array_like_size())); } -Value ArrayPrototype::pop(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop) { - 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 {}; if (this_object->is_array()) { @@ -246,9 +246,9 @@ Value ArrayPrototype::pop(Interpreter& interpreter) return element; } -Value ArrayPrototype::shift(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift) { - auto* array = array_from(interpreter, interpreter.global_object()); + auto* array = array_from(interpreter, global_object); if (!array) return {}; if (array->indexed_properties().is_empty()) @@ -259,22 +259,22 @@ Value ArrayPrototype::shift(Interpreter& interpreter) return result.value.value_or(js_undefined()); } -Value ArrayPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string) { - 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 {}; auto join_function = this_object->get("join"); if (interpreter.exception()) return {}; if (!join_function.is_function()) - return ObjectPrototype::to_string(interpreter); + return ObjectPrototype::to_string(interpreter, global_object); return interpreter.call(join_function.as_function(), this_object); } -Value ArrayPrototype::to_locale_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) { - 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 {}; String separator = ","; // NOTE: This is implementation-specific. @@ -303,9 +303,9 @@ Value ArrayPrototype::to_locale_string(Interpreter& interpreter) return js_string(interpreter, builder.to_string()); } -Value ArrayPrototype::join(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join) { - 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 {}; String separator = ","; @@ -334,13 +334,13 @@ Value ArrayPrototype::join(Interpreter& interpreter) return js_string(interpreter, builder.to_string()); } -Value ArrayPrototype::concat(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat) { - auto* array = array_from(interpreter, interpreter.global_object()); + auto* array = array_from(interpreter, global_object); if (!array) return {}; - auto* new_array = Array::create(interpreter.global_object()); + auto* new_array = Array::create(global_object); new_array->indexed_properties().append_all(array, array->indexed_properties()); if (interpreter.exception()) return {}; @@ -360,13 +360,13 @@ Value ArrayPrototype::concat(Interpreter& interpreter) return Value(new_array); } -Value ArrayPrototype::slice(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice) { - auto* array = array_from(interpreter, interpreter.global_object()); + auto* array = array_from(interpreter, global_object); if (!array) return {}; - auto* new_array = Array::create(interpreter.global_object()); + auto* new_array = Array::create(global_object); if (interpreter.argument_count() == 0) { new_array->indexed_properties().append_all(array, array->indexed_properties()); if (interpreter.exception()) @@ -405,9 +405,9 @@ Value ArrayPrototype::slice(Interpreter& interpreter) return new_array; } -Value ArrayPrototype::index_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of) { - 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 {}; i32 length = get_length(interpreter, *this_object); @@ -436,9 +436,9 @@ Value ArrayPrototype::index_of(Interpreter& interpreter) return Value(-1); } -Value ArrayPrototype::reduce(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce) { - 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 {}; @@ -495,9 +495,9 @@ Value ArrayPrototype::reduce(Interpreter& interpreter) return accumulator; } -Value ArrayPrototype::reduce_right(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right) { - 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 {}; @@ -554,9 +554,9 @@ Value ArrayPrototype::reduce_right(Interpreter& interpreter) return accumulator; } -Value ArrayPrototype::reverse(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse) { - auto* array = array_from(interpreter, interpreter.global_object()); + auto* array = array_from(interpreter, global_object); if (!array) return {}; @@ -578,9 +578,9 @@ Value ArrayPrototype::reverse(Interpreter& interpreter) return array; } -Value ArrayPrototype::last_index_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of) { - 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 {}; i32 length = get_length(interpreter, *this_object); @@ -609,9 +609,9 @@ Value ArrayPrototype::last_index_of(Interpreter& interpreter) return Value(-1); } -Value ArrayPrototype::includes(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::includes) { - 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 {}; i32 length = get_length(interpreter, *this_object); @@ -640,11 +640,11 @@ Value ArrayPrototype::includes(Interpreter& interpreter) return Value(false); } -Value ArrayPrototype::find(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find) { auto result = js_undefined(); for_each_item( - interpreter, interpreter.global_object(), "find", [&](auto, auto value, auto callback_result) { + interpreter, global_object, "find", [&](auto, auto value, auto callback_result) { if (callback_result.to_boolean()) { result = value; return IterationDecision::Break; @@ -655,11 +655,11 @@ Value ArrayPrototype::find(Interpreter& interpreter) return result; } -Value ArrayPrototype::find_index(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index) { auto result_index = -1; for_each_item( - interpreter, interpreter.global_object(), "findIndex", [&](auto index, auto, auto callback_result) { + interpreter, global_object, "findIndex", [&](auto index, auto, auto callback_result) { if (callback_result.to_boolean()) { result_index = index; return IterationDecision::Break; @@ -670,10 +670,10 @@ Value ArrayPrototype::find_index(Interpreter& interpreter) return Value(result_index); } -Value ArrayPrototype::some(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some) { auto result = false; - for_each_item(interpreter, interpreter.global_object(), "some", [&](auto, auto, auto callback_result) { + for_each_item(interpreter, global_object, "some", [&](auto, auto, auto callback_result) { if (callback_result.to_boolean()) { result = true; return IterationDecision::Break; @@ -683,10 +683,10 @@ Value ArrayPrototype::some(Interpreter& interpreter) return Value(result); } -Value ArrayPrototype::every(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every) { auto result = true; - for_each_item(interpreter, interpreter.global_object(), "every", [&](auto, auto, auto callback_result) { + for_each_item(interpreter, global_object, "every", [&](auto, auto, auto callback_result) { if (!callback_result.to_boolean()) { result = false; return IterationDecision::Break; @@ -696,9 +696,9 @@ Value ArrayPrototype::every(Interpreter& interpreter) return Value(result); } -Value ArrayPrototype::splice(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) { - 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 {}; @@ -736,7 +736,7 @@ Value ArrayPrototype::splice(Interpreter& interpreter) if (new_length > MAX_ARRAY_LIKE_INDEX) return interpreter.throw_exception<TypeError>(ErrorType::ArrayMaxSize); - auto removed_elements = Array::create(interpreter.global_object()); + auto removed_elements = Array::create(global_object); for (size_t i = 0; i < actual_delete_count; ++i) { auto value = this_object->get(actual_start + i); @@ -799,9 +799,9 @@ Value ArrayPrototype::splice(Interpreter& interpreter) return removed_elements; } -Value ArrayPrototype::fill(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::fill) { - 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 {}; diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.h b/Libraries/LibJS/Runtime/ArrayPrototype.h index 90d03cbc0d..678db7ca89 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.h +++ b/Libraries/LibJS/Runtime/ArrayPrototype.h @@ -39,30 +39,30 @@ public: private: virtual const char* class_name() const override { return "ArrayPrototype"; } - static Value filter(Interpreter&); - static Value for_each(Interpreter&); - static Value map(Interpreter&); - static Value pop(Interpreter&); - static Value push(Interpreter&); - static Value shift(Interpreter&); - static Value to_string(Interpreter&); - static Value to_locale_string(Interpreter&); - static Value unshift(Interpreter&); - static Value join(Interpreter&); - static Value concat(Interpreter&); - static Value slice(Interpreter&); - static Value index_of(Interpreter&); - static Value reduce(Interpreter&); - static Value reduce_right(Interpreter&); - static Value reverse(Interpreter&); - static Value last_index_of(Interpreter&); - static Value includes(Interpreter&); - static Value find(Interpreter&); - static Value find_index(Interpreter&); - static Value some(Interpreter&); - static Value every(Interpreter&); - static Value splice(Interpreter&); - static Value fill(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(filter); + JS_DECLARE_NATIVE_FUNCTION(for_each); + JS_DECLARE_NATIVE_FUNCTION(map); + JS_DECLARE_NATIVE_FUNCTION(pop); + JS_DECLARE_NATIVE_FUNCTION(push); + JS_DECLARE_NATIVE_FUNCTION(shift); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(to_locale_string); + JS_DECLARE_NATIVE_FUNCTION(unshift); + JS_DECLARE_NATIVE_FUNCTION(join); + JS_DECLARE_NATIVE_FUNCTION(concat); + JS_DECLARE_NATIVE_FUNCTION(slice); + JS_DECLARE_NATIVE_FUNCTION(index_of); + JS_DECLARE_NATIVE_FUNCTION(reduce); + JS_DECLARE_NATIVE_FUNCTION(reduce_right); + JS_DECLARE_NATIVE_FUNCTION(reverse); + JS_DECLARE_NATIVE_FUNCTION(last_index_of); + JS_DECLARE_NATIVE_FUNCTION(includes); + JS_DECLARE_NATIVE_FUNCTION(find); + JS_DECLARE_NATIVE_FUNCTION(find_index); + JS_DECLARE_NATIVE_FUNCTION(some); + JS_DECLARE_NATIVE_FUNCTION(every); + JS_DECLARE_NATIVE_FUNCTION(splice); + JS_DECLARE_NATIVE_FUNCTION(fill); }; } diff --git a/Libraries/LibJS/Runtime/BigIntConstructor.cpp b/Libraries/LibJS/Runtime/BigIntConstructor.cpp index 9dd20b9c05..db6b7d9356 100644 --- a/Libraries/LibJS/Runtime/BigIntConstructor.cpp +++ b/Libraries/LibJS/Runtime/BigIntConstructor.cpp @@ -73,12 +73,12 @@ Value BigIntConstructor::construct(Interpreter& interpreter) return {}; } -Value BigIntConstructor::as_int_n(Interpreter&) +JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_int_n) { TODO(); } -Value BigIntConstructor::as_uint_n(Interpreter&) +JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_uint_n) { TODO(); } diff --git a/Libraries/LibJS/Runtime/BigIntConstructor.h b/Libraries/LibJS/Runtime/BigIntConstructor.h index a012895afa..13bbb987c4 100644 --- a/Libraries/LibJS/Runtime/BigIntConstructor.h +++ b/Libraries/LibJS/Runtime/BigIntConstructor.h @@ -42,8 +42,8 @@ private: virtual bool has_constructor() const override { return true; } virtual const char* class_name() const override { return "BigIntConstructor"; } - static Value as_int_n(Interpreter&); - static Value as_uint_n(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(as_int_n); + JS_DECLARE_NATIVE_FUNCTION(as_uint_n); }; } diff --git a/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Libraries/LibJS/Runtime/BigIntPrototype.cpp index e36cefc1f7..4e624b4ebd 100644 --- a/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -57,22 +57,22 @@ static BigIntObject* bigint_object_from(Interpreter& interpreter, GlobalObject& return static_cast<BigIntObject*>(this_object); } -Value BigIntPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string) { - auto* bigint_object = bigint_object_from(interpreter, interpreter.global_object()); + auto* bigint_object = bigint_object_from(interpreter, global_object); if (!bigint_object) return {}; return js_string(interpreter, bigint_object->bigint().big_integer().to_base10()); } -Value BigIntPrototype::to_locale_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string) { - return to_string(interpreter); + return to_string(interpreter, global_object); } -Value BigIntPrototype::value_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::value_of) { - auto* bigint_object = bigint_object_from(interpreter, interpreter.global_object()); + auto* bigint_object = bigint_object_from(interpreter, global_object); if (!bigint_object) return {}; return bigint_object->value_of(); diff --git a/Libraries/LibJS/Runtime/BigIntPrototype.h b/Libraries/LibJS/Runtime/BigIntPrototype.h index c2cb1914cb..ebd17a3936 100644 --- a/Libraries/LibJS/Runtime/BigIntPrototype.h +++ b/Libraries/LibJS/Runtime/BigIntPrototype.h @@ -38,9 +38,9 @@ public: private: virtual const char* class_name() const override { return "BigIntPrototype"; } - static Value to_string(Interpreter&); - static Value to_locale_string(Interpreter&); - static Value value_of(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(to_locale_string); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } diff --git a/Libraries/LibJS/Runtime/BooleanPrototype.cpp b/Libraries/LibJS/Runtime/BooleanPrototype.cpp index ce6795c8d6..572e8c3c7d 100644 --- a/Libraries/LibJS/Runtime/BooleanPrototype.cpp +++ b/Libraries/LibJS/Runtime/BooleanPrototype.cpp @@ -39,11 +39,13 @@ BooleanPrototype::BooleanPrototype() define_native_function("valueOf", value_of, 0, Attribute::Writable | Attribute::Configurable); } -BooleanPrototype::~BooleanPrototype() { } +BooleanPrototype::~BooleanPrototype() +{ +} -Value BooleanPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::to_string) { - auto this_object = interpreter.this_value(interpreter.global_object()); + auto this_object = interpreter.this_value(global_object); if (this_object.is_boolean()) { return js_string(interpreter.heap(), this_object.as_bool() ? "true" : "false"); } @@ -56,9 +58,9 @@ Value BooleanPrototype::to_string(Interpreter& interpreter) return js_string(interpreter.heap(), bool_value ? "true" : "false"); } -Value BooleanPrototype::value_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::value_of) { - auto this_object = interpreter.this_value(interpreter.global_object()); + auto this_object = interpreter.this_value(global_object); if (this_object.is_boolean()) { return this_object; } diff --git a/Libraries/LibJS/Runtime/BooleanPrototype.h b/Libraries/LibJS/Runtime/BooleanPrototype.h index ea4142ebe2..e587a91b04 100644 --- a/Libraries/LibJS/Runtime/BooleanPrototype.h +++ b/Libraries/LibJS/Runtime/BooleanPrototype.h @@ -38,8 +38,8 @@ public: private: virtual const char* class_name() const override { return "BooleanPrototype"; } - static Value to_string(Interpreter&); - static Value value_of(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } diff --git a/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Libraries/LibJS/Runtime/ConsoleObject.cpp index e3887e6280..8489403ea9 100644 --- a/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -53,47 +53,47 @@ ConsoleObject::~ConsoleObject() { } -Value ConsoleObject::log(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log) { return interpreter.console().log(); } -Value ConsoleObject::debug(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug) { return interpreter.console().debug(); } -Value ConsoleObject::info(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info) { return interpreter.console().info(); } -Value ConsoleObject::warn(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn) { return interpreter.console().warn(); } -Value ConsoleObject::error(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error) { return interpreter.console().error(); } -Value ConsoleObject::trace(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace) { return interpreter.console().trace(); } -Value ConsoleObject::count(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count) { return interpreter.console().count(); } -Value ConsoleObject::count_reset(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset) { return interpreter.console().count_reset(); } -Value ConsoleObject::clear(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear) { return interpreter.console().clear(); } diff --git a/Libraries/LibJS/Runtime/ConsoleObject.h b/Libraries/LibJS/Runtime/ConsoleObject.h index eb5fedf84e..0f2a947faa 100644 --- a/Libraries/LibJS/Runtime/ConsoleObject.h +++ b/Libraries/LibJS/Runtime/ConsoleObject.h @@ -38,15 +38,15 @@ public: private: virtual const char* class_name() const override { return "ConsoleObject"; } - static Value log(Interpreter&); - static Value debug(Interpreter&); - static Value info(Interpreter&); - static Value warn(Interpreter&); - static Value error(Interpreter&); - static Value trace(Interpreter&); - static Value count(Interpreter&); - static Value count_reset(Interpreter&); - static Value clear(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(log); + JS_DECLARE_NATIVE_FUNCTION(debug); + JS_DECLARE_NATIVE_FUNCTION(info); + JS_DECLARE_NATIVE_FUNCTION(warn); + JS_DECLARE_NATIVE_FUNCTION(error); + JS_DECLARE_NATIVE_FUNCTION(trace); + JS_DECLARE_NATIVE_FUNCTION(count); + JS_DECLARE_NATIVE_FUNCTION(count_reset); + JS_DECLARE_NATIVE_FUNCTION(clear); }; } diff --git a/Libraries/LibJS/Runtime/DateConstructor.cpp b/Libraries/LibJS/Runtime/DateConstructor.cpp index a76db80b5e..d00b1e6323 100644 --- a/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -65,7 +65,7 @@ Value DateConstructor::construct(Interpreter&) return Date::create(global_object(), datetime, milliseconds); } -Value DateConstructor::now(Interpreter&) +JS_DEFINE_NATIVE_FUNCTION(DateConstructor::now) { struct timeval tv; gettimeofday(&tv, nullptr); diff --git a/Libraries/LibJS/Runtime/DateConstructor.h b/Libraries/LibJS/Runtime/DateConstructor.h index 707d9fe6fd..9e70bca833 100644 --- a/Libraries/LibJS/Runtime/DateConstructor.h +++ b/Libraries/LibJS/Runtime/DateConstructor.h @@ -42,7 +42,7 @@ private: virtual bool has_constructor() const override { return true; } virtual const char* class_name() const override { return "DateConstructor"; } - static Value now(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(now); }; } diff --git a/Libraries/LibJS/Runtime/DatePrototype.cpp b/Libraries/LibJS/Runtime/DatePrototype.cpp index 7492a0de9d..08bdf0e626 100644 --- a/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -70,7 +70,7 @@ DatePrototype::~DatePrototype() { } -Value DatePrototype::get_date(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -79,7 +79,7 @@ Value DatePrototype::get_date(Interpreter& interpreter) return Value(static_cast<double>(date)); } -Value DatePrototype::get_day(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -88,7 +88,7 @@ Value DatePrototype::get_day(Interpreter& interpreter) return Value(static_cast<double>(day)); } -Value DatePrototype::get_full_year(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -97,7 +97,7 @@ Value DatePrototype::get_full_year(Interpreter& interpreter) return Value(static_cast<double>(full_year)); } -Value DatePrototype::get_hours(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -106,7 +106,7 @@ Value DatePrototype::get_hours(Interpreter& interpreter) return Value(static_cast<double>(hours)); } -Value DatePrototype::get_milliseconds(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -115,7 +115,7 @@ Value DatePrototype::get_milliseconds(Interpreter& interpreter) return Value(static_cast<double>(milliseconds)); } -Value DatePrototype::get_minutes(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -124,7 +124,7 @@ Value DatePrototype::get_minutes(Interpreter& interpreter) return Value(static_cast<double>(minutes)); } -Value DatePrototype::get_month(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -133,7 +133,7 @@ Value DatePrototype::get_month(Interpreter& interpreter) return Value(static_cast<double>(months)); } -Value DatePrototype::get_seconds(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -142,7 +142,7 @@ Value DatePrototype::get_seconds(Interpreter& interpreter) return Value(static_cast<double>(seconds)); } -Value DatePrototype::get_time(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -152,7 +152,7 @@ Value DatePrototype::get_time(Interpreter& interpreter) return Value(static_cast<double>(seconds * 1000 + milliseconds)); } -Value DatePrototype::to_date_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -161,7 +161,7 @@ Value DatePrototype::to_date_string(Interpreter& interpreter) return js_string(interpreter, move(string)); } -Value DatePrototype::to_time_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) @@ -170,7 +170,7 @@ Value DatePrototype::to_time_string(Interpreter& interpreter) return js_string(interpreter, move(string)); } -Value DatePrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string) { auto* this_object = this_date_from_interpreter(interpreter); if (!this_object) diff --git a/Libraries/LibJS/Runtime/DatePrototype.h b/Libraries/LibJS/Runtime/DatePrototype.h index b92abe2b03..212705e314 100644 --- a/Libraries/LibJS/Runtime/DatePrototype.h +++ b/Libraries/LibJS/Runtime/DatePrototype.h @@ -38,18 +38,18 @@ public: private: virtual const char* class_name() const override { return "DatePrototype"; } - static Value get_date(Interpreter&); - static Value get_day(Interpreter&); - static Value get_full_year(Interpreter&); - static Value get_hours(Interpreter&); - static Value get_milliseconds(Interpreter&); - static Value get_minutes(Interpreter&); - static Value get_month(Interpreter&); - static Value get_seconds(Interpreter&); - static Value get_time(Interpreter&); - static Value to_date_string(Interpreter&); - static Value to_time_string(Interpreter&); - static Value to_string(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(get_date); + JS_DECLARE_NATIVE_FUNCTION(get_day); + JS_DECLARE_NATIVE_FUNCTION(get_full_year); + JS_DECLARE_NATIVE_FUNCTION(get_hours); + JS_DECLARE_NATIVE_FUNCTION(get_milliseconds); + JS_DECLARE_NATIVE_FUNCTION(get_minutes); + JS_DECLARE_NATIVE_FUNCTION(get_month); + JS_DECLARE_NATIVE_FUNCTION(get_seconds); + JS_DECLARE_NATIVE_FUNCTION(get_time); + JS_DECLARE_NATIVE_FUNCTION(to_date_string); + JS_DECLARE_NATIVE_FUNCTION(to_time_string); + JS_DECLARE_NATIVE_FUNCTION(to_string); }; } diff --git a/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Libraries/LibJS/Runtime/ErrorConstructor.cpp index f308f64a2a..0973ed37be 100644 --- a/Libraries/LibJS/Runtime/ErrorConstructor.cpp +++ b/Libraries/LibJS/Runtime/ErrorConstructor.cpp @@ -62,8 +62,8 @@ Value ErrorConstructor::construct(Interpreter& interpreter) ConstructorName::ConstructorName() \ : NativeFunction(*interpreter().global_object().function_prototype()) \ { \ - define_property("prototype", interpreter().global_object().snake_name##_prototype(), 0); \ - define_property("length", Value(1), Attribute::Configurable); \ + define_property("prototype", interpreter().global_object().snake_name##_prototype(), 0); \ + define_property("length", Value(1), Attribute::Configurable); \ } \ ConstructorName::~ConstructorName() { } \ Value ConstructorName::call(Interpreter& interpreter) \ @@ -78,7 +78,7 @@ Value ErrorConstructor::construct(Interpreter& interpreter) if (interpreter.exception()) \ return {}; \ } \ - return ClassName::create(interpreter.global_object(), message); \ + return ClassName::create(global_object(), message); \ } JS_ENUMERATE_ERROR_SUBCLASSES diff --git a/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Libraries/LibJS/Runtime/ErrorPrototype.cpp index 781c0ab32f..d3b6dcafee 100644 --- a/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -48,9 +48,9 @@ ErrorPrototype::~ErrorPrototype() { } -Value ErrorPrototype::name_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ErrorPrototype::name_getter) { - 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 {}; if (!this_object->is_error()) @@ -58,9 +58,9 @@ Value ErrorPrototype::name_getter(Interpreter& interpreter) return js_string(interpreter, static_cast<const Error*>(this_object)->name()); } -void ErrorPrototype::name_setter(Interpreter& interpreter, Value value) +JS_DEFINE_NATIVE_SETTER(ErrorPrototype::name_setter) { - 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; if (!this_object->is_error()) { @@ -73,9 +73,9 @@ void ErrorPrototype::name_setter(Interpreter& interpreter, Value value) static_cast<Error*>(this_object)->set_name(name); } -Value ErrorPrototype::message_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ErrorPrototype::message_getter) { - 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 {}; if (!this_object->is_error()) @@ -83,11 +83,11 @@ Value ErrorPrototype::message_getter(Interpreter& interpreter) return js_string(interpreter, static_cast<const Error*>(this_object)->message()); } -Value ErrorPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string) { - if (!interpreter.this_value(interpreter.global_object()).is_object()) - return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, interpreter.this_value(interpreter.global_object()).to_string_without_side_effects().characters()); - auto& this_object = interpreter.this_value(interpreter.global_object()).as_object(); + if (!interpreter.this_value(global_object).is_object()) + return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, interpreter.this_value(global_object).to_string_without_side_effects().characters()); + auto& this_object = interpreter.this_value(global_object).as_object(); String name = "Error"; auto name_property = this_object.get("name"); diff --git a/Libraries/LibJS/Runtime/ErrorPrototype.h b/Libraries/LibJS/Runtime/ErrorPrototype.h index a851407fee..183bd26b14 100644 --- a/Libraries/LibJS/Runtime/ErrorPrototype.h +++ b/Libraries/LibJS/Runtime/ErrorPrototype.h @@ -38,12 +38,12 @@ public: private: virtual const char* class_name() const override { return "ErrorPrototype"; } - static Value to_string(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(to_string); - static Value name_getter(Interpreter&); - static void name_setter(Interpreter&, Value); + JS_DECLARE_NATIVE_GETTER(name_getter); + JS_DECLARE_NATIVE_SETTER(name_setter); - static Value message_getter(Interpreter&); + JS_DECLARE_NATIVE_GETTER(message_getter); }; #define DECLARE_ERROR_SUBCLASS_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName) \ diff --git a/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 0fcef2453d..48e699f53e 100644 --- a/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -58,9 +58,9 @@ FunctionPrototype::~FunctionPrototype() { } -Value FunctionPrototype::apply(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply) { - 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 {}; if (!this_object->is_function()) @@ -88,9 +88,9 @@ Value FunctionPrototype::apply(Interpreter& interpreter) return interpreter.call(function, this_arg, move(arguments)); } -Value FunctionPrototype::bind(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind) { - 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 {}; if (!this_object->is_function()) @@ -108,9 +108,9 @@ Value FunctionPrototype::bind(Interpreter& interpreter) return this_function.bind(bound_this_arg, move(arguments)); } -Value FunctionPrototype::call(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::call) { - 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 {}; if (!this_object->is_function()) @@ -125,9 +125,9 @@ Value FunctionPrototype::call(Interpreter& interpreter) return interpreter.call(function, this_arg, move(arguments)); } -Value FunctionPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) { - 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 {}; if (!this_object->is_function()) diff --git a/Libraries/LibJS/Runtime/FunctionPrototype.h b/Libraries/LibJS/Runtime/FunctionPrototype.h index 1760522af3..495db7b317 100644 --- a/Libraries/LibJS/Runtime/FunctionPrototype.h +++ b/Libraries/LibJS/Runtime/FunctionPrototype.h @@ -40,10 +40,10 @@ public: private: virtual const char* class_name() const override { return "FunctionPrototype"; } - static Value apply(Interpreter&); - static Value bind(Interpreter&); - static Value call(Interpreter&); - static Value to_string(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(apply); + JS_DECLARE_NATIVE_FUNCTION(bind); + JS_DECLARE_NATIVE_FUNCTION(call); + JS_DECLARE_NATIVE_FUNCTION(to_string); }; } diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp index 3d9d7fdfb8..cab6083a69 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -135,14 +135,14 @@ void GlobalObject::visit_children(Visitor& visitor) #undef __JS_ENUMERATE } -Value GlobalObject::gc(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(GlobalObject::gc) { dbg() << "Forced garbage collection requested!"; interpreter.heap().collect_garbage(); return js_undefined(); } -Value GlobalObject::is_nan(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_nan) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -150,7 +150,7 @@ Value GlobalObject::is_nan(Interpreter& interpreter) return Value(number.is_nan()); } -Value GlobalObject::is_finite(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_finite) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -158,7 +158,7 @@ Value GlobalObject::is_finite(Interpreter& interpreter) return Value(number.is_finite_number()); } -Value GlobalObject::parse_float(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float) { if (interpreter.argument(0).is_number()) return interpreter.argument(0); diff --git a/Libraries/LibJS/Runtime/GlobalObject.h b/Libraries/LibJS/Runtime/GlobalObject.h index 9534c9e131..4e67bcd485 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Libraries/LibJS/Runtime/GlobalObject.h @@ -55,10 +55,10 @@ protected: private: virtual const char* class_name() const override { return "GlobalObject"; } - static Value gc(Interpreter&); - static Value is_nan(Interpreter&); - static Value is_finite(Interpreter&); - static Value parse_float(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(gc); + JS_DECLARE_NATIVE_FUNCTION(is_nan); + JS_DECLARE_NATIVE_FUNCTION(is_finite); + JS_DECLARE_NATIVE_FUNCTION(parse_float); Shape* m_empty_object_shape { nullptr }; diff --git a/Libraries/LibJS/Runtime/JSONObject.cpp b/Libraries/LibJS/Runtime/JSONObject.cpp index f5747085c2..fd2f666105 100644 --- a/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Libraries/LibJS/Runtime/JSONObject.cpp @@ -49,7 +49,7 @@ JSONObject::~JSONObject() { } -Value JSONObject::stringify(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify) { if (!interpreter.argument_count()) return js_undefined(); @@ -116,7 +116,7 @@ Value JSONObject::stringify(Interpreter& interpreter) state.gap = String::empty(); } - auto* wrapper = Object::create_empty(interpreter, interpreter.global_object()); + auto* wrapper = Object::create_empty(interpreter, global_object); wrapper->define_property(String::empty(), value); if (interpreter.exception()) return {}; @@ -368,7 +368,7 @@ String JSONObject::quote_json_string(String string) return builder.to_string(); } -Value JSONObject::parse(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse) { if (!interpreter.argument_count()) return js_undefined(); @@ -384,7 +384,7 @@ Value JSONObject::parse(Interpreter& interpreter) } Value result = parse_json_value(interpreter, json.value()); if (reviver.is_function()) { - auto* holder_object = Object::create_empty(interpreter, interpreter.global_object()); + auto* holder_object = Object::create_empty(interpreter, global_object); holder_object->define_property(String::empty(), result); if (interpreter.exception()) return {}; diff --git a/Libraries/LibJS/Runtime/JSONObject.h b/Libraries/LibJS/Runtime/JSONObject.h index c9b8a488ef..7fc71c7f9d 100644 --- a/Libraries/LibJS/Runtime/JSONObject.h +++ b/Libraries/LibJS/Runtime/JSONObject.h @@ -56,8 +56,8 @@ private: static Value parse_json_value(Interpreter&, const JsonValue&); static Value internalize_json_property(Interpreter&, Object* holder, const PropertyName& name, Function& reviver); - static Value stringify(Interpreter&); - static Value parse(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(stringify); + JS_DECLARE_NATIVE_FUNCTION(parse); }; } diff --git a/Libraries/LibJS/Runtime/MathObject.cpp b/Libraries/LibJS/Runtime/MathObject.cpp index 988d091218..1dcc6c2b3a 100644 --- a/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Libraries/LibJS/Runtime/MathObject.cpp @@ -70,7 +70,7 @@ MathObject::~MathObject() { } -Value MathObject::abs(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::abs) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -80,7 +80,7 @@ Value MathObject::abs(Interpreter& interpreter) return Value(number.as_double() >= 0 ? number.as_double() : -number.as_double()); } -Value MathObject::random(Interpreter&) +Value MathObject::random(Interpreter&, GlobalObject&) { #ifdef __serenity__ double r = (double)arc4random() / (double)UINT32_MAX; @@ -90,7 +90,7 @@ Value MathObject::random(Interpreter&) return Value(r); } -Value MathObject::sqrt(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::sqrt) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -100,7 +100,7 @@ Value MathObject::sqrt(Interpreter& interpreter) return Value(::sqrt(number.as_double())); } -Value MathObject::floor(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::floor) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -110,7 +110,7 @@ Value MathObject::floor(Interpreter& interpreter) return Value(::floor(number.as_double())); } -Value MathObject::ceil(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::ceil) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -120,7 +120,7 @@ Value MathObject::ceil(Interpreter& interpreter) return Value(::ceil(number.as_double())); } -Value MathObject::round(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::round) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -130,7 +130,7 @@ Value MathObject::round(Interpreter& interpreter) return Value(::round(number.as_double())); } -Value MathObject::max(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::max) { if (!interpreter.argument_count()) return js_negative_infinity(); @@ -147,7 +147,7 @@ Value MathObject::max(Interpreter& interpreter) return max; } -Value MathObject::min(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::min) { if (!interpreter.argument_count()) return js_infinity(); @@ -164,7 +164,7 @@ Value MathObject::min(Interpreter& interpreter) return min; } -Value MathObject::trunc(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -172,11 +172,11 @@ Value MathObject::trunc(Interpreter& interpreter) if (number.is_nan()) return js_nan(); if (number.as_double() < 0) - return MathObject::ceil(interpreter); - return MathObject::floor(interpreter); + return MathObject::ceil(interpreter, global_object); + return MathObject::floor(interpreter, global_object); } -Value MathObject::sin(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::sin) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -186,7 +186,7 @@ Value MathObject::sin(Interpreter& interpreter) return Value(::sin(number.as_double())); } -Value MathObject::cos(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::cos) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -196,7 +196,7 @@ Value MathObject::cos(Interpreter& interpreter) return Value(::cos(number.as_double())); } -Value MathObject::tan(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::tan) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -206,12 +206,12 @@ Value MathObject::tan(Interpreter& interpreter) return Value(::tan(number.as_double())); } -Value MathObject::pow(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::pow) { return JS::exp(interpreter, interpreter.argument(0), interpreter.argument(1)); } -Value MathObject::exp(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::exp) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -221,7 +221,7 @@ Value MathObject::exp(Interpreter& interpreter) return Value(::pow(M_E, number.as_double())); } -Value MathObject::expm1(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::expm1) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -231,7 +231,7 @@ Value MathObject::expm1(Interpreter& interpreter) return Value(::pow(M_E, number.as_double()) - 1); } -Value MathObject::sign(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::sign) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) @@ -247,7 +247,7 @@ Value MathObject::sign(Interpreter& interpreter) return js_nan(); } -Value MathObject::clz32(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32) { auto number = interpreter.argument(0).to_number(interpreter); if (interpreter.exception()) diff --git a/Libraries/LibJS/Runtime/MathObject.h b/Libraries/LibJS/Runtime/MathObject.h index 1cd550ca7d..d1da19a672 100644 --- a/Libraries/LibJS/Runtime/MathObject.h +++ b/Libraries/LibJS/Runtime/MathObject.h @@ -38,23 +38,23 @@ public: private: virtual const char* class_name() const override { return "MathObject"; } - static Value abs(Interpreter&); - static Value random(Interpreter&); - static Value sqrt(Interpreter&); - static Value floor(Interpreter&); - static Value ceil(Interpreter&); - static Value round(Interpreter&); - static Value max(Interpreter&); - static Value min(Interpreter&); - static Value trunc(Interpreter&); - static Value sin(Interpreter&); - static Value cos(Interpreter&); - static Value tan(Interpreter&); - static Value pow(Interpreter&); - static Value exp(Interpreter&); - static Value expm1(Interpreter&); - static Value sign(Interpreter&); - static Value clz32(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(abs); + JS_DECLARE_NATIVE_FUNCTION(random); + JS_DECLARE_NATIVE_FUNCTION(sqrt); + JS_DECLARE_NATIVE_FUNCTION(floor); + JS_DECLARE_NATIVE_FUNCTION(ceil); + JS_DECLARE_NATIVE_FUNCTION(round); + JS_DECLARE_NATIVE_FUNCTION(max); + JS_DECLARE_NATIVE_FUNCTION(min); + JS_DECLARE_NATIVE_FUNCTION(trunc); + JS_DECLARE_NATIVE_FUNCTION(sin); + JS_DECLARE_NATIVE_FUNCTION(cos); + JS_DECLARE_NATIVE_FUNCTION(tan); + JS_DECLARE_NATIVE_FUNCTION(pow); + JS_DECLARE_NATIVE_FUNCTION(exp); + JS_DECLARE_NATIVE_FUNCTION(expm1); + JS_DECLARE_NATIVE_FUNCTION(sign); + JS_DECLARE_NATIVE_FUNCTION(clz32); }; } diff --git a/Libraries/LibJS/Runtime/NativeFunction.cpp b/Libraries/LibJS/Runtime/NativeFunction.cpp index 3dd43660fc..0c0972bcc6 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -31,7 +31,7 @@ namespace JS { -NativeFunction* NativeFunction::create(Interpreter&, GlobalObject& global_object, const FlyString& name, AK::Function<Value(Interpreter&)> function) +NativeFunction* NativeFunction::create(Interpreter&, GlobalObject& global_object, const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)> function) { return global_object.heap().allocate<NativeFunction>(name, move(function), *global_object.function_prototype()); } @@ -41,7 +41,7 @@ NativeFunction::NativeFunction(Object& prototype) { } -NativeFunction::NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&)> native_function, Object& prototype) +NativeFunction::NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)> native_function, Object& prototype) : Function(prototype) , m_name(name) , m_native_function(move(native_function)) @@ -60,7 +60,7 @@ NativeFunction::~NativeFunction() Value NativeFunction::call(Interpreter& interpreter) { - return m_native_function(interpreter); + return m_native_function(interpreter, global_object()); } Value NativeFunction::construct(Interpreter&) diff --git a/Libraries/LibJS/Runtime/NativeFunction.h b/Libraries/LibJS/Runtime/NativeFunction.h index 9f0331c1a4..34446eef6d 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.h +++ b/Libraries/LibJS/Runtime/NativeFunction.h @@ -33,9 +33,9 @@ namespace JS { class NativeFunction : public Function { public: - static NativeFunction* create(Interpreter&, GlobalObject&, const FlyString& name, AK::Function<Value(Interpreter&)>); + static NativeFunction* create(Interpreter&, GlobalObject&, const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)>); - explicit NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&)>, Object& prototype); + explicit NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)>, Object& prototype); virtual ~NativeFunction() override; virtual Value call(Interpreter&) override; @@ -54,7 +54,7 @@ private: virtual LexicalEnvironment* create_environment() override final { return nullptr; } FlyString m_name; - AK::Function<Value(Interpreter&)> m_native_function; + AK::Function<Value(Interpreter&, GlobalObject&)> m_native_function; }; } diff --git a/Libraries/LibJS/Runtime/NativeProperty.cpp b/Libraries/LibJS/Runtime/NativeProperty.cpp index 9f9fd7b236..50487fde7a 100644 --- a/Libraries/LibJS/Runtime/NativeProperty.cpp +++ b/Libraries/LibJS/Runtime/NativeProperty.cpp @@ -29,7 +29,7 @@ namespace JS { -NativeProperty::NativeProperty(AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter) +NativeProperty::NativeProperty(AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter) : Object(nullptr) , m_getter(move(getter)) , m_setter(move(setter)) @@ -44,14 +44,14 @@ Value NativeProperty::get(Interpreter& interpreter) const { if (!m_getter) return js_undefined(); - return m_getter(interpreter); + return m_getter(interpreter, global_object()); } void NativeProperty::set(Interpreter& interpreter, Value value) { if (!m_setter) return; - m_setter(interpreter, move(value)); + m_setter(interpreter, global_object(), move(value)); } } diff --git a/Libraries/LibJS/Runtime/NativeProperty.h b/Libraries/LibJS/Runtime/NativeProperty.h index 0c9619e2bd..e98d9a91e7 100644 --- a/Libraries/LibJS/Runtime/NativeProperty.h +++ b/Libraries/LibJS/Runtime/NativeProperty.h @@ -33,7 +33,7 @@ namespace JS { class NativeProperty final : public Object { public: - NativeProperty(AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter); + NativeProperty(AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter); virtual ~NativeProperty() override; Value get(Interpreter&) const; @@ -43,8 +43,8 @@ private: virtual bool is_native_property() const override { return true; } virtual const char* class_name() const override { return "NativeProperty"; } - AK::Function<Value(Interpreter&)> m_getter; - AK::Function<void(Interpreter&, Value)> m_setter; + AK::Function<Value(Interpreter&, GlobalObject&)> m_getter; + AK::Function<void(Interpreter&, GlobalObject&, Value)> m_setter; }; } diff --git a/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Libraries/LibJS/Runtime/NumberConstructor.cpp index 0733b9c59a..14e6b4cb68 100644 --- a/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -78,22 +78,22 @@ Value NumberConstructor::construct(Interpreter& interpreter) return NumberObject::create(global_object(), number); } -Value NumberConstructor::is_finite(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_finite) { return Value(interpreter.argument(0).is_finite_number()); } -Value NumberConstructor::is_integer(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_integer) { return Value(interpreter.argument(0).is_integer()); } -Value NumberConstructor::is_nan(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_nan) { return Value(interpreter.argument(0).is_nan()); } -Value NumberConstructor::is_safe_integer(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(NumberConstructor::is_safe_integer) { if (!interpreter.argument(0).is_number()) return Value(false); diff --git a/Libraries/LibJS/Runtime/NumberConstructor.h b/Libraries/LibJS/Runtime/NumberConstructor.h index 4d23819a7a..f9e1546c6b 100644 --- a/Libraries/LibJS/Runtime/NumberConstructor.h +++ b/Libraries/LibJS/Runtime/NumberConstructor.h @@ -42,10 +42,10 @@ private: virtual bool has_constructor() const override { return true; } virtual const char* class_name() const override { return "NumberConstructor"; } - static Value is_finite(Interpreter&); - static Value is_integer(Interpreter&); - static Value is_nan(Interpreter&); - static Value is_safe_integer(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(is_finite); + JS_DECLARE_NATIVE_FUNCTION(is_integer); + JS_DECLARE_NATIVE_FUNCTION(is_nan); + JS_DECLARE_NATIVE_FUNCTION(is_safe_integer); }; } diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 92efb5ba4a..0f36ed527c 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -680,7 +680,7 @@ bool Object::put(PropertyName property_name, Value value) return put_own_property(*this, property_string, value, default_attributes, PutOwnPropertyMode::Put); } -bool Object::define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)> native_function, i32 length, PropertyAttributes attribute) +bool Object::define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute) { auto* function = NativeFunction::create(interpreter(), global_object(), property_name, move(native_function)); function->define_property("length", Value(length), Attribute::Configurable); @@ -692,7 +692,7 @@ bool Object::define_native_function(const FlyString& property_name, AK::Function return define_property(property_name, function, attribute); } -bool Object::define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter, PropertyAttributes attribute) +bool Object::define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter, PropertyAttributes attribute) { return define_property(property_name, heap().allocate<NativeProperty>(move(getter), move(setter)), attribute); } diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index 768ad03dd2..105ed851b7 100644 --- a/Libraries/LibJS/Runtime/Object.h +++ b/Libraries/LibJS/Runtime/Object.h @@ -90,8 +90,8 @@ public: virtual bool define_property(const FlyString& property_name, const Object& descriptor, bool throw_exceptions = true); bool define_property(PropertyName, Value value, PropertyAttributes attributes = default_attributes, bool throw_exceptions = true); - bool define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)>, i32 length = 0, PropertyAttributes attributes = default_attributes); - bool define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter, PropertyAttributes attributes = default_attributes); + bool define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)>, i32 length = 0, PropertyAttributes attributes = default_attributes); + bool define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter, PropertyAttributes attributes = default_attributes); virtual Value delete_property(PropertyName); diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 9c651cc840..10fa061d90 100644 --- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -69,14 +69,14 @@ Value ObjectConstructor::construct(Interpreter& interpreter) return call(interpreter); } -Value ObjectConstructor::get_own_property_names(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) { if (!interpreter.argument_count()) return {}; auto* object = interpreter.argument(0).to_object(interpreter); if (interpreter.exception()) return {}; - auto* result = Array::create(interpreter.global_object()); + auto* result = Array::create(global_object); for (auto& entry : object->indexed_properties()) result->indexed_properties().append(js_string(interpreter, String::number(entry.index()))); for (auto& it : object->shape().property_table_ordered()) @@ -85,7 +85,7 @@ Value ObjectConstructor::get_own_property_names(Interpreter& interpreter) return result; } -Value ObjectConstructor::get_prototype_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of) { if (!interpreter.argument_count()) return {}; @@ -95,7 +95,7 @@ Value ObjectConstructor::get_prototype_of(Interpreter& interpreter) return object->prototype(); } -Value ObjectConstructor::set_prototype_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of) { if (interpreter.argument_count() < 2) return interpreter.throw_exception<TypeError>(ErrorType::ObjectSetPrototypeOfTwoArgs); @@ -120,7 +120,7 @@ Value ObjectConstructor::set_prototype_of(Interpreter& interpreter) return object; } -Value ObjectConstructor::is_extensible(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible) { auto argument = interpreter.argument(0); if (!argument.is_object()) @@ -128,7 +128,7 @@ Value ObjectConstructor::is_extensible(Interpreter& interpreter) return Value(argument.as_object().is_extensible()); } -Value ObjectConstructor::prevent_extensions(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions) { auto argument = interpreter.argument(0); if (!argument.is_object()) @@ -141,7 +141,7 @@ Value ObjectConstructor::prevent_extensions(Interpreter& interpreter) return argument; } -Value ObjectConstructor::get_own_property_descriptor(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor) { auto* object = interpreter.argument(0).to_object(interpreter); if (interpreter.exception()) @@ -152,7 +152,7 @@ Value ObjectConstructor::get_own_property_descriptor(Interpreter& interpreter) return object->get_own_property_descriptor_object(property_key); } -Value ObjectConstructor::define_property_(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property_) { if (!interpreter.argument(0).is_object()) return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, "Object argument"); @@ -176,12 +176,12 @@ Value ObjectConstructor::define_property_(Interpreter& interpreter) return &object; } -Value ObjectConstructor::is(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is) { return Value(same_value(interpreter, interpreter.argument(0), interpreter.argument(1))); } -Value ObjectConstructor::keys(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) { if (!interpreter.argument_count()) return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject); @@ -193,7 +193,7 @@ Value ObjectConstructor::keys(Interpreter& interpreter) return obj_arg->get_own_properties(*obj_arg, GetOwnPropertyMode::Key, true); } -Value ObjectConstructor::values(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) { if (!interpreter.argument_count()) return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject); @@ -205,7 +205,7 @@ Value ObjectConstructor::values(Interpreter& interpreter) return obj_arg->get_own_properties(*obj_arg, GetOwnPropertyMode::Value, true); } -Value ObjectConstructor::entries(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) { if (!interpreter.argument_count()) return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject); diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.h b/Libraries/LibJS/Runtime/ObjectConstructor.h index 13ad1a57b7..97d8e6b0a6 100644 --- a/Libraries/LibJS/Runtime/ObjectConstructor.h +++ b/Libraries/LibJS/Runtime/ObjectConstructor.h @@ -42,17 +42,17 @@ private: virtual bool has_constructor() const override { return true; } virtual const char* class_name() const override { return "ObjectConstructor"; } - static Value define_property_(Interpreter&); - static Value is(Interpreter&); - static Value get_own_property_descriptor(Interpreter&); - static Value get_own_property_names(Interpreter&); - static Value get_prototype_of(Interpreter&); - static Value set_prototype_of(Interpreter&); - static Value is_extensible(Interpreter&); - static Value prevent_extensions(Interpreter&); - static Value keys(Interpreter&); - static Value values(Interpreter&); - static Value entries(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(define_property_); + JS_DECLARE_NATIVE_FUNCTION(is); + JS_DECLARE_NATIVE_FUNCTION(get_own_property_descriptor); + JS_DECLARE_NATIVE_FUNCTION(get_own_property_names); + JS_DECLARE_NATIVE_FUNCTION(get_prototype_of); + JS_DECLARE_NATIVE_FUNCTION(set_prototype_of); + JS_DECLARE_NATIVE_FUNCTION(is_extensible); + JS_DECLARE_NATIVE_FUNCTION(prevent_extensions); + JS_DECLARE_NATIVE_FUNCTION(keys); + JS_DECLARE_NATIVE_FUNCTION(values); + JS_DECLARE_NATIVE_FUNCTION(entries); }; } diff --git a/Libraries/LibJS/Runtime/ObjectPrototype.cpp b/Libraries/LibJS/Runtime/ObjectPrototype.cpp index b790a608f1..a3ceb3ea63 100644 --- a/Libraries/LibJS/Runtime/ObjectPrototype.cpp +++ b/Libraries/LibJS/Runtime/ObjectPrototype.cpp @@ -54,9 +54,9 @@ ObjectPrototype::~ObjectPrototype() { } -Value ObjectPrototype::has_own_property(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::has_own_property) { - 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 {}; auto name = interpreter.argument(0).to_string(interpreter); @@ -65,25 +65,25 @@ Value ObjectPrototype::has_own_property(Interpreter& interpreter) return Value(this_object->has_own_property(name)); } -Value ObjectPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string) { - 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 js_string(interpreter, String::format("[object %s]", this_object->class_name())); } -Value ObjectPrototype::to_locale_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string) { - 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 this_object->invoke("toString"); } -Value ObjectPrototype::value_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::value_of) { - 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 this_object->value_of(); diff --git a/Libraries/LibJS/Runtime/ObjectPrototype.h b/Libraries/LibJS/Runtime/ObjectPrototype.h index 708ddc7245..ceeaa0e092 100644 --- a/Libraries/LibJS/Runtime/ObjectPrototype.h +++ b/Libraries/LibJS/Runtime/ObjectPrototype.h @@ -38,14 +38,14 @@ public: virtual ~ObjectPrototype() override; // public to serve as intrinsic function %Object.prototype.toString% - static Value to_string(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(to_string); private: virtual const char* class_name() const override { return "ObjectPrototype"; } - static Value has_own_property(Interpreter&); - static Value to_locale_string(Interpreter&); - static Value value_of(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(has_own_property); + JS_DECLARE_NATIVE_FUNCTION(to_locale_string); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } diff --git a/Libraries/LibJS/Runtime/ReflectObject.cpp b/Libraries/LibJS/Runtime/ReflectObject.cpp index 9617209d5d..510f5f2a26 100644 --- a/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -98,7 +98,7 @@ ReflectObject::~ReflectObject() { } -Value ReflectObject::apply(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::apply) { auto* target = get_target_function_from(interpreter, "apply"); if (!target) @@ -111,7 +111,7 @@ Value ReflectObject::apply(Interpreter& interpreter) return interpreter.call(*target, this_arg, move(arguments)); } -Value ReflectObject::construct(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::construct) { auto* target = get_target_function_from(interpreter, "construct"); if (!target) @@ -133,7 +133,7 @@ Value ReflectObject::construct(Interpreter& interpreter) return interpreter.construct(*target, *new_target, move(arguments)); } -Value ReflectObject::define_property(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::define_property) { auto* target = get_target_object_from(interpreter, "defineProperty"); if (!target) @@ -150,7 +150,7 @@ Value ReflectObject::define_property(Interpreter& interpreter) return Value(success); } -Value ReflectObject::delete_property(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property) { auto* target = get_target_object_from(interpreter, "deleteProperty"); if (!target) @@ -171,7 +171,7 @@ Value ReflectObject::delete_property(Interpreter& interpreter) return target->delete_property(property_name); } -Value ReflectObject::get(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get) { // FIXME: There's a third argument, receiver, for getters - use it once we have those. auto* target = get_target_object_from(interpreter, "get"); @@ -183,7 +183,7 @@ Value ReflectObject::get(Interpreter& interpreter) return target->get(property_key).value_or(js_undefined()); } -Value ReflectObject::get_own_property_descriptor(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_own_property_descriptor) { auto* target = get_target_object_from(interpreter, "getOwnPropertyDescriptor"); if (!target) @@ -194,7 +194,7 @@ Value ReflectObject::get_own_property_descriptor(Interpreter& interpreter) return target->get_own_property_descriptor_object(property_key); } -Value ReflectObject::get_prototype_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_prototype_of) { auto* target = get_target_object_from(interpreter, "getPrototypeOf"); if (!target) @@ -202,7 +202,7 @@ Value ReflectObject::get_prototype_of(Interpreter& interpreter) return target->prototype(); } -Value ReflectObject::has(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::has) { auto* target = get_target_object_from(interpreter, "has"); if (!target) @@ -213,7 +213,7 @@ Value ReflectObject::has(Interpreter& interpreter) return Value(target->has_property(property_key)); } -Value ReflectObject::is_extensible(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible) { auto* target = get_target_object_from(interpreter, "isExtensible"); if (!target) @@ -221,7 +221,7 @@ Value ReflectObject::is_extensible(Interpreter& interpreter) return Value(target->is_extensible()); } -Value ReflectObject::own_keys(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys) { auto* target = get_target_object_from(interpreter, "ownKeys"); if (!target) @@ -229,7 +229,7 @@ Value ReflectObject::own_keys(Interpreter& interpreter) return target->get_own_properties(*target, GetOwnPropertyMode::Key); } -Value ReflectObject::prevent_extensions(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::prevent_extensions) { auto* target = get_target_object_from(interpreter, "preventExtensions"); if (!target) @@ -237,7 +237,7 @@ Value ReflectObject::prevent_extensions(Interpreter& interpreter) return Value(target->prevent_extensions()); } -Value ReflectObject::set(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set) { // FIXME: There's a fourth argument, receiver, for setters - use it once we have those. auto* target = get_target_object_from(interpreter, "set"); @@ -250,7 +250,7 @@ Value ReflectObject::set(Interpreter& interpreter) return Value(target->put(property_key, value)); } -Value ReflectObject::set_prototype_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set_prototype_of) { auto* target = get_target_object_from(interpreter, "setPrototypeOf"); if (!target) diff --git a/Libraries/LibJS/Runtime/ReflectObject.h b/Libraries/LibJS/Runtime/ReflectObject.h index 80ddadd7fa..219485b03f 100644 --- a/Libraries/LibJS/Runtime/ReflectObject.h +++ b/Libraries/LibJS/Runtime/ReflectObject.h @@ -38,19 +38,19 @@ public: private: virtual const char* class_name() const override { return "ReflectObject"; } - static Value apply(Interpreter&); - static Value construct(Interpreter&); - static Value define_property(Interpreter&); - static Value delete_property(Interpreter&); - static Value get(Interpreter&); - static Value get_own_property_descriptor(Interpreter&); - static Value get_prototype_of(Interpreter&); - static Value has(Interpreter&); - static Value is_extensible(Interpreter&); - static Value own_keys(Interpreter&); - static Value prevent_extensions(Interpreter&); - static Value set(Interpreter&); - static Value set_prototype_of(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(apply); + JS_DECLARE_NATIVE_FUNCTION(construct); + JS_DECLARE_NATIVE_FUNCTION(define_property); + JS_DECLARE_NATIVE_FUNCTION(delete_property); + JS_DECLARE_NATIVE_FUNCTION(get); + JS_DECLARE_NATIVE_FUNCTION(get_own_property_descriptor); + JS_DECLARE_NATIVE_FUNCTION(get_prototype_of); + JS_DECLARE_NATIVE_FUNCTION(has); + JS_DECLARE_NATIVE_FUNCTION(is_extensible); + JS_DECLARE_NATIVE_FUNCTION(own_keys); + JS_DECLARE_NATIVE_FUNCTION(prevent_extensions); + JS_DECLARE_NATIVE_FUNCTION(set); + JS_DECLARE_NATIVE_FUNCTION(set_prototype_of); }; } diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp index d54c3fa395..17749e85c6 100644 --- a/Libraries/LibJS/Runtime/ScriptFunction.cpp +++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp @@ -130,7 +130,7 @@ Value ScriptFunction::construct(Interpreter& interpreter) return call(interpreter); } -Value ScriptFunction::length_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter) { auto* function = script_function_from(interpreter); if (!function) @@ -138,7 +138,7 @@ Value ScriptFunction::length_getter(Interpreter& interpreter) return Value(static_cast<i32>(function->m_function_length)); } -Value ScriptFunction::name_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ScriptFunction::name_getter) { auto* function = script_function_from(interpreter); if (!function) diff --git a/Libraries/LibJS/Runtime/ScriptFunction.h b/Libraries/LibJS/Runtime/ScriptFunction.h index 1a605d0427..53b3c23a92 100644 --- a/Libraries/LibJS/Runtime/ScriptFunction.h +++ b/Libraries/LibJS/Runtime/ScriptFunction.h @@ -53,8 +53,8 @@ private: virtual LexicalEnvironment* create_environment() override; virtual void visit_children(Visitor&) override; - static Value length_getter(Interpreter&); - static Value name_getter(Interpreter&); + JS_DECLARE_NATIVE_GETTER(length_getter); + JS_DECLARE_NATIVE_GETTER(name_getter); FlyString m_name; NonnullRefPtr<Statement> m_body; diff --git a/Libraries/LibJS/Runtime/StringConstructor.cpp b/Libraries/LibJS/Runtime/StringConstructor.cpp index c42731b58f..ba31d4acbb 100644 --- a/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -72,7 +72,7 @@ Value StringConstructor::construct(Interpreter& interpreter) return StringObject::create(global_object(), *primitive_string); } -Value StringConstructor::raw(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw) { auto* template_object = interpreter.argument(0).to_object(interpreter); if (interpreter.exception()) @@ -111,7 +111,7 @@ Value StringConstructor::raw(Interpreter& interpreter) return js_string(interpreter, builder.build()); } -Value StringConstructor::from_char_code(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code) { StringBuilder builder; for (size_t i = 0; i < interpreter.argument_count(); ++i) { diff --git a/Libraries/LibJS/Runtime/StringConstructor.h b/Libraries/LibJS/Runtime/StringConstructor.h index 1cc6f8a089..4d6aaa8f18 100644 --- a/Libraries/LibJS/Runtime/StringConstructor.h +++ b/Libraries/LibJS/Runtime/StringConstructor.h @@ -42,8 +42,8 @@ private: virtual bool has_constructor() const override { return true; } virtual const char* class_name() const override { return "StringConstructor"; } - static Value raw(Interpreter&); - static Value from_char_code(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(raw); + JS_DECLARE_NATIVE_FUNCTION(from_char_code); }; } diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp index c6da030d79..f9d1a54827 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -88,7 +88,7 @@ StringPrototype::~StringPrototype() { } -Value StringPrototype::char_at(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at) { auto string = string_from(interpreter); if (string.is_null()) @@ -104,7 +104,7 @@ Value StringPrototype::char_at(Interpreter& interpreter) return js_string(interpreter, string.substring(index, 1)); } -Value StringPrototype::repeat(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat) { auto string = string_from(interpreter); if (string.is_null()) @@ -127,7 +127,7 @@ Value StringPrototype::repeat(Interpreter& interpreter) return js_string(interpreter, builder.to_string()); } -Value StringPrototype::starts_with(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with) { auto string = string_from(interpreter); if (string.is_null()) @@ -154,7 +154,7 @@ Value StringPrototype::starts_with(Interpreter& interpreter) return Value(string.substring(start, search_string_length) == search_string); } -Value StringPrototype::index_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of) { auto string = string_from(interpreter); if (string.is_null()) @@ -165,7 +165,7 @@ Value StringPrototype::index_of(Interpreter& interpreter) return Value((i32)string.index_of(needle).value_or(-1)); } -Value StringPrototype::to_lowercase(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase) { auto string = string_from(interpreter); if (string.is_null()) @@ -173,7 +173,7 @@ Value StringPrototype::to_lowercase(Interpreter& interpreter) return js_string(interpreter, string.to_lowercase()); } -Value StringPrototype::to_uppercase(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase) { auto string = string_from(interpreter); if (string.is_null()) @@ -181,7 +181,7 @@ Value StringPrototype::to_uppercase(Interpreter& interpreter) return js_string(interpreter, string.to_uppercase()); } -Value StringPrototype::length_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(StringPrototype::length_getter) { auto* string_object = string_object_from(interpreter); if (!string_object) @@ -189,7 +189,7 @@ Value StringPrototype::length_getter(Interpreter& interpreter) return Value((i32)string_object->primitive_string().string().length()); } -Value StringPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_string) { auto* string_object = string_object_from(interpreter); if (!string_object) @@ -231,7 +231,7 @@ static Value pad_string(Interpreter& interpreter, const String& string, PadPlace return js_string(interpreter, String::format("%s%s", string.characters(), filler.characters())); } -Value StringPrototype::pad_start(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_start) { auto string = string_from(interpreter); if (string.is_null()) @@ -239,7 +239,7 @@ Value StringPrototype::pad_start(Interpreter& interpreter) return pad_string(interpreter, string, PadPlacement::Start); } -Value StringPrototype::pad_end(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_end) { auto string = string_from(interpreter); if (string.is_null()) @@ -247,7 +247,7 @@ Value StringPrototype::pad_end(Interpreter& interpreter) return pad_string(interpreter, string, PadPlacement::End); } -Value StringPrototype::trim(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim) { auto string = string_from(interpreter); if (string.is_null()) @@ -255,7 +255,7 @@ Value StringPrototype::trim(Interpreter& interpreter) return js_string(interpreter, string.trim_whitespace(String::TrimMode::Both)); } -Value StringPrototype::trim_start(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_start) { auto string = string_from(interpreter); if (string.is_null()) @@ -263,7 +263,7 @@ Value StringPrototype::trim_start(Interpreter& interpreter) return js_string(interpreter, string.trim_whitespace(String::TrimMode::Left)); } -Value StringPrototype::trim_end(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_end) { auto string = string_from(interpreter); if (string.is_null()) @@ -271,7 +271,7 @@ Value StringPrototype::trim_end(Interpreter& interpreter) return js_string(interpreter, string.trim_whitespace(String::TrimMode::Right)); } -Value StringPrototype::concat(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat) { auto string = string_from(interpreter); if (string.is_null()) @@ -287,7 +287,7 @@ Value StringPrototype::concat(Interpreter& interpreter) return js_string(interpreter, builder.to_string()); } -Value StringPrototype::substring(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring) { auto string = string_from(interpreter); if (string.is_null()) @@ -322,7 +322,7 @@ Value StringPrototype::substring(Interpreter& interpreter) return js_string(interpreter, string_part); } -Value StringPrototype::includes(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes) { auto string = string_from(interpreter); if (string.is_null()) @@ -348,7 +348,7 @@ Value StringPrototype::includes(Interpreter& interpreter) return Value(substring_search.contains(search_string)); } -Value StringPrototype::slice(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice) { auto string = string_from(interpreter); if (string.is_null()) @@ -391,7 +391,7 @@ Value StringPrototype::slice(Interpreter& interpreter) return js_string(interpreter, string_part); } -Value StringPrototype::last_index_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of) { auto string = string_from(interpreter); if (string.is_null()) diff --git a/Libraries/LibJS/Runtime/StringPrototype.h b/Libraries/LibJS/Runtime/StringPrototype.h index e25e6b648c..bef8d091b0 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.h +++ b/Libraries/LibJS/Runtime/StringPrototype.h @@ -38,26 +38,26 @@ public: private: virtual const char* class_name() const override { return "StringPrototype"; } - static Value char_at(Interpreter&); - static Value repeat(Interpreter&); - static Value starts_with(Interpreter&); - static Value index_of(Interpreter&); - static Value to_lowercase(Interpreter&); - static Value to_uppercase(Interpreter&); - static Value to_string(Interpreter&); - static Value pad_start(Interpreter&); - static Value pad_end(Interpreter&); - static Value substring(Interpreter&); - - static Value length_getter(Interpreter&); - - static Value trim(Interpreter&); - static Value trim_start(Interpreter&); - static Value trim_end(Interpreter&); - static Value concat(Interpreter&); - static Value includes(Interpreter&); - static Value slice(Interpreter&); - static Value last_index_of(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(char_at); + JS_DECLARE_NATIVE_FUNCTION(repeat); + JS_DECLARE_NATIVE_FUNCTION(starts_with); + JS_DECLARE_NATIVE_FUNCTION(index_of); + JS_DECLARE_NATIVE_FUNCTION(to_lowercase); + JS_DECLARE_NATIVE_FUNCTION(to_uppercase); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(pad_start); + JS_DECLARE_NATIVE_FUNCTION(pad_end); + JS_DECLARE_NATIVE_FUNCTION(substring); + + JS_DECLARE_NATIVE_GETTER(length_getter); + + JS_DECLARE_NATIVE_FUNCTION(trim); + JS_DECLARE_NATIVE_FUNCTION(trim_start); + JS_DECLARE_NATIVE_FUNCTION(trim_end); + JS_DECLARE_NATIVE_FUNCTION(concat); + JS_DECLARE_NATIVE_FUNCTION(includes); + JS_DECLARE_NATIVE_FUNCTION(slice); + JS_DECLARE_NATIVE_FUNCTION(last_index_of); }; } diff --git a/Libraries/LibJS/Runtime/SymbolConstructor.cpp b/Libraries/LibJS/Runtime/SymbolConstructor.cpp index a9174f4f28..a1a4661ae4 100644 --- a/Libraries/LibJS/Runtime/SymbolConstructor.cpp +++ b/Libraries/LibJS/Runtime/SymbolConstructor.cpp @@ -75,7 +75,7 @@ Value SymbolConstructor::construct(Interpreter& interpreter) return {}; } -Value SymbolConstructor::for_(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_) { String description; if (!interpreter.argument_count()) { @@ -87,7 +87,7 @@ Value SymbolConstructor::for_(Interpreter& interpreter) return SymbolObject::get_global(interpreter, description); } -Value SymbolConstructor::key_for(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::key_for) { auto argument = interpreter.argument(0); if (!argument.is_symbol()) { diff --git a/Libraries/LibJS/Runtime/SymbolConstructor.h b/Libraries/LibJS/Runtime/SymbolConstructor.h index ced41de12e..5c7ee56aef 100644 --- a/Libraries/LibJS/Runtime/SymbolConstructor.h +++ b/Libraries/LibJS/Runtime/SymbolConstructor.h @@ -42,8 +42,8 @@ private: virtual bool has_constructor() const override { return true; } virtual const char* class_name() const override { return "SymbolConstructor"; } - static Value for_(Interpreter&); - static Value key_for(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(for_); + JS_DECLARE_NATIVE_FUNCTION(key_for); }; } diff --git a/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Libraries/LibJS/Runtime/SymbolPrototype.cpp index 43b959c300..2d5bdd6a6c 100644 --- a/Libraries/LibJS/Runtime/SymbolPrototype.cpp +++ b/Libraries/LibJS/Runtime/SymbolPrototype.cpp @@ -64,7 +64,7 @@ static SymbolObject* this_symbol_from_interpreter(Interpreter& interpreter) return static_cast<SymbolObject*>(this_object); } -Value SymbolPrototype::description_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter) { auto* this_object = this_symbol_from_interpreter(interpreter); if (!this_object) @@ -72,7 +72,7 @@ Value SymbolPrototype::description_getter(Interpreter& interpreter) return js_string(interpreter, this_object->description()); } -Value SymbolPrototype::to_string(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string) { auto* this_object = this_symbol_from_interpreter(interpreter); if (!this_object) @@ -81,7 +81,7 @@ Value SymbolPrototype::to_string(Interpreter& interpreter) return js_string(interpreter, move(string)); } -Value SymbolPrototype::value_of(Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::value_of) { auto* this_object = this_symbol_from_interpreter(interpreter); if (!this_object) diff --git a/Libraries/LibJS/Runtime/SymbolPrototype.h b/Libraries/LibJS/Runtime/SymbolPrototype.h index 5106a0b370..6c2c10b9e1 100644 --- a/Libraries/LibJS/Runtime/SymbolPrototype.h +++ b/Libraries/LibJS/Runtime/SymbolPrototype.h @@ -38,10 +38,10 @@ public: private: virtual const char* class_name() const override { return "SymbolPrototype"; } - static Value description_getter(Interpreter&); + JS_DECLARE_NATIVE_GETTER(description_getter); - static Value to_string(Interpreter&); - static Value value_of(Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } diff --git a/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp b/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp index 15ba4295e2..f9f8267718 100644 --- a/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp +++ b/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp @@ -53,9 +53,9 @@ Uint8ClampedArray::~Uint8ClampedArray() m_data = nullptr; } -Value Uint8ClampedArray::length_getter(Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(Uint8ClampedArray::length_getter) { - 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 {}; if (StringView(this_object->class_name()) != "Uint8ClampedArray") diff --git a/Libraries/LibJS/Runtime/Uint8ClampedArray.h b/Libraries/LibJS/Runtime/Uint8ClampedArray.h index a58c6c5dd4..bf2351789a 100644 --- a/Libraries/LibJS/Runtime/Uint8ClampedArray.h +++ b/Libraries/LibJS/Runtime/Uint8ClampedArray.h @@ -48,7 +48,7 @@ public: private: virtual const char* class_name() const override { return "Uint8ClampedArray"; } - static Value length_getter(Interpreter&); + JS_DECLARE_NATIVE_GETTER(length_getter); u8* m_data { nullptr }; u32 m_length { 0 }; |