| /* |
| This file is part of the WebKit open source project. |
| This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| |
| This library is free software; you can redistribute it and/or |
| modify it under the terms of the GNU Library General Public |
| License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. |
| |
| This library is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| Library General Public License for more details. |
| |
| You should have received a copy of the GNU Library General Public License |
| along with this library; see the file COPYING.LIB. If not, write to |
| the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| Boston, MA 02110-1301, USA. |
| */ |
| |
| #include "config.h" |
| #include "JSDOMURL.h" |
| |
| #include "ExceptionCode.h" |
| #include "JSBlob.h" |
| #include "JSDOMBinding.h" |
| #include "JSDOMConstructor.h" |
| #include "JSDOMURL.h" |
| #include "JSURLSearchParams.h" |
| #include "URL.h" |
| #include <runtime/Error.h> |
| #include <runtime/FunctionPrototype.h> |
| #include <runtime/JSString.h> |
| #include <wtf/GetPtr.h> |
| |
| #if ENABLE(MEDIA_SOURCE) |
| #include "DOMURLMediaSource.h" |
| #include "JSMediaSource.h" |
| #endif |
| |
| #if ENABLE(MEDIA_STREAM) |
| #include "DOMURLMediaStream.h" |
| #include "JSMediaStream.h" |
| #endif |
| |
| using namespace JSC; |
| |
| namespace WebCore { |
| |
| // Functions |
| |
| JSC::EncodedJSValue JSC_HOST_CALL jsDOMURLConstructorFunctionCreateObjectURL(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsDOMURLConstructorFunctionRevokeObjectURL(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsDOMURLPrototypeFunctionToString(JSC::ExecState*); |
| |
| // Attributes |
| |
| JSC::EncodedJSValue jsDOMURLHref(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLHref(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLOrigin(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsDOMURLProtocol(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLProtocol(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLUsername(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLUsername(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLPassword(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLPassword(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLHost(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLHost(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLHostname(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLHostname(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLPort(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLPort(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLPathname(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLPathname(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLHash(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLHash(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLSearch(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLSearch(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsDOMURLSearchParams(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsDOMURLConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSDOMURLConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| |
| class JSDOMURLPrototype : public JSC::JSNonFinalObject { |
| public: |
| typedef JSC::JSNonFinalObject Base; |
| static JSDOMURLPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) |
| { |
| JSDOMURLPrototype* ptr = new (NotNull, JSC::allocateCell<JSDOMURLPrototype>(vm.heap)) JSDOMURLPrototype(vm, globalObject, structure); |
| ptr->finishCreation(vm); |
| return ptr; |
| } |
| |
| DECLARE_INFO; |
| static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| { |
| return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| } |
| |
| private: |
| JSDOMURLPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| : JSC::JSNonFinalObject(vm, structure) |
| { |
| } |
| |
| void finishCreation(JSC::VM&); |
| }; |
| |
| typedef JSDOMConstructor<JSDOMURL> JSDOMURLConstructor; |
| |
| /* Hash table for constructor */ |
| |
| static const HashTableValue JSDOMURLConstructorTableValues[] = |
| { |
| { "createObjectURL", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsDOMURLConstructorFunctionCreateObjectURL), (intptr_t) (1) } }, |
| { "revokeObjectURL", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsDOMURLConstructorFunctionRevokeObjectURL), (intptr_t) (1) } }, |
| }; |
| |
| static inline EncodedJSValue constructJSDOMURL1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| auto* castedThis = jsCast<JSDOMURLConstructor*>(state->callee()); |
| ASSERT(castedThis); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCode ec = 0; |
| auto url = valueToUSVString(state, state->uncheckedArgument(0)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto object = DOMURL::create(WTFMove(url), ec); |
| if (UNLIKELY(ec)) { |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(JSValue()); |
| } |
| return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object))); |
| } |
| |
| static inline EncodedJSValue constructJSDOMURL2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| auto* castedThis = jsCast<JSDOMURLConstructor*>(state->callee()); |
| ASSERT(castedThis); |
| if (UNLIKELY(state->argumentCount() < 2)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCode ec = 0; |
| auto url = valueToUSVString(state, state->uncheckedArgument(0)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto base = valueToUSVString(state, state->uncheckedArgument(1)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto object = DOMURL::create(WTFMove(url), WTFMove(base), ec); |
| if (UNLIKELY(ec)) { |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(JSValue()); |
| } |
| return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object))); |
| } |
| |
| static inline EncodedJSValue constructJSDOMURL3(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| auto* castedThis = jsCast<JSDOMURLConstructor*>(state->callee()); |
| ASSERT(castedThis); |
| if (UNLIKELY(state->argumentCount() < 2)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCode ec = 0; |
| auto url = valueToUSVString(state, state->uncheckedArgument(0)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto base = JSDOMURL::toWrapped(state->uncheckedArgument(1)); |
| if (UNLIKELY(!base)) |
| return throwArgumentTypeError(*state, throwScope, 1, "base", "URL", nullptr, "DOMURL"); |
| auto object = DOMURL::create(WTFMove(url), *base, ec); |
| if (UNLIKELY(ec)) { |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(JSValue()); |
| } |
| return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object))); |
| } |
| |
| template<> EncodedJSValue JSC_HOST_CALL JSDOMURLConstructor::construct(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(2, state->argumentCount()); |
| if (argsCount == 1) { |
| return constructJSDOMURL1(state); |
| } |
| if (argsCount == 2) { |
| JSValue distinguishingArg = state->uncheckedArgument(1); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSDOMURL::info())) |
| return constructJSDOMURL3(state); |
| return constructJSDOMURL2(state); |
| } |
| return argsCount < 1 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| } |
| |
| template<> JSValue JSDOMURLConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| { |
| UNUSED_PARAM(vm); |
| return globalObject.functionPrototype(); |
| } |
| |
| template<> void JSDOMURLConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| { |
| putDirect(vm, vm.propertyNames->prototype, JSDOMURL::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("URL"))), ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum); |
| reifyStaticProperties(vm, JSDOMURLConstructorTableValues, *this); |
| } |
| |
| template<> const ClassInfo JSDOMURLConstructor::s_info = { "URL", &Base::s_info, 0, CREATE_METHOD_TABLE(JSDOMURLConstructor) }; |
| |
| /* Hash table for prototype */ |
| |
| static const HashTableValue JSDOMURLPrototypeTableValues[] = |
| { |
| { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLConstructor) } }, |
| { "href", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLHref), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLHref) } }, |
| { "origin", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLOrigin), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "protocol", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLProtocol), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLProtocol) } }, |
| { "username", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLUsername), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLUsername) } }, |
| { "password", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLPassword), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLPassword) } }, |
| { "host", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLHost), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLHost) } }, |
| { "hostname", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLHostname), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLHostname) } }, |
| { "port", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLPort), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLPort) } }, |
| { "pathname", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLPathname), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLPathname) } }, |
| { "hash", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLHash), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLHash) } }, |
| { "search", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLSearch), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMURLSearch) } }, |
| { "searchParams", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMURLSearchParams), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "toString", DontEnum | JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsDOMURLPrototypeFunctionToString), (intptr_t) (0) } }, |
| }; |
| |
| const ClassInfo JSDOMURLPrototype::s_info = { "URLPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSDOMURLPrototype) }; |
| |
| void JSDOMURLPrototype::finishCreation(VM& vm) |
| { |
| Base::finishCreation(vm); |
| reifyStaticProperties(vm, JSDOMURLPrototypeTableValues, *this); |
| } |
| |
| const ClassInfo JSDOMURL::s_info = { "URL", &Base::s_info, 0, CREATE_METHOD_TABLE(JSDOMURL) }; |
| |
| JSDOMURL::JSDOMURL(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DOMURL>&& impl) |
| : JSDOMWrapper<DOMURL>(structure, globalObject, WTFMove(impl)) |
| { |
| } |
| |
| JSObject* JSDOMURL::createPrototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return JSDOMURLPrototype::create(vm, globalObject, JSDOMURLPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); |
| } |
| |
| JSObject* JSDOMURL::prototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return getDOMPrototype<JSDOMURL>(vm, globalObject); |
| } |
| |
| void JSDOMURL::destroy(JSC::JSCell* cell) |
| { |
| JSDOMURL* thisObject = static_cast<JSDOMURL*>(cell); |
| thisObject->JSDOMURL::~JSDOMURL(); |
| } |
| |
| EncodedJSValue jsDOMURLHref(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "href"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.href()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLOrigin(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "origin"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.origin()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLProtocol(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "protocol"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.protocol()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLUsername(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "username"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.username()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLPassword(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "password"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.password()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLHost(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "host"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.host()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLHostname(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "hostname"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.hostname()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLPort(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "port"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.port()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLPathname(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "pathname"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.pathname()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLHash(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "hash"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.hash()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLSearch(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "search"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.search()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLSearchParams(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSDOMURL*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "URL", "searchParams"); |
| } |
| if (JSValue cachedValue = castedThis->m_searchParams.get()) |
| return JSValue::encode(cachedValue); |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.searchParams()); |
| castedThis->m_searchParams.set(state->vm(), castedThis, result); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsDOMURLConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSDOMURLPrototype* domObject = jsDynamicCast<JSDOMURLPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) |
| return throwVMTypeError(state, throwScope); |
| return JSValue::encode(JSDOMURL::getConstructor(state->vm(), domObject->globalObject())); |
| } |
| |
| bool setJSDOMURLConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSValue value = JSValue::decode(encodedValue); |
| JSDOMURLPrototype* domObject = jsDynamicCast<JSDOMURLPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) { |
| throwVMTypeError(state, throwScope); |
| return false; |
| } |
| // Shadowing a built-in constructor |
| return domObject->putDirect(state->vm(), state->propertyNames().constructor, value); |
| } |
| |
| bool setJSDOMURLHref(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "href"); |
| } |
| auto& impl = castedThis->wrapped(); |
| ExceptionCode ec = 0; |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setHref(WTFMove(nativeValue), ec); |
| setDOMException(state, throwScope, ec); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLProtocol(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "protocol"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setProtocol(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLUsername(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "username"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setUsername(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLPassword(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "password"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setPassword(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLHost(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "host"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setHost(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLHostname(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "hostname"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setHostname(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLPort(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "port"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setPort(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLPathname(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "pathname"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setPathname(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLHash(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "hash"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setHash(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSDOMURLSearch(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSDOMURL* castedThis = jsDynamicCast<JSDOMURL*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "URL", "search"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = valueToUSVString(state, value); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setSearch(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| JSValue JSDOMURL::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| { |
| return getDOMConstructor<JSDOMURLConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| } |
| |
| static inline EncodedJSValue jsDOMURLConstructorFunctionCreateObjectURL1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| auto blob = JSBlob::toWrapped(state->uncheckedArgument(0)); |
| if (UNLIKELY(!blob)) |
| return throwArgumentTypeError(*state, throwScope, 0, "blob", "URL", "createObjectURL", "Blob"); |
| JSValue result = jsStringWithCache(state, DOMURL::createObjectURL(*context, *blob)); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsDOMURLConstructorFunctionRevokeObjectURL(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| auto url = state->uncheckedArgument(0).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| DOMURL::revokeObjectURL(*context, WTFMove(url)); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #if ENABLE(MEDIA_SOURCE) |
| static inline EncodedJSValue jsDOMURLConstructorFunctionCreateObjectURL2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| auto source = JSMediaSource::toWrapped(state->uncheckedArgument(0)); |
| if (UNLIKELY(!source)) |
| return throwArgumentTypeError(*state, throwScope, 0, "source", "URL", "createObjectURL", "MediaSource"); |
| JSValue result = jsStringWithCache(state, WebCore::DOMURLMediaSource::createObjectURL(*context, *source)); |
| return JSValue::encode(result); |
| } |
| |
| #endif |
| |
| #if ENABLE(MEDIA_STREAM) |
| static inline EncodedJSValue jsDOMURLConstructorFunctionCreateObjectURL3(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| auto stream = JSMediaStream::toWrapped(state->uncheckedArgument(0)); |
| if (UNLIKELY(!stream)) |
| return throwArgumentTypeError(*state, throwScope, 0, "stream", "URL", "createObjectURL", "MediaStream"); |
| JSValue result = jsStringWithCache(state, WebCore::DOMURLMediaStream::createObjectURL(*context, *stream)); |
| return JSValue::encode(result); |
| } |
| |
| #endif |
| |
| EncodedJSValue JSC_HOST_CALL jsDOMURLConstructorFunctionCreateObjectURL(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(1, state->argumentCount()); |
| if (argsCount == 1) { |
| JSValue distinguishingArg = state->uncheckedArgument(0); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSBlob::info())) |
| return jsDOMURLConstructorFunctionCreateObjectURL1(state); |
| #if ENABLE(MEDIA_SOURCE) |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSMediaSource::info())) |
| return jsDOMURLConstructorFunctionCreateObjectURL2(state); |
| #endif |
| #if ENABLE(MEDIA_STREAM) |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSMediaStream::info())) |
| return jsDOMURLConstructorFunctionCreateObjectURL3(state); |
| #endif |
| } |
| return argsCount < 1 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsDOMURLPrototypeFunctionToString(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSDOMURL*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "URL", "toString"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSDOMURL::info()); |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.toString()); |
| return JSValue::encode(result); |
| } |
| |
| void JSDOMURL::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| { |
| auto* thisObject = jsCast<JSDOMURL*>(cell); |
| ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| Base::visitChildren(thisObject, visitor); |
| visitor.append(&thisObject->m_searchParams); |
| } |
| |
| bool JSDOMURLOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor) |
| { |
| UNUSED_PARAM(handle); |
| UNUSED_PARAM(visitor); |
| return false; |
| } |
| |
| void JSDOMURLOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| { |
| auto* jsDOMURL = jsCast<JSDOMURL*>(handle.slot()->asCell()); |
| auto& world = *static_cast<DOMWrapperWorld*>(context); |
| uncacheWrapper(world, &jsDOMURL->wrapped(), jsDOMURL); |
| } |
| |
| JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<DOMURL>&& impl) |
| { |
| #if COMPILER(CLANG) |
| // If you hit this failure the interface definition has the ImplementationLacksVTable |
| // attribute. You should remove that attribute. If the class has subclasses |
| // that may be passed through this toJS() function you should use the SkipVTableValidation |
| // attribute to DOMURL. |
| static_assert(!__is_polymorphic(DOMURL), "DOMURL is polymorphic but the IDL claims it is not"); |
| #endif |
| return createWrapper<DOMURL>(globalObject, WTFMove(impl)); |
| } |
| |
| JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, DOMURL& impl) |
| { |
| return wrap(state, globalObject, impl); |
| } |
| |
| DOMURL* JSDOMURL::toWrapped(JSC::JSValue value) |
| { |
| if (auto* wrapper = jsDynamicCast<JSDOMURL*>(value)) |
| return &wrapper->wrapped(); |
| return nullptr; |
| } |
| |
| } |