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

LibJS+LibWeb: Replace GlobalObject with Realm in object constructors

No functional changes - we can still very easily get to the global
object via `Realm::global_object()`. This is in preparation of moving
the intrinsics to the realm and no longer having to pass a global
object when allocating any object.
In a few (now, and many more in subsequent commits) places we get a
realm using `GlobalObject::associated_realm()`, this is intended to be
temporary. For example, create() functions will later receive the same
treatment and are passed a realm instead of a global object.
This commit is contained in:
Linus Groh 2022-08-16 00:20:49 +01:00
parent 4c300cc5e8
commit ecd163bdf1
315 changed files with 592 additions and 554 deletions

View file

@ -1837,7 +1837,7 @@ class @wrapper_class@ : public @wrapper_base_class@ {
public:
static @wrapper_class@* create(JS::GlobalObject&, @fully_qualified_name@&);
@wrapper_class@(JS::GlobalObject&, @fully_qualified_name@&);
@wrapper_class@(JS::Realm&, @fully_qualified_name@&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~@wrapper_class@() override;
)~~~");
@ -2004,25 +2004,26 @@ namespace Web::Bindings {
@wrapper_class@* @wrapper_class@::create(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
{
return global_object.heap().allocate<@wrapper_class@>(global_object, global_object, impl);
auto& realm = *global_object.associated_realm();
return global_object.heap().allocate<@wrapper_class@>(global_object, realm, impl);
}
)~~~");
if (interface.wrapper_base_class == "Wrapper") {
generator.append(R"~~~(
@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
: Wrapper(static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_class@>("@name@"))
@wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl)
: Wrapper(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@"))
, m_impl(impl)
{
}
)~~~");
} else {
generator.append(R"~~~(
@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
: @wrapper_base_class@(global_object, impl)
@wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl)
: @wrapper_base_class@(realm, impl)
{
set_prototype(&static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_class@>("@name@"));
set_prototype(&static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@"));
}
)~~~");
}
@ -2798,7 +2799,7 @@ namespace Web::Bindings {
class @constructor_class@ : public JS::NativeFunction {
JS_OBJECT(@constructor_class@, JS::NativeFunction);
public:
explicit @constructor_class@(JS::GlobalObject&);
explicit @constructor_class@(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~@constructor_class@() override;
@ -2927,8 +2928,8 @@ using namespace Web::WebGL;
namespace Web::Bindings {
@constructor_class@::@constructor_class@(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
@constructor_class@::@constructor_class@(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}
@ -3065,7 +3066,7 @@ namespace Web::Bindings {
class @prototype_class@ : public JS::Object {
JS_OBJECT(@prototype_class@, JS::Object);
public:
explicit @prototype_class@(JS::GlobalObject&);
explicit @prototype_class@(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~@prototype_class@() override;
private:
@ -3210,20 +3211,20 @@ using namespace Web::WebGL;
namespace Web::Bindings {
@prototype_class@::@prototype_class@([[maybe_unused]] JS::GlobalObject& global_object))~~~");
@prototype_class@::@prototype_class@([[maybe_unused]] JS::Realm& realm))~~~");
if (interface.name == "DOMException") {
// https://webidl.spec.whatwg.org/#es-DOMException-specialness
// Object.getPrototypeOf(DOMException.prototype) === Error.prototype
generator.append(R"~~~(
: Object(*global_object.error_prototype())
: Object(*realm.global_object().error_prototype())
)~~~");
} else if (!interface.parent_name.is_empty()) {
generator.append(R"~~~(
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_base_class@>("@parent_name@"))
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_base_class@>("@parent_name@"))
)~~~");
} else {
generator.append(R"~~~(
: Object(*global_object.object_prototype())
: Object(*realm.global_object().object_prototype())
)~~~");
}
@ -3587,7 +3588,7 @@ class @wrapper_class@ : public Wrapper {
public:
static @wrapper_class@* create(JS::GlobalObject&, @fully_qualified_name@&);
@wrapper_class@(JS::GlobalObject&, @fully_qualified_name@&);
@wrapper_class@(JS::Realm&, @fully_qualified_name@&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~@wrapper_class@() override;
@ -3659,11 +3660,12 @@ namespace Web::Bindings {
@wrapper_class@* @wrapper_class@::create(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
{
return global_object.heap().allocate<@wrapper_class@>(global_object, global_object, impl);
auto& realm = *global_object.associated_realm();
return global_object.heap().allocate<@wrapper_class@>(global_object, realm, impl);
}
@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
: Wrapper(static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_class@>("@name@"))
@wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl)
: Wrapper(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@"))
, m_impl(impl)
{
}
@ -3712,7 +3714,7 @@ namespace Web::Bindings {
class @prototype_class@ : public JS::Object {
JS_OBJECT(@prototype_class@, JS::Object);
public:
explicit @prototype_class@(JS::GlobalObject&);
explicit @prototype_class@(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~@prototype_class@() override;
@ -3776,8 +3778,8 @@ using namespace Web::WebGL;
namespace Web::Bindings {
@prototype_class@::@prototype_class@(JS::GlobalObject& global_object)
: Object(*global_object.iterator_prototype())
@prototype_class@::@prototype_class@(JS::Realm& realm)
: Object(*realm.global_object().iterator_prototype())
{
}

View file

@ -365,8 +365,8 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound)
return JS::Value(bounds.row);
}
WorkbookObject::WorkbookObject(Workbook& workbook, JS::GlobalObject& global_object)
: JS::Object(*JS::Object::create(global_object, global_object.object_prototype()))
WorkbookObject::WorkbookObject(JS::Realm& realm, Workbook& workbook)
: JS::Object(*realm.global_object().object_prototype())
, m_workbook(workbook)
{
}

View file

@ -50,7 +50,7 @@ class WorkbookObject final : public JS::Object {
JS_OBJECT(WorkbookObject, JS::Object);
public:
WorkbookObject(Workbook&, JS::GlobalObject&);
WorkbookObject(JS::Realm&, Workbook&);
virtual ~WorkbookObject() override = default;

View file

@ -29,7 +29,7 @@ Workbook::Workbook(NonnullRefPtrVector<Sheet>&& sheets, GUI::Window& parent_wind
, m_main_execution_context(m_vm->heap())
, m_parent_window(parent_window)
{
m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), *this, m_interpreter->global_object());
m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), m_interpreter->realm(), *this);
m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes);
m_main_execution_context.current_node = nullptr;

View file

@ -18,8 +18,8 @@
namespace JS::Test262 {
$262Object::$262Object(JS::GlobalObject& global_object)
: Object(Object::ConstructWithoutPrototypeTag::Tag, global_object)
$262Object::$262Object(Realm& realm)
: Object(Object::ConstructWithoutPrototypeTag::Tag, realm)
{
}
@ -27,8 +27,9 @@ void $262Object::initialize(JS::GlobalObject& global_object)
{
Base::initialize(global_object);
m_agent = vm().heap().allocate<AgentObject>(global_object, global_object);
m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(global_object, global_object);
auto& realm = *global_object.associated_realm();
m_agent = vm().heap().allocate<AgentObject>(global_object, realm);
m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(global_object, realm);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function("clearKeptObjects", clear_kept_objects, 0, attr);

View file

@ -17,7 +17,7 @@ class $262Object final : public Object {
JS_OBJECT($262Object, Object);
public:
$262Object(JS::GlobalObject&);
explicit $262Object(Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~$262Object() override = default;

View file

@ -12,8 +12,8 @@
namespace JS::Test262 {
AgentObject::AgentObject(JS::GlobalObject& global_object)
: Object(Object::ConstructWithoutPrototypeTag::Tag, global_object)
AgentObject::AgentObject(Realm& realm)
: Object(Object::ConstructWithoutPrototypeTag::Tag, realm)
{
}

View file

@ -15,7 +15,7 @@ class AgentObject final : public Object {
JS_OBJECT(AgentObject, Object);
public:
AgentObject(JS::GlobalObject&);
explicit AgentObject(Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~AgentObject() override = default;

View file

@ -18,7 +18,8 @@ void GlobalObject::initialize_global_object()
{
Base::initialize_global_object();
m_$262 = vm().heap().allocate<$262Object>(*this, *this);
auto& realm = *associated_realm();
m_$262 = vm().heap().allocate<$262Object>(*this, realm);
// https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
u8 attr = Attribute::Writable | Attribute::Configurable;

View file

@ -9,9 +9,9 @@
namespace JS::Test262 {
IsHTMLDDA::IsHTMLDDA(JS::GlobalObject& global_object)
IsHTMLDDA::IsHTMLDDA(Realm& realm)
// NativeFunction without prototype is currently not possible (only due to the lack of a ctor that supports it)
: NativeFunction("IsHTMLDDA", *global_object.function_prototype())
: NativeFunction("IsHTMLDDA", *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class IsHTMLDDA final : public NativeFunction {
JS_OBJECT(IsHTMLDDA, NativeFunction);
public:
explicit IsHTMLDDA(JS::GlobalObject&);
explicit IsHTMLDDA(Realm&);
virtual ~IsHTMLDDA() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -97,7 +97,7 @@ Object* Module::module_namespace_create(VM& vm, Vector<FlyString> unambiguous_na
// 6. Let sortedExports be a List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using undefined as comparefn.
// 7. Set M.[[Exports]] to sortedExports.
// 8. Create own properties of M corresponding to the definitions in 28.3.
Object* module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm().global_object(), realm().global_object(), this, move(unambiguous_names));
Object* module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm().global_object(), realm(), this, move(unambiguous_names));
// 9. Set module.[[Namespace]] to M.
m_namespace = make_handle(module_namespace);

View file

@ -1076,6 +1076,7 @@ Object* create_unmapped_arguments_object(GlobalObject& global_object, Span<Value
Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObject& function, Vector<FunctionNode::Parameter> const& formals, Span<Value> arguments, Environment& environment)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
// 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers. It may contain duplicate identifiers.
@ -1090,7 +1091,7 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje
// 7. Set obj.[[Set]] as specified in 10.4.4.4.
// 8. Set obj.[[Delete]] as specified in 10.4.4.5.
// 9. Set obj.[[Prototype]] to %Object.prototype%.
auto* object = vm.heap().allocate<ArgumentsObject>(global_object, global_object, environment);
auto* object = vm.heap().allocate<ArgumentsObject>(global_object, realm, environment);
// 14. Let index be 0.
// 15. Repeat, while index < len,

View file

@ -14,8 +14,8 @@
namespace JS {
AggregateErrorConstructor::AggregateErrorConstructor(GlobalObject& global_object)
: NativeFunction(*static_cast<Object*>(global_object.error_constructor()))
AggregateErrorConstructor::AggregateErrorConstructor(Realm& realm)
: NativeFunction(static_cast<Object&>(*realm.global_object().error_constructor()))
{
}

View file

@ -14,7 +14,7 @@ class AggregateErrorConstructor final : public NativeFunction {
JS_OBJECT(AggregateErrorConstructor, NativeFunction);
public:
explicit AggregateErrorConstructor(GlobalObject&);
explicit AggregateErrorConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AggregateErrorConstructor() override = default;

View file

@ -10,8 +10,8 @@
namespace JS {
AggregateErrorPrototype::AggregateErrorPrototype(GlobalObject& global_object)
: Object(*global_object.error_prototype())
AggregateErrorPrototype::AggregateErrorPrototype(Realm& realm)
: Object(*realm.global_object().error_prototype())
{
}

View file

@ -14,7 +14,7 @@ class AggregateErrorPrototype final : public Object {
JS_OBJECT(AggregateErrorPrototype, Object);
public:
explicit AggregateErrorPrototype(GlobalObject&);
explicit AggregateErrorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AggregateErrorPrototype() override = default;
};

View file

@ -10,8 +10,8 @@
namespace JS {
ArgumentsObject::ArgumentsObject(GlobalObject& global_object, Environment& environment)
: Object(*global_object.object_prototype())
ArgumentsObject::ArgumentsObject(Realm& realm, Environment& environment)
: Object(*realm.global_object().object_prototype())
, m_environment(environment)
{
}

View file

@ -16,7 +16,7 @@ class ArgumentsObject final : public Object {
JS_OBJECT(ArgumentsObject, Object);
public:
ArgumentsObject(GlobalObject&, Environment&);
ArgumentsObject(Realm&, Environment&);
virtual void initialize(GlobalObject&) override;
virtual ~ArgumentsObject() override = default;

View file

@ -13,8 +13,8 @@
namespace JS {
ArrayBufferConstructor::ArrayBufferConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.ArrayBuffer.as_string(), *global_object.function_prototype())
ArrayBufferConstructor::ArrayBufferConstructor(Realm& realm)
: NativeFunction(vm().names.ArrayBuffer.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class ArrayBufferConstructor final : public NativeFunction {
JS_OBJECT(ArrayBufferConstructor, NativeFunction);
public:
explicit ArrayBufferConstructor(GlobalObject&);
explicit ArrayBufferConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ArrayBufferConstructor() override = default;

View file

@ -14,8 +14,8 @@
namespace JS {
ArrayBufferPrototype::ArrayBufferPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.object_prototype())
ArrayBufferPrototype::ArrayBufferPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
{
}

View file

@ -15,7 +15,7 @@ class ArrayBufferPrototype final : public PrototypeObject<ArrayBufferPrototype,
JS_PROTOTYPE_OBJECT(ArrayBufferPrototype, ArrayBuffer, ArrayBuffer);
public:
explicit ArrayBufferPrototype(GlobalObject&);
explicit ArrayBufferPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ArrayBufferPrototype() override = default;

View file

@ -16,8 +16,8 @@
namespace JS {
ArrayConstructor::ArrayConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.Array.as_string(), *global_object.function_prototype())
ArrayConstructor::ArrayConstructor(Realm& realm)
: NativeFunction(vm().names.Array.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class ArrayConstructor final : public NativeFunction {
JS_OBJECT(ArrayConstructor, NativeFunction);
public:
explicit ArrayConstructor(GlobalObject&);
explicit ArrayConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ArrayConstructor() override = default;

View file

@ -14,8 +14,8 @@
namespace JS {
ArrayIteratorPrototype::ArrayIteratorPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.iterator_prototype())
ArrayIteratorPrototype::ArrayIteratorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().iterator_prototype())
{
}

View file

@ -15,7 +15,7 @@ class ArrayIteratorPrototype final : public PrototypeObject<ArrayIteratorPrototy
JS_PROTOTYPE_OBJECT(ArrayIteratorPrototype, ArrayIterator, ArrayIterator);
public:
ArrayIteratorPrototype(GlobalObject&);
ArrayIteratorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ArrayIteratorPrototype() override = default;

View file

@ -28,8 +28,8 @@ namespace JS {
static HashTable<Object*> s_array_join_seen_objects;
ArrayPrototype::ArrayPrototype(GlobalObject& global_object)
: Array(*global_object.object_prototype())
ArrayPrototype::ArrayPrototype(Realm& realm)
: Array(*realm.global_object().object_prototype())
{
}

View file

@ -15,7 +15,7 @@ class ArrayPrototype final : public Array {
JS_OBJECT(ArrayPrototype, Array);
public:
ArrayPrototype(GlobalObject&);
ArrayPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ArrayPrototype() override = default;

View file

@ -13,11 +13,12 @@ namespace JS {
AsyncFromSyncIterator* AsyncFromSyncIterator::create(GlobalObject& global_object, Iterator sync_iterator_record)
{
return global_object.heap().allocate<AsyncFromSyncIterator>(global_object, global_object, sync_iterator_record);
auto& realm = *global_object.associated_realm();
return global_object.heap().allocate<AsyncFromSyncIterator>(global_object, realm, sync_iterator_record);
}
AsyncFromSyncIterator::AsyncFromSyncIterator(GlobalObject& global_object, Iterator sync_iterator_record)
: Object(*global_object.async_from_sync_iterator_prototype())
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record)
: Object(*realm.global_object().async_from_sync_iterator_prototype())
, m_sync_iterator_record(sync_iterator_record)
{
}

View file

@ -19,7 +19,7 @@ class AsyncFromSyncIterator final : public Object {
public:
static AsyncFromSyncIterator* create(GlobalObject&, Iterator sync_iterator_record);
explicit AsyncFromSyncIterator(GlobalObject&, Iterator sync_iterator_record);
explicit AsyncFromSyncIterator(Realm&, Iterator sync_iterator_record);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncFromSyncIterator() override = default;

View file

@ -14,8 +14,8 @@
namespace JS {
AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.async_iterator_prototype())
AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().async_iterator_prototype())
{
}

View file

@ -19,7 +19,7 @@ class AsyncFromSyncIteratorPrototype final : public PrototypeObject<AsyncFromSyn
JS_PROTOTYPE_OBJECT(AsyncFromSyncIteratorPrototype, AsyncFromSyncIterator, AsyncFromSyncIterator);
public:
explicit AsyncFromSyncIteratorPrototype(GlobalObject&);
explicit AsyncFromSyncIteratorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncFromSyncIteratorPrototype() override = default;

View file

@ -12,8 +12,8 @@
namespace JS {
AsyncFunctionConstructor::AsyncFunctionConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.AsyncFunction.as_string(), *global_object.function_constructor())
AsyncFunctionConstructor::AsyncFunctionConstructor(Realm& realm)
: NativeFunction(vm().names.AsyncFunction.as_string(), *realm.global_object().function_constructor())
{
}

View file

@ -15,7 +15,7 @@ class AsyncFunctionConstructor final : public NativeFunction {
JS_OBJECT(AsyncFunctionConstructor, NativeFunction);
public:
explicit AsyncFunctionConstructor(GlobalObject&);
explicit AsyncFunctionConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncFunctionConstructor() override = default;

View file

@ -14,17 +14,18 @@ namespace JS {
ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(GlobalObject& global_object, GeneratorObject* generator_object)
{
auto wrapper = global_object.heap().allocate<AsyncFunctionDriverWrapper>(global_object, global_object, generator_object);
auto& realm = *global_object.associated_realm();
auto wrapper = global_object.heap().allocate<AsyncFunctionDriverWrapper>(global_object, realm, generator_object);
return wrapper->react_to_async_task_completion(global_object.vm(), global_object, js_undefined(), true);
}
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(GlobalObject& global_object, GeneratorObject* generator_object)
: Promise(*global_object.promise_prototype())
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorObject* generator_object)
: Promise(*realm.global_object().promise_prototype())
, m_generator_object(generator_object)
, m_on_fulfillment(NativeFunction::create(global_object, "async.on_fulfillment"sv, [this](VM& vm, GlobalObject& global_object) {
, m_on_fulfillment(NativeFunction::create(realm.global_object(), "async.on_fulfillment"sv, [this](VM& vm, GlobalObject& global_object) {
return react_to_async_task_completion(vm, global_object, vm.argument(0), true);
}))
, m_on_rejection(NativeFunction::create(global_object, "async.on_rejection"sv, [this](VM& vm, GlobalObject& global_object) {
, m_on_rejection(NativeFunction::create(realm.global_object(), "async.on_rejection"sv, [this](VM& vm, GlobalObject& global_object) {
return react_to_async_task_completion(vm, global_object, vm.argument(0), false);
}))
{

View file

@ -19,7 +19,7 @@ class AsyncFunctionDriverWrapper final : public Promise {
public:
static ThrowCompletionOr<Value> create(GlobalObject&, GeneratorObject*);
explicit AsyncFunctionDriverWrapper(GlobalObject&, GeneratorObject*);
explicit AsyncFunctionDriverWrapper(Realm&, GeneratorObject*);
virtual ~AsyncFunctionDriverWrapper() override = default;
void visit_edges(Cell::Visitor&) override;

View file

@ -9,8 +9,8 @@
namespace JS {
AsyncFunctionPrototype::AsyncFunctionPrototype(GlobalObject& global_object)
: Object(*global_object.function_prototype())
AsyncFunctionPrototype::AsyncFunctionPrototype(Realm& realm)
: Object(*realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class AsyncFunctionPrototype final : public Object {
JS_OBJECT(AsyncFunctionPrototype, Object);
public:
explicit AsyncFunctionPrototype(GlobalObject&);
explicit AsyncFunctionPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncFunctionPrototype() override = default;
};

View file

@ -12,8 +12,8 @@
namespace JS {
AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.AsyncGeneratorFunction.as_string(), *global_object.function_prototype())
AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(Realm& realm)
: NativeFunction(vm().names.AsyncGeneratorFunction.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class AsyncGeneratorFunctionConstructor final : public NativeFunction {
JS_OBJECT(AsyncGeneratorFunctionConstructor, NativeFunction);
public:
explicit AsyncGeneratorFunctionConstructor(GlobalObject&);
explicit AsyncGeneratorFunctionConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncGeneratorFunctionConstructor() override = default;

View file

@ -11,8 +11,8 @@
namespace JS {
AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.function_prototype())
AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class AsyncGeneratorFunctionPrototype final : public PrototypeObject<AsyncGenera
JS_PROTOTYPE_OBJECT(AsyncGeneratorFunctionPrototype, AsyncGeneratorFunction, AsyncGeneratorFunction);
public:
explicit AsyncGeneratorFunctionPrototype(GlobalObject&);
explicit AsyncGeneratorFunctionPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncGeneratorFunctionPrototype() override = default;
};

View file

@ -9,8 +9,8 @@
namespace JS {
// 27.6.1 Properties of the AsyncGenerator Prototype Object, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-prototype
AsyncGeneratorPrototype::AsyncGeneratorPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.async_iterator_prototype())
AsyncGeneratorPrototype::AsyncGeneratorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().async_iterator_prototype())
{
}

View file

@ -15,7 +15,7 @@ class AsyncGeneratorPrototype final : public PrototypeObject<AsyncGeneratorProto
JS_PROTOTYPE_OBJECT(AsyncGeneratorPrototype, AsyncGenerator, AsyncGenerator)
public:
explicit AsyncGeneratorPrototype(GlobalObject&);
explicit AsyncGeneratorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncGeneratorPrototype() override = default;
};

View file

@ -8,8 +8,8 @@
namespace JS {
AsyncIteratorPrototype::AsyncIteratorPrototype(GlobalObject& global_object)
: Object(*global_object.object_prototype())
AsyncIteratorPrototype::AsyncIteratorPrototype(Realm& realm)
: Object(*realm.global_object().object_prototype())
{
}

View file

@ -14,7 +14,7 @@ class AsyncIteratorPrototype final : public Object {
JS_OBJECT(AsyncIteratorPrototype, Object)
public:
explicit AsyncIteratorPrototype(GlobalObject&);
explicit AsyncIteratorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncIteratorPrototype() override = default;

View file

@ -129,8 +129,8 @@ static ThrowCompletionOr<Value> perform_atomic_operation(GlobalObject& global_ob
return atomic_read_modify_write(global_object, typed_array, index, value, move(operation_wrapper));
}
AtomicsObject::AtomicsObject(GlobalObject& global_object)
: Object(*global_object.object_prototype())
AtomicsObject::AtomicsObject(Realm& realm)
: Object(*realm.global_object().object_prototype())
{
}

View file

@ -14,7 +14,7 @@ class AtomicsObject : public Object {
JS_OBJECT(AtomicsObject, Object);
public:
explicit AtomicsObject(GlobalObject&);
explicit AtomicsObject(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~AtomicsObject() override = default;

View file

@ -17,8 +17,8 @@ namespace JS {
static const Crypto::SignedBigInteger BIGINT_ONE { 1 };
BigIntConstructor::BigIntConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.BigInt.as_string(), *global_object.function_prototype())
BigIntConstructor::BigIntConstructor(Realm& realm)
: NativeFunction(vm().names.BigInt.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class BigIntConstructor final : public NativeFunction {
JS_OBJECT(BigIntConstructor, NativeFunction);
public:
explicit BigIntConstructor(GlobalObject&);
explicit BigIntConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~BigIntConstructor() override = default;

View file

@ -17,8 +17,8 @@
namespace JS {
BigIntPrototype::BigIntPrototype(GlobalObject& global_object)
: Object(*global_object.object_prototype())
BigIntPrototype::BigIntPrototype(Realm& realm)
: Object(*realm.global_object().object_prototype())
{
}

View file

@ -14,7 +14,7 @@ class BigIntPrototype final : public Object {
JS_OBJECT(BigIntPrototype, Object);
public:
explicit BigIntPrototype(GlobalObject&);
explicit BigIntPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~BigIntPrototype() override = default;

View file

@ -11,8 +11,8 @@
namespace JS {
BooleanConstructor::BooleanConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.Boolean.as_string(), *global_object.function_prototype())
BooleanConstructor::BooleanConstructor(Realm& realm)
: NativeFunction(vm().names.Boolean.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class BooleanConstructor final : public NativeFunction {
JS_OBJECT(BooleanConstructor, NativeFunction);
public:
explicit BooleanConstructor(GlobalObject&);
explicit BooleanConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~BooleanConstructor() override = default;

View file

@ -12,8 +12,8 @@
namespace JS {
BooleanPrototype::BooleanPrototype(GlobalObject& global_object)
: BooleanObject(false, *global_object.object_prototype())
BooleanPrototype::BooleanPrototype(Realm& realm)
: BooleanObject(false, *realm.global_object().object_prototype())
{
}

View file

@ -14,7 +14,7 @@ class BooleanPrototype final : public BooleanObject {
JS_OBJECT(BooleanPrototype, BooleanObject);
public:
explicit BooleanPrototype(GlobalObject&);
explicit BooleanPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~BooleanPrototype() override = default;

View file

@ -14,6 +14,8 @@ namespace JS {
// 10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs ), https://tc39.es/ecma262/#sec-boundfunctioncreate
ThrowCompletionOr<BoundFunction*> BoundFunction::create(GlobalObject& global_object, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments)
{
auto& realm = *global_object.associated_realm();
// 1. Let proto be ? targetFunction.[[GetPrototypeOf]]().
auto* prototype = TRY(target_function.internal_get_prototype_of());
@ -26,14 +28,14 @@ ThrowCompletionOr<BoundFunction*> BoundFunction::create(GlobalObject& global_obj
// 7. Set obj.[[BoundTargetFunction]] to targetFunction.
// 8. Set obj.[[BoundThis]] to boundThis.
// 9. Set obj.[[BoundArguments]] to boundArgs.
auto* object = global_object.heap().allocate<BoundFunction>(global_object, global_object, target_function, bound_this, move(bound_arguments), prototype);
auto* object = global_object.heap().allocate<BoundFunction>(global_object, realm, target_function, bound_this, move(bound_arguments), prototype);
// 10. Return obj.
return object;
}
BoundFunction::BoundFunction(GlobalObject& global_object, FunctionObject& bound_target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype)
: FunctionObject(global_object, prototype)
BoundFunction::BoundFunction(Realm& realm, FunctionObject& bound_target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype)
: FunctionObject(realm, prototype)
, m_bound_target_function(&bound_target_function)
, m_bound_this(bound_this)
, m_bound_arguments(move(bound_arguments))

View file

@ -17,7 +17,7 @@ class BoundFunction final : public FunctionObject {
public:
static ThrowCompletionOr<BoundFunction*> create(GlobalObject&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments);
BoundFunction(GlobalObject&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype);
BoundFunction(Realm&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype);
virtual ~BoundFunction() override = default;
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, MarkedVector<Value> arguments_list) override;

View file

@ -12,8 +12,8 @@
namespace JS {
ConsoleObject::ConsoleObject(GlobalObject& global_object)
: Object(*global_object.object_prototype())
ConsoleObject::ConsoleObject(Realm& realm)
: Object(*realm.global_object().object_prototype())
{
}

View file

@ -14,7 +14,7 @@ class ConsoleObject final : public Object {
JS_OBJECT(ConsoleObject, Object);
public:
explicit ConsoleObject(GlobalObject&);
explicit ConsoleObject(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ConsoleObject() override = default;

View file

@ -13,8 +13,8 @@
namespace JS {
DataViewConstructor::DataViewConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.DataView.as_string(), *global_object.function_prototype())
DataViewConstructor::DataViewConstructor(Realm& realm)
: NativeFunction(vm().names.DataView.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class DataViewConstructor final : public NativeFunction {
JS_OBJECT(DataViewConstructor, NativeFunction);
public:
explicit DataViewConstructor(GlobalObject&);
explicit DataViewConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~DataViewConstructor() override = default;

View file

@ -10,8 +10,8 @@
namespace JS {
DataViewPrototype::DataViewPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.object_prototype())
DataViewPrototype::DataViewPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
{
}

View file

@ -15,7 +15,7 @@ class DataViewPrototype final : public PrototypeObject<DataViewPrototype, DataVi
JS_PROTOTYPE_OBJECT(DataViewPrototype, DataView, DataView);
public:
DataViewPrototype(GlobalObject&);
DataViewPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~DataViewPrototype() override = default;

View file

@ -162,8 +162,8 @@ static double parse_date_string(String const& date_string)
return NAN;
}
DateConstructor::DateConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.Date.as_string(), *global_object.function_prototype())
DateConstructor::DateConstructor(Realm& realm)
: NativeFunction(vm().names.Date.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class DateConstructor final : public NativeFunction {
JS_OBJECT(DateConstructor, NativeFunction);
public:
explicit DateConstructor(GlobalObject&);
explicit DateConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~DateConstructor() override = default;

View file

@ -30,8 +30,8 @@
namespace JS {
DatePrototype::DatePrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.object_prototype())
DatePrototype::DatePrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
{
}

View file

@ -15,7 +15,7 @@ class DatePrototype final : public PrototypeObject<DatePrototype, Date> {
JS_PROTOTYPE_OBJECT(DatePrototype, Date, Date);
public:
explicit DatePrototype(GlobalObject&);
explicit DatePrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~DatePrototype() override = default;

View file

@ -11,8 +11,8 @@
namespace JS {
ErrorConstructor::ErrorConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.Error.as_string(), *global_object.function_prototype())
ErrorConstructor::ErrorConstructor(Realm& realm)
: NativeFunction(vm().names.Error.as_string(), *realm.global_object().function_prototype())
{
}
@ -63,8 +63,8 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
ConstructorName::ConstructorName(GlobalObject& global_object) \
: NativeFunction(vm().names.ClassName.as_string(), *static_cast<Object*>(global_object.error_constructor())) \
ConstructorName::ConstructorName(Realm& realm) \
: NativeFunction(vm().names.ClassName.as_string(), *static_cast<Object*>(realm.global_object().error_constructor())) \
{ \
} \
\

View file

@ -15,7 +15,7 @@ class ErrorConstructor final : public NativeFunction {
JS_OBJECT(ErrorConstructor, NativeFunction);
public:
explicit ErrorConstructor(GlobalObject&);
explicit ErrorConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ErrorConstructor() override = default;
@ -31,7 +31,7 @@ private:
JS_OBJECT(ConstructorName, NativeFunction); \
\
public: \
explicit ConstructorName(GlobalObject&); \
explicit ConstructorName(Realm&); \
virtual void initialize(GlobalObject&) override; \
virtual ~ConstructorName() override; \
virtual ThrowCompletionOr<Value> call() override; \

View file

@ -15,8 +15,8 @@
namespace JS {
ErrorPrototype::ErrorPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.object_prototype())
ErrorPrototype::ErrorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
{
}
@ -124,8 +124,8 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_setter)
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
PrototypeName::PrototypeName(GlobalObject& global_object) \
: PrototypeObject(*global_object.error_prototype()) \
PrototypeName::PrototypeName(Realm& realm) \
: PrototypeObject(*realm.global_object().error_prototype()) \
{ \
} \
\

View file

@ -16,7 +16,7 @@ class ErrorPrototype final : public PrototypeObject<ErrorPrototype, Error> {
JS_PROTOTYPE_OBJECT(ErrorPrototype, Error, Error);
public:
explicit ErrorPrototype(GlobalObject&);
explicit ErrorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~ErrorPrototype() override = default;
@ -31,7 +31,7 @@ private:
JS_PROTOTYPE_OBJECT(PrototypeName, ClassName, ClassName); \
\
public: \
explicit PrototypeName(GlobalObject&); \
explicit PrototypeName(Realm&); \
virtual void initialize(GlobalObject&) override; \
virtual ~PrototypeName() override = default; \
};

View file

@ -13,8 +13,8 @@
namespace JS {
FinalizationRegistryConstructor::FinalizationRegistryConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.FinalizationRegistry.as_string(), *global_object.function_prototype())
FinalizationRegistryConstructor::FinalizationRegistryConstructor(Realm& realm)
: NativeFunction(vm().names.FinalizationRegistry.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class FinalizationRegistryConstructor final : public NativeFunction {
JS_OBJECT(FinalizationRegistryConstructor, NativeFunction);
public:
explicit FinalizationRegistryConstructor(GlobalObject&);
explicit FinalizationRegistryConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~FinalizationRegistryConstructor() override = default;

View file

@ -9,8 +9,8 @@
namespace JS {
FinalizationRegistryPrototype::FinalizationRegistryPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.object_prototype())
FinalizationRegistryPrototype::FinalizationRegistryPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
{
}

View file

@ -15,7 +15,7 @@ class FinalizationRegistryPrototype final : public PrototypeObject<FinalizationR
JS_PROTOTYPE_OBJECT(FinalizationRegistryPrototype, FinalizationRegistry, FinalizationRegistry);
public:
FinalizationRegistryPrototype(GlobalObject&);
FinalizationRegistryPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~FinalizationRegistryPrototype() override = default;

View file

@ -19,8 +19,8 @@
namespace JS {
FunctionConstructor::FunctionConstructor(GlobalObject& global_object)
: NativeFunction(vm().names.Function.as_string(), *global_object.function_prototype())
FunctionConstructor::FunctionConstructor(Realm& realm)
: NativeFunction(vm().names.Function.as_string(), *realm.global_object().function_prototype())
{
}

View file

@ -17,7 +17,7 @@ class FunctionConstructor final : public NativeFunction {
public:
static ThrowCompletionOr<ECMAScriptFunctionObject*> create_dynamic_function(GlobalObject& global_object, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, MarkedVector<Value> const& args);
explicit FunctionConstructor(GlobalObject&);
explicit FunctionConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~FunctionConstructor() override = default;

View file

@ -11,8 +11,8 @@
namespace JS {
FunctionObject::FunctionObject(GlobalObject& global_object, Object* prototype)
: Object(global_object, prototype)
FunctionObject::FunctionObject(Realm& realm, Object* prototype)
: Object(realm, prototype)
{
}

View file

@ -40,7 +40,7 @@ public:
virtual Realm* realm() const { return nullptr; }
protected:
explicit FunctionObject(GlobalObject&, Object* prototype);
explicit FunctionObject(Realm&, Object* prototype);
explicit FunctionObject(Object& prototype);
private:

View file

@ -20,8 +20,8 @@
namespace JS {
FunctionPrototype::FunctionPrototype(GlobalObject& global_object)
: FunctionObject(*global_object.object_prototype())
FunctionPrototype::FunctionPrototype(Realm& realm)
: FunctionObject(*realm.global_object().object_prototype())
{
}

View file

@ -14,7 +14,7 @@ class FunctionPrototype final : public FunctionObject {
JS_OBJECT(FunctionPrototype, FunctionObject);
public:
explicit FunctionPrototype(GlobalObject&);
explicit FunctionPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~FunctionPrototype() override = default;

View file

@ -11,8 +11,8 @@
namespace JS {
GeneratorFunctionConstructor::GeneratorFunctionConstructor(GlobalObject& global_object)
: NativeFunction(*static_cast<Object*>(global_object.function_constructor()))
GeneratorFunctionConstructor::GeneratorFunctionConstructor(Realm& realm)
: NativeFunction(static_cast<Object&>(*realm.global_object().function_constructor()))
{
}

View file

@ -15,7 +15,7 @@ class GeneratorFunctionConstructor final : public NativeFunction {
JS_OBJECT(GeneratorFunctionConstructor, NativeFunction);
public:
explicit GeneratorFunctionConstructor(GlobalObject&);
explicit GeneratorFunctionConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~GeneratorFunctionConstructor() override = default;

View file

@ -10,8 +10,8 @@
namespace JS {
GeneratorFunctionPrototype::GeneratorFunctionPrototype(GlobalObject& global_object)
: Object(*global_object.function_prototype())
GeneratorFunctionPrototype::GeneratorFunctionPrototype(Realm& realm)
: Object(*realm.global_object().function_prototype())
{
}

View file

@ -16,7 +16,7 @@ class GeneratorFunctionPrototype final : public Object {
JS_OBJECT(GeneratorFunctionPrototype, Object);
public:
explicit GeneratorFunctionPrototype(GlobalObject&);
explicit GeneratorFunctionPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~GeneratorFunctionPrototype() override = default;
};

View file

@ -15,6 +15,8 @@ namespace JS {
ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(GlobalObject& global_object, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::RegisterWindow frame)
{
auto& realm = *global_object.associated_realm();
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
Value generating_function_prototype;
if (generating_function->kind() == FunctionKind::Async) {
@ -26,14 +28,14 @@ ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(GlobalObject& global
generating_function_prototype = TRY(generating_function->get(global_object.vm().names.prototype));
}
auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(global_object));
auto object = global_object.heap().allocate<GeneratorObject>(global_object, global_object, *generating_function_prototype_object, move(execution_context));
auto object = global_object.heap().allocate<GeneratorObject>(global_object, realm, *generating_function_prototype_object, move(execution_context));
object->m_generating_function = generating_function;
object->m_frame = move(frame);
object->m_previous_value = initial_value;
return object;
}
GeneratorObject::GeneratorObject(GlobalObject&, Object& prototype, ExecutionContext context)
GeneratorObject::GeneratorObject(Realm&, Object& prototype, ExecutionContext context)
: Object(prototype)
, m_execution_context(move(context))
{

View file

@ -17,7 +17,7 @@ class GeneratorObject final : public Object {
public:
static ThrowCompletionOr<GeneratorObject*> create(GlobalObject&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow);
GeneratorObject(GlobalObject&, Object& prototype, ExecutionContext);
GeneratorObject(Realm&, Object& prototype, ExecutionContext);
virtual void initialize(GlobalObject&) override;
virtual ~GeneratorObject() override = default;
void visit_edges(Cell::Visitor&) override;

View file

@ -9,8 +9,8 @@
namespace JS {
GeneratorPrototype::GeneratorPrototype(GlobalObject& global_object)
: PrototypeObject(*global_object.iterator_prototype())
GeneratorPrototype::GeneratorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().iterator_prototype())
{
}

View file

@ -16,7 +16,7 @@ class GeneratorPrototype final : public PrototypeObject<GeneratorPrototype, Gene
JS_PROTOTYPE_OBJECT(GeneratorPrototype, GeneratorObject, Generator);
public:
explicit GeneratorPrototype(GlobalObject&);
explicit GeneratorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~GeneratorPrototype() override = default;

View file

@ -155,8 +155,8 @@ void GlobalObject::initialize_global_object()
VERIFY(associated_realm());
auto& realm = *associated_realm();
m_empty_object_shape = heap().allocate_without_global_object<Shape>(realm);
m_object_prototype = heap().allocate_without_global_object<ObjectPrototype>(*this);
m_function_prototype = heap().allocate_without_global_object<FunctionPrototype>(*this);
m_object_prototype = heap().allocate_without_global_object<ObjectPrototype>(realm);
m_function_prototype = heap().allocate_without_global_object<FunctionPrototype>(realm);
m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(realm);
m_new_object_shape->set_prototype_without_transition(m_object_prototype);
@ -174,29 +174,29 @@ void GlobalObject::initialize_global_object()
Object::set_prototype(m_object_prototype);
// This must be initialized before allocating AggregateErrorPrototype, which uses ErrorPrototype as its prototype.
m_error_prototype = heap().allocate<ErrorPrototype>(*this, *this);
m_error_prototype = heap().allocate<ErrorPrototype>(*this, realm);
#define __JS_ENUMERATE(ClassName, snake_name) \
if (!m_##snake_name##_prototype) \
m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(*this, *this);
m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(*this, realm);
JS_ENUMERATE_ITERATOR_PROTOTYPES
#undef __JS_ENUMERATE
// These must be initialized separately as they have no companion constructor
m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(*this, *this);
m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(*this, *this);
m_generator_prototype = heap().allocate<GeneratorPrototype>(*this, *this);
m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(*this, *this);
m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(*this, realm);
m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(*this, realm);
m_generator_prototype = heap().allocate<GeneratorPrototype>(*this, realm);
m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(*this, realm);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
if (!m_##snake_name##_prototype) \
m_##snake_name##_prototype = heap().allocate<PrototypeName>(*this, *this);
m_##snake_name##_prototype = heap().allocate<PrototypeName>(*this, realm);
JS_ENUMERATE_BUILTIN_TYPES
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
if (!m_intl_##snake_name##_prototype) \
m_intl_##snake_name##_prototype = heap().allocate<Intl::PrototypeName>(*this, *this);
m_intl_##snake_name##_prototype = heap().allocate<Intl::PrototypeName>(*this, realm);
JS_ENUMERATE_INTL_OBJECTS
#undef __JS_ENUMERATE
@ -208,7 +208,7 @@ void GlobalObject::initialize_global_object()
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
if (!m_temporal_##snake_name##_prototype) \
m_temporal_##snake_name##_prototype = heap().allocate<Temporal::PrototypeName>(*this, *this);
m_temporal_##snake_name##_prototype = heap().allocate<Temporal::PrototypeName>(*this, realm);
JS_ENUMERATE_TEMPORAL_OBJECTS
#undef __JS_ENUMERATE
@ -250,13 +250,13 @@ void GlobalObject::initialize_global_object()
define_direct_property(vm.names.undefined, js_undefined(), 0);
define_direct_property(vm.names.globalThis, this, attr);
define_direct_property(vm.names.console, heap().allocate<ConsoleObject>(*this, *this), attr);
define_direct_property(vm.names.Atomics, heap().allocate<AtomicsObject>(*this, *this), attr);
define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, *this), attr);
define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, *this), attr);
define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, *this), attr);
define_direct_property(vm.names.Intl, heap().allocate<Intl::Intl>(*this, *this), attr);
define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(*this, *this), attr);
define_direct_property(vm.names.console, heap().allocate<ConsoleObject>(*this, realm), attr);
define_direct_property(vm.names.Atomics, heap().allocate<AtomicsObject>(*this, realm), attr);
define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, realm), attr);
define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, realm), attr);
define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, realm), attr);
define_direct_property(vm.names.Intl, heap().allocate<Intl::Intl>(*this, realm), attr);
define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(*this, realm), attr);
// This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype.
initialize_constructor(vm.names.Error, m_error_constructor, m_error_prototype);

View file

@ -177,7 +177,8 @@ template<typename ConstructorType>
inline void GlobalObject::initialize_constructor(PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype, PropertyAttributes attributes)
{
auto& vm = this->vm();
constructor = heap().allocate<ConstructorType>(*this, *this);
auto& realm = *associated_realm();
constructor = heap().allocate<ConstructorType>(*this, realm);
constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable);
if (prototype)
prototype->define_direct_property(vm.names.constructor, constructor, attributes);

View file

@ -13,11 +13,12 @@ namespace JS::Intl {
CollatorCompareFunction* CollatorCompareFunction::create(GlobalObject& global_object, Collator& collator)
{
return global_object.heap().allocate<CollatorCompareFunction>(global_object, global_object, collator);
auto& realm = *global_object.associated_realm();
return global_object.heap().allocate<CollatorCompareFunction>(global_object, realm, collator);
}
CollatorCompareFunction::CollatorCompareFunction(GlobalObject& global_object, Collator& collator)
: NativeFunction(*global_object.function_prototype())
CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)
: NativeFunction(*realm.global_object().function_prototype())
, m_collator(collator)
{
}

View file

@ -16,7 +16,7 @@ class CollatorCompareFunction : public NativeFunction {
public:
static CollatorCompareFunction* create(GlobalObject&, Collator&);
explicit CollatorCompareFunction(GlobalObject&, Collator&);
CollatorCompareFunction(Realm&, Collator&);
virtual void initialize(GlobalObject&) override;
virtual ~CollatorCompareFunction() override = default;

View file

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

View file

@ -14,7 +14,7 @@ class CollatorConstructor final : public NativeFunction {
JS_OBJECT(CollatorConstructor, NativeFunction);
public:
explicit CollatorConstructor(GlobalObject&);
explicit CollatorConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~CollatorConstructor() override = default;

View file

@ -12,8 +12,8 @@
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(GlobalObject& global_object)
: PrototypeObject(*global_object.object_prototype())
CollatorPrototype::CollatorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
{
}

View file

@ -15,7 +15,7 @@ class CollatorPrototype final : public PrototypeObject<CollatorPrototype, Collat
JS_PROTOTYPE_OBJECT(CollatorPrototype, Collator, Collator);
public:
explicit CollatorPrototype(GlobalObject&);
explicit CollatorPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual ~CollatorPrototype() override = default;

View file

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

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