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