| 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 "JSXMLSerializer.h" |
| 23 | |
| 24 | #include "JSDOMBinding.h" |
| 25 | #include "JSDOMConstructor.h" |
| 26 | #include "JSDOMConvertInterface.h" |
| 27 | #include "JSDOMConvertStrings.h" |
| 28 | #include "JSDOMExceptionHandling.h" |
| 29 | #include "JSDOMOperation.h" |
| 30 | #include "JSDOMWrapperCache.h" |
| 31 | #include "JSNode.h" |
| 32 | #include "ScriptExecutionContext.h" |
| 33 | #include <JavaScriptCore/FunctionPrototype.h> |
| 34 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 35 | #include <JavaScriptCore/JSCInlines.h> |
| 36 | #include <wtf/GetPtr.h> |
| 37 | #include <wtf/PointerPreparations.h> |
| 38 | #include <wtf/URL.h> |
| 39 | |
| 40 | |
| 41 | namespace WebCore { |
| 42 | using namespace JSC; |
| 43 | |
| 44 | // Functions |
| 45 | |
| 46 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLSerializerPrototypeFunctionSerializeToString(JSC::ExecState*); |
| 47 | |
| 48 | // Attributes |
| 49 | |
| 50 | JSC::EncodedJSValue jsXMLSerializerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 51 | bool setJSXMLSerializerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 52 | |
| 53 | class JSXMLSerializerPrototype : public JSC::JSNonFinalObject { |
| 54 | public: |
| 55 | using Base = JSC::JSNonFinalObject; |
| 56 | static JSXMLSerializerPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 57 | { |
| 58 | JSXMLSerializerPrototype* ptr = new (NotNull, JSC::allocateCell<JSXMLSerializerPrototype>(vm.heap)) JSXMLSerializerPrototype(vm, globalObject, structure); |
| 59 | ptr->finishCreation(vm); |
| 60 | return ptr; |
| 61 | } |
| 62 | |
| 63 | DECLARE_INFO; |
| 64 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 65 | { |
| 66 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | JSXMLSerializerPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 71 | : JSC::JSNonFinalObject(vm, structure) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | void finishCreation(JSC::VM&); |
| 76 | }; |
| 77 | |
| 78 | using JSXMLSerializerConstructor = JSDOMConstructor<JSXMLSerializer>; |
| 79 | |
| 80 | template<> EncodedJSValue JSC_HOST_CALL JSXMLSerializerConstructor::construct(ExecState* state) |
| 81 | { |
| 82 | VM& vm = state->vm(); |
| 83 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 84 | UNUSED_PARAM(throwScope); |
| 85 | auto* castedThis = jsCast<JSXMLSerializerConstructor*>(state->jsCallee()); |
| 86 | ASSERT(castedThis); |
| 87 | auto object = XMLSerializer::create(); |
| 88 | return JSValue::encode(toJSNewlyCreated<IDLInterface<XMLSerializer>>(*state, *castedThis->globalObject(), WTFMove(object))); |
| 89 | } |
| 90 | |
| 91 | template<> JSValue JSXMLSerializerConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 92 | { |
| 93 | UNUSED_PARAM(vm); |
| 94 | return globalObject.functionPrototype(); |
| 95 | } |
| 96 | |
| 97 | template<> void JSXMLSerializerConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 98 | { |
| 99 | putDirect(vm, vm.propertyNames->prototype, JSXMLSerializer::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 100 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("XMLSerializer"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 101 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 102 | } |
| 103 | |
| 104 | template<> const ClassInfo JSXMLSerializerConstructor::s_info = { "XMLSerializer" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSXMLSerializerConstructor) }; |
| 105 | |
| 106 | /* Hash table for prototype */ |
| 107 | |
| 108 | static const HashTableValue JSXMLSerializerPrototypeTableValues[] = |
| 109 | { |
| 110 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLSerializerConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLSerializerConstructor) } }, |
| 111 | { "serializeToString" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLSerializerPrototypeFunctionSerializeToString), (intptr_t) (1) } }, |
| 112 | }; |
| 113 | |
| 114 | const ClassInfo JSXMLSerializerPrototype::s_info = { "XMLSerializerPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSXMLSerializerPrototype) }; |
| 115 | |
| 116 | void JSXMLSerializerPrototype::finishCreation(VM& vm) |
| 117 | { |
| 118 | Base::finishCreation(vm); |
| 119 | reifyStaticProperties(vm, JSXMLSerializer::info(), JSXMLSerializerPrototypeTableValues, *this); |
| 120 | } |
| 121 | |
| 122 | const ClassInfo JSXMLSerializer::s_info = { "XMLSerializer" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSXMLSerializer) }; |
| 123 | |
| 124 | JSXMLSerializer::JSXMLSerializer(Structure* structure, JSDOMGlobalObject& globalObject, Ref<XMLSerializer>&& impl) |
| 125 | : JSDOMWrapper<XMLSerializer>(structure, globalObject, WTFMove(impl)) |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | void JSXMLSerializer::finishCreation(VM& vm) |
| 130 | { |
| 131 | Base::finishCreation(vm); |
| 132 | ASSERT(inherits(vm, info())); |
| 133 | |
| 134 | } |
| 135 | |
| 136 | JSObject* JSXMLSerializer::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 137 | { |
| 138 | return JSXMLSerializerPrototype::create(vm, &globalObject, JSXMLSerializerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 139 | } |
| 140 | |
| 141 | JSObject* JSXMLSerializer::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 142 | { |
| 143 | return getDOMPrototype<JSXMLSerializer>(vm, globalObject); |
| 144 | } |
| 145 | |
| 146 | JSValue JSXMLSerializer::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 147 | { |
| 148 | return getDOMConstructor<JSXMLSerializerConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 149 | } |
| 150 | |
| 151 | void JSXMLSerializer::destroy(JSC::JSCell* cell) |
| 152 | { |
| 153 | JSXMLSerializer* thisObject = static_cast<JSXMLSerializer*>(cell); |
| 154 | thisObject->JSXMLSerializer::~JSXMLSerializer(); |
| 155 | } |
| 156 | |
| 157 | template<> inline JSXMLSerializer* IDLOperation<JSXMLSerializer>::cast(ExecState& state) |
| 158 | { |
| 159 | return jsDynamicCast<JSXMLSerializer*>(state.vm(), state.thisValue()); |
| 160 | } |
| 161 | |
| 162 | EncodedJSValue jsXMLSerializerConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 163 | { |
| 164 | VM& vm = state->vm(); |
| 165 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 166 | auto* prototype = jsDynamicCast<JSXMLSerializerPrototype*>(vm, JSValue::decode(thisValue)); |
| 167 | if (UNLIKELY(!prototype)) |
| 168 | return throwVMTypeError(state, throwScope); |
| 169 | return JSValue::encode(JSXMLSerializer::getConstructor(state->vm(), prototype->globalObject())); |
| 170 | } |
| 171 | |
| 172 | bool setJSXMLSerializerConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 173 | { |
| 174 | VM& vm = state->vm(); |
| 175 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 176 | auto* prototype = jsDynamicCast<JSXMLSerializerPrototype*>(vm, JSValue::decode(thisValue)); |
| 177 | if (UNLIKELY(!prototype)) { |
| 178 | throwVMTypeError(state, throwScope); |
| 179 | return false; |
| 180 | } |
| 181 | // Shadowing a built-in constructor |
| 182 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 183 | } |
| 184 | |
| 185 | static inline JSC::EncodedJSValue jsXMLSerializerPrototypeFunctionSerializeToStringBody(JSC::ExecState* state, typename IDLOperation<JSXMLSerializer>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 186 | { |
| 187 | UNUSED_PARAM(state); |
| 188 | UNUSED_PARAM(throwScope); |
| 189 | auto& impl = castedThis->wrapped(); |
| 190 | if (UNLIKELY(state->argumentCount() < 1)) |
| 191 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 192 | auto node = convert<IDLInterface<Node>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "node" , "XMLSerializer" , "serializeToString" , "Node" ); }); |
| 193 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 194 | return JSValue::encode(toJS<IDLDOMString>(*state, impl.serializeToString(*node))); |
| 195 | } |
| 196 | |
| 197 | EncodedJSValue JSC_HOST_CALL jsXMLSerializerPrototypeFunctionSerializeToString(ExecState* state) |
| 198 | { |
| 199 | return IDLOperation<JSXMLSerializer>::call<jsXMLSerializerPrototypeFunctionSerializeToStringBody>(*state, "serializeToString" ); |
| 200 | } |
| 201 | |
| 202 | void JSXMLSerializer::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 203 | { |
| 204 | auto* thisObject = jsCast<JSXMLSerializer*>(cell); |
| 205 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 206 | if (thisObject->scriptExecutionContext()) |
| 207 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 208 | Base::heapSnapshot(cell, builder); |
| 209 | } |
| 210 | |
| 211 | bool JSXMLSerializerOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 212 | { |
| 213 | UNUSED_PARAM(handle); |
| 214 | UNUSED_PARAM(visitor); |
| 215 | UNUSED_PARAM(reason); |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | void JSXMLSerializerOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 220 | { |
| 221 | auto* jsXMLSerializer = static_cast<JSXMLSerializer*>(handle.slot()->asCell()); |
| 222 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 223 | uncacheWrapper(world, &jsXMLSerializer->wrapped(), jsXMLSerializer); |
| 224 | } |
| 225 | |
| 226 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<XMLSerializer>&& impl) |
| 227 | { |
| 228 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
| 229 | // attribute. You should remove that attribute. If the class has subclasses |
| 230 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
| 231 | // attribute to XMLSerializer. |
| 232 | static_assert(!std::is_polymorphic<XMLSerializer>::value, "XMLSerializer is polymorphic but the IDL claims it is not" ); |
| 233 | return createWrapper<XMLSerializer>(globalObject, WTFMove(impl)); |
| 234 | } |
| 235 | |
| 236 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, XMLSerializer& impl) |
| 237 | { |
| 238 | return wrap(state, globalObject, impl); |
| 239 | } |
| 240 | |
| 241 | XMLSerializer* JSXMLSerializer::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 242 | { |
| 243 | if (auto* wrapper = jsDynamicCast<JSXMLSerializer*>(vm, value)) |
| 244 | return &wrapper->wrapped(); |
| 245 | return nullptr; |
| 246 | } |
| 247 | |
| 248 | } |
| 249 | |