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