diff --git a/bench/snippets/url.mjs b/bench/snippets/url.mjs new file mode 100644 index 00000000000000..1cb6e7a8f1ea5c --- /dev/null +++ b/bench/snippets/url.mjs @@ -0,0 +1,19 @@ +import { bench, run } from "./runner.mjs"; + +bench(`new URL('https://example.com/')`, () => { + const url = new URL("https://example.com/"); +}); + +bench(`new URL('https://example.com')`, () => { + const url = new URL("https://example.com"); +}); + +bench(`new URL('https://www.example.com')`, () => { + const url = new URL("https://www.example.com"); +}); + +bench(`new URL('https://www.example.com/')`, () => { + const url = new URL("https://www.example.com/"); +}); + +await run(); diff --git a/src/bun.js/bindings/DOMURL.cpp b/src/bun.js/bindings/DOMURL.cpp index 9818fc6cb99a0a..638111df9dc003 100644 --- a/src/bun.js/bindings/DOMURL.cpp +++ b/src/bun.js/bindings/DOMURL.cpp @@ -23,42 +23,50 @@ * Boston, MA 02110-1301, USA. */ +#include "config.h" #include "DOMURL.h" -// #include "ActiveDOMObject.h" +#include "ActiveDOMObject.h" // #include "Blob.h" // #include "BlobURL.h" // #include "MemoryCache.h" // #include "PublicURLManager.h" // #include "ResourceRequest.h" +#include "ScriptExecutionContext.h" +// #include "SecurityOrigin.h" #include "URLSearchParams.h" -// #include +#include + +class URLRegistrable { +public: +}; + +class Blob { +public: +}; namespace WebCore { static inline String redact(const String& input) { - if (input.contains("@"_s)) + if (input.contains('@')) return ""_s; return makeString('"', input, '"'); } -inline DOMURL::DOMURL(URL&& completeURL, const URL& baseURL) - : m_baseURL(baseURL) - , m_url(WTFMove(completeURL)) +inline DOMURL::DOMURL(URL&& completeURL) + : m_url(WTFMove(completeURL)) { + ASSERT(m_url.isValid()); } -DOMURL::~DOMURL() = default; - -bool DOMURL::canParse(const String& url, const String& base) +ExceptionOr> DOMURL::create(const String& url) { - URL baseURL { base }; - if (!base.isNull() && !baseURL.isValid()) - return false; - URL completeURL { baseURL, url }; - return completeURL.isValid(); + URL completeURL { url }; + if (!completeURL.isValid()) + return Exception { TypeError, makeString(redact(url), " cannot be parsed as a URL.") }; + return adoptRef(*new DOMURL(WTFMove(completeURL))); } ExceptionOr> DOMURL::create(const String& url, const URL& base) @@ -67,7 +75,7 @@ ExceptionOr> DOMURL::create(const String& url, const URL& base) URL completeURL { base, url }; if (!completeURL.isValid()) return Exception { TypeError, makeString(redact(url), " cannot be parsed as a URL.") }; - return adoptRef(*new DOMURL(WTFMove(completeURL), base)); + return adoptRef(*new DOMURL(WTFMove(completeURL))); } ExceptionOr> DOMURL::create(const String& url, const String& base) @@ -78,9 +86,27 @@ ExceptionOr> DOMURL::create(const String& url, const String& base) return create(url, baseURL); } -ExceptionOr> DOMURL::create(const String& url, const DOMURL& base) +DOMURL::~DOMURL() = default; + +static URL parseInternal(const String& url, const String& base) +{ + URL baseURL { base }; + if (!base.isNull() && !baseURL.isValid()) + return {}; + return { baseURL, url }; +} + +RefPtr DOMURL::parse(const String& url, const String& base) { - return create(url, base.href()); + auto completeURL = parseInternal(url, base); + if (!completeURL.isValid()) + return {}; + return adoptRef(*new DOMURL(WTFMove(completeURL))); +} + +bool DOMURL::canParse(const String& url, const String& base) +{ + return parseInternal(url, base).isValid(); } ExceptionOr DOMURL::setHref(const String& url) @@ -96,26 +122,27 @@ ExceptionOr DOMURL::setHref(const String& url) return {}; } -void DOMURL::setQuery(const String& query) +String DOMURL::createObjectURL(ScriptExecutionContext& scriptExecutionContext, Blob& blob) { - m_url.setQuery(query); + UNUSED_PARAM(blob); + UNUSED_PARAM(scriptExecutionContext); + return String(); + // return createPublicURL(scriptExecutionContext, blob); } -// String DOMURL::createObjectURL(Blob& blob) -// { -// return createPublicURL(scriptExecutionContext, blob); -// } - -// String DOMURL::createPublicURL(URLRegistrable& registrable) -// { -// URL publicURL = BlobURL::createPublicURL(scriptExecutionContext.securityOrigin()); -// if (publicURL.isEmpty()) -// return String(); +String DOMURL::createPublicURL(ScriptExecutionContext& scriptExecutionContext, URLRegistrable& registrable) +{ + // URL publicURL = BlobURL::createPublicURL(scriptExecutionContext.securityOrigin()); + // if (publicURL.isEmpty()) + // return String(); -// scriptExecutionContext.publicURLManager().registerURL(publicURL, registrable); + // scriptExecutionContext.publicURLManager().registerURL(publicURL, registrable); -// return publicURL.string(); -// } + // return publicURL.string(); + UNUSED_PARAM(scriptExecutionContext); + UNUSED_PARAM(registrable); + return String(); +} URLSearchParams& DOMURL::searchParams() { @@ -124,15 +151,17 @@ URLSearchParams& DOMURL::searchParams() return *m_searchParams; } -// void DOMURL::revokeObjectURL(const String& urlString) -// { -// // URL url(URL(), urlString); -// // ResourceRequest request(url); -// // request.setDomainForCachePartition(scriptExecutionContext.domainForCachePartition()); +void DOMURL::revokeObjectURL(ScriptExecutionContext& scriptExecutionContext, const String& urlString) +{ + // URL url { urlString }; + // ResourceRequest request(url); + // request.setDomainForCachePartition(scriptExecutionContext.domainForCachePartition()); -// // MemoryCache::removeRequestFromSessionCaches(scriptExecutionContext, request); + // MemoryCache::removeRequestFromSessionCaches(scriptExecutionContext, request); -// // scriptExecutionContext.publicURLManager().revoke(url); -// } + // scriptExecutionContext.publicURLManager().revoke(url); + UNUSED_PARAM(scriptExecutionContext); + UNUSED_PARAM(urlString); +} } // namespace WebCore diff --git a/src/bun.js/bindings/DOMURL.h b/src/bun.js/bindings/DOMURL.h index 7e8c40015e2d95..e0aff84cbc9d41 100644 --- a/src/bun.js/bindings/DOMURL.h +++ b/src/bun.js/bindings/DOMURL.h @@ -35,36 +35,39 @@ namespace WebCore { +class Blob; +class ScriptExecutionContext; +class URLRegistrable; class URLSearchParams; class DOMURL final : public RefCounted, public CanMakeWeakPtr, public URLDecomposition { public: static ExceptionOr> create(const String& url, const String& base); - static ExceptionOr> create(const String& url, const DOMURL& base); - ~DOMURL(); + static ExceptionOr> create(const String& url); + WEBCORE_EXPORT ~DOMURL(); + static RefPtr parse(const String& url, const String& base); static bool canParse(const String& url, const String& base); + const URL& href() const { return m_url; } ExceptionOr setHref(const String&); - void setQuery(const String&); URLSearchParams& searchParams(); const String& toJSON() const { return m_url.string(); } - // static String createObjectURL(ScriptExecutionContext&, Blob&); - // static void revokeObjectURL(ScriptExecutionContext&, const String&); + static String createObjectURL(ScriptExecutionContext&, Blob&); + static void revokeObjectURL(ScriptExecutionContext&, const String&); - // static String createPublicURL(ScriptExecutionContext&, URLRegistrable&); + static String createPublicURL(ScriptExecutionContext&, URLRegistrable&); private: static ExceptionOr> create(const String& url, const URL& base); - DOMURL(URL&& completeURL, const URL& baseURL); + DOMURL(URL&& completeURL); URL fullURL() const final { return m_url; } void setFullURL(const URL& fullURL) final { setHref(fullURL.string()); } - URL m_baseURL; URL m_url; RefPtr m_searchParams; }; diff --git a/src/bun.js/bindings/URLSearchParams.cpp b/src/bun.js/bindings/URLSearchParams.cpp index dd86cab765b389..fc0b543842d30b 100644 --- a/src/bun.js/bindings/URLSearchParams.cpp +++ b/src/bun.js/bindings/URLSearchParams.cpp @@ -165,7 +165,7 @@ String URLSearchParams::toString() const void URLSearchParams::updateURL() { if (m_associatedURL) - m_associatedURL->setQuery(WTF::URLParser::serialize(m_pairs)); + m_associatedURL->setSearch(WTF::URLParser::serialize(m_pairs)); } void URLSearchParams::updateFromAssociatedURL() diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 0215b7ab6f664b..41a86ff0837b6b 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -2709,7 +2709,7 @@ pub const JSGlobalObject = extern struct { got: usize, ) JSC.JSValue { return JSC.toTypeErrorWithCode( - "NOT_ENOUGH_ARGUMENTS", + @tagName(JSC.Node.ErrorCode.ERR_MISSING_ARGS), "Not enough arguments to '" ++ name_ ++ "'. Expected {d}, got {d}.", .{ expected, got }, this, diff --git a/src/bun.js/bindings/webcore/JSDOMOperation.cpp b/src/bun.js/bindings/webcore/JSDOMOperation.cpp new file mode 100644 index 00000000000000..0e824fe29b6a77 --- /dev/null +++ b/src/bun.js/bindings/webcore/JSDOMOperation.cpp @@ -0,0 +1,22 @@ +#include "root.h" + +#include "BunClientData.h" +#include "JSDOMOperation.h" +#include "BunBuiltinNames.h" + +#undef createNotEnoughArgumentsError + +namespace WebCore { + +JSC::JSObject* createNotEnoughArgumentsErrorBun(JSC::JSGlobalObject* globalObject) +{ + JSC::JSObject* error = JSC::createNotEnoughArgumentsError(globalObject); + if (LIKELY(error)) { + auto& vm = globalObject->vm(); + const auto& names = WebCore::builtinNames(vm); + error->putDirect(vm, names.codePublicName(), JSC::jsString(vm, WTF::String("ERR_MISSING_ARGS"_s)), 0); + } + + return error; +} +} \ No newline at end of file diff --git a/src/bun.js/bindings/webcore/JSDOMOperation.h b/src/bun.js/bindings/webcore/JSDOMOperation.h index c3f6d0451cddfc..afae4b89865af9 100644 --- a/src/bun.js/bindings/webcore/JSDOMOperation.h +++ b/src/bun.js/bindings/webcore/JSDOMOperation.h @@ -49,7 +49,7 @@ class IDLOperation { static JSC::EncodedJSValue call(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, const char* operationName) { auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); - + auto* thisObject = cast(lexicalGlobalObject, callFrame); if constexpr (shouldThrow != CastedThisErrorBehavior::Assert) { if (UNLIKELY(!thisObject)) @@ -58,7 +58,7 @@ class IDLOperation { ASSERT(thisObject); ASSERT_GC_OBJECT_INHERITS(thisObject, JSClass::info()); - + // FIXME: We should refactor the binding generated code to use references for lexicalGlobalObject and thisObject. RELEASE_AND_RETURN(throwScope, (operation(&lexicalGlobalObject, &callFrame, thisObject))); } @@ -71,4 +71,12 @@ class IDLOperation { } }; +// Rewrite all usages of JSC::createNotEnoughArgumentsError to use our own version. +// Our version adds the "code" property from Node.js. +JSC::JSObject* createNotEnoughArgumentsErrorBun(JSGlobalObject* globalObject); + +#ifndef createNotEnoughArgumentsError +#define createNotEnoughArgumentsError WebCore::createNotEnoughArgumentsErrorBun +#endif + } // namespace WebCore diff --git a/src/bun.js/bindings/webcore/JSDOMURL.cpp b/src/bun.js/bindings/webcore/JSDOMURL.cpp index 87994d289a1e09..ff0ecf8ae27368 100755 --- a/src/bun.js/bindings/webcore/JSDOMURL.cpp +++ b/src/bun.js/bindings/webcore/JSDOMURL.cpp @@ -18,19 +18,20 @@ Boston, MA 02110-1301, USA. */ -#include "root.h" +#include "config.h" #include "JSDOMURL.h" #include "ActiveDOMObject.h" #include "ExtendedDOMClientIsoSubspaces.h" #include "ExtendedDOMIsoSubspaces.h" #include "IDLTypes.h" -// #include "JSBlob.h" #include "JSDOMAttribute.h" #include "JSDOMBinding.h" #include "JSDOMConstructor.h" #include "JSDOMConvertBase.h" +#include "JSDOMConvertBoolean.h" #include "JSDOMConvertInterface.h" +#include "JSDOMConvertNullable.h" #include "JSDOMConvertStrings.h" #include "JSDOMExceptionHandling.h" #include "JSDOMGlobalObject.h" @@ -43,7 +44,7 @@ #include "WebCoreJSClientData.h" #include #include - +#include #include #include #include @@ -61,10 +62,11 @@ using namespace JSC; // Functions +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_parse); +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toJSON); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_createObjectURL); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_revokeObjectURL); -static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toString); // Attributes @@ -130,48 +132,27 @@ using JSDOMURLDOMConstructor = JSDOMConstructor; /* Hash table for constructor */ static const HashTableValue JSDOMURLConstructorTableValues[] = { + { "parse"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_parse, 1 } }, + { "canParse"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_canParse, 1 } }, { "createObjectURL"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_createObjectURL, 1 } }, { "revokeObjectURL"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_revokeObjectURL, 1 } }, - { "canParse"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_canParse, 1 } }, }; -static inline JSC::EncodedJSValue constructJSDOMURL1(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMURLDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) { - VM& vm = lexicalGlobalObject->vm(); + auto& vm = lexicalGlobalObject->vm(); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto url = convert(*lexicalGlobalObject, argument0.value()); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); EnsureStillAliveScope argument1 = callFrame->argument(1); auto base = argument1.value().isUndefined() ? String() : convert(*lexicalGlobalObject, argument1.value()); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - auto object = DOMURL::create(WTFMove(url), WTFMove(base)); - if constexpr (IsExceptionOr) - RETURN_IF_EXCEPTION(throwScope, {}); - static_assert(TypeOrExceptionOrUnderlyingType::isRef); - auto jsValue = toJSNewlyCreated>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object)); - if constexpr (IsExceptionOr) - RETURN_IF_EXCEPTION(throwScope, {}); - setSubclassStructureIfNeeded(lexicalGlobalObject, callFrame, asObject(jsValue)); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(jsValue); -} - -static inline JSC::EncodedJSValue constructJSDOMURL2(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) -{ - VM& vm = lexicalGlobalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto* castedThis = jsCast(callFrame->jsCallee()); - ASSERT(castedThis); - EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - auto url = convert(*lexicalGlobalObject, argument0.value()); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); - auto base = convert>(*lexicalGlobalObject, argument1.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 1, "base", "URL", nullptr, "DOMURL"); }); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - auto object = DOMURL::create(WTFMove(url), *base); + auto object = base.isEmpty() ? DOMURL::create(WTFMove(url)) : DOMURL::create(WTFMove(url), WTFMove(base)); if constexpr (IsExceptionOr) RETURN_IF_EXCEPTION(throwScope, {}); static_assert(TypeOrExceptionOrUnderlyingType::isRef); @@ -182,27 +163,7 @@ static inline JSC::EncodedJSValue constructJSDOMURL2(JSGlobalObject* lexicalGlob RETURN_IF_EXCEPTION(throwScope, {}); return JSValue::encode(jsValue); } - -template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMURLDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) -{ - VM& vm = lexicalGlobalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - UNUSED_PARAM(throwScope); - size_t argsCount = std::min(2, callFrame->argumentCount()); - if (argsCount == 1) { - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); - } - if (argsCount == 2) { - JSValue distinguishingArg = callFrame->uncheckedArgument(1); - if (distinguishingArg.isUndefined()) - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); - if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL2(lexicalGlobalObject, callFrame))); - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); - } - return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); -} -JSC_ANNOTATE_HOST_FUNCTION(JSDOMURLConstructorConstruct, JSDOMURLDOMConstructor::construct); +JSC_ANNOTATE_HOST_FUNCTION(JSDOMURLDOMConstructorConstruct, JSDOMURLDOMConstructor::construct); template<> const ClassInfo JSDOMURLDOMConstructor::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMURLDOMConstructor) }; @@ -220,24 +181,36 @@ template<> void JSDOMURLDOMConstructor::initializeProperties(VM& vm, JSDOMGlobal putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); putDirect(vm, vm.propertyNames->prototype, JSDOMURL::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); reifyStaticProperties(vm, JSDOMURL::info(), JSDOMURLConstructorTableValues, *this); + // if (!((&globalObject)->inherits() || (&globalObject)->inherits() || (&globalObject)->inherits())) { + // auto propertyName = Identifier::fromString(vm, "createObjectURL"_s); + // VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); + // DeletePropertySlot slot; + // JSObject::deleteProperty(this, &globalObject, propertyName, slot); + // } + // if (!((&globalObject)->inherits() || (&globalObject)->inherits() || (&globalObject)->inherits())) { + // auto propertyName = Identifier::fromString(vm, "revokeObjectURL"_s); + // VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); + // DeletePropertySlot slot; + // JSObject::deleteProperty(this, &globalObject, propertyName, slot); + // } } /* Hash table for prototype */ static const HashTableValue JSDOMURLPrototypeTableValues[] = { - { "constructor"_s, static_cast(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURLConstructor, 0 } }, - { "href"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_href, setJSDOMURL_href } }, - { "origin"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_origin, 0 } }, - { "protocol"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_protocol, setJSDOMURL_protocol } }, - { "username"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_username, setJSDOMURL_username } }, - { "password"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_password, setJSDOMURL_password } }, - { "host"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_host, setJSDOMURL_host } }, - { "hostname"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hostname, setJSDOMURL_hostname } }, - { "port"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_port, setJSDOMURL_port } }, - { "pathname"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_pathname, setJSDOMURL_pathname } }, - { "hash"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hash, setJSDOMURL_hash } }, - { "search"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_search, setJSDOMURL_search } }, - { "searchParams"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_searchParams, 0 } }, + { "constructor"_s, static_cast(PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURLConstructor, 0 } }, + { "href"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_href, setJSDOMURL_href } }, + { "origin"_s, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_origin, 0 } }, + { "protocol"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_protocol, setJSDOMURL_protocol } }, + { "username"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_username, setJSDOMURL_username } }, + { "password"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_password, setJSDOMURL_password } }, + { "host"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_host, setJSDOMURL_host } }, + { "hostname"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hostname, setJSDOMURL_hostname } }, + { "port"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_port, setJSDOMURL_port } }, + { "pathname"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_pathname, setJSDOMURL_pathname } }, + { "hash"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hash, setJSDOMURL_hash } }, + { "search"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_search, setJSDOMURL_search } }, + { "searchParams"_s, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_searchParams, 0 } }, { "toJSON"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLPrototypeFunction_toJSON, 0 } }, { "toString"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLPrototypeFunction_toString, 0 } }, }; @@ -258,13 +231,7 @@ JSDOMURL::JSDOMURL(Structure* structure, JSDOMGlobalObject& globalObject, Ref::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); -} +// static_assert(!std::is_base_of::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); JSObject* JSDOMURL::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) { @@ -289,14 +256,14 @@ void JSDOMURL::destroy(JSC::JSCell* cell) thisObject->JSDOMURL::~JSDOMURL(); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURLConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURLConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) { - VM& vm = JSC::getVM(lexicalGlobalObject); + auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); if (UNLIKELY(!prototype)) return throwVMTypeError(lexicalGlobalObject, throwScope); - return JSValue::encode(JSDOMURL::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); + return JSValue::encode(JSDOMURL::getConstructor(vm, prototype->globalObject())); } static inline JSValue jsDOMURL_hrefGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) @@ -307,7 +274,7 @@ static inline JSValue jsDOMURL_hrefGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.href()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_href, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_href, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -315,6 +282,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_href, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_hrefSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -325,7 +293,7 @@ static inline bool setJSDOMURL_hrefSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_href, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_href, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -338,7 +306,7 @@ static inline JSValue jsDOMURL_originGetter(JSGlobalObject& lexicalGlobalObject, RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.origin()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_origin, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_origin, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -351,7 +319,7 @@ static inline JSValue jsDOMURL_protocolGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.protocol()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -359,6 +327,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_protocol, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_protocolSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -369,7 +338,7 @@ static inline bool setJSDOMURL_protocolSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -382,7 +351,7 @@ static inline JSValue jsDOMURL_usernameGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.username()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_username, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_username, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -390,6 +359,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_username, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_usernameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -400,7 +370,7 @@ static inline bool setJSDOMURL_usernameSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_username, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_username, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -413,7 +383,7 @@ static inline JSValue jsDOMURL_passwordGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.password()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_password, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_password, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -421,6 +391,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_password, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_passwordSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -431,7 +402,7 @@ static inline bool setJSDOMURL_passwordSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_password, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_password, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -444,7 +415,7 @@ static inline JSValue jsDOMURL_hostGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.host()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_host, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_host, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -452,6 +423,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_host, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_hostSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -462,7 +434,7 @@ static inline bool setJSDOMURL_hostSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_host, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_host, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -475,7 +447,7 @@ static inline JSValue jsDOMURL_hostnameGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.hostname()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -483,6 +455,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hostname, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_hostnameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -493,7 +466,7 @@ static inline bool setJSDOMURL_hostnameSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -506,7 +479,7 @@ static inline JSValue jsDOMURL_portGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.port()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_port, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_port, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -514,6 +487,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_port, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_portSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -524,7 +498,7 @@ static inline bool setJSDOMURL_portSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_port, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_port, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -537,7 +511,7 @@ static inline JSValue jsDOMURL_pathnameGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.pathname()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -545,6 +519,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_pathname, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_pathnameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -555,7 +530,7 @@ static inline bool setJSDOMURL_pathnameSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -568,7 +543,7 @@ static inline JSValue jsDOMURL_hashGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.hash()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -576,6 +551,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_hashSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -586,7 +562,7 @@ static inline bool setJSDOMURL_hashSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -599,7 +575,7 @@ static inline JSValue jsDOMURL_searchGetter(JSGlobalObject& lexicalGlobalObject, RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.search()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_search, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_search, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -607,6 +583,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_search, (JSGlobalObject * lexicalGlobalObject, static inline bool setJSDOMURL_searchSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -617,7 +594,7 @@ static inline bool setJSDOMURL_searchSetter(JSGlobalObject& lexicalGlobalObject, return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_search, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_search, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -635,11 +612,55 @@ static inline JSValue jsDOMURL_searchParamsGetter(JSGlobalObject& lexicalGlobalO return result; } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_searchParams, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_searchParams, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_parseBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto url = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->argument(1); + auto base = argument1.value().isUndefined() ? String() : convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS>>(*lexicalGlobalObject, *jsCast(lexicalGlobalObject), throwScope, DOMURL::parse(WTFMove(url), WTFMove(base))))); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_parse, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "parse"); +} + +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_canParseBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto url = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->argument(1); + auto base = argument1.value().isUndefined() ? String() : convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, DOMURL::canParse(WTFMove(url), WTFMove(base))))); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "canParse"); +} + static inline JSC::EncodedJSValue jsDOMURLPrototypeFunction_toJSONBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); @@ -659,8 +680,8 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURL1Bo { // auto& vm = JSC::getVM(lexicalGlobalObject); // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); - // UNUSED_PARAM(callFrame); + UNUSED_PARAM(lexicalGlobalObject); + UNUSED_PARAM(callFrame); // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); // if (UNLIKELY(!context)) return JSValue::encode(jsUndefined()); @@ -674,8 +695,8 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_revokeObjectURLBod { // auto& vm = JSC::getVM(lexicalGlobalObject); // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); - // UNUSED_PARAM(callFrame); + UNUSED_PARAM(lexicalGlobalObject); + UNUSED_PARAM(callFrame); // if (UNLIKELY(callFrame->argumentCount() < 1)) // return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); @@ -692,70 +713,31 @@ JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_revokeObjectURL, (JSGlobalO return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "revokeObjectURL"); } -static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_canParseBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +void JSDOMURL::finishCreation(JSC::VM& vm) { - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - - if (UNLIKELY(callFrame->argumentCount() < 1)) - return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); - - EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - auto url = convert(*lexicalGlobalObject, argument0.value()); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - - EnsureStillAliveScope argument1 = callFrame->argument(1); - String base; - if (!argument1.value().isUndefinedOrNull()) { - base = convert(*lexicalGlobalObject, argument1.value()); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - } - - return JSValue::encode(jsBoolean(DOMURL::canParse(url, base))); -} - -JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "canParse"); -} - -#if ENABLE(MEDIA_SOURCE) -static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURL2Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) -{ - // auto& vm = JSC::getVM(lexicalGlobalObject); - // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); - // UNUSED_PARAM(callFrame); - // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - // if (UNLIKELY(!context)) - return JSValue::encode(jsUndefined()); - // EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - // auto source = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "source", "URL", "createObjectURL", "MediaSource"); }); - // RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - // RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, WebCore::DOMURLMediaSource::createObjectURL(*context, *source)))); + Base::finishCreation(vm); + ASSERT(inherits(info())); } -#endif - static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURLOverloadDispatcher(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) { - return JSValue::encode(jsUndefined()); - - // auto& vm = JSC::getVM(lexicalGlobalObject); - // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); - // size_t argsCount = std::min(1, callFrame->argumentCount()); - // if (argsCount == 1) { - // JSValue distinguishingArg = callFrame->uncheckedArgument(0); - // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) - // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL1Body(lexicalGlobalObject, callFrame))); - // #if ENABLE(MEDIA_SOURCE) - // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) - // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL2Body(lexicalGlobalObject, callFrame))); - // #endif - // } - // return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); + size_t argsCount = std::min(1, callFrame->argumentCount()); + if (argsCount == 1) { + JSValue distinguishingArg = callFrame->uncheckedArgument(0); + if (distinguishingArg.isObject()) { + return JSValue::encode(jsUndefined()); + } + // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) + // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL1Body(lexicalGlobalObject, callFrame))); + // #if ENABLE(MEDIA_SOURCE) + // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) + // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL2Body(lexicalGlobalObject, callFrame))); + } + return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); } JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_createObjectURL, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) @@ -803,8 +785,8 @@ void JSDOMURL::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) { auto* thisObject = jsCast(cell); analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped()); - // if (thisObject->scriptExecutionContext()) - // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + if (thisObject->scriptExecutionContext()) + analyzer.setLabelForCell(cell, "url "_s + thisObject->scriptExecutionContext()->url().string()); Base::analyzeHeap(cell, analyzer); } @@ -867,11 +849,10 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g return wrap(lexicalGlobalObject, globalObject, impl); } -DOMURL* JSDOMURL::toWrapped(JSC::VM& vm, JSC::JSValue value) +DOMURL* JSDOMURL::toWrapped(JSC::VM&, JSC::JSValue value) { if (auto* wrapper = jsDynamicCast(value)) return &wrapper->wrapped(); return nullptr; } - } diff --git a/test/js/node/url/url.test.ts b/test/js/node/url/url.test.ts index f01484136dd76b..004fb499914e83 100644 --- a/test/js/node/url/url.test.ts +++ b/test/js/node/url/url.test.ts @@ -66,3 +66,16 @@ describe("Url.prototype.parse", () => { }); }); }); + +it("URL constructor throws ERR_MISSING_ARGS", () => { + var err; + try { + // @ts-expect-error + new URL(); + } catch (e) { + err = e; + } + + // @ts-expect-error + expect(err?.code).toEqual("ERR_MISSING_ARGS"); +});