mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +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:
parent
4aa98052ca
commit
e4add19915
79 changed files with 541 additions and 519 deletions
|
@ -26,6 +26,24 @@
|
||||||
|
|
||||||
#pragma once
|
#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 \
|
#define JS_ENUMERATE_NATIVE_OBJECTS \
|
||||||
__JS_ENUMERATE(Array, array, ArrayPrototype, ArrayConstructor) \
|
__JS_ENUMERATE(Array, array, ArrayPrototype, ArrayConstructor) \
|
||||||
__JS_ENUMERATE(BigIntObject, bigint, BigIntPrototype, BigIntConstructor) \
|
__JS_ENUMERATE(BigIntObject, bigint, BigIntPrototype, BigIntConstructor) \
|
||||||
|
|
|
@ -61,7 +61,7 @@ Array* array_from(Interpreter& interpreter, GlobalObject& global_object)
|
||||||
return static_cast<Array*>(this_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());
|
auto* array = array_from(interpreter, interpreter.global_object());
|
||||||
if (!array)
|
if (!array)
|
||||||
|
@ -69,9 +69,9 @@ Value Array::length_getter(Interpreter& interpreter)
|
||||||
return Value(static_cast<i32>(array->indexed_properties().array_like_size()));
|
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)
|
if (!array)
|
||||||
return;
|
return;
|
||||||
auto length = value.to_number(interpreter);
|
auto length = value.to_number(interpreter);
|
||||||
|
|
|
@ -43,8 +43,8 @@ private:
|
||||||
virtual const char* class_name() const override { return "Array"; }
|
virtual const char* class_name() const override { return "Array"; }
|
||||||
virtual bool is_array() const override { return true; }
|
virtual bool is_array() const override { return true; }
|
||||||
|
|
||||||
static Value length_getter(Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(length_getter);
|
||||||
static void length_setter(Interpreter&, Value);
|
JS_DECLARE_NATIVE_SETTER(length_setter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,15 +78,15 @@ Value ArrayConstructor::construct(Interpreter& interpreter)
|
||||||
return call(interpreter);
|
return call(interpreter);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ArrayConstructor::is_array(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array)
|
||||||
{
|
{
|
||||||
auto value = interpreter.argument(0);
|
auto value = interpreter.argument(0);
|
||||||
return Value(value.is_array());
|
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)
|
for (size_t i = 0; i < interpreter.argument_count(); ++i)
|
||||||
array->indexed_properties().append(interpreter.argument(i));
|
array->indexed_properties().append(interpreter.argument(i));
|
||||||
return array;
|
return array;
|
||||||
|
|
|
@ -42,8 +42,8 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "ArrayConstructor"; }
|
virtual const char* class_name() const override { return "ArrayConstructor"; }
|
||||||
|
|
||||||
static Value is_array(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_array);
|
||||||
static Value of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
auto* new_array = Array::create(global_object);
|
||||||
for_each_item(interpreter, interpreter.global_object(), "filter", [&](auto, auto value, auto callback_result) {
|
for_each_item(interpreter, global_object, "filter", [&](auto, auto value, auto callback_result) {
|
||||||
if (callback_result.to_boolean())
|
if (callback_result.to_boolean())
|
||||||
new_array->indexed_properties().append(value);
|
new_array->indexed_properties().append(value);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
@ -150,25 +150,25 @@ Value ArrayPrototype::filter(Interpreter& interpreter)
|
||||||
return Value(new_array);
|
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 IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
return js_undefined();
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
auto initial_length = get_length(interpreter, *this_object);
|
auto initial_length = get_length(interpreter, *this_object);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
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);
|
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);
|
new_array->put(index, callback_result);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -177,9 +177,9 @@ Value ArrayPrototype::map(Interpreter& interpreter)
|
||||||
return Value(new_array);
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (this_object->is_array()) {
|
if (this_object->is_array()) {
|
||||||
|
@ -207,9 +207,9 @@ Value ArrayPrototype::push(Interpreter& interpreter)
|
||||||
return new_length_value;
|
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)
|
if (!array)
|
||||||
return {};
|
return {};
|
||||||
for (size_t i = 0; i < interpreter.argument_count(); ++i)
|
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()));
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (this_object->is_array()) {
|
if (this_object->is_array()) {
|
||||||
|
@ -246,9 +246,9 @@ Value ArrayPrototype::pop(Interpreter& interpreter)
|
||||||
return element;
|
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)
|
if (!array)
|
||||||
return {};
|
return {};
|
||||||
if (array->indexed_properties().is_empty())
|
if (array->indexed_properties().is_empty())
|
||||||
|
@ -259,22 +259,22 @@ Value ArrayPrototype::shift(Interpreter& interpreter)
|
||||||
return result.value.value_or(js_undefined());
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
auto join_function = this_object->get("join");
|
auto join_function = this_object->get("join");
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
if (!join_function.is_function())
|
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);
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
String separator = ","; // NOTE: This is implementation-specific.
|
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());
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
String separator = ",";
|
String separator = ",";
|
||||||
|
@ -334,13 +334,13 @@ Value ArrayPrototype::join(Interpreter& interpreter)
|
||||||
return js_string(interpreter, builder.to_string());
|
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)
|
if (!array)
|
||||||
return {};
|
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());
|
new_array->indexed_properties().append_all(array, array->indexed_properties());
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
@ -360,13 +360,13 @@ Value ArrayPrototype::concat(Interpreter& interpreter)
|
||||||
return Value(new_array);
|
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)
|
if (!array)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto* new_array = Array::create(interpreter.global_object());
|
auto* new_array = Array::create(global_object);
|
||||||
if (interpreter.argument_count() == 0) {
|
if (interpreter.argument_count() == 0) {
|
||||||
new_array->indexed_properties().append_all(array, array->indexed_properties());
|
new_array->indexed_properties().append_all(array, array->indexed_properties());
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -405,9 +405,9 @@ Value ArrayPrototype::slice(Interpreter& interpreter)
|
||||||
return new_array;
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
i32 length = get_length(interpreter, *this_object);
|
i32 length = get_length(interpreter, *this_object);
|
||||||
|
@ -436,9 +436,9 @@ Value ArrayPrototype::index_of(Interpreter& interpreter)
|
||||||
return Value(-1);
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -495,9 +495,9 @@ Value ArrayPrototype::reduce(Interpreter& interpreter)
|
||||||
return accumulator;
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -554,9 +554,9 @@ Value ArrayPrototype::reduce_right(Interpreter& interpreter)
|
||||||
return accumulator;
|
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)
|
if (!array)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -578,9 +578,9 @@ Value ArrayPrototype::reverse(Interpreter& interpreter)
|
||||||
return array;
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
i32 length = get_length(interpreter, *this_object);
|
i32 length = get_length(interpreter, *this_object);
|
||||||
|
@ -609,9 +609,9 @@ Value ArrayPrototype::last_index_of(Interpreter& interpreter)
|
||||||
return Value(-1);
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
i32 length = get_length(interpreter, *this_object);
|
i32 length = get_length(interpreter, *this_object);
|
||||||
|
@ -640,11 +640,11 @@ Value ArrayPrototype::includes(Interpreter& interpreter)
|
||||||
return Value(false);
|
return Value(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ArrayPrototype::find(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find)
|
||||||
{
|
{
|
||||||
auto result = js_undefined();
|
auto result = js_undefined();
|
||||||
for_each_item(
|
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()) {
|
if (callback_result.to_boolean()) {
|
||||||
result = value;
|
result = value;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -655,11 +655,11 @@ Value ArrayPrototype::find(Interpreter& interpreter)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ArrayPrototype::find_index(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index)
|
||||||
{
|
{
|
||||||
auto result_index = -1;
|
auto result_index = -1;
|
||||||
for_each_item(
|
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()) {
|
if (callback_result.to_boolean()) {
|
||||||
result_index = index;
|
result_index = index;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -670,10 +670,10 @@ Value ArrayPrototype::find_index(Interpreter& interpreter)
|
||||||
return Value(result_index);
|
return Value(result_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ArrayPrototype::some(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some)
|
||||||
{
|
{
|
||||||
auto result = false;
|
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()) {
|
if (callback_result.to_boolean()) {
|
||||||
result = true;
|
result = true;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -683,10 +683,10 @@ Value ArrayPrototype::some(Interpreter& interpreter)
|
||||||
return Value(result);
|
return Value(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ArrayPrototype::every(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every)
|
||||||
{
|
{
|
||||||
auto result = true;
|
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()) {
|
if (!callback_result.to_boolean()) {
|
||||||
result = false;
|
result = false;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -696,9 +696,9 @@ Value ArrayPrototype::every(Interpreter& interpreter)
|
||||||
return Value(result);
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -736,7 +736,7 @@ Value ArrayPrototype::splice(Interpreter& interpreter)
|
||||||
if (new_length > MAX_ARRAY_LIKE_INDEX)
|
if (new_length > MAX_ARRAY_LIKE_INDEX)
|
||||||
return interpreter.throw_exception<TypeError>(ErrorType::ArrayMaxSize);
|
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) {
|
for (size_t i = 0; i < actual_delete_count; ++i) {
|
||||||
auto value = this_object->get(actual_start + i);
|
auto value = this_object->get(actual_start + i);
|
||||||
|
@ -799,9 +799,9 @@ Value ArrayPrototype::splice(Interpreter& interpreter)
|
||||||
return removed_elements;
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -39,30 +39,30 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ArrayPrototype"; }
|
virtual const char* class_name() const override { return "ArrayPrototype"; }
|
||||||
|
|
||||||
static Value filter(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(filter);
|
||||||
static Value for_each(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(for_each);
|
||||||
static Value map(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(map);
|
||||||
static Value pop(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(pop);
|
||||||
static Value push(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(push);
|
||||||
static Value shift(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(shift);
|
||||||
static Value to_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
static Value to_locale_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||||
static Value unshift(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(unshift);
|
||||||
static Value join(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(join);
|
||||||
static Value concat(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(concat);
|
||||||
static Value slice(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(slice);
|
||||||
static Value index_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(index_of);
|
||||||
static Value reduce(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(reduce);
|
||||||
static Value reduce_right(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(reduce_right);
|
||||||
static Value reverse(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(reverse);
|
||||||
static Value last_index_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(last_index_of);
|
||||||
static Value includes(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(includes);
|
||||||
static Value find(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(find);
|
||||||
static Value find_index(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(find_index);
|
||||||
static Value some(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(some);
|
||||||
static Value every(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(every);
|
||||||
static Value splice(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(splice);
|
||||||
static Value fill(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(fill);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,12 +73,12 @@ Value BigIntConstructor::construct(Interpreter& interpreter)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Value BigIntConstructor::as_int_n(Interpreter&)
|
JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_int_n)
|
||||||
{
|
{
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value BigIntConstructor::as_uint_n(Interpreter&)
|
JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_uint_n)
|
||||||
{
|
{
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "BigIntConstructor"; }
|
virtual const char* class_name() const override { return "BigIntConstructor"; }
|
||||||
|
|
||||||
static Value as_int_n(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(as_int_n);
|
||||||
static Value as_uint_n(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(as_uint_n);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,22 +57,22 @@ static BigIntObject* bigint_object_from(Interpreter& interpreter, GlobalObject&
|
||||||
return static_cast<BigIntObject*>(this_object);
|
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)
|
if (!bigint_object)
|
||||||
return {};
|
return {};
|
||||||
return js_string(interpreter, bigint_object->bigint().big_integer().to_base10());
|
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)
|
if (!bigint_object)
|
||||||
return {};
|
return {};
|
||||||
return bigint_object->value_of();
|
return bigint_object->value_of();
|
||||||
|
|
|
@ -38,9 +38,9 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "BigIntPrototype"; }
|
virtual const char* class_name() const override { return "BigIntPrototype"; }
|
||||||
|
|
||||||
static Value to_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
static Value to_locale_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||||
static Value value_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,13 @@ BooleanPrototype::BooleanPrototype()
|
||||||
define_native_function("valueOf", value_of, 0, Attribute::Writable | Attribute::Configurable);
|
define_native_function("valueOf", value_of, 0, Attribute::Writable | Attribute::Configurable);
|
||||||
}
|
}
|
||||||
|
|
||||||
BooleanPrototype::~BooleanPrototype() { }
|
BooleanPrototype::~BooleanPrototype()
|
||||||
|
|
||||||
Value BooleanPrototype::to_string(Interpreter& interpreter)
|
|
||||||
{
|
{
|
||||||
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()) {
|
if (this_object.is_boolean()) {
|
||||||
return js_string(interpreter.heap(), this_object.as_bool() ? "true" : "false");
|
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");
|
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()) {
|
if (this_object.is_boolean()) {
|
||||||
return this_object;
|
return this_object;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "BooleanPrototype"; }
|
virtual const char* class_name() const override { return "BooleanPrototype"; }
|
||||||
|
|
||||||
static Value to_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
static Value value_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,47 +53,47 @@ ConsoleObject::~ConsoleObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::log(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log)
|
||||||
{
|
{
|
||||||
return interpreter.console().log();
|
return interpreter.console().log();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::debug(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug)
|
||||||
{
|
{
|
||||||
return interpreter.console().debug();
|
return interpreter.console().debug();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::info(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info)
|
||||||
{
|
{
|
||||||
return interpreter.console().info();
|
return interpreter.console().info();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::warn(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn)
|
||||||
{
|
{
|
||||||
return interpreter.console().warn();
|
return interpreter.console().warn();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::error(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error)
|
||||||
{
|
{
|
||||||
return interpreter.console().error();
|
return interpreter.console().error();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::trace(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace)
|
||||||
{
|
{
|
||||||
return interpreter.console().trace();
|
return interpreter.console().trace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::count(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count)
|
||||||
{
|
{
|
||||||
return interpreter.console().count();
|
return interpreter.console().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::count_reset(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset)
|
||||||
{
|
{
|
||||||
return interpreter.console().count_reset();
|
return interpreter.console().count_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ConsoleObject::clear(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear)
|
||||||
{
|
{
|
||||||
return interpreter.console().clear();
|
return interpreter.console().clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,15 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ConsoleObject"; }
|
virtual const char* class_name() const override { return "ConsoleObject"; }
|
||||||
|
|
||||||
static Value log(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(log);
|
||||||
static Value debug(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(debug);
|
||||||
static Value info(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(info);
|
||||||
static Value warn(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(warn);
|
||||||
static Value error(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(error);
|
||||||
static Value trace(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(trace);
|
||||||
static Value count(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(count);
|
||||||
static Value count_reset(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(count_reset);
|
||||||
static Value clear(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(clear);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ Value DateConstructor::construct(Interpreter&)
|
||||||
return Date::create(global_object(), datetime, milliseconds);
|
return Date::create(global_object(), datetime, milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value DateConstructor::now(Interpreter&)
|
JS_DEFINE_NATIVE_FUNCTION(DateConstructor::now)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, nullptr);
|
gettimeofday(&tv, nullptr);
|
||||||
|
|
|
@ -42,7 +42,7 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "DateConstructor"; }
|
virtual const char* class_name() const override { return "DateConstructor"; }
|
||||||
|
|
||||||
static Value now(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(now);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -79,7 +79,7 @@ Value DatePrototype::get_date(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(date));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -88,7 +88,7 @@ Value DatePrototype::get_day(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(day));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -97,7 +97,7 @@ Value DatePrototype::get_full_year(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(full_year));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -106,7 +106,7 @@ Value DatePrototype::get_hours(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(hours));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -115,7 +115,7 @@ Value DatePrototype::get_milliseconds(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(milliseconds));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -124,7 +124,7 @@ Value DatePrototype::get_minutes(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(minutes));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -133,7 +133,7 @@ Value DatePrototype::get_month(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(months));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -142,7 +142,7 @@ Value DatePrototype::get_seconds(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(seconds));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -152,7 +152,7 @@ Value DatePrototype::get_time(Interpreter& interpreter)
|
||||||
return Value(static_cast<double>(seconds * 1000 + milliseconds));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -161,7 +161,7 @@ Value DatePrototype::to_date_string(Interpreter& interpreter)
|
||||||
return js_string(interpreter, move(string));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -170,7 +170,7 @@ Value DatePrototype::to_time_string(Interpreter& interpreter)
|
||||||
return js_string(interpreter, move(string));
|
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);
|
auto* this_object = this_date_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
|
|
@ -38,18 +38,18 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "DatePrototype"; }
|
virtual const char* class_name() const override { return "DatePrototype"; }
|
||||||
|
|
||||||
static Value get_date(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_date);
|
||||||
static Value get_day(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_day);
|
||||||
static Value get_full_year(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_full_year);
|
||||||
static Value get_hours(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_hours);
|
||||||
static Value get_milliseconds(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_milliseconds);
|
||||||
static Value get_minutes(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_minutes);
|
||||||
static Value get_month(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_month);
|
||||||
static Value get_seconds(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_seconds);
|
||||||
static Value get_time(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_time);
|
||||||
static Value to_date_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_date_string);
|
||||||
static Value to_time_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_time_string);
|
||||||
static Value to_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,8 @@ Value ErrorConstructor::construct(Interpreter& interpreter)
|
||||||
ConstructorName::ConstructorName() \
|
ConstructorName::ConstructorName() \
|
||||||
: NativeFunction(*interpreter().global_object().function_prototype()) \
|
: NativeFunction(*interpreter().global_object().function_prototype()) \
|
||||||
{ \
|
{ \
|
||||||
define_property("prototype", interpreter().global_object().snake_name##_prototype(), 0); \
|
define_property("prototype", interpreter().global_object().snake_name##_prototype(), 0); \
|
||||||
define_property("length", Value(1), Attribute::Configurable); \
|
define_property("length", Value(1), Attribute::Configurable); \
|
||||||
} \
|
} \
|
||||||
ConstructorName::~ConstructorName() { } \
|
ConstructorName::~ConstructorName() { } \
|
||||||
Value ConstructorName::call(Interpreter& interpreter) \
|
Value ConstructorName::call(Interpreter& interpreter) \
|
||||||
|
@ -78,7 +78,7 @@ Value ErrorConstructor::construct(Interpreter& interpreter)
|
||||||
if (interpreter.exception()) \
|
if (interpreter.exception()) \
|
||||||
return {}; \
|
return {}; \
|
||||||
} \
|
} \
|
||||||
return ClassName::create(interpreter.global_object(), message); \
|
return ClassName::create(global_object(), message); \
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_ERROR_SUBCLASSES
|
||||||
|
|
|
@ -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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (!this_object->is_error())
|
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());
|
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)
|
if (!this_object)
|
||||||
return;
|
return;
|
||||||
if (!this_object->is_error()) {
|
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);
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (!this_object->is_error())
|
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());
|
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())
|
if (!interpreter.this_value(global_object).is_object())
|
||||||
return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, interpreter.this_value(interpreter.global_object()).to_string_without_side_effects().characters());
|
return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, interpreter.this_value(global_object).to_string_without_side_effects().characters());
|
||||||
auto& this_object = interpreter.this_value(interpreter.global_object()).as_object();
|
auto& this_object = interpreter.this_value(global_object).as_object();
|
||||||
|
|
||||||
String name = "Error";
|
String name = "Error";
|
||||||
auto name_property = this_object.get("name");
|
auto name_property = this_object.get("name");
|
||||||
|
|
|
@ -38,12 +38,12 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ErrorPrototype"; }
|
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&);
|
JS_DECLARE_NATIVE_GETTER(name_getter);
|
||||||
static void name_setter(Interpreter&, Value);
|
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) \
|
#define DECLARE_ERROR_SUBCLASS_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||||
|
|
|
@ -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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (!this_object->is_function())
|
if (!this_object->is_function())
|
||||||
|
@ -88,9 +88,9 @@ Value FunctionPrototype::apply(Interpreter& interpreter)
|
||||||
return interpreter.call(function, this_arg, move(arguments));
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (!this_object->is_function())
|
if (!this_object->is_function())
|
||||||
|
@ -108,9 +108,9 @@ Value FunctionPrototype::bind(Interpreter& interpreter)
|
||||||
return this_function.bind(bound_this_arg, move(arguments));
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (!this_object->is_function())
|
if (!this_object->is_function())
|
||||||
|
@ -125,9 +125,9 @@ Value FunctionPrototype::call(Interpreter& interpreter)
|
||||||
return interpreter.call(function, this_arg, move(arguments));
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (!this_object->is_function())
|
if (!this_object->is_function())
|
||||||
|
|
|
@ -40,10 +40,10 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "FunctionPrototype"; }
|
virtual const char* class_name() const override { return "FunctionPrototype"; }
|
||||||
|
|
||||||
static Value apply(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(apply);
|
||||||
static Value bind(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(bind);
|
||||||
static Value call(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(call);
|
||||||
static Value to_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,14 +135,14 @@ void GlobalObject::visit_children(Visitor& visitor)
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
}
|
}
|
||||||
|
|
||||||
Value GlobalObject::gc(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::gc)
|
||||||
{
|
{
|
||||||
dbg() << "Forced garbage collection requested!";
|
dbg() << "Forced garbage collection requested!";
|
||||||
interpreter.heap().collect_garbage();
|
interpreter.heap().collect_garbage();
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value GlobalObject::is_nan(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_nan)
|
||||||
{
|
{
|
||||||
auto number = interpreter.argument(0).to_number(interpreter);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -150,7 +150,7 @@ Value GlobalObject::is_nan(Interpreter& interpreter)
|
||||||
return Value(number.is_nan());
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -158,7 +158,7 @@ Value GlobalObject::is_finite(Interpreter& interpreter)
|
||||||
return Value(number.is_finite_number());
|
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())
|
if (interpreter.argument(0).is_number())
|
||||||
return interpreter.argument(0);
|
return interpreter.argument(0);
|
||||||
|
|
|
@ -55,10 +55,10 @@ protected:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "GlobalObject"; }
|
virtual const char* class_name() const override { return "GlobalObject"; }
|
||||||
|
|
||||||
static Value gc(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(gc);
|
||||||
static Value is_nan(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_nan);
|
||||||
static Value is_finite(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_finite);
|
||||||
static Value parse_float(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(parse_float);
|
||||||
|
|
||||||
Shape* m_empty_object_shape { nullptr };
|
Shape* m_empty_object_shape { nullptr };
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ JSONObject::~JSONObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Value JSONObject::stringify(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
|
@ -116,7 +116,7 @@ Value JSONObject::stringify(Interpreter& interpreter)
|
||||||
state.gap = String::empty();
|
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);
|
wrapper->define_property(String::empty(), value);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
@ -368,7 +368,7 @@ String JSONObject::quote_json_string(String string)
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value JSONObject::parse(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
|
@ -384,7 +384,7 @@ Value JSONObject::parse(Interpreter& interpreter)
|
||||||
}
|
}
|
||||||
Value result = parse_json_value(interpreter, json.value());
|
Value result = parse_json_value(interpreter, json.value());
|
||||||
if (reviver.is_function()) {
|
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);
|
holder_object->define_property(String::empty(), result);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -56,8 +56,8 @@ private:
|
||||||
static Value parse_json_value(Interpreter&, const JsonValue&);
|
static Value parse_json_value(Interpreter&, const JsonValue&);
|
||||||
static Value internalize_json_property(Interpreter&, Object* holder, const PropertyName& name, Function& reviver);
|
static Value internalize_json_property(Interpreter&, Object* holder, const PropertyName& name, Function& reviver);
|
||||||
|
|
||||||
static Value stringify(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(stringify);
|
||||||
static Value parse(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(parse);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -80,7 +80,7 @@ Value MathObject::abs(Interpreter& interpreter)
|
||||||
return Value(number.as_double() >= 0 ? number.as_double() : -number.as_double());
|
return Value(number.as_double() >= 0 ? number.as_double() : -number.as_double());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MathObject::random(Interpreter&)
|
Value MathObject::random(Interpreter&, GlobalObject&)
|
||||||
{
|
{
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
double r = (double)arc4random() / (double)UINT32_MAX;
|
double r = (double)arc4random() / (double)UINT32_MAX;
|
||||||
|
@ -90,7 +90,7 @@ Value MathObject::random(Interpreter&)
|
||||||
return Value(r);
|
return Value(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MathObject::sqrt(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::sqrt)
|
||||||
{
|
{
|
||||||
auto number = interpreter.argument(0).to_number(interpreter);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -100,7 +100,7 @@ Value MathObject::sqrt(Interpreter& interpreter)
|
||||||
return Value(::sqrt(number.as_double()));
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -110,7 +110,7 @@ Value MathObject::floor(Interpreter& interpreter)
|
||||||
return Value(::floor(number.as_double()));
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -120,7 +120,7 @@ Value MathObject::ceil(Interpreter& interpreter)
|
||||||
return Value(::ceil(number.as_double()));
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -130,7 +130,7 @@ Value MathObject::round(Interpreter& interpreter)
|
||||||
return Value(::round(number.as_double()));
|
return Value(::round(number.as_double()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MathObject::max(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::max)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
return js_negative_infinity();
|
return js_negative_infinity();
|
||||||
|
@ -147,7 +147,7 @@ Value MathObject::max(Interpreter& interpreter)
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MathObject::min(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::min)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
return js_infinity();
|
return js_infinity();
|
||||||
|
@ -164,7 +164,7 @@ Value MathObject::min(Interpreter& interpreter)
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MathObject::trunc(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc)
|
||||||
{
|
{
|
||||||
auto number = interpreter.argument(0).to_number(interpreter);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -172,11 +172,11 @@ Value MathObject::trunc(Interpreter& interpreter)
|
||||||
if (number.is_nan())
|
if (number.is_nan())
|
||||||
return js_nan();
|
return js_nan();
|
||||||
if (number.as_double() < 0)
|
if (number.as_double() < 0)
|
||||||
return MathObject::ceil(interpreter);
|
return MathObject::ceil(interpreter, global_object);
|
||||||
return MathObject::floor(interpreter);
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -186,7 +186,7 @@ Value MathObject::sin(Interpreter& interpreter)
|
||||||
return Value(::sin(number.as_double()));
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -196,7 +196,7 @@ Value MathObject::cos(Interpreter& interpreter)
|
||||||
return Value(::cos(number.as_double()));
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -206,12 +206,12 @@ Value MathObject::tan(Interpreter& interpreter)
|
||||||
return Value(::tan(number.as_double()));
|
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));
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -221,7 +221,7 @@ Value MathObject::exp(Interpreter& interpreter)
|
||||||
return Value(::pow(M_E, number.as_double()));
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -231,7 +231,7 @@ Value MathObject::expm1(Interpreter& interpreter)
|
||||||
return Value(::pow(M_E, number.as_double()) - 1);
|
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);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -247,7 +247,7 @@ Value MathObject::sign(Interpreter& interpreter)
|
||||||
return js_nan();
|
return js_nan();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MathObject::clz32(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32)
|
||||||
{
|
{
|
||||||
auto number = interpreter.argument(0).to_number(interpreter);
|
auto number = interpreter.argument(0).to_number(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
|
|
@ -38,23 +38,23 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "MathObject"; }
|
virtual const char* class_name() const override { return "MathObject"; }
|
||||||
|
|
||||||
static Value abs(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(abs);
|
||||||
static Value random(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(random);
|
||||||
static Value sqrt(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(sqrt);
|
||||||
static Value floor(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(floor);
|
||||||
static Value ceil(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(ceil);
|
||||||
static Value round(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(round);
|
||||||
static Value max(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(max);
|
||||||
static Value min(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(min);
|
||||||
static Value trunc(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(trunc);
|
||||||
static Value sin(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(sin);
|
||||||
static Value cos(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(cos);
|
||||||
static Value tan(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(tan);
|
||||||
static Value pow(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(pow);
|
||||||
static Value exp(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(exp);
|
||||||
static Value expm1(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(expm1);
|
||||||
static Value sign(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(sign);
|
||||||
static Value clz32(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(clz32);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
namespace JS {
|
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());
|
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)
|
: Function(prototype)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_native_function(move(native_function))
|
, m_native_function(move(native_function))
|
||||||
|
@ -60,7 +60,7 @@ NativeFunction::~NativeFunction()
|
||||||
|
|
||||||
Value NativeFunction::call(Interpreter& interpreter)
|
Value NativeFunction::call(Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
return m_native_function(interpreter);
|
return m_native_function(interpreter, global_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value NativeFunction::construct(Interpreter&)
|
Value NativeFunction::construct(Interpreter&)
|
||||||
|
|
|
@ -33,9 +33,9 @@ namespace JS {
|
||||||
|
|
||||||
class NativeFunction : public Function {
|
class NativeFunction : public Function {
|
||||||
public:
|
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 ~NativeFunction() override;
|
||||||
|
|
||||||
virtual Value call(Interpreter&) override;
|
virtual Value call(Interpreter&) override;
|
||||||
|
@ -54,7 +54,7 @@ private:
|
||||||
virtual LexicalEnvironment* create_environment() override final { return nullptr; }
|
virtual LexicalEnvironment* create_environment() override final { return nullptr; }
|
||||||
|
|
||||||
FlyString m_name;
|
FlyString m_name;
|
||||||
AK::Function<Value(Interpreter&)> m_native_function;
|
AK::Function<Value(Interpreter&, GlobalObject&)> m_native_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
namespace JS {
|
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)
|
: Object(nullptr)
|
||||||
, m_getter(move(getter))
|
, m_getter(move(getter))
|
||||||
, m_setter(move(setter))
|
, m_setter(move(setter))
|
||||||
|
@ -44,14 +44,14 @@ Value NativeProperty::get(Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
if (!m_getter)
|
if (!m_getter)
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
return m_getter(interpreter);
|
return m_getter(interpreter, global_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeProperty::set(Interpreter& interpreter, Value value)
|
void NativeProperty::set(Interpreter& interpreter, Value value)
|
||||||
{
|
{
|
||||||
if (!m_setter)
|
if (!m_setter)
|
||||||
return;
|
return;
|
||||||
m_setter(interpreter, move(value));
|
m_setter(interpreter, global_object(), move(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace JS {
|
||||||
|
|
||||||
class NativeProperty final : public Object {
|
class NativeProperty final : public Object {
|
||||||
public:
|
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;
|
virtual ~NativeProperty() override;
|
||||||
|
|
||||||
Value get(Interpreter&) const;
|
Value get(Interpreter&) const;
|
||||||
|
@ -43,8 +43,8 @@ private:
|
||||||
virtual bool is_native_property() const override { return true; }
|
virtual bool is_native_property() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "NativeProperty"; }
|
virtual const char* class_name() const override { return "NativeProperty"; }
|
||||||
|
|
||||||
AK::Function<Value(Interpreter&)> m_getter;
|
AK::Function<Value(Interpreter&, GlobalObject&)> m_getter;
|
||||||
AK::Function<void(Interpreter&, Value)> m_setter;
|
AK::Function<void(Interpreter&, GlobalObject&, Value)> m_setter;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,22 +78,22 @@ Value NumberConstructor::construct(Interpreter& interpreter)
|
||||||
return NumberObject::create(global_object(), number);
|
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());
|
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());
|
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());
|
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())
|
if (!interpreter.argument(0).is_number())
|
||||||
return Value(false);
|
return Value(false);
|
||||||
|
|
|
@ -42,10 +42,10 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "NumberConstructor"; }
|
virtual const char* class_name() const override { return "NumberConstructor"; }
|
||||||
|
|
||||||
static Value is_finite(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_finite);
|
||||||
static Value is_integer(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_integer);
|
||||||
static Value is_nan(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_nan);
|
||||||
static Value is_safe_integer(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_safe_integer);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -680,7 +680,7 @@ bool Object::put(PropertyName property_name, Value value)
|
||||||
return put_own_property(*this, property_string, value, default_attributes, PutOwnPropertyMode::Put);
|
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));
|
auto* function = NativeFunction::create(interpreter(), global_object(), property_name, move(native_function));
|
||||||
function->define_property("length", Value(length), Attribute::Configurable);
|
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);
|
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);
|
return define_property(property_name, heap().allocate<NativeProperty>(move(getter), move(setter)), attribute);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,8 @@ public:
|
||||||
virtual bool define_property(const FlyString& property_name, const Object& descriptor, bool throw_exceptions = true);
|
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_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_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&)> getter, AK::Function<void(Interpreter&, Value)> setter, 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);
|
virtual Value delete_property(PropertyName);
|
||||||
|
|
||||||
|
|
|
@ -69,14 +69,14 @@ Value ObjectConstructor::construct(Interpreter& interpreter)
|
||||||
return call(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())
|
if (!interpreter.argument_count())
|
||||||
return {};
|
return {};
|
||||||
auto* object = interpreter.argument(0).to_object(interpreter);
|
auto* object = interpreter.argument(0).to_object(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
auto* result = Array::create(interpreter.global_object());
|
auto* result = Array::create(global_object);
|
||||||
for (auto& entry : object->indexed_properties())
|
for (auto& entry : object->indexed_properties())
|
||||||
result->indexed_properties().append(js_string(interpreter, String::number(entry.index())));
|
result->indexed_properties().append(js_string(interpreter, String::number(entry.index())));
|
||||||
for (auto& it : object->shape().property_table_ordered())
|
for (auto& it : object->shape().property_table_ordered())
|
||||||
|
@ -85,7 +85,7 @@ Value ObjectConstructor::get_own_property_names(Interpreter& interpreter)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ObjectConstructor::get_prototype_of(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
return {};
|
return {};
|
||||||
|
@ -95,7 +95,7 @@ Value ObjectConstructor::get_prototype_of(Interpreter& interpreter)
|
||||||
return object->prototype();
|
return object->prototype();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ObjectConstructor::set_prototype_of(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of)
|
||||||
{
|
{
|
||||||
if (interpreter.argument_count() < 2)
|
if (interpreter.argument_count() < 2)
|
||||||
return interpreter.throw_exception<TypeError>(ErrorType::ObjectSetPrototypeOfTwoArgs);
|
return interpreter.throw_exception<TypeError>(ErrorType::ObjectSetPrototypeOfTwoArgs);
|
||||||
|
@ -120,7 +120,7 @@ Value ObjectConstructor::set_prototype_of(Interpreter& interpreter)
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ObjectConstructor::is_extensible(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible)
|
||||||
{
|
{
|
||||||
auto argument = interpreter.argument(0);
|
auto argument = interpreter.argument(0);
|
||||||
if (!argument.is_object())
|
if (!argument.is_object())
|
||||||
|
@ -128,7 +128,7 @@ Value ObjectConstructor::is_extensible(Interpreter& interpreter)
|
||||||
return Value(argument.as_object().is_extensible());
|
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);
|
auto argument = interpreter.argument(0);
|
||||||
if (!argument.is_object())
|
if (!argument.is_object())
|
||||||
|
@ -141,7 +141,7 @@ Value ObjectConstructor::prevent_extensions(Interpreter& interpreter)
|
||||||
return argument;
|
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);
|
auto* object = interpreter.argument(0).to_object(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -152,7 +152,7 @@ Value ObjectConstructor::get_own_property_descriptor(Interpreter& interpreter)
|
||||||
return object->get_own_property_descriptor_object(property_key);
|
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())
|
if (!interpreter.argument(0).is_object())
|
||||||
return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, "Object argument");
|
return interpreter.throw_exception<TypeError>(ErrorType::NotAnObject, "Object argument");
|
||||||
|
@ -176,12 +176,12 @@ Value ObjectConstructor::define_property_(Interpreter& interpreter)
|
||||||
return &object;
|
return &object;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ObjectConstructor::is(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is)
|
||||||
{
|
{
|
||||||
return Value(same_value(interpreter, interpreter.argument(0), interpreter.argument(1)));
|
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())
|
if (!interpreter.argument_count())
|
||||||
return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject);
|
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);
|
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())
|
if (!interpreter.argument_count())
|
||||||
return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject);
|
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);
|
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())
|
if (!interpreter.argument_count())
|
||||||
return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject);
|
return interpreter.throw_exception<TypeError>(ErrorType::ConvertUndefinedToObject);
|
||||||
|
|
|
@ -42,17 +42,17 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "ObjectConstructor"; }
|
virtual const char* class_name() const override { return "ObjectConstructor"; }
|
||||||
|
|
||||||
static Value define_property_(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(define_property_);
|
||||||
static Value is(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is);
|
||||||
static Value get_own_property_descriptor(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_own_property_descriptor);
|
||||||
static Value get_own_property_names(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_own_property_names);
|
||||||
static Value get_prototype_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_prototype_of);
|
||||||
static Value set_prototype_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(set_prototype_of);
|
||||||
static Value is_extensible(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_extensible);
|
||||||
static Value prevent_extensions(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(prevent_extensions);
|
||||||
static Value keys(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(keys);
|
||||||
static Value values(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(values);
|
||||||
static Value entries(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(entries);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
auto name = interpreter.argument(0).to_string(interpreter);
|
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));
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
return js_string(interpreter, String::format("[object %s]", this_object->class_name()));
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
return this_object->invoke("toString");
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
return this_object->value_of();
|
return this_object->value_of();
|
||||||
|
|
|
@ -38,14 +38,14 @@ public:
|
||||||
virtual ~ObjectPrototype() override;
|
virtual ~ObjectPrototype() override;
|
||||||
|
|
||||||
// public to serve as intrinsic function %Object.prototype.toString%
|
// public to serve as intrinsic function %Object.prototype.toString%
|
||||||
static Value to_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ObjectPrototype"; }
|
virtual const char* class_name() const override { return "ObjectPrototype"; }
|
||||||
|
|
||||||
static Value has_own_property(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(has_own_property);
|
||||||
static Value to_locale_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||||
static Value value_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
auto* target = get_target_function_from(interpreter, "apply");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -111,7 +111,7 @@ Value ReflectObject::apply(Interpreter& interpreter)
|
||||||
return interpreter.call(*target, this_arg, move(arguments));
|
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");
|
auto* target = get_target_function_from(interpreter, "construct");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -133,7 +133,7 @@ Value ReflectObject::construct(Interpreter& interpreter)
|
||||||
return interpreter.construct(*target, *new_target, move(arguments));
|
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");
|
auto* target = get_target_object_from(interpreter, "defineProperty");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -150,7 +150,7 @@ Value ReflectObject::define_property(Interpreter& interpreter)
|
||||||
return Value(success);
|
return Value(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ReflectObject::delete_property(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property)
|
||||||
{
|
{
|
||||||
auto* target = get_target_object_from(interpreter, "deleteProperty");
|
auto* target = get_target_object_from(interpreter, "deleteProperty");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -171,7 +171,7 @@ Value ReflectObject::delete_property(Interpreter& interpreter)
|
||||||
return target->delete_property(property_name);
|
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.
|
// FIXME: There's a third argument, receiver, for getters - use it once we have those.
|
||||||
auto* target = get_target_object_from(interpreter, "get");
|
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());
|
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");
|
auto* target = get_target_object_from(interpreter, "getOwnPropertyDescriptor");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -194,7 +194,7 @@ Value ReflectObject::get_own_property_descriptor(Interpreter& interpreter)
|
||||||
return target->get_own_property_descriptor_object(property_key);
|
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");
|
auto* target = get_target_object_from(interpreter, "getPrototypeOf");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -202,7 +202,7 @@ Value ReflectObject::get_prototype_of(Interpreter& interpreter)
|
||||||
return target->prototype();
|
return target->prototype();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ReflectObject::has(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::has)
|
||||||
{
|
{
|
||||||
auto* target = get_target_object_from(interpreter, "has");
|
auto* target = get_target_object_from(interpreter, "has");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -213,7 +213,7 @@ Value ReflectObject::has(Interpreter& interpreter)
|
||||||
return Value(target->has_property(property_key));
|
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");
|
auto* target = get_target_object_from(interpreter, "isExtensible");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -221,7 +221,7 @@ Value ReflectObject::is_extensible(Interpreter& interpreter)
|
||||||
return Value(target->is_extensible());
|
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");
|
auto* target = get_target_object_from(interpreter, "ownKeys");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -229,7 +229,7 @@ Value ReflectObject::own_keys(Interpreter& interpreter)
|
||||||
return target->get_own_properties(*target, GetOwnPropertyMode::Key);
|
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");
|
auto* target = get_target_object_from(interpreter, "preventExtensions");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
@ -237,7 +237,7 @@ Value ReflectObject::prevent_extensions(Interpreter& interpreter)
|
||||||
return Value(target->prevent_extensions());
|
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.
|
// FIXME: There's a fourth argument, receiver, for setters - use it once we have those.
|
||||||
auto* target = get_target_object_from(interpreter, "set");
|
auto* target = get_target_object_from(interpreter, "set");
|
||||||
|
@ -250,7 +250,7 @@ Value ReflectObject::set(Interpreter& interpreter)
|
||||||
return Value(target->put(property_key, value));
|
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");
|
auto* target = get_target_object_from(interpreter, "setPrototypeOf");
|
||||||
if (!target)
|
if (!target)
|
||||||
|
|
|
@ -38,19 +38,19 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ReflectObject"; }
|
virtual const char* class_name() const override { return "ReflectObject"; }
|
||||||
|
|
||||||
static Value apply(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(apply);
|
||||||
static Value construct(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(construct);
|
||||||
static Value define_property(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(define_property);
|
||||||
static Value delete_property(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(delete_property);
|
||||||
static Value get(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get);
|
||||||
static Value get_own_property_descriptor(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_own_property_descriptor);
|
||||||
static Value get_prototype_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_prototype_of);
|
||||||
static Value has(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(has);
|
||||||
static Value is_extensible(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_extensible);
|
||||||
static Value own_keys(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(own_keys);
|
||||||
static Value prevent_extensions(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(prevent_extensions);
|
||||||
static Value set(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(set);
|
||||||
static Value set_prototype_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(set_prototype_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ Value ScriptFunction::construct(Interpreter& interpreter)
|
||||||
return call(interpreter);
|
return call(interpreter);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ScriptFunction::length_getter(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter)
|
||||||
{
|
{
|
||||||
auto* function = script_function_from(interpreter);
|
auto* function = script_function_from(interpreter);
|
||||||
if (!function)
|
if (!function)
|
||||||
|
@ -138,7 +138,7 @@ Value ScriptFunction::length_getter(Interpreter& interpreter)
|
||||||
return Value(static_cast<i32>(function->m_function_length));
|
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);
|
auto* function = script_function_from(interpreter);
|
||||||
if (!function)
|
if (!function)
|
||||||
|
|
|
@ -53,8 +53,8 @@ private:
|
||||||
virtual LexicalEnvironment* create_environment() override;
|
virtual LexicalEnvironment* create_environment() override;
|
||||||
virtual void visit_children(Visitor&) override;
|
virtual void visit_children(Visitor&) override;
|
||||||
|
|
||||||
static Value length_getter(Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(length_getter);
|
||||||
static Value name_getter(Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(name_getter);
|
||||||
|
|
||||||
FlyString m_name;
|
FlyString m_name;
|
||||||
NonnullRefPtr<Statement> m_body;
|
NonnullRefPtr<Statement> m_body;
|
||||||
|
|
|
@ -72,7 +72,7 @@ Value StringConstructor::construct(Interpreter& interpreter)
|
||||||
return StringObject::create(global_object(), *primitive_string);
|
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);
|
auto* template_object = interpreter.argument(0).to_object(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -111,7 +111,7 @@ Value StringConstructor::raw(Interpreter& interpreter)
|
||||||
return js_string(interpreter, builder.build());
|
return js_string(interpreter, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value StringConstructor::from_char_code(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (size_t i = 0; i < interpreter.argument_count(); ++i) {
|
for (size_t i = 0; i < interpreter.argument_count(); ++i) {
|
||||||
|
|
|
@ -42,8 +42,8 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "StringConstructor"; }
|
virtual const char* class_name() const override { return "StringConstructor"; }
|
||||||
|
|
||||||
static Value raw(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(raw);
|
||||||
static Value from_char_code(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(from_char_code);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ StringPrototype::~StringPrototype()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Value StringPrototype::char_at(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at)
|
||||||
{
|
{
|
||||||
auto string = string_from(interpreter);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -104,7 +104,7 @@ Value StringPrototype::char_at(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string.substring(index, 1));
|
return js_string(interpreter, string.substring(index, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value StringPrototype::repeat(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat)
|
||||||
{
|
{
|
||||||
auto string = string_from(interpreter);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -127,7 +127,7 @@ Value StringPrototype::repeat(Interpreter& interpreter)
|
||||||
return js_string(interpreter, builder.to_string());
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -154,7 +154,7 @@ Value StringPrototype::starts_with(Interpreter& interpreter)
|
||||||
return Value(string.substring(start, search_string_length) == search_string);
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -165,7 +165,7 @@ Value StringPrototype::index_of(Interpreter& interpreter)
|
||||||
return Value((i32)string.index_of(needle).value_or(-1));
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -173,7 +173,7 @@ Value StringPrototype::to_lowercase(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string.to_lowercase());
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -181,7 +181,7 @@ Value StringPrototype::to_uppercase(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string.to_uppercase());
|
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);
|
auto* string_object = string_object_from(interpreter);
|
||||||
if (!string_object)
|
if (!string_object)
|
||||||
|
@ -189,7 +189,7 @@ Value StringPrototype::length_getter(Interpreter& interpreter)
|
||||||
return Value((i32)string_object->primitive_string().string().length());
|
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);
|
auto* string_object = string_object_from(interpreter);
|
||||||
if (!string_object)
|
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()));
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -239,7 +239,7 @@ Value StringPrototype::pad_start(Interpreter& interpreter)
|
||||||
return pad_string(interpreter, string, PadPlacement::Start);
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -247,7 +247,7 @@ Value StringPrototype::pad_end(Interpreter& interpreter)
|
||||||
return pad_string(interpreter, string, PadPlacement::End);
|
return pad_string(interpreter, string, PadPlacement::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value StringPrototype::trim(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim)
|
||||||
{
|
{
|
||||||
auto string = string_from(interpreter);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -255,7 +255,7 @@ Value StringPrototype::trim(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string.trim_whitespace(String::TrimMode::Both));
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -263,7 +263,7 @@ Value StringPrototype::trim_start(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string.trim_whitespace(String::TrimMode::Left));
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -271,7 +271,7 @@ Value StringPrototype::trim_end(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string.trim_whitespace(String::TrimMode::Right));
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -287,7 +287,7 @@ Value StringPrototype::concat(Interpreter& interpreter)
|
||||||
return js_string(interpreter, builder.to_string());
|
return js_string(interpreter, builder.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value StringPrototype::substring(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
|
||||||
{
|
{
|
||||||
auto string = string_from(interpreter);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -322,7 +322,7 @@ Value StringPrototype::substring(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string_part);
|
return js_string(interpreter, string_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value StringPrototype::includes(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
|
||||||
{
|
{
|
||||||
auto string = string_from(interpreter);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -348,7 +348,7 @@ Value StringPrototype::includes(Interpreter& interpreter)
|
||||||
return Value(substring_search.contains(search_string));
|
return Value(substring_search.contains(search_string));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value StringPrototype::slice(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
|
||||||
{
|
{
|
||||||
auto string = string_from(interpreter);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
@ -391,7 +391,7 @@ Value StringPrototype::slice(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string_part);
|
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);
|
auto string = string_from(interpreter);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
|
|
@ -38,26 +38,26 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "StringPrototype"; }
|
virtual const char* class_name() const override { return "StringPrototype"; }
|
||||||
|
|
||||||
static Value char_at(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(char_at);
|
||||||
static Value repeat(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(repeat);
|
||||||
static Value starts_with(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(starts_with);
|
||||||
static Value index_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(index_of);
|
||||||
static Value to_lowercase(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_lowercase);
|
||||||
static Value to_uppercase(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_uppercase);
|
||||||
static Value to_string(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
static Value pad_start(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(pad_start);
|
||||||
static Value pad_end(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(pad_end);
|
||||||
static Value substring(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(substring);
|
||||||
|
|
||||||
static Value length_getter(Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(length_getter);
|
||||||
|
|
||||||
static Value trim(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(trim);
|
||||||
static Value trim_start(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(trim_start);
|
||||||
static Value trim_end(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(trim_end);
|
||||||
static Value concat(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(concat);
|
||||||
static Value includes(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(includes);
|
||||||
static Value slice(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(slice);
|
||||||
static Value last_index_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(last_index_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ Value SymbolConstructor::construct(Interpreter& interpreter)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Value SymbolConstructor::for_(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_)
|
||||||
{
|
{
|
||||||
String description;
|
String description;
|
||||||
if (!interpreter.argument_count()) {
|
if (!interpreter.argument_count()) {
|
||||||
|
@ -87,7 +87,7 @@ Value SymbolConstructor::for_(Interpreter& interpreter)
|
||||||
return SymbolObject::get_global(interpreter, description);
|
return SymbolObject::get_global(interpreter, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value SymbolConstructor::key_for(Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::key_for)
|
||||||
{
|
{
|
||||||
auto argument = interpreter.argument(0);
|
auto argument = interpreter.argument(0);
|
||||||
if (!argument.is_symbol()) {
|
if (!argument.is_symbol()) {
|
||||||
|
|
|
@ -42,8 +42,8 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
virtual const char* class_name() const override { return "SymbolConstructor"; }
|
virtual const char* class_name() const override { return "SymbolConstructor"; }
|
||||||
|
|
||||||
static Value for_(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(for_);
|
||||||
static Value key_for(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(key_for);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ static SymbolObject* this_symbol_from_interpreter(Interpreter& interpreter)
|
||||||
return static_cast<SymbolObject*>(this_object);
|
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);
|
auto* this_object = this_symbol_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -72,7 +72,7 @@ Value SymbolPrototype::description_getter(Interpreter& interpreter)
|
||||||
return js_string(interpreter, this_object->description());
|
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);
|
auto* this_object = this_symbol_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
@ -81,7 +81,7 @@ Value SymbolPrototype::to_string(Interpreter& interpreter)
|
||||||
return js_string(interpreter, move(string));
|
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);
|
auto* this_object = this_symbol_from_interpreter(interpreter);
|
||||||
if (!this_object)
|
if (!this_object)
|
||||||
|
|
|
@ -38,10 +38,10 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "SymbolPrototype"; }
|
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&);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
static Value value_of(Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ Uint8ClampedArray::~Uint8ClampedArray()
|
||||||
m_data = nullptr;
|
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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (StringView(this_object->class_name()) != "Uint8ClampedArray")
|
if (StringView(this_object->class_name()) != "Uint8ClampedArray")
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "Uint8ClampedArray"; }
|
virtual const char* class_name() const override { return "Uint8ClampedArray"; }
|
||||||
|
|
||||||
static Value length_getter(Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(length_getter);
|
||||||
|
|
||||||
u8* m_data { nullptr };
|
u8* m_data { nullptr };
|
||||||
u32 m_length { 0 };
|
u32 m_length { 0 };
|
||||||
|
|
|
@ -85,7 +85,7 @@ static CanvasRenderingContext2D* impl_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<CanvasRenderingContext2DWrapper*>(this_object)->impl();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -108,7 +108,7 @@ JS::Value CanvasRenderingContext2DWrapper::fill_rect(JS::Interpreter& interprete
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::stroke_rect(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::stroke_rect)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -131,7 +131,7 @@ JS::Value CanvasRenderingContext2DWrapper::stroke_rect(JS::Interpreter& interpre
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::draw_image(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::draw_image)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -154,7 +154,7 @@ JS::Value CanvasRenderingContext2DWrapper::draw_image(JS::Interpreter& interpret
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::scale(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::scale)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -172,7 +172,7 @@ JS::Value CanvasRenderingContext2DWrapper::scale(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::translate(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::translate)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -190,7 +190,7 @@ JS::Value CanvasRenderingContext2DWrapper::translate(JS::Interpreter& interprete
|
||||||
return JS::js_undefined();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -198,7 +198,7 @@ JS::Value CanvasRenderingContext2DWrapper::fill_style_getter(JS::Interpreter& in
|
||||||
return JS::js_string(interpreter, impl->fill_style());
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -209,7 +209,7 @@ void CanvasRenderingContext2DWrapper::fill_style_setter(JS::Interpreter& interpr
|
||||||
impl->set_fill_style(string);
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -217,7 +217,7 @@ JS::Value CanvasRenderingContext2DWrapper::stroke_style_getter(JS::Interpreter&
|
||||||
return JS::js_string(interpreter, impl->stroke_style());
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -228,7 +228,7 @@ void CanvasRenderingContext2DWrapper::stroke_style_setter(JS::Interpreter& inter
|
||||||
impl->set_stroke_style(string);
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -236,7 +236,7 @@ JS::Value CanvasRenderingContext2DWrapper::line_width_getter(JS::Interpreter& in
|
||||||
return JS::Value(impl->line_width());
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -247,7 +247,7 @@ void CanvasRenderingContext2DWrapper::line_width_setter(JS::Interpreter& interpr
|
||||||
impl->set_line_width(line_width);
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -256,7 +256,7 @@ JS::Value CanvasRenderingContext2DWrapper::begin_path(JS::Interpreter& interpret
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::close_path(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::close_path)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -265,7 +265,7 @@ JS::Value CanvasRenderingContext2DWrapper::close_path(JS::Interpreter& interpret
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::stroke(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::stroke)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -274,7 +274,7 @@ JS::Value CanvasRenderingContext2DWrapper::stroke(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::fill(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::fill)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -301,7 +301,7 @@ JS::Value CanvasRenderingContext2DWrapper::fill(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::move_to(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::move_to)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -316,7 +316,7 @@ JS::Value CanvasRenderingContext2DWrapper::move_to(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::line_to(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::line_to)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -331,7 +331,7 @@ JS::Value CanvasRenderingContext2DWrapper::line_to(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -352,7 +352,7 @@ JS::Value CanvasRenderingContext2DWrapper::quadratic_curve_to(JS::Interpreter& i
|
||||||
return JS::js_undefined();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -363,11 +363,11 @@ JS::Value CanvasRenderingContext2DWrapper::create_image_data(JS::Interpreter& in
|
||||||
auto height = interpreter.argument(1).to_i32(interpreter);
|
auto height = interpreter.argument(1).to_i32(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
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);
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -392,7 +392,7 @@ JS::Value CanvasRenderingContext2DWrapper::put_image_data(JS::Interpreter& inter
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value CanvasRenderingContext2DWrapper::canvas_getter(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_GETTER(CanvasRenderingContext2DWrapper::canvas_getter)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
|
|
@ -42,31 +42,31 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "CanvasRenderingContext2DWrapper"; }
|
virtual const char* class_name() const override { return "CanvasRenderingContext2DWrapper"; }
|
||||||
|
|
||||||
static JS::Value fill_rect(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(fill_rect);
|
||||||
static JS::Value stroke_rect(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(stroke_rect);
|
||||||
static JS::Value draw_image(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(draw_image);
|
||||||
static JS::Value scale(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(scale);
|
||||||
static JS::Value translate(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(translate);
|
||||||
static JS::Value begin_path(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(begin_path);
|
||||||
static JS::Value close_path(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(close_path);
|
||||||
static JS::Value stroke(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(stroke);
|
||||||
static JS::Value fill(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(fill);
|
||||||
static JS::Value move_to(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(move_to);
|
||||||
static JS::Value line_to(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(line_to);
|
||||||
static JS::Value quadratic_curve_to(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(quadratic_curve_to);
|
||||||
static JS::Value create_image_data(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(create_image_data);
|
||||||
static JS::Value put_image_data(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(put_image_data);
|
||||||
|
|
||||||
static JS::Value fill_style_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(fill_style_getter);
|
||||||
static void fill_style_setter(JS::Interpreter&, JS::Value);
|
JS_DECLARE_NATIVE_SETTER(fill_style_setter);
|
||||||
|
|
||||||
static JS::Value stroke_style_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(stroke_style_getter);
|
||||||
static void stroke_style_setter(JS::Interpreter&, JS::Value);
|
JS_DECLARE_NATIVE_SETTER(stroke_style_setter);
|
||||||
|
|
||||||
static void line_width_setter(JS::Interpreter&, JS::Value);
|
JS_DECLARE_NATIVE_GETTER(line_width_getter);
|
||||||
static JS::Value line_width_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_SETTER(line_width_setter);
|
||||||
|
|
||||||
static JS::Value canvas_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(canvas_getter);
|
||||||
|
|
||||||
NonnullRefPtr<CanvasRenderingContext2D> m_impl;
|
NonnullRefPtr<CanvasRenderingContext2D> m_impl;
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,7 +72,7 @@ static Document* document_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<DocumentWrapper*>(this_object)->node();
|
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);
|
auto* document = document_from(interpreter);
|
||||||
if (!document)
|
if (!document)
|
||||||
|
@ -88,7 +88,7 @@ JS::Value DocumentWrapper::get_element_by_id(JS::Interpreter& interpreter)
|
||||||
return wrap(interpreter.heap(), const_cast<Element&>(*element));
|
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);
|
auto* document = document_from(interpreter);
|
||||||
if (!document)
|
if (!document)
|
||||||
|
@ -105,7 +105,7 @@ JS::Value DocumentWrapper::query_selector(JS::Interpreter& interpreter)
|
||||||
return wrap(interpreter.heap(), *element);
|
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);
|
auto* document = document_from(interpreter);
|
||||||
if (!document)
|
if (!document)
|
||||||
|
@ -118,7 +118,7 @@ JS::Value DocumentWrapper::query_selector_all(JS::Interpreter& interpreter)
|
||||||
// FIXME: Throw if selector is invalid
|
// FIXME: Throw if selector is invalid
|
||||||
auto elements = document->query_selector_all(selector);
|
auto elements = document->query_selector_all(selector);
|
||||||
// FIXME: This should be a static NodeList, not a plain JS::Array.
|
// 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) {
|
for (auto& element : elements) {
|
||||||
node_list->indexed_properties().append(wrap(interpreter.heap(), element));
|
node_list->indexed_properties().append(wrap(interpreter.heap(), element));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,9 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "DocumentWrapper"; }
|
virtual const char* class_name() const override { return "DocumentWrapper"; }
|
||||||
|
|
||||||
static JS::Value get_element_by_id(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_element_by_id);
|
||||||
static JS::Value query_selector(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(query_selector);
|
||||||
static JS::Value query_selector_all(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(query_selector_all);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ static Element* impl_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<ElementWrapper*>(this_object)->node();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -92,7 +92,7 @@ JS::Value ElementWrapper::get_attribute(JS::Interpreter& interpreter)
|
||||||
return JS::js_string(interpreter, attribute_value);
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -113,14 +113,14 @@ JS::Value ElementWrapper::set_attribute(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
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))
|
if (auto* impl = impl_from(interpreter))
|
||||||
return JS::js_string(interpreter, impl->inner_html());
|
return JS::js_string(interpreter, impl->inner_html());
|
||||||
return {};
|
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)) {
|
if (auto* impl = impl_from(interpreter)) {
|
||||||
auto string = value.to_string(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))
|
if (auto* impl = impl_from(interpreter))
|
||||||
return JS::js_string(interpreter, impl->attribute(HTML::AttributeNames::id));
|
return JS::js_string(interpreter, impl->attribute(HTML::AttributeNames::id));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementWrapper::id_setter(JS::Interpreter& interpreter, JS::Value value)
|
JS_DEFINE_NATIVE_SETTER(ElementWrapper::id_setter)
|
||||||
{
|
{
|
||||||
if (auto* impl = impl_from(interpreter)) {
|
if (auto* impl = impl_from(interpreter)) {
|
||||||
auto string = value.to_string(interpreter);
|
auto string = value.to_string(interpreter);
|
||||||
|
|
|
@ -42,14 +42,14 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ElementWrapper"; }
|
virtual const char* class_name() const override { return "ElementWrapper"; }
|
||||||
|
|
||||||
static JS::Value inner_html_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(inner_html_getter);
|
||||||
static void inner_html_setter(JS::Interpreter&, JS::Value);
|
JS_DECLARE_NATIVE_SETTER(inner_html_setter);
|
||||||
|
|
||||||
static JS::Value id_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(id_getter);
|
||||||
static void id_setter(JS::Interpreter&, JS::Value);
|
JS_DECLARE_NATIVE_SETTER(id_setter);
|
||||||
|
|
||||||
static JS::Value get_attribute(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(get_attribute);
|
||||||
static JS::Value set_attribute(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(set_attribute);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
if (!this_object)
|
||||||
return {};
|
return {};
|
||||||
if (interpreter.argument_count() < 2)
|
if (interpreter.argument_count() < 2)
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "EventTargetWrapper"; }
|
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;
|
NonnullRefPtr<EventTarget> m_impl;
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,7 +70,7 @@ static HTMLCanvasElement* impl_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<HTMLCanvasElementWrapper*>(this_object)->node();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -84,14 +84,14 @@ JS::Value HTMLCanvasElementWrapper::get_context(JS::Interpreter& interpreter)
|
||||||
return wrap(interpreter.heap(), *context);
|
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))
|
if (auto* impl = impl_from(interpreter))
|
||||||
return JS::Value(impl->requested_width());
|
return JS::Value(impl->requested_width());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value HTMLCanvasElementWrapper::height_getter(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_GETTER(HTMLCanvasElementWrapper::height_getter)
|
||||||
{
|
{
|
||||||
if (auto* impl = impl_from(interpreter))
|
if (auto* impl = impl_from(interpreter))
|
||||||
return JS::Value(impl->requested_height());
|
return JS::Value(impl->requested_height());
|
||||||
|
|
|
@ -42,10 +42,10 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "HTMLCanvasElementWrapper"; }
|
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&);
|
JS_DECLARE_NATIVE_GETTER(width_getter);
|
||||||
static JS::Value height_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(height_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ static ImageData* impl_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<ImageDataWrapper*>(this_object)->impl();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -75,7 +75,7 @@ JS::Value ImageDataWrapper::width_getter(JS::Interpreter& interpreter)
|
||||||
return JS::Value(impl->width());
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -83,7 +83,7 @@ JS::Value ImageDataWrapper::height_getter(JS::Interpreter& interpreter)
|
||||||
return JS::Value(impl->height());
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
|
|
@ -42,9 +42,9 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ImageDataWrapper"; }
|
virtual const char* class_name() const override { return "ImageDataWrapper"; }
|
||||||
|
|
||||||
static JS::Value width_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(width_getter);
|
||||||
static JS::Value height_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(height_getter);
|
||||||
static JS::Value data_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(data_getter);
|
||||||
|
|
||||||
NonnullRefPtr<ImageData> m_impl;
|
NonnullRefPtr<ImageData> m_impl;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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());
|
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);
|
auto new_href = value.to_string(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return;
|
return;
|
||||||
window.impl().did_set_location_href({}, new_href);
|
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());
|
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());
|
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();
|
auto url = window.impl().document().url();
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(url.host());
|
builder.append(url.host());
|
||||||
|
@ -92,9 +92,9 @@ JS::Value LocationObject::host_getter(JS::Interpreter& interpreter)
|
||||||
return JS::js_string(interpreter, builder.to_string());
|
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();
|
auto fragment = window.impl().document().url().fragment();
|
||||||
if (!fragment.length())
|
if (!fragment.length())
|
||||||
return JS::js_string(interpreter, "");
|
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());
|
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();
|
auto query = window.impl().document().url().query();
|
||||||
if (!query.length())
|
if (!query.length())
|
||||||
return JS::js_string(interpreter, "");
|
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());
|
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;
|
StringBuilder builder;
|
||||||
builder.append(window.impl().document().url().protocol());
|
builder.append(window.impl().document().url().protocol());
|
||||||
builder.append(':');
|
builder.append(':');
|
||||||
return JS::js_string(interpreter, builder.to_string());
|
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({});
|
window.impl().did_call_location_reload({});
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,17 +40,17 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "LocationObject"; }
|
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&);
|
JS_DECLARE_NATIVE_GETTER(href_getter);
|
||||||
static void href_setter(JS::Interpreter&, JS::Value);
|
JS_DECLARE_NATIVE_SETTER(href_setter);
|
||||||
|
|
||||||
static JS::Value host_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(host_getter);
|
||||||
static JS::Value hostname_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(hostname_getter);
|
||||||
static JS::Value pathname_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(pathname_getter);
|
||||||
static JS::Value hash_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(hash_getter);
|
||||||
static JS::Value search_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(search_getter);
|
||||||
static JS::Value protocol_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(protocol_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,14 +65,14 @@ static MouseEvent* impl_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<MouseEventWrapper*>(this_object)->event();
|
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))
|
if (auto* impl = impl_from(interpreter))
|
||||||
return JS::Value(impl->offset_x());
|
return JS::Value(impl->offset_x());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value MouseEventWrapper::offset_y_getter(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_GETTER(MouseEventWrapper::offset_y_getter)
|
||||||
{
|
{
|
||||||
if (auto* impl = impl_from(interpreter))
|
if (auto* impl = impl_from(interpreter))
|
||||||
return JS::Value(impl->offset_y());
|
return JS::Value(impl->offset_y());
|
||||||
|
|
|
@ -42,8 +42,8 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "MouseEventWrapper"; }
|
virtual const char* class_name() const override { return "MouseEventWrapper"; }
|
||||||
|
|
||||||
static JS::Value offset_x_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(offset_x_getter);
|
||||||
static JS::Value offset_y_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(offset_y_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
return JS::js_string(interpreter, ResourceLoader::the().user_agent());
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "NavigatorObject"; }
|
virtual const char* class_name() const override { return "NavigatorObject"; }
|
||||||
|
|
||||||
static JS::Value user_agent_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(user_agent_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ static Window* impl_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<WindowObject*>(this_object)->impl();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -109,7 +109,7 @@ JS::Value WindowObject::alert(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value WindowObject::confirm(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(WindowObject::confirm)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -123,7 +123,7 @@ JS::Value WindowObject::confirm(JS::Interpreter& interpreter)
|
||||||
return JS::Value(impl->confirm(message));
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -149,7 +149,7 @@ JS::Value WindowObject::set_interval(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_timeout)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -175,7 +175,7 @@ JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
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)));
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -204,7 +204,7 @@ JS::Value WindowObject::cancel_animation_frame(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value WindowObject::document_getter(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -212,9 +212,10 @@ JS::Value WindowObject::document_getter(JS::Interpreter& interpreter)
|
||||||
return wrap(interpreter.heap(), impl->document());
|
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.
|
// FIXME: Figure out what we should do here. Just ignore attempts to set window.document for now.
|
||||||
|
UNUSED_PARAM(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,15 +48,15 @@ private:
|
||||||
virtual const char* class_name() const override { return "WindowObject"; }
|
virtual const char* class_name() const override { return "WindowObject"; }
|
||||||
virtual void visit_children(Visitor&) override;
|
virtual void visit_children(Visitor&) override;
|
||||||
|
|
||||||
static JS::Value document_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(document_getter);
|
||||||
static void document_setter(JS::Interpreter&, JS::Value);
|
JS_DECLARE_NATIVE_SETTER(document_setter);
|
||||||
|
|
||||||
static JS::Value alert(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(alert);
|
||||||
static JS::Value confirm(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(confirm);
|
||||||
static JS::Value set_interval(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(set_interval);
|
||||||
static JS::Value set_timeout(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(set_timeout);
|
||||||
static JS::Value request_animation_frame(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(request_animation_frame);
|
||||||
static JS::Value cancel_animation_frame(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(cancel_animation_frame);
|
||||||
|
|
||||||
NonnullRefPtr<Window> m_impl;
|
NonnullRefPtr<Window> m_impl;
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ static XMLHttpRequest* impl_from(JS::Interpreter& interpreter)
|
||||||
return &static_cast<XMLHttpRequestWrapper*>(this_object)->impl();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -81,7 +81,7 @@ JS::Value XMLHttpRequestPrototype::open(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value XMLHttpRequestPrototype::send(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::send)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -90,7 +90,7 @@ JS::Value XMLHttpRequestPrototype::send(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
@ -98,7 +98,7 @@ JS::Value XMLHttpRequestPrototype::ready_state_getter(JS::Interpreter& interpret
|
||||||
return JS::Value((i32)impl->ready_state());
|
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);
|
auto* impl = impl_from(interpreter);
|
||||||
if (!impl)
|
if (!impl)
|
||||||
|
|
|
@ -39,11 +39,11 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "XMLHttpRequestPrototype"; }
|
virtual const char* class_name() const override { return "XMLHttpRequestPrototype"; }
|
||||||
|
|
||||||
static JS::Value open(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(open);
|
||||||
static JS::Value send(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(send);
|
||||||
|
|
||||||
static JS::Value ready_state_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(ready_state_getter);
|
||||||
static JS::Value response_text_getter(JS::Interpreter&);
|
JS_DECLARE_NATIVE_GETTER(response_text_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,14 +55,15 @@ public:
|
||||||
virtual void initialize() override;
|
virtual void initialize() override;
|
||||||
virtual ~ReplObject() override;
|
virtual ~ReplObject() override;
|
||||||
|
|
||||||
static JS::Value load_file(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(load_file);
|
||||||
static JS::Value is_strict_mode(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(is_strict_mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ReplObject"; }
|
virtual const char* class_name() const override { return "ReplObject"; }
|
||||||
static JS::Value exit_interpreter(JS::Interpreter&);
|
|
||||||
static JS::Value repl_help(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(exit_interpreter);
|
||||||
static JS::Value save_to_file(JS::Interpreter&);
|
JS_DECLARE_NATIVE_FUNCTION(repl_help);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(save_to_file);
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool s_dump_ast = false;
|
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())
|
if (!interpreter.argument_count())
|
||||||
return JS::Value(false);
|
return JS::Value(false);
|
||||||
|
@ -396,7 +397,7 @@ JS::Value ReplObject::save_to_file(JS::Interpreter& interpreter)
|
||||||
return JS::Value(false);
|
return JS::Value(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value ReplObject::exit_interpreter(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ReplObject::exit_interpreter)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -406,7 +407,7 @@ JS::Value ReplObject::exit_interpreter(JS::Interpreter& interpreter)
|
||||||
exit(exit_code.as_double());
|
exit(exit_code.as_double());
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value ReplObject::repl_help(JS::Interpreter&)
|
JS_DEFINE_NATIVE_FUNCTION(ReplObject::repl_help)
|
||||||
{
|
{
|
||||||
printf("REPL commands:\n");
|
printf("REPL commands:\n");
|
||||||
printf(" exit(code): exit the REPL with specified code. Defaults to 0.\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();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Value ReplObject::load_file(JS::Interpreter& interpreter)
|
JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_file)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
return JS::Value(false);
|
return JS::Value(false);
|
||||||
|
@ -440,7 +441,7 @@ JS::Value ReplObject::load_file(JS::Interpreter& interpreter)
|
||||||
return JS::Value(true);
|
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());
|
return JS::Value(interpreter.in_strict_mode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue