4e9a13c8a326daee7e2975cf44dd68a1d0b89d74
[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 "JSDOMPromise.h"
29 #include "ObjectConstructor.h"
30 #include "RuntimeEnabledFeatures.h"
31 #include "URL.h"
32 #include <runtime/Error.h>
33 #include <runtime/JSString.h>
34 #include <wtf/GetPtr.h>
35
36 using namespace JSC;
37
38 namespace WebCore {
39
40 // Functions
41
42 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(JSC::ExecState*);
43 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState*);
44 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState*);
45 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState*);
46 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState*);
47 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState*);
48 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionToJSON(JSC::ExecState*);
49
50 // Attributes
51
52 JSC::EncodedJSValue jsTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
53 bool setJSTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
54 JSC::EncodedJSValue jsTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
55 bool setJSTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
56
57 class JSTestNodePrototype : public JSC::JSNonFinalObject {
58 public:
59     using Base = JSC::JSNonFinalObject;
60     static JSTestNodePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
61     {
62         JSTestNodePrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNodePrototype>(vm.heap)) JSTestNodePrototype(vm, globalObject, structure);
63         ptr->finishCreation(vm);
64         return ptr;
65     }
66
67     DECLARE_INFO;
68     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
69     {
70         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
71     }
72
73 private:
74     JSTestNodePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
75         : JSC::JSNonFinalObject(vm, structure)
76     {
77     }
78
79     void finishCreation(JSC::VM&);
80 };
81
82 using JSTestNodeConstructor = JSDOMConstructor<JSTestNode>;
83
84 template<> EncodedJSValue JSC_HOST_CALL JSTestNodeConstructor::construct(ExecState* state)
85 {
86     VM& vm = state->vm();
87     auto throwScope = DECLARE_THROW_SCOPE(vm);
88     UNUSED_PARAM(throwScope);
89     auto* castedThis = jsCast<JSTestNodeConstructor*>(state->callee());
90     ASSERT(castedThis);
91     auto object = TestNode::create();
92     return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));
93 }
94
95 template<> JSValue JSTestNodeConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
96 {
97     return JSNode::getConstructor(vm, &globalObject);
98 }
99
100 template<> void JSTestNodeConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
101 {
102     putDirect(vm, vm.propertyNames->prototype, JSTestNode::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
103     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNode"))), ReadOnly | DontEnum);
104     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
105 }
106
107 template<> const ClassInfo JSTestNodeConstructor::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodeConstructor) };
108
109 /* Hash table for prototype */
110
111 static const HashTableValue JSTestNodePrototypeTableValues[] =
112 {
113     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeConstructor) } },
114     { "name", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeName) } },
115     { "testWorkerPromise", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionTestWorkerPromise), (intptr_t) (0) } },
116     { "entries", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionEntries), (intptr_t) (0) } },
117     { "keys", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionKeys), (intptr_t) (0) } },
118     { "values", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionValues), (intptr_t) (0) } },
119     { "forEach", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionForEach), (intptr_t) (1) } },
120     { "toJSON", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionToJSON), (intptr_t) (0) } },
121 };
122
123 const ClassInfo JSTestNodePrototype::s_info = { "TestNodePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodePrototype) };
124
125 void JSTestNodePrototype::finishCreation(VM& vm)
126 {
127     Base::finishCreation(vm);
128     reifyStaticProperties(vm, JSTestNodePrototypeTableValues, *this);
129     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
130         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("entries"), strlen("entries"));
131         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
132         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
133     }
134     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
135         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("keys"), strlen("keys"));
136         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
137         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
138     }
139     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
140         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("values"), strlen("values"));
141         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
142         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
143     }
144     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
145         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("forEach"), strlen("forEach"));
146         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
147         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
148     }
149     if (RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
150         putDirect(vm, vm.propertyNames->iteratorSymbol, JSFunction::create(vm, globalObject(), 0, ASCIILiteral("[Symbol.Iterator]"), jsTestNodePrototypeFunctionSymbolIterator), DontEnum);
151     }
152 }
153
154 const ClassInfo JSTestNode::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNode) };
155
156 JSTestNode::JSTestNode(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNode>&& impl)
157     : JSNode(structure, globalObject, WTFMove(impl))
158 {
159 }
160
161 JSObject* JSTestNode::createPrototype(VM& vm, JSGlobalObject* globalObject)
162 {
163     return JSTestNodePrototype::create(vm, globalObject, JSTestNodePrototype::createStructure(vm, globalObject, JSNode::prototype(vm, globalObject)));
164 }
165
166 JSObject* JSTestNode::prototype(VM& vm, JSGlobalObject* globalObject)
167 {
168     return getDOMPrototype<JSTestNode>(vm, globalObject);
169 }
170
171 EncodedJSValue jsTestNodeName(ExecState* state, EncodedJSValue thisValue, PropertyName)
172 {
173     VM& vm = state->vm();
174     auto throwScope = DECLARE_THROW_SCOPE(vm);
175     UNUSED_PARAM(throwScope);
176     UNUSED_PARAM(thisValue);
177     JSValue decodedThisValue = JSValue::decode(thisValue);
178     auto* castedThis = jsDynamicCast<JSTestNode*>(decodedThisValue);
179     if (UNLIKELY(!castedThis)) {
180         return throwGetterTypeError(*state, throwScope, "TestNode", "name");
181     }
182     auto& impl = castedThis->wrapped();
183     JSValue result = jsStringWithCache(state, impl.name());
184     return JSValue::encode(result);
185 }
186
187
188 EncodedJSValue jsTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
189 {
190     VM& vm = state->vm();
191     auto throwScope = DECLARE_THROW_SCOPE(vm);
192     JSTestNodePrototype* domObject = jsDynamicCast<JSTestNodePrototype*>(JSValue::decode(thisValue));
193     if (UNLIKELY(!domObject))
194         return throwVMTypeError(state, throwScope);
195     return JSValue::encode(JSTestNode::getConstructor(state->vm(), domObject->globalObject()));
196 }
197
198 bool setJSTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
199 {
200     VM& vm = state->vm();
201     auto throwScope = DECLARE_THROW_SCOPE(vm);
202     JSValue value = JSValue::decode(encodedValue);
203     JSTestNodePrototype* domObject = jsDynamicCast<JSTestNodePrototype*>(JSValue::decode(thisValue));
204     if (UNLIKELY(!domObject)) {
205         throwVMTypeError(state, throwScope);
206         return false;
207     }
208     // Shadowing a built-in constructor
209     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
210 }
211
212 bool setJSTestNodeName(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
213 {
214     VM& vm = state->vm();
215     auto throwScope = DECLARE_THROW_SCOPE(vm);
216     UNUSED_PARAM(throwScope);
217     JSValue value = JSValue::decode(encodedValue);
218     UNUSED_PARAM(thisValue);
219     JSTestNode* castedThis = jsDynamicCast<JSTestNode*>(JSValue::decode(thisValue));
220     if (UNLIKELY(!castedThis)) {
221         return throwSetterTypeError(*state, throwScope, "TestNode", "name");
222     }
223     auto& impl = castedThis->wrapped();
224     auto nativeValue = value.toWTFString(state);
225     RETURN_IF_EXCEPTION(throwScope, false);
226     impl.setName(WTFMove(nativeValue));
227     return true;
228 }
229
230
231 JSValue JSTestNode::getConstructor(VM& vm, const JSGlobalObject* globalObject)
232 {
233     return getDOMConstructor<JSTestNodeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
234 }
235
236 static EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState*, Ref<DeferredPromise>&&);
237
238 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(ExecState* state)
239 {
240     ASSERT(state);
241     return JSValue::encode(callPromiseFunction<jsTestNodePrototypeFunctionTestWorkerPromisePromise, PromiseExecutionScope::WindowOrWorker>(*state));
242 }
243
244 static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState* state, Ref<DeferredPromise>&& promise)
245 {
246     VM& vm = state->vm();
247     auto throwScope = DECLARE_THROW_SCOPE(vm);
248     UNUSED_PARAM(throwScope);
249     JSValue thisValue = state->thisValue();
250     auto castedThis = jsDynamicCast<JSTestNode*>(thisValue);
251     if (UNLIKELY(!castedThis))
252         return throwThisTypeError(*state, throwScope, "TestNode", "testWorkerPromise");
253     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestNode::info());
254     auto& impl = castedThis->wrapped();
255     impl.testWorkerPromise(WTFMove(promise));
256     return JSValue::encode(jsUndefined());
257 }
258
259 using TestNodeIterator = JSDOMIterator<JSTestNode>;
260 using TestNodeIteratorPrototype = JSDOMIteratorPrototype<JSTestNode>;
261
262 template<>
263 const JSC::ClassInfo TestNodeIterator::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIterator) };
264
265 template<>
266 const JSC::ClassInfo TestNodeIteratorPrototype::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIteratorPrototype) };
267
268 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState* state)
269 {
270     return iteratorCreate<JSTestNode>(*state, IterationKind::Value, "[Symbol.Iterator]");
271 }
272
273 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState* state)
274 {
275     return iteratorCreate<JSTestNode>(*state, IterationKind::KeyValue, "entries");
276 }
277
278 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState* state)
279 {
280     return iteratorCreate<JSTestNode>(*state, IterationKind::Key, "keys");
281 }
282
283 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState* state)
284 {
285     return iteratorCreate<JSTestNode>(*state, IterationKind::Value, "values");
286 }
287
288 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState* state)
289 {
290     return iteratorForEach<JSTestNode>(*state, "forEach");
291 }
292
293 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionToJSON(ExecState* state)
294 {
295     ASSERT(state);
296     auto thisValue = state->thisValue();
297     auto castedThis = jsDynamicCast<JSTestNode*>(thisValue);
298     VM& vm = state->vm();
299     auto throwScope = DECLARE_THROW_SCOPE(vm);
300     if (UNLIKELY(!castedThis)){
301         return throwThisTypeError(*state, throwScope, "TestNode", "toJSON");
302     }
303     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestNode::info());
304
305     auto* result = constructEmptyObject(state);
306     auto nameValue = jsTestNodeName(state, JSValue::encode(thisValue), Identifier());
307     ASSERT(!throwScope.exception());
308     result->putDirect(vm, Identifier::fromString(&vm, "name"), JSValue::decode(nameValue));
309     return JSValue::encode(result);
310 }
311
312 void JSTestNode::visitChildren(JSCell* cell, SlotVisitor& visitor)
313 {
314     auto* thisObject = jsCast<JSTestNode*>(cell);
315     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
316     Base::visitChildren(thisObject, visitor);
317     thisObject->wrapped().visitJSEventListeners(visitor);
318 }
319
320 #if ENABLE(BINDING_INTEGRITY)
321 #if PLATFORM(WIN)
322 #pragma warning(disable: 4483)
323 extern "C" { extern void (*const __identifier("??_7TestNode@WebCore@@6B@")[])(); }
324 #else
325 extern "C" { extern void* _ZTVN7WebCore8TestNodeE[]; }
326 #endif
327 #endif
328
329 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNode>&& impl)
330 {
331
332 #if ENABLE(BINDING_INTEGRITY)
333     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
334 #if PLATFORM(WIN)
335     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestNode@WebCore@@6B@"));
336 #else
337     void* expectedVTablePointer = &_ZTVN7WebCore8TestNodeE[2];
338 #if COMPILER(CLANG)
339     // If this fails TestNode does not have a vtable, so you need to add the
340     // ImplementationLacksVTable attribute to the interface definition
341     static_assert(__is_polymorphic(TestNode), "TestNode is not polymorphic");
342 #endif
343 #endif
344     // If you hit this assertion you either have a use after free bug, or
345     // TestNode has subclasses. If TestNode has subclasses that get passed
346     // to toJS() we currently require TestNode you to opt out of binding hardening
347     // by adding the SkipVTableValidation attribute to the interface IDL definition
348     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
349 #endif
350     return createWrapper<TestNode>(globalObject, WTFMove(impl));
351 }
352
353 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNode& impl)
354 {
355     return wrap(state, globalObject, impl);
356 }
357
358
359 }