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