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