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 "JSDedicatedWorkerGlobalScope.h"
23
24#include "EventNames.h"
25#include "JSDOMAttribute.h"
26#include "JSDOMBinding.h"
27#include "JSDOMConstructorNotConstructable.h"
28#include "JSDOMConvertAny.h"
29#include "JSDOMConvertObject.h"
30#include "JSDOMConvertSequences.h"
31#include "JSDOMConvertStrings.h"
32#include "JSDOMExceptionHandling.h"
33#include "JSDOMOperation.h"
34#include "JSDOMWrapperCache.h"
35#include "JSDedicatedWorkerGlobalScope.h"
36#include "JSEventListener.h"
37#include "JSXMLHttpRequest.h"
38#include "ScriptExecutionContext.h"
39#include <JavaScriptCore/HeapSnapshotBuilder.h>
40#include <JavaScriptCore/JSArray.h>
41#include <JavaScriptCore/JSCInlines.h>
42#include <wtf/GetPtr.h>
43#include <wtf/PointerPreparations.h>
44#include <wtf/URL.h>
45
46
47namespace WebCore {
48using namespace JSC;
49
50// Functions
51
52JSC::EncodedJSValue JSC_HOST_CALL jsDedicatedWorkerGlobalScopeInstanceFunctionPostMessage(JSC::ExecState*);
53JSC::EncodedJSValue JSC_HOST_CALL jsDedicatedWorkerGlobalScopeInstanceFunctionClose(JSC::ExecState*);
54
55// Attributes
56
57JSC::EncodedJSValue jsDedicatedWorkerGlobalScopeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58bool setJSDedicatedWorkerGlobalScopeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
59JSC::EncodedJSValue jsDedicatedWorkerGlobalScopeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60bool setJSDedicatedWorkerGlobalScopeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
61JSC::EncodedJSValue jsDedicatedWorkerGlobalScopeOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
62bool setJSDedicatedWorkerGlobalScopeOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
63JSC::EncodedJSValue jsDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
64bool setJSDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
65JSC::EncodedJSValue jsDedicatedWorkerGlobalScopeXMLHttpRequestConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
66bool setJSDedicatedWorkerGlobalScopeXMLHttpRequestConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
67
68using JSDedicatedWorkerGlobalScopeConstructor = JSDOMConstructorNotConstructable<JSDedicatedWorkerGlobalScope>;
69
70/* Hash table */
71
72static const struct CompactHashIndex JSDedicatedWorkerGlobalScopeTableIndex[17] = {
73 { -1, -1 },
74 { -1, -1 },
75 { -1, -1 },
76 { -1, -1 },
77 { 1, -1 },
78 { -1, -1 },
79 { -1, -1 },
80 { -1, -1 },
81 { -1, -1 },
82 { 0, 16 },
83 { 5, -1 },
84 { 2, -1 },
85 { -1, -1 },
86 { -1, -1 },
87 { -1, -1 },
88 { 3, -1 },
89 { 4, -1 },
90};
91
92
93static const HashTableValue JSDedicatedWorkerGlobalScopeTableValues[] =
94{
95 { "name", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDedicatedWorkerGlobalScopeName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDedicatedWorkerGlobalScopeName) } },
96 { "onmessage", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDedicatedWorkerGlobalScopeOnmessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDedicatedWorkerGlobalScopeOnmessage) } },
97 { "DedicatedWorkerGlobalScope", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructor) } },
98 { "XMLHttpRequest", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDedicatedWorkerGlobalScopeXMLHttpRequestConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDedicatedWorkerGlobalScopeXMLHttpRequestConstructor) } },
99 { "postMessage", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDedicatedWorkerGlobalScopeInstanceFunctionPostMessage), (intptr_t) (1) } },
100 { "close", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDedicatedWorkerGlobalScopeInstanceFunctionClose), (intptr_t) (0) } },
101};
102
103static const HashTable JSDedicatedWorkerGlobalScopeTable = { 6, 15, true, JSDedicatedWorkerGlobalScope::info(), JSDedicatedWorkerGlobalScopeTableValues, JSDedicatedWorkerGlobalScopeTableIndex };
104template<> JSValue JSDedicatedWorkerGlobalScopeConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
105{
106 return JSWorkerGlobalScope::getConstructor(vm, &globalObject);
107}
108
109template<> void JSDedicatedWorkerGlobalScopeConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
110{
111 putDirect(vm, vm.propertyNames->prototype, globalObject.getPrototypeDirect(vm), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
112 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("DedicatedWorkerGlobalScope"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
113 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
114}
115
116template<> const ClassInfo JSDedicatedWorkerGlobalScopeConstructor::s_info = { "DedicatedWorkerGlobalScope", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDedicatedWorkerGlobalScopeConstructor) };
117
118/* Hash table for prototype */
119
120static const struct CompactHashIndex JSDedicatedWorkerGlobalScopePrototypeTableIndex[2] = {
121 { -1, -1 },
122 { 0, -1 },
123};
124
125
126static const HashTableValue JSDedicatedWorkerGlobalScopePrototypeTableValues[] =
127{
128 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDedicatedWorkerGlobalScopeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDedicatedWorkerGlobalScopeConstructor) } },
129};
130
131static const HashTable JSDedicatedWorkerGlobalScopePrototypeTable = { 1, 1, true, JSDedicatedWorkerGlobalScope::info(), JSDedicatedWorkerGlobalScopePrototypeTableValues, JSDedicatedWorkerGlobalScopePrototypeTableIndex };
132const ClassInfo JSDedicatedWorkerGlobalScopePrototype::s_info = { "DedicatedWorkerGlobalScopePrototype", &Base::s_info, &JSDedicatedWorkerGlobalScopePrototypeTable, nullptr, CREATE_METHOD_TABLE(JSDedicatedWorkerGlobalScopePrototype) };
133
134const ClassInfo JSDedicatedWorkerGlobalScope::s_info = { "DedicatedWorkerGlobalScope", &Base::s_info, &JSDedicatedWorkerGlobalScopeTable, nullptr, CREATE_METHOD_TABLE(JSDedicatedWorkerGlobalScope) };
135
136JSDedicatedWorkerGlobalScope::JSDedicatedWorkerGlobalScope(VM& vm, Structure* structure, Ref<DedicatedWorkerGlobalScope>&& impl)
137 : JSWorkerGlobalScope(vm, structure, WTFMove(impl))
138{
139}
140
141void JSDedicatedWorkerGlobalScope::finishCreation(VM& vm, JSProxy* proxy)
142{
143 Base::finishCreation(vm, proxy);
144
145}
146
147JSValue JSDedicatedWorkerGlobalScope::getConstructor(VM& vm, const JSGlobalObject* globalObject)
148{
149 return getDOMConstructor<JSDedicatedWorkerGlobalScopeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
150}
151
152template<> inline JSDedicatedWorkerGlobalScope* IDLAttribute<JSDedicatedWorkerGlobalScope>::cast(ExecState& state, EncodedJSValue thisValue)
153{
154 auto decodedThisValue = JSValue::decode(thisValue);
155 if (decodedThisValue.isUndefinedOrNull())
156 decodedThisValue = state.thisValue().toThis(&state, NotStrictMode);
157 return toJSDedicatedWorkerGlobalScope(state.vm(), decodedThisValue);}
158
159template<> inline JSDedicatedWorkerGlobalScope* IDLOperation<JSDedicatedWorkerGlobalScope>::cast(ExecState& state)
160{
161 return toJSDedicatedWorkerGlobalScope(state.vm(), state.thisValue().toThis(&state, NotStrictMode));
162}
163
164EncodedJSValue jsDedicatedWorkerGlobalScopeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
165{
166 VM& vm = state->vm();
167 auto throwScope = DECLARE_THROW_SCOPE(vm);
168 auto* prototype = jsDynamicCast<JSDedicatedWorkerGlobalScopePrototype*>(vm, JSValue::decode(thisValue));
169 if (UNLIKELY(!prototype))
170 return throwVMTypeError(state, throwScope);
171 return JSValue::encode(JSDedicatedWorkerGlobalScope::getConstructor(state->vm(), prototype->globalObject()));
172}
173
174bool setJSDedicatedWorkerGlobalScopeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
175{
176 VM& vm = state->vm();
177 auto throwScope = DECLARE_THROW_SCOPE(vm);
178 auto* prototype = jsDynamicCast<JSDedicatedWorkerGlobalScopePrototype*>(vm, JSValue::decode(thisValue));
179 if (UNLIKELY(!prototype)) {
180 throwVMTypeError(state, throwScope);
181 return false;
182 }
183 // Shadowing a built-in constructor
184 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
185}
186
187static inline JSValue jsDedicatedWorkerGlobalScopeNameGetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, ThrowScope& throwScope)
188{
189 UNUSED_PARAM(throwScope);
190 UNUSED_PARAM(state);
191 auto& impl = thisObject.wrapped();
192 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.name());
193 return result;
194}
195
196EncodedJSValue jsDedicatedWorkerGlobalScopeName(ExecState* state, EncodedJSValue thisValue, PropertyName)
197{
198 return IDLAttribute<JSDedicatedWorkerGlobalScope>::get<jsDedicatedWorkerGlobalScopeNameGetter>(*state, thisValue, "name");
199}
200
201static inline bool setJSDedicatedWorkerGlobalScopeNameSetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, JSValue value, ThrowScope& throwScope)
202{
203 UNUSED_PARAM(throwScope);
204 // Shadowing a built-in property.
205 return replaceStaticPropertySlot(state.vm(), &thisObject, Identifier::fromString(&state.vm(), reinterpret_cast<const LChar*>("name"), strlen("name")), value);
206}
207
208bool setJSDedicatedWorkerGlobalScopeName(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
209{
210 return IDLAttribute<JSDedicatedWorkerGlobalScope>::set<setJSDedicatedWorkerGlobalScopeNameSetter>(*state, thisValue, encodedValue, "name");
211}
212
213static inline JSValue jsDedicatedWorkerGlobalScopeOnmessageGetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, ThrowScope& throwScope)
214{
215 UNUSED_PARAM(throwScope);
216 UNUSED_PARAM(state);
217 return eventHandlerAttribute(thisObject.wrapped(), eventNames().messageEvent, worldForDOMObject(thisObject));
218}
219
220EncodedJSValue jsDedicatedWorkerGlobalScopeOnmessage(ExecState* state, EncodedJSValue thisValue, PropertyName)
221{
222 return IDLAttribute<JSDedicatedWorkerGlobalScope>::get<jsDedicatedWorkerGlobalScopeOnmessageGetter>(*state, thisValue, "onmessage");
223}
224
225static inline bool setJSDedicatedWorkerGlobalScopeOnmessageSetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, JSValue value, ThrowScope& throwScope)
226{
227 UNUSED_PARAM(throwScope);
228 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().messageEvent, value);
229 return true;
230}
231
232bool setJSDedicatedWorkerGlobalScopeOnmessage(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
233{
234 return IDLAttribute<JSDedicatedWorkerGlobalScope>::set<setJSDedicatedWorkerGlobalScopeOnmessageSetter>(*state, thisValue, encodedValue, "onmessage");
235}
236
237static inline JSValue jsDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructorGetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, ThrowScope& throwScope)
238{
239 UNUSED_PARAM(throwScope);
240 UNUSED_PARAM(state);
241 return JSDedicatedWorkerGlobalScope::getConstructor(state.vm(), thisObject.globalObject());
242}
243
244EncodedJSValue jsDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
245{
246 return IDLAttribute<JSDedicatedWorkerGlobalScope>::get<jsDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructorGetter>(*state, thisValue, "DedicatedWorkerGlobalScope");
247}
248
249static inline bool setJSDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructorSetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, JSValue value, ThrowScope& throwScope)
250{
251 UNUSED_PARAM(throwScope);
252 // Shadowing a built-in constructor.
253 return thisObject.putDirect(state.vm(), Identifier::fromString(&state.vm(), reinterpret_cast<const LChar*>("DedicatedWorkerGlobalScope"), strlen("DedicatedWorkerGlobalScope")), value);
254}
255
256bool setJSDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
257{
258 return IDLAttribute<JSDedicatedWorkerGlobalScope>::set<setJSDedicatedWorkerGlobalScopeDedicatedWorkerGlobalScopeConstructorSetter>(*state, thisValue, encodedValue, "DedicatedWorkerGlobalScope");
259}
260
261static inline JSValue jsDedicatedWorkerGlobalScopeXMLHttpRequestConstructorGetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, ThrowScope& throwScope)
262{
263 UNUSED_PARAM(throwScope);
264 UNUSED_PARAM(state);
265 return JSXMLHttpRequest::getConstructor(state.vm(), thisObject.globalObject());
266}
267
268EncodedJSValue jsDedicatedWorkerGlobalScopeXMLHttpRequestConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
269{
270 return IDLAttribute<JSDedicatedWorkerGlobalScope>::get<jsDedicatedWorkerGlobalScopeXMLHttpRequestConstructorGetter>(*state, thisValue, "XMLHttpRequest");
271}
272
273static inline bool setJSDedicatedWorkerGlobalScopeXMLHttpRequestConstructorSetter(ExecState& state, JSDedicatedWorkerGlobalScope& thisObject, JSValue value, ThrowScope& throwScope)
274{
275 UNUSED_PARAM(throwScope);
276 // Shadowing a built-in constructor.
277 return thisObject.putDirect(state.vm(), Identifier::fromString(&state.vm(), reinterpret_cast<const LChar*>("XMLHttpRequest"), strlen("XMLHttpRequest")), value);
278}
279
280bool setJSDedicatedWorkerGlobalScopeXMLHttpRequestConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
281{
282 return IDLAttribute<JSDedicatedWorkerGlobalScope>::set<setJSDedicatedWorkerGlobalScopeXMLHttpRequestConstructorSetter>(*state, thisValue, encodedValue, "XMLHttpRequest");
283}
284
285static inline JSC::EncodedJSValue jsDedicatedWorkerGlobalScopeInstanceFunctionPostMessageBody(JSC::ExecState* state, typename IDLOperation<JSDedicatedWorkerGlobalScope>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
286{
287 UNUSED_PARAM(state);
288 UNUSED_PARAM(throwScope);
289 auto& impl = castedThis->wrapped();
290 if (UNLIKELY(state->argumentCount() < 1))
291 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
292 auto message = convert<IDLAny>(*state, state->uncheckedArgument(0));
293 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
294 auto transfer = state->argument(1).isUndefined() ? Converter<IDLSequence<IDLObject>>::ReturnType{ } : convert<IDLSequence<IDLObject>>(*state, state->uncheckedArgument(1));
295 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
296 propagateException(*state, throwScope, impl.postMessage(*state, WTFMove(message), WTFMove(transfer)));
297 return JSValue::encode(jsUndefined());
298}
299
300EncodedJSValue JSC_HOST_CALL jsDedicatedWorkerGlobalScopeInstanceFunctionPostMessage(ExecState* state)
301{
302 return IDLOperation<JSDedicatedWorkerGlobalScope>::call<jsDedicatedWorkerGlobalScopeInstanceFunctionPostMessageBody>(*state, "postMessage");
303}
304
305static inline JSC::EncodedJSValue jsDedicatedWorkerGlobalScopeInstanceFunctionCloseBody(JSC::ExecState* state, typename IDLOperation<JSDedicatedWorkerGlobalScope>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
306{
307 UNUSED_PARAM(state);
308 UNUSED_PARAM(throwScope);
309 auto& impl = castedThis->wrapped();
310 impl.close();
311 return JSValue::encode(jsUndefined());
312}
313
314EncodedJSValue JSC_HOST_CALL jsDedicatedWorkerGlobalScopeInstanceFunctionClose(ExecState* state)
315{
316 return IDLOperation<JSDedicatedWorkerGlobalScope>::call<jsDedicatedWorkerGlobalScopeInstanceFunctionCloseBody>(*state, "close");
317}
318
319void JSDedicatedWorkerGlobalScope::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
320{
321 auto* thisObject = jsCast<JSDedicatedWorkerGlobalScope*>(cell);
322 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
323 if (thisObject->scriptExecutionContext())
324 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
325 Base::heapSnapshot(cell, builder);
326}
327
328DedicatedWorkerGlobalScope* JSDedicatedWorkerGlobalScope::toWrapped(JSC::VM& vm, JSC::JSValue value)
329{
330 if (auto* wrapper = jsDynamicCast<JSDedicatedWorkerGlobalScope*>(vm, value))
331 return &wrapper->wrapped();
332 return nullptr;
333}
334
335}
336