1/*
2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "JSLocation.h"
23
24#include "DOMWindow.h"
25#include "JSDOMAttribute.h"
26#include "JSDOMBinding.h"
27#include "JSDOMBindingSecurity.h"
28#include "JSDOMConstructorNotConstructable.h"
29#include "JSDOMConvertInterface.h"
30#include "JSDOMConvertStrings.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMGlobalObject.h"
33#include "JSDOMOperation.h"
34#include "JSDOMStringList.h"
35#include "JSDOMWindowBase.h"
36#include "JSDOMWrapperCache.h"
37#include "ScriptExecutionContext.h"
38#include <JavaScriptCore/FunctionPrototype.h>
39#include <JavaScriptCore/HeapSnapshotBuilder.h>
40#include <JavaScriptCore/JSCInlines.h>
41#include <wtf/GetPtr.h>
42#include <wtf/PointerPreparations.h>
43#include <wtf/URL.h>
44
45
46namespace WebCore {
47using namespace JSC;
48
49// Functions
50
51JSC::EncodedJSValue JSC_HOST_CALL jsLocationInstanceFunctionToString(JSC::ExecState*);
52
53// Attributes
54
55JSC::EncodedJSValue jsLocationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
56bool setJSLocationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
57JSC::EncodedJSValue jsLocationHref(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58bool setJSLocationHref(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
59JSC::EncodedJSValue jsLocationProtocol(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60bool setJSLocationProtocol(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
61JSC::EncodedJSValue jsLocationHost(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
62bool setJSLocationHost(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
63JSC::EncodedJSValue jsLocationHostname(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
64bool setJSLocationHostname(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
65JSC::EncodedJSValue jsLocationPort(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
66bool setJSLocationPort(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
67JSC::EncodedJSValue jsLocationPathname(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
68bool setJSLocationPathname(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
69JSC::EncodedJSValue jsLocationSearch(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
70bool setJSLocationSearch(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
71JSC::EncodedJSValue jsLocationHash(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
72bool setJSLocationHash(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
73JSC::EncodedJSValue jsLocationOrigin(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
74JSC::EncodedJSValue jsLocationAncestorOrigins(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
75
76using JSLocationConstructor = JSDOMConstructorNotConstructable<JSLocation>;
77
78/* Hash table */
79
80static const struct CompactHashIndex JSLocationTableIndex[35] = {
81 { -1, -1 },
82 { -1, -1 },
83 { -1, -1 },
84 { -1, -1 },
85 { 8, 34 },
86 { -1, -1 },
87 { -1, -1 },
88 { 7, -1 },
89 { 0, 32 },
90 { 5, 33 },
91 { -1, -1 },
92 { 10, -1 },
93 { -1, -1 },
94 { 9, -1 },
95 { -1, -1 },
96 { -1, -1 },
97 { 3, -1 },
98 { -1, -1 },
99 { -1, -1 },
100 { -1, -1 },
101 { -1, -1 },
102 { -1, -1 },
103 { -1, -1 },
104 { 11, -1 },
105 { -1, -1 },
106 { 1, -1 },
107 { -1, -1 },
108 { 4, -1 },
109 { 13, -1 },
110 { -1, -1 },
111 { -1, -1 },
112 { -1, -1 },
113 { 2, -1 },
114 { 6, -1 },
115 { 12, -1 },
116};
117
118
119static const HashTableValue JSLocationTableValues[] =
120{
121 { "href", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationHref), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationHref) } },
122 { "protocol", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationProtocol), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationProtocol) } },
123 { "host", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationHost), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationHost) } },
124 { "hostname", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationHostname), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationHostname) } },
125 { "port", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationPort), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationPort) } },
126 { "pathname", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationPathname), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationPathname) } },
127 { "search", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationSearch), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationSearch) } },
128 { "hash", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationHash), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationHash) } },
129 { "origin", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationOrigin), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
130 { "ancestorOrigins", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationAncestorOrigins), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
131 { "assign", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsLocationInstanceFunctionAssign), (intptr_t) (1) } },
132 { "replace", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsLocationInstanceFunctionReplace), (intptr_t) (1) } },
133 { "reload", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsLocationInstanceFunctionReload), (intptr_t) (0) } },
134 { "toString", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsLocationInstanceFunctionToString), (intptr_t) (0) } },
135};
136
137static const HashTable JSLocationTable = { 14, 31, true, JSLocation::info(), JSLocationTableValues, JSLocationTableIndex };
138template<> JSValue JSLocationConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
139{
140 UNUSED_PARAM(vm);
141 return globalObject.functionPrototype();
142}
143
144template<> void JSLocationConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
145{
146 putDirect(vm, vm.propertyNames->prototype, JSLocation::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
147 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Location"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
148 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
149}
150
151template<> const ClassInfo JSLocationConstructor::s_info = { "Location", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSLocationConstructor) };
152
153/* Hash table for prototype */
154
155static const HashTableValue JSLocationPrototypeTableValues[] =
156{
157 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsLocationConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSLocationConstructor) } },
158};
159
160const ClassInfo JSLocationPrototype::s_info = { "LocationPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSLocationPrototype) };
161
162void JSLocationPrototype::finishCreation(VM& vm)
163{
164 Base::finishCreation(vm);
165 reifyStaticProperties(vm, JSLocation::info(), JSLocationPrototypeTableValues, *this);
166}
167
168const ClassInfo JSLocation::s_info = { "Location", &Base::s_info, &JSLocationTable, nullptr, CREATE_METHOD_TABLE(JSLocation) };
169
170JSLocation::JSLocation(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Location>&& impl)
171 : JSDOMWrapper<Location>(structure, globalObject, WTFMove(impl))
172{
173}
174
175void JSLocation::finishCreation(VM& vm)
176{
177 Base::finishCreation(vm);
178 ASSERT(inherits(vm, info()));
179
180 putDirect(vm, vm.propertyNames->valueOf, globalObject()->objectProtoValueOfFunction(), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
181 putDirect(vm, vm.propertyNames->toPrimitiveSymbol, jsUndefined(), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
182}
183
184JSObject* JSLocation::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
185{
186 return JSLocationPrototype::create(vm, &globalObject, JSLocationPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
187}
188
189JSObject* JSLocation::prototype(VM& vm, JSDOMGlobalObject& globalObject)
190{
191 return getDOMPrototype<JSLocation>(vm, globalObject);
192}
193
194JSValue JSLocation::getConstructor(VM& vm, const JSGlobalObject* globalObject)
195{
196 return getDOMConstructor<JSLocationConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
197}
198
199void JSLocation::destroy(JSC::JSCell* cell)
200{
201 JSLocation* thisObject = static_cast<JSLocation*>(cell);
202 thisObject->JSLocation::~JSLocation();
203}
204
205template<> inline JSLocation* IDLAttribute<JSLocation>::cast(ExecState& state, EncodedJSValue thisValue)
206{
207 return jsDynamicCast<JSLocation*>(state.vm(), JSValue::decode(thisValue));
208}
209
210template<> inline JSLocation* IDLOperation<JSLocation>::cast(ExecState& state)
211{
212 return jsDynamicCast<JSLocation*>(state.vm(), state.thisValue());
213}
214
215EncodedJSValue jsLocationConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
216{
217 VM& vm = state->vm();
218 auto throwScope = DECLARE_THROW_SCOPE(vm);
219 auto* prototype = jsDynamicCast<JSLocationPrototype*>(vm, JSValue::decode(thisValue));
220 if (UNLIKELY(!prototype))
221 return throwVMTypeError(state, throwScope);
222 return JSValue::encode(JSLocation::getConstructor(state->vm(), prototype->globalObject()));
223}
224
225bool setJSLocationConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
226{
227 VM& vm = state->vm();
228 auto throwScope = DECLARE_THROW_SCOPE(vm);
229 auto* prototype = jsDynamicCast<JSLocationPrototype*>(vm, JSValue::decode(thisValue));
230 if (UNLIKELY(!prototype)) {
231 throwVMTypeError(state, throwScope);
232 return false;
233 }
234 // Shadowing a built-in constructor
235 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
236}
237
238static inline JSValue jsLocationHrefGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
239{
240 UNUSED_PARAM(throwScope);
241 UNUSED_PARAM(state);
242 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
243 return jsUndefined();
244 auto& impl = thisObject.wrapped();
245 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.href());
246 return result;
247}
248
249EncodedJSValue jsLocationHref(ExecState* state, EncodedJSValue thisValue, PropertyName)
250{
251 return IDLAttribute<JSLocation>::get<jsLocationHrefGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "href");
252}
253
254static inline bool setJSLocationHrefSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
255{
256 UNUSED_PARAM(throwScope);
257 auto& impl = thisObject.wrapped();
258 auto nativeValue = convert<IDLUSVString>(state, value);
259 RETURN_IF_EXCEPTION(throwScope, false);
260 AttributeSetter::call(state, throwScope, [&] {
261 return impl.setHref(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
262 });
263 return true;
264}
265
266bool setJSLocationHref(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
267{
268 return IDLAttribute<JSLocation>::set<setJSLocationHrefSetter>(*state, thisValue, encodedValue, "href");
269}
270
271static inline JSValue jsLocationProtocolGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
272{
273 UNUSED_PARAM(throwScope);
274 UNUSED_PARAM(state);
275 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
276 return jsUndefined();
277 auto& impl = thisObject.wrapped();
278 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.protocol());
279 return result;
280}
281
282EncodedJSValue jsLocationProtocol(ExecState* state, EncodedJSValue thisValue, PropertyName)
283{
284 return IDLAttribute<JSLocation>::get<jsLocationProtocolGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "protocol");
285}
286
287static inline bool setJSLocationProtocolSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
288{
289 UNUSED_PARAM(throwScope);
290 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
291 return false;
292 auto& impl = thisObject.wrapped();
293 auto nativeValue = convert<IDLUSVString>(state, value);
294 RETURN_IF_EXCEPTION(throwScope, false);
295 AttributeSetter::call(state, throwScope, [&] {
296 return impl.setProtocol(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
297 });
298 return true;
299}
300
301bool setJSLocationProtocol(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
302{
303 return IDLAttribute<JSLocation>::set<setJSLocationProtocolSetter>(*state, thisValue, encodedValue, "protocol");
304}
305
306static inline JSValue jsLocationHostGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
307{
308 UNUSED_PARAM(throwScope);
309 UNUSED_PARAM(state);
310 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
311 return jsUndefined();
312 auto& impl = thisObject.wrapped();
313 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.host());
314 return result;
315}
316
317EncodedJSValue jsLocationHost(ExecState* state, EncodedJSValue thisValue, PropertyName)
318{
319 return IDLAttribute<JSLocation>::get<jsLocationHostGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "host");
320}
321
322static inline bool setJSLocationHostSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
323{
324 UNUSED_PARAM(throwScope);
325 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
326 return false;
327 auto& impl = thisObject.wrapped();
328 auto nativeValue = convert<IDLUSVString>(state, value);
329 RETURN_IF_EXCEPTION(throwScope, false);
330 AttributeSetter::call(state, throwScope, [&] {
331 return impl.setHost(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
332 });
333 return true;
334}
335
336bool setJSLocationHost(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
337{
338 return IDLAttribute<JSLocation>::set<setJSLocationHostSetter>(*state, thisValue, encodedValue, "host");
339}
340
341static inline JSValue jsLocationHostnameGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
342{
343 UNUSED_PARAM(throwScope);
344 UNUSED_PARAM(state);
345 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
346 return jsUndefined();
347 auto& impl = thisObject.wrapped();
348 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.hostname());
349 return result;
350}
351
352EncodedJSValue jsLocationHostname(ExecState* state, EncodedJSValue thisValue, PropertyName)
353{
354 return IDLAttribute<JSLocation>::get<jsLocationHostnameGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "hostname");
355}
356
357static inline bool setJSLocationHostnameSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
358{
359 UNUSED_PARAM(throwScope);
360 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
361 return false;
362 auto& impl = thisObject.wrapped();
363 auto nativeValue = convert<IDLUSVString>(state, value);
364 RETURN_IF_EXCEPTION(throwScope, false);
365 AttributeSetter::call(state, throwScope, [&] {
366 return impl.setHostname(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
367 });
368 return true;
369}
370
371bool setJSLocationHostname(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
372{
373 return IDLAttribute<JSLocation>::set<setJSLocationHostnameSetter>(*state, thisValue, encodedValue, "hostname");
374}
375
376static inline JSValue jsLocationPortGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
377{
378 UNUSED_PARAM(throwScope);
379 UNUSED_PARAM(state);
380 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
381 return jsUndefined();
382 auto& impl = thisObject.wrapped();
383 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.port());
384 return result;
385}
386
387EncodedJSValue jsLocationPort(ExecState* state, EncodedJSValue thisValue, PropertyName)
388{
389 return IDLAttribute<JSLocation>::get<jsLocationPortGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "port");
390}
391
392static inline bool setJSLocationPortSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
393{
394 UNUSED_PARAM(throwScope);
395 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
396 return false;
397 auto& impl = thisObject.wrapped();
398 auto nativeValue = convert<IDLUSVString>(state, value);
399 RETURN_IF_EXCEPTION(throwScope, false);
400 AttributeSetter::call(state, throwScope, [&] {
401 return impl.setPort(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
402 });
403 return true;
404}
405
406bool setJSLocationPort(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
407{
408 return IDLAttribute<JSLocation>::set<setJSLocationPortSetter>(*state, thisValue, encodedValue, "port");
409}
410
411static inline JSValue jsLocationPathnameGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
412{
413 UNUSED_PARAM(throwScope);
414 UNUSED_PARAM(state);
415 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
416 return jsUndefined();
417 auto& impl = thisObject.wrapped();
418 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.pathname());
419 return result;
420}
421
422EncodedJSValue jsLocationPathname(ExecState* state, EncodedJSValue thisValue, PropertyName)
423{
424 return IDLAttribute<JSLocation>::get<jsLocationPathnameGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "pathname");
425}
426
427static inline bool setJSLocationPathnameSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
428{
429 UNUSED_PARAM(throwScope);
430 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
431 return false;
432 auto& impl = thisObject.wrapped();
433 auto nativeValue = convert<IDLUSVString>(state, value);
434 RETURN_IF_EXCEPTION(throwScope, false);
435 AttributeSetter::call(state, throwScope, [&] {
436 return impl.setPathname(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
437 });
438 return true;
439}
440
441bool setJSLocationPathname(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
442{
443 return IDLAttribute<JSLocation>::set<setJSLocationPathnameSetter>(*state, thisValue, encodedValue, "pathname");
444}
445
446static inline JSValue jsLocationSearchGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
447{
448 UNUSED_PARAM(throwScope);
449 UNUSED_PARAM(state);
450 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
451 return jsUndefined();
452 auto& impl = thisObject.wrapped();
453 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.search());
454 return result;
455}
456
457EncodedJSValue jsLocationSearch(ExecState* state, EncodedJSValue thisValue, PropertyName)
458{
459 return IDLAttribute<JSLocation>::get<jsLocationSearchGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "search");
460}
461
462static inline bool setJSLocationSearchSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
463{
464 UNUSED_PARAM(throwScope);
465 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
466 return false;
467 auto& impl = thisObject.wrapped();
468 auto nativeValue = convert<IDLUSVString>(state, value);
469 RETURN_IF_EXCEPTION(throwScope, false);
470 AttributeSetter::call(state, throwScope, [&] {
471 return impl.setSearch(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
472 });
473 return true;
474}
475
476bool setJSLocationSearch(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
477{
478 return IDLAttribute<JSLocation>::set<setJSLocationSearchSetter>(*state, thisValue, encodedValue, "search");
479}
480
481static inline JSValue jsLocationHashGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
482{
483 UNUSED_PARAM(throwScope);
484 UNUSED_PARAM(state);
485 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
486 return jsUndefined();
487 auto& impl = thisObject.wrapped();
488 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.hash());
489 return result;
490}
491
492EncodedJSValue jsLocationHash(ExecState* state, EncodedJSValue thisValue, PropertyName)
493{
494 return IDLAttribute<JSLocation>::get<jsLocationHashGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "hash");
495}
496
497static inline bool setJSLocationHashSetter(ExecState& state, JSLocation& thisObject, JSValue value, ThrowScope& throwScope)
498{
499 UNUSED_PARAM(throwScope);
500 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
501 return false;
502 auto& impl = thisObject.wrapped();
503 auto nativeValue = convert<IDLUSVString>(state, value);
504 RETURN_IF_EXCEPTION(throwScope, false);
505 AttributeSetter::call(state, throwScope, [&] {
506 return impl.setHash(activeDOMWindow(state), firstDOMWindow(state), WTFMove(nativeValue));
507 });
508 return true;
509}
510
511bool setJSLocationHash(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
512{
513 return IDLAttribute<JSLocation>::set<setJSLocationHashSetter>(*state, thisValue, encodedValue, "hash");
514}
515
516static inline JSValue jsLocationOriginGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
517{
518 UNUSED_PARAM(throwScope);
519 UNUSED_PARAM(state);
520 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
521 return jsUndefined();
522 auto& impl = thisObject.wrapped();
523 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.origin());
524 return result;
525}
526
527EncodedJSValue jsLocationOrigin(ExecState* state, EncodedJSValue thisValue, PropertyName)
528{
529 return IDLAttribute<JSLocation>::get<jsLocationOriginGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "origin");
530}
531
532static inline JSValue jsLocationAncestorOriginsGetter(ExecState& state, JSLocation& thisObject, ThrowScope& throwScope)
533{
534 UNUSED_PARAM(throwScope);
535 UNUSED_PARAM(state);
536 if (!BindingSecurity::shouldAllowAccessToDOMWindow(&state, thisObject.wrapped().window(), ThrowSecurityError))
537 return jsUndefined();
538 if (JSValue cachedValue = thisObject.m_ancestorOrigins.get())
539 return cachedValue;
540 auto& impl = thisObject.wrapped();
541 JSValue result = toJS<IDLInterface<DOMStringList>>(state, *thisObject.globalObject(), throwScope, impl.ancestorOrigins());
542 thisObject.m_ancestorOrigins.set(state.vm(), &thisObject, result);
543 return result;
544}
545
546EncodedJSValue jsLocationAncestorOrigins(ExecState* state, EncodedJSValue thisValue, PropertyName)
547{
548 return IDLAttribute<JSLocation>::get<jsLocationAncestorOriginsGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ancestorOrigins");
549}
550
551static inline JSC::EncodedJSValue jsLocationInstanceFunctionAssignBody(JSC::ExecState* state, typename IDLOperation<JSLocation>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
552{
553 UNUSED_PARAM(state);
554 UNUSED_PARAM(throwScope);
555 if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, castedThis->wrapped().window(), ThrowSecurityError))
556 return JSValue::encode(jsUndefined());
557 auto& impl = castedThis->wrapped();
558 if (UNLIKELY(state->argumentCount() < 1))
559 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
560 auto url = convert<IDLUSVString>(*state, state->uncheckedArgument(0));
561 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
562 propagateException(*state, throwScope, impl.assign(activeDOMWindow(*state), firstDOMWindow(*state), WTFMove(url)));
563 return JSValue::encode(jsUndefined());
564}
565
566EncodedJSValue JSC_HOST_CALL jsLocationInstanceFunctionAssign(ExecState* state)
567{
568 return IDLOperation<JSLocation>::call<jsLocationInstanceFunctionAssignBody>(*state, "assign");
569}
570
571static inline JSC::EncodedJSValue jsLocationInstanceFunctionReplaceBody(JSC::ExecState* state, typename IDLOperation<JSLocation>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
572{
573 UNUSED_PARAM(state);
574 UNUSED_PARAM(throwScope);
575 auto& impl = castedThis->wrapped();
576 if (UNLIKELY(state->argumentCount() < 1))
577 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
578 auto url = convert<IDLUSVString>(*state, state->uncheckedArgument(0));
579 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
580 impl.replace(activeDOMWindow(*state), firstDOMWindow(*state), WTFMove(url));
581 return JSValue::encode(jsUndefined());
582}
583
584EncodedJSValue JSC_HOST_CALL jsLocationInstanceFunctionReplace(ExecState* state)
585{
586 return IDLOperation<JSLocation>::call<jsLocationInstanceFunctionReplaceBody>(*state, "replace");
587}
588
589static inline JSC::EncodedJSValue jsLocationInstanceFunctionReloadBody(JSC::ExecState* state, typename IDLOperation<JSLocation>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
590{
591 UNUSED_PARAM(state);
592 UNUSED_PARAM(throwScope);
593 if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, castedThis->wrapped().window(), ThrowSecurityError))
594 return JSValue::encode(jsUndefined());
595 auto& impl = castedThis->wrapped();
596 impl.reload(activeDOMWindow(*state));
597 return JSValue::encode(jsUndefined());
598}
599
600EncodedJSValue JSC_HOST_CALL jsLocationInstanceFunctionReload(ExecState* state)
601{
602 return IDLOperation<JSLocation>::call<jsLocationInstanceFunctionReloadBody>(*state, "reload");
603}
604
605static inline JSC::EncodedJSValue jsLocationInstanceFunctionToStringBody(JSC::ExecState* state, typename IDLOperation<JSLocation>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
606{
607 UNUSED_PARAM(state);
608 UNUSED_PARAM(throwScope);
609 if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, castedThis->wrapped().window(), ThrowSecurityError))
610 return JSValue::encode(jsUndefined());
611 auto& impl = castedThis->wrapped();
612 return JSValue::encode(toJS<IDLUSVString>(*state, impl.href()));
613}
614
615EncodedJSValue JSC_HOST_CALL jsLocationInstanceFunctionToString(ExecState* state)
616{
617 return IDLOperation<JSLocation>::call<jsLocationInstanceFunctionToStringBody>(*state, "toString");
618}
619
620void JSLocation::visitChildren(JSCell* cell, SlotVisitor& visitor)
621{
622 auto* thisObject = jsCast<JSLocation*>(cell);
623 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
624 Base::visitChildren(thisObject, visitor);
625 visitor.append(thisObject->m_ancestorOrigins);
626}
627
628void JSLocation::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
629{
630 auto* thisObject = jsCast<JSLocation*>(cell);
631 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
632 if (thisObject->scriptExecutionContext())
633 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
634 Base::heapSnapshot(cell, builder);
635}
636
637bool JSLocationOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
638{
639 auto* jsLocation = jsCast<JSLocation*>(handle.slot()->asCell());
640 Frame* root = WTF::getPtr(jsLocation->wrapped().frame());
641 if (!root)
642 return false;
643 if (UNLIKELY(reason))
644 *reason = "Reachable from Frame";
645 return visitor.containsOpaqueRoot(root);
646}
647
648void JSLocationOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
649{
650 auto* jsLocation = static_cast<JSLocation*>(handle.slot()->asCell());
651 auto& world = *static_cast<DOMWrapperWorld*>(context);
652 uncacheWrapper(world, &jsLocation->wrapped(), jsLocation);
653}
654
655JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Location>&& impl)
656{
657 // If you hit this failure the interface definition has the ImplementationLacksVTable
658 // attribute. You should remove that attribute. If the class has subclasses
659 // that may be passed through this toJS() function you should use the SkipVTableValidation
660 // attribute to Location.
661 static_assert(!std::is_polymorphic<Location>::value, "Location is polymorphic but the IDL claims it is not");
662 return createWrapper<Location>(globalObject, WTFMove(impl));
663}
664
665JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Location& impl)
666{
667 return wrap(state, globalObject, impl);
668}
669
670Location* JSLocation::toWrapped(JSC::VM& vm, JSC::JSValue value)
671{
672 if (auto* wrapper = jsDynamicCast<JSLocation*>(vm, value))
673 return &wrapper->wrapped();
674 return nullptr;
675}
676
677}
678