| 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 "JSProgressEvent.h" |
| 23 | |
| 24 | #include "JSDOMAttribute.h" |
| 25 | #include "JSDOMBinding.h" |
| 26 | #include "JSDOMConstructor.h" |
| 27 | #include "JSDOMConvertBoolean.h" |
| 28 | #include "JSDOMConvertInterface.h" |
| 29 | #include "JSDOMConvertNumbers.h" |
| 30 | #include "JSDOMConvertStrings.h" |
| 31 | #include "JSDOMExceptionHandling.h" |
| 32 | #include "JSDOMWrapperCache.h" |
| 33 | #include "ScriptExecutionContext.h" |
| 34 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 35 | #include <JavaScriptCore/JSCInlines.h> |
| 36 | #include <wtf/GetPtr.h> |
| 37 | #include <wtf/PointerPreparations.h> |
| 38 | #include <wtf/URL.h> |
| 39 | |
| 40 | |
| 41 | namespace WebCore { |
| 42 | using namespace JSC; |
| 43 | |
| 44 | template<> ProgressEvent::Init convertDictionary<ProgressEvent::Init>(ExecState& state, JSValue value) |
| 45 | { |
| 46 | VM& vm = state.vm(); |
| 47 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 48 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 49 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 50 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 51 | throwTypeError(&state, throwScope); |
| 52 | return { }; |
| 53 | } |
| 54 | ProgressEvent::Init result; |
| 55 | JSValue bubblesValue; |
| 56 | if (isNullOrUndefined) |
| 57 | bubblesValue = jsUndefined(); |
| 58 | else { |
| 59 | bubblesValue = object->get(&state, Identifier::fromString(&state, "bubbles" )); |
| 60 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 61 | } |
| 62 | if (!bubblesValue.isUndefined()) { |
| 63 | result.bubbles = convert<IDLBoolean>(state, bubblesValue); |
| 64 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 65 | } else |
| 66 | result.bubbles = false; |
| 67 | JSValue cancelableValue; |
| 68 | if (isNullOrUndefined) |
| 69 | cancelableValue = jsUndefined(); |
| 70 | else { |
| 71 | cancelableValue = object->get(&state, Identifier::fromString(&state, "cancelable" )); |
| 72 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 73 | } |
| 74 | if (!cancelableValue.isUndefined()) { |
| 75 | result.cancelable = convert<IDLBoolean>(state, cancelableValue); |
| 76 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 77 | } else |
| 78 | result.cancelable = false; |
| 79 | JSValue composedValue; |
| 80 | if (isNullOrUndefined) |
| 81 | composedValue = jsUndefined(); |
| 82 | else { |
| 83 | composedValue = object->get(&state, Identifier::fromString(&state, "composed" )); |
| 84 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 85 | } |
| 86 | if (!composedValue.isUndefined()) { |
| 87 | result.composed = convert<IDLBoolean>(state, composedValue); |
| 88 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 89 | } else |
| 90 | result.composed = false; |
| 91 | JSValue lengthComputableValue; |
| 92 | if (isNullOrUndefined) |
| 93 | lengthComputableValue = jsUndefined(); |
| 94 | else { |
| 95 | lengthComputableValue = object->get(&state, Identifier::fromString(&state, "lengthComputable" )); |
| 96 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 97 | } |
| 98 | if (!lengthComputableValue.isUndefined()) { |
| 99 | result.lengthComputable = convert<IDLBoolean>(state, lengthComputableValue); |
| 100 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 101 | } else |
| 102 | result.lengthComputable = false; |
| 103 | JSValue loadedValue; |
| 104 | if (isNullOrUndefined) |
| 105 | loadedValue = jsUndefined(); |
| 106 | else { |
| 107 | loadedValue = object->get(&state, Identifier::fromString(&state, "loaded" )); |
| 108 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 109 | } |
| 110 | if (!loadedValue.isUndefined()) { |
| 111 | result.loaded = convert<IDLUnsignedLongLong>(state, loadedValue); |
| 112 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 113 | } else |
| 114 | result.loaded = 0; |
| 115 | JSValue totalValue; |
| 116 | if (isNullOrUndefined) |
| 117 | totalValue = jsUndefined(); |
| 118 | else { |
| 119 | totalValue = object->get(&state, Identifier::fromString(&state, "total" )); |
| 120 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 121 | } |
| 122 | if (!totalValue.isUndefined()) { |
| 123 | result.total = convert<IDLUnsignedLongLong>(state, totalValue); |
| 124 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 125 | } else |
| 126 | result.total = 0; |
| 127 | return result; |
| 128 | } |
| 129 | |
| 130 | // Attributes |
| 131 | |
| 132 | JSC::EncodedJSValue jsProgressEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 133 | bool setJSProgressEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 134 | JSC::EncodedJSValue jsProgressEventLengthComputable(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 135 | JSC::EncodedJSValue jsProgressEventLoaded(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 136 | JSC::EncodedJSValue jsProgressEventTotal(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 137 | |
| 138 | class JSProgressEventPrototype : public JSC::JSNonFinalObject { |
| 139 | public: |
| 140 | using Base = JSC::JSNonFinalObject; |
| 141 | static JSProgressEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 142 | { |
| 143 | JSProgressEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSProgressEventPrototype>(vm.heap)) JSProgressEventPrototype(vm, globalObject, structure); |
| 144 | ptr->finishCreation(vm); |
| 145 | return ptr; |
| 146 | } |
| 147 | |
| 148 | DECLARE_INFO; |
| 149 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 150 | { |
| 151 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 152 | } |
| 153 | |
| 154 | private: |
| 155 | JSProgressEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 156 | : JSC::JSNonFinalObject(vm, structure) |
| 157 | { |
| 158 | } |
| 159 | |
| 160 | void finishCreation(JSC::VM&); |
| 161 | }; |
| 162 | |
| 163 | using JSProgressEventConstructor = JSDOMConstructor<JSProgressEvent>; |
| 164 | |
| 165 | template<> EncodedJSValue JSC_HOST_CALL JSProgressEventConstructor::construct(ExecState* state) |
| 166 | { |
| 167 | VM& vm = state->vm(); |
| 168 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 169 | UNUSED_PARAM(throwScope); |
| 170 | auto* castedThis = jsCast<JSProgressEventConstructor*>(state->jsCallee()); |
| 171 | ASSERT(castedThis); |
| 172 | if (UNLIKELY(state->argumentCount() < 1)) |
| 173 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 174 | auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 175 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 176 | auto eventInitDict = convert<IDLDictionary<ProgressEvent::Init>>(*state, state->argument(1)); |
| 177 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 178 | auto object = ProgressEvent::create(WTFMove(type), WTFMove(eventInitDict)); |
| 179 | return JSValue::encode(toJSNewlyCreated<IDLInterface<ProgressEvent>>(*state, *castedThis->globalObject(), WTFMove(object))); |
| 180 | } |
| 181 | |
| 182 | template<> JSValue JSProgressEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 183 | { |
| 184 | return JSEvent::getConstructor(vm, &globalObject); |
| 185 | } |
| 186 | |
| 187 | template<> void JSProgressEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 188 | { |
| 189 | putDirect(vm, vm.propertyNames->prototype, JSProgressEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 190 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("ProgressEvent"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 191 | putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 192 | } |
| 193 | |
| 194 | template<> const ClassInfo JSProgressEventConstructor::s_info = { "ProgressEvent" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSProgressEventConstructor) }; |
| 195 | |
| 196 | /* Hash table for prototype */ |
| 197 | |
| 198 | static const HashTableValue JSProgressEventPrototypeTableValues[] = |
| 199 | { |
| 200 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsProgressEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSProgressEventConstructor) } }, |
| 201 | { "lengthComputable" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsProgressEventLengthComputable), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 202 | { "loaded" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsProgressEventLoaded), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 203 | { "total" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsProgressEventTotal), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 204 | }; |
| 205 | |
| 206 | const ClassInfo JSProgressEventPrototype::s_info = { "ProgressEventPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSProgressEventPrototype) }; |
| 207 | |
| 208 | void JSProgressEventPrototype::finishCreation(VM& vm) |
| 209 | { |
| 210 | Base::finishCreation(vm); |
| 211 | reifyStaticProperties(vm, JSProgressEvent::info(), JSProgressEventPrototypeTableValues, *this); |
| 212 | } |
| 213 | |
| 214 | const ClassInfo JSProgressEvent::s_info = { "ProgressEvent" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSProgressEvent) }; |
| 215 | |
| 216 | JSProgressEvent::JSProgressEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ProgressEvent>&& impl) |
| 217 | : JSEvent(structure, globalObject, WTFMove(impl)) |
| 218 | { |
| 219 | } |
| 220 | |
| 221 | void JSProgressEvent::finishCreation(VM& vm) |
| 222 | { |
| 223 | Base::finishCreation(vm); |
| 224 | ASSERT(inherits(vm, info())); |
| 225 | |
| 226 | } |
| 227 | |
| 228 | JSObject* JSProgressEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 229 | { |
| 230 | return JSProgressEventPrototype::create(vm, &globalObject, JSProgressEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject))); |
| 231 | } |
| 232 | |
| 233 | JSObject* JSProgressEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 234 | { |
| 235 | return getDOMPrototype<JSProgressEvent>(vm, globalObject); |
| 236 | } |
| 237 | |
| 238 | JSValue JSProgressEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 239 | { |
| 240 | return getDOMConstructor<JSProgressEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 241 | } |
| 242 | |
| 243 | template<> inline JSProgressEvent* IDLAttribute<JSProgressEvent>::cast(ExecState& state, EncodedJSValue thisValue) |
| 244 | { |
| 245 | return jsDynamicCast<JSProgressEvent*>(state.vm(), JSValue::decode(thisValue)); |
| 246 | } |
| 247 | |
| 248 | EncodedJSValue jsProgressEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 249 | { |
| 250 | VM& vm = state->vm(); |
| 251 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 252 | auto* prototype = jsDynamicCast<JSProgressEventPrototype*>(vm, JSValue::decode(thisValue)); |
| 253 | if (UNLIKELY(!prototype)) |
| 254 | return throwVMTypeError(state, throwScope); |
| 255 | return JSValue::encode(JSProgressEvent::getConstructor(state->vm(), prototype->globalObject())); |
| 256 | } |
| 257 | |
| 258 | bool setJSProgressEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 259 | { |
| 260 | VM& vm = state->vm(); |
| 261 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 262 | auto* prototype = jsDynamicCast<JSProgressEventPrototype*>(vm, JSValue::decode(thisValue)); |
| 263 | if (UNLIKELY(!prototype)) { |
| 264 | throwVMTypeError(state, throwScope); |
| 265 | return false; |
| 266 | } |
| 267 | // Shadowing a built-in constructor |
| 268 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 269 | } |
| 270 | |
| 271 | static inline JSValue jsProgressEventLengthComputableGetter(ExecState& state, JSProgressEvent& thisObject, ThrowScope& throwScope) |
| 272 | { |
| 273 | UNUSED_PARAM(throwScope); |
| 274 | UNUSED_PARAM(state); |
| 275 | auto& impl = thisObject.wrapped(); |
| 276 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.lengthComputable()); |
| 277 | return result; |
| 278 | } |
| 279 | |
| 280 | EncodedJSValue jsProgressEventLengthComputable(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 281 | { |
| 282 | return IDLAttribute<JSProgressEvent>::get<jsProgressEventLengthComputableGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "lengthComputable" ); |
| 283 | } |
| 284 | |
| 285 | static inline JSValue jsProgressEventLoadedGetter(ExecState& state, JSProgressEvent& thisObject, ThrowScope& throwScope) |
| 286 | { |
| 287 | UNUSED_PARAM(throwScope); |
| 288 | UNUSED_PARAM(state); |
| 289 | auto& impl = thisObject.wrapped(); |
| 290 | JSValue result = toJS<IDLUnsignedLongLong>(state, throwScope, impl.loaded()); |
| 291 | return result; |
| 292 | } |
| 293 | |
| 294 | EncodedJSValue jsProgressEventLoaded(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 295 | { |
| 296 | return IDLAttribute<JSProgressEvent>::get<jsProgressEventLoadedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "loaded" ); |
| 297 | } |
| 298 | |
| 299 | static inline JSValue jsProgressEventTotalGetter(ExecState& state, JSProgressEvent& thisObject, ThrowScope& throwScope) |
| 300 | { |
| 301 | UNUSED_PARAM(throwScope); |
| 302 | UNUSED_PARAM(state); |
| 303 | auto& impl = thisObject.wrapped(); |
| 304 | JSValue result = toJS<IDLUnsignedLongLong>(state, throwScope, impl.total()); |
| 305 | return result; |
| 306 | } |
| 307 | |
| 308 | EncodedJSValue jsProgressEventTotal(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 309 | { |
| 310 | return IDLAttribute<JSProgressEvent>::get<jsProgressEventTotalGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "total" ); |
| 311 | } |
| 312 | |
| 313 | void JSProgressEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 314 | { |
| 315 | auto* thisObject = jsCast<JSProgressEvent*>(cell); |
| 316 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 317 | if (thisObject->scriptExecutionContext()) |
| 318 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 319 | Base::heapSnapshot(cell, builder); |
| 320 | } |
| 321 | |
| 322 | #if ENABLE(BINDING_INTEGRITY) |
| 323 | #if PLATFORM(WIN) |
| 324 | #pragma warning(disable: 4483) |
| 325 | extern "C" { extern void (*const __identifier("??_7ProgressEvent@WebCore@@6B@" )[])(); } |
| 326 | #else |
| 327 | extern "C" { extern void* _ZTVN7WebCore13ProgressEventE[]; } |
| 328 | #endif |
| 329 | #endif |
| 330 | |
| 331 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ProgressEvent>&& impl) |
| 332 | { |
| 333 | |
| 334 | #if ENABLE(BINDING_INTEGRITY) |
| 335 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| 336 | #if PLATFORM(WIN) |
| 337 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7ProgressEvent@WebCore@@6B@" )); |
| 338 | #else |
| 339 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore13ProgressEventE[2]); |
| 340 | #endif |
| 341 | |
| 342 | // If this fails ProgressEvent does not have a vtable, so you need to add the |
| 343 | // ImplementationLacksVTable attribute to the interface definition |
| 344 | static_assert(std::is_polymorphic<ProgressEvent>::value, "ProgressEvent is not polymorphic" ); |
| 345 | |
| 346 | // If you hit this assertion you either have a use after free bug, or |
| 347 | // ProgressEvent has subclasses. If ProgressEvent has subclasses that get passed |
| 348 | // to toJS() we currently require ProgressEvent you to opt out of binding hardening |
| 349 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
| 350 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| 351 | #endif |
| 352 | return createWrapper<ProgressEvent>(globalObject, WTFMove(impl)); |
| 353 | } |
| 354 | |
| 355 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ProgressEvent& impl) |
| 356 | { |
| 357 | return wrap(state, globalObject, impl); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | } |
| 362 | |