| 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 | |
| 44 | namespace WebCore { |
| 45 | using namespace JSC; |
| 46 | |
| 47 | // Functions |
| 48 | |
| 49 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionInsertRule(JSC::ExecState*); |
| 50 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionDeleteRule(JSC::ExecState*); |
| 51 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionAddRule(JSC::ExecState*); |
| 52 | JSC::EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionRemoveRule(JSC::ExecState*); |
| 53 | |
| 54 | // Attributes |
| 55 | |
| 56 | JSC::EncodedJSValue jsCSSStyleSheetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 57 | bool setJSCSSStyleSheetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 58 | JSC::EncodedJSValue jsCSSStyleSheetOwnerRule(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 59 | JSC::EncodedJSValue jsCSSStyleSheetCssRules(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 60 | JSC::EncodedJSValue jsCSSStyleSheetRules(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 61 | |
| 62 | class JSCSSStyleSheetPrototype : public JSC::JSNonFinalObject { |
| 63 | public: |
| 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 | |
| 78 | private: |
| 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 | |
| 87 | using JSCSSStyleSheetConstructor = JSDOMConstructorNotConstructable<JSCSSStyleSheet>; |
| 88 | |
| 89 | template<> JSValue JSCSSStyleSheetConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 90 | { |
| 91 | return JSStyleSheet::getConstructor(vm, &globalObject); |
| 92 | } |
| 93 | |
| 94 | template<> 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 | |
| 101 | template<> const ClassInfo JSCSSStyleSheetConstructor::s_info = { "CSSStyleSheet" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleSheetConstructor) }; |
| 102 | |
| 103 | /* Hash table for prototype */ |
| 104 | |
| 105 | static 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 | |
| 117 | const ClassInfo JSCSSStyleSheetPrototype::s_info = { "CSSStyleSheetPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleSheetPrototype) }; |
| 118 | |
| 119 | void JSCSSStyleSheetPrototype::finishCreation(VM& vm) |
| 120 | { |
| 121 | Base::finishCreation(vm); |
| 122 | reifyStaticProperties(vm, JSCSSStyleSheet::info(), JSCSSStyleSheetPrototypeTableValues, *this); |
| 123 | } |
| 124 | |
| 125 | const ClassInfo JSCSSStyleSheet::s_info = { "CSSStyleSheet" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCSSStyleSheet) }; |
| 126 | |
| 127 | JSCSSStyleSheet::JSCSSStyleSheet(Structure* structure, JSDOMGlobalObject& globalObject, Ref<CSSStyleSheet>&& impl) |
| 128 | : JSStyleSheet(structure, globalObject, WTFMove(impl)) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | void JSCSSStyleSheet::finishCreation(VM& vm) |
| 133 | { |
| 134 | Base::finishCreation(vm); |
| 135 | ASSERT(inherits(vm, info())); |
| 136 | |
| 137 | } |
| 138 | |
| 139 | JSObject* JSCSSStyleSheet::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 140 | { |
| 141 | return JSCSSStyleSheetPrototype::create(vm, &globalObject, JSCSSStyleSheetPrototype::createStructure(vm, &globalObject, JSStyleSheet::prototype(vm, globalObject))); |
| 142 | } |
| 143 | |
| 144 | JSObject* JSCSSStyleSheet::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 145 | { |
| 146 | return getDOMPrototype<JSCSSStyleSheet>(vm, globalObject); |
| 147 | } |
| 148 | |
| 149 | JSValue JSCSSStyleSheet::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 150 | { |
| 151 | return getDOMConstructor<JSCSSStyleSheetConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 152 | } |
| 153 | |
| 154 | template<> inline JSCSSStyleSheet* IDLAttribute<JSCSSStyleSheet>::cast(ExecState& state, EncodedJSValue thisValue) |
| 155 | { |
| 156 | return jsDynamicCast<JSCSSStyleSheet*>(state.vm(), JSValue::decode(thisValue)); |
| 157 | } |
| 158 | |
| 159 | template<> inline JSCSSStyleSheet* IDLOperation<JSCSSStyleSheet>::cast(ExecState& state) |
| 160 | { |
| 161 | return jsDynamicCast<JSCSSStyleSheet*>(state.vm(), state.thisValue()); |
| 162 | } |
| 163 | |
| 164 | EncodedJSValue 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 | |
| 174 | bool 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 | |
| 187 | static 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 | |
| 196 | EncodedJSValue jsCSSStyleSheetOwnerRule(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 197 | { |
| 198 | return IDLAttribute<JSCSSStyleSheet>::get<jsCSSStyleSheetOwnerRuleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ownerRule" ); |
| 199 | } |
| 200 | |
| 201 | static 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 | |
| 210 | EncodedJSValue jsCSSStyleSheetCssRules(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 211 | { |
| 212 | return IDLAttribute<JSCSSStyleSheet>::get<jsCSSStyleSheetCssRulesGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "cssRules" ); |
| 213 | } |
| 214 | |
| 215 | static 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 | |
| 224 | EncodedJSValue jsCSSStyleSheetRules(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 225 | { |
| 226 | return IDLAttribute<JSCSSStyleSheet>::get<jsCSSStyleSheetRulesGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "rules" ); |
| 227 | } |
| 228 | |
| 229 | static 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 | |
| 243 | EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionInsertRule(ExecState* state) |
| 244 | { |
| 245 | return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionInsertRuleBody>(*state, "insertRule" ); |
| 246 | } |
| 247 | |
| 248 | static 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 | |
| 261 | EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionDeleteRule(ExecState* state) |
| 262 | { |
| 263 | return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionDeleteRuleBody>(*state, "deleteRule" ); |
| 264 | } |
| 265 | |
| 266 | static 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 | |
| 280 | EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionAddRule(ExecState* state) |
| 281 | { |
| 282 | return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionAddRuleBody>(*state, "addRule" ); |
| 283 | } |
| 284 | |
| 285 | static 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 | |
| 296 | EncodedJSValue JSC_HOST_CALL jsCSSStyleSheetPrototypeFunctionRemoveRule(ExecState* state) |
| 297 | { |
| 298 | return IDLOperation<JSCSSStyleSheet>::call<jsCSSStyleSheetPrototypeFunctionRemoveRuleBody>(*state, "removeRule" ); |
| 299 | } |
| 300 | |
| 301 | void 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 | |