mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibJS: Remove GlobalObject parameter from native functions
This commit is contained in:
parent
7b990c27a1
commit
b465f46e00
77 changed files with 240 additions and 215 deletions
|
@ -1788,12 +1788,12 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
|
||||||
|
|
||||||
if (arguments_match_check.is_empty()) {
|
if (arguments_match_check.is_empty()) {
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
return @function.name:snakecase@@overload_suffix@(vm, global_object);
|
return @function.name:snakecase@@overload_suffix@(vm);
|
||||||
)~~~");
|
)~~~");
|
||||||
} else {
|
} else {
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
if (@arguments_match_check@)
|
if (@arguments_match_check@)
|
||||||
return @function.name:snakecase@@overload_suffix@(vm, global_object);
|
return @function.name:snakecase@@overload_suffix@(vm);
|
||||||
)~~~");
|
)~~~");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ TEST_ROOT("Userland/Libraries/LibWasm/Tests");
|
||||||
|
|
||||||
TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile)
|
TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto filename = TRY(vm.argument(0).to_string(vm));
|
auto filename = TRY(vm.argument(0).to_string(vm));
|
||||||
auto file = Core::Stream::File::open(filename, Core::Stream::OpenMode::Read);
|
auto file = Core::Stream::File::open(filename, Core::Stream::OpenMode::Read);
|
||||||
if (file.is_error())
|
if (file.is_error())
|
||||||
|
@ -100,7 +100,7 @@ HashMap<Wasm::Linker::Name, Wasm::ExternValue> WebAssemblyModule::s_spec_test_na
|
||||||
|
|
||||||
TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
|
TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||||
if (!is<JS::Uint8Array>(object))
|
if (!is<JS::Uint8Array>(object))
|
||||||
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array argument to parse_webassembly_module");
|
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array argument to parse_webassembly_module");
|
||||||
|
|
|
@ -177,7 +177,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_name)
|
||||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "SheetGlobalObject");
|
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "SheetGlobalObject");
|
||||||
|
|
||||||
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
||||||
return JS::js_string(global_object.heap(), sheet_object->m_sheet.name());
|
return JS::js_string(vm, sheet_object->m_sheet.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_real_cell_contents)
|
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_real_cell_contents)
|
||||||
|
@ -240,7 +240,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::set_real_cell_contents)
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
||||||
if (!position.has_value())
|
if (!position.has_value())
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
|
|
||||||
auto object = JS::Object::create(realm, global_object.object_prototype());
|
auto object = JS::Object::create(realm, realm.global_object().object_prototype());
|
||||||
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.value().column)), JS::default_attributes);
|
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.value().column)), JS::default_attributes);
|
||||||
object->define_direct_property("row", JS::Value((unsigned)position.value().row), JS::default_attributes);
|
object->define_direct_property("row", JS::Value((unsigned)position.value().row), JS::default_attributes);
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
|
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
if (vm.argument_count() != 0)
|
if (vm.argument_count() != 0)
|
||||||
return vm.throw_completion<JS::TypeError>("Expected no arguments to current_cell_position()");
|
return vm.throw_completion<JS::TypeError>("Expected no arguments to current_cell_position()");
|
||||||
|
@ -284,7 +284,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
|
||||||
|
|
||||||
auto position = current_cell->position();
|
auto position = current_cell->position();
|
||||||
|
|
||||||
auto object = JS::Object::create(realm, global_object.object_prototype());
|
auto object = JS::Object::create(realm, realm.global_object().object_prototype());
|
||||||
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.column)), JS::default_attributes);
|
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.column)), JS::default_attributes);
|
||||||
object->define_direct_property("row", JS::Value((unsigned)position.row), JS::default_attributes);
|
object->define_direct_property("row", JS::Value((unsigned)position.row), JS::default_attributes);
|
||||||
|
|
||||||
|
|
|
@ -718,8 +718,8 @@ ThrowCompletionOr<void> GetObjectPropertyIterator::execute_impl(Bytecode::Interp
|
||||||
.iterator = object,
|
.iterator = object,
|
||||||
.next_method = NativeFunction::create(
|
.next_method = NativeFunction::create(
|
||||||
interpreter.realm(),
|
interpreter.realm(),
|
||||||
[seen_items = HashTable<PropertyKey>(), items = move(properties)](VM& vm, GlobalObject& global_object) mutable -> ThrowCompletionOr<Value> {
|
[seen_items = HashTable<PropertyKey>(), items = move(properties)](VM& vm) mutable -> ThrowCompletionOr<Value> {
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto iterated_object_value = vm.this_value();
|
auto iterated_object_value = vm.this_value();
|
||||||
if (!iterated_object_value.is_object())
|
if (!iterated_object_value.is_object())
|
||||||
return vm.throw_completion<InternalError>("Invalid state for GetObjectPropertyIterator.next");
|
return vm.throw_completion<InternalError>("Invalid state for GetObjectPropertyIterator.next");
|
||||||
|
|
|
@ -446,7 +446,7 @@ void CyclicModule::execute_async_module(VM& vm)
|
||||||
auto capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
auto capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
||||||
|
|
||||||
// 4. Let fulfilledClosure be a new Abstract Closure with no parameters that captures module and performs the following steps when called:
|
// 4. Let fulfilledClosure be a new Abstract Closure with no parameters that captures module and performs the following steps when called:
|
||||||
auto fulfilled_closure = [&](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
auto fulfilled_closure = [&](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
// a. Perform AsyncModuleExecutionFulfilled(module).
|
// a. Perform AsyncModuleExecutionFulfilled(module).
|
||||||
async_module_execution_fulfilled(vm);
|
async_module_execution_fulfilled(vm);
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ void CyclicModule::execute_async_module(VM& vm)
|
||||||
auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
|
auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
|
||||||
|
|
||||||
// 6. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures module and performs the following steps when called:
|
// 6. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures module and performs the following steps when called:
|
||||||
auto rejected_closure = [&](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
auto rejected_closure = [&](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
auto error = vm.argument(0);
|
auto error = vm.argument(0);
|
||||||
|
|
||||||
// a. Perform AsyncModuleExecutionRejected(module, error).
|
// a. Perform AsyncModuleExecutionRejected(module, error).
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
#define JS_DECLARE_NATIVE_FUNCTION(name) \
|
#define JS_DECLARE_NATIVE_FUNCTION(name) \
|
||||||
static JS::ThrowCompletionOr<JS::Value> name(JS::VM&, JS::GlobalObject&)
|
static JS::ThrowCompletionOr<JS::Value> name(JS::VM&)
|
||||||
|
|
||||||
#define JS_DEFINE_NATIVE_FUNCTION(name) \
|
#define JS_DEFINE_NATIVE_FUNCTION(name) \
|
||||||
JS::ThrowCompletionOr<JS::Value> name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object)
|
JS::ThrowCompletionOr<JS::Value> name([[maybe_unused]] JS::VM& vm)
|
||||||
|
|
||||||
// NOTE: Proxy is not included here as it doesn't have a prototype - m_proxy_constructor is initialized separately.
|
// NOTE: Proxy is not included here as it doesn't have a prototype - m_proxy_constructor is initialized separately.
|
||||||
#define JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
|
#define JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
|
||||||
|
|
|
@ -1118,10 +1118,10 @@ Object* create_mapped_arguments_object(VM& vm, FunctionObject& function, Vector<
|
||||||
// 3. Perform ! map.[[DefineOwnProperty]](! ToString(𝔽(index)), PropertyDescriptor { [[Set]]: p, [[Get]]: g, [[Enumerable]]: false, [[Configurable]]: true }).
|
// 3. Perform ! map.[[DefineOwnProperty]](! ToString(𝔽(index)), PropertyDescriptor { [[Set]]: p, [[Get]]: g, [[Enumerable]]: false, [[Configurable]]: true }).
|
||||||
object->parameter_map().define_native_accessor(
|
object->parameter_map().define_native_accessor(
|
||||||
PropertyKey { index },
|
PropertyKey { index },
|
||||||
[&environment, name](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
[&environment, name](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
return MUST(environment.get_binding_value(vm, name, false));
|
return MUST(environment.get_binding_value(vm, name, false));
|
||||||
},
|
},
|
||||||
[&environment, name](VM& vm, GlobalObject&) {
|
[&environment, name](VM& vm) {
|
||||||
MUST(environment.set_mutable_binding(vm, name, vm.argument(0), false));
|
MUST(environment.set_mutable_binding(vm, name, vm.argument(0), false));
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
},
|
},
|
||||||
|
|
|
@ -34,6 +34,8 @@ void ArrayBufferPrototype::initialize(Realm& realm)
|
||||||
// 25.1.5.3 ArrayBuffer.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice
|
// 25.1.5.3 ArrayBuffer.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let O be the this value.
|
// 1. Let O be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
|
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
|
||||||
auto* array_buffer_object = TRY(typed_this_value(vm));
|
auto* array_buffer_object = TRY(typed_this_value(vm));
|
||||||
|
@ -80,7 +82,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
||||||
auto new_length = max(final - first, 0.0);
|
auto new_length = max(final - first, 0.0);
|
||||||
|
|
||||||
// 15. Let ctor be ? SpeciesConstructor(O, %ArrayBuffer%).
|
// 15. Let ctor be ? SpeciesConstructor(O, %ArrayBuffer%).
|
||||||
auto* constructor = TRY(species_constructor(vm, *array_buffer_object, *global_object.array_buffer_constructor()));
|
auto* constructor = TRY(species_constructor(vm, *array_buffer_object, *realm.global_object().array_buffer_constructor()));
|
||||||
|
|
||||||
// 16. Let new be ? Construct(ctor, « 𝔽(newLen) »).
|
// 16. Let new be ? Construct(ctor, « 𝔽(newLen) »).
|
||||||
auto* new_array_buffer = TRY(construct(vm, *constructor, Value(new_length)));
|
auto* new_array_buffer = TRY(construct(vm, *constructor, Value(new_length)));
|
||||||
|
|
|
@ -85,7 +85,7 @@ ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_targe
|
||||||
// 23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-array.from
|
// 23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-array.from
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto constructor = vm.this_value();
|
auto constructor = vm.this_value();
|
||||||
|
|
||||||
FunctionObject* map_fn = nullptr;
|
FunctionObject* map_fn = nullptr;
|
||||||
|
@ -177,7 +177,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array)
|
||||||
// 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of
|
// 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto this_value = vm.this_value();
|
auto this_value = vm.this_value();
|
||||||
Object* array;
|
Object* array;
|
||||||
if (this_value.is_constructor())
|
if (this_value.is_constructor())
|
||||||
|
|
|
@ -34,7 +34,7 @@ void ArrayIteratorPrototype::initialize(Realm& realm)
|
||||||
// FIXME: This seems to be CreateArrayIterator (https://tc39.es/ecma262/#sec-createarrayiterator) instead of %ArrayIteratorPrototype%.next.
|
// FIXME: This seems to be CreateArrayIterator (https://tc39.es/ecma262/#sec-createarrayiterator) instead of %ArrayIteratorPrototype%.next.
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* iterator = TRY(typed_this_value(vm));
|
auto* iterator = TRY(typed_this_value(vm));
|
||||||
auto target_array = iterator->array();
|
auto target_array = iterator->array();
|
||||||
|
|
|
@ -189,7 +189,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
|
||||||
return TRY(val.is_array(vm));
|
return TRY(val.is_array(vm));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto append_to_new_array = [&vm, &is_concat_spreadable, &new_array, &global_object, &n](Value arg) -> ThrowCompletionOr<void> {
|
auto append_to_new_array = [&vm, &is_concat_spreadable, &new_array, &n](Value arg) -> ThrowCompletionOr<void> {
|
||||||
auto spreadable = TRY(is_concat_spreadable(arg));
|
auto spreadable = TRY(is_concat_spreadable(arg));
|
||||||
if (spreadable) {
|
if (spreadable) {
|
||||||
VERIFY(arg.is_object());
|
VERIFY(arg.is_object());
|
||||||
|
@ -295,7 +295,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::copy_within)
|
||||||
// 23.1.3.5 Array.prototype.entries ( ), https://tc39.es/ecma262/#sec-array.prototype.entries
|
// 23.1.3.5 Array.prototype.entries ( ), https://tc39.es/ecma262/#sec-array.prototype.entries
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::entries)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::entries)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||||
|
|
||||||
|
@ -753,7 +753,7 @@ static void add_value_to_keyed_group(VM& vm, GroupsType& groups, KeyType key, Va
|
||||||
// 2.1 Array.prototype.group ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.group
|
// 2.1 Array.prototype.group ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.group
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto callback_function = vm.argument(0);
|
auto callback_function = vm.argument(0);
|
||||||
auto this_arg = vm.argument(1);
|
auto this_arg = vm.argument(1);
|
||||||
|
@ -809,7 +809,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
|
||||||
// 2.2 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.grouptomap
|
// 2.2 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.grouptomap
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto callback_function = vm.argument(0);
|
auto callback_function = vm.argument(0);
|
||||||
auto this_arg = vm.argument(1);
|
auto this_arg = vm.argument(1);
|
||||||
|
@ -1018,7 +1018,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
|
||||||
// 23.1.3.19 Array.prototype.keys ( ), https://tc39.es/ecma262/#sec-array.prototype.keys
|
// 23.1.3.19 Array.prototype.keys ( ), https://tc39.es/ecma262/#sec-array.prototype.keys
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::keys)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::keys)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||||
|
|
||||||
|
@ -1749,7 +1749,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
|
||||||
// 1.1.1.4 Array.prototype.toReversed ( ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed
|
// 1.1.1.4 Array.prototype.toReversed ( ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let O be ? ToObject(this value).
|
// 1. Let O be ? ToObject(this value).
|
||||||
auto* object = TRY(vm.this_value().to_object(vm));
|
auto* object = TRY(vm.this_value().to_object(vm));
|
||||||
|
@ -1785,7 +1785,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
|
||||||
// 1.1.1.5 Array.prototype.toSorted ( comparefn ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted
|
// 1.1.1.5 Array.prototype.toSorted ( comparefn ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto comparefn = vm.argument(0);
|
auto comparefn = vm.argument(0);
|
||||||
|
|
||||||
|
@ -1827,7 +1827,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
|
||||||
// 1.1.1.6 Array.prototype.toSpliced ( start, deleteCount, ...items ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced
|
// 1.1.1.6 Array.prototype.toSpliced ( start, deleteCount, ...items ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto start = vm.argument(0);
|
auto start = vm.argument(0);
|
||||||
auto delete_count = vm.argument(1);
|
auto delete_count = vm.argument(1);
|
||||||
|
@ -1958,6 +1958,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
|
||||||
// 23.1.3.33 Array.prototype.toString ( ), https://tc39.es/ecma262/#sec-array.prototype.tostring
|
// 23.1.3.33 Array.prototype.toString ( ), https://tc39.es/ecma262/#sec-array.prototype.tostring
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let array be ? ToObject(this value).
|
// 1. Let array be ? ToObject(this value).
|
||||||
auto* array = TRY(vm.this_value().to_object(vm));
|
auto* array = TRY(vm.this_value().to_object(vm));
|
||||||
|
|
||||||
|
@ -1966,7 +1968,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string)
|
||||||
|
|
||||||
// 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%.
|
// 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%.
|
||||||
if (!func.is_function())
|
if (!func.is_function())
|
||||||
func = global_object.object_prototype_to_string_function();
|
func = realm.global_object().object_prototype_to_string_function();
|
||||||
|
|
||||||
// 4. Return ? Call(func, array).
|
// 4. Return ? Call(func, array).
|
||||||
return TRY(call(vm, func.as_function(), array));
|
return TRY(call(vm, func.as_function(), array));
|
||||||
|
@ -2007,7 +2009,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift)
|
||||||
// 23.1.3.35 Array.prototype.values ( ), https://tc39.es/ecma262/#sec-array.prototype.values
|
// 23.1.3.35 Array.prototype.values ( ), https://tc39.es/ecma262/#sec-array.prototype.values
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||||
|
|
||||||
|
@ -2017,7 +2019,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values)
|
||||||
// 1.1.1.7 Array.prototype.with ( index, value ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with
|
// 1.1.1.7 Array.prototype.with ( index, value ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::with)
|
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::with)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto index = vm.argument(0);
|
auto index = vm.argument(0);
|
||||||
auto value = vm.argument(1);
|
auto value = vm.argument(1);
|
||||||
|
|
|
@ -50,7 +50,7 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro
|
||||||
auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *global_object.promise_constructor(), value));
|
auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *global_object.promise_constructor(), value));
|
||||||
|
|
||||||
// 8. Let unwrap be a new Abstract Closure with parameters (value) that captures done and performs the following steps when called:
|
// 8. Let unwrap be a new Abstract Closure with parameters (value) that captures done and performs the following steps when called:
|
||||||
auto unwrap = [done](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
auto unwrap = [done](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
// a. Return CreateIterResultObject(value, done).
|
// a. Return CreateIterResultObject(value, done).
|
||||||
return create_iterator_result_object(vm, vm.argument(0), done);
|
return create_iterator_result_object(vm, vm.argument(0), done);
|
||||||
};
|
};
|
||||||
|
@ -69,12 +69,14 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro
|
||||||
// 27.1.4.2.1 %AsyncFromSyncIteratorPrototype%.next ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.next
|
// 27.1.4.2.1 %AsyncFromSyncIteratorPrototype%.next ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.next
|
||||||
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let O be the this value.
|
// 1. Let O be the this value.
|
||||||
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
|
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
|
||||||
auto* this_object = MUST(typed_this_object(vm));
|
auto* this_object = MUST(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||||
|
|
||||||
// 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]].
|
// 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]].
|
||||||
auto& sync_iterator_record = this_object->sync_iterator_record();
|
auto& sync_iterator_record = this_object->sync_iterator_record();
|
||||||
|
@ -95,14 +97,14 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next)
|
||||||
// 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.return
|
// 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.return
|
||||||
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
|
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let O be the this value.
|
// 1. Let O be the this value.
|
||||||
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
|
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
|
||||||
auto* this_object = MUST(typed_this_object(vm));
|
auto* this_object = MUST(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||||
|
|
||||||
// 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]].
|
// 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]].
|
||||||
auto* sync_iterator = this_object->sync_iterator_record().iterator;
|
auto* sync_iterator = this_object->sync_iterator_record().iterator;
|
||||||
|
@ -148,14 +150,14 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
|
||||||
// 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.throw
|
// 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.throw
|
||||||
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
|
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let O be the this value.
|
// 1. Let O be the this value.
|
||||||
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
|
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
|
||||||
auto* this_object = MUST(typed_this_object(vm));
|
auto* this_object = MUST(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||||
|
|
||||||
// 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]].
|
// 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]].
|
||||||
auto* sync_iterator = this_object->sync_iterator_record().iterator;
|
auto* sync_iterator = this_object->sync_iterator_record().iterator;
|
||||||
|
|
|
@ -21,10 +21,10 @@ ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(Realm& realm, Genera
|
||||||
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorObject* generator_object)
|
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorObject* generator_object)
|
||||||
: Promise(*realm.global_object().promise_prototype())
|
: Promise(*realm.global_object().promise_prototype())
|
||||||
, m_generator_object(generator_object)
|
, m_generator_object(generator_object)
|
||||||
, m_on_fulfillment(NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm, GlobalObject&) {
|
, m_on_fulfillment(NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm) {
|
||||||
return react_to_async_task_completion(vm, vm.argument(0), true);
|
return react_to_async_task_completion(vm, vm.argument(0), true);
|
||||||
}))
|
}))
|
||||||
, m_on_rejection(NativeFunction::create(realm, "async.on_rejection"sv, [this](VM& vm, GlobalObject&) {
|
, m_on_rejection(NativeFunction::create(realm, "async.on_rejection"sv, [this](VM& vm) {
|
||||||
return react_to_async_task_completion(vm, vm.argument(0), false);
|
return react_to_async_task_completion(vm, vm.argument(0), false);
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,8 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string)
|
||||||
// 19.3.1 BigInt.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-bigint.prototype.tolocalestring
|
// 19.3.1 BigInt.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-bigint.prototype.tolocalestring
|
||||||
JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string)
|
JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto locales = vm.argument(0);
|
auto locales = vm.argument(0);
|
||||||
auto options = vm.argument(1);
|
auto options = vm.argument(1);
|
||||||
|
|
||||||
|
@ -69,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string)
|
||||||
auto* bigint = TRY(this_bigint_value(vm, vm.this_value()));
|
auto* bigint = TRY(this_bigint_value(vm, vm.this_value()));
|
||||||
|
|
||||||
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
|
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
|
||||||
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *global_object.intl_number_format_constructor(), locales, options)));
|
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), locales, options)));
|
||||||
|
|
||||||
// 3. Return ? FormatNumeric(numberFormat, x).
|
// 3. Return ? FormatNumeric(numberFormat, x).
|
||||||
auto formatted = Intl::format_numeric(vm, *number_format, Value(bigint));
|
auto formatted = Intl::format_numeric(vm, *number_format, Value(bigint));
|
||||||
|
|
|
@ -42,7 +42,7 @@ ThrowCompletionOr<Value> await(VM& vm, Value value)
|
||||||
Optional<bool> success;
|
Optional<bool> success;
|
||||||
Value result;
|
Value result;
|
||||||
// 3. Let fulfilledClosure be a new Abstract Closure with parameters (value) that captures asyncContext and performs the following steps when called:
|
// 3. Let fulfilledClosure be a new Abstract Closure with parameters (value) that captures asyncContext and performs the following steps when called:
|
||||||
auto fulfilled_closure = [&success, &result](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
auto fulfilled_closure = [&success, &result](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
// a. Let prevContext be the running execution context.
|
// a. Let prevContext be the running execution context.
|
||||||
// b. Suspend prevContext.
|
// b. Suspend prevContext.
|
||||||
// FIXME: We don't have this concept yet.
|
// FIXME: We don't have this concept yet.
|
||||||
|
@ -66,7 +66,7 @@ ThrowCompletionOr<Value> await(VM& vm, Value value)
|
||||||
auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 1, "");
|
auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 1, "");
|
||||||
|
|
||||||
// 5. Let rejectedClosure be a new Abstract Closure with parameters (reason) that captures asyncContext and performs the following steps when called:
|
// 5. Let rejectedClosure be a new Abstract Closure with parameters (reason) that captures asyncContext and performs the following steps when called:
|
||||||
auto rejected_closure = [&success, &result](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
auto rejected_closure = [&success, &result](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
// a. Let prevContext be the running execution context.
|
// a. Let prevContext be the running execution context.
|
||||||
// b. Suspend prevContext.
|
// b. Suspend prevContext.
|
||||||
// FIXME: We don't have this concept yet.
|
// FIXME: We don't have this concept yet.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
||||||
* Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
|
* Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -43,97 +43,97 @@ void ConsoleObject::initialize(Realm& realm)
|
||||||
// 1.1.6. log(...data), https://console.spec.whatwg.org/#log
|
// 1.1.6. log(...data), https://console.spec.whatwg.org/#log
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log)
|
||||||
{
|
{
|
||||||
return global_object.console().log();
|
return vm.current_realm()->global_object().console().log();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1.3. debug(...data), https://console.spec.whatwg.org/#debug
|
// 1.1.3. debug(...data), https://console.spec.whatwg.org/#debug
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug)
|
||||||
{
|
{
|
||||||
return global_object.console().debug();
|
return vm.current_realm()->global_object().console().debug();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1.5. info(...data), https://console.spec.whatwg.org/#info
|
// 1.1.5. info(...data), https://console.spec.whatwg.org/#info
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info)
|
||||||
{
|
{
|
||||||
return global_object.console().info();
|
return vm.current_realm()->global_object().console().info();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1.9. warn(...data), https://console.spec.whatwg.org/#warn
|
// 1.1.9. warn(...data), https://console.spec.whatwg.org/#warn
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn)
|
||||||
{
|
{
|
||||||
return global_object.console().warn();
|
return vm.current_realm()->global_object().console().warn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1.4. error(...data), https://console.spec.whatwg.org/#error
|
// 1.1.4. error(...data), https://console.spec.whatwg.org/#error
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error)
|
||||||
{
|
{
|
||||||
return global_object.console().error();
|
return vm.current_realm()->global_object().console().error();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1.8. trace(...data), https://console.spec.whatwg.org/#trace
|
// 1.1.8. trace(...data), https://console.spec.whatwg.org/#trace
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace)
|
||||||
{
|
{
|
||||||
return global_object.console().trace();
|
return vm.current_realm()->global_object().console().trace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.2.1. count(label), https://console.spec.whatwg.org/#count
|
// 1.2.1. count(label), https://console.spec.whatwg.org/#count
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count)
|
||||||
{
|
{
|
||||||
return global_object.console().count();
|
return vm.current_realm()->global_object().console().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.2.2. countReset(label), https://console.spec.whatwg.org/#countreset
|
// 1.2.2. countReset(label), https://console.spec.whatwg.org/#countreset
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset)
|
||||||
{
|
{
|
||||||
return global_object.console().count_reset();
|
return vm.current_realm()->global_object().console().count_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1.2. clear(), https://console.spec.whatwg.org/#clear
|
// 1.1.2. clear(), https://console.spec.whatwg.org/#clear
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear)
|
||||||
{
|
{
|
||||||
return global_object.console().clear();
|
return vm.current_realm()->global_object().console().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1.1. assert(condition, ...data), https://console.spec.whatwg.org/#assert
|
// 1.1.1. assert(condition, ...data), https://console.spec.whatwg.org/#assert
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::assert_)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::assert_)
|
||||||
{
|
{
|
||||||
return global_object.console().assert_();
|
return vm.current_realm()->global_object().console().assert_();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.3.1. group(...data), https://console.spec.whatwg.org/#group
|
// 1.3.1. group(...data), https://console.spec.whatwg.org/#group
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group)
|
||||||
{
|
{
|
||||||
return global_object.console().group();
|
return vm.current_realm()->global_object().console().group();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.3.2. groupCollapsed(...data), https://console.spec.whatwg.org/#groupcollapsed
|
// 1.3.2. groupCollapsed(...data), https://console.spec.whatwg.org/#groupcollapsed
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_collapsed)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_collapsed)
|
||||||
{
|
{
|
||||||
return global_object.console().group_collapsed();
|
return vm.current_realm()->global_object().console().group_collapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.3.3. groupEnd(), https://console.spec.whatwg.org/#groupend
|
// 1.3.3. groupEnd(), https://console.spec.whatwg.org/#groupend
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_end)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_end)
|
||||||
{
|
{
|
||||||
return global_object.console().group_end();
|
return vm.current_realm()->global_object().console().group_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.4.1. time(label), https://console.spec.whatwg.org/#time
|
// 1.4.1. time(label), https://console.spec.whatwg.org/#time
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time)
|
||||||
{
|
{
|
||||||
return global_object.console().time();
|
return vm.current_realm()->global_object().console().time();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.4.2. timeLog(label, ...data), https://console.spec.whatwg.org/#timelog
|
// 1.4.2. timeLog(label, ...data), https://console.spec.whatwg.org/#timelog
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_log)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_log)
|
||||||
{
|
{
|
||||||
return global_object.console().time_log();
|
return vm.current_realm()->global_object().console().time_log();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.4.3. timeEnd(label), https://console.spec.whatwg.org/#timeend
|
// 1.4.3. timeEnd(label), https://console.spec.whatwg.org/#timeend
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_end)
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_end)
|
||||||
{
|
{
|
||||||
return global_object.console().time_end();
|
return vm.current_realm()->global_object().console().time_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,6 @@ ThrowCompletionOr<Value> DateConstructor::call()
|
||||||
ThrowCompletionOr<Object*> DateConstructor::construct(FunctionObject& new_target)
|
ThrowCompletionOr<Object*> DateConstructor::construct(FunctionObject& new_target)
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
auto& global_object = this->global_object();
|
|
||||||
|
|
||||||
double date_value;
|
double date_value;
|
||||||
|
|
||||||
|
@ -249,7 +248,7 @@ ThrowCompletionOr<Object*> DateConstructor::construct(FunctionObject& new_target
|
||||||
// c. Let m be ? ToNumber(values[1]).
|
// c. Let m be ? ToNumber(values[1]).
|
||||||
auto month = TRY(vm.argument(1).to_number(vm)).as_double();
|
auto month = TRY(vm.argument(1).to_number(vm)).as_double();
|
||||||
|
|
||||||
auto arg_or = [&vm, &global_object](size_t i, double fallback) -> ThrowCompletionOr<double> {
|
auto arg_or = [&vm](size_t i, double fallback) -> ThrowCompletionOr<double> {
|
||||||
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback;
|
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -312,7 +311,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse)
|
||||||
// 21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ), https://tc39.es/ecma262/#sec-date.utc
|
// 21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ), https://tc39.es/ecma262/#sec-date.utc
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DateConstructor::utc)
|
JS_DEFINE_NATIVE_FUNCTION(DateConstructor::utc)
|
||||||
{
|
{
|
||||||
auto arg_or = [&vm, &global_object](size_t i, double fallback) -> ThrowCompletionOr<double> {
|
auto arg_or = [&vm](size_t i, double fallback) -> ThrowCompletionOr<double> {
|
||||||
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback;
|
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1318,7 +1318,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year)
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string)
|
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string)
|
||||||
{
|
{
|
||||||
// NOTE: The toUTCString method is preferred. The toGMTString method is provided principally for compatibility with old code.
|
// NOTE: The toUTCString method is preferred. The toGMTString method is provided principally for compatibility with old code.
|
||||||
return to_utc_string(vm, global_object);
|
return to_utc_string(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -726,7 +726,7 @@ void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, Promi
|
||||||
auto& running_context = vm.running_execution_context();
|
auto& running_context = vm.running_execution_context();
|
||||||
|
|
||||||
// 3. Set the code evaluation state of asyncContext such that when evaluation is resumed for that execution context the following steps will be performed:
|
// 3. Set the code evaluation state of asyncContext such that when evaluation is resumed for that execution context the following steps will be performed:
|
||||||
auto* execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
auto* execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm) -> ThrowCompletionOr<Value> {
|
||||||
// a. Let result be the result of evaluating asyncBody.
|
// a. Let result be the result of evaluating asyncBody.
|
||||||
auto result = async_body->execute(vm.interpreter());
|
auto result = async_body->execute(vm.interpreter());
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply)
|
||||||
// 3.1.2.1 Function.prototype.bind ( thisArg, ...args ), https://tc39.es/proposal-shadowrealm/#sec-function.prototype.bind
|
// 3.1.2.1 Function.prototype.bind ( thisArg, ...args ), https://tc39.es/proposal-shadowrealm/#sec-function.prototype.bind
|
||||||
JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind)
|
JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto this_argument = vm.argument(0);
|
auto this_argument = vm.argument(0);
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ void GlobalObject::initialize_global_object()
|
||||||
|
|
||||||
// 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
|
// 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
|
||||||
m_throw_type_error_function = NativeFunction::create(
|
m_throw_type_error_function = NativeFunction::create(
|
||||||
realm, [](VM& vm, GlobalObject&) {
|
realm, [](VM& vm) {
|
||||||
return vm.throw_completion<TypeError>(ErrorType::RestrictedFunctionPropertiesAccess);
|
return vm.throw_completion<TypeError>(ErrorType::RestrictedFunctionPropertiesAccess);
|
||||||
},
|
},
|
||||||
0, "", &realm);
|
0, "", &realm);
|
||||||
|
|
|
@ -34,7 +34,7 @@ void CollatorPrototype::initialize(Realm& realm)
|
||||||
// 10.3.3 get Intl.Collator.prototype.compare, https://tc39.es/ecma402/#sec-intl.collator.prototype.compare
|
// 10.3.3 get Intl.Collator.prototype.compare, https://tc39.es/ecma402/#sec-intl.collator.prototype.compare
|
||||||
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
|
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let collator be the this value.
|
// 1. Let collator be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
|
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
|
||||||
|
@ -57,14 +57,14 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
|
||||||
// 10.3.4 Intl.Collator.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.collator.prototype.resolvedoptions
|
// 10.3.4 Intl.Collator.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.collator.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let collator be the this value.
|
// 1. Let collator be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
|
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
|
||||||
auto* collator = TRY(typed_this_object(vm));
|
auto* collator = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each row of Table 3, except the header row, in table order, do
|
// 4. For each row of Table 3, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -40,7 +40,7 @@ void DateTimeFormatPrototype::initialize(Realm& realm)
|
||||||
// 11.3.3 get Intl.DateTimeFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.format
|
// 11.3.3 get Intl.DateTimeFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.format
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
|
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let dtf be the this value.
|
// 1. Let dtf be the this value.
|
||||||
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
||||||
|
@ -65,6 +65,8 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
|
||||||
// 11.3.4 Intl.DateTimeFormat.prototype.formatToParts ( date ), https://tc39.es/ecma402/#sec-Intl.DateTimeFormat.prototype.formatToParts
|
// 11.3.4 Intl.DateTimeFormat.prototype.formatToParts ( date ), https://tc39.es/ecma402/#sec-Intl.DateTimeFormat.prototype.formatToParts
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
|
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto date = vm.argument(0);
|
auto date = vm.argument(0);
|
||||||
|
|
||||||
// 1. Let dtf be the this value.
|
// 1. Let dtf be the this value.
|
||||||
|
@ -76,7 +78,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
|
||||||
// 3. If date is undefined, then
|
// 3. If date is undefined, then
|
||||||
if (date.is_undefined()) {
|
if (date.is_undefined()) {
|
||||||
// a. Let x be ! Call(%Date.now%, undefined).
|
// a. Let x be ! Call(%Date.now%, undefined).
|
||||||
date_value = MUST(call(vm, global_object.date_constructor_now_function(), js_undefined())).as_double();
|
date_value = MUST(call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double();
|
||||||
}
|
}
|
||||||
// 4. Else,
|
// 4. Else,
|
||||||
else {
|
else {
|
||||||
|
@ -144,7 +146,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts)
|
||||||
// 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
|
// 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let dtf be the this value.
|
// 1. Let dtf be the this value.
|
||||||
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
||||||
|
@ -153,7 +155,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
|
||||||
auto* date_time_format = TRY(typed_this_object(vm));
|
auto* date_time_format = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 5. For each row of Table 5, except the header row, in table order, do
|
// 5. For each row of Table 5, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -124,14 +124,14 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
|
||||||
// 12.3.4 Intl.DisplayNames.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions
|
// 12.3.4 Intl.DisplayNames.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let displayNames be this value.
|
// 1. Let displayNames be this value.
|
||||||
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
|
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
|
||||||
auto* display_names = TRY(typed_this_object(vm));
|
auto* display_names = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each row of Table 8, except the header row, in table order, do
|
// 4. For each row of Table 8, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
|
||||||
// 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts
|
// 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let df be this value.
|
// 1. Let df be this value.
|
||||||
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
|
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
|
||||||
|
@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
||||||
auto const& part = formatted[n];
|
auto const& part = formatted[n];
|
||||||
|
|
||||||
// a. Let obj be ! OrdinaryObjectCreate(%ObjectPrototype%).
|
// a. Let obj be ! OrdinaryObjectCreate(%ObjectPrototype%).
|
||||||
auto* object = Object::create(realm, global_object.object_prototype());
|
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]).
|
// b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]).
|
||||||
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
||||||
|
@ -110,14 +110,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
||||||
// 1.4.5 Intl.DurationFormat.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.resolvedOptions
|
// 1.4.5 Intl.DurationFormat.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.resolvedOptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let df be the this value.
|
// 1. Let df be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
|
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
|
||||||
auto* duration_format = TRY(typed_this_object(vm));
|
auto* duration_format = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each row of Table 2, except the header row, in table order, do
|
// 4. For each row of Table 2, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -61,7 +61,7 @@ void Intl::initialize(Realm& realm)
|
||||||
// 8.3.1 Intl.getCanonicalLocales ( locales ), https://tc39.es/ecma402/#sec-intl.getcanonicallocales
|
// 8.3.1 Intl.getCanonicalLocales ( locales ), https://tc39.es/ecma402/#sec-intl.getcanonicallocales
|
||||||
JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
|
JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto locales = vm.argument(0);
|
auto locales = vm.argument(0);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ static Vector<StringView> available_time_zones()
|
||||||
// 2.2.2 Intl.supportedValuesOf ( key ), https://tc39.es/proposal-intl-enumeration/#sec-intl.supportedvaluesof
|
// 2.2.2 Intl.supportedValuesOf ( key ), https://tc39.es/proposal-intl-enumeration/#sec-intl.supportedvaluesof
|
||||||
JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
|
JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let key be ? ToString(key).
|
// 1. Let key be ? ToString(key).
|
||||||
auto key = TRY(vm.argument(0).to_string(vm));
|
auto key = TRY(vm.argument(0).to_string(vm));
|
||||||
|
|
|
@ -69,14 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
|
||||||
// 13.3.5 Intl.ListFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions
|
// 13.3.5 Intl.ListFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let lf be the this value.
|
// 1. Let lf be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
|
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
|
||||||
auto* list_format = TRY(typed_this_object(vm));
|
auto* list_format = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each row of Table 10, except the header row, in table order, do
|
// 4. For each row of Table 10, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -55,7 +55,7 @@ void LocalePrototype::initialize(Realm& realm)
|
||||||
// 14.3.3 Intl.Locale.prototype.maximize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.maximize
|
// 14.3.3 Intl.Locale.prototype.maximize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.maximize
|
||||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
|
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let loc be the this value.
|
// 1. Let loc be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||||
|
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
|
||||||
// 14.3.4 Intl.Locale.prototype.minimize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.minimize
|
// 14.3.4 Intl.Locale.prototype.minimize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.minimize
|
||||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
|
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let loc be the this value.
|
// 1. Let loc be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||||
|
@ -251,14 +251,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::time_zones)
|
||||||
// 1.4.21 get Intl.Locale.prototype.textInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.textInfo
|
// 1.4.21 get Intl.Locale.prototype.textInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.textInfo
|
||||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
|
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let loc be the this value.
|
// 1. Let loc be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||||
auto* locale_object = TRY(typed_this_object(vm));
|
auto* locale_object = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let info be ! ObjectCreate(%Object.prototype%).
|
// 3. Let info be ! ObjectCreate(%Object.prototype%).
|
||||||
auto* info = Object::create(realm, global_object.object_prototype());
|
auto* info = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Let dir be ! CharacterDirectionOfLocale(loc).
|
// 4. Let dir be ! CharacterDirectionOfLocale(loc).
|
||||||
auto direction = character_direction_of_locale(*locale_object);
|
auto direction = character_direction_of_locale(*locale_object);
|
||||||
|
@ -273,14 +273,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
|
||||||
// 1.4.22 get Intl.Locale.prototype.weekInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.weekInfo
|
// 1.4.22 get Intl.Locale.prototype.weekInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.weekInfo
|
||||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info)
|
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let loc be the this value.
|
// 1. Let loc be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||||
[[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm));
|
[[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let info be ! ObjectCreate(%Object.prototype%).
|
// 3. Let info be ! ObjectCreate(%Object.prototype%).
|
||||||
auto* info = Object::create(realm, global_object.object_prototype());
|
auto* info = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Let wi be ! WeekInfoOfLocale(loc).
|
// 4. Let wi be ! WeekInfoOfLocale(loc).
|
||||||
auto week_info = week_info_of_locale(*locale_object);
|
auto week_info = week_info_of_locale(*locale_object);
|
||||||
|
|
|
@ -40,7 +40,7 @@ void NumberFormatPrototype::initialize(Realm& realm)
|
||||||
// 15.3.3 get Intl.NumberFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.numberformat.prototype.format
|
// 15.3.3 get Intl.NumberFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.numberformat.prototype.format
|
||||||
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format)
|
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let nf be the this value.
|
// 1. Let nf be the this value.
|
||||||
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
||||||
|
@ -136,7 +136,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range_to_parts)
|
||||||
// 15.3.5 Intl.NumberFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions
|
// 15.3.5 Intl.NumberFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let nf be the this value.
|
// 1. Let nf be the this value.
|
||||||
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
|
||||||
|
@ -145,7 +145,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
|
||||||
auto* number_format = TRY(typed_this_object(vm));
|
auto* number_format = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 5. For each row of Table 11, except the header row, in table order, do
|
// 5. For each row of Table 11, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -79,14 +79,14 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
|
||||||
// 1.4.5 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.resolvedoptions
|
// 1.4.5 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let pr be the this value.
|
// 1. Let pr be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
|
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
|
||||||
auto* plural_rules = TRY(typed_this_object(vm));
|
auto* plural_rules = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each row of Table 13, except the header row, in table order, do
|
// 4. For each row of Table 13, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -69,14 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format_to_parts)
|
||||||
// 17.3.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
|
// 17.3.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let relativeTimeFormat be the this value.
|
// 1. Let relativeTimeFormat be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
|
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
|
||||||
auto* relative_time_format = TRY(typed_this_object(vm));
|
auto* relative_time_format = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each row of Table 15, except the header row, in table order, do
|
// 4. For each row of Table 15, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
|
|
@ -34,14 +34,14 @@ void SegmenterPrototype::initialize(Realm& realm)
|
||||||
// 18.3.4 Intl.Segmenter.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.resolvedoptions
|
// 18.3.4 Intl.Segmenter.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let segmenter be the this value.
|
// 1. Let segmenter be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
|
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
|
||||||
auto* segmenter = TRY(typed_this_object(vm));
|
auto* segmenter = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* options = Object::create(realm, global_object.object_prototype());
|
auto* options = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each row of Table 16, except the header row, in table order, do
|
// 4. For each row of Table 16, except the header row, in table order, do
|
||||||
// a. Let p be the Property value of the current row.
|
// a. Let p be the Property value of the current row.
|
||||||
|
@ -58,7 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
|
||||||
// 18.3.3 Intl.Segmenter.prototype.segment ( string ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.segment
|
// 18.3.3 Intl.Segmenter.prototype.segment ( string ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.segment
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
|
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let segmenter be the this value.
|
// 1. Let segmenter be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
|
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
|
||||||
|
|
|
@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::containing)
|
||||||
// 18.5.2.2 %SegmentsPrototype% [ @@iterator ] ( ), https://tc39.es/ecma402/#sec-%segmentsprototype%-@@iterator
|
// 18.5.2.2 %SegmentsPrototype% [ @@iterator ] ( ), https://tc39.es/ecma402/#sec-%segmentsprototype%-@@iterator
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
|
JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let segments be the this value.
|
// 1. Let segments be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
|
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
|
||||||
|
|
|
@ -391,7 +391,7 @@ String JSONObject::quote_json_string(String string)
|
||||||
// 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse
|
// 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse
|
||||||
JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
|
JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto string = TRY(vm.argument(0).to_string(vm));
|
auto string = TRY(vm.argument(0).to_string(vm));
|
||||||
auto reviver = vm.argument(1);
|
auto reviver = vm.argument(1);
|
||||||
|
@ -401,7 +401,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
|
||||||
return vm.throw_completion<SyntaxError>(ErrorType::JsonMalformed);
|
return vm.throw_completion<SyntaxError>(ErrorType::JsonMalformed);
|
||||||
Value unfiltered = parse_json_value(vm, json.value());
|
Value unfiltered = parse_json_value(vm, json.value());
|
||||||
if (reviver.is_function()) {
|
if (reviver.is_function()) {
|
||||||
auto* root = Object::create(realm, global_object.object_prototype());
|
auto* root = Object::create(realm, realm.global_object().object_prototype());
|
||||||
auto root_name = String::empty();
|
auto root_name = String::empty();
|
||||||
MUST(root->create_data_property_or_throw(root_name, unfiltered));
|
MUST(root->create_data_property_or_throw(root_name, unfiltered));
|
||||||
return internalize_json_property(vm, root, root_name, reviver.as_function());
|
return internalize_json_property(vm, root, root_name, reviver.as_function());
|
||||||
|
|
|
@ -30,7 +30,7 @@ void MapIteratorPrototype::initialize(Realm& realm)
|
||||||
// 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next
|
// 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next
|
||||||
JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* map_iterator = TRY(typed_this_value(vm));
|
auto* map_iterator = TRY(typed_this_value(vm));
|
||||||
if (map_iterator->done())
|
if (map_iterator->done())
|
||||||
|
|
|
@ -57,7 +57,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::delete_)
|
||||||
// 24.1.3.4 Map.prototype.entries ( ), https://tc39.es/ecma262/#sec-map.prototype.entries
|
// 24.1.3.4 Map.prototype.entries ( ), https://tc39.es/ecma262/#sec-map.prototype.entries
|
||||||
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::entries)
|
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::entries)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* map = TRY(typed_this_object(vm));
|
auto* map = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::has)
|
||||||
// 24.1.3.8 Map.prototype.keys ( ), https://tc39.es/ecma262/#sec-map.prototype.keys
|
// 24.1.3.8 Map.prototype.keys ( ), https://tc39.es/ecma262/#sec-map.prototype.keys
|
||||||
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::keys)
|
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::keys)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* map = TRY(typed_this_object(vm));
|
auto* map = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::set)
|
||||||
// 24.1.3.11 Map.prototype.values ( ), https://tc39.es/ecma262/#sec-map.prototype.values
|
// 24.1.3.11 Map.prototype.values ( ), https://tc39.es/ecma262/#sec-map.prototype.values
|
||||||
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::values)
|
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::values)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* map = TRY(typed_this_object(vm));
|
auto* map = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,8 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc)
|
||||||
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(vm, global_object);
|
return MathObject::ceil(vm);
|
||||||
return MathObject::floor(vm, global_object);
|
return MathObject::floor(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 21.3.2.30 Math.sin ( x ), https://tc39.es/ecma262/#sec-math.sin
|
// 21.3.2.30 Math.sin ( x ), https://tc39.es/ecma262/#sec-math.sin
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace JS {
|
||||||
|
|
||||||
// 10.3.3 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix ] ] ] ), https://tc39.es/ecma262/#sec-createbuiltinfunction
|
// 10.3.3 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix ] ] ] ), https://tc39.es/ecma262/#sec-createbuiltinfunction
|
||||||
// NOTE: This doesn't consider additionalInternalSlotsList, which is rarely used, and can either be implemented using only the `function` lambda, or needs a NativeFunction subclass.
|
// NOTE: This doesn't consider additionalInternalSlotsList, which is rarely used, and can either be implemented using only the `function` lambda, or needs a NativeFunction subclass.
|
||||||
NativeFunction* NativeFunction::create(Realm& allocating_realm, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> realm, Optional<Object*> prototype, Optional<StringView> const& prefix)
|
NativeFunction* NativeFunction::create(Realm& allocating_realm, Function<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> realm, Optional<Object*> prototype, Optional<StringView> const& prefix)
|
||||||
{
|
{
|
||||||
auto& vm = allocating_realm.vm();
|
auto& vm = allocating_realm.vm();
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Function<ThrowCo
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeFunction* NativeFunction::create(Realm& realm, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> function)
|
NativeFunction* NativeFunction::create(Realm& realm, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&)> function)
|
||||||
{
|
{
|
||||||
return realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.global_object().function_prototype());
|
return realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.global_object().function_prototype());
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeFunction::NativeFunction(Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, Object* prototype, Realm& realm)
|
NativeFunction::NativeFunction(Function<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm)
|
||||||
: FunctionObject(realm, prototype)
|
: FunctionObject(realm, prototype)
|
||||||
, m_native_function(move(native_function))
|
, m_native_function(move(native_function))
|
||||||
, m_realm(&realm)
|
, m_realm(&realm)
|
||||||
|
@ -73,7 +73,7 @@ NativeFunction::NativeFunction(Object& prototype)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeFunction::NativeFunction(FlyString name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, Object& prototype)
|
NativeFunction::NativeFunction(FlyString name, Function<ThrowCompletionOr<Value>(VM&)> native_function, Object& prototype)
|
||||||
: FunctionObject(prototype)
|
: FunctionObject(prototype)
|
||||||
, m_name(move(name))
|
, m_name(move(name))
|
||||||
, m_native_function(move(native_function))
|
, m_native_function(move(native_function))
|
||||||
|
@ -224,7 +224,7 @@ ThrowCompletionOr<Object*> NativeFunction::internal_construct(MarkedVector<Value
|
||||||
|
|
||||||
ThrowCompletionOr<Value> NativeFunction::call()
|
ThrowCompletionOr<Value> NativeFunction::call()
|
||||||
{
|
{
|
||||||
return m_native_function(vm(), global_object());
|
return m_native_function(vm());
|
||||||
}
|
}
|
||||||
|
|
||||||
ThrowCompletionOr<Object*> NativeFunction::construct(FunctionObject&)
|
ThrowCompletionOr<Object*> NativeFunction::construct(FunctionObject&)
|
||||||
|
|
|
@ -20,11 +20,11 @@ class NativeFunction : public FunctionObject {
|
||||||
JS_OBJECT(NativeFunction, FunctionObject);
|
JS_OBJECT(NativeFunction, FunctionObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static NativeFunction* create(Realm&, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
|
static NativeFunction* create(Realm&, Function<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
|
||||||
static NativeFunction* create(Realm&, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>);
|
static NativeFunction* create(Realm&, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&)>);
|
||||||
|
|
||||||
NativeFunction(Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>, Object* prototype, Realm& realm);
|
NativeFunction(Function<ThrowCompletionOr<Value>(VM&)>, Object* prototype, Realm& realm);
|
||||||
NativeFunction(FlyString name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>, Object& prototype);
|
NativeFunction(FlyString name, Function<ThrowCompletionOr<Value>(VM&)>, Object& prototype);
|
||||||
virtual void initialize(Realm&) override { }
|
virtual void initialize(Realm&) override { }
|
||||||
virtual ~NativeFunction() override = default;
|
virtual ~NativeFunction() override = default;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ private:
|
||||||
|
|
||||||
FlyString m_name;
|
FlyString m_name;
|
||||||
Optional<FlyString> m_initial_name; // [[InitialName]]
|
Optional<FlyString> m_initial_name; // [[InitialName]]
|
||||||
Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> m_native_function;
|
Function<ThrowCompletionOr<Value>(VM&)> m_native_function;
|
||||||
Realm* m_realm { nullptr };
|
Realm* m_realm { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -318,6 +318,8 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
|
||||||
// 19.2.1 Number.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
|
// 19.2.1 Number.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
|
||||||
JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string)
|
JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto locales = vm.argument(0);
|
auto locales = vm.argument(0);
|
||||||
auto options = vm.argument(1);
|
auto options = vm.argument(1);
|
||||||
|
|
||||||
|
@ -325,7 +327,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string)
|
||||||
auto number_value = TRY(this_number_value(vm, vm.this_value()));
|
auto number_value = TRY(this_number_value(vm, vm.this_value()));
|
||||||
|
|
||||||
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
|
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
|
||||||
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *global_object.intl_number_format_constructor(), locales, options)));
|
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), locales, options)));
|
||||||
|
|
||||||
// 3. Return ? FormatNumeric(numberFormat, x).
|
// 3. Return ? FormatNumeric(numberFormat, x).
|
||||||
// Note: Our implementation of FormatNumeric does not throw.
|
// Note: Our implementation of FormatNumeric does not throw.
|
||||||
|
|
|
@ -1073,7 +1073,7 @@ void Object::set_prototype(Object* new_prototype)
|
||||||
m_shape = shape.create_prototype_transition(new_prototype);
|
m_shape = shape.create_prototype_transition(new_prototype);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::define_native_accessor(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> getter, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> setter, PropertyAttributes attribute)
|
void Object::define_native_accessor(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&)> getter, Function<ThrowCompletionOr<Value>(VM&)> setter, PropertyAttributes attribute)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object().associated_realm();
|
auto& realm = *global_object().associated_realm();
|
||||||
FunctionObject* getter_function = nullptr;
|
FunctionObject* getter_function = nullptr;
|
||||||
|
@ -1123,7 +1123,7 @@ Value Object::get_without_side_effects(PropertyKey const& property_key) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::define_native_function(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute)
|
void Object::define_native_function(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&)> native_function, i32 length, PropertyAttributes attribute)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object().associated_realm();
|
auto& realm = *global_object().associated_realm();
|
||||||
auto* function = NativeFunction::create(realm, move(native_function), length, property_key, &realm);
|
auto* function = NativeFunction::create(realm, move(native_function), length, property_key, &realm);
|
||||||
|
|
|
@ -157,8 +157,8 @@ public:
|
||||||
void define_direct_property(PropertyKey const& property_key, Value value, PropertyAttributes attributes) { storage_set(property_key, { value, attributes }); };
|
void define_direct_property(PropertyKey const& property_key, Value value, PropertyAttributes attributes) { storage_set(property_key, { value, attributes }); };
|
||||||
void define_direct_accessor(PropertyKey const&, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes);
|
void define_direct_accessor(PropertyKey const&, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes);
|
||||||
|
|
||||||
void define_native_function(PropertyKey const&, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>, i32 length, PropertyAttributes attributes);
|
void define_native_function(PropertyKey const&, Function<ThrowCompletionOr<Value>(VM&)>, i32 length, PropertyAttributes attributes);
|
||||||
void define_native_accessor(PropertyKey const&, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> getter, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> setter, PropertyAttributes attributes);
|
void define_native_accessor(PropertyKey const&, Function<ThrowCompletionOr<Value>(VM&)> getter, Function<ThrowCompletionOr<Value>(VM&)> setter, PropertyAttributes attributes);
|
||||||
|
|
||||||
virtual bool is_function() const { return false; }
|
virtual bool is_function() const { return false; }
|
||||||
virtual bool is_typed_array() const { return false; }
|
virtual bool is_typed_array() const { return false; }
|
||||||
|
|
|
@ -111,7 +111,7 @@ static ThrowCompletionOr<MarkedVector<Value>> get_own_property_keys(VM& vm, Valu
|
||||||
// 20.1.2.10 Object.getOwnPropertyNames ( O ), https://tc39.es/ecma262/#sec-object.getownpropertynames
|
// 20.1.2.10 Object.getOwnPropertyNames ( O ), https://tc39.es/ecma262/#sec-object.getownpropertynames
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, string)).
|
// 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, string)).
|
||||||
return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::String)));
|
return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::String)));
|
||||||
|
@ -120,7 +120,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names)
|
||||||
// 20.1.2.11 Object.getOwnPropertySymbols ( O ), https://tc39.es/ecma262/#sec-object.getownpropertysymbols
|
// 20.1.2.11 Object.getOwnPropertySymbols ( O ), https://tc39.es/ecma262/#sec-object.getownpropertysymbols
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, symbol)).
|
// 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, symbol)).
|
||||||
return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::Symbol)));
|
return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::Symbol)));
|
||||||
|
@ -221,10 +221,10 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::freeze)
|
||||||
// 20.1.2.7 Object.fromEntries ( iterable ), https://tc39.es/ecma262/#sec-object.fromentries
|
// 20.1.2.7 Object.fromEntries ( iterable ), https://tc39.es/ecma262/#sec-object.fromentries
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto iterable = TRY(require_object_coercible(vm, vm.argument(0)));
|
auto iterable = TRY(require_object_coercible(vm, vm.argument(0)));
|
||||||
|
|
||||||
auto* object = Object::create(realm, global_object.object_prototype());
|
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
(void)TRY(get_iterator_values(vm, iterable, [&](Value iterator_value) -> Optional<Completion> {
|
(void)TRY(get_iterator_values(vm, iterable, [&](Value iterator_value) -> Optional<Completion> {
|
||||||
if (!iterator_value.is_object())
|
if (!iterator_value.is_object())
|
||||||
|
@ -266,7 +266,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor)
|
||||||
// 20.1.2.9 Object.getOwnPropertyDescriptors ( O ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
|
// 20.1.2.9 Object.getOwnPropertyDescriptors ( O ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let obj be ? ToObject(O).
|
// 1. Let obj be ? ToObject(O).
|
||||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||||
|
@ -275,7 +275,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
|
||||||
auto own_keys = TRY(object->internal_own_property_keys());
|
auto own_keys = TRY(object->internal_own_property_keys());
|
||||||
|
|
||||||
// 3. Let descriptors be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let descriptors be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* descriptors = Object::create(realm, global_object.object_prototype());
|
auto* descriptors = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. For each element key of ownKeys, do
|
// 4. For each element key of ownKeys, do
|
||||||
for (auto& key : own_keys) {
|
for (auto& key : own_keys) {
|
||||||
|
@ -330,7 +330,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is)
|
||||||
// 20.1.2.18 Object.keys ( O ), https://tc39.es/ecma262/#sec-object.keys
|
// 20.1.2.18 Object.keys ( O ), https://tc39.es/ecma262/#sec-object.keys
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||||
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Key));
|
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Key));
|
||||||
|
@ -340,7 +340,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
|
||||||
// 20.1.2.23 Object.values ( O ), https://tc39.es/ecma262/#sec-object.values
|
// 20.1.2.23 Object.values ( O ), https://tc39.es/ecma262/#sec-object.values
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||||
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Value));
|
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Value));
|
||||||
|
@ -350,7 +350,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
|
||||||
// 20.1.2.5 Object.entries ( O ), https://tc39.es/ecma262/#sec-object.entries
|
// 20.1.2.5 Object.entries ( O ), https://tc39.es/ecma262/#sec-object.entries
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||||
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::KeyAndValue));
|
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::KeyAndValue));
|
||||||
|
@ -360,7 +360,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
|
||||||
// 20.1.2.2 Object.create ( O, Properties ), https://tc39.es/ecma262/#sec-object.create
|
// 20.1.2.2 Object.create ( O, Properties ), https://tc39.es/ecma262/#sec-object.create
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create)
|
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto proto = vm.argument(0);
|
auto proto = vm.argument(0);
|
||||||
auto properties = vm.argument(1);
|
auto properties = vm.argument(1);
|
||||||
|
|
|
@ -71,10 +71,10 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
|
||||||
// 6. Set resolve.[[AlreadyResolved]] to alreadyResolved.
|
// 6. Set resolve.[[AlreadyResolved]] to alreadyResolved.
|
||||||
|
|
||||||
// 27.2.1.3.2 Promise Resolve Functions, https://tc39.es/ecma262/#sec-promise-resolve-functions
|
// 27.2.1.3.2 Promise Resolve Functions, https://tc39.es/ecma262/#sec-promise-resolve-functions
|
||||||
auto* resolve_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& global_object, auto& promise, auto& already_resolved) {
|
auto* resolve_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& promise, auto& already_resolved) {
|
||||||
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Resolve function was called", &promise);
|
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Resolve function was called", &promise);
|
||||||
|
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto resolution = vm.argument(0);
|
auto resolution = vm.argument(0);
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
|
||||||
// 11. Set reject.[[AlreadyResolved]] to alreadyResolved.
|
// 11. Set reject.[[AlreadyResolved]] to alreadyResolved.
|
||||||
|
|
||||||
// 27.2.1.3.1 Promise Reject Functions, https://tc39.es/ecma262/#sec-promise-reject-functions
|
// 27.2.1.3.1 Promise Reject Functions, https://tc39.es/ecma262/#sec-promise-reject-functions
|
||||||
auto* reject_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto&, auto& promise, auto& already_resolved) {
|
auto* reject_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& promise, auto& already_resolved) {
|
||||||
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Reject function was called", &promise);
|
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Reject function was called", &promise);
|
||||||
|
|
||||||
auto reason = vm.argument(0);
|
auto reason = vm.argument(0);
|
||||||
|
|
|
@ -38,6 +38,8 @@ void PromisePrototype::initialize(Realm& realm)
|
||||||
// 27.2.5.4 Promise.prototype.then ( onFulfilled, onRejected ), https://tc39.es/ecma262/#sec-promise.prototype.then
|
// 27.2.5.4 Promise.prototype.then ( onFulfilled, onRejected ), https://tc39.es/ecma262/#sec-promise.prototype.then
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then)
|
JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto on_fulfilled = vm.argument(0);
|
auto on_fulfilled = vm.argument(0);
|
||||||
auto on_rejected = vm.argument(1);
|
auto on_rejected = vm.argument(1);
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then)
|
||||||
auto* promise = TRY(typed_this_object(vm));
|
auto* promise = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
|
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
|
||||||
auto* constructor = TRY(species_constructor(vm, *promise, *global_object.promise_constructor()));
|
auto* constructor = TRY(species_constructor(vm, *promise, *realm.global_object().promise_constructor()));
|
||||||
|
|
||||||
// 4. Let resultCapability be ? NewPromiseCapability(C).
|
// 4. Let resultCapability be ? NewPromiseCapability(C).
|
||||||
auto result_capability = TRY(new_promise_capability(vm, constructor));
|
auto result_capability = TRY(new_promise_capability(vm, constructor));
|
||||||
|
@ -70,7 +72,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::catch_)
|
||||||
// 27.2.5.3 Promise.prototype.finally ( onFinally ), https://tc39.es/ecma262/#sec-promise.prototype.finally
|
// 27.2.5.3 Promise.prototype.finally ( onFinally ), https://tc39.es/ecma262/#sec-promise.prototype.finally
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto on_finally = vm.argument(0);
|
auto on_finally = vm.argument(0);
|
||||||
|
|
||||||
|
@ -82,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, promise.to_string_without_side_effects());
|
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, promise.to_string_without_side_effects());
|
||||||
|
|
||||||
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
|
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
|
||||||
auto* constructor = TRY(species_constructor(vm, promise.as_object(), *global_object.promise_constructor()));
|
auto* constructor = TRY(species_constructor(vm, promise.as_object(), *realm.global_object().promise_constructor()));
|
||||||
|
|
||||||
// 4. Assert: IsConstructor(C) is true.
|
// 4. Assert: IsConstructor(C) is true.
|
||||||
VERIFY(constructor);
|
VERIFY(constructor);
|
||||||
|
@ -101,8 +103,8 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
// 6. Else,
|
// 6. Else,
|
||||||
else {
|
else {
|
||||||
// a. Let thenFinallyClosure be a new Abstract Closure with parameters (value) that captures onFinally and C and performs the following steps when called:
|
// a. Let thenFinallyClosure be a new Abstract Closure with parameters (value) that captures onFinally and C and performs the following steps when called:
|
||||||
auto then_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
auto then_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm) -> ThrowCompletionOr<Value> {
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
|
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
|
||||||
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
|
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
|
||||||
auto value = vm.argument(0);
|
auto value = vm.argument(0);
|
||||||
|
@ -114,7 +116,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
auto* promise = TRY(promise_resolve(vm, constructor, result));
|
auto* promise = TRY(promise_resolve(vm, constructor, result));
|
||||||
|
|
||||||
// iii. Let returnValue be a new Abstract Closure with no parameters that captures value and performs the following steps when called:
|
// iii. Let returnValue be a new Abstract Closure with no parameters that captures value and performs the following steps when called:
|
||||||
auto return_value = [value_handle = make_handle(value)](auto&, auto&) -> ThrowCompletionOr<Value> {
|
auto return_value = [value_handle = make_handle(value)](auto&) -> ThrowCompletionOr<Value> {
|
||||||
// 1. Return value.
|
// 1. Return value.
|
||||||
return value_handle.value();
|
return value_handle.value();
|
||||||
};
|
};
|
||||||
|
@ -130,8 +132,8 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
then_finally = NativeFunction::create(realm, move(then_finally_closure), 1, "");
|
then_finally = NativeFunction::create(realm, move(then_finally_closure), 1, "");
|
||||||
|
|
||||||
// c. Let catchFinallyClosure be a new Abstract Closure with parameters (reason) that captures onFinally and C and performs the following steps when called:
|
// c. Let catchFinallyClosure be a new Abstract Closure with parameters (reason) that captures onFinally and C and performs the following steps when called:
|
||||||
auto catch_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
auto catch_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm) -> ThrowCompletionOr<Value> {
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
|
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
|
||||||
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
|
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
|
||||||
auto reason = vm.argument(0);
|
auto reason = vm.argument(0);
|
||||||
|
@ -143,7 +145,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
auto* promise = TRY(promise_resolve(vm, constructor, result));
|
auto* promise = TRY(promise_resolve(vm, constructor, result));
|
||||||
|
|
||||||
// iii. Let throwReason be a new Abstract Closure with no parameters that captures reason and performs the following steps when called:
|
// iii. Let throwReason be a new Abstract Closure with no parameters that captures reason and performs the following steps when called:
|
||||||
auto throw_reason = [reason_handle = make_handle(reason)](auto&, auto&) -> ThrowCompletionOr<Value> {
|
auto throw_reason = [reason_handle = make_handle(reason)](auto&) -> ThrowCompletionOr<Value> {
|
||||||
// 1. Return ThrowCompletion(reason).
|
// 1. Return ThrowCompletion(reason).
|
||||||
return throw_completion(reason_handle.value());
|
return throw_completion(reason_handle.value());
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ ThrowCompletionOr<PromiseCapability> new_promise_capability(VM& vm, Value constr
|
||||||
} promise_capability_functions;
|
} promise_capability_functions;
|
||||||
|
|
||||||
// 4. Let executorClosure be a new Abstract Closure with parameters (resolve, reject) that captures promiseCapability and performs the following steps when called:
|
// 4. Let executorClosure be a new Abstract Closure with parameters (resolve, reject) that captures promiseCapability and performs the following steps when called:
|
||||||
auto executor_closure = [&promise_capability_functions](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
auto executor_closure = [&promise_capability_functions](auto& vm) -> ThrowCompletionOr<Value> {
|
||||||
auto resolve = vm.argument(0);
|
auto resolve = vm.argument(0);
|
||||||
auto reject = vm.argument(1);
|
auto reject = vm.argument(1);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,7 @@ void PromiseResolvingFunction::initialize(Realm& realm)
|
||||||
|
|
||||||
ThrowCompletionOr<Value> PromiseResolvingFunction::call()
|
ThrowCompletionOr<Value> PromiseResolvingFunction::call()
|
||||||
{
|
{
|
||||||
return m_native_function(vm(), global_object(), m_promise, m_already_resolved);
|
return m_native_function(vm(), m_promise, m_already_resolved);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PromiseResolvingFunction::visit_edges(Cell::Visitor& visitor)
|
void PromiseResolvingFunction::visit_edges(Cell::Visitor& visitor)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +26,7 @@ class PromiseResolvingFunction final : public NativeFunction {
|
||||||
JS_OBJECT(PromiseResolvingFunction, NativeFunction);
|
JS_OBJECT(PromiseResolvingFunction, NativeFunction);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using FunctionType = Function<ThrowCompletionOr<Value>(VM&, GlobalObject&, Promise&, AlreadyResolved&)>;
|
using FunctionType = Function<ThrowCompletionOr<Value>(VM&, Promise&, AlreadyResolved&)>;
|
||||||
|
|
||||||
static PromiseResolvingFunction* create(Realm&, Promise&, AlreadyResolved&, FunctionType);
|
static PromiseResolvingFunction* create(Realm&, Promise&, AlreadyResolved&, FunctionType);
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable)
|
||||||
auto* proxy = TRY(proxy_create(vm, vm.argument(0), vm.argument(1)));
|
auto* proxy = TRY(proxy_create(vm, vm.argument(0), vm.argument(1)));
|
||||||
|
|
||||||
// 2. Let revokerClosure be a new Abstract Closure with no parameters that captures nothing and performs the following steps when called:
|
// 2. Let revokerClosure be a new Abstract Closure with no parameters that captures nothing and performs the following steps when called:
|
||||||
auto revoker_closure = [proxy_handle = make_handle(proxy)](auto&, auto&) -> ThrowCompletionOr<Value> {
|
auto revoker_closure = [proxy_handle = make_handle(proxy)](auto&) -> ThrowCompletionOr<Value> {
|
||||||
// a. Let F be the active function object.
|
// a. Let F be the active function object.
|
||||||
|
|
||||||
// b. Let p be F.[[RevocableProxy]].
|
// b. Let p be F.[[RevocableProxy]].
|
||||||
|
@ -87,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable)
|
||||||
auto* revoker = NativeFunction::create(realm, move(revoker_closure), 0, "");
|
auto* revoker = NativeFunction::create(realm, move(revoker_closure), 0, "");
|
||||||
|
|
||||||
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
|
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* result = Object::create(realm, global_object.object_prototype());
|
auto* result = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 6. Perform ! CreateDataPropertyOrThrow(result, "proxy", p).
|
// 6. Perform ! CreateDataPropertyOrThrow(result, "proxy", p).
|
||||||
MUST(result->create_data_property_or_throw(vm.names.proxy, proxy));
|
MUST(result->create_data_property_or_throw(vm.names.proxy, proxy));
|
||||||
|
|
|
@ -215,7 +215,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible)
|
||||||
// 28.1.10 Reflect.ownKeys ( target ), https://tc39.es/ecma262/#sec-reflect.ownkeys
|
// 28.1.10 Reflect.ownKeys ( target ), https://tc39.es/ecma262/#sec-reflect.ownkeys
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys)
|
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto target = vm.argument(0);
|
auto target = vm.argument(0);
|
||||||
|
|
||||||
|
|
|
@ -412,12 +412,13 @@ size_t advance_string_index(Utf16View const& string, size_t index, bool unicode)
|
||||||
#define __JS_ENUMERATE(flagName, flag_name, flag_char) \
|
#define __JS_ENUMERATE(flagName, flag_name, flag_char) \
|
||||||
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flag_name) \
|
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flag_name) \
|
||||||
{ \
|
{ \
|
||||||
|
auto& realm = *vm.current_realm(); \
|
||||||
/* 1. If Type(R) is not Object, throw a TypeError exception. */ \
|
/* 1. If Type(R) is not Object, throw a TypeError exception. */ \
|
||||||
auto* regexp_object = TRY(this_object(vm)); \
|
auto* regexp_object = TRY(this_object(vm)); \
|
||||||
/* 2. If R does not have an [[OriginalFlags]] internal slot, then */ \
|
/* 2. If R does not have an [[OriginalFlags]] internal slot, then */ \
|
||||||
if (!is<RegExpObject>(regexp_object)) { \
|
if (!is<RegExpObject>(regexp_object)) { \
|
||||||
/* a. If SameValue(R, %RegExp.prototype%) is true, return undefined. */ \
|
/* a. If SameValue(R, %RegExp.prototype%) is true, return undefined. */ \
|
||||||
if (same_value(regexp_object, global_object.regexp_prototype())) \
|
if (same_value(regexp_object, realm.global_object().regexp_prototype())) \
|
||||||
return js_undefined(); \
|
return js_undefined(); \
|
||||||
/* b. Otherwise, throw a TypeError exception. */ \
|
/* b. Otherwise, throw a TypeError exception. */ \
|
||||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "RegExp"); \
|
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "RegExp"); \
|
||||||
|
@ -487,7 +488,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flags)
|
||||||
// With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp.prototype-%2540%2540match
|
// With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp.prototype-%2540%2540match
|
||||||
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
|
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let rx be the this value.
|
// 1. Let rx be the this value.
|
||||||
// 2. If Type(rx) is not Object, throw a TypeError exception.
|
// 2. If Type(rx) is not Object, throw a TypeError exception.
|
||||||
|
@ -566,7 +567,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
|
||||||
// With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp-prototype-matchall
|
// With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp-prototype-matchall
|
||||||
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
|
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let R be the this value.
|
// 1. Let R be the this value.
|
||||||
// 2. If Type(R) is not Object, throw a TypeError exception.
|
// 2. If Type(R) is not Object, throw a TypeError exception.
|
||||||
|
@ -576,7 +577,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
|
||||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||||
|
|
||||||
// 4. Let C be ? SpeciesConstructor(R, %RegExp%).
|
// 4. Let C be ? SpeciesConstructor(R, %RegExp%).
|
||||||
auto* constructor = TRY(species_constructor(vm, *regexp_object, *global_object.regexp_constructor()));
|
auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.global_object().regexp_constructor()));
|
||||||
|
|
||||||
// 5. Let flags be ? ToString(? Get(R, "flags")).
|
// 5. Let flags be ? ToString(? Get(R, "flags")).
|
||||||
auto flags_value = TRY(regexp_object->get(vm.names.flags));
|
auto flags_value = TRY(regexp_object->get(vm.names.flags));
|
||||||
|
@ -842,6 +843,8 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_search)
|
||||||
// 22.2.5.13 get RegExp.prototype.source, https://tc39.es/ecma262/#sec-get-regexp.prototype.source
|
// 22.2.5.13 get RegExp.prototype.source, https://tc39.es/ecma262/#sec-get-regexp.prototype.source
|
||||||
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source)
|
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let R be the this value.
|
// 1. Let R be the this value.
|
||||||
// 2. If Type(R) is not Object, throw a TypeError exception.
|
// 2. If Type(R) is not Object, throw a TypeError exception.
|
||||||
auto* regexp_object = TRY(this_object(vm));
|
auto* regexp_object = TRY(this_object(vm));
|
||||||
|
@ -849,7 +852,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source)
|
||||||
// 3. If R does not have an [[OriginalSource]] internal slot, then
|
// 3. If R does not have an [[OriginalSource]] internal slot, then
|
||||||
if (!is<RegExpObject>(regexp_object)) {
|
if (!is<RegExpObject>(regexp_object)) {
|
||||||
// a. If SameValue(R, %RegExp.prototype%) is true, return "(?:)".
|
// a. If SameValue(R, %RegExp.prototype%) is true, return "(?:)".
|
||||||
if (same_value(regexp_object, global_object.regexp_prototype()))
|
if (same_value(regexp_object, realm.global_object().regexp_prototype()))
|
||||||
return js_string(vm, "(?:)");
|
return js_string(vm, "(?:)");
|
||||||
|
|
||||||
// b. Otherwise, throw a TypeError exception.
|
// b. Otherwise, throw a TypeError exception.
|
||||||
|
@ -866,7 +869,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source)
|
||||||
// 22.2.5.14 RegExp.prototype [ @@split ] ( string, limit ), https://tc39.es/ecma262/#sec-regexp.prototype-@@split
|
// 22.2.5.14 RegExp.prototype [ @@split ] ( string, limit ), https://tc39.es/ecma262/#sec-regexp.prototype-@@split
|
||||||
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let rx be the this value.
|
// 1. Let rx be the this value.
|
||||||
// 2. If Type(rx) is not Object, throw a TypeError exception.
|
// 2. If Type(rx) is not Object, throw a TypeError exception.
|
||||||
|
@ -876,7 +879,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
||||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||||
|
|
||||||
// 4. Let C be ? SpeciesConstructor(rx, %RegExp%).
|
// 4. Let C be ? SpeciesConstructor(rx, %RegExp%).
|
||||||
auto* constructor = TRY(species_constructor(vm, *regexp_object, *global_object.regexp_constructor()));
|
auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.global_object().regexp_constructor()));
|
||||||
|
|
||||||
// 5. Let flags be ? ToString(? Get(rx, "flags")).
|
// 5. Let flags be ? ToString(? Get(rx, "flags")).
|
||||||
auto flags_value = TRY(regexp_object->get(vm.names.flags));
|
auto flags_value = TRY(regexp_object->get(vm.names.flags));
|
||||||
|
|
|
@ -32,7 +32,7 @@ void SetIteratorPrototype::initialize(Realm& realm)
|
||||||
// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next
|
// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* set_iterator = TRY(typed_this_value(vm));
|
auto* set_iterator = TRY(typed_this_value(vm));
|
||||||
if (set_iterator->done())
|
if (set_iterator->done())
|
||||||
|
|
|
@ -70,7 +70,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_)
|
||||||
// 24.2.3.5 Set.prototype.entries ( ), https://tc39.es/ecma262/#sec-set.prototype.entries
|
// 24.2.3.5 Set.prototype.entries ( ), https://tc39.es/ecma262/#sec-set.prototype.entries
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries)
|
JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* set = TRY(typed_this_object(vm));
|
auto* set = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has)
|
||||||
// 24.2.3.10 Set.prototype.values ( ), https://tc39.es/ecma262/#sec-set.prototype.values
|
// 24.2.3.10 Set.prototype.values ( ), https://tc39.es/ecma262/#sec-set.prototype.values
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values)
|
JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* set = TRY(typed_this_object(vm));
|
auto* set = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
|
|
|
@ -232,7 +232,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, String specifier_stri
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
|
|
||||||
// 9. Let steps be the steps of an ExportGetter function as described below.
|
// 9. Let steps be the steps of an ExportGetter function as described below.
|
||||||
auto steps = [string = move(export_name_string)](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
auto steps = [string = move(export_name_string)](auto& vm) -> ThrowCompletionOr<Value> {
|
||||||
// 1. Assert: exports is a module namespace exotic object.
|
// 1. Assert: exports is a module namespace exotic object.
|
||||||
VERIFY(vm.argument(0).is_object());
|
VERIFY(vm.argument(0).is_object());
|
||||||
auto& exports = vm.argument(0).as_object();
|
auto& exports = vm.argument(0).as_object();
|
||||||
|
@ -271,7 +271,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, String specifier_stri
|
||||||
|
|
||||||
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
|
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
|
||||||
// Throw a nicer TypeError forwarding the import error message instead (we know the argument is an Error object).
|
// Throw a nicer TypeError forwarding the import error message instead (we know the argument is an Error object).
|
||||||
auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm) -> ThrowCompletionOr<Value> {
|
||||||
return vm.template throw_completion<TypeError>(vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string());
|
return vm.template throw_completion<TypeError>(vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -648,7 +648,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
|
||||||
// 22.1.3.22 String.prototype.split ( separator, limit ), https://tc39.es/ecma262/#sec-string.prototype.split
|
// 22.1.3.22 String.prototype.split ( separator, limit ), https://tc39.es/ecma262/#sec-string.prototype.split
|
||||||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto object = TRY(require_object_coercible(vm, vm.this_value()));
|
auto object = TRY(require_object_coercible(vm, vm.this_value()));
|
||||||
|
|
||||||
|
@ -771,7 +771,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at)
|
||||||
// 22.1.3.34 String.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-string.prototype-@@iterator
|
// 22.1.3.34 String.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-string.prototype-@@iterator
|
||||||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
|
auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
|
||||||
auto string = TRY(this_object.to_string(vm));
|
auto string = TRY(this_object.to_string(vm));
|
||||||
|
@ -1076,6 +1076,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::sup)
|
||||||
// 19.1.1 String.prototype.localeCompare ( that [ , locales [ , options ] ] ), https://tc39.es/ecma402/#sup-String.prototype.localeCompare
|
// 19.1.1 String.prototype.localeCompare ( that [ , locales [ , options ] ] ), https://tc39.es/ecma402/#sup-String.prototype.localeCompare
|
||||||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::locale_compare)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::locale_compare)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let O be ? RequireObjectCoercible(this value).
|
// 1. Let O be ? RequireObjectCoercible(this value).
|
||||||
auto object = TRY(require_object_coercible(vm, vm.this_value()));
|
auto object = TRY(require_object_coercible(vm, vm.this_value()));
|
||||||
|
|
||||||
|
@ -1086,7 +1088,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::locale_compare)
|
||||||
auto that_value = TRY(vm.argument(0).to_string(vm));
|
auto that_value = TRY(vm.argument(0).to_string(vm));
|
||||||
|
|
||||||
// 4. Let collator be ? Construct(%Collator%, « locales, options »).
|
// 4. Let collator be ? Construct(%Collator%, « locales, options »).
|
||||||
auto* collator = TRY(construct(vm, *global_object.intl_collator_constructor(), vm.argument(1), vm.argument(2)));
|
auto* collator = TRY(construct(vm, *realm.global_object().intl_collator_constructor(), vm.argument(1), vm.argument(2)));
|
||||||
|
|
||||||
// 5. Return CompareStrings(collator, S, thatValue).
|
// 5. Return CompareStrings(collator, S, thatValue).
|
||||||
return Intl::compare_strings(static_cast<Intl::Collator&>(*collator), Utf8View(string), Utf8View(that_value));
|
return Intl::compare_strings(static_cast<Intl::Collator&>(*collator), Utf8View(string), Utf8View(that_value));
|
||||||
|
|
|
@ -54,7 +54,7 @@ ThrowCompletionOr<Object*> SymbolConstructor::construct(FunctionObject&)
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_)
|
JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_)
|
||||||
{
|
{
|
||||||
auto description = TRY(vm.argument(0).to_string(vm));
|
auto description = TRY(vm.argument(0).to_string(vm));
|
||||||
return global_object.vm().get_global_symbol(description);
|
return vm.get_global_symbol(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 20.4.2.6 Symbol.keyFor ( sym ), https://tc39.es/ecma262/#sec-symbol.keyfor
|
// 20.4.2.6 Symbol.keyFor ( sym ), https://tc39.es/ecma262/#sec-symbol.keyfor
|
||||||
|
|
|
@ -501,7 +501,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::in_leap_year)
|
||||||
// NOTE: This is the minimum fields implementation for engines without ECMA-402.
|
// NOTE: This is the minimum fields implementation for engines without ECMA-402.
|
||||||
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
|
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto fields = vm.argument(0);
|
auto fields = vm.argument(0);
|
||||||
|
|
||||||
|
|
|
@ -322,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::subtract)
|
||||||
// 7.3.20 Temporal.Duration.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.round
|
// 7.3.20 Temporal.Duration.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.round
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
|
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let duration be the this value.
|
// 1. Let duration be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
||||||
|
@ -446,7 +446,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
|
||||||
// 7.3.21 Temporal.Duration.prototype.total ( totalOf ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.total
|
// 7.3.21 Temporal.Duration.prototype.total ( totalOf ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.total
|
||||||
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
|
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let duration be the this value.
|
// 1. Let duration be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
||||||
|
|
|
@ -175,7 +175,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::since)
|
||||||
// 8.3.11 Temporal.Instant.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.round
|
// 8.3.11 Temporal.Instant.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.round
|
||||||
JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round)
|
JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let instant be the this value.
|
// 1. Let instant be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
|
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
|
||||||
|
|
|
@ -319,14 +319,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_month_day)
|
||||||
// 3.3.18 Temporal.PlainDate.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.getisofields
|
// 3.3.18 Temporal.PlainDate.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.getisofields
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::get_iso_fields)
|
JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::get_iso_fields)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let temporalDate be the this value.
|
// 1. Let temporalDate be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(temporalDate, [[InitializedTemporalDate]]).
|
// 2. Perform ? RequireInternalSlot(temporalDate, [[InitializedTemporalDate]]).
|
||||||
auto* temporal_date = TRY(typed_this_object(vm));
|
auto* temporal_date = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* fields = Object::create(realm, global_object.object_prototype());
|
auto* fields = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalDate.[[Calendar]]).
|
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalDate.[[Calendar]]).
|
||||||
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_date->calendar())));
|
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_date->calendar())));
|
||||||
|
|
|
@ -517,7 +517,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::since)
|
||||||
// 5.3.30 Temporal.PlainDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.round
|
// 5.3.30 Temporal.PlainDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.round
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::round)
|
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::round)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let dateTime be the this value.
|
// 1. Let dateTime be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
||||||
|
@ -728,14 +728,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_time)
|
||||||
// 5.3.41 Temporal.PlainDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.getisofields
|
// 5.3.41 Temporal.PlainDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.getisofields
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::get_iso_fields)
|
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::get_iso_fields)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let dateTime be the this value.
|
// 1. Let dateTime be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
||||||
auto* date_time = TRY(typed_this_object(vm));
|
auto* date_time = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* fields = Object::create(realm, global_object.object_prototype());
|
auto* fields = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", dateTime.[[Calendar]]).
|
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", dateTime.[[Calendar]]).
|
||||||
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&date_time->calendar())));
|
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&date_time->calendar())));
|
||||||
|
|
|
@ -202,7 +202,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::value_of)
|
||||||
// 10.3.12 Temporal.PlainMonthDay.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.toplaindate
|
// 10.3.12 Temporal.PlainMonthDay.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.toplaindate
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
|
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto item = vm.argument(0);
|
auto item = vm.argument(0);
|
||||||
|
|
||||||
|
@ -253,14 +253,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
|
||||||
// 10.3.13 Temporal.PlainMonthDay.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.getisofields
|
// 10.3.13 Temporal.PlainMonthDay.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.getisofields
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields)
|
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let monthDay be the this value.
|
// 1. Let monthDay be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
// 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
||||||
auto* month_day = TRY(typed_this_object(vm));
|
auto* month_day = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* fields = Object::create(realm, global_object.object_prototype());
|
auto* fields = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", monthDay.[[Calendar]]).
|
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", monthDay.[[Calendar]]).
|
||||||
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&month_day->calendar())));
|
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&month_day->calendar())));
|
||||||
|
|
|
@ -265,7 +265,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::since)
|
||||||
// 4.3.15 Temporal.PlainTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.round
|
// 4.3.15 Temporal.PlainTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.round
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round)
|
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let temporalTime be the this value.
|
// 1. Let temporalTime be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
||||||
|
@ -418,14 +418,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_zoned_date_time)
|
||||||
// 4.3.19 Temporal.PlainTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.getisofields
|
// 4.3.19 Temporal.PlainTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.getisofields
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::get_iso_fields)
|
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::get_iso_fields)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let temporalTime be the this value.
|
// 1. Let temporalTime be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
||||||
auto* temporal_time = TRY(typed_this_object(vm));
|
auto* temporal_time = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* fields = Object::create(realm, global_object.object_prototype());
|
auto* fields = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalTime.[[Calendar]]).
|
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalTime.[[Calendar]]).
|
||||||
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_time->calendar())));
|
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_time->calendar())));
|
||||||
|
|
|
@ -369,7 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::value_of)
|
||||||
// 9.3.21 Temporal.PlainYearMonth.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.toplaindate
|
// 9.3.21 Temporal.PlainYearMonth.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.toplaindate
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
|
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto item = vm.argument(0);
|
auto item = vm.argument(0);
|
||||||
|
|
||||||
|
@ -420,14 +420,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
|
||||||
// 9.3.22 Temporal.PlainYearMonth.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.getisofields
|
// 9.3.22 Temporal.PlainYearMonth.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.getisofields
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields)
|
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let yearMonth be the this value.
|
// 1. Let yearMonth be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
// 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
||||||
auto* year_month = TRY(typed_this_object(vm));
|
auto* year_month = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* fields = Object::create(realm, global_object.object_prototype());
|
auto* fields = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", yearMonth.[[Calendar]]).
|
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", yearMonth.[[Calendar]]).
|
||||||
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&year_month->calendar())));
|
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&year_month->calendar())));
|
||||||
|
|
|
@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_instant_for)
|
||||||
// 11.4.8 Temporal.TimeZone.prototype.getPossibleInstantsFor ( dateTime ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getpossibleinstantsfor
|
// 11.4.8 Temporal.TimeZone.prototype.getPossibleInstantsFor ( dateTime ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getpossibleinstantsfor
|
||||||
JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
|
JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let timeZone be the this value.
|
// 1. Let timeZone be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimezone]]).
|
// 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimezone]]).
|
||||||
|
|
|
@ -951,7 +951,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::since)
|
||||||
// 6.3.39 Temporal.ZonedDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.round
|
// 6.3.39 Temporal.ZonedDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.round
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
|
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let zonedDateTime be the this value.
|
// 1. Let zonedDateTime be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
|
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
|
||||||
|
@ -1284,14 +1284,14 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_month_day)
|
||||||
// 6.3.52 Temporal.ZonedDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.getisofields
|
// 6.3.52 Temporal.ZonedDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.getisofields
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields)
|
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. Let zonedDateTime be the this value.
|
// 1. Let zonedDateTime be the this value.
|
||||||
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
|
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
|
||||||
auto* zoned_date_time = TRY(typed_this_object(vm));
|
auto* zoned_date_time = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
|
||||||
auto* fields = Object::create(realm, global_object.object_prototype());
|
auto* fields = Object::create(realm, realm.global_object().object_prototype());
|
||||||
|
|
||||||
// 4. Let timeZone be zonedDateTime.[[TimeZone]].
|
// 4. Let timeZone be zonedDateTime.[[TimeZone]].
|
||||||
auto& time_zone = zoned_date_time->time_zone();
|
auto& time_zone = zoned_date_time->time_zone();
|
||||||
|
|
|
@ -386,7 +386,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::copy_within)
|
||||||
// 23.2.3.7 %TypedArray%.prototype.entries ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.entries
|
// 23.2.3.7 %TypedArray%.prototype.entries ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.entries
|
||||||
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::entries)
|
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::entries)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* typed_array = TRY(validate_typed_array_from_this(vm));
|
auto* typed_array = TRY(validate_typed_array_from_this(vm));
|
||||||
return ArrayIterator::create(realm, typed_array, Object::PropertyKind::KeyAndValue);
|
return ArrayIterator::create(realm, typed_array, Object::PropertyKind::KeyAndValue);
|
||||||
|
@ -688,7 +688,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::join)
|
||||||
// 23.2.3.19 %TypedArray%.prototype.keys ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.keys
|
// 23.2.3.19 %TypedArray%.prototype.keys ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.keys
|
||||||
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::keys)
|
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::keys)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* typed_array = TRY(validate_typed_array_from_this(vm));
|
auto* typed_array = TRY(validate_typed_array_from_this(vm));
|
||||||
return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Key);
|
return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Key);
|
||||||
|
@ -1622,7 +1622,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::with)
|
||||||
// 23.2.3.33 %TypedArray%.prototype.values ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.values
|
// 23.2.3.33 %TypedArray%.prototype.values ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.values
|
||||||
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::values)
|
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::values)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* typed_array = TRY(typed_array_from_this(vm));
|
auto* typed_array = TRY(typed_array_from_this(vm));
|
||||||
return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Value);
|
return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Value);
|
||||||
|
|
|
@ -83,10 +83,10 @@ VM::VM(OwnPtr<CustomData> custom_data)
|
||||||
promise->reject(Error::create(realm, ErrorType::DynamicImportNotAllowed.message()));
|
promise->reject(Error::create(realm, ErrorType::DynamicImportNotAllowed.message()));
|
||||||
|
|
||||||
promise->perform_then(
|
promise->perform_then(
|
||||||
NativeFunction::create(realm, "", [](auto&, auto&) -> ThrowCompletionOr<Value> {
|
NativeFunction::create(realm, "", [](auto&) -> ThrowCompletionOr<Value> {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}),
|
}),
|
||||||
NativeFunction::create(realm, "", [reject = make_handle(promise_capability.reject)](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
NativeFunction::create(realm, "", [reject = make_handle(promise_capability.reject)](auto& vm) -> ThrowCompletionOr<Value> {
|
||||||
auto error = vm.argument(0);
|
auto error = vm.argument(0);
|
||||||
|
|
||||||
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
|
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
|
||||||
|
@ -1037,7 +1037,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
|
||||||
auto& realm = *current_realm();
|
auto& realm = *current_realm();
|
||||||
|
|
||||||
// 1. Let fulfilledClosure be a new Abstract Closure with parameters (result) that captures referencingScriptOrModule, specifier, and promiseCapability and performs the following steps when called:
|
// 1. Let fulfilledClosure be a new Abstract Closure with parameters (result) that captures referencingScriptOrModule, specifier, and promiseCapability and performs the following steps when called:
|
||||||
auto fulfilled_closure = [referencing_script_or_module, module_request = move(module_request), resolve_function = make_handle(promise_capability.resolve), reject_function = make_handle(promise_capability.reject)](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
auto fulfilled_closure = [referencing_script_or_module, module_request = move(module_request), resolve_function = make_handle(promise_capability.resolve), reject_function = make_handle(promise_capability.reject)](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
auto result = vm.argument(0);
|
auto result = vm.argument(0);
|
||||||
// a. Assert: result is undefined.
|
// a. Assert: result is undefined.
|
||||||
VERIFY(result.is_undefined());
|
VERIFY(result.is_undefined());
|
||||||
|
@ -1069,7 +1069,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
|
||||||
auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
|
auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
|
||||||
|
|
||||||
// 3. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures promiseCapability and performs the following steps when called:
|
// 3. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures promiseCapability and performs the following steps when called:
|
||||||
auto rejected_closure = [rejected_function = make_handle(promise_capability.reject)](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
|
auto rejected_closure = [rejected_function = make_handle(promise_capability.reject)](VM& vm) -> ThrowCompletionOr<Value> {
|
||||||
auto error = vm.argument(0);
|
auto error = vm.argument(0);
|
||||||
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
|
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
|
||||||
MUST(call(vm, rejected_function.cell(), js_undefined(), error));
|
MUST(call(vm, rejected_function.cell(), js_undefined(), error));
|
||||||
|
|
|
@ -130,7 +130,7 @@ extern bool g_collect_on_every_allocation;
|
||||||
extern bool g_run_bytecode;
|
extern bool g_run_bytecode;
|
||||||
extern String g_currently_running_test;
|
extern String g_currently_running_test;
|
||||||
struct FunctionWithLength {
|
struct FunctionWithLength {
|
||||||
JS::ThrowCompletionOr<JS::Value> (*function)(JS::VM&, JS::GlobalObject&);
|
JS::ThrowCompletionOr<JS::Value> (*function)(JS::VM&);
|
||||||
size_t length { 0 };
|
size_t length { 0 };
|
||||||
};
|
};
|
||||||
extern HashMap<String, FunctionWithLength> s_exposed_global_functions;
|
extern HashMap<String, FunctionWithLength> s_exposed_global_functions;
|
||||||
|
@ -206,8 +206,8 @@ inline void TestRunnerGlobalObject::initialize_global_object()
|
||||||
define_direct_property("global", this, JS::Attribute::Enumerable);
|
define_direct_property("global", this, JS::Attribute::Enumerable);
|
||||||
for (auto& entry : s_exposed_global_functions) {
|
for (auto& entry : s_exposed_global_functions) {
|
||||||
define_native_function(
|
define_native_function(
|
||||||
entry.key, [fn = entry.value.function](auto& vm, auto& global_object) {
|
entry.key, [fn = entry.value.function](auto& vm) {
|
||||||
return fn(vm, global_object);
|
return fn(vm);
|
||||||
},
|
},
|
||||||
entry.value.length, JS::default_attributes);
|
entry.value.length, JS::default_attributes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
||||||
// 2. If IsCallable(value) is true, then set value to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the IDL operation P on object O.
|
// 2. If IsCallable(value) is true, then set value to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the IDL operation P on object O.
|
||||||
if (value->is_function()) {
|
if (value->is_function()) {
|
||||||
value = JS::NativeFunction::create(
|
value = JS::NativeFunction::create(
|
||||||
realm, [function = JS::make_handle(*value)](auto& vm, auto&) {
|
realm, [function = JS::make_handle(*value)](auto& vm) {
|
||||||
return JS::call(vm, function.value(), JS::js_undefined());
|
return JS::call(vm, function.value(), JS::js_undefined());
|
||||||
},
|
},
|
||||||
0, "");
|
0, "");
|
||||||
|
@ -143,7 +143,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
||||||
// 2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.
|
// 2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.
|
||||||
if (*entry.needs_get) {
|
if (*entry.needs_get) {
|
||||||
cross_origin_get = JS::NativeFunction::create(
|
cross_origin_get = JS::NativeFunction::create(
|
||||||
realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto& vm, auto&) {
|
realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto& vm) {
|
||||||
return JS::call(vm, getter.cell(), object_ptr);
|
return JS::call(vm, getter.cell(), object_ptr);
|
||||||
},
|
},
|
||||||
0, "");
|
0, "");
|
||||||
|
@ -155,7 +155,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
||||||
// If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.
|
// If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.
|
||||||
if (*entry.needs_set) {
|
if (*entry.needs_set) {
|
||||||
cross_origin_set = JS::NativeFunction::create(
|
cross_origin_set = JS::NativeFunction::create(
|
||||||
realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto& vm, auto&) {
|
realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto& vm) {
|
||||||
return JS::call(vm, setter.cell(), object_ptr);
|
return JS::call(vm, setter.cell(), object_ptr);
|
||||||
},
|
},
|
||||||
0, "");
|
0, "");
|
||||||
|
|
|
@ -95,6 +95,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter)
|
||||||
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2
|
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2
|
||||||
JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
|
JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
auto& global_object = realm.global_object();
|
||||||
auto& window = static_cast<WindowObject&>(global_object);
|
auto& window = static_cast<WindowObject&>(global_object);
|
||||||
|
|
||||||
// FIXME: 1. If this's relevant Document is null, then return.
|
// FIXME: 1. If this's relevant Document is null, then return.
|
||||||
|
@ -218,6 +220,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter)
|
||||||
// https://html.spec.whatwg.org/multipage/history.html#dom-location-reload
|
// https://html.spec.whatwg.org/multipage/history.html#dom-location-reload
|
||||||
JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
|
JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
auto& global_object = realm.global_object();
|
||||||
auto& window = static_cast<WindowObject&>(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();
|
||||||
|
@ -226,6 +230,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
|
||||||
// https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
|
// https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
|
||||||
JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace)
|
JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
auto& global_object = realm.global_object();
|
||||||
auto& window = static_cast<WindowObject&>(global_object);
|
auto& window = static_cast<WindowObject&>(global_object);
|
||||||
auto url = TRY(vm.argument(0).to_string(vm));
|
auto url = TRY(vm.argument(0).to_string(vm));
|
||||||
// FIXME: This needs spec compliance work.
|
// FIXME: This needs spec compliance work.
|
||||||
|
|
|
@ -626,7 +626,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
|
||||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrollby
|
// https://www.w3.org/TR/cssom-view/#dom-window-scrollby
|
||||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
|
JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* impl = TRY(impl_from(vm));
|
auto* impl = TRY(impl_from(vm));
|
||||||
if (!impl->page())
|
if (!impl->page())
|
||||||
|
|
|
@ -524,7 +524,7 @@ void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandl
|
||||||
// document.body.remove();
|
// document.body.remove();
|
||||||
// location.reload();
|
// location.reload();
|
||||||
// The body element is no longer in the DOM and there is no variable holding onto it. However, the onunload handler is still called, meaning the callback keeps the body element alive.
|
// The body element is no longer in the DOM and there is no variable holding onto it. However, the onunload handler is still called, meaning the callback keeps the body element alive.
|
||||||
auto callback_function = JS::NativeFunction::create(realm, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm, auto&) mutable -> JS::ThrowCompletionOr<JS::Value> {
|
auto callback_function = JS::NativeFunction::create(realm, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm) mutable -> JS::ThrowCompletionOr<JS::Value> {
|
||||||
// The event dispatcher should only call this with one argument.
|
// The event dispatcher should only call this with one argument.
|
||||||
VERIFY(vm.argument_count() == 1);
|
VERIFY(vm.argument_count() == 1);
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti
|
||||||
// FIXME: This should be done with IDL
|
// FIXME: This should be done with IDL
|
||||||
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
|
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
|
||||||
m_worker_scope->define_native_function(
|
m_worker_scope->define_native_function(
|
||||||
"postMessage", [this](auto& vm, auto&) {
|
"postMessage", [this](auto& vm) {
|
||||||
// This is the implementation of the function that the spawned worked calls
|
// This is the implementation of the function that the spawned worked calls
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-dedicatedworkerglobalscope-postmessage
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-dedicatedworkerglobalscope-postmessage
|
||||||
|
|
|
@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
|
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||||
if (!is<WebAssemblyMemoryObject>(this_object))
|
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||||
|
|
|
@ -154,7 +154,7 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::VM& vm, JS::Object* buffer_object
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
|
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// FIXME: This shouldn't block!
|
// FIXME: This shouldn't block!
|
||||||
auto buffer_or_error = vm.argument(0).to_object(vm);
|
auto buffer_or_error = vm.argument(0).to_object(vm);
|
||||||
|
@ -317,7 +317,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(JS::VM& vm,
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
|
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
|
||||||
{
|
{
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// FIXME: This shouldn't block!
|
// FIXME: This shouldn't block!
|
||||||
auto buffer_or_error = vm.argument(0).to_object(vm);
|
auto buffer_or_error = vm.argument(0).to_object(vm);
|
||||||
|
@ -449,8 +449,8 @@ JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress add
|
||||||
auto function = JS::NativeFunction::create(
|
auto function = JS::NativeFunction::create(
|
||||||
realm,
|
realm,
|
||||||
name,
|
name,
|
||||||
[address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::ThrowCompletionOr<JS::Value> {
|
[address, type = type.release_value()](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
|
||||||
auto& realm = *global_object.associated_realm();
|
auto& realm = *vm.current_realm();
|
||||||
Vector<Wasm::Value> values;
|
Vector<Wasm::Value> values;
|
||||||
values.ensure_capacity(type.parameters().size());
|
values.ensure_capacity(type.parameters().size());
|
||||||
|
|
||||||
|
|
|
@ -1311,10 +1311,11 @@ void ReplObject::initialize_global_object()
|
||||||
|
|
||||||
define_native_accessor(
|
define_native_accessor(
|
||||||
"_",
|
"_",
|
||||||
[](JS::VM&, JS::GlobalObject&) {
|
[](JS::VM&) {
|
||||||
return g_last_value.value();
|
return g_last_value.value();
|
||||||
},
|
},
|
||||||
[](JS::VM& vm, JS::GlobalObject& global_object) -> JS::ThrowCompletionOr<JS::Value> {
|
[](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
|
||||||
|
auto& global_object = vm.get_global_object();
|
||||||
VERIFY(is<ReplObject>(global_object));
|
VERIFY(is<ReplObject>(global_object));
|
||||||
outln("Disable writing last value to '_'");
|
outln("Disable writing last value to '_'");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue