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