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 "JSCSSRuleList.h"
23
24#include "JSCSSRule.h"
25#include "JSDOMAttribute.h"
26#include "JSDOMBinding.h"
27#include "JSDOMConstructorNotConstructable.h"
28#include "JSDOMConvertInterface.h"
29#include "JSDOMConvertNumbers.h"
30#include "JSDOMExceptionHandling.h"
31#include "JSDOMGlobalObject.h"
32#include "JSDOMOperation.h"
33#include "JSDOMWrapperCache.h"
34#include "ScriptExecutionContext.h"
35#include <JavaScriptCore/ArrayPrototype.h>
36#include <JavaScriptCore/BuiltinNames.h>
37#include <JavaScriptCore/FunctionPrototype.h>
38#include <JavaScriptCore/HeapSnapshotBuilder.h>
39#include <JavaScriptCore/JSCInlines.h>
40#include <JavaScriptCore/PropertyNameArray.h>
41#include <wtf/GetPtr.h>
42#include <wtf/PointerPreparations.h>
43#include <wtf/URL.h>
44
45
46namespace WebCore {
47using namespace JSC;
48
49// Functions
50
51JSC::EncodedJSValue JSC_HOST_CALL jsCSSRuleListPrototypeFunctionItem(JSC::ExecState*);
52
53// Attributes
54
55JSC::EncodedJSValue jsCSSRuleListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
56bool setJSCSSRuleListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
57JSC::EncodedJSValue jsCSSRuleListLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58
59class JSCSSRuleListPrototype : public JSC::JSNonFinalObject {
60public:
61 using Base = JSC::JSNonFinalObject;
62 static JSCSSRuleListPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
63 {
64 JSCSSRuleListPrototype* ptr = new (NotNull, JSC::allocateCell<JSCSSRuleListPrototype>(vm.heap)) JSCSSRuleListPrototype(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
75private:
76 JSCSSRuleListPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
77 : JSC::JSNonFinalObject(vm, structure)
78 {
79 }
80
81 void finishCreation(JSC::VM&);
82};
83
84using JSCSSRuleListConstructor = JSDOMConstructorNotConstructable<JSCSSRuleList>;
85
86template<> JSValue JSCSSRuleListConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
87{
88 UNUSED_PARAM(vm);
89 return globalObject.functionPrototype();
90}
91
92template<> void JSCSSRuleListConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
93{
94 putDirect(vm, vm.propertyNames->prototype, JSCSSRuleList::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
95 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("CSSRuleList"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
96 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
97}
98
99template<> const ClassInfo JSCSSRuleListConstructor::s_info = { "CSSRuleList", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSRuleListConstructor) };
100
101/* Hash table for prototype */
102
103static const HashTableValue JSCSSRuleListPrototypeTableValues[] =
104{
105 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSRuleListConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCSSRuleListConstructor) } },
106 { "length", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSRuleListLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
107 { "item", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSRuleListPrototypeFunctionItem), (intptr_t) (1) } },
108};
109
110const ClassInfo JSCSSRuleListPrototype::s_info = { "CSSRuleListPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSRuleListPrototype) };
111
112void JSCSSRuleListPrototype::finishCreation(VM& vm)
113{
114 Base::finishCreation(vm);
115 reifyStaticProperties(vm, JSCSSRuleList::info(), JSCSSRuleListPrototypeTableValues, *this);
116 putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
117}
118
119const ClassInfo JSCSSRuleList::s_info = { "CSSRuleList", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSRuleList) };
120
121JSCSSRuleList::JSCSSRuleList(Structure* structure, JSDOMGlobalObject& globalObject, Ref<CSSRuleList>&& impl)
122 : JSDOMWrapper<CSSRuleList>(structure, globalObject, WTFMove(impl))
123{
124}
125
126void JSCSSRuleList::finishCreation(VM& vm)
127{
128 Base::finishCreation(vm);
129 ASSERT(inherits(vm, info()));
130
131}
132
133JSObject* JSCSSRuleList::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
134{
135 return JSCSSRuleListPrototype::create(vm, &globalObject, JSCSSRuleListPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
136}
137
138JSObject* JSCSSRuleList::prototype(VM& vm, JSDOMGlobalObject& globalObject)
139{
140 return getDOMPrototype<JSCSSRuleList>(vm, globalObject);
141}
142
143JSValue JSCSSRuleList::getConstructor(VM& vm, const JSGlobalObject* globalObject)
144{
145 return getDOMConstructor<JSCSSRuleListConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
146}
147
148void JSCSSRuleList::destroy(JSC::JSCell* cell)
149{
150 JSCSSRuleList* thisObject = static_cast<JSCSSRuleList*>(cell);
151 thisObject->JSCSSRuleList::~JSCSSRuleList();
152}
153
154bool JSCSSRuleList::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
155{
156 auto* thisObject = jsCast<JSCSSRuleList*>(object);
157 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
158 if (auto index = parseIndex(propertyName)) {
159 if (index.value() < thisObject->wrapped().length()) {
160 auto value = toJS<IDLInterface<CSSRule>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index.value()));
161 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
162 return true;
163 }
164 }
165 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
166}
167
168bool JSCSSRuleList::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
169{
170 auto* thisObject = jsCast<JSCSSRuleList*>(object);
171 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
172 if (LIKELY(index <= MAX_ARRAY_INDEX)) {
173 if (index < thisObject->wrapped().length()) {
174 auto value = toJS<IDLInterface<CSSRule>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index));
175 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
176 return true;
177 }
178 }
179 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
180}
181
182void JSCSSRuleList::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
183{
184 auto* thisObject = jsCast<JSCSSRuleList*>(object);
185 ASSERT_GC_OBJECT_INHERITS(object, info());
186 for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i)
187 propertyNames.add(Identifier::from(state, i));
188 JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
189}
190
191template<> inline JSCSSRuleList* IDLAttribute<JSCSSRuleList>::cast(ExecState& state, EncodedJSValue thisValue)
192{
193 return jsDynamicCast<JSCSSRuleList*>(state.vm(), JSValue::decode(thisValue));
194}
195
196template<> inline JSCSSRuleList* IDLOperation<JSCSSRuleList>::cast(ExecState& state)
197{
198 return jsDynamicCast<JSCSSRuleList*>(state.vm(), state.thisValue());
199}
200
201EncodedJSValue jsCSSRuleListConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
202{
203 VM& vm = state->vm();
204 auto throwScope = DECLARE_THROW_SCOPE(vm);
205 auto* prototype = jsDynamicCast<JSCSSRuleListPrototype*>(vm, JSValue::decode(thisValue));
206 if (UNLIKELY(!prototype))
207 return throwVMTypeError(state, throwScope);
208 return JSValue::encode(JSCSSRuleList::getConstructor(state->vm(), prototype->globalObject()));
209}
210
211bool setJSCSSRuleListConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
212{
213 VM& vm = state->vm();
214 auto throwScope = DECLARE_THROW_SCOPE(vm);
215 auto* prototype = jsDynamicCast<JSCSSRuleListPrototype*>(vm, JSValue::decode(thisValue));
216 if (UNLIKELY(!prototype)) {
217 throwVMTypeError(state, throwScope);
218 return false;
219 }
220 // Shadowing a built-in constructor
221 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
222}
223
224static inline JSValue jsCSSRuleListLengthGetter(ExecState& state, JSCSSRuleList& thisObject, ThrowScope& throwScope)
225{
226 UNUSED_PARAM(throwScope);
227 UNUSED_PARAM(state);
228 auto& impl = thisObject.wrapped();
229 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length());
230 return result;
231}
232
233EncodedJSValue jsCSSRuleListLength(ExecState* state, EncodedJSValue thisValue, PropertyName)
234{
235 return IDLAttribute<JSCSSRuleList>::get<jsCSSRuleListLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length");
236}
237
238static inline JSC::EncodedJSValue jsCSSRuleListPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSCSSRuleList>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
239{
240 UNUSED_PARAM(state);
241 UNUSED_PARAM(throwScope);
242 auto& impl = castedThis->wrapped();
243 if (UNLIKELY(state->argumentCount() < 1))
244 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
245 auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
246 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
247 return JSValue::encode(toJS<IDLInterface<CSSRule>>(*state, *castedThis->globalObject(), impl.item(WTFMove(index))));
248}
249
250EncodedJSValue JSC_HOST_CALL jsCSSRuleListPrototypeFunctionItem(ExecState* state)
251{
252 return IDLOperation<JSCSSRuleList>::call<jsCSSRuleListPrototypeFunctionItemBody>(*state, "item");
253}
254
255void JSCSSRuleList::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
256{
257 auto* thisObject = jsCast<JSCSSRuleList*>(cell);
258 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
259 if (thisObject->scriptExecutionContext())
260 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
261 Base::heapSnapshot(cell, builder);
262}
263
264void JSCSSRuleListOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
265{
266 auto* jsCSSRuleList = static_cast<JSCSSRuleList*>(handle.slot()->asCell());
267 auto& world = *static_cast<DOMWrapperWorld*>(context);
268 uncacheWrapper(world, &jsCSSRuleList->wrapped(), jsCSSRuleList);
269}
270
271JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<CSSRuleList>&& impl)
272{
273 return createWrapper<CSSRuleList>(globalObject, WTFMove(impl));
274}
275
276JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, CSSRuleList& impl)
277{
278 return wrap(state, globalObject, impl);
279}
280
281CSSRuleList* JSCSSRuleList::toWrapped(JSC::VM& vm, JSC::JSValue value)
282{
283 if (auto* wrapper = jsDynamicCast<JSCSSRuleList*>(vm, value))
284 return &wrapper->wrapped();
285 return nullptr;
286}
287
288}
289