Add [ActiveDOMObject] to IDLs of ActiveDOMObjects
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedGetterWithIdentifier.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 "JSTestNamedGetterWithIdentifier.h"
23
24 #include "ActiveDOMObject.h"
25 #include "JSDOMAbstractOperations.h"
26 #include "JSDOMBinding.h"
27 #include "JSDOMConstructorNotConstructable.h"
28 #include "JSDOMConvertStrings.h"
29 #include "JSDOMExceptionHandling.h"
30 #include "JSDOMOperation.h"
31 #include "JSDOMWrapperCache.h"
32 #include "ScriptExecutionContext.h"
33 #include <JavaScriptCore/FunctionPrototype.h>
34 #include <JavaScriptCore/HeapAnalyzer.h>
35 #include <JavaScriptCore/JSCInlines.h>
36 #include <wtf/GetPtr.h>
37 #include <wtf/PointerPreparations.h>
38 #include <wtf/URL.h>
39
40
41 namespace WebCore {
42 using namespace JSC;
43
44 // Functions
45
46 JSC::EncodedJSValue JSC_HOST_CALL jsTestNamedGetterWithIdentifierPrototypeFunctionGetterName(JSC::JSGlobalObject*, JSC::CallFrame*);
47
48 // Attributes
49
50 JSC::EncodedJSValue jsTestNamedGetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
51 bool setJSTestNamedGetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
52
53 class JSTestNamedGetterWithIdentifierPrototype : public JSC::JSNonFinalObject {
54 public:
55     using Base = JSC::JSNonFinalObject;
56     static JSTestNamedGetterWithIdentifierPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
57     {
58         JSTestNamedGetterWithIdentifierPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedGetterWithIdentifierPrototype>(vm.heap)) JSTestNamedGetterWithIdentifierPrototype(vm, globalObject, structure);
59         ptr->finishCreation(vm);
60         return ptr;
61     }
62
63     DECLARE_INFO;
64     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
65     {
66         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
67     }
68
69 private:
70     JSTestNamedGetterWithIdentifierPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
71         : JSC::JSNonFinalObject(vm, structure)
72     {
73     }
74
75     void finishCreation(JSC::VM&);
76 };
77
78 using JSTestNamedGetterWithIdentifierConstructor = JSDOMConstructorNotConstructable<JSTestNamedGetterWithIdentifier>;
79
80 template<> JSValue JSTestNamedGetterWithIdentifierConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
81 {
82     UNUSED_PARAM(vm);
83     return globalObject.functionPrototype();
84 }
85
86 template<> void JSTestNamedGetterWithIdentifierConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
87 {
88     putDirect(vm, vm.propertyNames->prototype, JSTestNamedGetterWithIdentifier::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
89     putDirect(vm, vm.propertyNames->name, jsNontrivialString(vm, String("TestNamedGetterWithIdentifier"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
90     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
91 }
92
93 template<> const ClassInfo JSTestNamedGetterWithIdentifierConstructor::s_info = { "TestNamedGetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterWithIdentifierConstructor) };
94
95 /* Hash table for prototype */
96
97 static const HashTableValue JSTestNamedGetterWithIdentifierPrototypeTableValues[] =
98 {
99     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedGetterWithIdentifierConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedGetterWithIdentifierConstructor) } },
100     { "getterName", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestNamedGetterWithIdentifierPrototypeFunctionGetterName), (intptr_t) (1) } },
101 };
102
103 const ClassInfo JSTestNamedGetterWithIdentifierPrototype::s_info = { "TestNamedGetterWithIdentifierPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterWithIdentifierPrototype) };
104
105 void JSTestNamedGetterWithIdentifierPrototype::finishCreation(VM& vm)
106 {
107     Base::finishCreation(vm);
108     reifyStaticProperties(vm, JSTestNamedGetterWithIdentifier::info(), JSTestNamedGetterWithIdentifierPrototypeTableValues, *this);
109 }
110
111 const ClassInfo JSTestNamedGetterWithIdentifier::s_info = { "TestNamedGetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterWithIdentifier) };
112
113 JSTestNamedGetterWithIdentifier::JSTestNamedGetterWithIdentifier(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedGetterWithIdentifier>&& impl)
114     : JSDOMWrapper<TestNamedGetterWithIdentifier>(structure, globalObject, WTFMove(impl))
115 {
116 }
117
118 void JSTestNamedGetterWithIdentifier::finishCreation(VM& vm)
119 {
120     Base::finishCreation(vm);
121     ASSERT(inherits(vm, info()));
122
123     static_assert(!std::is_base_of<ActiveDOMObject, TestNamedGetterWithIdentifier>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");
124
125 }
126
127 JSObject* JSTestNamedGetterWithIdentifier::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
128 {
129     return JSTestNamedGetterWithIdentifierPrototype::create(vm, &globalObject, JSTestNamedGetterWithIdentifierPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
130 }
131
132 JSObject* JSTestNamedGetterWithIdentifier::prototype(VM& vm, JSDOMGlobalObject& globalObject)
133 {
134     return getDOMPrototype<JSTestNamedGetterWithIdentifier>(vm, globalObject);
135 }
136
137 JSValue JSTestNamedGetterWithIdentifier::getConstructor(VM& vm, const JSGlobalObject* globalObject)
138 {
139     return getDOMConstructor<JSTestNamedGetterWithIdentifierConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
140 }
141
142 void JSTestNamedGetterWithIdentifier::destroy(JSC::JSCell* cell)
143 {
144     JSTestNamedGetterWithIdentifier* thisObject = static_cast<JSTestNamedGetterWithIdentifier*>(cell);
145     thisObject->JSTestNamedGetterWithIdentifier::~JSTestNamedGetterWithIdentifier();
146 }
147
148 bool JSTestNamedGetterWithIdentifier::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
149 {
150     auto* thisObject = jsCast<JSTestNamedGetterWithIdentifier*>(object);
151     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
152     using GetterIDLType = IDLDOMString;
153     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
154         auto result = thisObject.wrapped().getterName(propertyNameToAtomString(propertyName));
155         if (!GetterIDLType::isNullValue(result))
156             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
157         return WTF::nullopt;
158     };
159     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
160         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
161         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
162         return true;
163     }
164     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
165 }
166
167 bool JSTestNamedGetterWithIdentifier::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
168 {
169     VM& vm = state->vm();
170     auto* thisObject = jsCast<JSTestNamedGetterWithIdentifier*>(object);
171     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
172     auto propertyName = Identifier::from(vm, index);
173     using GetterIDLType = IDLDOMString;
174     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
175         auto result = thisObject.wrapped().getterName(propertyNameToAtomString(propertyName));
176         if (!GetterIDLType::isNullValue(result))
177             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
178         return WTF::nullopt;
179     };
180     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
181         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
182         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
183         return true;
184     }
185     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
186 }
187
188 void JSTestNamedGetterWithIdentifier::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
189 {
190     VM& vm = state->vm();
191     auto* thisObject = jsCast<JSTestNamedGetterWithIdentifier*>(object);
192     ASSERT_GC_OBJECT_INHERITS(object, info());
193     for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
194         propertyNames.add(Identifier::fromString(vm, propertyName));
195     JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
196 }
197
198 template<> inline JSTestNamedGetterWithIdentifier* IDLOperation<JSTestNamedGetterWithIdentifier>::cast(ExecState& state)
199 {
200     return jsDynamicCast<JSTestNamedGetterWithIdentifier*>(state.vm(), state.thisValue());
201 }
202
203 EncodedJSValue jsTestNamedGetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
204 {
205     VM& vm = state->vm();
206     auto throwScope = DECLARE_THROW_SCOPE(vm);
207     auto* prototype = jsDynamicCast<JSTestNamedGetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
208     if (UNLIKELY(!prototype))
209         return throwVMTypeError(state, throwScope);
210     return JSValue::encode(JSTestNamedGetterWithIdentifier::getConstructor(state->vm(), prototype->globalObject()));
211 }
212
213 bool setJSTestNamedGetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
214 {
215     VM& vm = state->vm();
216     auto throwScope = DECLARE_THROW_SCOPE(vm);
217     auto* prototype = jsDynamicCast<JSTestNamedGetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
218     if (UNLIKELY(!prototype)) {
219         throwVMTypeError(state, throwScope);
220         return false;
221     }
222     // Shadowing a built-in constructor
223     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
224 }
225
226 static inline JSC::EncodedJSValue jsTestNamedGetterWithIdentifierPrototypeFunctionGetterNameBody(JSC::ExecState* state, typename IDLOperation<JSTestNamedGetterWithIdentifier>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
227 {
228     UNUSED_PARAM(state);
229     UNUSED_PARAM(throwScope);
230     auto& impl = castedThis->wrapped();
231     if (UNLIKELY(state->argumentCount() < 1))
232         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
233     auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
234     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
235     return JSValue::encode(toJS<IDLDOMString>(*state, impl.getterName(WTFMove(name))));
236 }
237
238 EncodedJSValue JSC_HOST_CALL jsTestNamedGetterWithIdentifierPrototypeFunctionGetterName(JSGlobalObject* globalObject, CallFrame* state)
239 {
240     UNUSED_PARAM(globalObject);
241     return IDLOperation<JSTestNamedGetterWithIdentifier>::call<jsTestNamedGetterWithIdentifierPrototypeFunctionGetterNameBody>(*state, "getterName");
242 }
243
244 void JSTestNamedGetterWithIdentifier::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
245 {
246     auto* thisObject = jsCast<JSTestNamedGetterWithIdentifier*>(cell);
247     analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped());
248     if (thisObject->scriptExecutionContext())
249         analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
250     Base::analyzeHeap(cell, analyzer);
251 }
252
253 bool JSTestNamedGetterWithIdentifierOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
254 {
255     UNUSED_PARAM(handle);
256     UNUSED_PARAM(visitor);
257     UNUSED_PARAM(reason);
258     return false;
259 }
260
261 void JSTestNamedGetterWithIdentifierOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
262 {
263     auto* jsTestNamedGetterWithIdentifier = static_cast<JSTestNamedGetterWithIdentifier*>(handle.slot()->asCell());
264     auto& world = *static_cast<DOMWrapperWorld*>(context);
265     uncacheWrapper(world, &jsTestNamedGetterWithIdentifier->wrapped(), jsTestNamedGetterWithIdentifier);
266 }
267
268 #if ENABLE(BINDING_INTEGRITY)
269 #if PLATFORM(WIN)
270 #pragma warning(disable: 4483)
271 extern "C" { extern void (*const __identifier("??_7TestNamedGetterWithIdentifier@WebCore@@6B@")[])(); }
272 #else
273 extern "C" { extern void* _ZTVN7WebCore29TestNamedGetterWithIdentifierE[]; }
274 #endif
275 #endif
276
277 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedGetterWithIdentifier>&& impl)
278 {
279
280 #if ENABLE(BINDING_INTEGRITY)
281     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
282 #if PLATFORM(WIN)
283     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedGetterWithIdentifier@WebCore@@6B@"));
284 #else
285     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore29TestNamedGetterWithIdentifierE[2]);
286 #endif
287
288     // If this fails TestNamedGetterWithIdentifier does not have a vtable, so you need to add the
289     // ImplementationLacksVTable attribute to the interface definition
290     static_assert(std::is_polymorphic<TestNamedGetterWithIdentifier>::value, "TestNamedGetterWithIdentifier is not polymorphic");
291
292     // If you hit this assertion you either have a use after free bug, or
293     // TestNamedGetterWithIdentifier has subclasses. If TestNamedGetterWithIdentifier has subclasses that get passed
294     // to toJS() we currently require TestNamedGetterWithIdentifier you to opt out of binding hardening
295     // by adding the SkipVTableValidation attribute to the interface IDL definition
296     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
297 #endif
298     return createWrapper<TestNamedGetterWithIdentifier>(globalObject, WTFMove(impl));
299 }
300
301 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedGetterWithIdentifier& impl)
302 {
303     return wrap(state, globalObject, impl);
304 }
305
306 TestNamedGetterWithIdentifier* JSTestNamedGetterWithIdentifier::toWrapped(JSC::VM& vm, JSC::JSValue value)
307 {
308     if (auto* wrapper = jsDynamicCast<JSTestNamedGetterWithIdentifier*>(vm, value))
309         return &wrapper->wrapped();
310     return nullptr;
311 }
312
313 }