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