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 "JSCSSStyleDeclaration.h" |
23 | |
24 | #include "CustomElementReactionQueue.h" |
25 | #include "JSCSSRule.h" |
26 | #include "JSDOMAbstractOperations.h" |
27 | #include "JSDOMAttribute.h" |
28 | #include "JSDOMBinding.h" |
29 | #include "JSDOMConstructorNotConstructable.h" |
30 | #include "JSDOMConvertBoolean.h" |
31 | #include "JSDOMConvertInterface.h" |
32 | #include "JSDOMConvertNullable.h" |
33 | #include "JSDOMConvertNumbers.h" |
34 | #include "JSDOMConvertStrings.h" |
35 | #include "JSDOMConvertUnion.h" |
36 | #include "JSDOMExceptionHandling.h" |
37 | #include "JSDOMGlobalObject.h" |
38 | #include "JSDOMOperation.h" |
39 | #include "JSDOMWrapperCache.h" |
40 | #include "JSDeprecatedCSSOMValue.h" |
41 | #include "ScriptExecutionContext.h" |
42 | #include <JavaScriptCore/ArrayPrototype.h> |
43 | #include <JavaScriptCore/BuiltinNames.h> |
44 | #include <JavaScriptCore/FunctionPrototype.h> |
45 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
46 | #include <JavaScriptCore/JSCInlines.h> |
47 | #include <JavaScriptCore/PropertyNameArray.h> |
48 | #include <wtf/GetPtr.h> |
49 | #include <wtf/PointerPreparations.h> |
50 | #include <wtf/URL.h> |
51 | #include <wtf/Variant.h> |
52 | |
53 | |
54 | namespace WebCore { |
55 | using namespace JSC; |
56 | |
57 | // Functions |
58 | |
59 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyValue(JSC::ExecState*); |
60 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionRemoveProperty(JSC::ExecState*); |
61 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyPriority(JSC::ExecState*); |
62 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionSetProperty(JSC::ExecState*); |
63 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionItem(JSC::ExecState*); |
64 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyShorthand(JSC::ExecState*); |
65 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionIsPropertyImplicit(JSC::ExecState*); |
66 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyCSSValue(JSC::ExecState*); |
67 | |
68 | // Attributes |
69 | |
70 | JSC::EncodedJSValue jsCSSStyleDeclarationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
71 | bool setJSCSSStyleDeclarationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
72 | JSC::EncodedJSValue jsCSSStyleDeclarationCssText(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
73 | bool setJSCSSStyleDeclarationCssText(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
74 | JSC::EncodedJSValue jsCSSStyleDeclarationLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
75 | JSC::EncodedJSValue jsCSSStyleDeclarationParentRule(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
76 | JSC::EncodedJSValue jsCSSStyleDeclarationCssFloat(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
77 | bool setJSCSSStyleDeclarationCssFloat(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
78 | |
79 | class JSCSSStyleDeclarationPrototype : public JSC::JSNonFinalObject { |
80 | public: |
81 | using Base = JSC::JSNonFinalObject; |
82 | static JSCSSStyleDeclarationPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
83 | { |
84 | JSCSSStyleDeclarationPrototype* ptr = new (NotNull, JSC::allocateCell<JSCSSStyleDeclarationPrototype>(vm.heap)) JSCSSStyleDeclarationPrototype(vm, globalObject, structure); |
85 | ptr->finishCreation(vm); |
86 | return ptr; |
87 | } |
88 | |
89 | DECLARE_INFO; |
90 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
91 | { |
92 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
93 | } |
94 | |
95 | private: |
96 | JSCSSStyleDeclarationPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
97 | : JSC::JSNonFinalObject(vm, structure) |
98 | { |
99 | } |
100 | |
101 | void finishCreation(JSC::VM&); |
102 | }; |
103 | |
104 | using JSCSSStyleDeclarationConstructor = JSDOMConstructorNotConstructable<JSCSSStyleDeclaration>; |
105 | |
106 | template<> JSValue JSCSSStyleDeclarationConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
107 | { |
108 | UNUSED_PARAM(vm); |
109 | return globalObject.functionPrototype(); |
110 | } |
111 | |
112 | template<> void JSCSSStyleDeclarationConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
113 | { |
114 | putDirect(vm, vm.propertyNames->prototype, JSCSSStyleDeclaration::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
115 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("CSSStyleDeclaration"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
116 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
117 | } |
118 | |
119 | template<> const ClassInfo JSCSSStyleDeclarationConstructor::s_info = { "CSSStyleDeclaration" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleDeclarationConstructor) }; |
120 | |
121 | /* Hash table for prototype */ |
122 | |
123 | static const HashTableValue JSCSSStyleDeclarationPrototypeTableValues[] = |
124 | { |
125 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleDeclarationConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCSSStyleDeclarationConstructor) } }, |
126 | { "cssText" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleDeclarationCssText), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCSSStyleDeclarationCssText) } }, |
127 | { "length" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleDeclarationLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
128 | { "parentRule" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleDeclarationParentRule), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
129 | { "cssFloat" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSStyleDeclarationCssFloat), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCSSStyleDeclarationCssFloat) } }, |
130 | { "getPropertyValue" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionGetPropertyValue), (intptr_t) (1) } }, |
131 | { "removeProperty" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionRemoveProperty), (intptr_t) (1) } }, |
132 | { "getPropertyPriority" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionGetPropertyPriority), (intptr_t) (1) } }, |
133 | { "setProperty" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionSetProperty), (intptr_t) (2) } }, |
134 | { "item" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionItem), (intptr_t) (1) } }, |
135 | { "getPropertyShorthand" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionGetPropertyShorthand), (intptr_t) (0) } }, |
136 | { "isPropertyImplicit" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionIsPropertyImplicit), (intptr_t) (0) } }, |
137 | { "getPropertyCSSValue" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCSSStyleDeclarationPrototypeFunctionGetPropertyCSSValue), (intptr_t) (1) } }, |
138 | }; |
139 | |
140 | const ClassInfo JSCSSStyleDeclarationPrototype::s_info = { "CSSStyleDeclarationPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleDeclarationPrototype) }; |
141 | |
142 | void JSCSSStyleDeclarationPrototype::finishCreation(VM& vm) |
143 | { |
144 | Base::finishCreation(vm); |
145 | reifyStaticProperties(vm, JSCSSStyleDeclaration::info(), JSCSSStyleDeclarationPrototypeTableValues, *this); |
146 | putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum)); |
147 | } |
148 | |
149 | const ClassInfo JSCSSStyleDeclaration::s_info = { "CSSStyleDeclaration" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleDeclaration) }; |
150 | |
151 | JSCSSStyleDeclaration::JSCSSStyleDeclaration(Structure* structure, JSDOMGlobalObject& globalObject, Ref<CSSStyleDeclaration>&& impl) |
152 | : JSDOMWrapper<CSSStyleDeclaration>(structure, globalObject, WTFMove(impl)) |
153 | { |
154 | } |
155 | |
156 | void JSCSSStyleDeclaration::finishCreation(VM& vm) |
157 | { |
158 | Base::finishCreation(vm); |
159 | ASSERT(inherits(vm, info())); |
160 | |
161 | } |
162 | |
163 | JSObject* JSCSSStyleDeclaration::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
164 | { |
165 | return JSCSSStyleDeclarationPrototype::create(vm, &globalObject, JSCSSStyleDeclarationPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
166 | } |
167 | |
168 | JSObject* JSCSSStyleDeclaration::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
169 | { |
170 | return getDOMPrototype<JSCSSStyleDeclaration>(vm, globalObject); |
171 | } |
172 | |
173 | JSValue JSCSSStyleDeclaration::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
174 | { |
175 | return getDOMConstructor<JSCSSStyleDeclarationConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
176 | } |
177 | |
178 | void JSCSSStyleDeclaration::destroy(JSC::JSCell* cell) |
179 | { |
180 | JSCSSStyleDeclaration* thisObject = static_cast<JSCSSStyleDeclaration*>(cell); |
181 | thisObject->JSCSSStyleDeclaration::~JSCSSStyleDeclaration(); |
182 | } |
183 | |
184 | bool JSCSSStyleDeclaration::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot) |
185 | { |
186 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(object); |
187 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
188 | if (auto index = parseIndex(propertyName)) { |
189 | if (index.value() < thisObject->wrapped().length()) { |
190 | auto value = toJS<IDLDOMString>(*state, thisObject->wrapped().item(index.value())); |
191 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
192 | return true; |
193 | } |
194 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
195 | } |
196 | using GetterIDLType = IDLUnion<IDLDOMString, IDLDouble>; |
197 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
198 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName)); |
199 | if (!GetterIDLType::isNullValue(result)) |
200 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
201 | return WTF::nullopt; |
202 | }; |
203 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
204 | auto value = toJS<IDLUnion<IDLDOMString, IDLDouble>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
205 | slot.setValue(thisObject, static_cast<unsigned>(0), value); |
206 | return true; |
207 | } |
208 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
209 | } |
210 | |
211 | bool JSCSSStyleDeclaration::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot) |
212 | { |
213 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(object); |
214 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
215 | if (LIKELY(index <= MAX_ARRAY_INDEX)) { |
216 | if (index < thisObject->wrapped().length()) { |
217 | auto value = toJS<IDLDOMString>(*state, thisObject->wrapped().item(index)); |
218 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
219 | return true; |
220 | } |
221 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
222 | } |
223 | auto propertyName = Identifier::from(state, index); |
224 | using GetterIDLType = IDLUnion<IDLDOMString, IDLDouble>; |
225 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
226 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName)); |
227 | if (!GetterIDLType::isNullValue(result)) |
228 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
229 | return WTF::nullopt; |
230 | }; |
231 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
232 | auto value = toJS<IDLUnion<IDLDOMString, IDLDouble>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
233 | slot.setValue(thisObject, static_cast<unsigned>(0), value); |
234 | return true; |
235 | } |
236 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
237 | } |
238 | |
239 | void JSCSSStyleDeclaration::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode) |
240 | { |
241 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(object); |
242 | ASSERT_GC_OBJECT_INHERITS(object, info()); |
243 | for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i) |
244 | propertyNames.add(Identifier::from(state, i)); |
245 | for (auto& propertyName : thisObject->wrapped().supportedPropertyNames()) |
246 | propertyNames.add(Identifier::fromString(state, propertyName)); |
247 | JSObject::getOwnPropertyNames(object, state, propertyNames, mode); |
248 | } |
249 | |
250 | bool JSCSSStyleDeclaration::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot) |
251 | { |
252 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(cell); |
253 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
254 | |
255 | CustomElementReactionStack customElementReactionStack(*state); |
256 | if (!propertyName.isSymbol()) { |
257 | PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry }; |
258 | JSValue prototype = thisObject->getPrototypeDirect(state->vm()); |
259 | if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) { |
260 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
261 | auto nativeValue = convert<IDLTreatNullAsEmptyAdaptor<IDLDOMString>>(*state, value); |
262 | RETURN_IF_EXCEPTION(throwScope, true); |
263 | bool isPropertySupported = true; |
264 | propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue), isPropertySupported)); |
265 | if (!isPropertySupported) |
266 | return JSObject::put(thisObject, state, propertyName, value, putPropertySlot); |
267 | return true; |
268 | } |
269 | } |
270 | |
271 | return JSObject::put(thisObject, state, propertyName, value, putPropertySlot); |
272 | } |
273 | |
274 | bool JSCSSStyleDeclaration::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool shouldThrow) |
275 | { |
276 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(cell); |
277 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
278 | |
279 | CustomElementReactionStack customElementReactionStack(*state); |
280 | auto propertyName = Identifier::from(state, index); |
281 | PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry }; |
282 | JSValue prototype = thisObject->getPrototypeDirect(state->vm()); |
283 | if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) { |
284 | auto throwScope = DECLARE_THROW_SCOPE(state->vm()); |
285 | auto nativeValue = convert<IDLTreatNullAsEmptyAdaptor<IDLDOMString>>(*state, value); |
286 | RETURN_IF_EXCEPTION(throwScope, true); |
287 | bool isPropertySupported = true; |
288 | propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue), isPropertySupported)); |
289 | if (!isPropertySupported) |
290 | return JSObject::putByIndex(cell, state, index, value, shouldThrow); |
291 | return true; |
292 | } |
293 | |
294 | return JSObject::putByIndex(cell, state, index, value, shouldThrow); |
295 | } |
296 | |
297 | template<> inline JSCSSStyleDeclaration* IDLAttribute<JSCSSStyleDeclaration>::cast(ExecState& state, EncodedJSValue thisValue) |
298 | { |
299 | return jsDynamicCast<JSCSSStyleDeclaration*>(state.vm(), JSValue::decode(thisValue)); |
300 | } |
301 | |
302 | template<> inline JSCSSStyleDeclaration* IDLOperation<JSCSSStyleDeclaration>::cast(ExecState& state) |
303 | { |
304 | return jsDynamicCast<JSCSSStyleDeclaration*>(state.vm(), state.thisValue()); |
305 | } |
306 | |
307 | EncodedJSValue jsCSSStyleDeclarationConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
308 | { |
309 | VM& vm = state->vm(); |
310 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
311 | auto* prototype = jsDynamicCast<JSCSSStyleDeclarationPrototype*>(vm, JSValue::decode(thisValue)); |
312 | if (UNLIKELY(!prototype)) |
313 | return throwVMTypeError(state, throwScope); |
314 | return JSValue::encode(JSCSSStyleDeclaration::getConstructor(state->vm(), prototype->globalObject())); |
315 | } |
316 | |
317 | bool setJSCSSStyleDeclarationConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
318 | { |
319 | VM& vm = state->vm(); |
320 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
321 | auto* prototype = jsDynamicCast<JSCSSStyleDeclarationPrototype*>(vm, JSValue::decode(thisValue)); |
322 | if (UNLIKELY(!prototype)) { |
323 | throwVMTypeError(state, throwScope); |
324 | return false; |
325 | } |
326 | // Shadowing a built-in constructor |
327 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
328 | } |
329 | |
330 | static inline JSValue jsCSSStyleDeclarationCssTextGetter(ExecState& state, JSCSSStyleDeclaration& thisObject, ThrowScope& throwScope) |
331 | { |
332 | UNUSED_PARAM(throwScope); |
333 | UNUSED_PARAM(state); |
334 | auto& impl = thisObject.wrapped(); |
335 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.cssText()); |
336 | return result; |
337 | } |
338 | |
339 | EncodedJSValue jsCSSStyleDeclarationCssText(ExecState* state, EncodedJSValue thisValue, PropertyName) |
340 | { |
341 | return IDLAttribute<JSCSSStyleDeclaration>::get<jsCSSStyleDeclarationCssTextGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "cssText" ); |
342 | } |
343 | |
344 | static inline bool setJSCSSStyleDeclarationCssTextSetter(ExecState& state, JSCSSStyleDeclaration& thisObject, JSValue value, ThrowScope& throwScope) |
345 | { |
346 | UNUSED_PARAM(throwScope); |
347 | CustomElementReactionStack customElementReactionStack(state); |
348 | auto& impl = thisObject.wrapped(); |
349 | auto nativeValue = convert<IDLDOMString>(state, value); |
350 | RETURN_IF_EXCEPTION(throwScope, false); |
351 | AttributeSetter::call(state, throwScope, [&] { |
352 | return impl.setCssText(WTFMove(nativeValue)); |
353 | }); |
354 | return true; |
355 | } |
356 | |
357 | bool setJSCSSStyleDeclarationCssText(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
358 | { |
359 | return IDLAttribute<JSCSSStyleDeclaration>::set<setJSCSSStyleDeclarationCssTextSetter>(*state, thisValue, encodedValue, "cssText" ); |
360 | } |
361 | |
362 | static inline JSValue jsCSSStyleDeclarationLengthGetter(ExecState& state, JSCSSStyleDeclaration& thisObject, ThrowScope& throwScope) |
363 | { |
364 | UNUSED_PARAM(throwScope); |
365 | UNUSED_PARAM(state); |
366 | auto& impl = thisObject.wrapped(); |
367 | JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length()); |
368 | return result; |
369 | } |
370 | |
371 | EncodedJSValue jsCSSStyleDeclarationLength(ExecState* state, EncodedJSValue thisValue, PropertyName) |
372 | { |
373 | return IDLAttribute<JSCSSStyleDeclaration>::get<jsCSSStyleDeclarationLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length" ); |
374 | } |
375 | |
376 | static inline JSValue jsCSSStyleDeclarationParentRuleGetter(ExecState& state, JSCSSStyleDeclaration& thisObject, ThrowScope& throwScope) |
377 | { |
378 | UNUSED_PARAM(throwScope); |
379 | UNUSED_PARAM(state); |
380 | auto& impl = thisObject.wrapped(); |
381 | JSValue result = toJS<IDLNullable<IDLInterface<CSSRule>>>(state, *thisObject.globalObject(), throwScope, impl.parentRule()); |
382 | return result; |
383 | } |
384 | |
385 | EncodedJSValue jsCSSStyleDeclarationParentRule(ExecState* state, EncodedJSValue thisValue, PropertyName) |
386 | { |
387 | return IDLAttribute<JSCSSStyleDeclaration>::get<jsCSSStyleDeclarationParentRuleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "parentRule" ); |
388 | } |
389 | |
390 | static inline JSValue jsCSSStyleDeclarationCssFloatGetter(ExecState& state, JSCSSStyleDeclaration& thisObject, ThrowScope& throwScope) |
391 | { |
392 | UNUSED_PARAM(throwScope); |
393 | UNUSED_PARAM(state); |
394 | auto& impl = thisObject.wrapped(); |
395 | JSValue result = toJS<IDLTreatNullAsEmptyAdaptor<IDLDOMString>>(state, throwScope, impl.cssFloat()); |
396 | return result; |
397 | } |
398 | |
399 | EncodedJSValue jsCSSStyleDeclarationCssFloat(ExecState* state, EncodedJSValue thisValue, PropertyName) |
400 | { |
401 | return IDLAttribute<JSCSSStyleDeclaration>::get<jsCSSStyleDeclarationCssFloatGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "cssFloat" ); |
402 | } |
403 | |
404 | static inline bool setJSCSSStyleDeclarationCssFloatSetter(ExecState& state, JSCSSStyleDeclaration& thisObject, JSValue value, ThrowScope& throwScope) |
405 | { |
406 | UNUSED_PARAM(throwScope); |
407 | CustomElementReactionStack customElementReactionStack(state); |
408 | auto& impl = thisObject.wrapped(); |
409 | auto nativeValue = convert<IDLTreatNullAsEmptyAdaptor<IDLDOMString>>(state, value); |
410 | RETURN_IF_EXCEPTION(throwScope, false); |
411 | AttributeSetter::call(state, throwScope, [&] { |
412 | return impl.setCssFloat(WTFMove(nativeValue)); |
413 | }); |
414 | return true; |
415 | } |
416 | |
417 | bool setJSCSSStyleDeclarationCssFloat(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
418 | { |
419 | return IDLAttribute<JSCSSStyleDeclaration>::set<setJSCSSStyleDeclarationCssFloatSetter>(*state, thisValue, encodedValue, "cssFloat" ); |
420 | } |
421 | |
422 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionGetPropertyValueBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
423 | { |
424 | UNUSED_PARAM(state); |
425 | UNUSED_PARAM(throwScope); |
426 | auto& impl = castedThis->wrapped(); |
427 | if (UNLIKELY(state->argumentCount() < 1)) |
428 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
429 | auto propertyName = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
430 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
431 | return JSValue::encode(toJS<IDLDOMString>(*state, impl.getPropertyValue(WTFMove(propertyName)))); |
432 | } |
433 | |
434 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyValue(ExecState* state) |
435 | { |
436 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionGetPropertyValueBody>(*state, "getPropertyValue" ); |
437 | } |
438 | |
439 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionRemovePropertyBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
440 | { |
441 | UNUSED_PARAM(state); |
442 | UNUSED_PARAM(throwScope); |
443 | CustomElementReactionStack customElementReactionStack(*state); |
444 | auto& impl = castedThis->wrapped(); |
445 | if (UNLIKELY(state->argumentCount() < 1)) |
446 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
447 | auto propertyName = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
448 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
449 | return JSValue::encode(toJS<IDLDOMString>(*state, throwScope, impl.removeProperty(WTFMove(propertyName)))); |
450 | } |
451 | |
452 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionRemoveProperty(ExecState* state) |
453 | { |
454 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionRemovePropertyBody>(*state, "removeProperty" ); |
455 | } |
456 | |
457 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionGetPropertyPriorityBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
458 | { |
459 | UNUSED_PARAM(state); |
460 | UNUSED_PARAM(throwScope); |
461 | auto& impl = castedThis->wrapped(); |
462 | if (UNLIKELY(state->argumentCount() < 1)) |
463 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
464 | auto propertyName = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
465 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
466 | return JSValue::encode(toJS<IDLNullable<IDLDOMString>>(*state, impl.getPropertyPriority(WTFMove(propertyName)))); |
467 | } |
468 | |
469 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyPriority(ExecState* state) |
470 | { |
471 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionGetPropertyPriorityBody>(*state, "getPropertyPriority" ); |
472 | } |
473 | |
474 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionSetPropertyBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
475 | { |
476 | UNUSED_PARAM(state); |
477 | UNUSED_PARAM(throwScope); |
478 | CustomElementReactionStack customElementReactionStack(*state); |
479 | auto& impl = castedThis->wrapped(); |
480 | if (UNLIKELY(state->argumentCount() < 2)) |
481 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
482 | auto propertyName = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
483 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
484 | auto value = convert<IDLTreatNullAsEmptyAdaptor<IDLDOMString>>(*state, state->uncheckedArgument(1)); |
485 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
486 | auto priority = state->argument(2).isUndefined() ? emptyString() : convert<IDLTreatNullAsEmptyAdaptor<IDLDOMString>>(*state, state->uncheckedArgument(2)); |
487 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
488 | propagateException(*state, throwScope, impl.setProperty(WTFMove(propertyName), WTFMove(value), WTFMove(priority))); |
489 | return JSValue::encode(jsUndefined()); |
490 | } |
491 | |
492 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionSetProperty(ExecState* state) |
493 | { |
494 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionSetPropertyBody>(*state, "setProperty" ); |
495 | } |
496 | |
497 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
498 | { |
499 | UNUSED_PARAM(state); |
500 | UNUSED_PARAM(throwScope); |
501 | auto& impl = castedThis->wrapped(); |
502 | if (UNLIKELY(state->argumentCount() < 1)) |
503 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
504 | auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
505 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
506 | return JSValue::encode(toJS<IDLDOMString>(*state, impl.item(WTFMove(index)))); |
507 | } |
508 | |
509 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionItem(ExecState* state) |
510 | { |
511 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionItemBody>(*state, "item" ); |
512 | } |
513 | |
514 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionGetPropertyShorthandBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
515 | { |
516 | UNUSED_PARAM(state); |
517 | UNUSED_PARAM(throwScope); |
518 | auto& impl = castedThis->wrapped(); |
519 | auto propertyName = convert<IDLDOMString>(*state, state->argument(0)); |
520 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
521 | return JSValue::encode(toJS<IDLNullable<IDLDOMString>>(*state, impl.getPropertyShorthand(WTFMove(propertyName)))); |
522 | } |
523 | |
524 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyShorthand(ExecState* state) |
525 | { |
526 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionGetPropertyShorthandBody>(*state, "getPropertyShorthand" ); |
527 | } |
528 | |
529 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionIsPropertyImplicitBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
530 | { |
531 | UNUSED_PARAM(state); |
532 | UNUSED_PARAM(throwScope); |
533 | auto& impl = castedThis->wrapped(); |
534 | auto propertyName = convert<IDLDOMString>(*state, state->argument(0)); |
535 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
536 | return JSValue::encode(toJS<IDLBoolean>(impl.isPropertyImplicit(WTFMove(propertyName)))); |
537 | } |
538 | |
539 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionIsPropertyImplicit(ExecState* state) |
540 | { |
541 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionIsPropertyImplicitBody>(*state, "isPropertyImplicit" ); |
542 | } |
543 | |
544 | static inline JSC::EncodedJSValue jsCSSStyleDeclarationPrototypeFunctionGetPropertyCSSValueBody(JSC::ExecState* state, typename IDLOperation<JSCSSStyleDeclaration>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
545 | { |
546 | UNUSED_PARAM(state); |
547 | UNUSED_PARAM(throwScope); |
548 | auto& impl = castedThis->wrapped(); |
549 | if (UNLIKELY(state->argumentCount() < 1)) |
550 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
551 | auto propertyName = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
552 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
553 | return JSValue::encode(toJS<IDLNullable<IDLInterface<DeprecatedCSSOMValue>>>(*state, *castedThis->globalObject(), impl.getPropertyCSSValue(WTFMove(propertyName)))); |
554 | } |
555 | |
556 | EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyCSSValue(ExecState* state) |
557 | { |
558 | return IDLOperation<JSCSSStyleDeclaration>::call<jsCSSStyleDeclarationPrototypeFunctionGetPropertyCSSValueBody>(*state, "getPropertyCSSValue" ); |
559 | } |
560 | |
561 | void JSCSSStyleDeclaration::visitChildren(JSCell* cell, SlotVisitor& visitor) |
562 | { |
563 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(cell); |
564 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
565 | Base::visitChildren(thisObject, visitor); |
566 | thisObject->visitAdditionalChildren(visitor); |
567 | } |
568 | |
569 | void JSCSSStyleDeclaration::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor) |
570 | { |
571 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(cell); |
572 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
573 | Base::visitOutputConstraints(thisObject, visitor); |
574 | thisObject->visitAdditionalChildren(visitor); |
575 | } |
576 | |
577 | void JSCSSStyleDeclaration::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
578 | { |
579 | auto* thisObject = jsCast<JSCSSStyleDeclaration*>(cell); |
580 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
581 | if (thisObject->scriptExecutionContext()) |
582 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
583 | Base::heapSnapshot(cell, builder); |
584 | } |
585 | |
586 | bool JSCSSStyleDeclarationOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
587 | { |
588 | auto* jsCSSStyleDeclaration = jsCast<JSCSSStyleDeclaration*>(handle.slot()->asCell()); |
589 | void* root = WebCore::root(&jsCSSStyleDeclaration->wrapped()); |
590 | if (UNLIKELY(reason)) |
591 | *reason = "Reachable from jsCSSStyleDeclaration" ; |
592 | return visitor.containsOpaqueRoot(root); |
593 | } |
594 | |
595 | void JSCSSStyleDeclarationOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
596 | { |
597 | auto* jsCSSStyleDeclaration = static_cast<JSCSSStyleDeclaration*>(handle.slot()->asCell()); |
598 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
599 | uncacheWrapper(world, &jsCSSStyleDeclaration->wrapped(), jsCSSStyleDeclaration); |
600 | } |
601 | |
602 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<CSSStyleDeclaration>&& impl) |
603 | { |
604 | return createWrapper<CSSStyleDeclaration>(globalObject, WTFMove(impl)); |
605 | } |
606 | |
607 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, CSSStyleDeclaration& impl) |
608 | { |
609 | return wrap(state, globalObject, impl); |
610 | } |
611 | |
612 | CSSStyleDeclaration* JSCSSStyleDeclaration::toWrapped(JSC::VM& vm, JSC::JSValue value) |
613 | { |
614 | if (auto* wrapper = jsDynamicCast<JSCSSStyleDeclaration*>(vm, value)) |
615 | return &wrapper->wrapped(); |
616 | return nullptr; |
617 | } |
618 | |
619 | } |
620 | |