Skip to content

Commit

Permalink
LibWeb: Update Location initialization according to spec
Browse files Browse the repository at this point in the history
(cherry picked from commit 361c6f1b64393de645c6728712658a6052e857a1)
  • Loading branch information
shlyakpavel authored and nico committed Dec 21, 2024
1 parent ccd40e0 commit 267b55e
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Userland/Libraries/LibWeb/HTML/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
Expand Down

0 comments on commit 267b55e

Please sign in to comment.