LibJS: Make intrinsics getters return NonnullGCPtr

Some of these are allocated upon initialization of the intrinsics, and
some lazily, but in neither case the getters actually return a nullptr.

This saves us a whole bunch of pointer dereferences (as NonnullGCPtr has
an `operator T&()`), and also has the interesting side effect of forcing
us to explicitly use the FunctionObject& overload of call(), as passing
a NonnullGCPtr is ambigous - it could implicitly be turned into a Value
_or_ a FunctionObject& (so we have to dereference manually).
This commit is contained in:
Linus Groh 2023-04-13 00:47:15 +02:00
parent ed9e2366da
commit b84f8fb55b
Notes: sideshowbarker 2024-07-16 21:45:42 +09:00
182 changed files with 564 additions and 567 deletions
Meta/Lagom
Tools/CodeGenerators/LibWeb/BindingsGenerator
Wasm
Tests/LibWasm
Userland
Applications/Spreadsheet
Libraries/LibJS
AST.cppConsole.cpp
Contrib/Test262
Runtime
AbstractOperations.cppAbstractOperations.hAggregateError.cppAggregateErrorConstructor.cppAggregateErrorPrototype.cppArgumentsObject.cppArrayBuffer.cppArrayBufferConstructor.cppArrayBufferPrototype.cppArrayConstructor.cppArrayIterator.cppArrayIteratorPrototype.cppArrayPrototype.cppAsyncFromSyncIterator.cppAsyncFromSyncIteratorPrototype.cppAsyncFunctionConstructor.cppAsyncFunctionDriverWrapper.cppAsyncFunctionPrototype.cppAsyncGeneratorFunctionConstructor.cppAsyncGeneratorFunctionPrototype.cppAsyncGeneratorPrototype.cppAsyncIteratorPrototype.cppAtomicsObject.cppBigIntConstructor.cppBigIntObject.cppBigIntPrototype.cppBooleanConstructor.cppBooleanObject.cppBooleanPrototype.cppCompletion.cppConsoleObject.cppDataView.cppDataViewConstructor.cppDataViewPrototype.cppDate.cppDateConstructor.cppDatePrototype.cppDisposableStackConstructor.cppDisposableStackPrototype.cppECMAScriptFunctionObject.cppError.cppErrorConstructor.cppErrorPrototype.cppFinalizationRegistryConstructor.cppFinalizationRegistryPrototype.cppFunctionConstructor.cppFunctionPrototype.cppGeneratorFunctionConstructor.cppGeneratorFunctionPrototype.cppGeneratorPrototype.cpp
Intl
Intrinsics.cppIntrinsics.hIteratorPrototype.cppJSONObject.cppMap.cppMapConstructor.cppMapIterator.cppMapIteratorPrototype.cppMapPrototype.cppMathObject.cppModuleNamespaceObject.cppNativeFunction.cpp

View file

@ -3311,7 +3311,7 @@ using namespace Web::WebIDL;
namespace Web::Bindings {
@constructor_class@::@constructor_class@(JS::Realm& realm)
: NativeFunction("@name@"sv, *realm.intrinsics().function_prototype())
: NativeFunction("@name@"sv, realm.intrinsics().function_prototype())
{
}
@ -3698,7 +3698,7 @@ namespace Web::Bindings {
// https://webidl.spec.whatwg.org/#es-DOMException-specialness
// Object.getPrototypeOf(DOMException.prototype) === Error.prototype
generator.append(R"~~~(
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().error_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().error_prototype())
)~~~");
} else if (!interface.parent_name.is_empty()) {
generator.append(R"~~~(
@ -3706,7 +3706,7 @@ namespace Web::Bindings {
)~~~");
} else {
generator.append(R"~~~(
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
)~~~");
}
@ -3821,7 +3821,7 @@ using namespace Web::WebIDL;
namespace Web::Bindings {
@prototype_class@::@prototype_class@(JS::Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().iterator_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().iterator_prototype())
{
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2022, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -382,9 +382,9 @@ extern "C" int initialize_repl(char const* time_zone)
s_print_last_result = true;
interpreter = JS::Interpreter::create<ReplObject>(*g_vm);
auto& console_object = *interpreter->realm().intrinsics().console_object();
g_console_client = make<ReplConsoleClient>(console_object.console());
console_object.console().set_client(*g_console_client);
auto console_object = interpreter->realm().intrinsics().console_object();
g_console_client = make<ReplConsoleClient>(console_object->console());
console_object->console().set_client(*g_console_client);
g_interpreter = move(interpreter);
return 0;

View file

@ -56,7 +56,7 @@ public:
static JS::ThrowCompletionOr<WebAssemblyModule*> create(JS::Realm& realm, Wasm::Module module, HashMap<Wasm::Linker::Name, Wasm::ExternValue> const& imports)
{
auto& vm = realm.vm();
auto instance = MUST_OR_THROW_OOM(realm.heap().allocate<WebAssemblyModule>(realm, *realm.intrinsics().object_prototype()));
auto instance = MUST_OR_THROW_OOM(realm.heap().allocate<WebAssemblyModule>(realm, realm.intrinsics().object_prototype()));
instance->m_module = move(module);
Wasm::Linker linker(*instance->m_module);
linker.link(imports);

View file

@ -373,7 +373,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound)
}
WorkbookObject::WorkbookObject(JS::Realm& realm, Workbook& workbook)
: JS::Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: JS::Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
, m_workbook(workbook)
{
}

View file

@ -1955,8 +1955,8 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
class_private_environment->add_private_name({}, opt_private_name.release_value());
}
auto* proto_parent = realm.intrinsics().object_prototype();
auto* constructor_parent = realm.intrinsics().function_prototype();
auto proto_parent = GCPtr { realm.intrinsics().object_prototype() };
auto constructor_parent = realm.intrinsics().function_prototype();
if (!m_super_class.is_null()) {
vm.running_execution_context().lexical_environment = class_environment;
@ -1985,9 +1985,9 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
if (super_class_prototype.is_null())
proto_parent = nullptr;
else
proto_parent = &super_class_prototype.as_object();
proto_parent = super_class_prototype.as_object();
constructor_parent = &super_class.as_object();
constructor_parent = super_class.as_object();
}
}

View file

@ -615,7 +615,7 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
// 1. If specifier is %s, let converted be the result of Call(%String%, undefined, « current »).
if (specifier == "%s"sv) {
converted = TRY(call(vm, realm.intrinsics().string_constructor(), js_undefined(), current));
converted = TRY(call(vm, *realm.intrinsics().string_constructor(), js_undefined(), current));
}
// 2. If specifier is %d or %i:
else if (specifier.is_one_of("%d"sv, "%i"sv)) {
@ -625,7 +625,7 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
}
// 2. Otherwise, let converted be the result of Call(%parseInt%, undefined, « current, 10 »).
else {
converted = TRY(call(vm, realm.intrinsics().parse_int_function(), js_undefined(), current, Value { 10 }));
converted = TRY(call(vm, *realm.intrinsics().parse_int_function(), js_undefined(), current, Value { 10 }));
}
}
// 3. If specifier is %f:
@ -636,7 +636,7 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
}
// 2. Otherwise, let converted be the result of Call(% parseFloat %, undefined, « current »).
else {
converted = TRY(call(vm, realm.intrinsics().parse_float_function(), js_undefined(), current));
converted = TRY(call(vm, *realm.intrinsics().parse_float_function(), js_undefined(), current));
}
}
// 4. If specifier is %o, optionally let converted be current with optimally useful formatting applied.

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -11,7 +11,7 @@ namespace JS::Test262 {
IsHTMLDDA::IsHTMLDDA(Realm& realm)
// NativeFunction without prototype is currently not possible (only due to the lack of a ctor that supports it)
: NativeFunction("IsHTMLDDA", *realm.intrinsics().function_prototype())
: NativeFunction("IsHTMLDDA", realm.intrinsics().function_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -364,7 +364,7 @@ bool validate_and_apply_property_descriptor(Object* object, PropertyKey const& p
}
// 10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ), https://tc39.es/ecma262/#sec-getprototypefromconstructor
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM& vm, FunctionObject const& constructor, Object* (Intrinsics::*intrinsic_default_prototype)())
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM& vm, FunctionObject const& constructor, NonnullGCPtr<Object> (Intrinsics::*intrinsic_default_prototype)())
{
// 1. Assert: intrinsicDefaultProto is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.
@ -1075,11 +1075,11 @@ Object* create_unmapped_arguments_object(VM& vm, Span<Value> arguments)
}
// 7. Perform ! DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
auto* array_prototype_values = realm.intrinsics().array_prototype_values_function();
auto array_prototype_values = realm.intrinsics().array_prototype_values_function();
MUST(object->define_property_or_throw(*vm.well_known_symbol_iterator(), { .value = array_prototype_values, .writable = true, .enumerable = false, .configurable = true }));
// 8. Perform ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Get]]: %ThrowTypeError%, [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false }).
auto* throw_type_error = realm.intrinsics().throw_type_error_function();
auto throw_type_error = realm.intrinsics().throw_type_error_function();
MUST(object->define_property_or_throw(vm.names.callee, { .get = throw_type_error, .set = throw_type_error, .enumerable = false, .configurable = false }));
// 9. Return obj.
@ -1158,7 +1158,7 @@ Object* create_mapped_arguments_object(VM& vm, FunctionObject& function, Vector<
}
// 20. Perform ! DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
auto* array_prototype_values = realm.intrinsics().array_prototype_values_function();
auto array_prototype_values = realm.intrinsics().array_prototype_values_function();
MUST(object->define_property_or_throw(*vm.well_known_symbol_iterator(), { .value = array_prototype_values, .writable = true, .enumerable = false, .configurable = true }));
// 21. Perform ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Value]]: func, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -38,7 +38,7 @@ ThrowCompletionOr<Realm*> get_function_realm(VM&, FunctionObject const&);
ThrowCompletionOr<void> initialize_bound_name(VM&, DeprecatedFlyString const&, Value, Environment*);
bool is_compatible_property_descriptor(bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
bool validate_and_apply_property_descriptor(Object*, PropertyKey const&, bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM&, FunctionObject const& constructor, Object* (Intrinsics::*intrinsic_default_prototype)());
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM&, FunctionObject const& constructor, NonnullGCPtr<Object> (Intrinsics::*intrinsic_default_prototype)());
Object* create_unmapped_arguments_object(VM&, Span<Value> arguments);
Object* create_mapped_arguments_object(VM&, FunctionObject&, Vector<FunctionParameter> const&, Span<Value> arguments, Environment&);
@ -142,7 +142,7 @@ ALWAYS_INLINE ThrowCompletionOr<NonnullGCPtr<Object>> construct(VM& vm, Function
// 10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor
template<typename T, typename... Args>
ThrowCompletionOr<NonnullGCPtr<T>> ordinary_create_from_constructor(VM& vm, FunctionObject const& constructor, Object* (Intrinsics::*intrinsic_default_prototype)(), Args&&... args)
ThrowCompletionOr<NonnullGCPtr<T>> ordinary_create_from_constructor(VM& vm, FunctionObject const& constructor, NonnullGCPtr<Object> (Intrinsics::*intrinsic_default_prototype)(), Args&&... args)
{
auto& realm = *vm.current_realm();
auto* prototype = TRY(get_prototype_from_constructor(vm, constructor, intrinsic_default_prototype));

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -12,7 +12,7 @@ namespace JS {
NonnullGCPtr<AggregateError> AggregateError::create(Realm& realm)
{
return realm.heap().allocate<AggregateError>(realm, *realm.intrinsics().aggregate_error_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<AggregateError>(realm, realm.intrinsics().aggregate_error_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
AggregateError::AggregateError(Object& prototype)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -11,7 +11,7 @@
namespace JS {
AggregateErrorPrototype::AggregateErrorPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().error_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().error_prototype())
{
}

View file

@ -11,7 +11,7 @@
namespace JS {
ArgumentsObject::ArgumentsObject(Realm& realm, Environment& environment)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
, m_environment(environment)
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -17,17 +17,17 @@ ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> ArrayBuffer::create(Realm& realm, s
if (buffer.is_error())
return realm.vm().throw_completion<RangeError>(ErrorType::NotEnoughMemoryToAllocate, byte_length);
return MUST_OR_THROW_OOM(realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), *realm.intrinsics().array_buffer_prototype()));
return MUST_OR_THROW_OOM(realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), realm.intrinsics().array_buffer_prototype()));
}
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer buffer)
{
return realm.heap().allocate<ArrayBuffer>(realm, move(buffer), *realm.intrinsics().array_buffer_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<ArrayBuffer>(realm, move(buffer), realm.intrinsics().array_buffer_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer* buffer)
{
return realm.heap().allocate<ArrayBuffer>(realm, buffer, *realm.intrinsics().array_buffer_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<ArrayBuffer>(realm, buffer, realm.intrinsics().array_buffer_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype)
@ -101,7 +101,7 @@ ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(VM& vm, ArrayBuffer& source_b
VERIFY(!source_buffer.is_detached());
// 2. Let targetBuffer be ? AllocateArrayBuffer(%ArrayBuffer%, srcLength).
auto* target_buffer = TRY(allocate_array_buffer(vm, *realm.intrinsics().array_buffer_constructor(), source_length));
auto* target_buffer = TRY(allocate_array_buffer(vm, realm.intrinsics().array_buffer_constructor(), source_length));
// 3. Let srcBlock be srcBuffer.[[ArrayBufferData]].
auto& source_block = source_buffer.buffer();

View file

@ -15,7 +15,7 @@
namespace JS {
ArrayBufferConstructor::ArrayBufferConstructor(Realm& realm)
: NativeFunction(realm.vm().names.ArrayBuffer.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.ArrayBuffer.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2022, Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
@ -15,7 +15,7 @@
namespace JS {
ArrayBufferPrototype::ArrayBufferPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}
@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
auto new_length = max(final - first, 0.0);
// 15. Let ctor be ? SpeciesConstructor(O, %ArrayBuffer%).
auto* constructor = TRY(species_constructor(vm, *array_buffer_object, *realm.intrinsics().array_buffer_constructor()));
auto* constructor = TRY(species_constructor(vm, *array_buffer_object, realm.intrinsics().array_buffer_constructor()));
// 16. Let new be ? Construct(ctor, « 𝔽(newLen) »).
auto new_array_buffer = TRY(construct(vm, *constructor, Value(new_length)));

View file

@ -17,7 +17,7 @@
namespace JS {
ArrayConstructor::ArrayConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Array.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Array.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<ArrayIterator> ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind)
{
return realm.heap().allocate<ArrayIterator>(realm, array, iteration_kind, *realm.intrinsics().array_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<ArrayIterator>(realm, array, iteration_kind, realm.intrinsics().array_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype)

View file

@ -15,7 +15,7 @@
namespace JS {
ArrayIteratorPrototype::ArrayIteratorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().iterator_prototype())
: PrototypeObject(realm.intrinsics().iterator_prototype())
{
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020, Marcin Gasperowicz <xnooga@gmail.com>
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
*
@ -29,7 +29,7 @@ namespace JS {
static HashTable<Object*> s_array_join_seen_objects;
ArrayPrototype::ArrayPrototype(Realm& realm)
: Array(*realm.intrinsics().object_prototype())
: Array(realm.intrinsics().object_prototype())
{
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -17,7 +17,7 @@ NonnullGCPtr<AsyncFromSyncIterator> AsyncFromSyncIterator::create(Realm& realm,
}
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().async_from_sync_iterator_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().async_from_sync_iterator_prototype())
, m_sync_iterator_record(sync_iterator_record)
{
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -15,7 +15,7 @@
namespace JS {
AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().async_iterator_prototype())
: PrototypeObject(realm.intrinsics().async_iterator_prototype())
{
}
@ -48,7 +48,7 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro
// 6. Let valueWrapper be PromiseResolve(%Promise%, value).
// 7. IfAbruptRejectPromise(valueWrapper, promiseCapability).
auto value_wrapper = TRY_OR_MUST_REJECT(vm, &promise_capability, promise_resolve(vm, *realm.intrinsics().promise_constructor(), value));
auto value_wrapper = TRY_OR_MUST_REJECT(vm, &promise_capability, promise_resolve(vm, realm.intrinsics().promise_constructor(), value));
// 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) -> ThrowCompletionOr<Value> {

View file

@ -13,7 +13,7 @@
namespace JS {
AsyncFunctionConstructor::AsyncFunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.AsyncFunction.as_string(), *realm.intrinsics().function_constructor())
: NativeFunction(realm.vm().names.AsyncFunction.as_string(), realm.intrinsics().function_constructor())
{
}

View file

@ -27,7 +27,7 @@ ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(Realm& realm, Genera
}
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, NonnullGCPtr<GeneratorObject> generator_object, NonnullGCPtr<Promise> top_level_promise)
: Promise(*realm.intrinsics().promise_prototype())
: Promise(realm.intrinsics().promise_prototype())
, m_generator_object(generator_object)
, m_on_fulfillment(*NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm) -> ThrowCompletionOr<Value> {
auto arg = vm.argument(0);

View file

@ -10,7 +10,7 @@
namespace JS {
AsyncFunctionPrototype::AsyncFunctionPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().function_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().function_prototype())
{
}

View file

@ -13,7 +13,7 @@
namespace JS {
AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.AsyncGeneratorFunction.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.AsyncGeneratorFunction.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -12,7 +12,7 @@
namespace JS {
AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().function_prototype())
: PrototypeObject(realm.intrinsics().function_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -10,7 +10,7 @@ namespace JS {
// 27.6.1 Properties of the AsyncGenerator Prototype Object, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-prototype
AsyncGeneratorPrototype::AsyncGeneratorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().async_iterator_prototype())
: PrototypeObject(realm.intrinsics().async_iterator_prototype())
{
}

View file

@ -9,7 +9,7 @@
namespace JS {
AsyncIteratorPrototype::AsyncIteratorPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}

View file

@ -125,7 +125,7 @@ static ThrowCompletionOr<Value> perform_atomic_operation(VM& vm, TypedArrayBase&
}
AtomicsObject::AtomicsObject(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -17,7 +17,7 @@ namespace JS {
static const Crypto::SignedBigInteger BIGINT_ONE { 1 };
BigIntConstructor::BigIntConstructor(Realm& realm)
: NativeFunction(realm.vm().names.BigInt.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.BigInt.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<BigIntObject> BigIntObject::create(Realm& realm, BigInt& bigint)
{
return realm.heap().allocate<BigIntObject>(realm, bigint, *realm.intrinsics().bigint_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<BigIntObject>(realm, bigint, realm.intrinsics().bigint_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
BigIntObject::BigIntObject(BigInt& bigint, Object& prototype)

View file

@ -18,7 +18,7 @@
namespace JS {
BigIntPrototype::BigIntPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}
@ -90,7 +90,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string)
auto* bigint = TRY(this_bigint_value(vm, vm.this_value()));
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), locales, options)).ptr());
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, realm.intrinsics().intl_number_format_constructor(), locales, options)).ptr());
// 3. Return ? FormatNumeric(numberFormat, x).
auto formatted = TRY(Intl::format_numeric(vm, *number_format, Value(bigint)));

View file

@ -13,7 +13,7 @@
namespace JS {
BooleanConstructor::BooleanConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Boolean.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Boolean.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<BooleanObject> BooleanObject::create(Realm& realm, bool value)
{
return realm.heap().allocate<BooleanObject>(realm, value, *realm.intrinsics().boolean_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<BooleanObject>(realm, value, realm.intrinsics().boolean_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
BooleanObject::BooleanObject(bool value, Object& prototype)

View file

@ -14,7 +14,7 @@
namespace JS {
BooleanPrototype::BooleanPrototype(Realm& realm)
: BooleanObject(false, *realm.intrinsics().object_prototype())
: BooleanObject(false, realm.intrinsics().object_prototype())
{
}

View file

@ -37,7 +37,7 @@ ThrowCompletionOr<Value> await(VM& vm, Value value)
// NOTE: This is not needed, as we don't suspend anything.
// 2. Let promise be ? PromiseResolve(%Promise%, value).
auto* promise_object = TRY(promise_resolve(vm, *realm.intrinsics().promise_constructor(), value));
auto* promise_object = TRY(promise_resolve(vm, realm.intrinsics().promise_constructor(), value));
Optional<bool> success;
Value result;

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -13,7 +13,7 @@
namespace JS {
ConsoleObject::ConsoleObject(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
, m_console(make<Console>(realm))
{
}

View file

@ -10,7 +10,7 @@ namespace JS {
NonnullGCPtr<DataView> DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset)
{
return realm.heap().allocate<DataView>(realm, viewed_buffer, byte_length, byte_offset, *realm.intrinsics().data_view_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<DataView>(realm, viewed_buffer, byte_length, byte_offset, realm.intrinsics().data_view_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
DataView::DataView(ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset, Object& prototype)

View file

@ -15,7 +15,7 @@
namespace JS {
DataViewConstructor::DataViewConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DataView.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DataView.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -11,7 +11,7 @@
namespace JS {
DataViewPrototype::DataViewPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -25,7 +25,7 @@ Crypto::SignedBigInteger const ns_per_day_bigint { static_cast<i64>(ns_per_day)
NonnullGCPtr<Date> Date::create(Realm& realm, double date_value)
{
return realm.heap().allocate<Date>(realm, date_value, *realm.intrinsics().date_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<Date>(realm, date_value, realm.intrinsics().date_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
Date::Date(double date_value, Object& prototype)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020, Nico Weber <thakis@chromium.org>
* Copyright (c) 2021, Petróczi Zoltán <petroczizoltan@tutanota.com>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
@ -179,7 +179,7 @@ static double parse_date_string(DeprecatedString const& date_string)
}
DateConstructor::DateConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Date.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Date.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Petróczi Zoltán <petroczizoltan@tutanota.com>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
@ -30,7 +30,7 @@
namespace JS {
DatePrototype::DatePrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}
@ -987,7 +987,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json)
static ThrowCompletionOr<Intl::DateTimeFormat*> construct_date_time_format(VM& vm, Value locales, Value options)
{
auto& realm = *vm.current_realm();
auto date_time_format = TRY(construct(vm, *realm.intrinsics().intl_date_time_format_constructor(), locales, options));
auto date_time_format = TRY(construct(vm, realm.intrinsics().intl_date_time_format_constructor(), locales, options));
return static_cast<Intl::DateTimeFormat*>(date_time_format.ptr());
}

View file

@ -11,7 +11,7 @@
namespace JS {
DisposableStackConstructor::DisposableStackConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DisposableStack.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DisposableStack.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -13,7 +13,7 @@
namespace JS {
DisposableStackPrototype::DisposableStackPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -115,7 +115,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::initialize(Realm& realm)
Object* prototype = nullptr;
switch (m_kind) {
case FunctionKind::Normal:
prototype = MUST_OR_THROW_OOM(vm.heap().allocate<Object>(realm, *realm.intrinsics().new_ordinary_function_prototype_object_shape()));
prototype = MUST_OR_THROW_OOM(vm.heap().allocate<Object>(realm, realm.intrinsics().new_ordinary_function_prototype_object_shape()));
MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true }));
break;
case FunctionKind::Generator:

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -17,7 +17,7 @@ namespace JS {
NonnullGCPtr<Error> Error::create(Realm& realm)
{
return realm.heap().allocate<Error>(realm, *realm.intrinsics().error_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<Error>(realm, realm.intrinsics().error_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NonnullGCPtr<Error> Error::create(Realm& realm, String message)
@ -105,29 +105,29 @@ ThrowCompletionOr<String> Error::stack_string(VM& vm) const
return stack_string_builder.to_string();
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \
{ \
return realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); \
} \
\
NonnullGCPtr<ClassName> ClassName::create(Realm& realm, String message) \
{ \
auto& vm = realm.vm(); \
auto error = ClassName::create(realm); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, move(message)), attr); \
return error; \
} \
\
ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, StringView message) \
{ \
return create(realm, TRY_OR_THROW_OOM(realm.vm(), String::from_utf8(message))); \
} \
\
ClassName::ClassName(Object& prototype) \
: Error(prototype) \
{ \
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \
{ \
return realm.heap().allocate<ClassName>(realm, realm.intrinsics().snake_name##_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); \
} \
\
NonnullGCPtr<ClassName> ClassName::create(Realm& realm, String message) \
{ \
auto& vm = realm.vm(); \
auto error = ClassName::create(realm); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, move(message)), attr); \
return error; \
} \
\
ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, StringView message) \
{ \
return create(realm, TRY_OR_THROW_OOM(realm.vm(), String::from_utf8(message))); \
} \
\
ClassName::ClassName(Object& prototype) \
: Error(prototype) \
{ \
}
JS_ENUMERATE_NATIVE_ERRORS

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -12,7 +12,7 @@
namespace JS {
ErrorConstructor::ErrorConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Error.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Error.as_string(), realm.intrinsics().function_prototype())
{
}
@ -63,59 +63,59 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ErrorConstructor::construct(FunctionObje
return error;
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
ConstructorName::ConstructorName(Realm& realm) \
: NativeFunction(realm.vm().names.ClassName.as_string(), *static_cast<Object*>(realm.intrinsics().error_constructor())) \
{ \
} \
\
ThrowCompletionOr<void> ConstructorName::initialize(Realm& realm) \
{ \
auto& vm = this->vm(); \
MUST_OR_THROW_OOM(NativeFunction::initialize(realm)); \
\
/* 20.5.6.2.1 NativeError.prototype, https://tc39.es/ecma262/#sec-nativeerror.prototype */ \
define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0); \
\
define_direct_property(vm.names.length, Value(1), Attribute::Configurable); \
\
return {}; \
} \
\
ConstructorName::~ConstructorName() = default; \
\
/* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \
ThrowCompletionOr<Value> ConstructorName::call() \
{ \
/* 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. */ \
return TRY(construct(*this)); \
} \
\
/* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \
ThrowCompletionOr<NonnullGCPtr<Object>> ConstructorName::construct(FunctionObject& new_target) \
{ \
auto& vm = this->vm(); \
\
auto message = vm.argument(0); \
auto options = vm.argument(1); \
\
/* 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »). */ \
auto error = TRY(ordinary_create_from_constructor<ClassName>(vm, new_target, &Intrinsics::snake_name##_prototype)); \
\
/* 3. If message is not undefined, then */ \
if (!message.is_undefined()) { \
/* a. Let msg be ? ToString(message). */ \
auto msg = TRY(message.to_string(vm)); \
\
/* b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). */ \
error->create_non_enumerable_data_property_or_throw(vm.names.message, PrimitiveString::create(vm, move(msg))); \
} \
\
/* 4. Perform ? InstallErrorCause(O, options). */ \
TRY(error->install_error_cause(options)); \
\
/* 5. Return O. */ \
return error; \
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
ConstructorName::ConstructorName(Realm& realm) \
: NativeFunction(realm.vm().names.ClassName.as_string(), realm.intrinsics().error_constructor()) \
{ \
} \
\
ThrowCompletionOr<void> ConstructorName::initialize(Realm& realm) \
{ \
auto& vm = this->vm(); \
MUST_OR_THROW_OOM(NativeFunction::initialize(realm)); \
\
/* 20.5.6.2.1 NativeError.prototype, https://tc39.es/ecma262/#sec-nativeerror.prototype */ \
define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0); \
\
define_direct_property(vm.names.length, Value(1), Attribute::Configurable); \
\
return {}; \
} \
\
ConstructorName::~ConstructorName() = default; \
\
/* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \
ThrowCompletionOr<Value> ConstructorName::call() \
{ \
/* 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. */ \
return TRY(construct(*this)); \
} \
\
/* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \
ThrowCompletionOr<NonnullGCPtr<Object>> ConstructorName::construct(FunctionObject& new_target) \
{ \
auto& vm = this->vm(); \
\
auto message = vm.argument(0); \
auto options = vm.argument(1); \
\
/* 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »). */ \
auto error = TRY(ordinary_create_from_constructor<ClassName>(vm, new_target, &Intrinsics::snake_name##_prototype)); \
\
/* 3. If message is not undefined, then */ \
if (!message.is_undefined()) { \
/* a. Let msg be ? ToString(message). */ \
auto msg = TRY(message.to_string(vm)); \
\
/* b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). */ \
error->create_non_enumerable_data_property_or_throw(vm.names.message, PrimitiveString::create(vm, move(msg))); \
} \
\
/* 4. Perform ? InstallErrorCause(O, options). */ \
TRY(error->install_error_cause(options)); \
\
/* 5. Return O. */ \
return error; \
}
JS_ENUMERATE_NATIVE_ERRORS

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -15,7 +15,7 @@
namespace JS {
ErrorPrototype::ErrorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}
@ -126,7 +126,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_setter)
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
PrototypeName::PrototypeName(Realm& realm) \
: PrototypeObject(*realm.intrinsics().error_prototype()) \
: PrototypeObject(realm.intrinsics().error_prototype()) \
{ \
} \
\

View file

@ -14,7 +14,7 @@
namespace JS {
FinalizationRegistryConstructor::FinalizationRegistryConstructor(Realm& realm)
: NativeFunction(realm.vm().names.FinalizationRegistry.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.FinalizationRegistry.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -11,7 +11,7 @@
namespace JS {
FinalizationRegistryPrototype::FinalizationRegistryPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -19,7 +19,7 @@
namespace JS {
FunctionConstructor::FunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Function.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Function.as_string(), realm.intrinsics().function_prototype())
{
}
@ -50,7 +50,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
new_target = &constructor;
StringView prefix;
Object* (Intrinsics::*fallback_prototype)() = nullptr;
NonnullGCPtr<Object> (Intrinsics::*fallback_prototype)() = nullptr;
switch (kind) {
// 4. If kind is normal, then

View file

@ -21,7 +21,7 @@
namespace JS {
FunctionPrototype::FunctionPrototype(Realm& realm)
: FunctionObject(*realm.intrinsics().object_prototype())
: FunctionObject(realm.intrinsics().object_prototype())
{
}

View file

@ -12,7 +12,7 @@
namespace JS {
GeneratorFunctionConstructor::GeneratorFunctionConstructor(Realm& realm)
: NativeFunction(static_cast<Object&>(*realm.intrinsics().function_constructor()))
: NativeFunction(static_cast<Object&>(realm.intrinsics().function_constructor()))
{
}

View file

@ -11,7 +11,7 @@
namespace JS {
GeneratorFunctionPrototype::GeneratorFunctionPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().function_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().function_prototype())
{
}

View file

@ -10,7 +10,7 @@
namespace JS {
GeneratorPrototype::GeneratorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().iterator_prototype())
: PrototypeObject(realm.intrinsics().iterator_prototype())
{
}

View file

@ -17,7 +17,7 @@ NonnullGCPtr<CollatorCompareFunction> CollatorCompareFunction::create(Realm& rea
}
CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)
: NativeFunction(*realm.intrinsics().function_prototype())
: NativeFunction(realm.intrinsics().function_prototype())
, m_collator(collator)
{
}

View file

@ -131,7 +131,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 10.1 The Intl.Collator Constructor, https://tc39.es/ecma402/#sec-the-intl-collator-constructor
CollatorConstructor::CollatorConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Collator.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Collator.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
// 10.3 Properties of the Intl.Collator Prototype Object, https://tc39.es/ecma402/#sec-properties-of-the-intl-collator-prototype-object
CollatorPrototype::CollatorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -551,7 +551,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
auto const& data_locale = date_time_format.data_locale();
auto construct_number_format = [&](auto& options) -> ThrowCompletionOr<NumberFormat*> {
auto number_format = TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, locale), options));
auto number_format = TRY(construct(vm, realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, locale), options));
return static_cast<NumberFormat*>(number_format.ptr());
};

View file

@ -19,7 +19,7 @@ namespace JS::Intl {
// 11.1 The Intl.DateTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
DateTimeFormatConstructor::DateTimeFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DateTimeFormat.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DateTimeFormat.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
// 11.5.5 DateTime Format Functions, https://tc39.es/ecma402/#sec-datetime-format-functions
NonnullGCPtr<DateTimeFormatFunction> DateTimeFormatFunction::create(Realm& realm, DateTimeFormat& date_time_format)
{
return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype)
@ -51,7 +51,7 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
// 3. If date is not provided or is undefined, then
if (date.is_undefined()) {
// a. Let x be ! Call(%Date.now%, undefined).
date_value = MUST(JS::call(vm, realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double();
date_value = MUST(JS::call(vm, *realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double();
}
// 4. Else,
else {

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 11.3 Properties of the Intl.DateTimeFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-datetimeformat-prototype-object
DateTimeFormatPrototype::DateTimeFormatPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}
@ -80,7 +80,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
// 3. If date is undefined, then
if (date.is_undefined()) {
// a. Let x be ! Call(%Date.now%, undefined).
date_value = MUST(call(vm, realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double();
date_value = MUST(call(vm, *realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double();
}
// 4. Else,
else {

View file

@ -17,7 +17,7 @@ namespace JS::Intl {
// 12.1 The Intl.DisplayNames Constructor, https://tc39.es/ecma402/#sec-intl-displaynames-constructor
DisplayNamesConstructor::DisplayNamesConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DisplayNames.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DisplayNames.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 12.3 Properties of the Intl.DisplayNames Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-displaynames-prototype-object
DisplayNamesPrototype::DisplayNamesPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -438,7 +438,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
// i. If style is "2-digit" or "numeric", then
if (style == DurationFormat::ValueStyle::TwoDigit || style == DurationFormat::ValueStyle::Numeric) {
// 1. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)).ptr());
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)).ptr());
// 2. Let dataLocale be durationFormat.[[DataLocale]].
auto const& data_locale = duration_format.data_locale();
@ -502,7 +502,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, unicode_style))));
// 4. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)).ptr());
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)).ptr());
// 5. Let parts be ! PartitionNumberPattern(nf, 𝔽(value)).
auto parts = MUST_OR_THROW_OOM(partition_number_pattern(vm, *number_format, MathematicalValue(value)));
@ -543,7 +543,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
MUST(list_format_options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, unicode_list_style))));
// 9. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »).
auto* list_format = static_cast<ListFormat*>(MUST(construct(vm, *realm.intrinsics().intl_list_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), list_format_options)).ptr());
auto* list_format = static_cast<ListFormat*>(MUST(construct(vm, realm.intrinsics().intl_list_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), list_format_options)).ptr());
// FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records
// so we try to hack something together from it that looks mostly right

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
// 1.2 The Intl.DurationFormat Constructor, https://tc39.es/proposal-intl-duration-format/#sec-intl-durationformat-constructor
DurationFormatConstructor::DurationFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DurationFormat.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DurationFormat.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 1.4 Properties of the Intl.DurationFormat Prototype Object, https://tc39.es/proposal-intl-duration-format/#sec-properties-of-intl-durationformat-prototype-object
DurationFormatPrototype::DurationFormatPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -28,7 +28,7 @@ namespace JS::Intl {
// 8 The Intl Object, https://tc39.es/ecma402/#intl-object
Intl::Intl(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
// 13.1 The Intl.ListFormat Constructor, https://tc39.es/ecma402/#sec-intl-listformat-constructor
ListFormatConstructor::ListFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.ListFormat.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.ListFormat.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 13.3 Properties of the Intl.ListFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-listformat-prototype-object
ListFormatPrototype::ListFormatPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
ThrowCompletionOr<NonnullGCPtr<Locale>> Locale::create(Realm& realm, ::Locale::LocaleID locale_id)
{
auto locale = MUST_OR_THROW_OOM(realm.heap().allocate<Locale>(realm, *realm.intrinsics().intl_locale_prototype()));
auto locale = MUST_OR_THROW_OOM(realm.heap().allocate<Locale>(realm, realm.intrinsics().intl_locale_prototype()));
locale->set_locale(TRY_OR_THROW_OOM(realm.vm(), locale_id.to_string()));
for (auto& extension : locale_id.extensions) {

View file

@ -218,7 +218,7 @@ static ThrowCompletionOr<LocaleAndKeys> apply_unicode_extension_to_tag(VM& vm, S
// 14.1 The Intl.Locale Constructor, https://tc39.es/ecma402/#sec-intl-locale-constructor
LocaleConstructor::LocaleConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Locale.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Locale.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 14.3 Properties of the Intl.Locale Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-locale-prototype-object
LocalePrototype::LocalePrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 15.1 The Intl.NumberFormat Constructor, https://tc39.es/ecma402/#sec-intl-numberformat-constructor
NumberFormatConstructor::NumberFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.NumberFormat.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.NumberFormat.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
// 15.5.2 Number Format Functions, https://tc39.es/ecma402/#sec-number-format-functions
NonnullGCPtr<NumberFormatFunction> NumberFormatFunction::create(Realm& realm, NumberFormat& number_format)
{
return realm.heap().allocate<NumberFormatFunction>(realm, number_format, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<NumberFormatFunction>(realm, number_format, realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype)

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 15.3 Properties of the Intl.NumberFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-numberformat-prototype-object
NumberFormatPrototype::NumberFormatPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -17,7 +17,7 @@ namespace JS::Intl {
// 16.1 The Intl.PluralRules Constructor, https://tc39.es/ecma402/#sec-intl-pluralrules-constructor
PluralRulesConstructor::PluralRulesConstructor(Realm& realm)
: NativeFunction(realm.vm().names.PluralRules.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.PluralRules.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 16.3 Properties of the Intl.PluralRules Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-pluralrules-prototype-object
PluralRulesPrototype::PluralRulesPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -20,7 +20,7 @@ namespace JS::Intl {
// 17.1 The Intl.RelativeTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor
RelativeTimeFormatConstructor::RelativeTimeFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.RelativeTimeFormat.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.RelativeTimeFormat.as_string(), realm.intrinsics().function_prototype())
{
}
@ -140,11 +140,11 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
relative_time_format.set_numeric(TRY(numeric.as_string().utf8_string_view()));
// 19. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »).
auto number_format = MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, locale)));
auto number_format = MUST(construct(vm, realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, locale)));
relative_time_format.set_number_format(static_cast<NumberFormat*>(number_format.ptr()));
// 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »).
auto plural_rules = MUST(construct(vm, *realm.intrinsics().intl_plural_rules_constructor(), PrimitiveString::create(vm, locale)));
auto plural_rules = MUST(construct(vm, realm.intrinsics().intl_plural_rules_constructor(), PrimitiveString::create(vm, locale)));
relative_time_format.set_plural_rules(static_cast<PluralRules*>(plural_rules.ptr()));
// 21. Return relativeTimeFormat.

View file

@ -12,7 +12,7 @@ namespace JS::Intl {
// 17.3 Properties of the Intl.RelativeTimeFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-relativetimeformat-prototype-object
RelativeTimeFormatPrototype::RelativeTimeFormatPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -24,7 +24,7 @@ NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, Segmenter& s
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
SegmentIterator::SegmentIterator(Realm& realm, Segmenter& segmenter, Utf16View const& string, Segments const& segments)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().intl_segment_iterator_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().intl_segment_iterator_prototype())
, m_iterating_segmenter(segmenter)
, m_iterated_string(string)
, m_segments(segments)

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 18.6.2 The %SegmentIteratorPrototype% Object, https://tc39.es/ecma402/#sec-%segmentiteratorprototype%-object
SegmentIteratorPrototype::SegmentIteratorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().iterator_prototype())
: PrototypeObject(realm.intrinsics().iterator_prototype())
{
}

View file

@ -17,7 +17,7 @@ namespace JS::Intl {
// 18.1 The Intl.Segmenter Constructor, https://tc39.es/ecma402/#sec-intl-segmenter-constructor
SegmenterConstructor::SegmenterConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Segmenter.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Segmenter.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
// 18.3 Properties of the Intl.Segmenter Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-segmenter-prototype-object
SegmenterPrototype::SegmenterPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -23,7 +23,7 @@ NonnullGCPtr<Segments> Segments::create(Realm& realm, Segmenter& segmenter, Utf1
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
Segments::Segments(Realm& realm, Segmenter& segmenter, Utf16String string)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().intl_segments_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().intl_segments_prototype())
, m_segments_segmenter(segmenter)
, m_segments_string(move(string))
{

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
// 18.5.2 The %SegmentsPrototype% Object, https://tc39.es/ecma402/#sec-%segmentsprototype%-object
SegmentsPrototype::SegmentsPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -302,18 +302,18 @@ JS_ENUMERATE_TYPED_ARRAYS
initialize_constructor(vm, vm.names.ClassName, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
} \
\
Namespace::ConstructorName* Intrinsics::snake_namespace##snake_name##_constructor() \
NonnullGCPtr<Namespace::ConstructorName> Intrinsics::snake_namespace##snake_name##_constructor() \
{ \
if (!m_##snake_namespace##snake_name##_constructor) \
initialize_##snake_namespace##snake_name(); \
return m_##snake_namespace##snake_name##_constructor; \
return *m_##snake_namespace##snake_name##_constructor; \
} \
\
Object* Intrinsics::snake_namespace##snake_name##_prototype() \
NonnullGCPtr<Object> Intrinsics::snake_namespace##snake_name##_prototype() \
{ \
if (!m_##snake_namespace##snake_name##_prototype) \
initialize_##snake_namespace##snake_name(); \
return m_##snake_namespace##snake_name##_prototype; \
return *m_##snake_namespace##snake_name##_prototype; \
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
@ -334,11 +334,11 @@ JS_ENUMERATE_TEMPORAL_OBJECTS
#undef __JS_ENUMERATE_INNER
#define __JS_ENUMERATE(ClassName, snake_name) \
ClassName* Intrinsics::snake_name##_object() \
NonnullGCPtr<ClassName> Intrinsics::snake_name##_object() \
{ \
if (!m_##snake_name##_object) \
m_##snake_name##_object = heap().allocate<ClassName>(m_realm, m_realm).release_allocated_value_but_fixme_should_propagate_errors(); \
return m_##snake_name##_object; \
return *m_##snake_name##_object; \
}
JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
#undef __JS_ENUMERATE
@ -397,10 +397,10 @@ void add_restricted_function_properties(FunctionObject& function, Realm& realm)
auto& vm = realm.vm();
// 1. Assert: realm.[[Intrinsics]].[[%ThrowTypeError%]] exists and has been initialized.
VERIFY(realm.intrinsics().throw_type_error_function());
// NOTE: This is ensured by dereferencing the GCPtr in the getter.
// 2. Let thrower be realm.[[Intrinsics]].[[%ThrowTypeError%]].
auto* thrower = realm.intrinsics().throw_type_error_function();
auto thrower = realm.intrinsics().throw_type_error_function();
// 3. Perform ! DefinePropertyOrThrow(F, "caller", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }).
function.define_direct_accessor(vm.names.caller, thrower, thrower, Attribute::Configurable);

View file

@ -17,75 +17,75 @@ class Intrinsics final : public Cell {
public:
static ThrowCompletionOr<NonnullGCPtr<Intrinsics>> create(Realm&);
Shape* empty_object_shape() { return m_empty_object_shape; }
NonnullGCPtr<Shape> empty_object_shape() { return *m_empty_object_shape; }
Shape* new_object_shape() { return m_new_object_shape; }
Shape* new_ordinary_function_prototype_object_shape() { return m_new_ordinary_function_prototype_object_shape; }
NonnullGCPtr<Shape> new_object_shape() { return *m_new_object_shape; }
NonnullGCPtr<Shape> new_ordinary_function_prototype_object_shape() { return *m_new_ordinary_function_prototype_object_shape; }
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
ProxyConstructor* proxy_constructor() { return m_proxy_constructor; }
NonnullGCPtr<ProxyConstructor> proxy_constructor() { return *m_proxy_constructor; }
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
Object* async_from_sync_iterator_prototype() { return m_async_from_sync_iterator_prototype; }
Object* async_generator_prototype() { return m_async_generator_prototype; }
Object* generator_prototype() { return m_generator_prototype; }
NonnullGCPtr<Object> async_from_sync_iterator_prototype() { return *m_async_from_sync_iterator_prototype; }
NonnullGCPtr<Object> async_generator_prototype() { return *m_async_generator_prototype; }
NonnullGCPtr<Object> generator_prototype() { return *m_generator_prototype; }
// Alias for the AsyncGenerator Prototype Object used by the spec (%AsyncGeneratorFunction.prototype.prototype%)
Object* async_generator_function_prototype_prototype() { return m_async_generator_prototype; }
NonnullGCPtr<Object> async_generator_function_prototype_prototype() { return *m_async_generator_prototype; }
// Alias for the Generator Prototype Object used by the spec (%GeneratorFunction.prototype.prototype%)
Object* generator_function_prototype_prototype() { return m_generator_prototype; }
NonnullGCPtr<Object> generator_function_prototype_prototype() { return *m_generator_prototype; }
// Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
Object* intl_segments_prototype() { return m_intl_segments_prototype; }
NonnullGCPtr<Object> intl_segments_prototype() { return *m_intl_segments_prototype; }
// Global object functions
FunctionObject* eval_function() const { return m_eval_function; }
FunctionObject* is_finite_function() const { return m_is_finite_function; }
FunctionObject* is_nan_function() const { return m_is_nan_function; }
FunctionObject* parse_float_function() const { return m_parse_float_function; }
FunctionObject* parse_int_function() const { return m_parse_int_function; }
FunctionObject* decode_uri_function() const { return m_decode_uri_function; }
FunctionObject* decode_uri_component_function() const { return m_decode_uri_component_function; }
FunctionObject* encode_uri_function() const { return m_encode_uri_function; }
FunctionObject* encode_uri_component_function() const { return m_encode_uri_component_function; }
FunctionObject* escape_function() const { return m_escape_function; }
FunctionObject* unescape_function() const { return m_unescape_function; }
NonnullGCPtr<FunctionObject> eval_function() const { return *m_eval_function; }
NonnullGCPtr<FunctionObject> is_finite_function() const { return *m_is_finite_function; }
NonnullGCPtr<FunctionObject> is_nan_function() const { return *m_is_nan_function; }
NonnullGCPtr<FunctionObject> parse_float_function() const { return *m_parse_float_function; }
NonnullGCPtr<FunctionObject> parse_int_function() const { return *m_parse_int_function; }
NonnullGCPtr<FunctionObject> decode_uri_function() const { return *m_decode_uri_function; }
NonnullGCPtr<FunctionObject> decode_uri_component_function() const { return *m_decode_uri_component_function; }
NonnullGCPtr<FunctionObject> encode_uri_function() const { return *m_encode_uri_function; }
NonnullGCPtr<FunctionObject> encode_uri_component_function() const { return *m_encode_uri_component_function; }
NonnullGCPtr<FunctionObject> escape_function() const { return *m_escape_function; }
NonnullGCPtr<FunctionObject> unescape_function() const { return *m_unescape_function; }
// Namespace/constructor object functions
FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; }
FunctionObject* date_constructor_now_function() const { return m_date_constructor_now_function; }
FunctionObject* json_parse_function() const { return m_json_parse_function; }
FunctionObject* json_stringify_function() const { return m_json_stringify_function; }
FunctionObject* object_prototype_to_string_function() const { return m_object_prototype_to_string_function; }
FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; }
NonnullGCPtr<FunctionObject> array_prototype_values_function() const { return *m_array_prototype_values_function; }
NonnullGCPtr<FunctionObject> date_constructor_now_function() const { return *m_date_constructor_now_function; }
NonnullGCPtr<FunctionObject> json_parse_function() const { return *m_json_parse_function; }
NonnullGCPtr<FunctionObject> json_stringify_function() const { return *m_json_stringify_function; }
NonnullGCPtr<FunctionObject> object_prototype_to_string_function() const { return *m_object_prototype_to_string_function; }
NonnullGCPtr<FunctionObject> throw_type_error_function() const { return *m_throw_type_error_function; }
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
ConstructorName* snake_name##_constructor(); \
Object* snake_name##_prototype();
NonnullGCPtr<ConstructorName> snake_name##_constructor(); \
NonnullGCPtr<Object> snake_name##_prototype();
JS_ENUMERATE_BUILTIN_TYPES
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
Intl::ConstructorName* intl_##snake_name##_constructor(); \
Object* intl_##snake_name##_prototype();
NonnullGCPtr<Intl::ConstructorName> intl_##snake_name##_constructor(); \
NonnullGCPtr<Object> intl_##snake_name##_prototype();
JS_ENUMERATE_INTL_OBJECTS
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
Temporal::ConstructorName* temporal_##snake_name##_constructor(); \
Object* temporal_##snake_name##_prototype();
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
NonnullGCPtr<Temporal::ConstructorName> temporal_##snake_name##_constructor(); \
NonnullGCPtr<Object> temporal_##snake_name##_prototype();
JS_ENUMERATE_TEMPORAL_OBJECTS
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(ClassName, snake_name) \
ClassName* snake_name##_object();
NonnullGCPtr<ClassName> snake_name##_object();
JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(ClassName, snake_name) \
Object* snake_name##_prototype() \
{ \
return m_##snake_name##_prototype; \
#define __JS_ENUMERATE(ClassName, snake_name) \
NonnullGCPtr<Object> snake_name##_prototype() \
{ \
return *m_##snake_name##_prototype; \
}
JS_ENUMERATE_ITERATOR_PROTOTYPES
#undef __JS_ENUMERATE

View file

@ -12,7 +12,7 @@ namespace JS {
// 27.1.2 The %IteratorPrototype% Object, https://tc39.es/ecma262/#sec-%iteratorprototype%-object
IteratorPrototype::IteratorPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}

View file

@ -27,7 +27,7 @@
namespace JS {
JSONObject::JSONObject(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}

View file

@ -10,7 +10,7 @@ namespace JS {
NonnullGCPtr<Map> Map::create(Realm& realm)
{
return realm.heap().allocate<Map>(realm, *realm.intrinsics().map_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<Map>(realm, realm.intrinsics().map_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
Map::Map(Object& prototype)

View file

@ -14,7 +14,7 @@
namespace JS {
MapConstructor::MapConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Map.as_string(), *realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Map.as_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<MapIterator> MapIterator::create(Realm& realm, Map& map, Object::PropertyKind iteration_kind)
{
return realm.heap().allocate<MapIterator>(realm, map, iteration_kind, *realm.intrinsics().map_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<MapIterator>(realm, map, iteration_kind, realm.intrinsics().map_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype)

View file

@ -14,7 +14,7 @@
namespace JS {
MapIteratorPrototype::MapIteratorPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().iterator_prototype())
: PrototypeObject(realm.intrinsics().iterator_prototype())
{
}

View file

@ -13,7 +13,7 @@
namespace JS {
MapPrototype::MapPrototype(Realm& realm)
: PrototypeObject(*realm.intrinsics().object_prototype())
: PrototypeObject(realm.intrinsics().object_prototype())
{
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -16,7 +16,7 @@
namespace JS {
MathObject::MathObject(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}

View file

@ -11,7 +11,7 @@
namespace JS {
ModuleNamespaceObject::ModuleNamespaceObject(Realm& realm, Module* module, Vector<DeprecatedFlyString> exports)
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
, m_module(module)
, m_exports(move(exports))
{

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -53,7 +53,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Saf
NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& realm, DeprecatedFlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)> function)
{
return realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
return realm.heap().allocate<NativeFunction>(realm, name, move(function), realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NativeFunction::NativeFunction(SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm)

Some files were not shown because too many files have changed in this diff Show more