Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestGlobalObject.cpp
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 "JSTestGlobalObject.h"
23
24 #include "DOMWrapperWorld.h"
25 #include "JSDOMAttribute.h"
26 #include "JSDOMBinding.h"
27 #include "JSDOMConstructorNotConstructable.h"
28 #include "JSDOMConvertBoolean.h"
29 #include "JSDOMConvertNumbers.h"
30 #include "JSDOMConvertStrings.h"
31 #include "JSDOMExceptionHandling.h"
32 #include "JSDOMOperation.h"
33 #include "JSDOMOperationReturningPromise.h"
34 #include "JSDOMWrapperCache.h"
35 #include "RuntimeEnabledFeatures.h"
36 #include "ScriptExecutionContext.h"
37 #include "WebCoreJSClientData.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 #if ENABLE(TEST_FEATURE)
46 #include "TestGlobalObjectBuiltins.h"
47 #endif
48
49
50 namespace WebCore {
51 using namespace JSC;
52
53 // Functions
54
55 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionRegularOperation(JSC::ExecState*);
56 #if ENABLE(TEST_FEATURE)
57 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation(JSC::ExecState*);
58 #endif
59 #if ENABLE(TEST_FEATURE)
60 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectConstructorFunctionEnabledAtRuntimeOperationStatic(JSC::ExecState*);
61 #endif
62 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld(JSC::ExecState*);
63 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeatureEnabled(JSC::ExecState*);
64 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeaturesEnabled(JSC::ExecState*);
65 #if ENABLE(TEST_FEATURE)
66 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestPrivateFunction(JSC::ExecState*);
67 #endif
68 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionCalculateSecretResult(JSC::ExecState*);
69 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionGetSecretBoolean(JSC::ExecState*);
70 #if ENABLE(TEST_FEATURE)
71 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestFeatureGetSecretBoolean(JSC::ExecState*);
72 #endif
73
74 // Attributes
75
76 JSC::EncodedJSValue jsTestGlobalObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
77 bool setJSTestGlobalObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
78 JSC::EncodedJSValue jsTestGlobalObjectRegularAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
79 bool setJSTestGlobalObjectRegularAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
80 JSC::EncodedJSValue jsTestGlobalObjectPublicAndPrivateAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
81 bool setJSTestGlobalObjectPublicAndPrivateAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
82 #if ENABLE(TEST_FEATURE)
83 JSC::EncodedJSValue jsTestGlobalObjectPublicAndPrivateConditionalAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
84 bool setJSTestGlobalObjectPublicAndPrivateConditionalAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
85 #endif
86 #if ENABLE(TEST_FEATURE)
87 JSC::EncodedJSValue jsTestGlobalObjectEnabledAtRuntimeAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
88 bool setJSTestGlobalObjectEnabledAtRuntimeAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
89 #endif
90
91 using JSTestGlobalObjectConstructor = JSDOMConstructorNotConstructable<JSTestGlobalObject>;
92
93 /* Hash table */
94
95 static const struct CompactHashIndex JSTestGlobalObjectTableIndex[16] = {
96     { -1, -1 },
97     { -1, -1 },
98     { 2, -1 },
99     { 0, -1 },
100     { -1, -1 },
101     { -1, -1 },
102     { -1, -1 },
103     { -1, -1 },
104     { -1, -1 },
105     { 3, -1 },
106     { -1, -1 },
107     { -1, -1 },
108     { -1, -1 },
109     { -1, -1 },
110     { 1, -1 },
111     { -1, -1 },
112 };
113
114
115 static const HashTableValue JSTestGlobalObjectTableValues[] =
116 {
117     { "regularAttribute", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestGlobalObjectRegularAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestGlobalObjectRegularAttribute) } },
118     { "publicAndPrivateAttribute", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestGlobalObjectPublicAndPrivateAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestGlobalObjectPublicAndPrivateAttribute) } },
119 #if ENABLE(TEST_FEATURE)
120     { "publicAndPrivateConditionalAttribute", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestGlobalObjectPublicAndPrivateConditionalAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestGlobalObjectPublicAndPrivateConditionalAttribute) } },
121 #else
122     { 0, 0, NoIntrinsic, { 0, 0 } },
123 #endif
124     { "regularOperation", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestGlobalObjectInstanceFunctionRegularOperation), (intptr_t) (1) } },
125 };
126
127 static const HashTable JSTestGlobalObjectTable = { 4, 15, true, JSTestGlobalObject::info(), JSTestGlobalObjectTableValues, JSTestGlobalObjectTableIndex };
128 /* Hash table for constructor */
129
130 static const HashTableValue JSTestGlobalObjectConstructorTableValues[] =
131 {
132 #if ENABLE(TEST_FEATURE)
133     { "enabledAtRuntimeOperationStatic", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestGlobalObjectConstructorFunctionEnabledAtRuntimeOperationStatic), (intptr_t) (1) } },
134 #else
135     { 0, 0, NoIntrinsic, { 0, 0 } },
136 #endif
137 };
138
139 template<> JSValue JSTestGlobalObjectConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
140 {
141     UNUSED_PARAM(vm);
142     return globalObject.functionPrototype();
143 }
144
145 template<> void JSTestGlobalObjectConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
146 {
147     putDirect(vm, vm.propertyNames->prototype, globalObject.getPrototypeDirect(vm), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
148     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestGlobalObject"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
149     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
150     reifyStaticProperties(vm, JSTestGlobalObject::info(), JSTestGlobalObjectConstructorTableValues, *this);
151 }
152
153 template<> const ClassInfo JSTestGlobalObjectConstructor::s_info = { "TestGlobalObject", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestGlobalObjectConstructor) };
154
155 /* Hash table for prototype */
156
157 static const struct CompactHashIndex JSTestGlobalObjectPrototypeTableIndex[2] = {
158     { -1, -1 },
159     { 0, -1 },
160 };
161
162
163 static const HashTableValue JSTestGlobalObjectPrototypeTableValues[] =
164 {
165     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestGlobalObjectConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestGlobalObjectConstructor) } },
166 };
167
168 static const HashTable JSTestGlobalObjectPrototypeTable = { 1, 1, true, JSTestGlobalObject::info(), JSTestGlobalObjectPrototypeTableValues, JSTestGlobalObjectPrototypeTableIndex };
169 const ClassInfo JSTestGlobalObjectPrototype::s_info = { "TestGlobalObjectPrototype", &Base::s_info, &JSTestGlobalObjectPrototypeTable, nullptr, CREATE_METHOD_TABLE(JSTestGlobalObjectPrototype) };
170
171 const ClassInfo JSTestGlobalObject::s_info = { "TestGlobalObject", &Base::s_info, &JSTestGlobalObjectTable, nullptr, CREATE_METHOD_TABLE(JSTestGlobalObject) };
172
173 JSTestGlobalObject::JSTestGlobalObject(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestGlobalObject>&& impl)
174     : JSDOMWrapper<TestGlobalObject>(structure, globalObject, WTFMove(impl))
175 {
176 }
177
178 void JSTestGlobalObject::finishCreation(VM& vm)
179 {
180     Base::finishCreation(vm);
181     ASSERT(inherits(vm, info()));
182
183 #if ENABLE(TEST_FEATURE)
184     if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
185         putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().enabledAtRuntimeAttributePublicName(), CustomGetterSetter::create(vm, jsTestGlobalObjectEnabledAtRuntimeAttribute, setJSTestGlobalObjectEnabledAtRuntimeAttribute), attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor)));
186 #endif
187     putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().publicAndPrivateAttributePrivateName(), CustomGetterSetter::create(vm, jsTestGlobalObjectPublicAndPrivateAttribute, nullptr), attributesForStructure(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly));
188 #if ENABLE(TEST_FEATURE)
189     putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().publicAndPrivateConditionalAttributePrivateName(), CustomGetterSetter::create(vm, jsTestGlobalObjectPublicAndPrivateConditionalAttribute, nullptr), attributesForStructure(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly));
190 #endif
191 #if ENABLE(TEST_FEATURE)
192     if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
193         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().enabledAtRuntimeOperationPublicName(), 1, jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
194 #endif
195 #if ENABLE(TEST_FEATURE)
196     if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
197         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().enabledAtRuntimeOperationStaticPublicName(), 1, jsTestGlobalObjectConstructorFunctionEnabledAtRuntimeOperationStatic, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
198 #endif
199     if (worldForDOMObject(*this).specificWorld())
200         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().enabledInSpecificWorldPublicName(), 1, jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
201     if ((worldForDOMObject(*this).specificWorld() && RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled()))
202         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().enabledInSpecificWorldWhenRuntimeFeatureEnabledPublicName(), 1, jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeatureEnabled, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
203     if ((worldForDOMObject(*this).specificWorld() && RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled() && RuntimeEnabledFeatures::sharedFeatures().testFeature1Enabled()))
204         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().enabledInSpecificWorldWhenRuntimeFeaturesEnabledPublicName(), 1, jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeaturesEnabled, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
205 #if ENABLE(TEST_FEATURE)
206     if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
207         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().testPrivateFunctionPrivateName(), 0, jsTestGlobalObjectInstanceFunctionTestPrivateFunction, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
208 #endif
209 #if ENABLE(TEST_FEATURE)
210     if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
211         putDirectBuiltinFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().testJSBuiltinFunctionPublicName(), testGlobalObjectTestJSBuiltinFunctionCodeGenerator(vm), attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Builtin)));
212 #endif
213     if (jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isSecureContext())
214         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().calculateSecretResultPublicName(), 0, jsTestGlobalObjectInstanceFunctionCalculateSecretResult, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
215     if (jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isSecureContext())
216         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().getSecretBooleanPublicName(), 0, jsTestGlobalObjectInstanceFunctionGetSecretBoolean, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
217 #if ENABLE(TEST_FEATURE)
218     if ((jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isSecureContext() && RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled()))
219         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().testFeatureGetSecretBooleanPublicName(), 0, jsTestGlobalObjectInstanceFunctionTestFeatureGetSecretBoolean, NoIntrinsic, attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::Function)));
220 #endif
221 }
222
223 JSValue JSTestGlobalObject::getConstructor(VM& vm, const JSGlobalObject* globalObject)
224 {
225     return getDOMConstructor<JSTestGlobalObjectConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
226 }
227
228 void JSTestGlobalObject::destroy(JSC::JSCell* cell)
229 {
230     JSTestGlobalObject* thisObject = static_cast<JSTestGlobalObject*>(cell);
231     thisObject->JSTestGlobalObject::~JSTestGlobalObject();
232 }
233
234 template<> inline JSTestGlobalObject* IDLAttribute<JSTestGlobalObject>::cast(ExecState& state, EncodedJSValue thisValue)
235 {
236     return jsDynamicCast<JSTestGlobalObject*>(state.vm(), JSValue::decode(thisValue));
237 }
238
239 template<> inline JSTestGlobalObject* IDLOperation<JSTestGlobalObject>::cast(ExecState& state)
240 {
241     return jsDynamicCast<JSTestGlobalObject*>(state.vm(), state.thisValue());
242 }
243
244 EncodedJSValue jsTestGlobalObjectConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
245 {
246     VM& vm = state->vm();
247     auto throwScope = DECLARE_THROW_SCOPE(vm);
248     auto* prototype = jsDynamicCast<JSTestGlobalObjectPrototype*>(vm, JSValue::decode(thisValue));
249     if (UNLIKELY(!prototype))
250         return throwVMTypeError(state, throwScope);
251     return JSValue::encode(JSTestGlobalObject::getConstructor(state->vm(), prototype->globalObject()));
252 }
253
254 bool setJSTestGlobalObjectConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
255 {
256     VM& vm = state->vm();
257     auto throwScope = DECLARE_THROW_SCOPE(vm);
258     auto* prototype = jsDynamicCast<JSTestGlobalObjectPrototype*>(vm, JSValue::decode(thisValue));
259     if (UNLIKELY(!prototype)) {
260         throwVMTypeError(state, throwScope);
261         return false;
262     }
263     // Shadowing a built-in constructor
264     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
265 }
266
267 static inline JSValue jsTestGlobalObjectRegularAttributeGetter(ExecState& state, JSTestGlobalObject& thisObject, ThrowScope& throwScope)
268 {
269     UNUSED_PARAM(throwScope);
270     UNUSED_PARAM(state);
271     auto& impl = thisObject.wrapped();
272     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.regularAttribute());
273     return result;
274 }
275
276 EncodedJSValue jsTestGlobalObjectRegularAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
277 {
278     return IDLAttribute<JSTestGlobalObject>::get<jsTestGlobalObjectRegularAttributeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "regularAttribute");
279 }
280
281 static inline bool setJSTestGlobalObjectRegularAttributeSetter(ExecState& state, JSTestGlobalObject& thisObject, JSValue value, ThrowScope& throwScope)
282 {
283     UNUSED_PARAM(throwScope);
284     auto& impl = thisObject.wrapped();
285     auto nativeValue = convert<IDLDOMString>(state, value);
286     RETURN_IF_EXCEPTION(throwScope, false);
287     AttributeSetter::call(state, throwScope, [&] {
288         return impl.setRegularAttribute(WTFMove(nativeValue));
289     });
290     return true;
291 }
292
293 bool setJSTestGlobalObjectRegularAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
294 {
295     return IDLAttribute<JSTestGlobalObject>::set<setJSTestGlobalObjectRegularAttributeSetter>(*state, thisValue, encodedValue, "regularAttribute");
296 }
297
298 static inline JSValue jsTestGlobalObjectPublicAndPrivateAttributeGetter(ExecState& state, JSTestGlobalObject& thisObject, ThrowScope& throwScope)
299 {
300     UNUSED_PARAM(throwScope);
301     UNUSED_PARAM(state);
302     auto& impl = thisObject.wrapped();
303     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.publicAndPrivateAttribute());
304     return result;
305 }
306
307 EncodedJSValue jsTestGlobalObjectPublicAndPrivateAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
308 {
309     return IDLAttribute<JSTestGlobalObject>::get<jsTestGlobalObjectPublicAndPrivateAttributeGetter>(*state, thisValue, "publicAndPrivateAttribute");
310 }
311
312 static inline bool setJSTestGlobalObjectPublicAndPrivateAttributeSetter(ExecState& state, JSTestGlobalObject& thisObject, JSValue value, ThrowScope& throwScope)
313 {
314     UNUSED_PARAM(throwScope);
315     auto& impl = thisObject.wrapped();
316     auto nativeValue = convert<IDLDOMString>(state, value);
317     RETURN_IF_EXCEPTION(throwScope, false);
318     AttributeSetter::call(state, throwScope, [&] {
319         return impl.setPublicAndPrivateAttribute(WTFMove(nativeValue));
320     });
321     return true;
322 }
323
324 bool setJSTestGlobalObjectPublicAndPrivateAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
325 {
326     return IDLAttribute<JSTestGlobalObject>::set<setJSTestGlobalObjectPublicAndPrivateAttributeSetter>(*state, thisValue, encodedValue, "publicAndPrivateAttribute");
327 }
328
329 #if ENABLE(TEST_FEATURE)
330 static inline JSValue jsTestGlobalObjectPublicAndPrivateConditionalAttributeGetter(ExecState& state, JSTestGlobalObject& thisObject, ThrowScope& throwScope)
331 {
332     UNUSED_PARAM(throwScope);
333     UNUSED_PARAM(state);
334     auto& impl = thisObject.wrapped();
335     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.publicAndPrivateConditionalAttribute());
336     return result;
337 }
338
339 EncodedJSValue jsTestGlobalObjectPublicAndPrivateConditionalAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
340 {
341     return IDLAttribute<JSTestGlobalObject>::get<jsTestGlobalObjectPublicAndPrivateConditionalAttributeGetter>(*state, thisValue, "publicAndPrivateConditionalAttribute");
342 }
343
344 #endif
345
346 #if ENABLE(TEST_FEATURE)
347 static inline bool setJSTestGlobalObjectPublicAndPrivateConditionalAttributeSetter(ExecState& state, JSTestGlobalObject& thisObject, JSValue value, ThrowScope& throwScope)
348 {
349     UNUSED_PARAM(throwScope);
350     auto& impl = thisObject.wrapped();
351     auto nativeValue = convert<IDLDOMString>(state, value);
352     RETURN_IF_EXCEPTION(throwScope, false);
353     AttributeSetter::call(state, throwScope, [&] {
354         return impl.setPublicAndPrivateConditionalAttribute(WTFMove(nativeValue));
355     });
356     return true;
357 }
358
359 bool setJSTestGlobalObjectPublicAndPrivateConditionalAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
360 {
361     return IDLAttribute<JSTestGlobalObject>::set<setJSTestGlobalObjectPublicAndPrivateConditionalAttributeSetter>(*state, thisValue, encodedValue, "publicAndPrivateConditionalAttribute");
362 }
363
364 #endif
365
366 #if ENABLE(TEST_FEATURE)
367 static inline JSValue jsTestGlobalObjectEnabledAtRuntimeAttributeGetter(ExecState& state, JSTestGlobalObject& thisObject, ThrowScope& throwScope)
368 {
369     UNUSED_PARAM(throwScope);
370     UNUSED_PARAM(state);
371     auto& impl = thisObject.wrapped();
372     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.enabledAtRuntimeAttribute());
373     return result;
374 }
375
376 EncodedJSValue jsTestGlobalObjectEnabledAtRuntimeAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
377 {
378     return IDLAttribute<JSTestGlobalObject>::get<jsTestGlobalObjectEnabledAtRuntimeAttributeGetter>(*state, thisValue, "enabledAtRuntimeAttribute");
379 }
380
381 #endif
382
383 #if ENABLE(TEST_FEATURE)
384 static inline bool setJSTestGlobalObjectEnabledAtRuntimeAttributeSetter(ExecState& state, JSTestGlobalObject& thisObject, JSValue value, ThrowScope& throwScope)
385 {
386     UNUSED_PARAM(throwScope);
387     auto& impl = thisObject.wrapped();
388     auto nativeValue = convert<IDLDOMString>(state, value);
389     RETURN_IF_EXCEPTION(throwScope, false);
390     AttributeSetter::call(state, throwScope, [&] {
391         return impl.setEnabledAtRuntimeAttribute(WTFMove(nativeValue));
392     });
393     return true;
394 }
395
396 bool setJSTestGlobalObjectEnabledAtRuntimeAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
397 {
398     return IDLAttribute<JSTestGlobalObject>::set<setJSTestGlobalObjectEnabledAtRuntimeAttributeSetter>(*state, thisValue, encodedValue, "enabledAtRuntimeAttribute");
399 }
400
401 #endif
402
403 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionRegularOperationBody(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
404 {
405     UNUSED_PARAM(state);
406     UNUSED_PARAM(throwScope);
407     auto& impl = castedThis->wrapped();
408     if (UNLIKELY(state->argumentCount() < 1))
409         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
410     auto testParam = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
411     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
412     impl.regularOperation(WTFMove(testParam));
413     return JSValue::encode(jsUndefined());
414 }
415
416 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionRegularOperation(ExecState* state)
417 {
418     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionRegularOperationBody>(*state, "regularOperation");
419 }
420
421 #if ENABLE(TEST_FEATURE)
422 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation1Body(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
423 {
424     UNUSED_PARAM(state);
425     UNUSED_PARAM(throwScope);
426     auto& impl = castedThis->wrapped();
427     auto testParam = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
428     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
429     impl.enabledAtRuntimeOperation(WTFMove(testParam));
430     return JSValue::encode(jsUndefined());
431 }
432
433 #endif
434
435 #if ENABLE(TEST_FEATURE)
436 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation2Body(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
437 {
438     UNUSED_PARAM(state);
439     UNUSED_PARAM(throwScope);
440     auto& impl = castedThis->wrapped();
441     auto testParam = convert<IDLLong>(*state, state->uncheckedArgument(0));
442     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
443     impl.enabledAtRuntimeOperation(WTFMove(testParam));
444     return JSValue::encode(jsUndefined());
445 }
446
447 #endif
448
449 #if ENABLE(TEST_FEATURE)
450
451 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperationOverloadDispatcher(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
452 {
453     UNUSED_PARAM(state);
454     UNUSED_PARAM(throwScope);
455     VM& vm = state->vm();
456     UNUSED_PARAM(vm);
457     size_t argsCount = std::min<size_t>(1, state->argumentCount());
458     if (argsCount == 1) {
459         JSValue distinguishingArg = state->uncheckedArgument(0);
460 #if ENABLE(TEST_FEATURE)
461         if (distinguishingArg.isNumber())
462             return jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation2Body(state, castedThis, throwScope);
463 #endif
464 #if ENABLE(TEST_FEATURE)
465         return jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation1Body(state, castedThis, throwScope);
466 #endif
467     }
468     return argsCount < 1 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope);
469 }
470
471 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation(ExecState* state)
472 {
473     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperationOverloadDispatcher>(*state, "enabledAtRuntimeOperation");
474 }
475
476 #endif
477
478 #if ENABLE(TEST_FEATURE)
479 static inline JSC::EncodedJSValue jsTestGlobalObjectConstructorFunctionEnabledAtRuntimeOperationStaticBody(JSC::ExecState* state, JSC::ThrowScope& throwScope)
480 {
481     UNUSED_PARAM(state);
482     UNUSED_PARAM(throwScope);
483     if (UNLIKELY(state->argumentCount() < 1))
484         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
485     auto testParam = convert<IDLLong>(*state, state->uncheckedArgument(0));
486     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
487     TestGlobalObject::enabledAtRuntimeOperationStatic(WTFMove(testParam));
488     return JSValue::encode(jsUndefined());
489 }
490
491 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectConstructorFunctionEnabledAtRuntimeOperationStatic(ExecState* state)
492 {
493     return IDLOperation<JSTestGlobalObject>::callStatic<jsTestGlobalObjectConstructorFunctionEnabledAtRuntimeOperationStaticBody>(*state, "enabledAtRuntimeOperationStatic");
494 }
495
496 #endif
497
498 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldBody(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
499 {
500     UNUSED_PARAM(state);
501     UNUSED_PARAM(throwScope);
502     auto& impl = castedThis->wrapped();
503     if (UNLIKELY(state->argumentCount() < 1))
504         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
505     auto testParam = convert<IDLLong>(*state, state->uncheckedArgument(0));
506     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
507     impl.enabledInSpecificWorld(WTFMove(testParam));
508     return JSValue::encode(jsUndefined());
509 }
510
511 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld(ExecState* state)
512 {
513     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldBody>(*state, "enabledInSpecificWorld");
514 }
515
516 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeatureEnabledBody(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
517 {
518     UNUSED_PARAM(state);
519     UNUSED_PARAM(throwScope);
520     auto& impl = castedThis->wrapped();
521     if (UNLIKELY(state->argumentCount() < 1))
522         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
523     auto testParam = convert<IDLLong>(*state, state->uncheckedArgument(0));
524     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
525     impl.enabledInSpecificWorldWhenRuntimeFeatureEnabled(WTFMove(testParam));
526     return JSValue::encode(jsUndefined());
527 }
528
529 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeatureEnabled(ExecState* state)
530 {
531     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeatureEnabledBody>(*state, "enabledInSpecificWorldWhenRuntimeFeatureEnabled");
532 }
533
534 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeaturesEnabledBody(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
535 {
536     UNUSED_PARAM(state);
537     UNUSED_PARAM(throwScope);
538     auto& impl = castedThis->wrapped();
539     if (UNLIKELY(state->argumentCount() < 1))
540         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
541     auto testParam = convert<IDLLong>(*state, state->uncheckedArgument(0));
542     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
543     impl.enabledInSpecificWorldWhenRuntimeFeaturesEnabled(WTFMove(testParam));
544     return JSValue::encode(jsUndefined());
545 }
546
547 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeaturesEnabled(ExecState* state)
548 {
549     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldWhenRuntimeFeaturesEnabledBody>(*state, "enabledInSpecificWorldWhenRuntimeFeaturesEnabled");
550 }
551
552 #if ENABLE(TEST_FEATURE)
553 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionTestPrivateFunctionBody(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
554 {
555     UNUSED_PARAM(state);
556     UNUSED_PARAM(throwScope);
557     auto& impl = castedThis->wrapped();
558     impl.testPrivateFunction();
559     return JSValue::encode(jsUndefined());
560 }
561
562 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestPrivateFunction(ExecState* state)
563 {
564     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionTestPrivateFunctionBody, CastedThisErrorBehavior::Assert>(*state, "testPrivateFunction");
565 }
566
567 #endif
568
569 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionCalculateSecretResultBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSTestGlobalObject>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
570 {
571     UNUSED_PARAM(state);
572     UNUSED_PARAM(throwScope);
573     auto& impl = castedThis->wrapped();
574     impl.calculateSecretResult(WTFMove(promise));
575     return JSValue::encode(jsUndefined());
576 }
577
578 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionCalculateSecretResult(ExecState* state)
579 {
580     return IDLOperationReturningPromise<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionCalculateSecretResultBody, PromiseExecutionScope::WindowOnly>(*state, "calculateSecretResult");
581 }
582
583 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionGetSecretBooleanBody(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
584 {
585     UNUSED_PARAM(state);
586     UNUSED_PARAM(throwScope);
587     auto& impl = castedThis->wrapped();
588     return JSValue::encode(toJS<IDLBoolean>(impl.getSecretBoolean()));
589 }
590
591 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionGetSecretBoolean(ExecState* state)
592 {
593     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionGetSecretBooleanBody>(*state, "getSecretBoolean");
594 }
595
596 #if ENABLE(TEST_FEATURE)
597 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionTestFeatureGetSecretBooleanBody(JSC::ExecState* state, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
598 {
599     UNUSED_PARAM(state);
600     UNUSED_PARAM(throwScope);
601     auto& impl = castedThis->wrapped();
602     return JSValue::encode(toJS<IDLBoolean>(impl.testFeatureGetSecretBoolean()));
603 }
604
605 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestFeatureGetSecretBoolean(ExecState* state)
606 {
607     return IDLOperation<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionTestFeatureGetSecretBooleanBody>(*state, "testFeatureGetSecretBoolean");
608 }
609
610 #endif
611
612 void JSTestGlobalObject::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
613 {
614     auto* thisObject = jsCast<JSTestGlobalObject*>(cell);
615     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
616     if (thisObject->scriptExecutionContext())
617         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
618     Base::heapSnapshot(cell, builder);
619 }
620
621 bool JSTestGlobalObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
622 {
623     UNUSED_PARAM(handle);
624     UNUSED_PARAM(visitor);
625     UNUSED_PARAM(reason);
626     return false;
627 }
628
629 void JSTestGlobalObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
630 {
631     auto* jsTestGlobalObject = static_cast<JSTestGlobalObject*>(handle.slot()->asCell());
632     auto& world = *static_cast<DOMWrapperWorld*>(context);
633     uncacheWrapper(world, &jsTestGlobalObject->wrapped(), jsTestGlobalObject);
634 }
635
636 #if ENABLE(BINDING_INTEGRITY)
637 #if PLATFORM(WIN)
638 #pragma warning(disable: 4483)
639 extern "C" { extern void (*const __identifier("??_7TestGlobalObject@WebCore@@6B@")[])(); }
640 #else
641 extern "C" { extern void* _ZTVN7WebCore16TestGlobalObjectE[]; }
642 #endif
643 #endif
644
645 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestGlobalObject>&& impl)
646 {
647
648 #if ENABLE(BINDING_INTEGRITY)
649     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
650 #if PLATFORM(WIN)
651     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestGlobalObject@WebCore@@6B@"));
652 #else
653     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore16TestGlobalObjectE[2]);
654 #endif
655
656     // If this fails TestGlobalObject does not have a vtable, so you need to add the
657     // ImplementationLacksVTable attribute to the interface definition
658     static_assert(std::is_polymorphic<TestGlobalObject>::value, "TestGlobalObject is not polymorphic");
659
660     // If you hit this assertion you either have a use after free bug, or
661     // TestGlobalObject has subclasses. If TestGlobalObject has subclasses that get passed
662     // to toJS() we currently require TestGlobalObject you to opt out of binding hardening
663     // by adding the SkipVTableValidation attribute to the interface IDL definition
664     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
665 #endif
666     return createWrapper<TestGlobalObject>(globalObject, WTFMove(impl));
667 }
668
669 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestGlobalObject& impl)
670 {
671     return wrap(state, globalObject, impl);
672 }
673
674 TestGlobalObject* JSTestGlobalObject::toWrapped(JSC::VM& vm, JSC::JSValue value)
675 {
676     if (auto* wrapper = jsDynamicCast<JSTestGlobalObject*>(vm, value))
677         return &wrapper->wrapped();
678     return nullptr;
679 }
680
681 }