| 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 "JSTextDecoder.h" |
| 23 | |
| 24 | #include "JSDOMAttribute.h" |
| 25 | #include "JSDOMBinding.h" |
| 26 | #include "JSDOMConstructor.h" |
| 27 | #include "JSDOMConvertBoolean.h" |
| 28 | #include "JSDOMConvertBufferSource.h" |
| 29 | #include "JSDOMConvertInterface.h" |
| 30 | #include "JSDOMConvertNullable.h" |
| 31 | #include "JSDOMConvertStrings.h" |
| 32 | #include "JSDOMConvertUnion.h" |
| 33 | #include "JSDOMExceptionHandling.h" |
| 34 | #include "JSDOMOperation.h" |
| 35 | #include "JSDOMWrapperCache.h" |
| 36 | #include "ScriptExecutionContext.h" |
| 37 | #include <JavaScriptCore/FunctionPrototype.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 | #include <wtf/Variant.h> |
| 44 | |
| 45 | |
| 46 | namespace WebCore { |
| 47 | using namespace JSC; |
| 48 | |
| 49 | template<> TextDecoder::Options convertDictionary<TextDecoder::Options>(ExecState& state, JSValue value) |
| 50 | { |
| 51 | VM& vm = state.vm(); |
| 52 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 53 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 54 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 55 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 56 | throwTypeError(&state, throwScope); |
| 57 | return { }; |
| 58 | } |
| 59 | TextDecoder::Options result; |
| 60 | JSValue fatalValue; |
| 61 | if (isNullOrUndefined) |
| 62 | fatalValue = jsUndefined(); |
| 63 | else { |
| 64 | fatalValue = object->get(&state, Identifier::fromString(&state, "fatal" )); |
| 65 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 66 | } |
| 67 | if (!fatalValue.isUndefined()) { |
| 68 | result.fatal = convert<IDLBoolean>(state, fatalValue); |
| 69 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 70 | } else |
| 71 | result.fatal = false; |
| 72 | JSValue ignoreBOMValue; |
| 73 | if (isNullOrUndefined) |
| 74 | ignoreBOMValue = jsUndefined(); |
| 75 | else { |
| 76 | ignoreBOMValue = object->get(&state, Identifier::fromString(&state, "ignoreBOM" )); |
| 77 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 78 | } |
| 79 | if (!ignoreBOMValue.isUndefined()) { |
| 80 | result.ignoreBOM = convert<IDLBoolean>(state, ignoreBOMValue); |
| 81 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 82 | } else |
| 83 | result.ignoreBOM = false; |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | template<> TextDecoder::DecodeOptions convertDictionary<TextDecoder::DecodeOptions>(ExecState& state, JSValue value) |
| 88 | { |
| 89 | VM& vm = state.vm(); |
| 90 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 91 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 92 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 93 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 94 | throwTypeError(&state, throwScope); |
| 95 | return { }; |
| 96 | } |
| 97 | TextDecoder::DecodeOptions result; |
| 98 | JSValue streamValue; |
| 99 | if (isNullOrUndefined) |
| 100 | streamValue = jsUndefined(); |
| 101 | else { |
| 102 | streamValue = object->get(&state, Identifier::fromString(&state, "stream" )); |
| 103 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 104 | } |
| 105 | if (!streamValue.isUndefined()) { |
| 106 | result.stream = convert<IDLBoolean>(state, streamValue); |
| 107 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 108 | } else |
| 109 | result.stream = false; |
| 110 | return result; |
| 111 | } |
| 112 | |
| 113 | // Functions |
| 114 | |
| 115 | JSC::EncodedJSValue JSC_HOST_CALL jsTextDecoderPrototypeFunctionDecode(JSC::ExecState*); |
| 116 | |
| 117 | // Attributes |
| 118 | |
| 119 | JSC::EncodedJSValue jsTextDecoderConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 120 | bool setJSTextDecoderConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 121 | JSC::EncodedJSValue jsTextDecoderEncoding(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 122 | JSC::EncodedJSValue jsTextDecoderFatal(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 123 | JSC::EncodedJSValue jsTextDecoderIgnoreBOM(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 124 | |
| 125 | class JSTextDecoderPrototype : public JSC::JSNonFinalObject { |
| 126 | public: |
| 127 | using Base = JSC::JSNonFinalObject; |
| 128 | static JSTextDecoderPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 129 | { |
| 130 | JSTextDecoderPrototype* ptr = new (NotNull, JSC::allocateCell<JSTextDecoderPrototype>(vm.heap)) JSTextDecoderPrototype(vm, globalObject, structure); |
| 131 | ptr->finishCreation(vm); |
| 132 | return ptr; |
| 133 | } |
| 134 | |
| 135 | DECLARE_INFO; |
| 136 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 137 | { |
| 138 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 139 | } |
| 140 | |
| 141 | private: |
| 142 | JSTextDecoderPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 143 | : JSC::JSNonFinalObject(vm, structure) |
| 144 | { |
| 145 | } |
| 146 | |
| 147 | void finishCreation(JSC::VM&); |
| 148 | }; |
| 149 | |
| 150 | using JSTextDecoderConstructor = JSDOMConstructor<JSTextDecoder>; |
| 151 | |
| 152 | template<> EncodedJSValue JSC_HOST_CALL JSTextDecoderConstructor::construct(ExecState* state) |
| 153 | { |
| 154 | VM& vm = state->vm(); |
| 155 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 156 | UNUSED_PARAM(throwScope); |
| 157 | auto* castedThis = jsCast<JSTextDecoderConstructor*>(state->jsCallee()); |
| 158 | ASSERT(castedThis); |
| 159 | auto label = state->argument(0).isUndefined() ? "utf-8"_s : convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 160 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 161 | auto options = convert<IDLDictionary<TextDecoder::Options>>(*state, state->argument(1)); |
| 162 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 163 | auto object = TextDecoder::create(WTFMove(label), WTFMove(options)); |
| 164 | return JSValue::encode(toJSNewlyCreated<IDLInterface<TextDecoder>>(*state, *castedThis->globalObject(), throwScope, WTFMove(object))); |
| 165 | } |
| 166 | |
| 167 | template<> JSValue JSTextDecoderConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 168 | { |
| 169 | UNUSED_PARAM(vm); |
| 170 | return globalObject.functionPrototype(); |
| 171 | } |
| 172 | |
| 173 | template<> void JSTextDecoderConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 174 | { |
| 175 | putDirect(vm, vm.propertyNames->prototype, JSTextDecoder::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 176 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TextDecoder"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 177 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 178 | } |
| 179 | |
| 180 | template<> const ClassInfo JSTextDecoderConstructor::s_info = { "TextDecoder" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextDecoderConstructor) }; |
| 181 | |
| 182 | /* Hash table for prototype */ |
| 183 | |
| 184 | static const HashTableValue JSTextDecoderPrototypeTableValues[] = |
| 185 | { |
| 186 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextDecoderConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTextDecoderConstructor) } }, |
| 187 | { "encoding" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextDecoderEncoding), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 188 | { "fatal" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextDecoderFatal), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 189 | { "ignoreBOM" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextDecoderIgnoreBOM), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 190 | { "decode" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTextDecoderPrototypeFunctionDecode), (intptr_t) (0) } }, |
| 191 | }; |
| 192 | |
| 193 | const ClassInfo JSTextDecoderPrototype::s_info = { "TextDecoderPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextDecoderPrototype) }; |
| 194 | |
| 195 | void JSTextDecoderPrototype::finishCreation(VM& vm) |
| 196 | { |
| 197 | Base::finishCreation(vm); |
| 198 | reifyStaticProperties(vm, JSTextDecoder::info(), JSTextDecoderPrototypeTableValues, *this); |
| 199 | } |
| 200 | |
| 201 | const ClassInfo JSTextDecoder::s_info = { "TextDecoder" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextDecoder) }; |
| 202 | |
| 203 | JSTextDecoder::JSTextDecoder(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TextDecoder>&& impl) |
| 204 | : JSDOMWrapper<TextDecoder>(structure, globalObject, WTFMove(impl)) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | void JSTextDecoder::finishCreation(VM& vm) |
| 209 | { |
| 210 | Base::finishCreation(vm); |
| 211 | ASSERT(inherits(vm, info())); |
| 212 | |
| 213 | } |
| 214 | |
| 215 | JSObject* JSTextDecoder::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 216 | { |
| 217 | return JSTextDecoderPrototype::create(vm, &globalObject, JSTextDecoderPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 218 | } |
| 219 | |
| 220 | JSObject* JSTextDecoder::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 221 | { |
| 222 | return getDOMPrototype<JSTextDecoder>(vm, globalObject); |
| 223 | } |
| 224 | |
| 225 | JSValue JSTextDecoder::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 226 | { |
| 227 | return getDOMConstructor<JSTextDecoderConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 228 | } |
| 229 | |
| 230 | void JSTextDecoder::destroy(JSC::JSCell* cell) |
| 231 | { |
| 232 | JSTextDecoder* thisObject = static_cast<JSTextDecoder*>(cell); |
| 233 | thisObject->JSTextDecoder::~JSTextDecoder(); |
| 234 | } |
| 235 | |
| 236 | template<> inline JSTextDecoder* IDLAttribute<JSTextDecoder>::cast(ExecState& state, EncodedJSValue thisValue) |
| 237 | { |
| 238 | return jsDynamicCast<JSTextDecoder*>(state.vm(), JSValue::decode(thisValue)); |
| 239 | } |
| 240 | |
| 241 | template<> inline JSTextDecoder* IDLOperation<JSTextDecoder>::cast(ExecState& state) |
| 242 | { |
| 243 | return jsDynamicCast<JSTextDecoder*>(state.vm(), state.thisValue()); |
| 244 | } |
| 245 | |
| 246 | EncodedJSValue jsTextDecoderConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 247 | { |
| 248 | VM& vm = state->vm(); |
| 249 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 250 | auto* prototype = jsDynamicCast<JSTextDecoderPrototype*>(vm, JSValue::decode(thisValue)); |
| 251 | if (UNLIKELY(!prototype)) |
| 252 | return throwVMTypeError(state, throwScope); |
| 253 | return JSValue::encode(JSTextDecoder::getConstructor(state->vm(), prototype->globalObject())); |
| 254 | } |
| 255 | |
| 256 | bool setJSTextDecoderConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 257 | { |
| 258 | VM& vm = state->vm(); |
| 259 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 260 | auto* prototype = jsDynamicCast<JSTextDecoderPrototype*>(vm, JSValue::decode(thisValue)); |
| 261 | if (UNLIKELY(!prototype)) { |
| 262 | throwVMTypeError(state, throwScope); |
| 263 | return false; |
| 264 | } |
| 265 | // Shadowing a built-in constructor |
| 266 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 267 | } |
| 268 | |
| 269 | static inline JSValue jsTextDecoderEncodingGetter(ExecState& state, JSTextDecoder& thisObject, ThrowScope& throwScope) |
| 270 | { |
| 271 | UNUSED_PARAM(throwScope); |
| 272 | UNUSED_PARAM(state); |
| 273 | auto& impl = thisObject.wrapped(); |
| 274 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.encoding()); |
| 275 | return result; |
| 276 | } |
| 277 | |
| 278 | EncodedJSValue jsTextDecoderEncoding(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 279 | { |
| 280 | return IDLAttribute<JSTextDecoder>::get<jsTextDecoderEncodingGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "encoding" ); |
| 281 | } |
| 282 | |
| 283 | static inline JSValue jsTextDecoderFatalGetter(ExecState& state, JSTextDecoder& thisObject, ThrowScope& throwScope) |
| 284 | { |
| 285 | UNUSED_PARAM(throwScope); |
| 286 | UNUSED_PARAM(state); |
| 287 | auto& impl = thisObject.wrapped(); |
| 288 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.fatal()); |
| 289 | return result; |
| 290 | } |
| 291 | |
| 292 | EncodedJSValue jsTextDecoderFatal(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 293 | { |
| 294 | return IDLAttribute<JSTextDecoder>::get<jsTextDecoderFatalGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "fatal" ); |
| 295 | } |
| 296 | |
| 297 | static inline JSValue jsTextDecoderIgnoreBOMGetter(ExecState& state, JSTextDecoder& thisObject, ThrowScope& throwScope) |
| 298 | { |
| 299 | UNUSED_PARAM(throwScope); |
| 300 | UNUSED_PARAM(state); |
| 301 | auto& impl = thisObject.wrapped(); |
| 302 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.ignoreBOM()); |
| 303 | return result; |
| 304 | } |
| 305 | |
| 306 | EncodedJSValue jsTextDecoderIgnoreBOM(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 307 | { |
| 308 | return IDLAttribute<JSTextDecoder>::get<jsTextDecoderIgnoreBOMGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ignoreBOM" ); |
| 309 | } |
| 310 | |
| 311 | static inline JSC::EncodedJSValue jsTextDecoderPrototypeFunctionDecodeBody(JSC::ExecState* state, typename IDLOperation<JSTextDecoder>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 312 | { |
| 313 | UNUSED_PARAM(state); |
| 314 | UNUSED_PARAM(throwScope); |
| 315 | auto& impl = castedThis->wrapped(); |
| 316 | auto input = state->argument(0).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>>>(*state, state->uncheckedArgument(0)); |
| 317 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 318 | auto options = convert<IDLDictionary<TextDecoder::DecodeOptions>>(*state, state->argument(1)); |
| 319 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 320 | return JSValue::encode(toJS<IDLUSVString>(*state, throwScope, impl.decode(WTFMove(input), WTFMove(options)))); |
| 321 | } |
| 322 | |
| 323 | EncodedJSValue JSC_HOST_CALL jsTextDecoderPrototypeFunctionDecode(ExecState* state) |
| 324 | { |
| 325 | return IDLOperation<JSTextDecoder>::call<jsTextDecoderPrototypeFunctionDecodeBody>(*state, "decode" ); |
| 326 | } |
| 327 | |
| 328 | void JSTextDecoder::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 329 | { |
| 330 | auto* thisObject = jsCast<JSTextDecoder*>(cell); |
| 331 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 332 | if (thisObject->scriptExecutionContext()) |
| 333 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 334 | Base::heapSnapshot(cell, builder); |
| 335 | } |
| 336 | |
| 337 | bool JSTextDecoderOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 338 | { |
| 339 | UNUSED_PARAM(handle); |
| 340 | UNUSED_PARAM(visitor); |
| 341 | UNUSED_PARAM(reason); |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | void JSTextDecoderOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 346 | { |
| 347 | auto* jsTextDecoder = static_cast<JSTextDecoder*>(handle.slot()->asCell()); |
| 348 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 349 | uncacheWrapper(world, &jsTextDecoder->wrapped(), jsTextDecoder); |
| 350 | } |
| 351 | |
| 352 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TextDecoder>&& impl) |
| 353 | { |
| 354 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
| 355 | // attribute. You should remove that attribute. If the class has subclasses |
| 356 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
| 357 | // attribute to TextDecoder. |
| 358 | static_assert(!std::is_polymorphic<TextDecoder>::value, "TextDecoder is polymorphic but the IDL claims it is not" ); |
| 359 | return createWrapper<TextDecoder>(globalObject, WTFMove(impl)); |
| 360 | } |
| 361 | |
| 362 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TextDecoder& impl) |
| 363 | { |
| 364 | return wrap(state, globalObject, impl); |
| 365 | } |
| 366 | |
| 367 | TextDecoder* JSTextDecoder::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 368 | { |
| 369 | if (auto* wrapper = jsDynamicCast<JSTextDecoder*>(vm, value)) |
| 370 | return &wrapper->wrapped(); |
| 371 | return nullptr; |
| 372 | } |
| 373 | |
| 374 | } |
| 375 | |