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 "JSStyleSheet.h" |
23 | |
24 | #include "JSDOMAttribute.h" |
25 | #include "JSDOMBinding.h" |
26 | #include "JSDOMConstructorNotConstructable.h" |
27 | #include "JSDOMConvertBoolean.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSDOMConvertNullable.h" |
30 | #include "JSDOMConvertStrings.h" |
31 | #include "JSDOMExceptionHandling.h" |
32 | #include "JSDOMGlobalObject.h" |
33 | #include "JSDOMWrapperCache.h" |
34 | #include "JSMediaList.h" |
35 | #include "JSNode.h" |
36 | #include "JSStyleSheet.h" |
37 | #include "ScriptExecutionContext.h" |
38 | #include <JavaScriptCore/FunctionPrototype.h> |
39 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
40 | #include <JavaScriptCore/JSCInlines.h> |
41 | #include <wtf/GetPtr.h> |
42 | #include <wtf/PointerPreparations.h> |
43 | #include <wtf/URL.h> |
44 | |
45 | |
46 | namespace WebCore { |
47 | using namespace JSC; |
48 | |
49 | // Attributes |
50 | |
51 | JSC::EncodedJSValue jsStyleSheetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
52 | bool setJSStyleSheetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
53 | JSC::EncodedJSValue jsStyleSheetType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
54 | JSC::EncodedJSValue jsStyleSheetDisabled(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
55 | bool setJSStyleSheetDisabled(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
56 | JSC::EncodedJSValue jsStyleSheetOwnerNode(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
57 | JSC::EncodedJSValue jsStyleSheetParentStyleSheet(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
58 | JSC::EncodedJSValue jsStyleSheetHref(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
59 | JSC::EncodedJSValue jsStyleSheetTitle(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
60 | JSC::EncodedJSValue jsStyleSheetMedia(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
61 | |
62 | class JSStyleSheetPrototype : public JSC::JSNonFinalObject { |
63 | public: |
64 | using Base = JSC::JSNonFinalObject; |
65 | static JSStyleSheetPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
66 | { |
67 | JSStyleSheetPrototype* ptr = new (NotNull, JSC::allocateCell<JSStyleSheetPrototype>(vm.heap)) JSStyleSheetPrototype(vm, globalObject, structure); |
68 | ptr->finishCreation(vm); |
69 | return ptr; |
70 | } |
71 | |
72 | DECLARE_INFO; |
73 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
74 | { |
75 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
76 | } |
77 | |
78 | private: |
79 | JSStyleSheetPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
80 | : JSC::JSNonFinalObject(vm, structure) |
81 | { |
82 | } |
83 | |
84 | void finishCreation(JSC::VM&); |
85 | }; |
86 | |
87 | using JSStyleSheetConstructor = JSDOMConstructorNotConstructable<JSStyleSheet>; |
88 | |
89 | template<> JSValue JSStyleSheetConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
90 | { |
91 | UNUSED_PARAM(vm); |
92 | return globalObject.functionPrototype(); |
93 | } |
94 | |
95 | template<> void JSStyleSheetConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
96 | { |
97 | putDirect(vm, vm.propertyNames->prototype, JSStyleSheet::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
98 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("StyleSheet"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
99 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
100 | } |
101 | |
102 | template<> const ClassInfo JSStyleSheetConstructor::s_info = { "StyleSheet" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStyleSheetConstructor) }; |
103 | |
104 | /* Hash table for prototype */ |
105 | |
106 | static const HashTableValue JSStyleSheetPrototypeTableValues[] = |
107 | { |
108 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSStyleSheetConstructor) } }, |
109 | { "type" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
110 | { "disabled" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetDisabled), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSStyleSheetDisabled) } }, |
111 | { "ownerNode" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetOwnerNode), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
112 | { "parentStyleSheet" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetParentStyleSheet), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
113 | { "href" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetHref), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
114 | { "title" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetTitle), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
115 | { "media" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsStyleSheetMedia), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
116 | }; |
117 | |
118 | const ClassInfo JSStyleSheetPrototype::s_info = { "StyleSheetPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStyleSheetPrototype) }; |
119 | |
120 | void JSStyleSheetPrototype::finishCreation(VM& vm) |
121 | { |
122 | Base::finishCreation(vm); |
123 | reifyStaticProperties(vm, JSStyleSheet::info(), JSStyleSheetPrototypeTableValues, *this); |
124 | } |
125 | |
126 | const ClassInfo JSStyleSheet::s_info = { "StyleSheet" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSStyleSheet) }; |
127 | |
128 | JSStyleSheet::JSStyleSheet(Structure* structure, JSDOMGlobalObject& globalObject, Ref<StyleSheet>&& impl) |
129 | : JSDOMWrapper<StyleSheet>(structure, globalObject, WTFMove(impl)) |
130 | { |
131 | } |
132 | |
133 | void JSStyleSheet::finishCreation(VM& vm) |
134 | { |
135 | Base::finishCreation(vm); |
136 | ASSERT(inherits(vm, info())); |
137 | |
138 | } |
139 | |
140 | JSObject* JSStyleSheet::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
141 | { |
142 | return JSStyleSheetPrototype::create(vm, &globalObject, JSStyleSheetPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
143 | } |
144 | |
145 | JSObject* JSStyleSheet::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
146 | { |
147 | return getDOMPrototype<JSStyleSheet>(vm, globalObject); |
148 | } |
149 | |
150 | JSValue JSStyleSheet::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
151 | { |
152 | return getDOMConstructor<JSStyleSheetConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
153 | } |
154 | |
155 | void JSStyleSheet::destroy(JSC::JSCell* cell) |
156 | { |
157 | JSStyleSheet* thisObject = static_cast<JSStyleSheet*>(cell); |
158 | thisObject->JSStyleSheet::~JSStyleSheet(); |
159 | } |
160 | |
161 | template<> inline JSStyleSheet* IDLAttribute<JSStyleSheet>::cast(ExecState& state, EncodedJSValue thisValue) |
162 | { |
163 | return jsDynamicCast<JSStyleSheet*>(state.vm(), JSValue::decode(thisValue)); |
164 | } |
165 | |
166 | EncodedJSValue jsStyleSheetConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
167 | { |
168 | VM& vm = state->vm(); |
169 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
170 | auto* prototype = jsDynamicCast<JSStyleSheetPrototype*>(vm, JSValue::decode(thisValue)); |
171 | if (UNLIKELY(!prototype)) |
172 | return throwVMTypeError(state, throwScope); |
173 | return JSValue::encode(JSStyleSheet::getConstructor(state->vm(), prototype->globalObject())); |
174 | } |
175 | |
176 | bool setJSStyleSheetConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
177 | { |
178 | VM& vm = state->vm(); |
179 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
180 | auto* prototype = jsDynamicCast<JSStyleSheetPrototype*>(vm, JSValue::decode(thisValue)); |
181 | if (UNLIKELY(!prototype)) { |
182 | throwVMTypeError(state, throwScope); |
183 | return false; |
184 | } |
185 | // Shadowing a built-in constructor |
186 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
187 | } |
188 | |
189 | static inline JSValue jsStyleSheetTypeGetter(ExecState& state, JSStyleSheet& thisObject, ThrowScope& throwScope) |
190 | { |
191 | UNUSED_PARAM(throwScope); |
192 | UNUSED_PARAM(state); |
193 | auto& impl = thisObject.wrapped(); |
194 | JSValue result = toJS<IDLNullable<IDLDOMString>>(state, throwScope, impl.type()); |
195 | return result; |
196 | } |
197 | |
198 | EncodedJSValue jsStyleSheetType(ExecState* state, EncodedJSValue thisValue, PropertyName) |
199 | { |
200 | return IDLAttribute<JSStyleSheet>::get<jsStyleSheetTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "type" ); |
201 | } |
202 | |
203 | static inline JSValue jsStyleSheetDisabledGetter(ExecState& state, JSStyleSheet& thisObject, ThrowScope& throwScope) |
204 | { |
205 | UNUSED_PARAM(throwScope); |
206 | UNUSED_PARAM(state); |
207 | auto& impl = thisObject.wrapped(); |
208 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.disabled()); |
209 | return result; |
210 | } |
211 | |
212 | EncodedJSValue jsStyleSheetDisabled(ExecState* state, EncodedJSValue thisValue, PropertyName) |
213 | { |
214 | return IDLAttribute<JSStyleSheet>::get<jsStyleSheetDisabledGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "disabled" ); |
215 | } |
216 | |
217 | static inline bool setJSStyleSheetDisabledSetter(ExecState& state, JSStyleSheet& thisObject, JSValue value, ThrowScope& throwScope) |
218 | { |
219 | UNUSED_PARAM(throwScope); |
220 | auto& impl = thisObject.wrapped(); |
221 | auto nativeValue = convert<IDLBoolean>(state, value); |
222 | RETURN_IF_EXCEPTION(throwScope, false); |
223 | AttributeSetter::call(state, throwScope, [&] { |
224 | return impl.setDisabled(WTFMove(nativeValue)); |
225 | }); |
226 | return true; |
227 | } |
228 | |
229 | bool setJSStyleSheetDisabled(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
230 | { |
231 | return IDLAttribute<JSStyleSheet>::set<setJSStyleSheetDisabledSetter>(*state, thisValue, encodedValue, "disabled" ); |
232 | } |
233 | |
234 | static inline JSValue jsStyleSheetOwnerNodeGetter(ExecState& state, JSStyleSheet& thisObject, ThrowScope& throwScope) |
235 | { |
236 | UNUSED_PARAM(throwScope); |
237 | UNUSED_PARAM(state); |
238 | auto& impl = thisObject.wrapped(); |
239 | JSValue result = toJS<IDLInterface<Node>>(state, *thisObject.globalObject(), throwScope, impl.ownerNode()); |
240 | return result; |
241 | } |
242 | |
243 | EncodedJSValue jsStyleSheetOwnerNode(ExecState* state, EncodedJSValue thisValue, PropertyName) |
244 | { |
245 | return IDLAttribute<JSStyleSheet>::get<jsStyleSheetOwnerNodeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ownerNode" ); |
246 | } |
247 | |
248 | static inline JSValue jsStyleSheetParentStyleSheetGetter(ExecState& state, JSStyleSheet& thisObject, ThrowScope& throwScope) |
249 | { |
250 | UNUSED_PARAM(throwScope); |
251 | UNUSED_PARAM(state); |
252 | auto& impl = thisObject.wrapped(); |
253 | JSValue result = toJS<IDLInterface<StyleSheet>>(state, *thisObject.globalObject(), throwScope, impl.parentStyleSheet()); |
254 | return result; |
255 | } |
256 | |
257 | EncodedJSValue jsStyleSheetParentStyleSheet(ExecState* state, EncodedJSValue thisValue, PropertyName) |
258 | { |
259 | return IDLAttribute<JSStyleSheet>::get<jsStyleSheetParentStyleSheetGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "parentStyleSheet" ); |
260 | } |
261 | |
262 | static inline JSValue jsStyleSheetHrefGetter(ExecState& state, JSStyleSheet& thisObject, ThrowScope& throwScope) |
263 | { |
264 | UNUSED_PARAM(throwScope); |
265 | UNUSED_PARAM(state); |
266 | auto& impl = thisObject.wrapped(); |
267 | JSValue result = toJS<IDLNullable<IDLDOMString>>(state, throwScope, impl.href()); |
268 | return result; |
269 | } |
270 | |
271 | EncodedJSValue jsStyleSheetHref(ExecState* state, EncodedJSValue thisValue, PropertyName) |
272 | { |
273 | return IDLAttribute<JSStyleSheet>::get<jsStyleSheetHrefGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "href" ); |
274 | } |
275 | |
276 | static inline JSValue jsStyleSheetTitleGetter(ExecState& state, JSStyleSheet& thisObject, ThrowScope& throwScope) |
277 | { |
278 | UNUSED_PARAM(throwScope); |
279 | UNUSED_PARAM(state); |
280 | auto& impl = thisObject.wrapped(); |
281 | JSValue result = toJS<IDLNullable<IDLDOMString>>(state, throwScope, impl.title()); |
282 | return result; |
283 | } |
284 | |
285 | EncodedJSValue jsStyleSheetTitle(ExecState* state, EncodedJSValue thisValue, PropertyName) |
286 | { |
287 | return IDLAttribute<JSStyleSheet>::get<jsStyleSheetTitleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "title" ); |
288 | } |
289 | |
290 | static inline JSValue jsStyleSheetMediaGetter(ExecState& state, JSStyleSheet& thisObject, ThrowScope& throwScope) |
291 | { |
292 | UNUSED_PARAM(throwScope); |
293 | UNUSED_PARAM(state); |
294 | auto& impl = thisObject.wrapped(); |
295 | JSValue result = toJS<IDLInterface<MediaList>>(state, *thisObject.globalObject(), throwScope, impl.media()); |
296 | return result; |
297 | } |
298 | |
299 | EncodedJSValue jsStyleSheetMedia(ExecState* state, EncodedJSValue thisValue, PropertyName) |
300 | { |
301 | return IDLAttribute<JSStyleSheet>::get<jsStyleSheetMediaGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "media" ); |
302 | } |
303 | |
304 | void JSStyleSheet::visitChildren(JSCell* cell, SlotVisitor& visitor) |
305 | { |
306 | auto* thisObject = jsCast<JSStyleSheet*>(cell); |
307 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
308 | Base::visitChildren(thisObject, visitor); |
309 | thisObject->visitAdditionalChildren(visitor); |
310 | } |
311 | |
312 | void JSStyleSheet::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor) |
313 | { |
314 | auto* thisObject = jsCast<JSStyleSheet*>(cell); |
315 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
316 | Base::visitOutputConstraints(thisObject, visitor); |
317 | thisObject->visitAdditionalChildren(visitor); |
318 | } |
319 | |
320 | void JSStyleSheet::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
321 | { |
322 | auto* thisObject = jsCast<JSStyleSheet*>(cell); |
323 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
324 | if (thisObject->scriptExecutionContext()) |
325 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
326 | Base::heapSnapshot(cell, builder); |
327 | } |
328 | |
329 | bool JSStyleSheetOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
330 | { |
331 | auto* jsStyleSheet = jsCast<JSStyleSheet*>(handle.slot()->asCell()); |
332 | void* root = WebCore::root(&jsStyleSheet->wrapped()); |
333 | if (UNLIKELY(reason)) |
334 | *reason = "Reachable from jsStyleSheet" ; |
335 | return visitor.containsOpaqueRoot(root); |
336 | } |
337 | |
338 | void JSStyleSheetOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
339 | { |
340 | auto* jsStyleSheet = static_cast<JSStyleSheet*>(handle.slot()->asCell()); |
341 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
342 | uncacheWrapper(world, &jsStyleSheet->wrapped(), jsStyleSheet); |
343 | } |
344 | |
345 | StyleSheet* JSStyleSheet::toWrapped(JSC::VM& vm, JSC::JSValue value) |
346 | { |
347 | if (auto* wrapper = jsDynamicCast<JSStyleSheet*>(vm, value)) |
348 | return &wrapper->wrapped(); |
349 | return nullptr; |
350 | } |
351 | |
352 | } |
353 | |