1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

LibJS: Move intrinsics to the realm

Intrinsics, i.e. mostly constructor and prototype objects, but also
things like empty and new object shape now live on a new heap-allocated
JS::Intrinsics object, thus completing the long journey of taking all
the magic away from the global object.
This represents the Realm's [[Intrinsics]] slot in the spec and matches
its existing [[GlobalObject]] / [[GlobalEnv]] slots in terms of
architecture.

In the majority of cases it should now be possibly to fully allocate a
regular object without the global object existing, and in fact that's
what we do now - the realm is allocated before the global object, and
the intrinsics between both :^)
This commit is contained in:
Linus Groh 2022-08-27 00:54:55 +01:00
parent 84c4b66721
commit 50428ea8d2
217 changed files with 1305 additions and 1039 deletions

View file

@ -442,7 +442,7 @@ Completion CallExpression::execute(Interpreter& interpreter) const
auto& function = callee.as_function();
if (&function == realm.global_object().eval_function()
if (&function == realm.intrinsics().eval_function()
&& callee_reference.is_environment_reference()
&& callee_reference.name().is_string()
&& callee_reference.name().as_string() == vm.names.eval.as_string()) {
@ -1829,9 +1829,8 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
class_private_environment->add_private_name({}, opt_private_name.release_value());
}
auto* proto_parent = vm.current_realm()->global_object().object_prototype();
auto* constructor_parent = vm.current_realm()->global_object().function_prototype();
auto* proto_parent = 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;
@ -3036,7 +3035,7 @@ Completion ObjectExpression::execute(Interpreter& interpreter) const
auto& realm = *vm.current_realm();
// 1. Let obj be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// 2. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with argument obj.
for (auto& property : m_properties) {
@ -3347,7 +3346,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const
// Note: options_value is undefined by default.
// 6. Let promiseCapability be ! NewPromiseCapability(%Promise%).
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor()));
// 7. Let specifierString be Completion(ToString(specifier)).
// 8. IfAbruptRejectPromise(specifierString, promiseCapability).