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

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.
This commit is contained in:
Andreas Kling 2020-06-20 13:55:34 +02:00
parent 4aa98052ca
commit e4add19915
79 changed files with 541 additions and 519 deletions

View file

@ -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) \

View file

@ -61,7 +61,7 @@ Array* array_from(Interpreter& interpreter, GlobalObject& global_object)
return static_cast<Array*>(this_object);
}
Value Array::length_getter(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(Array::length_getter)
{
auto* array = array_from(interpreter, interpreter.global_object());
if (!array)
@ -69,9 +69,9 @@ Value Array::length_getter(Interpreter& interpreter)
return Value(static_cast<i32>(array->indexed_properties().array_like_size()));
}
void Array::length_setter(Interpreter& interpreter, Value value)
JS_DEFINE_NATIVE_SETTER(Array::length_setter)
{
auto* array = array_from(interpreter, interpreter.global_object());
auto* array = array_from(interpreter, global_object);
if (!array)
return;
auto length = value.to_number(interpreter);

View file

@ -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);
};
}

View file

@ -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;

View file

@ -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);
};
}

View file

@ -139,10 +139,10 @@ static void for_each_item(Interpreter& interpreter, GlobalObject& global_object,
}
}
Value ArrayPrototype::filter(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter)
{
auto* new_array = Array::create(interpreter.global_object());
for_each_item(interpreter, interpreter.global_object(), "filter", [&](auto, auto value, auto callback_result) {
auto* new_array = Array::create(global_object);
for_each_item(interpreter, global_object, "filter", [&](auto, auto value, auto callback_result) {
if (callback_result.to_boolean())
new_array->indexed_properties().append(value);
return IterationDecision::Continue;
@ -150,25 +150,25 @@ Value ArrayPrototype::filter(Interpreter& interpreter)
return Value(new_array);
}
Value ArrayPrototype::for_each(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::for_each)
{
for_each_item(interpreter, interpreter.global_object(), "forEach", [](auto, auto, auto) {
for_each_item(interpreter, global_object, "forEach", [](auto, auto, auto) {
return IterationDecision::Continue;
});
return js_undefined();
}
Value ArrayPrototype::map(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
auto initial_length = get_length(interpreter, *this_object);
if (interpreter.exception())
return {};
auto* new_array = Array::create(interpreter.global_object());
auto* new_array = Array::create(global_object);
new_array->indexed_properties().set_array_like_size(initial_length);
for_each_item(interpreter, interpreter.global_object(), "map", [&](auto index, auto, auto callback_result) {
for_each_item(interpreter, global_object, "map", [&](auto index, auto, auto callback_result) {
new_array->put(index, callback_result);
if (interpreter.exception())
return IterationDecision::Break;
@ -177,9 +177,9 @@ Value ArrayPrototype::map(Interpreter& interpreter)
return Value(new_array);
}
Value ArrayPrototype::push(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
if (this_object->is_array()) {
@ -207,9 +207,9 @@ Value ArrayPrototype::push(Interpreter& interpreter)
return new_length_value;
}
Value ArrayPrototype::unshift(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift)
{
auto* array = array_from(interpreter, interpreter.global_object());
auto* array = array_from(interpreter, global_object);
if (!array)
return {};
for (size_t i = 0; i < interpreter.argument_count(); ++i)
@ -217,9 +217,9 @@ Value ArrayPrototype::unshift(Interpreter& interpreter)
return Value(static_cast<i32>(array->indexed_properties().array_like_size()));
}
Value ArrayPrototype::pop(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
if (this_object->is_array()) {
@ -246,9 +246,9 @@ Value ArrayPrototype::pop(Interpreter& interpreter)
return element;
}
Value ArrayPrototype::shift(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift)
{
auto* array = array_from(interpreter, interpreter.global_object());
auto* array = array_from(interpreter, global_object);
if (!array)
return {};
if (array->indexed_properties().is_empty())
@ -259,22 +259,22 @@ Value ArrayPrototype::shift(Interpreter& interpreter)
return result.value.value_or(js_undefined());
}
Value ArrayPrototype::to_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
auto join_function = this_object->get("join");
if (interpreter.exception())
return {};
if (!join_function.is_function())
return ObjectPrototype::to_string(interpreter);
return ObjectPrototype::to_string(interpreter, global_object);
return interpreter.call(join_function.as_function(), this_object);
}
Value ArrayPrototype::to_locale_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
String separator = ","; // NOTE: This is implementation-specific.
@ -303,9 +303,9 @@ Value ArrayPrototype::to_locale_string(Interpreter& interpreter)
return js_string(interpreter, builder.to_string());
}
Value ArrayPrototype::join(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
String separator = ",";
@ -334,13 +334,13 @@ Value ArrayPrototype::join(Interpreter& interpreter)
return js_string(interpreter, builder.to_string());
}
Value ArrayPrototype::concat(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
{
auto* array = array_from(interpreter, interpreter.global_object());
auto* array = array_from(interpreter, global_object);
if (!array)
return {};
auto* new_array = Array::create(interpreter.global_object());
auto* new_array = Array::create(global_object);
new_array->indexed_properties().append_all(array, array->indexed_properties());
if (interpreter.exception())
return {};
@ -360,13 +360,13 @@ Value ArrayPrototype::concat(Interpreter& interpreter)
return Value(new_array);
}
Value ArrayPrototype::slice(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice)
{
auto* array = array_from(interpreter, interpreter.global_object());
auto* array = array_from(interpreter, global_object);
if (!array)
return {};
auto* new_array = Array::create(interpreter.global_object());
auto* new_array = Array::create(global_object);
if (interpreter.argument_count() == 0) {
new_array->indexed_properties().append_all(array, array->indexed_properties());
if (interpreter.exception())
@ -405,9 +405,9 @@ Value ArrayPrototype::slice(Interpreter& interpreter)
return new_array;
}
Value ArrayPrototype::index_of(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
i32 length = get_length(interpreter, *this_object);
@ -436,9 +436,9 @@ Value ArrayPrototype::index_of(Interpreter& interpreter)
return Value(-1);
}
Value ArrayPrototype::reduce(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
@ -495,9 +495,9 @@ Value ArrayPrototype::reduce(Interpreter& interpreter)
return accumulator;
}
Value ArrayPrototype::reduce_right(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
@ -554,9 +554,9 @@ Value ArrayPrototype::reduce_right(Interpreter& interpreter)
return accumulator;
}
Value ArrayPrototype::reverse(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse)
{
auto* array = array_from(interpreter, interpreter.global_object());
auto* array = array_from(interpreter, global_object);
if (!array)
return {};
@ -578,9 +578,9 @@ Value ArrayPrototype::reverse(Interpreter& interpreter)
return array;
}
Value ArrayPrototype::last_index_of(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
i32 length = get_length(interpreter, *this_object);
@ -609,9 +609,9 @@ Value ArrayPrototype::last_index_of(Interpreter& interpreter)
return Value(-1);
}
Value ArrayPrototype::includes(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::includes)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
i32 length = get_length(interpreter, *this_object);
@ -640,11 +640,11 @@ Value ArrayPrototype::includes(Interpreter& interpreter)
return Value(false);
}
Value ArrayPrototype::find(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find)
{
auto result = js_undefined();
for_each_item(
interpreter, interpreter.global_object(), "find", [&](auto, auto value, auto callback_result) {
interpreter, global_object, "find", [&](auto, auto value, auto callback_result) {
if (callback_result.to_boolean()) {
result = value;
return IterationDecision::Break;
@ -655,11 +655,11 @@ Value ArrayPrototype::find(Interpreter& interpreter)
return result;
}
Value ArrayPrototype::find_index(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index)
{
auto result_index = -1;
for_each_item(
interpreter, interpreter.global_object(), "findIndex", [&](auto index, auto, auto callback_result) {
interpreter, global_object, "findIndex", [&](auto index, auto, auto callback_result) {
if (callback_result.to_boolean()) {
result_index = index;
return IterationDecision::Break;
@ -670,10 +670,10 @@ Value ArrayPrototype::find_index(Interpreter& interpreter)
return Value(result_index);
}
Value ArrayPrototype::some(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some)
{
auto result = false;
for_each_item(interpreter, interpreter.global_object(), "some", [&](auto, auto, auto callback_result) {
for_each_item(interpreter, global_object, "some", [&](auto, auto, auto callback_result) {
if (callback_result.to_boolean()) {
result = true;
return IterationDecision::Break;
@ -683,10 +683,10 @@ Value ArrayPrototype::some(Interpreter& interpreter)
return Value(result);
}
Value ArrayPrototype::every(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every)
{
auto result = true;
for_each_item(interpreter, interpreter.global_object(), "every", [&](auto, auto, auto callback_result) {
for_each_item(interpreter, global_object, "every", [&](auto, auto, auto callback_result) {
if (!callback_result.to_boolean()) {
result = false;
return IterationDecision::Break;
@ -696,9 +696,9 @@ Value ArrayPrototype::every(Interpreter& interpreter)
return Value(result);
}
Value ArrayPrototype::splice(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
@ -736,7 +736,7 @@ Value ArrayPrototype::splice(Interpreter& interpreter)
if (new_length > MAX_ARRAY_LIKE_INDEX)
return interpreter.throw_exception<TypeError>(ErrorType::ArrayMaxSize);
auto removed_elements = Array::create(interpreter.global_object());
auto removed_elements = Array::create(global_object);
for (size_t i = 0; i < actual_delete_count; ++i) {
auto value = this_object->get(actual_start + i);
@ -799,9 +799,9 @@ Value ArrayPrototype::splice(Interpreter& interpreter)
return removed_elements;
}
Value ArrayPrototype::fill(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::fill)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};

View file

@ -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);
};
}

View file

@ -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();
}

View file

@ -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);
};
}

View file

@ -57,22 +57,22 @@ static BigIntObject* bigint_object_from(Interpreter& interpreter, GlobalObject&
return static_cast<BigIntObject*>(this_object);
}
Value BigIntPrototype::to_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string)
{
auto* bigint_object = bigint_object_from(interpreter, interpreter.global_object());
auto* bigint_object = bigint_object_from(interpreter, global_object);
if (!bigint_object)
return {};
return js_string(interpreter, bigint_object->bigint().big_integer().to_base10());
}
Value BigIntPrototype::to_locale_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string)
{
return to_string(interpreter);
return to_string(interpreter, global_object);
}
Value BigIntPrototype::value_of(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::value_of)
{
auto* bigint_object = bigint_object_from(interpreter, interpreter.global_object());
auto* bigint_object = bigint_object_from(interpreter, global_object);
if (!bigint_object)
return {};
return bigint_object->value_of();

View file

@ -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);
};
}

View file

@ -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;
}

View file

@ -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);
};
}

View file

@ -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();
}

View file

@ -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);
};
}

View file

@ -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);

View file

@ -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);
};
}

View file

@ -70,7 +70,7 @@ DatePrototype::~DatePrototype()
{
}
Value DatePrototype::get_date(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -79,7 +79,7 @@ Value DatePrototype::get_date(Interpreter& interpreter)
return Value(static_cast<double>(date));
}
Value DatePrototype::get_day(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -88,7 +88,7 @@ Value DatePrototype::get_day(Interpreter& interpreter)
return Value(static_cast<double>(day));
}
Value DatePrototype::get_full_year(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -97,7 +97,7 @@ Value DatePrototype::get_full_year(Interpreter& interpreter)
return Value(static_cast<double>(full_year));
}
Value DatePrototype::get_hours(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -106,7 +106,7 @@ Value DatePrototype::get_hours(Interpreter& interpreter)
return Value(static_cast<double>(hours));
}
Value DatePrototype::get_milliseconds(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -115,7 +115,7 @@ Value DatePrototype::get_milliseconds(Interpreter& interpreter)
return Value(static_cast<double>(milliseconds));
}
Value DatePrototype::get_minutes(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -124,7 +124,7 @@ Value DatePrototype::get_minutes(Interpreter& interpreter)
return Value(static_cast<double>(minutes));
}
Value DatePrototype::get_month(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -133,7 +133,7 @@ Value DatePrototype::get_month(Interpreter& interpreter)
return Value(static_cast<double>(months));
}
Value DatePrototype::get_seconds(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -142,7 +142,7 @@ Value DatePrototype::get_seconds(Interpreter& interpreter)
return Value(static_cast<double>(seconds));
}
Value DatePrototype::get_time(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -152,7 +152,7 @@ Value DatePrototype::get_time(Interpreter& interpreter)
return Value(static_cast<double>(seconds * 1000 + milliseconds));
}
Value DatePrototype::to_date_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -161,7 +161,7 @@ Value DatePrototype::to_date_string(Interpreter& interpreter)
return js_string(interpreter, move(string));
}
Value DatePrototype::to_time_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)
@ -170,7 +170,7 @@ Value DatePrototype::to_time_string(Interpreter& interpreter)
return js_string(interpreter, move(string));
}
Value DatePrototype::to_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string)
{
auto* this_object = this_date_from_interpreter(interpreter);
if (!this_object)

View file

@ -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);
};
}

View file

@ -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

View file

@ -48,9 +48,9 @@ ErrorPrototype::~ErrorPrototype()
{
}
Value ErrorPrototype::name_getter(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(ErrorPrototype::name_getter)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
if (!this_object->is_error())
@ -58,9 +58,9 @@ Value ErrorPrototype::name_getter(Interpreter& interpreter)
return js_string(interpreter, static_cast<const Error*>(this_object)->name());
}
void ErrorPrototype::name_setter(Interpreter& interpreter, Value value)
JS_DEFINE_NATIVE_SETTER(ErrorPrototype::name_setter)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return;
if (!this_object->is_error()) {
@ -73,9 +73,9 @@ void ErrorPrototype::name_setter(Interpreter& interpreter, Value value)
static_cast<Error*>(this_object)->set_name(name);
}
Value ErrorPrototype::message_getter(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(ErrorPrototype::message_getter)
{
auto* this_object = interpreter.this_value(interpreter.global_object()).to_object(interpreter);
auto* this_object = interpreter.this_value(global_object).to_object(interpreter);
if (!this_object)
return {};
if (!this_object->is_error())
@ -83,11 +83,11 @@ Value ErrorPrototype::message_getter(Interpreter& interpreter)
return js_string(interpreter, static_cast<const Error*>(this_object)->message());
}
Value ErrorPrototype::to_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
{
if (!interpreter.this_value(interpreter.global_object()).is_object())
return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, interpreter.this_value(interpreter.global_object()).to_string_without_side_effects().characters());
auto& this_object = interpreter.this_value(interpreter.global_object()).as_object();
if (!interpreter.this_value(global_object).is_object())
return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, interpreter.this_value(global_object).to_string_without_side_effects().characters());
auto& this_object = interpreter.this_value(global_object).as_object();
String name = "Error";
auto name_property = this_object.get("name");

View file

@ -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) \

View file

@ -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())

View file

@ -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);
};
}

View file

@ -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);

View file

@ -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 };

View file

@ -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 {};

View file

@ -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);
};
}

View file

@ -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())

View file

@ -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);
};
}

View file

@ -31,7 +31,7 @@
namespace JS {
NativeFunction* NativeFunction::create(Interpreter&, GlobalObject& global_object, const FlyString& name, AK::Function<Value(Interpreter&)> function)
NativeFunction* NativeFunction::create(Interpreter&, GlobalObject& global_object, const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)> function)
{
return global_object.heap().allocate<NativeFunction>(name, move(function), *global_object.function_prototype());
}
@ -41,7 +41,7 @@ NativeFunction::NativeFunction(Object& prototype)
{
}
NativeFunction::NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&)> native_function, Object& prototype)
NativeFunction::NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)> native_function, Object& prototype)
: Function(prototype)
, m_name(name)
, m_native_function(move(native_function))
@ -60,7 +60,7 @@ NativeFunction::~NativeFunction()
Value NativeFunction::call(Interpreter& interpreter)
{
return m_native_function(interpreter);
return m_native_function(interpreter, global_object());
}
Value NativeFunction::construct(Interpreter&)

View file

@ -33,9 +33,9 @@ namespace JS {
class NativeFunction : public Function {
public:
static NativeFunction* create(Interpreter&, GlobalObject&, const FlyString& name, AK::Function<Value(Interpreter&)>);
static NativeFunction* create(Interpreter&, GlobalObject&, const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)>);
explicit NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&)>, Object& prototype);
explicit NativeFunction(const FlyString& name, AK::Function<Value(Interpreter&, GlobalObject&)>, Object& prototype);
virtual ~NativeFunction() override;
virtual Value call(Interpreter&) override;
@ -54,7 +54,7 @@ private:
virtual LexicalEnvironment* create_environment() override final { return nullptr; }
FlyString m_name;
AK::Function<Value(Interpreter&)> m_native_function;
AK::Function<Value(Interpreter&, GlobalObject&)> m_native_function;
};
}

View file

@ -29,7 +29,7 @@
namespace JS {
NativeProperty::NativeProperty(AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter)
NativeProperty::NativeProperty(AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter)
: Object(nullptr)
, m_getter(move(getter))
, m_setter(move(setter))
@ -44,14 +44,14 @@ Value NativeProperty::get(Interpreter& interpreter) const
{
if (!m_getter)
return js_undefined();
return m_getter(interpreter);
return m_getter(interpreter, global_object());
}
void NativeProperty::set(Interpreter& interpreter, Value value)
{
if (!m_setter)
return;
m_setter(interpreter, move(value));
m_setter(interpreter, global_object(), move(value));
}
}

View file

@ -33,7 +33,7 @@ namespace JS {
class NativeProperty final : public Object {
public:
NativeProperty(AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter);
NativeProperty(AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter);
virtual ~NativeProperty() override;
Value get(Interpreter&) const;
@ -43,8 +43,8 @@ private:
virtual bool is_native_property() const override { return true; }
virtual const char* class_name() const override { return "NativeProperty"; }
AK::Function<Value(Interpreter&)> m_getter;
AK::Function<void(Interpreter&, Value)> m_setter;
AK::Function<Value(Interpreter&, GlobalObject&)> m_getter;
AK::Function<void(Interpreter&, GlobalObject&, Value)> m_setter;
};
}

View file

@ -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);

View file

@ -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);
};
}

View file

@ -680,7 +680,7 @@ bool Object::put(PropertyName property_name, Value value)
return put_own_property(*this, property_string, value, default_attributes, PutOwnPropertyMode::Put);
}
bool Object::define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)> native_function, i32 length, PropertyAttributes attribute)
bool Object::define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute)
{
auto* function = NativeFunction::create(interpreter(), global_object(), property_name, move(native_function));
function->define_property("length", Value(length), Attribute::Configurable);
@ -692,7 +692,7 @@ bool Object::define_native_function(const FlyString& property_name, AK::Function
return define_property(property_name, function, attribute);
}
bool Object::define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter, PropertyAttributes attribute)
bool Object::define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter, PropertyAttributes attribute)
{
return define_property(property_name, heap().allocate<NativeProperty>(move(getter), move(setter)), attribute);
}

View file

@ -90,8 +90,8 @@ public:
virtual bool define_property(const FlyString& property_name, const Object& descriptor, bool throw_exceptions = true);
bool define_property(PropertyName, Value value, PropertyAttributes attributes = default_attributes, bool throw_exceptions = true);
bool define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)>, i32 length = 0, PropertyAttributes attributes = default_attributes);
bool define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter, PropertyAttributes attributes = default_attributes);
bool define_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)>, i32 length = 0, PropertyAttributes attributes = default_attributes);
bool define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter, PropertyAttributes attributes = default_attributes);
virtual Value delete_property(PropertyName);

View file

@ -69,14 +69,14 @@ Value ObjectConstructor::construct(Interpreter& interpreter)
return call(interpreter);
}
Value ObjectConstructor::get_own_property_names(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names)
{
if (!interpreter.argument_count())
return {};
auto* object = interpreter.argument(0).to_object(interpreter);
if (interpreter.exception())
return {};
auto* result = Array::create(interpreter.global_object());
auto* result = Array::create(global_object);
for (auto& entry : object->indexed_properties())
result->indexed_properties().append(js_string(interpreter, String::number(entry.index())));
for (auto& it : object->shape().property_table_ordered())
@ -85,7 +85,7 @@ Value ObjectConstructor::get_own_property_names(Interpreter& interpreter)
return result;
}
Value ObjectConstructor::get_prototype_of(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of)
{
if (!interpreter.argument_count())
return {};
@ -95,7 +95,7 @@ Value ObjectConstructor::get_prototype_of(Interpreter& interpreter)
return object->prototype();
}
Value ObjectConstructor::set_prototype_of(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of)
{
if (interpreter.argument_count() < 2)
return interpreter.throw_exception<TypeError>(ErrorType::ObjectSetPrototypeOfTwoArgs);
@ -120,7 +120,7 @@ Value ObjectConstructor::set_prototype_of(Interpreter& interpreter)
return object;
}
Value ObjectConstructor::is_extensible(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible)
{
auto argument = interpreter.argument(0);
if (!argument.is_object())
@ -128,7 +128,7 @@ Value ObjectConstructor::is_extensible(Interpreter& interpreter)
return Value(argument.as_object().is_extensible());
}
Value ObjectConstructor::prevent_extensions(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions)
{
auto argument = interpreter.argument(0);
if (!argument.is_object())
@ -141,7 +141,7 @@ Value ObjectConstructor::prevent_extensions(Interpreter& interpreter)
return argument;
}
Value ObjectConstructor::get_own_property_descriptor(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor)
{
auto* object = interpreter.argument(0).to_object(interpreter);
if (interpreter.exception())
@ -152,7 +152,7 @@ Value ObjectConstructor::get_own_property_descriptor(Interpreter& interpreter)
return object->get_own_property_descriptor_object(property_key);
}
Value ObjectConstructor::define_property_(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property_)
{
if (!interpreter.argument(0).is_object())
return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, "Object argument");
@ -176,12 +176,12 @@ Value ObjectConstructor::define_property_(Interpreter& interpreter)
return &object;
}
Value ObjectConstructor::is(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is)
{
return Value(same_value(interpreter, interpreter.argument(0), interpreter.argument(1)));
}
Value ObjectConstructor::keys(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
{
if (!interpreter.argument_count())
return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject);
@ -193,7 +193,7 @@ Value ObjectConstructor::keys(Interpreter& interpreter)
return obj_arg->get_own_properties(*obj_arg, GetOwnPropertyMode::Key, true);
}
Value ObjectConstructor::values(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
{
if (!interpreter.argument_count())
return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject);
@ -205,7 +205,7 @@ Value ObjectConstructor::values(Interpreter& interpreter)
return obj_arg->get_own_properties(*obj_arg, GetOwnPropertyMode::Value, true);
}
Value ObjectConstructor::entries(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
{
if (!interpreter.argument_count())
return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject);

View file

@ -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);
};
}

View file

@ -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();

View file

@ -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);
};
}

View file

@ -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)

View file

@ -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);
};
}

View file

@ -130,7 +130,7 @@ Value ScriptFunction::construct(Interpreter& interpreter)
return call(interpreter);
}
Value ScriptFunction::length_getter(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter)
{
auto* function = script_function_from(interpreter);
if (!function)
@ -138,7 +138,7 @@ Value ScriptFunction::length_getter(Interpreter& interpreter)
return Value(static_cast<i32>(function->m_function_length));
}
Value ScriptFunction::name_getter(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(ScriptFunction::name_getter)
{
auto* function = script_function_from(interpreter);
if (!function)

View file

@ -53,8 +53,8 @@ private:
virtual LexicalEnvironment* create_environment() override;
virtual void visit_children(Visitor&) override;
static Value length_getter(Interpreter&);
static Value name_getter(Interpreter&);
JS_DECLARE_NATIVE_GETTER(length_getter);
JS_DECLARE_NATIVE_GETTER(name_getter);
FlyString m_name;
NonnullRefPtr<Statement> m_body;

View file

@ -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) {

View file

@ -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);
};
}

View file

@ -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())

View file

@ -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);
};
}

View file

@ -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()) {

View file

@ -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);
};
}

View file

@ -64,7 +64,7 @@ static SymbolObject* this_symbol_from_interpreter(Interpreter& interpreter)
return static_cast<SymbolObject*>(this_object);
}
Value SymbolPrototype::description_getter(Interpreter& interpreter)
JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter)
{
auto* this_object = this_symbol_from_interpreter(interpreter);
if (!this_object)
@ -72,7 +72,7 @@ Value SymbolPrototype::description_getter(Interpreter& interpreter)
return js_string(interpreter, this_object->description());
}
Value SymbolPrototype::to_string(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string)
{
auto* this_object = this_symbol_from_interpreter(interpreter);
if (!this_object)
@ -81,7 +81,7 @@ Value SymbolPrototype::to_string(Interpreter& interpreter)
return js_string(interpreter, move(string));
}
Value SymbolPrototype::value_of(Interpreter& interpreter)
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::value_of)
{
auto* this_object = this_symbol_from_interpreter(interpreter);
if (!this_object)

View file

@ -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);
};
}

View file

@ -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")

View file

@ -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 };

View file

@ -85,7 +85,7 @@ static CanvasRenderingContext2D* impl_from(JS::Interpreter& interpreter)
return &static_cast<CanvasRenderingContext2DWrapper*>(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)

View file

@ -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<CanvasRenderingContext2D> m_impl;
};

View file

@ -72,7 +72,7 @@ static Document* document_from(JS::Interpreter& interpreter)
return &static_cast<DocumentWrapper*>(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&>(*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));
}

View file

@ -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);
};
}

View file

@ -72,7 +72,7 @@ static Element* impl_from(JS::Interpreter& interpreter)
return &static_cast<ElementWrapper*>(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);

View file

@ -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);
};
}

View file

@ -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)

View file

@ -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<EventTarget> m_impl;
};

View file

@ -70,7 +70,7 @@ static HTMLCanvasElement* impl_from(JS::Interpreter& interpreter)
return &static_cast<HTMLCanvasElementWrapper*>(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());

View file

@ -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);
};
}

View file

@ -67,7 +67,7 @@ static ImageData* impl_from(JS::Interpreter& interpreter)
return &static_cast<ImageDataWrapper*>(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)

View file

@ -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<ImageData> m_impl;
};

View file

@ -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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(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<WindowObject&>(interpreter.global_object());
auto& window = static_cast<WindowObject&>(global_object);
window.impl().did_call_location_reload({});
return JS::js_undefined();
}

View file

@ -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);
};
}

View file

@ -65,14 +65,14 @@ static MouseEvent* impl_from(JS::Interpreter& interpreter)
return &static_cast<MouseEventWrapper*>(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());

View file

@ -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);
};
}

View file

@ -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());
}

View file

@ -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);
};
}

View file

@ -94,7 +94,7 @@ static Window* impl_from(JS::Interpreter& interpreter)
return &static_cast<WindowObject*>(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<JS::Function*>(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);
}
}

View file

@ -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<Window> m_impl;

View file

@ -66,7 +66,7 @@ static XMLHttpRequest* impl_from(JS::Interpreter& interpreter)
return &static_cast<XMLHttpRequestWrapper*>(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)

View file

@ -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);
};
}

View file

@ -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());
}