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