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 "JSCSSStyleSheet.h"
23
24#include "JSCSSRule.h"
25#include "JSCSSRuleList.h"
26#include "JSDOMAttribute.h"
27#include "JSDOMBinding.h"
28#include "JSDOMConstructorNotConstructable.h"
29#include "JSDOMConvertInterface.h"
30#include "JSDOMConvertNumbers.h"
31#include "JSDOMConvertStrings.h"
32#include "JSDOMExceptionHandling.h"
33#include "JSDOMGlobalObject.h"
34#include "JSDOMOperation.h"
35#include "JSDOMWrapperCache.h"
36#include "ScriptExecutionContext.h"
37#include <JavaScriptCore/HeapSnapshotBuilder.h>
38#include <JavaScriptCore/JSCInlines.h>
39#include <wtf/GetPtr.h>
40#include <wtf/PointerPreparations.h>
41#include <wtf/URL.h>
42
43
44namespace WebCore {
45using namespace JSC;
46
47// Functions
48
49JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionInsertRule(JSC::ExecState*);
50JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionDeleteRule(JSC::ExecState*);
51JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionAddRule(JSC::ExecState*);
52JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionRemoveRule(JSC::ExecState*);
53
54// Attributes
55
56JSC::EncodedJSValue jsCSSStyleSheetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
57bool setJSCSSStyleSheetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
58JSC::EncodedJSValue jsCSSStyleSheetOwnerRule(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
59JSC::EncodedJSValue jsCSSStyleSheetCssRules(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60JSC::EncodedJSValue jsCSSStyleSheetRules(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
61
62class JSCSSStyleSheetPrototype : public JSC::JSNonFinalObject {
63public:
64 using Base = JSC::JSNonFinalObject;
65 static JSCSSStyleSheetPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
66 {
67 JSCSSStyleSheetPrototype* ptr = new (NotNull, JSC::allocateCell<JSCSSStyleSheetPrototype>(vm.heap)) JSCSSStyleSheetPrototype(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
78private:
79 JSCSSStyleSheetPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
80 : JSC::JSNonFinalObject(vm, structure)
81 {
82 }
83
84 void finishCreation(JSC::VM&);
85};
86
87using JSCSSStyleSheetConstructor = JSDOMConstructorNotConstructable<JSCSSStyleSheet>;
88
89template<> JSValue JSCSSStyleSheetConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
90{
91 return JSStyleSheet::getConstructor(vm, &globalObject);
92}
93
94template<> void JSCSSStyleSheetConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
95{
96 putDirect(vm, vm.propertyNames->prototype, JSCSSStyleSheet::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
97 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("CSSStyleSheet"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
98 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
99}
100
101template<> const ClassInfo JSCSSStyleSheetConstructor::s_info = { "CSSStyleSheet", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleSheetConstructor) };
102
103/* Hash table for prototype */
104
105static const HashTableValue JSCSSStyleSheetPrototypeTableValues[] =
106{
107 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleSheetConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCSSStyleSheetConstructor) } },
108 { "ownerRule", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleSheetOwnerRule), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
109 { "cssRules", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleSheetCssRules), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
110 { "rules", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleSheetRules), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
111 { "insertRule", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleSheetPrototypeFunctionInsertRule), (intptr_t) (1) } },
112 { "deleteRule", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleSheetPrototypeFunctionDeleteRule), (intptr_t) (1) } },
113 { "addRule", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleSheetPrototypeFunctionAddRule), (intptr_t) (0) } },
114 { "removeRule", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleSheetPrototypeFunctionRemoveRule), (intptr_t) (0) } },
115};
116
117const ClassInfo JSCSSStyleSheetPrototype::s_info = { "CSSStyleSheetPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleSheetPrototype) };
118
119void JSCSSStyleSheetPrototype::finishCreation(VM& vm)
120{
121 Base::finishCreation(vm);
122 reifyStaticProperties(vm, JSCSSStyleSheet::info(), JSCSSStyleSheetPrototypeTableValues, *this);
123}
124
125const ClassInfo JSCSSStyleSheet::s_info = { "CSSStyleSheet", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleSheet) };
126
127JSCSSStyleSheet::JSCSSStyleSheet(Structure* structure, JSDOMGlobalObject& globalObject, Ref<CSSStyleSheet>&& impl)
128 : JSStyleSheet(structure, globalObject, WTFMove(impl))
129{
130}
131
132void JSCSSStyleSheet::finishCreation(VM& vm)
133{
134 Base::finishCreation(vm);
135 ASSERT(inherits(vm, info()));
136
137}
138
139JSObject* JSCSSStyleSheet::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
140{
141 return JSCSSStyleSheetPrototype::create(vm, &globalObject, JSCSSStyleSheetPrototype::createStructure(vm, &globalObject, JSStyleSheet::prototype(vm, globalObject)));
142}
143
144JSObject* JSCSSStyleSheet::prototype(VM& vm, JSDOMGlobalObject& globalObject)
145{
146 return getDOMPrototype<JSCSSStyleSheet>(vm, globalObject);
147}
148
149JSValue JSCSSStyleSheet::getConstructor(VM& vm, const JSGlobalObject* globalObject)
150{
151 return getDOMConstructor<JSCSSStyleSheetConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
152}
153
154template<> inline JSCSSStyleSheet* IDLAttribute<JSCSSStyleSheet>::cast(ExecState& state, EncodedJSValue thisValue)
155{
156 return jsDynamicCast<JSCSSStyleSheet*>(state.vm(), JSValue::decode(thisValue));
157}
158
159template<> inline JSCSSStyleSheet* IDLOperation<JSCSSStyleSheet>::cast(ExecState& state)
160{
161 return jsDynamicCast<JSCSSStyleSheet*>(state.vm(), state.thisValue());
162}
163
164EncodedJSValue jsCSSStyleSheetConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
165{
166 VM& vm = state->vm();
167 auto throwScope = DECLARE_THROW_SCOPE(vm);
168 auto* prototype = jsDynamicCast<JSCSSStyleSheetPrototype*>(vm, JSValue::decode(thisValue));
169 if (UNLIKELY(!prototype))
170 return throwVMTypeError(state, throwScope);
171 return JSValue::encode(JSCSSStyleSheet::getConstructor(state->vm(), prototype->globalObject()));
172}
173
174bool setJSCSSStyleSheetConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
175{
176 VM& vm = state->vm();
177 auto throwScope = DECLARE_THROW_SCOPE(vm);
178 auto* prototype = jsDynamicCast<JSCSSStyleSheetPrototype*>(vm, JSValue::decode(thisValue));
179 if (UNLIKELY(!prototype)) {
180 throwVMTypeError(state, throwScope);
181 return false;
182 }
183 // Shadowing a built-in constructor
184 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
185}
186
187static inline JSValue jsCSSStyleSheetOwnerRuleGetter(ExecState& state, JSCSSStyleSheet& thisObject, ThrowScope& throwScope)
188{
189 UNUSED_PARAM(throwScope);
190 UNUSED_PARAM(state);
191 auto& impl = thisObject.wrapped();
192 JSValue result = toJS<IDLInterface<CSSRule>>(state, *thisObject.globalObject(), throwScope, impl.ownerRule());
193 return result;
194}
195
196EncodedJSValue jsCSSStyleSheetOwnerRule(ExecState* state, EncodedJSValue thisValue, PropertyName)
197{
198 return IDLAttribute<JSCSSStyleSheet>::get<jsCSSStyleSheetOwnerRuleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ownerRule");
199}
200
201static inline JSValue jsCSSStyleSheetCssRulesGetter(ExecState& state, JSCSSStyleSheet& thisObject, ThrowScope& throwScope)
202{
203 UNUSED_PARAM(throwScope);
204 UNUSED_PARAM(state);
205 auto& impl = thisObject.wrapped();
206 JSValue result = toJS<IDLInterface<CSSRuleList>>(state, *thisObject.globalObject(), throwScope, impl.cssRules());
207 return result;
208}
209
210EncodedJSValue jsCSSStyleSheetCssRules(ExecState* state, EncodedJSValue thisValue, PropertyName)
211{
212 return IDLAttribute<JSCSSStyleSheet>::get<jsCSSStyleSheetCssRulesGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "cssRules");
213}
214
215static inline JSValue jsCSSStyleSheetRulesGetter(ExecState& state, JSCSSStyleSheet& thisObject, ThrowScope& throwScope)
216{
217 UNUSED_PARAM(throwScope);
218 UNUSED_PARAM(state);
219 auto& impl = thisObject.wrapped();
220 JSValue result = toJS<IDLInterface<CSSRuleList>>(state, *thisObject.globalObject(), throwScope, impl.rules());
221 return result;
222}
223
224EncodedJSValue jsCSSStyleSheetRules(ExecState* state, EncodedJSValue thisValue, PropertyName)
225{
226 return IDLAttribute<JSCSSStyleSheet>::get<jsCSSStyleSheetRulesGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "rules");
227}
228
229static inline JSC::EncodedJSValue jsCSSStyleSheetPrototypeFunctionInsertRuleBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleSheet>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
230{
231 UNUSED_PARAM(state);
232 UNUSED_PARAM(throwScope);
233 auto& impl = castedThis->wrapped();
234 if (UNLIKELY(state->argumentCount() < 1))
235 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
236 auto rule = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
237 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
238 auto index = convert<IDLUnsignedLong>(*state, state->argument(1));
239 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
240 return JSValue::encode(toJS<IDLUnsignedLong>(*state, throwScope, impl.insertRule(WTFMove(rule), WTFMove(index))));
241}
242
243EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionInsertRule(ExecState* state)
244{
245 return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionInsertRuleBody>(*state, "insertRule");
246}
247
248static inline JSC::EncodedJSValue jsCSSStyleSheetPrototypeFunctionDeleteRuleBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleSheet>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
249{
250 UNUSED_PARAM(state);
251 UNUSED_PARAM(throwScope);
252 auto& impl = castedThis->wrapped();
253 if (UNLIKELY(state->argumentCount() < 1))
254 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
255 auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
256 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
257 propagateException(*state, throwScope, impl.deleteRule(WTFMove(index)));
258 return JSValue::encode(jsUndefined());
259}
260
261EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionDeleteRule(ExecState* state)
262{
263 return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionDeleteRuleBody>(*state, "deleteRule");
264}
265
266static inline JSC::EncodedJSValue jsCSSStyleSheetPrototypeFunctionAddRuleBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleSheet>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
267{
268 UNUSED_PARAM(state);
269 UNUSED_PARAM(throwScope);
270 auto& impl = castedThis->wrapped();
271 auto selector = convert<IDLDOMString>(*state, state->argument(0));
272 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
273 auto style = convert<IDLDOMString>(*state, state->argument(1));
274 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
275 auto index = state->argument(2).isUndefined() ? Optional<Converter<IDLUnsignedLong>::ReturnType>() : Optional<Converter<IDLUnsignedLong>::ReturnType>(convert<IDLUnsignedLong>(*state, state->uncheckedArgument(2)));
276 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
277 return JSValue::encode(toJS<IDLLong>(*state, throwScope, impl.addRule(WTFMove(selector), WTFMove(style), WTFMove(index))));
278}
279
280EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionAddRule(ExecState* state)
281{
282 return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionAddRuleBody>(*state, "addRule");
283}
284
285static inline JSC::EncodedJSValue jsCSSStyleSheetPrototypeFunctionRemoveRuleBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleSheet>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
286{
287 UNUSED_PARAM(state);
288 UNUSED_PARAM(throwScope);
289 auto& impl = castedThis->wrapped();
290 auto index = convert<IDLUnsignedLong>(*state, state->argument(0));
291 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
292 propagateException(*state, throwScope, impl.removeRule(WTFMove(index)));
293 return JSValue::encode(jsUndefined());
294}
295
296EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionRemoveRule(ExecState* state)
297{
298 return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionRemoveRuleBody>(*state, "removeRule");
299}
300
301void JSCSSStyleSheet::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
302{
303 auto* thisObject = jsCast<JSCSSStyleSheet*>(cell);
304 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
305 if (thisObject->scriptExecutionContext())
306 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
307 Base::heapSnapshot(cell, builder);
308}
309
310
311}
312