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 "JSStyleSheetList.h" |
23 | |
24 | #include "Element.h" |
25 | #include "JSCSSStyleSheet.h" |
26 | #include "JSDOMAbstractOperations.h" |
27 | #include "JSDOMAttribute.h" |
28 | #include "JSDOMBinding.h" |
29 | #include "JSDOMConstructorNotConstructable.h" |
30 | #include "JSDOMConvertInterface.h" |
31 | #include "JSDOMConvertNullable.h" |
32 | #include "JSDOMConvertNumbers.h" |
33 | #include "JSDOMExceptionHandling.h" |
34 | #include "JSDOMGlobalObject.h" |
35 | #include "JSDOMOperation.h" |
36 | #include "JSDOMWrapperCache.h" |
37 | #include "JSNodeCustom.h" |
38 | #include "JSStyleSheet.h" |
39 | #include "ScriptExecutionContext.h" |
40 | #include <JavaScriptCore/ArrayPrototype.h> |
41 | #include <JavaScriptCore/BuiltinNames.h> |
42 | #include <JavaScriptCore/FunctionPrototype.h> |
43 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
44 | #include <JavaScriptCore/JSCInlines.h> |
45 | #include <JavaScriptCore/PropertyNameArray.h> |
46 | #include <wtf/GetPtr.h> |
47 | #include <wtf/PointerPreparations.h> |
48 | #include <wtf/URL.h> |
49 | |
50 | |
51 | namespace WebCore { |
52 | using namespace JSC; |
53 | |
54 | // Functions |
55 | |
56 | JSC::EncodedJSValue JSC_HOST_CALL jsStyleSheetListPrototypeFunctionItem(JSC::ExecState*); |
57 | |
58 | // Attributes |
59 | |
60 | JSC::EncodedJSValue jsStyleSheetListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
61 | bool setJSStyleSheetListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
62 | JSC::EncodedJSValue jsStyleSheetListLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
63 | |
64 | class JSStyleSheetListPrototype : public JSC::JSNonFinalObject { |
65 | public: |
66 | using Base = JSC::JSNonFinalObject; |
67 | static JSStyleSheetListPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
68 | { |
69 | JSStyleSheetListPrototype* ptr = new (NotNull, JSC::allocateCell<JSStyleSheetListPrototype>(vm.heap)) JSStyleSheetListPrototype(vm, globalObject, structure); |
70 | ptr->finishCreation(vm); |
71 | return ptr; |
72 | } |
73 | |
74 | DECLARE_INFO; |
75 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
76 | { |
77 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
78 | } |
79 | |
80 | private: |
81 | JSStyleSheetListPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
82 | : JSC::JSNonFinalObject(vm, structure) |
83 | { |
84 | } |
85 | |
86 | void finishCreation(JSC::VM&); |
87 | }; |
88 | |
89 | using JSStyleSheetListConstructor = JSDOMConstructorNotConstructable<JSStyleSheetList>; |
90 | |
91 | template<> JSValue JSStyleSheetListConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
92 | { |
93 | UNUSED_PARAM(vm); |
94 | return globalObject.functionPrototype(); |
95 | } |
96 | |
97 | template<> void JSStyleSheetListConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
98 | { |
99 | putDirect(vm, vm.propertyNames->prototype, JSStyleSheetList::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
100 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("StyleSheetList"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
101 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
102 | } |
103 | |
104 | template<> const ClassInfo JSStyleSheetListConstructor::s_info = { "StyleSheetList" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStyleSheetListConstructor) }; |
105 | |
106 | /* Hash table for prototype */ |
107 | |
108 | static const HashTableValue JSStyleSheetListPrototypeTableValues[] = |
109 | { |
110 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetListConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSStyleSheetListConstructor) } }, |
111 | { "length" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetListLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
112 | { "item" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsStyleSheetListPrototypeFunctionItem), (intptr_t) (1) } }, |
113 | }; |
114 | |
115 | const ClassInfo JSStyleSheetListPrototype::s_info = { "StyleSheetListPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStyleSheetListPrototype) }; |
116 | |
117 | void JSStyleSheetListPrototype::finishCreation(VM& vm) |
118 | { |
119 | Base::finishCreation(vm); |
120 | reifyStaticProperties(vm, JSStyleSheetList::info(), JSStyleSheetListPrototypeTableValues, *this); |
121 | putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum)); |
122 | } |
123 | |
124 | const ClassInfo JSStyleSheetList::s_info = { "StyleSheetList" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStyleSheetList) }; |
125 | |
126 | JSStyleSheetList::JSStyleSheetList(Structure* structure, JSDOMGlobalObject& globalObject, Ref<StyleSheetList>&& impl) |
127 | : JSDOMWrapper<StyleSheetList>(structure, globalObject, WTFMove(impl)) |
128 | { |
129 | } |
130 | |
131 | void JSStyleSheetList::finishCreation(VM& vm) |
132 | { |
133 | Base::finishCreation(vm); |
134 | ASSERT(inherits(vm, info())); |
135 | |
136 | } |
137 | |
138 | JSObject* JSStyleSheetList::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
139 | { |
140 | return JSStyleSheetListPrototype::create(vm, &globalObject, JSStyleSheetListPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
141 | } |
142 | |
143 | JSObject* JSStyleSheetList::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
144 | { |
145 | return getDOMPrototype<JSStyleSheetList>(vm, globalObject); |
146 | } |
147 | |
148 | JSValue JSStyleSheetList::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
149 | { |
150 | return getDOMConstructor<JSStyleSheetListConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
151 | } |
152 | |
153 | void JSStyleSheetList::destroy(JSC::JSCell* cell) |
154 | { |
155 | JSStyleSheetList* thisObject = static_cast<JSStyleSheetList*>(cell); |
156 | thisObject->JSStyleSheetList::~JSStyleSheetList(); |
157 | } |
158 | |
159 | bool JSStyleSheetList::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot) |
160 | { |
161 | auto* thisObject = jsCast<JSStyleSheetList*>(object); |
162 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
163 | if (auto index = parseIndex(propertyName)) { |
164 | if (index.value() < thisObject->wrapped().length()) { |
165 | auto value = toJS<IDLNullable<IDLInterface<StyleSheet>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index.value())); |
166 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
167 | return true; |
168 | } |
169 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
170 | } |
171 | using GetterIDLType = IDLInterface<CSSStyleSheet>; |
172 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
173 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName)); |
174 | if (!GetterIDLType::isNullValue(result)) |
175 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
176 | return WTF::nullopt; |
177 | }; |
178 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
179 | auto value = toJS<IDLInterface<CSSStyleSheet>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
180 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
181 | return true; |
182 | } |
183 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
184 | } |
185 | |
186 | bool JSStyleSheetList::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot) |
187 | { |
188 | auto* thisObject = jsCast<JSStyleSheetList*>(object); |
189 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
190 | if (LIKELY(index <= MAX_ARRAY_INDEX)) { |
191 | if (index < thisObject->wrapped().length()) { |
192 | auto value = toJS<IDLNullable<IDLInterface<StyleSheet>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index)); |
193 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
194 | return true; |
195 | } |
196 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
197 | } |
198 | auto propertyName = Identifier::from(state, index); |
199 | using GetterIDLType = IDLInterface<CSSStyleSheet>; |
200 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
201 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName)); |
202 | if (!GetterIDLType::isNullValue(result)) |
203 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
204 | return WTF::nullopt; |
205 | }; |
206 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
207 | auto value = toJS<IDLInterface<CSSStyleSheet>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
208 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
209 | return true; |
210 | } |
211 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
212 | } |
213 | |
214 | void JSStyleSheetList::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode) |
215 | { |
216 | auto* thisObject = jsCast<JSStyleSheetList*>(object); |
217 | ASSERT_GC_OBJECT_INHERITS(object, info()); |
218 | for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i) |
219 | propertyNames.add(Identifier::from(state, i)); |
220 | for (auto& propertyName : thisObject->wrapped().supportedPropertyNames()) |
221 | propertyNames.add(Identifier::fromString(state, propertyName)); |
222 | JSObject::getOwnPropertyNames(object, state, propertyNames, mode); |
223 | } |
224 | |
225 | template<> inline JSStyleSheetList* IDLAttribute<JSStyleSheetList>::cast(ExecState& state, EncodedJSValue thisValue) |
226 | { |
227 | return jsDynamicCast<JSStyleSheetList*>(state.vm(), JSValue::decode(thisValue)); |
228 | } |
229 | |
230 | template<> inline JSStyleSheetList* IDLOperation<JSStyleSheetList>::cast(ExecState& state) |
231 | { |
232 | return jsDynamicCast<JSStyleSheetList*>(state.vm(), state.thisValue()); |
233 | } |
234 | |
235 | EncodedJSValue jsStyleSheetListConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
236 | { |
237 | VM& vm = state->vm(); |
238 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
239 | auto* prototype = jsDynamicCast<JSStyleSheetListPrototype*>(vm, JSValue::decode(thisValue)); |
240 | if (UNLIKELY(!prototype)) |
241 | return throwVMTypeError(state, throwScope); |
242 | return JSValue::encode(JSStyleSheetList::getConstructor(state->vm(), prototype->globalObject())); |
243 | } |
244 | |
245 | bool setJSStyleSheetListConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
246 | { |
247 | VM& vm = state->vm(); |
248 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
249 | auto* prototype = jsDynamicCast<JSStyleSheetListPrototype*>(vm, JSValue::decode(thisValue)); |
250 | if (UNLIKELY(!prototype)) { |
251 | throwVMTypeError(state, throwScope); |
252 | return false; |
253 | } |
254 | // Shadowing a built-in constructor |
255 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
256 | } |
257 | |
258 | static inline JSValue jsStyleSheetListLengthGetter(ExecState& state, JSStyleSheetList& thisObject, ThrowScope& throwScope) |
259 | { |
260 | UNUSED_PARAM(throwScope); |
261 | UNUSED_PARAM(state); |
262 | auto& impl = thisObject.wrapped(); |
263 | JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length()); |
264 | return result; |
265 | } |
266 | |
267 | EncodedJSValue jsStyleSheetListLength(ExecState* state, EncodedJSValue thisValue, PropertyName) |
268 | { |
269 | return IDLAttribute<JSStyleSheetList>::get<jsStyleSheetListLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length" ); |
270 | } |
271 | |
272 | static inline JSC::EncodedJSValue jsStyleSheetListPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSStyleSheetList>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
273 | { |
274 | UNUSED_PARAM(state); |
275 | UNUSED_PARAM(throwScope); |
276 | auto& impl = castedThis->wrapped(); |
277 | if (UNLIKELY(state->argumentCount() < 1)) |
278 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
279 | auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
280 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
281 | return JSValue::encode(toJS<IDLNullable<IDLInterface<StyleSheet>>>(*state, *castedThis->globalObject(), impl.item(WTFMove(index)))); |
282 | } |
283 | |
284 | EncodedJSValue JSC_HOST_CALL jsStyleSheetListPrototypeFunctionItem(ExecState* state) |
285 | { |
286 | return IDLOperation<JSStyleSheetList>::call<jsStyleSheetListPrototypeFunctionItemBody>(*state, "item" ); |
287 | } |
288 | |
289 | void JSStyleSheetList::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
290 | { |
291 | auto* thisObject = jsCast<JSStyleSheetList*>(cell); |
292 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
293 | if (thisObject->scriptExecutionContext()) |
294 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
295 | Base::heapSnapshot(cell, builder); |
296 | } |
297 | |
298 | bool JSStyleSheetListOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
299 | { |
300 | auto* jsStyleSheetList = jsCast<JSStyleSheetList*>(handle.slot()->asCell()); |
301 | void* root = WebCore::root(jsStyleSheetList->wrapped().ownerNode()); |
302 | if (UNLIKELY(reason)) |
303 | *reason = "Reachable from StyleSheetList ownerNode" ; |
304 | return visitor.containsOpaqueRoot(root); |
305 | } |
306 | |
307 | void JSStyleSheetListOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
308 | { |
309 | auto* jsStyleSheetList = static_cast<JSStyleSheetList*>(handle.slot()->asCell()); |
310 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
311 | uncacheWrapper(world, &jsStyleSheetList->wrapped(), jsStyleSheetList); |
312 | } |
313 | |
314 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<StyleSheetList>&& impl) |
315 | { |
316 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
317 | // attribute. You should remove that attribute. If the class has subclasses |
318 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
319 | // attribute to StyleSheetList. |
320 | static_assert(!std::is_polymorphic<StyleSheetList>::value, "StyleSheetList is polymorphic but the IDL claims it is not" ); |
321 | return createWrapper<StyleSheetList>(globalObject, WTFMove(impl)); |
322 | } |
323 | |
324 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, StyleSheetList& impl) |
325 | { |
326 | return wrap(state, globalObject, impl); |
327 | } |
328 | |
329 | StyleSheetList* JSStyleSheetList::toWrapped(JSC::VM& vm, JSC::JSValue value) |
330 | { |
331 | if (auto* wrapper = jsDynamicCast<JSStyleSheetList*>(vm, value)) |
332 | return &wrapper->wrapped(); |
333 | return nullptr; |
334 | } |
335 | |
336 | } |
337 | |