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