Rebaselining bindings tests
[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 "ExceptionCode.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructor.h"
27 #include "JSNode.h"
28 #include <runtime/Error.h>
29 #include <runtime/FunctionPrototype.h>
30 #include <wtf/GetPtr.h>
31
32 using namespace JSC;
33
34 namespace WebCore {
35
36 // Functions
37
38 JSC::EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionExcitingFunction(JSC::ExecState*);
39 JSC::EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(JSC::ExecState*);
40
41 // Attributes
42
43 JSC::EncodedJSValue jsTestActiveDOMObjectExcitingAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
44 JSC::EncodedJSValue jsTestActiveDOMObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
45 void setJSTestActiveDOMObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
46
47 class JSTestActiveDOMObjectPrototype : public JSC::JSNonFinalObject {
48 public:
49     typedef JSC::JSNonFinalObject Base;
50     static JSTestActiveDOMObjectPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
51     {
52         JSTestActiveDOMObjectPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestActiveDOMObjectPrototype>(vm.heap)) JSTestActiveDOMObjectPrototype(vm, globalObject, structure);
53         ptr->finishCreation(vm);
54         return ptr;
55     }
56
57     DECLARE_INFO;
58     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
59     {
60         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
61     }
62
63 private:
64     JSTestActiveDOMObjectPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
65         : JSC::JSNonFinalObject(vm, structure)
66     {
67     }
68
69     void finishCreation(JSC::VM&);
70 };
71
72 typedef JSDOMConstructorNotConstructable<JSTestActiveDOMObject> JSTestActiveDOMObjectConstructor;
73
74 /* Hash table */
75
76 static const struct CompactHashIndex JSTestActiveDOMObjectTableIndex[4] = {
77     { 1, -1 },
78     { 0, -1 },
79     { -1, -1 },
80     { -1, -1 },
81 };
82
83
84 static const HashTableValue JSTestActiveDOMObjectTableValues[] =
85 {
86     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestActiveDOMObjectConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestActiveDOMObjectConstructor) } },
87     { "excitingAttr", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestActiveDOMObjectExcitingAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
88 };
89
90 static const HashTable JSTestActiveDOMObjectTable = { 2, 3, true, JSTestActiveDOMObjectTableValues, JSTestActiveDOMObjectTableIndex };
91 template<> JSValue JSTestActiveDOMObjectConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
92 {
93     UNUSED_PARAM(vm);
94     return globalObject.functionPrototype();
95 }
96
97 template<> void JSTestActiveDOMObjectConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
98 {
99     putDirect(vm, vm.propertyNames->prototype, JSTestActiveDOMObject::getPrototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
100     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestActiveDOMObject"))), ReadOnly | DontEnum);
101     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
102 }
103
104 template<> const ClassInfo JSTestActiveDOMObjectConstructor::s_info = { "TestActiveDOMObject", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestActiveDOMObjectConstructor) };
105
106 /* Hash table for prototype */
107
108 static const HashTableValue JSTestActiveDOMObjectPrototypeTableValues[] =
109 {
110     { "excitingFunction", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestActiveDOMObjectPrototypeFunctionExcitingFunction), (intptr_t) (1) } },
111     { "postMessage", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestActiveDOMObjectPrototypeFunctionPostMessage), (intptr_t) (1) } },
112 };
113
114 const ClassInfo JSTestActiveDOMObjectPrototype::s_info = { "TestActiveDOMObjectPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestActiveDOMObjectPrototype) };
115
116 void JSTestActiveDOMObjectPrototype::finishCreation(VM& vm)
117 {
118     Base::finishCreation(vm);
119     reifyStaticProperties(vm, JSTestActiveDOMObjectPrototypeTableValues, *this);
120 }
121
122 const ClassInfo JSTestActiveDOMObject::s_info = { "TestActiveDOMObject", &Base::s_info, &JSTestActiveDOMObjectTable, CREATE_METHOD_TABLE(JSTestActiveDOMObject) };
123
124 JSTestActiveDOMObject::JSTestActiveDOMObject(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestActiveDOMObject>&& impl)
125     : JSDOMWrapper<TestActiveDOMObject>(structure, globalObject, WTFMove(impl))
126 {
127 }
128
129 JSObject* JSTestActiveDOMObject::createPrototype(VM& vm, JSGlobalObject* globalObject)
130 {
131     return JSTestActiveDOMObjectPrototype::create(vm, globalObject, JSTestActiveDOMObjectPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
132 }
133
134 JSObject* JSTestActiveDOMObject::getPrototype(VM& vm, JSGlobalObject* globalObject)
135 {
136     return getDOMPrototype<JSTestActiveDOMObject>(vm, globalObject);
137 }
138
139 void JSTestActiveDOMObject::destroy(JSC::JSCell* cell)
140 {
141     JSTestActiveDOMObject* thisObject = static_cast<JSTestActiveDOMObject*>(cell);
142     thisObject->JSTestActiveDOMObject::~JSTestActiveDOMObject();
143 }
144
145 bool JSTestActiveDOMObject::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
146 {
147     auto* thisObject = jsCast<JSTestActiveDOMObject*>(object);
148     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
149     if (getStaticValueSlot<JSTestActiveDOMObject, Base>(state, JSTestActiveDOMObjectTable, thisObject, propertyName, slot))
150         return true;
151     return false;
152 }
153
154 EncodedJSValue jsTestActiveDOMObjectExcitingAttr(ExecState* state, EncodedJSValue thisValue, PropertyName)
155 {
156     UNUSED_PARAM(state);
157     UNUSED_PARAM(thisValue);
158     JSValue decodedThisValue = JSValue::decode(thisValue);
159     auto* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(decodedThisValue);
160     if (UNLIKELY(!castedThis)) {
161         return throwGetterTypeError(*state, "TestActiveDOMObject", "excitingAttr");
162     }
163     if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, castedThis->wrapped()))
164         return JSValue::encode(jsUndefined());
165     auto& impl = castedThis->wrapped();
166     JSValue result = jsNumber(impl.excitingAttr());
167     return JSValue::encode(result);
168 }
169
170
171 EncodedJSValue jsTestActiveDOMObjectConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
172 {
173     JSTestActiveDOMObject* domObject = jsDynamicCast<JSTestActiveDOMObject*>(JSValue::decode(thisValue));
174     if (!domObject)
175         return throwVMTypeError(state);
176     if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, domObject->wrapped()))
177         return JSValue::encode(jsUndefined());
178     return JSValue::encode(JSTestActiveDOMObject::getConstructor(state->vm(), domObject->globalObject()));
179 }
180
181 void setJSTestActiveDOMObjectConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
182 {
183     JSValue value = JSValue::decode(encodedValue);
184     JSTestActiveDOMObject* domObject = jsDynamicCast<JSTestActiveDOMObject*>(JSValue::decode(thisValue));
185     if (UNLIKELY(!domObject)) {
186         throwVMTypeError(state);
187         return;
188     }
189     if (!shouldAllowAccessToFrame(state, domObject->wrapped().frame()))
190         return;
191     // Shadowing a built-in constructor
192     domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
193 }
194
195 JSValue JSTestActiveDOMObject::getConstructor(VM& vm, const JSGlobalObject* globalObject)
196 {
197     return getDOMConstructor<JSTestActiveDOMObjectConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
198 }
199
200 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionExcitingFunction(ExecState* state)
201 {
202     JSValue thisValue = state->thisValue();
203     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
204     if (UNLIKELY(!castedThis))
205         return throwThisTypeError(*state, "TestActiveDOMObject", "excitingFunction");
206     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
207     if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, castedThis->wrapped()))
208         return JSValue::encode(jsUndefined());
209     auto& impl = castedThis->wrapped();
210     if (UNLIKELY(state->argumentCount() < 1))
211         return throwVMError(state, createNotEnoughArgumentsError(state));
212     Node* nextChild = JSNode::toWrapped(state->argument(0));
213     if (UNLIKELY(state->hadException()))
214         return JSValue::encode(jsUndefined());
215     impl.excitingFunction(nextChild);
216     return JSValue::encode(jsUndefined());
217 }
218
219 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(ExecState* state)
220 {
221     JSValue thisValue = state->thisValue();
222     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
223     if (UNLIKELY(!castedThis))
224         return throwThisTypeError(*state, "TestActiveDOMObject", "postMessage");
225     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
226     auto& impl = castedThis->wrapped();
227     if (UNLIKELY(state->argumentCount() < 1))
228         return throwVMError(state, createNotEnoughArgumentsError(state));
229     String message = state->argument(0).toString(state)->value(state);
230     if (UNLIKELY(state->hadException()))
231         return JSValue::encode(jsUndefined());
232     impl.postMessage(message);
233     return JSValue::encode(jsUndefined());
234 }
235
236 bool JSTestActiveDOMObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
237 {
238     UNUSED_PARAM(handle);
239     UNUSED_PARAM(visitor);
240     return false;
241 }
242
243 void JSTestActiveDOMObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
244 {
245     auto* jsTestActiveDOMObject = jsCast<JSTestActiveDOMObject*>(handle.slot()->asCell());
246     auto& world = *static_cast<DOMWrapperWorld*>(context);
247     uncacheWrapper(world, &jsTestActiveDOMObject->wrapped(), jsTestActiveDOMObject);
248 }
249
250 #if ENABLE(BINDING_INTEGRITY)
251 #if PLATFORM(WIN)
252 #pragma warning(disable: 4483)
253 extern "C" { extern void (*const __identifier("??_7TestActiveDOMObject@WebCore@@6B@")[])(); }
254 #else
255 extern "C" { extern void* _ZTVN7WebCore19TestActiveDOMObjectE[]; }
256 #endif
257 #endif
258
259 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestActiveDOMObject* impl)
260 {
261     if (!impl)
262         return jsNull();
263     return createNewWrapper<JSTestActiveDOMObject>(globalObject, impl);
264 }
265
266 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestActiveDOMObject* impl)
267 {
268     if (!impl)
269         return jsNull();
270     if (JSValue result = getExistingWrapper<JSTestActiveDOMObject>(globalObject, impl))
271         return result;
272
273 #if ENABLE(BINDING_INTEGRITY)
274     void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
275 #if PLATFORM(WIN)
276     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestActiveDOMObject@WebCore@@6B@"));
277 #else
278     void* expectedVTablePointer = &_ZTVN7WebCore19TestActiveDOMObjectE[2];
279 #if COMPILER(CLANG)
280     // If this fails TestActiveDOMObject does not have a vtable, so you need to add the
281     // ImplementationLacksVTable attribute to the interface definition
282     COMPILE_ASSERT(__is_polymorphic(TestActiveDOMObject), TestActiveDOMObject_is_not_polymorphic);
283 #endif
284 #endif
285     // If you hit this assertion you either have a use after free bug, or
286     // TestActiveDOMObject has subclasses. If TestActiveDOMObject has subclasses that get passed
287     // to toJS() we currently require TestActiveDOMObject you to opt out of binding hardening
288     // by adding the SkipVTableValidation attribute to the interface IDL definition
289     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
290 #endif
291     return createNewWrapper<JSTestActiveDOMObject>(globalObject, impl);
292 }
293
294 TestActiveDOMObject* JSTestActiveDOMObject::toWrapped(JSC::JSValue value)
295 {
296     if (auto* wrapper = jsDynamicCast<JSTestActiveDOMObject*>(value))
297         return &wrapper->wrapped();
298     return nullptr;
299 }
300
301 }