From e4add199153bd32a7a4ccbe32751c799aaacaea9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 20 Jun 2020 13:55:34 +0200 Subject: [PATCH] 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. --- Libraries/LibJS/Forward.h | 18 +++ Libraries/LibJS/Runtime/Array.cpp | 6 +- Libraries/LibJS/Runtime/Array.h | 4 +- Libraries/LibJS/Runtime/ArrayConstructor.cpp | 6 +- Libraries/LibJS/Runtime/ArrayConstructor.h | 4 +- Libraries/LibJS/Runtime/ArrayPrototype.cpp | 110 +++++++++--------- Libraries/LibJS/Runtime/ArrayPrototype.h | 48 ++++---- Libraries/LibJS/Runtime/BigIntConstructor.cpp | 4 +- Libraries/LibJS/Runtime/BigIntConstructor.h | 4 +- Libraries/LibJS/Runtime/BigIntPrototype.cpp | 12 +- Libraries/LibJS/Runtime/BigIntPrototype.h | 6 +- Libraries/LibJS/Runtime/BooleanPrototype.cpp | 14 ++- Libraries/LibJS/Runtime/BooleanPrototype.h | 4 +- Libraries/LibJS/Runtime/ConsoleObject.cpp | 18 +-- Libraries/LibJS/Runtime/ConsoleObject.h | 18 +-- Libraries/LibJS/Runtime/DateConstructor.cpp | 2 +- Libraries/LibJS/Runtime/DateConstructor.h | 2 +- Libraries/LibJS/Runtime/DatePrototype.cpp | 24 ++-- Libraries/LibJS/Runtime/DatePrototype.h | 24 ++-- Libraries/LibJS/Runtime/ErrorConstructor.cpp | 6 +- Libraries/LibJS/Runtime/ErrorPrototype.cpp | 20 ++-- Libraries/LibJS/Runtime/ErrorPrototype.h | 8 +- Libraries/LibJS/Runtime/FunctionPrototype.cpp | 16 +-- Libraries/LibJS/Runtime/FunctionPrototype.h | 8 +- Libraries/LibJS/Runtime/GlobalObject.cpp | 8 +- Libraries/LibJS/Runtime/GlobalObject.h | 8 +- Libraries/LibJS/Runtime/JSONObject.cpp | 8 +- Libraries/LibJS/Runtime/JSONObject.h | 4 +- Libraries/LibJS/Runtime/MathObject.cpp | 38 +++--- Libraries/LibJS/Runtime/MathObject.h | 34 +++--- Libraries/LibJS/Runtime/NativeFunction.cpp | 6 +- Libraries/LibJS/Runtime/NativeFunction.h | 6 +- Libraries/LibJS/Runtime/NativeProperty.cpp | 6 +- Libraries/LibJS/Runtime/NativeProperty.h | 6 +- Libraries/LibJS/Runtime/NumberConstructor.cpp | 8 +- Libraries/LibJS/Runtime/NumberConstructor.h | 8 +- Libraries/LibJS/Runtime/Object.cpp | 4 +- Libraries/LibJS/Runtime/Object.h | 4 +- Libraries/LibJS/Runtime/ObjectConstructor.cpp | 24 ++-- Libraries/LibJS/Runtime/ObjectConstructor.h | 22 ++-- Libraries/LibJS/Runtime/ObjectPrototype.cpp | 16 +-- Libraries/LibJS/Runtime/ObjectPrototype.h | 8 +- Libraries/LibJS/Runtime/ReflectObject.cpp | 26 ++--- Libraries/LibJS/Runtime/ReflectObject.h | 26 ++--- Libraries/LibJS/Runtime/ScriptFunction.cpp | 4 +- Libraries/LibJS/Runtime/ScriptFunction.h | 4 +- Libraries/LibJS/Runtime/StringConstructor.cpp | 4 +- Libraries/LibJS/Runtime/StringConstructor.h | 4 +- Libraries/LibJS/Runtime/StringPrototype.cpp | 36 +++--- Libraries/LibJS/Runtime/StringPrototype.h | 36 +++--- Libraries/LibJS/Runtime/SymbolConstructor.cpp | 4 +- Libraries/LibJS/Runtime/SymbolConstructor.h | 4 +- Libraries/LibJS/Runtime/SymbolPrototype.cpp | 6 +- Libraries/LibJS/Runtime/SymbolPrototype.h | 6 +- Libraries/LibJS/Runtime/Uint8ClampedArray.cpp | 4 +- Libraries/LibJS/Runtime/Uint8ClampedArray.h | 2 +- .../CanvasRenderingContext2DWrapper.cpp | 44 +++---- .../CanvasRenderingContext2DWrapper.h | 42 +++---- Libraries/LibWeb/Bindings/DocumentWrapper.cpp | 8 +- Libraries/LibWeb/Bindings/DocumentWrapper.h | 6 +- Libraries/LibWeb/Bindings/ElementWrapper.cpp | 12 +- Libraries/LibWeb/Bindings/ElementWrapper.h | 12 +- .../LibWeb/Bindings/EventTargetWrapper.cpp | 4 +- .../LibWeb/Bindings/EventTargetWrapper.h | 2 +- .../Bindings/HTMLCanvasElementWrapper.cpp | 6 +- .../Bindings/HTMLCanvasElementWrapper.h | 6 +- .../LibWeb/Bindings/ImageDataWrapper.cpp | 6 +- Libraries/LibWeb/Bindings/ImageDataWrapper.h | 6 +- Libraries/LibWeb/Bindings/LocationObject.cpp | 36 +++--- Libraries/LibWeb/Bindings/LocationObject.h | 18 +-- .../LibWeb/Bindings/MouseEventWrapper.cpp | 4 +- Libraries/LibWeb/Bindings/MouseEventWrapper.h | 4 +- Libraries/LibWeb/Bindings/NavigatorObject.cpp | 2 +- Libraries/LibWeb/Bindings/NavigatorObject.h | 2 +- Libraries/LibWeb/Bindings/WindowObject.cpp | 17 +-- Libraries/LibWeb/Bindings/WindowObject.h | 16 +-- .../Bindings/XMLHttpRequestPrototype.cpp | 8 +- .../LibWeb/Bindings/XMLHttpRequestPrototype.h | 8 +- Userland/js.cpp | 21 ++-- 79 files changed, 541 insertions(+), 519 deletions(-) diff --git a/Libraries/LibJS/Forward.h b/Libraries/LibJS/Forward.h index bea0352ae24..31a58d52d9a 100644 --- a/Libraries/LibJS/Forward.h +++ b/Libraries/LibJS/Forward.h @@ -26,6 +26,24 @@ #pragma once +#define JS_DECLARE_NATIVE_FUNCTION(name) \ + static JS::Value name(JS::Interpreter&, JS::GlobalObject&) + +#define JS_DECLARE_NATIVE_GETTER(name) \ + static JS::Value name(JS::Interpreter&, JS::GlobalObject&) + +#define JS_DECLARE_NATIVE_SETTER(name) \ + static void name(JS::Interpreter&, JS::GlobalObject&, JS::Value) + +#define JS_DEFINE_NATIVE_FUNCTION(name) \ + JS::Value name([[maybe_unused]] JS::Interpreter& interpreter, [[maybe_unused]] JS::GlobalObject& global_object) + +#define JS_DEFINE_NATIVE_GETTER(name) \ + JS::Value name([[maybe_unused]] JS::Interpreter& interpreter, [[maybe_unused]] JS::GlobalObject& global_object) + +#define JS_DEFINE_NATIVE_SETTER(name) \ + void name([[maybe_unused]] JS::Interpreter& interpreter, [[maybe_unused]] JS::GlobalObject& global_object, JS::Value value) + #define JS_ENUMERATE_NATIVE_OBJECTS \ __JS_ENUMERATE(Array, array, ArrayPrototype, ArrayConstructor) \ __JS_ENUMERATE(BigIntObject, bigint, BigIntPrototype, BigIntConstructor) \ diff --git a/Libraries/LibJS/Runtime/Array.cpp b/Libraries/LibJS/Runtime/Array.cpp index fdd2e0ac03d..1c58dacc05d 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(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(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 7a620802870..999098f26dc 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 1a250dce50b..c72a36299b7 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 14e5f306652..b2b666aa4ba 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 199c2df72bf..febf1207734 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(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(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 90d03cbc0d9..678db7ca899 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 9dd20b9c05c..db6b7d93567 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 a012895afa1..13bbb987c4b 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 e36cefc1f75..4e624b4ebd1 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(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 c2cb1914cb4..ebd17a3936a 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 ce6795c8d66..572e8c3c7db 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() { } - -Value BooleanPrototype::to_string(Interpreter& interpreter) +BooleanPrototype::~BooleanPrototype() { - auto this_object = interpreter.this_value(interpreter.global_object()); +} + +JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::to_string) +{ + 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 ea4142ebe25..e587a91b049 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 e3887e6280f..8489403ea9f 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 eb5fedf84eb..0f2a947faaf 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 a76db80b5ea..d00b1e6323e 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 707d9fe6fd3..9e70bca8338 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 7492a0de9d1..08bdf0e6263 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(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(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(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(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(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(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(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(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(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 b92abe2b033..212705e3142 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 f308f64a2ad..0973ed37be2 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 781c0ab32f8..d3b6dcafee5 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(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(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(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(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(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 a851407fee6..183bd26b14c 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 0fcef2453d3..48e699f53eb 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 1760522af3a..495db7b3177 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 3d9d7fdfb89..cab6083a69e 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 9534c9e1315..4e67bcd4854 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 f5747085c2b..fd2f666105c 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 c9b8a488efb..7fc71c7f9da 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 988d0912186..1dcc6c2b3ac 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 1cd550ca7dc..d1da19a6720 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 3dd43660fcc..0c0972bcc60 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 function) +NativeFunction* NativeFunction::create(Interpreter&, GlobalObject& global_object, const FlyString& name, AK::Function function) { return global_object.heap().allocate(name, move(function), *global_object.function_prototype()); } @@ -41,7 +41,7 @@ NativeFunction::NativeFunction(Object& prototype) { } -NativeFunction::NativeFunction(const FlyString& name, AK::Function native_function, Object& prototype) +NativeFunction::NativeFunction(const FlyString& name, AK::Function 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 9f0331c1a4e..34446eef6d2 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); + static NativeFunction* create(Interpreter&, GlobalObject&, const FlyString& name, AK::Function); - explicit NativeFunction(const FlyString& name, AK::Function, Object& prototype); + explicit NativeFunction(const FlyString& name, AK::Function, 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 m_native_function; + AK::Function m_native_function; }; } diff --git a/Libraries/LibJS/Runtime/NativeProperty.cpp b/Libraries/LibJS/Runtime/NativeProperty.cpp index 9f9fd7b236f..50487fde7a4 100644 --- a/Libraries/LibJS/Runtime/NativeProperty.cpp +++ b/Libraries/LibJS/Runtime/NativeProperty.cpp @@ -29,7 +29,7 @@ namespace JS { -NativeProperty::NativeProperty(AK::Function getter, AK::Function setter) +NativeProperty::NativeProperty(AK::Function getter, AK::Function 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 0c9619e2bd8..e98d9a91e75 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 getter, AK::Function setter); + NativeProperty(AK::Function getter, AK::Function 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 m_getter; - AK::Function m_setter; + AK::Function m_getter; + AK::Function m_setter; }; } diff --git a/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Libraries/LibJS/Runtime/NumberConstructor.cpp index 0733b9c59aa..14e6b4cb68d 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 4d23819a7af..f9e1546c6b9 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 92efb5ba4ab..0f36ed527cb 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 native_function, i32 length, PropertyAttributes attribute) +bool Object::define_native_function(const FlyString& property_name, AK::Function 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 getter, AK::Function setter, PropertyAttributes attribute) +bool Object::define_native_property(const FlyString& property_name, AK::Function getter, AK::Function setter, PropertyAttributes attribute) { return define_property(property_name, heap().allocate(move(getter), move(setter)), attribute); } diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index 768ad03dd2c..105ed851b76 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, i32 length = 0, PropertyAttributes attributes = default_attributes); - bool define_native_property(const FlyString& property_name, AK::Function getter, AK::Function setter, PropertyAttributes attributes = default_attributes); + bool define_native_function(const FlyString& property_name, AK::Function, i32 length = 0, PropertyAttributes attributes = default_attributes); + bool define_native_property(const FlyString& property_name, AK::Function getter, AK::Function 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 9c651cc8402..10fa061d90e 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(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(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(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(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(ErrorType::ConvertUndefinedToObject); diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.h b/Libraries/LibJS/Runtime/ObjectConstructor.h index 13ad1a57b73..97d8e6b0a6c 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 b790a608f1a..a3ceb3ea631 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 708ddc72457..ceeaa0e092b 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 9617209d5da..510f5f2a268 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 80ddadd7fa0..219485b03f2 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 d54c3fa3951..17749e85c63 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(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 1a605d04279..53b3c23a92d 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 m_body; diff --git a/Libraries/LibJS/Runtime/StringConstructor.cpp b/Libraries/LibJS/Runtime/StringConstructor.cpp index c42731b58fa..ba31d4acbbc 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 1cc6f8a0893..4d6aaa8f188 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 c6da030d794..f9d1a548278 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 e25e6b648cb..bef8d091b01 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&); + 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); - static Value length_getter(Interpreter&); + JS_DECLARE_NATIVE_GETTER(length_getter); - 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(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 a9174f4f28e..a1a4661ae49 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 ced41de12eb..5c7ee56aeff 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 43b959c3008..2d5bdd6a6c8 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(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 5106a0b3703..6c2c10b9e13 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 15ba4295e2c..f9f8267718a 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 a58c6c5dd4b..bf2351789a4 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 }; diff --git a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp index b112afc222b..eecd6b1b4f1 100644 --- a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp +++ b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp @@ -85,7 +85,7 @@ static CanvasRenderingContext2D* impl_from(JS::Interpreter& interpreter) return &static_cast(this_object)->impl(); } -JS::Value CanvasRenderingContext2DWrapper::fill_rect(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::fill_rect) { auto* impl = impl_from(interpreter); if (!impl) @@ -108,7 +108,7 @@ JS::Value CanvasRenderingContext2DWrapper::fill_rect(JS::Interpreter& interprete return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::stroke_rect(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::stroke_rect) { auto* impl = impl_from(interpreter); if (!impl) @@ -131,7 +131,7 @@ JS::Value CanvasRenderingContext2DWrapper::stroke_rect(JS::Interpreter& interpre return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::draw_image(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::draw_image) { auto* impl = impl_from(interpreter); if (!impl) @@ -154,7 +154,7 @@ JS::Value CanvasRenderingContext2DWrapper::draw_image(JS::Interpreter& interpret return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::scale(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::scale) { auto* impl = impl_from(interpreter); if (!impl) @@ -172,7 +172,7 @@ JS::Value CanvasRenderingContext2DWrapper::scale(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::translate(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::translate) { auto* impl = impl_from(interpreter); if (!impl) @@ -190,7 +190,7 @@ JS::Value CanvasRenderingContext2DWrapper::translate(JS::Interpreter& interprete return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::fill_style_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(CanvasRenderingContext2DWrapper::fill_style_getter) { auto* impl = impl_from(interpreter); if (!impl) @@ -198,7 +198,7 @@ JS::Value CanvasRenderingContext2DWrapper::fill_style_getter(JS::Interpreter& in return JS::js_string(interpreter, impl->fill_style()); } -void CanvasRenderingContext2DWrapper::fill_style_setter(JS::Interpreter& interpreter, JS::Value value) +JS_DEFINE_NATIVE_SETTER(CanvasRenderingContext2DWrapper::fill_style_setter) { auto* impl = impl_from(interpreter); if (!impl) @@ -209,7 +209,7 @@ void CanvasRenderingContext2DWrapper::fill_style_setter(JS::Interpreter& interpr impl->set_fill_style(string); } -JS::Value CanvasRenderingContext2DWrapper::stroke_style_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(CanvasRenderingContext2DWrapper::stroke_style_getter) { auto* impl = impl_from(interpreter); if (!impl) @@ -217,7 +217,7 @@ JS::Value CanvasRenderingContext2DWrapper::stroke_style_getter(JS::Interpreter& return JS::js_string(interpreter, impl->stroke_style()); } -void CanvasRenderingContext2DWrapper::stroke_style_setter(JS::Interpreter& interpreter, JS::Value value) +JS_DEFINE_NATIVE_SETTER(CanvasRenderingContext2DWrapper::stroke_style_setter) { auto* impl = impl_from(interpreter); if (!impl) @@ -228,7 +228,7 @@ void CanvasRenderingContext2DWrapper::stroke_style_setter(JS::Interpreter& inter impl->set_stroke_style(string); } -JS::Value CanvasRenderingContext2DWrapper::line_width_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(CanvasRenderingContext2DWrapper::line_width_getter) { auto* impl = impl_from(interpreter); if (!impl) @@ -236,7 +236,7 @@ JS::Value CanvasRenderingContext2DWrapper::line_width_getter(JS::Interpreter& in return JS::Value(impl->line_width()); } -void CanvasRenderingContext2DWrapper::line_width_setter(JS::Interpreter& interpreter, JS::Value value) +JS_DEFINE_NATIVE_SETTER(CanvasRenderingContext2DWrapper::line_width_setter) { auto* impl = impl_from(interpreter); if (!impl) @@ -247,7 +247,7 @@ void CanvasRenderingContext2DWrapper::line_width_setter(JS::Interpreter& interpr impl->set_line_width(line_width); } -JS::Value CanvasRenderingContext2DWrapper::begin_path(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::begin_path) { auto* impl = impl_from(interpreter); if (!impl) @@ -256,7 +256,7 @@ JS::Value CanvasRenderingContext2DWrapper::begin_path(JS::Interpreter& interpret return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::close_path(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::close_path) { auto* impl = impl_from(interpreter); if (!impl) @@ -265,7 +265,7 @@ JS::Value CanvasRenderingContext2DWrapper::close_path(JS::Interpreter& interpret return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::stroke(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::stroke) { auto* impl = impl_from(interpreter); if (!impl) @@ -274,7 +274,7 @@ JS::Value CanvasRenderingContext2DWrapper::stroke(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::fill(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::fill) { auto* impl = impl_from(interpreter); if (!impl) @@ -301,7 +301,7 @@ JS::Value CanvasRenderingContext2DWrapper::fill(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::move_to(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::move_to) { auto* impl = impl_from(interpreter); if (!impl) @@ -316,7 +316,7 @@ JS::Value CanvasRenderingContext2DWrapper::move_to(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::line_to(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::line_to) { auto* impl = impl_from(interpreter); if (!impl) @@ -331,7 +331,7 @@ JS::Value CanvasRenderingContext2DWrapper::line_to(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::quadratic_curve_to(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::quadratic_curve_to) { auto* impl = impl_from(interpreter); if (!impl) @@ -352,7 +352,7 @@ JS::Value CanvasRenderingContext2DWrapper::quadratic_curve_to(JS::Interpreter& i return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::create_image_data(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::create_image_data) { auto* impl = impl_from(interpreter); if (!impl) @@ -363,11 +363,11 @@ JS::Value CanvasRenderingContext2DWrapper::create_image_data(JS::Interpreter& in auto height = interpreter.argument(1).to_i32(interpreter); if (interpreter.exception()) return {}; - auto image_data = impl->create_image_data(interpreter.global_object(), width, height); + auto image_data = impl->create_image_data(global_object, width, height); return wrap(interpreter.heap(), *image_data); } -JS::Value CanvasRenderingContext2DWrapper::put_image_data(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::put_image_data) { auto* impl = impl_from(interpreter); if (!impl) @@ -392,7 +392,7 @@ JS::Value CanvasRenderingContext2DWrapper::put_image_data(JS::Interpreter& inter return JS::js_undefined(); } -JS::Value CanvasRenderingContext2DWrapper::canvas_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(CanvasRenderingContext2DWrapper::canvas_getter) { auto* impl = impl_from(interpreter); if (!impl) diff --git a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h index eed7cc17711..783ddf86275 100644 --- a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h +++ b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h @@ -42,31 +42,31 @@ public: private: virtual const char* class_name() const override { return "CanvasRenderingContext2DWrapper"; } - static JS::Value fill_rect(JS::Interpreter&); - static JS::Value stroke_rect(JS::Interpreter&); - static JS::Value draw_image(JS::Interpreter&); - static JS::Value scale(JS::Interpreter&); - static JS::Value translate(JS::Interpreter&); - static JS::Value begin_path(JS::Interpreter&); - static JS::Value close_path(JS::Interpreter&); - static JS::Value stroke(JS::Interpreter&); - static JS::Value fill(JS::Interpreter&); - static JS::Value move_to(JS::Interpreter&); - static JS::Value line_to(JS::Interpreter&); - static JS::Value quadratic_curve_to(JS::Interpreter&); - static JS::Value create_image_data(JS::Interpreter&); - static JS::Value put_image_data(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(fill_rect); + JS_DECLARE_NATIVE_FUNCTION(stroke_rect); + JS_DECLARE_NATIVE_FUNCTION(draw_image); + JS_DECLARE_NATIVE_FUNCTION(scale); + JS_DECLARE_NATIVE_FUNCTION(translate); + JS_DECLARE_NATIVE_FUNCTION(begin_path); + JS_DECLARE_NATIVE_FUNCTION(close_path); + JS_DECLARE_NATIVE_FUNCTION(stroke); + JS_DECLARE_NATIVE_FUNCTION(fill); + JS_DECLARE_NATIVE_FUNCTION(move_to); + JS_DECLARE_NATIVE_FUNCTION(line_to); + JS_DECLARE_NATIVE_FUNCTION(quadratic_curve_to); + JS_DECLARE_NATIVE_FUNCTION(create_image_data); + JS_DECLARE_NATIVE_FUNCTION(put_image_data); - static JS::Value fill_style_getter(JS::Interpreter&); - static void fill_style_setter(JS::Interpreter&, JS::Value); + JS_DECLARE_NATIVE_GETTER(fill_style_getter); + JS_DECLARE_NATIVE_SETTER(fill_style_setter); - static JS::Value stroke_style_getter(JS::Interpreter&); - static void stroke_style_setter(JS::Interpreter&, JS::Value); + JS_DECLARE_NATIVE_GETTER(stroke_style_getter); + JS_DECLARE_NATIVE_SETTER(stroke_style_setter); - static void line_width_setter(JS::Interpreter&, JS::Value); - static JS::Value line_width_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(line_width_getter); + JS_DECLARE_NATIVE_SETTER(line_width_setter); - static JS::Value canvas_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(canvas_getter); NonnullRefPtr m_impl; }; diff --git a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp index 06954130d61..4e8f35a8c18 100644 --- a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp +++ b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp @@ -72,7 +72,7 @@ static Document* document_from(JS::Interpreter& interpreter) return &static_cast(this_object)->node(); } -JS::Value DocumentWrapper::get_element_by_id(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DocumentWrapper::get_element_by_id) { auto* document = document_from(interpreter); if (!document) @@ -88,7 +88,7 @@ JS::Value DocumentWrapper::get_element_by_id(JS::Interpreter& interpreter) return wrap(interpreter.heap(), const_cast(*element)); } -JS::Value DocumentWrapper::query_selector(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DocumentWrapper::query_selector) { auto* document = document_from(interpreter); if (!document) @@ -105,7 +105,7 @@ JS::Value DocumentWrapper::query_selector(JS::Interpreter& interpreter) return wrap(interpreter.heap(), *element); } -JS::Value DocumentWrapper::query_selector_all(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(DocumentWrapper::query_selector_all) { auto* document = document_from(interpreter); if (!document) @@ -118,7 +118,7 @@ JS::Value DocumentWrapper::query_selector_all(JS::Interpreter& interpreter) // FIXME: Throw if selector is invalid auto elements = document->query_selector_all(selector); // FIXME: This should be a static NodeList, not a plain JS::Array. - auto* node_list = JS::Array::create(interpreter.global_object()); + auto* node_list = JS::Array::create(global_object); for (auto& element : elements) { node_list->indexed_properties().append(wrap(interpreter.heap(), element)); } diff --git a/Libraries/LibWeb/Bindings/DocumentWrapper.h b/Libraries/LibWeb/Bindings/DocumentWrapper.h index 9cf4c765b37..539c2f9bf8d 100644 --- a/Libraries/LibWeb/Bindings/DocumentWrapper.h +++ b/Libraries/LibWeb/Bindings/DocumentWrapper.h @@ -42,9 +42,9 @@ public: private: virtual const char* class_name() const override { return "DocumentWrapper"; } - static JS::Value get_element_by_id(JS::Interpreter&); - static JS::Value query_selector(JS::Interpreter&); - static JS::Value query_selector_all(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(get_element_by_id); + JS_DECLARE_NATIVE_FUNCTION(query_selector); + JS_DECLARE_NATIVE_FUNCTION(query_selector_all); }; } diff --git a/Libraries/LibWeb/Bindings/ElementWrapper.cpp b/Libraries/LibWeb/Bindings/ElementWrapper.cpp index a17c43b51b3..32f82d45700 100644 --- a/Libraries/LibWeb/Bindings/ElementWrapper.cpp +++ b/Libraries/LibWeb/Bindings/ElementWrapper.cpp @@ -72,7 +72,7 @@ static Element* impl_from(JS::Interpreter& interpreter) return &static_cast(this_object)->node(); } -JS::Value ElementWrapper::get_attribute(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ElementWrapper::get_attribute) { auto* impl = impl_from(interpreter); if (!impl) @@ -92,7 +92,7 @@ JS::Value ElementWrapper::get_attribute(JS::Interpreter& interpreter) return JS::js_string(interpreter, attribute_value); } -JS::Value ElementWrapper::set_attribute(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ElementWrapper::set_attribute) { auto* impl = impl_from(interpreter); if (!impl) @@ -113,14 +113,14 @@ JS::Value ElementWrapper::set_attribute(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value ElementWrapper::inner_html_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ElementWrapper::inner_html_getter) { if (auto* impl = impl_from(interpreter)) return JS::js_string(interpreter, impl->inner_html()); return {}; } -void ElementWrapper::inner_html_setter(JS::Interpreter& interpreter, JS::Value value) +JS_DEFINE_NATIVE_SETTER(ElementWrapper::inner_html_setter) { if (auto* impl = impl_from(interpreter)) { auto string = value.to_string(interpreter); @@ -130,14 +130,14 @@ void ElementWrapper::inner_html_setter(JS::Interpreter& interpreter, JS::Value v } } -JS::Value ElementWrapper::id_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ElementWrapper::id_getter) { if (auto* impl = impl_from(interpreter)) return JS::js_string(interpreter, impl->attribute(HTML::AttributeNames::id)); return {}; } -void ElementWrapper::id_setter(JS::Interpreter& interpreter, JS::Value value) +JS_DEFINE_NATIVE_SETTER(ElementWrapper::id_setter) { if (auto* impl = impl_from(interpreter)) { auto string = value.to_string(interpreter); diff --git a/Libraries/LibWeb/Bindings/ElementWrapper.h b/Libraries/LibWeb/Bindings/ElementWrapper.h index df75234d96f..e8bf71ae3b9 100644 --- a/Libraries/LibWeb/Bindings/ElementWrapper.h +++ b/Libraries/LibWeb/Bindings/ElementWrapper.h @@ -42,14 +42,14 @@ public: private: virtual const char* class_name() const override { return "ElementWrapper"; } - static JS::Value inner_html_getter(JS::Interpreter&); - static void inner_html_setter(JS::Interpreter&, JS::Value); + JS_DECLARE_NATIVE_GETTER(inner_html_getter); + JS_DECLARE_NATIVE_SETTER(inner_html_setter); - static JS::Value id_getter(JS::Interpreter&); - static void id_setter(JS::Interpreter&, JS::Value); + JS_DECLARE_NATIVE_GETTER(id_getter); + JS_DECLARE_NATIVE_SETTER(id_setter); - static JS::Value get_attribute(JS::Interpreter&); - static JS::Value set_attribute(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(get_attribute); + JS_DECLARE_NATIVE_FUNCTION(set_attribute); }; } diff --git a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp index e53d6f89aa8..f6eab594299 100644 --- a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp +++ b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp @@ -49,9 +49,9 @@ EventTargetWrapper::~EventTargetWrapper() { } -JS::Value EventTargetWrapper::add_event_listener(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(EventTargetWrapper::add_event_listener) { - 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 (interpreter.argument_count() < 2) diff --git a/Libraries/LibWeb/Bindings/EventTargetWrapper.h b/Libraries/LibWeb/Bindings/EventTargetWrapper.h index f07aef60073..6bb430efec5 100644 --- a/Libraries/LibWeb/Bindings/EventTargetWrapper.h +++ b/Libraries/LibWeb/Bindings/EventTargetWrapper.h @@ -42,7 +42,7 @@ public: private: virtual const char* class_name() const override { return "EventTargetWrapper"; } - static JS::Value add_event_listener(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(add_event_listener); NonnullRefPtr m_impl; }; diff --git a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp index f194b380193..111f1a4b4eb 100644 --- a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp +++ b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp @@ -70,7 +70,7 @@ static HTMLCanvasElement* impl_from(JS::Interpreter& interpreter) return &static_cast(this_object)->node(); } -JS::Value HTMLCanvasElementWrapper::get_context(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(HTMLCanvasElementWrapper::get_context) { auto* impl = impl_from(interpreter); if (!impl) @@ -84,14 +84,14 @@ JS::Value HTMLCanvasElementWrapper::get_context(JS::Interpreter& interpreter) return wrap(interpreter.heap(), *context); } -JS::Value HTMLCanvasElementWrapper::width_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(HTMLCanvasElementWrapper::width_getter) { if (auto* impl = impl_from(interpreter)) return JS::Value(impl->requested_width()); return {}; } -JS::Value HTMLCanvasElementWrapper::height_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(HTMLCanvasElementWrapper::height_getter) { if (auto* impl = impl_from(interpreter)) return JS::Value(impl->requested_height()); diff --git a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.h b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.h index 4f5ae3fc79f..41e7b03d2ba 100644 --- a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.h +++ b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.h @@ -42,10 +42,10 @@ public: private: virtual const char* class_name() const override { return "HTMLCanvasElementWrapper"; } - static JS::Value get_context(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(get_context); - static JS::Value width_getter(JS::Interpreter&); - static JS::Value height_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(width_getter); + JS_DECLARE_NATIVE_GETTER(height_getter); }; } diff --git a/Libraries/LibWeb/Bindings/ImageDataWrapper.cpp b/Libraries/LibWeb/Bindings/ImageDataWrapper.cpp index 8c52fcae393..a62dcf2f5c2 100644 --- a/Libraries/LibWeb/Bindings/ImageDataWrapper.cpp +++ b/Libraries/LibWeb/Bindings/ImageDataWrapper.cpp @@ -67,7 +67,7 @@ static ImageData* impl_from(JS::Interpreter& interpreter) return &static_cast(this_object)->impl(); } -JS::Value ImageDataWrapper::width_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ImageDataWrapper::width_getter) { auto* impl = impl_from(interpreter); if (!impl) @@ -75,7 +75,7 @@ JS::Value ImageDataWrapper::width_getter(JS::Interpreter& interpreter) return JS::Value(impl->width()); } -JS::Value ImageDataWrapper::height_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ImageDataWrapper::height_getter) { auto* impl = impl_from(interpreter); if (!impl) @@ -83,7 +83,7 @@ JS::Value ImageDataWrapper::height_getter(JS::Interpreter& interpreter) return JS::Value(impl->height()); } -JS::Value ImageDataWrapper::data_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(ImageDataWrapper::data_getter) { auto* impl = impl_from(interpreter); if (!impl) diff --git a/Libraries/LibWeb/Bindings/ImageDataWrapper.h b/Libraries/LibWeb/Bindings/ImageDataWrapper.h index 99552553fd9..7772e6f0a0b 100644 --- a/Libraries/LibWeb/Bindings/ImageDataWrapper.h +++ b/Libraries/LibWeb/Bindings/ImageDataWrapper.h @@ -42,9 +42,9 @@ public: private: virtual const char* class_name() const override { return "ImageDataWrapper"; } - static JS::Value width_getter(JS::Interpreter&); - static JS::Value height_getter(JS::Interpreter&); - static JS::Value data_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(width_getter); + JS_DECLARE_NATIVE_GETTER(height_getter); + JS_DECLARE_NATIVE_GETTER(data_getter); NonnullRefPtr m_impl; }; diff --git a/Libraries/LibWeb/Bindings/LocationObject.cpp b/Libraries/LibWeb/Bindings/LocationObject.cpp index 27dddc64d79..b921edf8929 100644 --- a/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -54,36 +54,36 @@ LocationObject::~LocationObject() { } -JS::Value LocationObject::href_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(LocationObject::href_getter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); return JS::js_string(interpreter, window.impl().document().url().to_string()); } -void LocationObject::href_setter(JS::Interpreter& interpreter, JS::Value value) +JS_DEFINE_NATIVE_SETTER(LocationObject::href_setter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); auto new_href = value.to_string(interpreter); if (interpreter.exception()) return; window.impl().did_set_location_href({}, new_href); } -JS::Value LocationObject::pathname_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(LocationObject::pathname_getter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); return JS::js_string(interpreter, window.impl().document().url().path()); } -JS::Value LocationObject::hostname_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(LocationObject::hostname_getter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); return JS::js_string(interpreter, window.impl().document().url().host()); } -JS::Value LocationObject::host_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(LocationObject::host_getter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); auto url = window.impl().document().url(); StringBuilder builder; builder.append(url.host()); @@ -92,9 +92,9 @@ JS::Value LocationObject::host_getter(JS::Interpreter& interpreter) return JS::js_string(interpreter, builder.to_string()); } -JS::Value LocationObject::hash_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(LocationObject::hash_getter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); auto fragment = window.impl().document().url().fragment(); if (!fragment.length()) return JS::js_string(interpreter, ""); @@ -104,9 +104,9 @@ JS::Value LocationObject::hash_getter(JS::Interpreter& interpreter) return JS::js_string(interpreter, builder.to_string()); } -JS::Value LocationObject::search_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(LocationObject::search_getter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); auto query = window.impl().document().url().query(); if (!query.length()) return JS::js_string(interpreter, ""); @@ -116,18 +116,18 @@ JS::Value LocationObject::search_getter(JS::Interpreter& interpreter) return JS::js_string(interpreter, builder.to_string()); } -JS::Value LocationObject::protocol_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(LocationObject::protocol_getter) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); StringBuilder builder; builder.append(window.impl().document().url().protocol()); builder.append(':'); return JS::js_string(interpreter, builder.to_string()); } -JS::Value LocationObject::reload(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) { - auto& window = static_cast(interpreter.global_object()); + auto& window = static_cast(global_object); window.impl().did_call_location_reload({}); return JS::js_undefined(); } diff --git a/Libraries/LibWeb/Bindings/LocationObject.h b/Libraries/LibWeb/Bindings/LocationObject.h index 3e253913fe1..253dbf39c1a 100644 --- a/Libraries/LibWeb/Bindings/LocationObject.h +++ b/Libraries/LibWeb/Bindings/LocationObject.h @@ -40,17 +40,17 @@ public: private: virtual const char* class_name() const override { return "LocationObject"; } - static JS::Value reload(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(reload); - static JS::Value href_getter(JS::Interpreter&); - static void href_setter(JS::Interpreter&, JS::Value); + JS_DECLARE_NATIVE_GETTER(href_getter); + JS_DECLARE_NATIVE_SETTER(href_setter); - static JS::Value host_getter(JS::Interpreter&); - static JS::Value hostname_getter(JS::Interpreter&); - static JS::Value pathname_getter(JS::Interpreter&); - static JS::Value hash_getter(JS::Interpreter&); - static JS::Value search_getter(JS::Interpreter&); - static JS::Value protocol_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(host_getter); + JS_DECLARE_NATIVE_GETTER(hostname_getter); + JS_DECLARE_NATIVE_GETTER(pathname_getter); + JS_DECLARE_NATIVE_GETTER(hash_getter); + JS_DECLARE_NATIVE_GETTER(search_getter); + JS_DECLARE_NATIVE_GETTER(protocol_getter); }; } diff --git a/Libraries/LibWeb/Bindings/MouseEventWrapper.cpp b/Libraries/LibWeb/Bindings/MouseEventWrapper.cpp index 57ec50b853a..6633bf5a853 100644 --- a/Libraries/LibWeb/Bindings/MouseEventWrapper.cpp +++ b/Libraries/LibWeb/Bindings/MouseEventWrapper.cpp @@ -65,14 +65,14 @@ static MouseEvent* impl_from(JS::Interpreter& interpreter) return &static_cast(this_object)->event(); } -JS::Value MouseEventWrapper::offset_x_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(MouseEventWrapper::offset_x_getter) { if (auto* impl = impl_from(interpreter)) return JS::Value(impl->offset_x()); return {}; } -JS::Value MouseEventWrapper::offset_y_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(MouseEventWrapper::offset_y_getter) { if (auto* impl = impl_from(interpreter)) return JS::Value(impl->offset_y()); diff --git a/Libraries/LibWeb/Bindings/MouseEventWrapper.h b/Libraries/LibWeb/Bindings/MouseEventWrapper.h index 606e4017df5..ffa778b1fc0 100644 --- a/Libraries/LibWeb/Bindings/MouseEventWrapper.h +++ b/Libraries/LibWeb/Bindings/MouseEventWrapper.h @@ -42,8 +42,8 @@ public: private: virtual const char* class_name() const override { return "MouseEventWrapper"; } - static JS::Value offset_x_getter(JS::Interpreter&); - static JS::Value offset_y_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(offset_x_getter); + JS_DECLARE_NATIVE_GETTER(offset_y_getter); }; } diff --git a/Libraries/LibWeb/Bindings/NavigatorObject.cpp b/Libraries/LibWeb/Bindings/NavigatorObject.cpp index 1cf7dad679d..28fbfb23fbe 100644 --- a/Libraries/LibWeb/Bindings/NavigatorObject.cpp +++ b/Libraries/LibWeb/Bindings/NavigatorObject.cpp @@ -55,7 +55,7 @@ NavigatorObject::~NavigatorObject() { } -JS::Value NavigatorObject::user_agent_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(NavigatorObject::user_agent_getter) { return JS::js_string(interpreter, ResourceLoader::the().user_agent()); } diff --git a/Libraries/LibWeb/Bindings/NavigatorObject.h b/Libraries/LibWeb/Bindings/NavigatorObject.h index 5f12f4b8a6b..b7b69be585d 100644 --- a/Libraries/LibWeb/Bindings/NavigatorObject.h +++ b/Libraries/LibWeb/Bindings/NavigatorObject.h @@ -40,7 +40,7 @@ public: private: virtual const char* class_name() const override { return "NavigatorObject"; } - static JS::Value user_agent_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(user_agent_getter); }; } diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index 244e6313069..8fc0e92dd4f 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -94,7 +94,7 @@ static Window* impl_from(JS::Interpreter& interpreter) return &static_cast(this_object)->impl(); } -JS::Value WindowObject::alert(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(WindowObject::alert) { auto* impl = impl_from(interpreter); if (!impl) @@ -109,7 +109,7 @@ JS::Value WindowObject::alert(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value WindowObject::confirm(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(WindowObject::confirm) { auto* impl = impl_from(interpreter); if (!impl) @@ -123,7 +123,7 @@ JS::Value WindowObject::confirm(JS::Interpreter& interpreter) return JS::Value(impl->confirm(message)); } -JS::Value WindowObject::set_interval(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_interval) { auto* impl = impl_from(interpreter); if (!impl) @@ -149,7 +149,7 @@ JS::Value WindowObject::set_interval(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_timeout) { auto* impl = impl_from(interpreter); if (!impl) @@ -175,7 +175,7 @@ JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value WindowObject::request_animation_frame(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(WindowObject::request_animation_frame) { auto* impl = impl_from(interpreter); if (!impl) @@ -190,7 +190,7 @@ JS::Value WindowObject::request_animation_frame(JS::Interpreter& interpreter) return JS::Value(impl->request_animation_frame(*static_cast(callback_object))); } -JS::Value WindowObject::cancel_animation_frame(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_animation_frame) { auto* impl = impl_from(interpreter); if (!impl) @@ -204,7 +204,7 @@ JS::Value WindowObject::cancel_animation_frame(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value WindowObject::document_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter) { auto* impl = impl_from(interpreter); if (!impl) @@ -212,9 +212,10 @@ JS::Value WindowObject::document_getter(JS::Interpreter& interpreter) return wrap(interpreter.heap(), impl->document()); } -void WindowObject::document_setter(JS::Interpreter&, JS::Value) +JS_DEFINE_NATIVE_SETTER(WindowObject::document_setter) { // FIXME: Figure out what we should do here. Just ignore attempts to set window.document for now. + UNUSED_PARAM(value); } } diff --git a/Libraries/LibWeb/Bindings/WindowObject.h b/Libraries/LibWeb/Bindings/WindowObject.h index 39b00db2464..dff689c8e49 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.h +++ b/Libraries/LibWeb/Bindings/WindowObject.h @@ -48,15 +48,15 @@ private: virtual const char* class_name() const override { return "WindowObject"; } virtual void visit_children(Visitor&) override; - static JS::Value document_getter(JS::Interpreter&); - static void document_setter(JS::Interpreter&, JS::Value); + JS_DECLARE_NATIVE_GETTER(document_getter); + JS_DECLARE_NATIVE_SETTER(document_setter); - static JS::Value alert(JS::Interpreter&); - static JS::Value confirm(JS::Interpreter&); - static JS::Value set_interval(JS::Interpreter&); - static JS::Value set_timeout(JS::Interpreter&); - static JS::Value request_animation_frame(JS::Interpreter&); - static JS::Value cancel_animation_frame(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(alert); + JS_DECLARE_NATIVE_FUNCTION(confirm); + JS_DECLARE_NATIVE_FUNCTION(set_interval); + JS_DECLARE_NATIVE_FUNCTION(set_timeout); + JS_DECLARE_NATIVE_FUNCTION(request_animation_frame); + JS_DECLARE_NATIVE_FUNCTION(cancel_animation_frame); NonnullRefPtr m_impl; diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp index e03baa8304a..ea871c66635 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp @@ -66,7 +66,7 @@ static XMLHttpRequest* impl_from(JS::Interpreter& interpreter) return &static_cast(this_object)->impl(); } -JS::Value XMLHttpRequestPrototype::open(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::open) { auto* impl = impl_from(interpreter); if (!impl) @@ -81,7 +81,7 @@ JS::Value XMLHttpRequestPrototype::open(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value XMLHttpRequestPrototype::send(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::send) { auto* impl = impl_from(interpreter); if (!impl) @@ -90,7 +90,7 @@ JS::Value XMLHttpRequestPrototype::send(JS::Interpreter& interpreter) return JS::js_undefined(); } -JS::Value XMLHttpRequestPrototype::ready_state_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::ready_state_getter) { auto* impl = impl_from(interpreter); if (!impl) @@ -98,7 +98,7 @@ JS::Value XMLHttpRequestPrototype::ready_state_getter(JS::Interpreter& interpret return JS::Value((i32)impl->ready_state()); } -JS::Value XMLHttpRequestPrototype::response_text_getter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::response_text_getter) { auto* impl = impl_from(interpreter); if (!impl) diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h index 3fa5d48869a..50ba87d2367 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h @@ -39,11 +39,11 @@ public: private: virtual const char* class_name() const override { return "XMLHttpRequestPrototype"; } - static JS::Value open(JS::Interpreter&); - static JS::Value send(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(open); + JS_DECLARE_NATIVE_FUNCTION(send); - static JS::Value ready_state_getter(JS::Interpreter&); - static JS::Value response_text_getter(JS::Interpreter&); + JS_DECLARE_NATIVE_GETTER(ready_state_getter); + JS_DECLARE_NATIVE_GETTER(response_text_getter); }; } diff --git a/Userland/js.cpp b/Userland/js.cpp index 548c0dc567d..8178c0c2543 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -55,14 +55,15 @@ public: virtual void initialize() override; virtual ~ReplObject() override; - static JS::Value load_file(JS::Interpreter&); - static JS::Value is_strict_mode(JS::Interpreter&); + JS_DECLARE_NATIVE_FUNCTION(load_file); + JS_DECLARE_NATIVE_FUNCTION(is_strict_mode); private: virtual const char* class_name() const override { return "ReplObject"; } - static JS::Value exit_interpreter(JS::Interpreter&); - static JS::Value repl_help(JS::Interpreter&); - static JS::Value save_to_file(JS::Interpreter&); + + JS_DECLARE_NATIVE_FUNCTION(exit_interpreter); + JS_DECLARE_NATIVE_FUNCTION(repl_help); + JS_DECLARE_NATIVE_FUNCTION(save_to_file); }; static bool s_dump_ast = false; @@ -384,7 +385,7 @@ ReplObject::~ReplObject() { } -JS::Value ReplObject::save_to_file(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReplObject::save_to_file) { if (!interpreter.argument_count()) return JS::Value(false); @@ -396,7 +397,7 @@ JS::Value ReplObject::save_to_file(JS::Interpreter& interpreter) return JS::Value(false); } -JS::Value ReplObject::exit_interpreter(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReplObject::exit_interpreter) { if (!interpreter.argument_count()) exit(0); @@ -406,7 +407,7 @@ JS::Value ReplObject::exit_interpreter(JS::Interpreter& interpreter) exit(exit_code.as_double()); } -JS::Value ReplObject::repl_help(JS::Interpreter&) +JS_DEFINE_NATIVE_FUNCTION(ReplObject::repl_help) { printf("REPL commands:\n"); printf(" exit(code): exit the REPL with specified code. Defaults to 0.\n"); @@ -416,7 +417,7 @@ JS::Value ReplObject::repl_help(JS::Interpreter&) return JS::js_undefined(); } -JS::Value ReplObject::load_file(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_file) { if (!interpreter.argument_count()) return JS::Value(false); @@ -440,7 +441,7 @@ JS::Value ReplObject::load_file(JS::Interpreter& interpreter) return JS::Value(true); } -JS::Value ReplObject::is_strict_mode(JS::Interpreter& interpreter) +JS_DEFINE_NATIVE_FUNCTION(ReplObject::is_strict_mode) { return JS::Value(interpreter.in_strict_mode()); }