Location.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. /*
  2. * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/String.h>
  8. #include <AK/StringBuilder.h>
  9. #include <AK/URLParser.h>
  10. #include <LibJS/Heap/MarkedVector.h>
  11. #include <LibJS/Runtime/Completion.h>
  12. #include <LibJS/Runtime/PropertyDescriptor.h>
  13. #include <LibJS/Runtime/PropertyKey.h>
  14. #include <LibWeb/Bindings/LocationPrototype.h>
  15. #include <LibWeb/DOM/Document.h>
  16. #include <LibWeb/HTML/CrossOrigin/AbstractOperations.h>
  17. #include <LibWeb/HTML/Location.h>
  18. #include <LibWeb/HTML/Window.h>
  19. #include <LibWeb/WebIDL/DOMException.h>
  20. namespace Web::HTML {
  21. // https://html.spec.whatwg.org/multipage/history.html#the-location-interface
  22. Location::Location(JS::Realm& realm)
  23. : PlatformObject(realm)
  24. {
  25. }
  26. Location::~Location() = default;
  27. void Location::visit_edges(Cell::Visitor& visitor)
  28. {
  29. Base::visit_edges(visitor);
  30. for (auto& property : m_default_properties)
  31. visitor.visit(property);
  32. }
  33. void Location::initialize(JS::Realm& realm)
  34. {
  35. Base::initialize(realm);
  36. set_prototype(&Bindings::ensure_web_prototype<Bindings::LocationPrototype>(realm, "Location"));
  37. // FIXME: Implement steps 2.-4.
  38. // 5. Set the value of the [[DefaultProperties]] internal slot of location to location.[[OwnPropertyKeys]]().
  39. // NOTE: In LibWeb this happens before the ESO is set up, so we must avoid location's custom [[OwnPropertyKeys]].
  40. m_default_properties.extend(MUST(Object::internal_own_property_keys()));
  41. }
  42. // https://html.spec.whatwg.org/multipage/history.html#relevant-document
  43. JS::GCPtr<DOM::Document> Location::relevant_document() const
  44. {
  45. // A Location object has an associated relevant Document, which is this Location object's
  46. // relevant global object's browsing context's active document, if this Location object's
  47. // relevant global object's browsing context is non-null, and null otherwise.
  48. auto* browsing_context = verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).browsing_context();
  49. return browsing_context ? browsing_context->active_document() : nullptr;
  50. }
  51. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#location-object-navigate
  52. WebIDL::ExceptionOr<void> Location::navigate(AK::URL url, HistoryHandlingBehavior history_handling)
  53. {
  54. // 1. Let navigable be location's relevant global object's navigable.
  55. auto navigable = verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).navigable();
  56. // 2. Let sourceDocument be the incumbent global object's associated Document.
  57. auto& source_document = verify_cast<HTML::Window>(incumbent_global_object()).associated_document();
  58. // 3. If location's relevant Document is not yet completely loaded, and the incumbent global object does not have transient activation, then set historyHandling to "replace".
  59. if (!relevant_document()->is_completely_loaded() && !verify_cast<HTML::Window>(incumbent_global_object()).has_transient_activation()) {
  60. history_handling = HistoryHandlingBehavior::Replace;
  61. }
  62. // 4. Navigate navigable to url using sourceDocument, with exceptionsEnabled set to true and historyHandling set to historyHandling.
  63. TRY(navigable->navigate(url, source_document, {}, nullptr, true, history_handling));
  64. return {};
  65. }
  66. // https://html.spec.whatwg.org/multipage/history.html#concept-location-url
  67. AK::URL Location::url() const
  68. {
  69. // A Location object has an associated url, which is this Location object's relevant Document's URL,
  70. // if this Location object's relevant Document is non-null, and about:blank otherwise.
  71. auto const relevant_document = this->relevant_document();
  72. return relevant_document ? relevant_document->url() : "about:blank"sv;
  73. }
  74. // https://html.spec.whatwg.org/multipage/history.html#dom-location-href
  75. WebIDL::ExceptionOr<String> Location::href() const
  76. {
  77. auto& vm = this->vm();
  78. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  79. auto const relevant_document = this->relevant_document();
  80. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  81. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  82. // 2. Return this's url, serialized.
  83. return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(url().serialize()));
  84. }
  85. // https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2
  86. WebIDL::ExceptionOr<void> Location::set_href(String const& new_href)
  87. {
  88. auto& vm = this->vm();
  89. auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
  90. // 1. If this's relevant Document is null, then return.
  91. auto const relevant_document = this->relevant_document();
  92. if (!relevant_document)
  93. return {};
  94. // 2. Parse the given value relative to the entry settings object. If that failed, throw a TypeError exception.
  95. auto href_url = window.associated_document().parse_url(new_href.to_deprecated_string());
  96. if (!href_url.is_valid())
  97. return vm.throw_completion<JS::URIError>(TRY_OR_THROW_OOM(vm, String::formatted("Invalid URL '{}'", new_href)));
  98. // 3. Location-object navigate given the resulting URL record.
  99. window.did_set_location_href({}, href_url);
  100. return {};
  101. }
  102. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-origin
  103. WebIDL::ExceptionOr<String> Location::origin() const
  104. {
  105. auto& vm = this->vm();
  106. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  107. auto const relevant_document = this->relevant_document();
  108. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  109. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  110. // 2. Return the serialization of this's url's origin.
  111. return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(url().serialize_origin()));
  112. }
  113. // https://html.spec.whatwg.org/multipage/history.html#dom-location-protocol
  114. WebIDL::ExceptionOr<String> Location::protocol() const
  115. {
  116. auto& vm = this->vm();
  117. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  118. auto const relevant_document = this->relevant_document();
  119. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  120. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  121. // 2. Return this's url's scheme, followed by ":".
  122. return TRY_OR_THROW_OOM(vm, String::formatted("{}:", url().scheme()));
  123. }
  124. WebIDL::ExceptionOr<void> Location::set_protocol(String const&)
  125. {
  126. auto& vm = this->vm();
  127. return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotImplemented, "Location.protocol setter");
  128. }
  129. // https://html.spec.whatwg.org/multipage/history.html#dom-location-host
  130. WebIDL::ExceptionOr<String> Location::host() const
  131. {
  132. auto& vm = this->vm();
  133. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  134. auto const relevant_document = this->relevant_document();
  135. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  136. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  137. // 2. Let url be this's url.
  138. auto url = this->url();
  139. // 3. If url's host is null, return the empty string.
  140. if (url.host().has<Empty>())
  141. return String {};
  142. // 4. If url's port is null, return url's host, serialized.
  143. if (!url.port().has_value())
  144. return TRY_OR_THROW_OOM(vm, url.serialized_host());
  145. // 5. Return url's host, serialized, followed by ":" and url's port, serialized.
  146. return TRY_OR_THROW_OOM(vm, String::formatted("{}:{}", TRY_OR_THROW_OOM(vm, url.serialized_host()), *url.port()));
  147. }
  148. WebIDL::ExceptionOr<void> Location::set_host(String const&)
  149. {
  150. auto& vm = this->vm();
  151. return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotImplemented, "Location.host setter");
  152. }
  153. // https://html.spec.whatwg.org/multipage/history.html#dom-location-hostname
  154. WebIDL::ExceptionOr<String> Location::hostname() const
  155. {
  156. auto& vm = this->vm();
  157. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  158. auto const relevant_document = this->relevant_document();
  159. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  160. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  161. auto url = this->url();
  162. // 2. If this's url's host is null, return the empty string.
  163. if (url.host().has<Empty>())
  164. return String {};
  165. // 3. Return this's url's host, serialized.
  166. return TRY_OR_THROW_OOM(vm, url.serialized_host());
  167. }
  168. WebIDL::ExceptionOr<void> Location::set_hostname(String const&)
  169. {
  170. auto& vm = this->vm();
  171. return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotImplemented, "Location.hostname setter");
  172. }
  173. // https://html.spec.whatwg.org/multipage/history.html#dom-location-port
  174. WebIDL::ExceptionOr<String> Location::port() const
  175. {
  176. auto& vm = this->vm();
  177. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  178. auto const relevant_document = this->relevant_document();
  179. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  180. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  181. auto url = this->url();
  182. // 2. If this's url's port is null, return the empty string.
  183. if (!url.port().has_value())
  184. return String {};
  185. // 3. Return this's url's port, serialized.
  186. return TRY_OR_THROW_OOM(vm, String::number(*url.port()));
  187. }
  188. WebIDL::ExceptionOr<void> Location::set_port(String const&)
  189. {
  190. auto& vm = this->vm();
  191. return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotImplemented, "Location.port setter");
  192. }
  193. // https://html.spec.whatwg.org/multipage/history.html#dom-location-pathname
  194. WebIDL::ExceptionOr<String> Location::pathname() const
  195. {
  196. auto& vm = this->vm();
  197. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  198. auto const relevant_document = this->relevant_document();
  199. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  200. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  201. // 2. Return the result of URL path serializing this Location object's url.
  202. return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(url().serialize_path()));
  203. }
  204. WebIDL::ExceptionOr<void> Location::set_pathname(String const&)
  205. {
  206. auto& vm = this->vm();
  207. return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotImplemented, "Location.pathname setter");
  208. }
  209. // https://html.spec.whatwg.org/multipage/history.html#dom-location-search
  210. WebIDL::ExceptionOr<String> Location::search() const
  211. {
  212. auto& vm = this->vm();
  213. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  214. auto const relevant_document = this->relevant_document();
  215. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  216. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  217. auto url = this->url();
  218. // 2. If this's url's query is either null or the empty string, return the empty string.
  219. if (!url.query().has_value() || url.query()->is_empty())
  220. return String {};
  221. // 3. Return "?", followed by this's url's query.
  222. return TRY_OR_THROW_OOM(vm, String::formatted("?{}", url.query()));
  223. }
  224. WebIDL::ExceptionOr<void> Location::set_search(String const&)
  225. {
  226. auto& vm = this->vm();
  227. return vm.throw_completion<JS::InternalError>(JS::ErrorType::NotImplemented, "Location.search setter");
  228. }
  229. // https://html.spec.whatwg.org/multipage/history.html#dom-location-hash
  230. WebIDL::ExceptionOr<String> Location::hash() const
  231. {
  232. auto& vm = this->vm();
  233. // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  234. auto const relevant_document = this->relevant_document();
  235. if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  236. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  237. auto url = this->url();
  238. // 2. If this's url's fragment is either null or the empty string, return the empty string.
  239. if (!url.fragment().has_value() || url.fragment()->is_empty())
  240. return String {};
  241. // 3. Return "#", followed by this's url's fragment.
  242. return TRY_OR_THROW_OOM(vm, String::formatted("#{}", *url.fragment()));
  243. }
  244. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-hash
  245. WebIDL::ExceptionOr<void> Location::set_hash(String const& value)
  246. {
  247. // The hash setter steps are:
  248. auto const relevant_document = this->relevant_document();
  249. // 1. If this's relevant Document is null, then return.
  250. if (!relevant_document)
  251. return {};
  252. // 2. If this's relevant Document's origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  253. if (!relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  254. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  255. // 3. Let copyURL be a copy of this's url.
  256. auto copy_url = this->url();
  257. // 4. Let input be the given value with a single leading "#" removed, if any.
  258. auto input = value.bytes_as_string_view().trim("#"sv, TrimMode::Left);
  259. // 5. Set copyURL's fragment to the empty string.
  260. copy_url.set_fragment(String {});
  261. // 6. Basic URL parse input, with copyURL as url and fragment state as state override.
  262. auto result_url = URLParser::basic_parse(input, {}, copy_url, URLParser::State::Fragment);
  263. // 7. If copyURL's fragment is this's url's fragment, then return.
  264. if (copy_url.fragment() == this->url().fragment())
  265. return {};
  266. // 8. Location-object navigate this to copyURL.
  267. auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
  268. window.did_set_location_href({}, copy_url);
  269. return {};
  270. }
  271. // https://html.spec.whatwg.org/multipage/history.html#dom-location-reload
  272. void Location::reload() const
  273. {
  274. auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
  275. window.did_call_location_reload({});
  276. }
  277. // https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
  278. void Location::replace(String const& url) const
  279. {
  280. auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
  281. // FIXME: This needs spec compliance work.
  282. window.did_call_location_replace({}, url.to_deprecated_string());
  283. }
  284. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-assign
  285. WebIDL::ExceptionOr<void> Location::assign(String const& url) const
  286. {
  287. // 1. If this's relevant Document is null, then return.
  288. auto const relevant_document = this->relevant_document();
  289. if (!relevant_document)
  290. return {};
  291. // 2. If this's relevant Document's origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
  292. if (!relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
  293. return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv);
  294. // 3. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException.
  295. auto assign_url = entry_settings_object().parse_url(url);
  296. if (!assign_url.is_valid())
  297. return WebIDL::SyntaxError::create(realm(), DeprecatedString::formatted("Invalid URL '{}'", url));
  298. // 4. Location-object navigate this to the resulting URL record.
  299. auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
  300. window.did_set_location_href({}, assign_url);
  301. return {};
  302. }
  303. // 7.10.5.1 [[GetPrototypeOf]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-getprototypeof
  304. JS::ThrowCompletionOr<JS::Object*> Location::internal_get_prototype_of() const
  305. {
  306. // 1. If IsPlatformObjectSameOrigin(this) is true, then return ! OrdinaryGetPrototypeOf(this).
  307. if (HTML::is_platform_object_same_origin(*this))
  308. return MUST(JS::Object::internal_get_prototype_of());
  309. // 2. Return null.
  310. return nullptr;
  311. }
  312. // 7.10.5.2 [[SetPrototypeOf]] ( V ), https://html.spec.whatwg.org/multipage/history.html#location-setprototypeof
  313. JS::ThrowCompletionOr<bool> Location::internal_set_prototype_of(Object* prototype)
  314. {
  315. // 1. Return ! SetImmutablePrototype(this, V).
  316. return MUST(set_immutable_prototype(prototype));
  317. }
  318. // 7.10.5.3 [[IsExtensible]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-isextensible
  319. JS::ThrowCompletionOr<bool> Location::internal_is_extensible() const
  320. {
  321. // 1. Return true.
  322. return true;
  323. }
  324. // 7.10.5.4 [[PreventExtensions]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-preventextensions
  325. JS::ThrowCompletionOr<bool> Location::internal_prevent_extensions()
  326. {
  327. // 1. Return false.
  328. return false;
  329. }
  330. // 7.10.5.5 [[GetOwnProperty]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-getownproperty
  331. JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> Location::internal_get_own_property(JS::PropertyKey const& property_key) const
  332. {
  333. auto& vm = this->vm();
  334. // 1. If IsPlatformObjectSameOrigin(this) is true, then:
  335. if (HTML::is_platform_object_same_origin(*this)) {
  336. // 1. Let desc be OrdinaryGetOwnProperty(this, P).
  337. auto descriptor = MUST(Object::internal_get_own_property(property_key));
  338. // 2. If the value of the [[DefaultProperties]] internal slot of this contains P, then set desc.[[Configurable]] to true.
  339. auto property_key_value = property_key.is_symbol()
  340. ? JS::Value { property_key.as_symbol() }
  341. : JS::PrimitiveString::create(vm, property_key.to_string());
  342. if (m_default_properties.contains_slow(property_key_value))
  343. descriptor->configurable = true;
  344. // 3. Return desc.
  345. return descriptor;
  346. }
  347. // 2. Let property be CrossOriginGetOwnPropertyHelper(this, P).
  348. auto property = HTML::cross_origin_get_own_property_helper(const_cast<Location*>(this), property_key);
  349. // 3. If property is not undefined, then return property.
  350. if (property.has_value())
  351. return property;
  352. // 4. Return ? CrossOriginPropertyFallback(P).
  353. return TRY(HTML::cross_origin_property_fallback(vm, property_key));
  354. }
  355. // 7.10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/history.html#location-defineownproperty
  356. JS::ThrowCompletionOr<bool> Location::internal_define_own_property(JS::PropertyKey const& property_key, JS::PropertyDescriptor const& descriptor)
  357. {
  358. // 1. If IsPlatformObjectSameOrigin(this) is true, then:
  359. if (HTML::is_platform_object_same_origin(*this)) {
  360. // 1. If the value of the [[DefaultProperties]] internal slot of this contains P, then return false.
  361. // 2. Return ? OrdinaryDefineOwnProperty(this, P, Desc).
  362. return JS::Object::internal_define_own_property(property_key, descriptor);
  363. }
  364. // 2. Throw a "SecurityError" DOMException.
  365. return throw_completion(WebIDL::SecurityError::create(realm(), DeprecatedString::formatted("Can't define property '{}' on cross-origin object", property_key)));
  366. }
  367. // 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get
  368. JS::ThrowCompletionOr<JS::Value> Location::internal_get(JS::PropertyKey const& property_key, JS::Value receiver, JS::CacheablePropertyMetadata* cacheable_metadata) const
  369. {
  370. auto& vm = this->vm();
  371. // 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryGet(this, P, Receiver).
  372. if (HTML::is_platform_object_same_origin(*this))
  373. return JS::Object::internal_get(property_key, receiver, cacheable_metadata);
  374. // 2. Return ? CrossOriginGet(this, P, Receiver).
  375. return HTML::cross_origin_get(vm, static_cast<JS::Object const&>(*this), property_key, receiver);
  376. }
  377. // 7.10.5.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-set
  378. JS::ThrowCompletionOr<bool> Location::internal_set(JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver)
  379. {
  380. auto& vm = this->vm();
  381. // 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinarySet(this, P, V, Receiver).
  382. if (HTML::is_platform_object_same_origin(*this))
  383. return JS::Object::internal_set(property_key, value, receiver);
  384. // 2. Return ? CrossOriginSet(this, P, V, Receiver).
  385. return HTML::cross_origin_set(vm, static_cast<JS::Object&>(*this), property_key, value, receiver);
  386. }
  387. // 7.10.5.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-delete
  388. JS::ThrowCompletionOr<bool> Location::internal_delete(JS::PropertyKey const& property_key)
  389. {
  390. // 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryDelete(this, P).
  391. if (HTML::is_platform_object_same_origin(*this))
  392. return JS::Object::internal_delete(property_key);
  393. // 2. Throw a "SecurityError" DOMException.
  394. return throw_completion(WebIDL::SecurityError::create(realm(), DeprecatedString::formatted("Can't delete property '{}' on cross-origin object", property_key)));
  395. }
  396. // 7.10.5.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-ownpropertykeys
  397. JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> Location::internal_own_property_keys() const
  398. {
  399. // 1. If IsPlatformObjectSameOrigin(this) is true, then return OrdinaryOwnPropertyKeys(this).
  400. if (HTML::is_platform_object_same_origin(*this))
  401. return JS::Object::internal_own_property_keys();
  402. // 2. Return CrossOriginOwnPropertyKeys(this).
  403. return HTML::cross_origin_own_property_keys(this);
  404. }
  405. }