| 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(WEB_RTC) |
| 24 | |
| 25 | #include "JSRTCCertificate.h" |
| 26 | |
| 27 | #include "JSDOMAttribute.h" |
| 28 | #include "JSDOMBinding.h" |
| 29 | #include "JSDOMConstructorNotConstructable.h" |
| 30 | #include "JSDOMConvertNumbers.h" |
| 31 | #include "JSDOMConvertSequences.h" |
| 32 | #include "JSDOMConvertStrings.h" |
| 33 | #include "JSDOMExceptionHandling.h" |
| 34 | #include "JSDOMGlobalObject.h" |
| 35 | #include "JSDOMOperation.h" |
| 36 | #include "JSDOMWrapperCache.h" |
| 37 | #include "ScriptExecutionContext.h" |
| 38 | #include <JavaScriptCore/FunctionPrototype.h> |
| 39 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 40 | #include <JavaScriptCore/JSArray.h> |
| 41 | #include <JavaScriptCore/JSCInlines.h> |
| 42 | #include <JavaScriptCore/ObjectConstructor.h> |
| 43 | #include <wtf/GetPtr.h> |
| 44 | #include <wtf/PointerPreparations.h> |
| 45 | #include <wtf/URL.h> |
| 46 | |
| 47 | |
| 48 | namespace WebCore { |
| 49 | using namespace JSC; |
| 50 | |
| 51 | #if ENABLE(WEB_RTC) |
| 52 | |
| 53 | template<> RTCCertificate::DtlsFingerprint convertDictionary<RTCCertificate::DtlsFingerprint>(ExecState& state, JSValue value) |
| 54 | { |
| 55 | VM& vm = state.vm(); |
| 56 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 57 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 58 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 59 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 60 | throwTypeError(&state, throwScope); |
| 61 | return { }; |
| 62 | } |
| 63 | RTCCertificate::DtlsFingerprint result; |
| 64 | JSValue algorithmValue; |
| 65 | if (isNullOrUndefined) |
| 66 | algorithmValue = jsUndefined(); |
| 67 | else { |
| 68 | algorithmValue = object->get(&state, Identifier::fromString(&state, "algorithm" )); |
| 69 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 70 | } |
| 71 | if (!algorithmValue.isUndefined()) { |
| 72 | result.algorithm = convert<IDLDOMString>(state, algorithmValue); |
| 73 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 74 | } |
| 75 | JSValue valueValue; |
| 76 | if (isNullOrUndefined) |
| 77 | valueValue = jsUndefined(); |
| 78 | else { |
| 79 | valueValue = object->get(&state, Identifier::fromString(&state, "value" )); |
| 80 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 81 | } |
| 82 | if (!valueValue.isUndefined()) { |
| 83 | result.value = convert<IDLDOMString>(state, valueValue); |
| 84 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 85 | } |
| 86 | return result; |
| 87 | } |
| 88 | |
| 89 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const RTCCertificate::DtlsFingerprint& dictionary) |
| 90 | { |
| 91 | auto& vm = state.vm(); |
| 92 | |
| 93 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 94 | |
| 95 | if (!IDLDOMString::isNullValue(dictionary.algorithm)) { |
| 96 | auto algorithmValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.algorithm)); |
| 97 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "algorithm" ), algorithmValue); |
| 98 | } |
| 99 | if (!IDLDOMString::isNullValue(dictionary.value)) { |
| 100 | auto valueValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.value)); |
| 101 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "value" ), valueValue); |
| 102 | } |
| 103 | return result; |
| 104 | } |
| 105 | |
| 106 | #endif |
| 107 | |
| 108 | // Functions |
| 109 | |
| 110 | JSC::EncodedJSValue JSC_HOST_CALL jsRTCCertificatePrototypeFunctionGetFingerprints(JSC::ExecState*); |
| 111 | |
| 112 | // Attributes |
| 113 | |
| 114 | JSC::EncodedJSValue jsRTCCertificateConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 115 | bool setJSRTCCertificateConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 116 | JSC::EncodedJSValue jsRTCCertificateExpires(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 117 | |
| 118 | class JSRTCCertificatePrototype : public JSC::JSNonFinalObject { |
| 119 | public: |
| 120 | using Base = JSC::JSNonFinalObject; |
| 121 | static JSRTCCertificatePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 122 | { |
| 123 | JSRTCCertificatePrototype* ptr = new (NotNull, JSC::allocateCell<JSRTCCertificatePrototype>(vm.heap)) JSRTCCertificatePrototype(vm, globalObject, structure); |
| 124 | ptr->finishCreation(vm); |
| 125 | return ptr; |
| 126 | } |
| 127 | |
| 128 | DECLARE_INFO; |
| 129 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 130 | { |
| 131 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | JSRTCCertificatePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 136 | : JSC::JSNonFinalObject(vm, structure) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | void finishCreation(JSC::VM&); |
| 141 | }; |
| 142 | |
| 143 | using JSRTCCertificateConstructor = JSDOMConstructorNotConstructable<JSRTCCertificate>; |
| 144 | |
| 145 | template<> JSValue JSRTCCertificateConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 146 | { |
| 147 | UNUSED_PARAM(vm); |
| 148 | return globalObject.functionPrototype(); |
| 149 | } |
| 150 | |
| 151 | template<> void JSRTCCertificateConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 152 | { |
| 153 | putDirect(vm, vm.propertyNames->prototype, JSRTCCertificate::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 154 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("RTCCertificate"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 155 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 156 | } |
| 157 | |
| 158 | template<> const ClassInfo JSRTCCertificateConstructor::s_info = { "RTCCertificate" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSRTCCertificateConstructor) }; |
| 159 | |
| 160 | /* Hash table for prototype */ |
| 161 | |
| 162 | static const HashTableValue JSRTCCertificatePrototypeTableValues[] = |
| 163 | { |
| 164 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRTCCertificateConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSRTCCertificateConstructor) } }, |
| 165 | { "expires" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRTCCertificateExpires), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 166 | { "getFingerprints" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsRTCCertificatePrototypeFunctionGetFingerprints), (intptr_t) (0) } }, |
| 167 | }; |
| 168 | |
| 169 | const ClassInfo JSRTCCertificatePrototype::s_info = { "RTCCertificatePrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSRTCCertificatePrototype) }; |
| 170 | |
| 171 | void JSRTCCertificatePrototype::finishCreation(VM& vm) |
| 172 | { |
| 173 | Base::finishCreation(vm); |
| 174 | reifyStaticProperties(vm, JSRTCCertificate::info(), JSRTCCertificatePrototypeTableValues, *this); |
| 175 | } |
| 176 | |
| 177 | const ClassInfo JSRTCCertificate::s_info = { "RTCCertificate" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSRTCCertificate) }; |
| 178 | |
| 179 | JSRTCCertificate::JSRTCCertificate(Structure* structure, JSDOMGlobalObject& globalObject, Ref<RTCCertificate>&& impl) |
| 180 | : JSDOMWrapper<RTCCertificate>(structure, globalObject, WTFMove(impl)) |
| 181 | { |
| 182 | } |
| 183 | |
| 184 | void JSRTCCertificate::finishCreation(VM& vm) |
| 185 | { |
| 186 | Base::finishCreation(vm); |
| 187 | ASSERT(inherits(vm, info())); |
| 188 | |
| 189 | } |
| 190 | |
| 191 | JSObject* JSRTCCertificate::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 192 | { |
| 193 | return JSRTCCertificatePrototype::create(vm, &globalObject, JSRTCCertificatePrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 194 | } |
| 195 | |
| 196 | JSObject* JSRTCCertificate::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 197 | { |
| 198 | return getDOMPrototype<JSRTCCertificate>(vm, globalObject); |
| 199 | } |
| 200 | |
| 201 | JSValue JSRTCCertificate::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 202 | { |
| 203 | return getDOMConstructor<JSRTCCertificateConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 204 | } |
| 205 | |
| 206 | void JSRTCCertificate::destroy(JSC::JSCell* cell) |
| 207 | { |
| 208 | JSRTCCertificate* thisObject = static_cast<JSRTCCertificate*>(cell); |
| 209 | thisObject->JSRTCCertificate::~JSRTCCertificate(); |
| 210 | } |
| 211 | |
| 212 | template<> inline JSRTCCertificate* IDLAttribute<JSRTCCertificate>::cast(ExecState& state, EncodedJSValue thisValue) |
| 213 | { |
| 214 | return jsDynamicCast<JSRTCCertificate*>(state.vm(), JSValue::decode(thisValue)); |
| 215 | } |
| 216 | |
| 217 | template<> inline JSRTCCertificate* IDLOperation<JSRTCCertificate>::cast(ExecState& state) |
| 218 | { |
| 219 | return jsDynamicCast<JSRTCCertificate*>(state.vm(), state.thisValue()); |
| 220 | } |
| 221 | |
| 222 | EncodedJSValue jsRTCCertificateConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 223 | { |
| 224 | VM& vm = state->vm(); |
| 225 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 226 | auto* prototype = jsDynamicCast<JSRTCCertificatePrototype*>(vm, JSValue::decode(thisValue)); |
| 227 | if (UNLIKELY(!prototype)) |
| 228 | return throwVMTypeError(state, throwScope); |
| 229 | return JSValue::encode(JSRTCCertificate::getConstructor(state->vm(), prototype->globalObject())); |
| 230 | } |
| 231 | |
| 232 | bool setJSRTCCertificateConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 233 | { |
| 234 | VM& vm = state->vm(); |
| 235 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 236 | auto* prototype = jsDynamicCast<JSRTCCertificatePrototype*>(vm, JSValue::decode(thisValue)); |
| 237 | if (UNLIKELY(!prototype)) { |
| 238 | throwVMTypeError(state, throwScope); |
| 239 | return false; |
| 240 | } |
| 241 | // Shadowing a built-in constructor |
| 242 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 243 | } |
| 244 | |
| 245 | static inline JSValue jsRTCCertificateExpiresGetter(ExecState& state, JSRTCCertificate& thisObject, ThrowScope& throwScope) |
| 246 | { |
| 247 | UNUSED_PARAM(throwScope); |
| 248 | UNUSED_PARAM(state); |
| 249 | auto& impl = thisObject.wrapped(); |
| 250 | JSValue result = toJS<IDLDouble>(state, throwScope, impl.expires()); |
| 251 | return result; |
| 252 | } |
| 253 | |
| 254 | EncodedJSValue jsRTCCertificateExpires(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 255 | { |
| 256 | return IDLAttribute<JSRTCCertificate>::get<jsRTCCertificateExpiresGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "expires" ); |
| 257 | } |
| 258 | |
| 259 | static inline JSC::EncodedJSValue jsRTCCertificatePrototypeFunctionGetFingerprintsBody(JSC::ExecState* state, typename IDLOperation<JSRTCCertificate>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 260 | { |
| 261 | UNUSED_PARAM(state); |
| 262 | UNUSED_PARAM(throwScope); |
| 263 | auto& impl = castedThis->wrapped(); |
| 264 | return JSValue::encode(toJS<IDLSequence<IDLDictionary<RTCCertificate::DtlsFingerprint>>>(*state, *castedThis->globalObject(), impl.getFingerprints())); |
| 265 | } |
| 266 | |
| 267 | EncodedJSValue JSC_HOST_CALL jsRTCCertificatePrototypeFunctionGetFingerprints(ExecState* state) |
| 268 | { |
| 269 | return IDLOperation<JSRTCCertificate>::call<jsRTCCertificatePrototypeFunctionGetFingerprintsBody>(*state, "getFingerprints" ); |
| 270 | } |
| 271 | |
| 272 | void JSRTCCertificate::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 273 | { |
| 274 | auto* thisObject = jsCast<JSRTCCertificate*>(cell); |
| 275 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 276 | if (thisObject->scriptExecutionContext()) |
| 277 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 278 | Base::heapSnapshot(cell, builder); |
| 279 | } |
| 280 | |
| 281 | bool JSRTCCertificateOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 282 | { |
| 283 | UNUSED_PARAM(handle); |
| 284 | UNUSED_PARAM(visitor); |
| 285 | UNUSED_PARAM(reason); |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | void JSRTCCertificateOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 290 | { |
| 291 | auto* jsRTCCertificate = static_cast<JSRTCCertificate*>(handle.slot()->asCell()); |
| 292 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 293 | uncacheWrapper(world, &jsRTCCertificate->wrapped(), jsRTCCertificate); |
| 294 | } |
| 295 | |
| 296 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<RTCCertificate>&& impl) |
| 297 | { |
| 298 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
| 299 | // attribute. You should remove that attribute. If the class has subclasses |
| 300 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
| 301 | // attribute to RTCCertificate. |
| 302 | static_assert(!std::is_polymorphic<RTCCertificate>::value, "RTCCertificate is polymorphic but the IDL claims it is not" ); |
| 303 | return createWrapper<RTCCertificate>(globalObject, WTFMove(impl)); |
| 304 | } |
| 305 | |
| 306 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, RTCCertificate& impl) |
| 307 | { |
| 308 | return wrap(state, globalObject, impl); |
| 309 | } |
| 310 | |
| 311 | RTCCertificate* JSRTCCertificate::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 312 | { |
| 313 | if (auto* wrapper = jsDynamicCast<JSRTCCertificate*>(vm, value)) |
| 314 | return &wrapper->wrapped(); |
| 315 | return nullptr; |
| 316 | } |
| 317 | |
| 318 | } |
| 319 | |
| 320 | #endif // ENABLE(WEB_RTC) |
| 321 | |