Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestEnabledBySetting.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 "JSTestEnabledBySetting.h"
23
24 #include "Document.h"
25 #include "JSDOMAttribute.h"
26 #include "JSDOMBinding.h"
27 #include "JSDOMConstructorNotConstructable.h"
28 #include "JSDOMExceptionHandling.h"
29 #include "JSDOMOperation.h"
30 #include "JSDOMWrapperCache.h"
31 #include "JSTestSubObj.h"
32 #include "ScriptExecutionContext.h"
33 #include "Settings.h"
34 #include "WebCoreJSClientData.h"
35 #include <JavaScriptCore/FunctionPrototype.h>
36 #include <JavaScriptCore/HeapSnapshotBuilder.h>
37 #include <JavaScriptCore/JSCInlines.h>
38 #include <wtf/GetPtr.h>
39 #include <wtf/PointerPreparations.h>
40 #include <wtf/URL.h>
41
42 #if ENABLE(TEST_FEATURE)
43 #include "JSDOMConvertStrings.h"
44 #endif
45
46
47 namespace WebCore {
48 using namespace JSC;
49
50 // Functions
51
52 #if ENABLE(TEST_FEATURE)
53 JSC::EncodedJSValue JSC_HOST_CALL jsTestEnabledBySettingPrototypeFunctionEnabledBySettingOperation(JSC::ExecState*);
54 #endif
55
56 // Attributes
57
58 JSC::EncodedJSValue jsTestEnabledBySettingConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
59 bool setJSTestEnabledBySettingConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
60 JSC::EncodedJSValue jsTestEnabledBySettingTestSubObjEnabledBySettingConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
61 bool setJSTestEnabledBySettingTestSubObjEnabledBySettingConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
62 #if ENABLE(TEST_FEATURE)
63 JSC::EncodedJSValue jsTestEnabledBySettingEnabledBySettingAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
64 bool setJSTestEnabledBySettingEnabledBySettingAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
65 #endif
66
67 class JSTestEnabledBySettingPrototype : public JSC::JSNonFinalObject {
68 public:
69     using Base = JSC::JSNonFinalObject;
70     static JSTestEnabledBySettingPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
71     {
72         JSTestEnabledBySettingPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestEnabledBySettingPrototype>(vm.heap)) JSTestEnabledBySettingPrototype(vm, globalObject, structure);
73         ptr->finishCreation(vm);
74         return ptr;
75     }
76
77     DECLARE_INFO;
78     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
79     {
80         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
81     }
82
83 private:
84     JSTestEnabledBySettingPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
85         : JSC::JSNonFinalObject(vm, structure)
86     {
87     }
88
89     void finishCreation(JSC::VM&);
90 };
91
92 using JSTestEnabledBySettingConstructor = JSDOMConstructorNotConstructable<JSTestEnabledBySetting>;
93
94 template<> JSValue JSTestEnabledBySettingConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
95 {
96     UNUSED_PARAM(vm);
97     return globalObject.functionPrototype();
98 }
99
100 template<> void JSTestEnabledBySettingConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
101 {
102     putDirect(vm, vm.propertyNames->prototype, JSTestEnabledBySetting::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
103     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestEnabledBySetting"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
104     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
105 }
106
107 template<> const ClassInfo JSTestEnabledBySettingConstructor::s_info = { "TestEnabledBySetting", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEnabledBySettingConstructor) };
108
109 /* Hash table for prototype */
110
111 static const HashTableValue JSTestEnabledBySettingPrototypeTableValues[] =
112 {
113     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEnabledBySettingConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestEnabledBySettingConstructor) } },
114 #if ENABLE(TEST_FEATURE)
115     { "enabledBySettingAttribute", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEnabledBySettingEnabledBySettingAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestEnabledBySettingEnabledBySettingAttribute) } },
116 #else
117     { 0, 0, NoIntrinsic, { 0, 0 } },
118 #endif
119 #if ENABLE(TEST_FEATURE)
120     { "enabledBySettingOperation", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestEnabledBySettingPrototypeFunctionEnabledBySettingOperation), (intptr_t) (1) } },
121 #else
122     { 0, 0, NoIntrinsic, { 0, 0 } },
123 #endif
124 };
125
126 const ClassInfo JSTestEnabledBySettingPrototype::s_info = { "TestEnabledBySettingPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEnabledBySettingPrototype) };
127
128 void JSTestEnabledBySettingPrototype::finishCreation(VM& vm)
129 {
130     Base::finishCreation(vm);
131     reifyStaticProperties(vm, JSTestEnabledBySetting::info(), JSTestEnabledBySettingPrototypeTableValues, *this);
132 #if ENABLE(TEST_FEATURE)
133     if (!downcast<Document>(jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext())->settings().testSettingEnabled()) {
134         auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("enabledBySettingOperation"), strlen("enabledBySettingOperation"));
135         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
136         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
137     }
138 #endif
139 #if ENABLE(TEST_FEATURE)
140     if (!downcast<Document>(jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext())->settings().testSettingEnabled()) {
141         auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("enabledBySettingAttribute"), strlen("enabledBySettingAttribute"));
142         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
143         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
144     }
145 #endif
146 }
147
148 const ClassInfo JSTestEnabledBySetting::s_info = { "TestEnabledBySetting", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEnabledBySetting) };
149
150 JSTestEnabledBySetting::JSTestEnabledBySetting(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestEnabledBySetting>&& impl)
151     : JSDOMWrapper<TestEnabledBySetting>(structure, globalObject, WTFMove(impl))
152 {
153 }
154
155 void JSTestEnabledBySetting::finishCreation(VM& vm)
156 {
157     Base::finishCreation(vm);
158     ASSERT(inherits(vm, info()));
159
160     if (downcast<Document>(jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext())->settings().testSettingEnabled())
161         putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().TestSubObjEnabledBySettingPublicName(), CustomGetterSetter::create(vm, jsTestEnabledBySettingTestSubObjEnabledBySettingConstructor, setJSTestEnabledBySettingTestSubObjEnabledBySettingConstructor), attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::DontEnum)));
162 }
163
164 JSObject* JSTestEnabledBySetting::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
165 {
166     return JSTestEnabledBySettingPrototype::create(vm, &globalObject, JSTestEnabledBySettingPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
167 }
168
169 JSObject* JSTestEnabledBySetting::prototype(VM& vm, JSDOMGlobalObject& globalObject)
170 {
171     return getDOMPrototype<JSTestEnabledBySetting>(vm, globalObject);
172 }
173
174 JSValue JSTestEnabledBySetting::getConstructor(VM& vm, const JSGlobalObject* globalObject)
175 {
176     return getDOMConstructor<JSTestEnabledBySettingConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
177 }
178
179 void JSTestEnabledBySetting::destroy(JSC::JSCell* cell)
180 {
181     JSTestEnabledBySetting* thisObject = static_cast<JSTestEnabledBySetting*>(cell);
182     thisObject->JSTestEnabledBySetting::~JSTestEnabledBySetting();
183 }
184
185 template<> inline JSTestEnabledBySetting* IDLAttribute<JSTestEnabledBySetting>::cast(ExecState& state, EncodedJSValue thisValue)
186 {
187     return jsDynamicCast<JSTestEnabledBySetting*>(state.vm(), JSValue::decode(thisValue));
188 }
189
190 template<> inline JSTestEnabledBySetting* IDLOperation<JSTestEnabledBySetting>::cast(ExecState& state)
191 {
192     return jsDynamicCast<JSTestEnabledBySetting*>(state.vm(), state.thisValue());
193 }
194
195 EncodedJSValue jsTestEnabledBySettingConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
196 {
197     VM& vm = state->vm();
198     auto throwScope = DECLARE_THROW_SCOPE(vm);
199     auto* prototype = jsDynamicCast<JSTestEnabledBySettingPrototype*>(vm, JSValue::decode(thisValue));
200     if (UNLIKELY(!prototype))
201         return throwVMTypeError(state, throwScope);
202     return JSValue::encode(JSTestEnabledBySetting::getConstructor(state->vm(), prototype->globalObject()));
203 }
204
205 bool setJSTestEnabledBySettingConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
206 {
207     VM& vm = state->vm();
208     auto throwScope = DECLARE_THROW_SCOPE(vm);
209     auto* prototype = jsDynamicCast<JSTestEnabledBySettingPrototype*>(vm, JSValue::decode(thisValue));
210     if (UNLIKELY(!prototype)) {
211         throwVMTypeError(state, throwScope);
212         return false;
213     }
214     // Shadowing a built-in constructor
215     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
216 }
217
218 static inline JSValue jsTestEnabledBySettingTestSubObjEnabledBySettingConstructorGetter(ExecState& state, JSTestEnabledBySetting& thisObject, ThrowScope& throwScope)
219 {
220     UNUSED_PARAM(throwScope);
221     UNUSED_PARAM(state);
222     return JSTestSubObj::getConstructor(state.vm(), thisObject.globalObject());
223 }
224
225 EncodedJSValue jsTestEnabledBySettingTestSubObjEnabledBySettingConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
226 {
227     return IDLAttribute<JSTestEnabledBySetting>::get<jsTestEnabledBySettingTestSubObjEnabledBySettingConstructorGetter>(*state, thisValue, "TestSubObjEnabledBySetting");
228 }
229
230 static inline bool setJSTestEnabledBySettingTestSubObjEnabledBySettingConstructorSetter(ExecState& state, JSTestEnabledBySetting& thisObject, JSValue value, ThrowScope& throwScope)
231 {
232     UNUSED_PARAM(throwScope);
233     // Shadowing a built-in constructor.
234     return thisObject.putDirect(state.vm(), Identifier::fromString(&state.vm(), reinterpret_cast<const LChar*>("TestSubObjEnabledBySetting"), strlen("TestSubObjEnabledBySetting")), value);
235 }
236
237 bool setJSTestEnabledBySettingTestSubObjEnabledBySettingConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
238 {
239     return IDLAttribute<JSTestEnabledBySetting>::set<setJSTestEnabledBySettingTestSubObjEnabledBySettingConstructorSetter>(*state, thisValue, encodedValue, "TestSubObjEnabledBySetting");
240 }
241
242 #if ENABLE(TEST_FEATURE)
243 static inline JSValue jsTestEnabledBySettingEnabledBySettingAttributeGetter(ExecState& state, JSTestEnabledBySetting& thisObject, ThrowScope& throwScope)
244 {
245     UNUSED_PARAM(throwScope);
246     UNUSED_PARAM(state);
247     auto& impl = thisObject.wrapped();
248     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.enabledBySettingAttribute());
249     return result;
250 }
251
252 EncodedJSValue jsTestEnabledBySettingEnabledBySettingAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
253 {
254     return IDLAttribute<JSTestEnabledBySetting>::get<jsTestEnabledBySettingEnabledBySettingAttributeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "enabledBySettingAttribute");
255 }
256
257 #endif
258
259 #if ENABLE(TEST_FEATURE)
260 static inline bool setJSTestEnabledBySettingEnabledBySettingAttributeSetter(ExecState& state, JSTestEnabledBySetting& thisObject, JSValue value, ThrowScope& throwScope)
261 {
262     UNUSED_PARAM(throwScope);
263     auto& impl = thisObject.wrapped();
264     auto nativeValue = convert<IDLDOMString>(state, value);
265     RETURN_IF_EXCEPTION(throwScope, false);
266     AttributeSetter::call(state, throwScope, [&] {
267         return impl.setEnabledBySettingAttribute(WTFMove(nativeValue));
268     });
269     return true;
270 }
271
272 bool setJSTestEnabledBySettingEnabledBySettingAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
273 {
274     return IDLAttribute<JSTestEnabledBySetting>::set<setJSTestEnabledBySettingEnabledBySettingAttributeSetter>(*state, thisValue, encodedValue, "enabledBySettingAttribute");
275 }
276
277 #endif
278
279 #if ENABLE(TEST_FEATURE)
280 static inline JSC::EncodedJSValue jsTestEnabledBySettingPrototypeFunctionEnabledBySettingOperationBody(JSC::ExecState* state, typename IDLOperation<JSTestEnabledBySetting>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
281 {
282     UNUSED_PARAM(state);
283     UNUSED_PARAM(throwScope);
284     auto& impl = castedThis->wrapped();
285     if (UNLIKELY(state->argumentCount() < 1))
286         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
287     auto testParam = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
288     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
289     impl.enabledBySettingOperation(WTFMove(testParam));
290     return JSValue::encode(jsUndefined());
291 }
292
293 EncodedJSValue JSC_HOST_CALL jsTestEnabledBySettingPrototypeFunctionEnabledBySettingOperation(ExecState* state)
294 {
295     return IDLOperation<JSTestEnabledBySetting>::call<jsTestEnabledBySettingPrototypeFunctionEnabledBySettingOperationBody>(*state, "enabledBySettingOperation");
296 }
297
298 #endif
299
300 void JSTestEnabledBySetting::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
301 {
302     auto* thisObject = jsCast<JSTestEnabledBySetting*>(cell);
303     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
304     if (thisObject->scriptExecutionContext())
305         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
306     Base::heapSnapshot(cell, builder);
307 }
308
309 bool JSTestEnabledBySettingOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
310 {
311     UNUSED_PARAM(handle);
312     UNUSED_PARAM(visitor);
313     UNUSED_PARAM(reason);
314     return false;
315 }
316
317 void JSTestEnabledBySettingOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
318 {
319     auto* jsTestEnabledBySetting = static_cast<JSTestEnabledBySetting*>(handle.slot()->asCell());
320     auto& world = *static_cast<DOMWrapperWorld*>(context);
321     uncacheWrapper(world, &jsTestEnabledBySetting->wrapped(), jsTestEnabledBySetting);
322 }
323
324 #if ENABLE(BINDING_INTEGRITY)
325 #if PLATFORM(WIN)
326 #pragma warning(disable: 4483)
327 extern "C" { extern void (*const __identifier("??_7TestEnabledBySetting@WebCore@@6B@")[])(); }
328 #else
329 extern "C" { extern void* _ZTVN7WebCore20TestEnabledBySettingE[]; }
330 #endif
331 #endif
332
333 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestEnabledBySetting>&& impl)
334 {
335
336 #if ENABLE(BINDING_INTEGRITY)
337     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
338 #if PLATFORM(WIN)
339     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestEnabledBySetting@WebCore@@6B@"));
340 #else
341     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore20TestEnabledBySettingE[2]);
342 #endif
343
344     // If this fails TestEnabledBySetting does not have a vtable, so you need to add the
345     // ImplementationLacksVTable attribute to the interface definition
346     static_assert(std::is_polymorphic<TestEnabledBySetting>::value, "TestEnabledBySetting is not polymorphic");
347
348     // If you hit this assertion you either have a use after free bug, or
349     // TestEnabledBySetting has subclasses. If TestEnabledBySetting has subclasses that get passed
350     // to toJS() we currently require TestEnabledBySetting you to opt out of binding hardening
351     // by adding the SkipVTableValidation attribute to the interface IDL definition
352     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
353 #endif
354     return createWrapper<TestEnabledBySetting>(globalObject, WTFMove(impl));
355 }
356
357 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestEnabledBySetting& impl)
358 {
359     return wrap(state, globalObject, impl);
360 }
361
362 TestEnabledBySetting* JSTestEnabledBySetting::toWrapped(JSC::VM& vm, JSC::JSValue value)
363 {
364     if (auto* wrapper = jsDynamicCast<JSTestEnabledBySetting*>(vm, value))
365         return &wrapper->wrapped();
366     return nullptr;
367 }
368
369 }