Make custom constructors consistent with generated bindings code
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNode.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 "JSTestNode.h"
23
24 #include "ExceptionCode.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructor.h"
27 #include "JSDOMIterator.h"
28 #include "RuntimeEnabledFeatures.h"
29 #include "URL.h"
30 #include <runtime/Error.h>
31 #include <runtime/JSString.h>
32 #include <wtf/GetPtr.h>
33
34 using namespace JSC;
35
36 namespace WebCore {
37
38 // Functions
39
40 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState*);
41 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState*);
42 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState*);
43 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState*);
44 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState*);
45
46 // Attributes
47
48 JSC::EncodedJSValue jsTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
49 bool setJSTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
50 JSC::EncodedJSValue jsTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
51 bool setJSTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
52
53 class JSTestNodePrototype : public JSC::JSNonFinalObject {
54 public:
55     typedef JSC::JSNonFinalObject Base;
56     static JSTestNodePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
57     {
58         JSTestNodePrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNodePrototype>(vm.heap)) JSTestNodePrototype(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     JSTestNodePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
71         : JSC::JSNonFinalObject(vm, structure)
72     {
73     }
74
75     void finishCreation(JSC::VM&);
76 };
77
78 typedef JSDOMConstructor<JSTestNode> JSTestNodeConstructor;
79
80 template<> EncodedJSValue JSC_HOST_CALL JSTestNodeConstructor::construct(ExecState* state)
81 {
82     auto* castedThis = jsCast<JSTestNodeConstructor*>(state->callee());
83     ASSERT(castedThis);
84     auto object = TestNode::create();
85     return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));
86 }
87
88 template<> JSValue JSTestNodeConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
89 {
90     return JSNode::getConstructor(vm, &globalObject);
91 }
92
93 template<> void JSTestNodeConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
94 {
95     putDirect(vm, vm.propertyNames->prototype, JSTestNode::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
96     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNode"))), ReadOnly | DontEnum);
97     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
98 }
99
100 template<> const ClassInfo JSTestNodeConstructor::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodeConstructor) };
101
102 /* Hash table for prototype */
103
104 static const HashTableValue JSTestNodePrototypeTableValues[] =
105 {
106     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeConstructor) } },
107     { "name", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeName) } },
108     { "entries", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionEntries), (intptr_t) (0) } },
109     { "keys", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionKeys), (intptr_t) (0) } },
110     { "values", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionValues), (intptr_t) (0) } },
111     { "forEach", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionForEach), (intptr_t) (1) } },
112 };
113
114 const ClassInfo JSTestNodePrototype::s_info = { "TestNodePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodePrototype) };
115
116 void JSTestNodePrototype::finishCreation(VM& vm)
117 {
118     Base::finishCreation(vm);
119     reifyStaticProperties(vm, JSTestNodePrototypeTableValues, *this);
120     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
121         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("entries"), strlen("entries"));
122         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
123         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
124     }
125     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
126         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("keys"), strlen("keys"));
127         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
128         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
129     }
130     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
131         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("values"), strlen("values"));
132         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
133         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
134     }
135     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
136         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("forEach"), strlen("forEach"));
137         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
138         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
139     }
140     if (RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
141         putDirect(vm, vm.propertyNames->iteratorSymbol, JSFunction::create(vm, globalObject(), 0, ASCIILiteral("[Symbol.Iterator]"), jsTestNodePrototypeFunctionSymbolIterator), DontEnum);
142     }
143 }
144
145 const ClassInfo JSTestNode::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNode) };
146
147 JSTestNode::JSTestNode(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNode>&& impl)
148     : JSNode(structure, globalObject, WTFMove(impl))
149 {
150 }
151
152 JSObject* JSTestNode::createPrototype(VM& vm, JSGlobalObject* globalObject)
153 {
154     return JSTestNodePrototype::create(vm, globalObject, JSTestNodePrototype::createStructure(vm, globalObject, JSNode::prototype(vm, globalObject)));
155 }
156
157 JSObject* JSTestNode::prototype(VM& vm, JSGlobalObject* globalObject)
158 {
159     return getDOMPrototype<JSTestNode>(vm, globalObject);
160 }
161
162 EncodedJSValue jsTestNodeName(ExecState* state, EncodedJSValue thisValue, PropertyName)
163 {
164     UNUSED_PARAM(state);
165     UNUSED_PARAM(thisValue);
166     JSValue decodedThisValue = JSValue::decode(thisValue);
167     auto* castedThis = jsDynamicCast<JSTestNode*>(decodedThisValue);
168     if (UNLIKELY(!castedThis)) {
169         return throwGetterTypeError(*state, "TestNode", "name");
170     }
171     auto& impl = castedThis->wrapped();
172     JSValue result = jsStringWithCache(state, impl.name());
173     return JSValue::encode(result);
174 }
175
176
177 EncodedJSValue jsTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
178 {
179     JSTestNodePrototype* domObject = jsDynamicCast<JSTestNodePrototype*>(JSValue::decode(thisValue));
180     if (UNLIKELY(!domObject))
181         return throwVMTypeError(state);
182     return JSValue::encode(JSTestNode::getConstructor(state->vm(), domObject->globalObject()));
183 }
184
185 bool setJSTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
186 {
187     JSValue value = JSValue::decode(encodedValue);
188     JSTestNodePrototype* domObject = jsDynamicCast<JSTestNodePrototype*>(JSValue::decode(thisValue));
189     if (UNLIKELY(!domObject)) {
190         throwVMTypeError(state);
191         return false;
192     }
193     // Shadowing a built-in constructor
194     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
195 }
196
197 bool setJSTestNodeName(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
198 {
199     JSValue value = JSValue::decode(encodedValue);
200     UNUSED_PARAM(thisValue);
201     JSTestNode* castedThis = jsDynamicCast<JSTestNode*>(JSValue::decode(thisValue));
202     if (UNLIKELY(!castedThis)) {
203         return throwSetterTypeError(*state, "TestNode", "name");
204     }
205     auto& impl = castedThis->wrapped();
206     auto nativeValue = value.toWTFString(state);
207     if (UNLIKELY(state->hadException()))
208         return false;
209     impl.setName(WTFMove(nativeValue));
210     return true;
211 }
212
213
214 JSValue JSTestNode::getConstructor(VM& vm, const JSGlobalObject* globalObject)
215 {
216     return getDOMConstructor<JSTestNodeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
217 }
218
219 using TestNodeIterator = JSDOMIterator<JSTestNode>;
220 using TestNodeIteratorPrototype = JSDOMIteratorPrototype<JSTestNode>;
221
222 template<>
223 const JSC::ClassInfo TestNodeIterator::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIterator) };
224
225 template<>
226 const JSC::ClassInfo TestNodeIteratorPrototype::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIteratorPrototype) };
227
228 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState* state)
229 {
230     return iteratorCreate<JSTestNode>(*state, IterationKind::Value, "[Symbol.Iterator]");
231 }
232
233 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState* state)
234 {
235     return iteratorCreate<JSTestNode>(*state, IterationKind::KeyValue, "entries");
236 }
237
238 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState* state)
239 {
240     return iteratorCreate<JSTestNode>(*state, IterationKind::Key, "keys");
241 }
242
243 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState* state)
244 {
245     return iteratorCreate<JSTestNode>(*state, IterationKind::Value, "values");
246 }
247
248 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState* state)
249 {
250     return iteratorForEach<JSTestNode>(*state, "forEach");
251 }
252
253 void JSTestNode::visitChildren(JSCell* cell, SlotVisitor& visitor)
254 {
255     auto* thisObject = jsCast<JSTestNode*>(cell);
256     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
257     Base::visitChildren(thisObject, visitor);
258     thisObject->wrapped().visitJSEventListeners(visitor);
259 }
260
261 #if ENABLE(BINDING_INTEGRITY)
262 #if PLATFORM(WIN)
263 #pragma warning(disable: 4483)
264 extern "C" { extern void (*const __identifier("??_7TestNode@WebCore@@6B@")[])(); }
265 #else
266 extern "C" { extern void* _ZTVN7WebCore8TestNodeE[]; }
267 #endif
268 #endif
269
270 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNode>&& impl)
271 {
272
273 #if ENABLE(BINDING_INTEGRITY)
274     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
275 #if PLATFORM(WIN)
276     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestNode@WebCore@@6B@"));
277 #else
278     void* expectedVTablePointer = &_ZTVN7WebCore8TestNodeE[2];
279 #if COMPILER(CLANG)
280     // If this fails TestNode does not have a vtable, so you need to add the
281     // ImplementationLacksVTable attribute to the interface definition
282     static_assert(__is_polymorphic(TestNode), "TestNode is not polymorphic");
283 #endif
284 #endif
285     // If you hit this assertion you either have a use after free bug, or
286     // TestNode has subclasses. If TestNode has subclasses that get passed
287     // to toJS() we currently require TestNode 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 createWrapper<JSTestNode, TestNode>(globalObject, WTFMove(impl));
292 }
293
294 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNode& impl)
295 {
296     return wrap(state, globalObject, impl);
297 }
298
299
300 }