summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-08-28 17:09:31 +0100
committerLinus Groh <mail@linusgroh.de>2022-08-28 19:34:10 +0100
commite3804e6426e9a483df23382fe4d6876315b1f7ff (patch)
tree945c57588217da8d5cd68911d6f8fdc13cb192a8 /Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
parent3d5300a25eeaef1e328a973dc13645c1cf948db3 (diff)
downloadserenity-e3804e6426e9a483df23382fe4d6876315b1f7ff.zip
LibJS: Move construction of GlobalObject native functions to Intrinsics
This will later allow global objects not inheriting from the regular JS::GlobalObject to pull in these functions without having to implement them from scratch. The primary use case here is, again, a wrapper-less HTML::Window in LibWeb :^) Allocating these upfront now allows us to get rid of two hacks: - The GlobalObject assigning Intrinsics private members after finishing its initialization - The GlobalObject defining the parseInt and parseFloat properties of the NumberConstructor object, as they are supposed to be identical with the global functions of the same name
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/GlobalObject.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
index 5d147d37eb..b1880e19fe 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -100,15 +100,15 @@ void GlobalObject::initialize(Realm& realm)
u8 attr = Attribute::Writable | Attribute::Configurable;
// 19.2 Function Properties of the Global Object, https://tc39.es/ecma262/#sec-function-properties-of-the-global-object
- define_native_function(realm, vm.names.eval, eval, 1, attr);
- define_native_function(realm, vm.names.isFinite, is_finite, 1, attr);
- define_native_function(realm, vm.names.isNaN, is_nan, 1, attr);
- define_native_function(realm, vm.names.parseFloat, parse_float, 1, attr);
- define_native_function(realm, vm.names.parseInt, parse_int, 2, attr);
- define_native_function(realm, vm.names.decodeURI, decode_uri, 1, attr);
- define_native_function(realm, vm.names.decodeURIComponent, decode_uri_component, 1, attr);
- define_native_function(realm, vm.names.encodeURI, encode_uri, 1, attr);
- define_native_function(realm, vm.names.encodeURIComponent, encode_uri_component, 1, attr);
+ define_direct_property(vm.names.eval, realm.intrinsics().eval_function(), attr);
+ define_direct_property(vm.names.isFinite, realm.intrinsics().is_finite_function(), attr);
+ define_direct_property(vm.names.isNaN, realm.intrinsics().is_nan_function(), attr);
+ define_direct_property(vm.names.parseFloat, realm.intrinsics().parse_float_function(), attr);
+ define_direct_property(vm.names.parseInt, realm.intrinsics().parse_int_function(), attr);
+ define_direct_property(vm.names.decodeURI, realm.intrinsics().decode_uri_function(), attr);
+ define_direct_property(vm.names.decodeURIComponent, realm.intrinsics().decode_uri_component_function(), attr);
+ define_direct_property(vm.names.encodeURI, realm.intrinsics().encode_uri_function(), attr);
+ define_direct_property(vm.names.encodeURIComponent, realm.intrinsics().encode_uri_component_function(), attr);
// 19.1 Value Properties of the Global Object, https://tc39.es/ecma262/#sec-value-properties-of-the-global-object
define_direct_property(vm.names.globalThis, this, attr);
@@ -167,18 +167,13 @@ void GlobalObject::initialize(Realm& realm)
define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(realm, realm), attr);
// B.2.1 Additional Properties of the Global Object, https://tc39.es/ecma262/#sec-additional-properties-of-the-global-object
- define_native_function(realm, vm.names.escape, escape, 1, attr);
- define_native_function(realm, vm.names.unescape, unescape, 1, attr);
+ define_direct_property(vm.names.escape, realm.intrinsics().escape_function(), attr);
+ define_direct_property(vm.names.unescape, realm.intrinsics().unescape_function(), attr);
// Non-standard
define_direct_property(vm.names.InternalError, realm.intrinsics().internal_error_constructor(), attr);
define_direct_property(vm.names.console, realm.intrinsics().console_object(), attr);
define_native_function(realm, vm.names.gc, gc, 0, attr);
-
- // Assign intrinsics and functions that depend on the GlobalObject's native functions
- realm.intrinsics().m_eval_function = &get_without_side_effects(vm.names.eval).as_function();
- realm.intrinsics().m_number_constructor->define_direct_property(vm.names.parseInt, get_without_side_effects(vm.names.parseInt), attr);
- realm.intrinsics().m_number_constructor->define_direct_property(vm.names.parseFloat, get_without_side_effects(vm.names.parseFloat), attr);
}
GlobalObject::~GlobalObject() = default;