mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibWeb: Update Location initialization according to spec
This commit is contained in:
parent
695ce3763e
commit
361c6f1b64
Notes:
github-actions[bot]
2024-12-20 14:01:14 +00:00
Author: https://github.com/shlyakpavel Commit: https://github.com/LadybirdBrowser/ladybird/commit/361c6f1b643 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2667 Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/yyny
1 changed files with 24 additions and 1 deletions
|
@ -38,12 +38,35 @@ void Location::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_default_properties);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-location-interface
|
||||
void Location::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(Location);
|
||||
|
||||
// FIXME: Implement steps 2.-4.
|
||||
auto& vm = this->vm();
|
||||
|
||||
// Step 2: Let valueOf be location's relevant realm.[[Intrinsics]].[[%Object.prototype.valueOf%]].
|
||||
auto& intrinsics = realm.intrinsics();
|
||||
auto value_of_function = intrinsics.object_prototype()->get_without_side_effects(vm.names.valueOf);
|
||||
|
||||
// Step 3: Perform ! location.[[DefineOwnProperty]]("valueOf", { [[Value]]: valueOf, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||
auto value_of_property_descriptor = JS::PropertyDescriptor {
|
||||
.value = value_of_function,
|
||||
.writable = false,
|
||||
.enumerable = false,
|
||||
.configurable = false,
|
||||
};
|
||||
MUST(internal_define_own_property(vm.names.valueOf, value_of_property_descriptor));
|
||||
|
||||
// Step 4: Perform ! location.[[DefineOwnProperty]](%Symbol.toPrimitive%, { [[Value]]: undefined, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||
auto to_primitive_property_descriptor = JS::PropertyDescriptor {
|
||||
.value = JS::js_undefined(),
|
||||
.writable = false,
|
||||
.enumerable = false,
|
||||
.configurable = false,
|
||||
};
|
||||
MUST(internal_define_own_property(vm.well_known_symbol_to_primitive(), to_primitive_property_descriptor));
|
||||
|
||||
// 5. Set the value of the [[DefaultProperties]] internal slot of location to location.[[OwnPropertyKeys]]().
|
||||
// NOTE: In LibWeb this happens before the ESO is set up, so we must avoid location's custom [[OwnPropertyKeys]].
|
||||
|
|
Loading…
Reference in a new issue