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