From 205ac8718ad143891ff94ac79117fe77ca5a7757 Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Sat, 23 Sep 2023 22:37:31 -0400 Subject: [PATCH 1/9] check in --- misctools/fetch.zig | 2 +- misctools/http_bench.zig | 2 +- misctools/machbench.zig | 2 +- src/analytics/analytics_thread.zig | 2 +- src/bun.js/api/JSBundler.zig | 4 +- src/bun.js/api/JSTranspiler.zig | 4 +- src/bun.js/api/bun.zig | 2 +- src/bun.js/api/ffi.zig | 6 +- src/bun.js/api/filesystem_router.zig | 6 +- src/bun.js/api/server.classes.ts | 3 + src/bun.js/api/server.zig | 10 +- src/bun.js/bindings/BunString.cpp | 27 -- ...igGeneratedClasses+DOMClientIsoSubspaces.h | 3 +- .../ZigGeneratedClasses+DOMIsoSubspaces.h | 3 +- .../ZigGeneratedClasses+lazyStructureHeader.h | 6 +- .../ZigGeneratedClasses+lazyStructureImpl.h | 7 + src/bun.js/bindings/ZigGeneratedClasses.cpp | 313 +++++++++++++++++- src/bun.js/bindings/ZigGeneratedClasses.h | 50 +++ src/bun.js/bindings/bindings.zig | 18 +- src/bun.js/bindings/exports.zig | 2 +- src/bun.js/bindings/generated_classes.zig | 85 +++++ .../bindings/generated_classes_list.zig | 1 + src/bun.js/javascript.zig | 2 +- src/bun.js/module_loader.zig | 2 +- src/bun.js/node/types.zig | 2 +- src/bun.js/test/jest.zig | 2 +- src/bun.js/url.classes.ts | 14 + src/{ => bun.js}/url.zig | 35 +- src/bun.js/webcore/blob.zig | 2 +- src/bun.js/webcore/body.zig | 2 +- src/bun.js/webcore/encoding.zig | 2 +- src/bun.js/webcore/request.zig | 2 +- src/bun.js/webcore/response.zig | 4 +- src/bun.js/webcore/streams.zig | 2 +- src/bun.zig | 7 +- src/bun_dev_http_server.zig | 2 +- src/bundler.zig | 2 +- src/bundler/bundle_v2.zig | 2 +- src/bunfig.zig | 2 +- src/cli/create_command.zig | 2 +- src/cli/install_completions_command.zig | 2 +- src/cli/upgrade_command.zig | 2 +- src/css_scanner.zig | 2 +- src/env_loader.zig | 2 +- src/http/url_path.zig | 2 +- src/http_client_async.zig | 4 +- src/install/install.zig | 2 +- src/install/lockfile.zig | 2 +- src/install/npm.zig | 2 +- src/jsc.zig | 1 + src/linker.zig | 2 +- src/options.zig | 2 +- src/resolver/package_json.zig | 2 +- src/router.zig | 2 +- test/bun.lockb | Bin 162926 -> 163311 bytes 55 files changed, 565 insertions(+), 110 deletions(-) create mode 100644 src/bun.js/url.classes.ts rename src/{ => bun.js}/url.zig (98%) diff --git a/misctools/fetch.zig b/misctools/fetch.zig index 347ce8cde841..ac6cf575d4cf 100644 --- a/misctools/fetch.zig +++ b/misctools/fetch.zig @@ -13,7 +13,7 @@ pub usingnamespace @import("root").bun; const clap = bun.clap; -const URL = @import("../src/url.zig").URL; +const URL = bun.URL; const Headers = @import("root").bun.HTTP.Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; diff --git a/misctools/http_bench.zig b/misctools/http_bench.zig index 1759e630dddf..fe98027fad8c 100644 --- a/misctools/http_bench.zig +++ b/misctools/http_bench.zig @@ -11,7 +11,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const clap = @import("../src/deps/zig-clap/clap.zig"); -const URL = @import("../src/url.zig").URL; +const URL = bun.URL; const Headers = @import("../src/bun.js/webcore/response.zig").Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; diff --git a/misctools/machbench.zig b/misctools/machbench.zig index 5da20b5bad7d..569bcdec5c0c 100644 --- a/misctools/machbench.zig +++ b/misctools/machbench.zig @@ -13,7 +13,7 @@ const C = bun.C; const clap = @import("../src/deps/zig-clap/clap.zig"); const AsyncIO = @import("root").bun.AsyncIO; -const URL = @import("../src/url.zig").URL; +const URL = bun.URL; const Headers = @import("root").bun.HTTP.Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; diff --git a/src/analytics/analytics_thread.zig b/src/analytics/analytics_thread.zig index b0ee2cdbc02a..53c420683217 100644 --- a/src/analytics/analytics_thread.zig +++ b/src/analytics/analytics_thread.zig @@ -14,7 +14,7 @@ const sync = @import("../sync.zig"); const std = @import("std"); const HTTP = @import("root").bun.HTTP; const NetworkThread = HTTP.NetworkThread; -const URL = @import("../url.zig").URL; +const URL = bun.URL; const Fs = @import("../fs.zig"); const Analytics = @import("./analytics_schema.zig").analytics; const Writer = @import("./analytics_schema.zig").Writer; diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 4a4d10f0f2a8..14a72f8fa80b 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -2,8 +2,8 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const http = @import("../../bun_dev_http_server.zig"); const JavaScript = @import("../javascript.zig"); -const QueryStringMap = @import("../../url.zig").QueryStringMap; -const CombinedScanner = @import("../../url.zig").CombinedScanner; +const QueryStringMap = bun.QueryStringMap; +const CombinedScanner = bun.CombinedScanner; const bun = @import("root").bun; const string = bun.string; const JSC = bun.JSC; diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig index 8cec025eb4be..51f75f623692 100644 --- a/src/bun.js/api/JSTranspiler.zig +++ b/src/bun.js/api/JSTranspiler.zig @@ -2,8 +2,8 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const http = @import("../../bun_dev_http_server.zig"); const JavaScript = @import("../javascript.zig"); -const QueryStringMap = @import("../../url.zig").QueryStringMap; -const CombinedScanner = @import("../../url.zig").CombinedScanner; +const QueryStringMap = bun.QueryStringMap; +const CombinedScanner = bun.CombinedScanner; const bun = @import("root").bun; const string = bun.string; const JSC = bun.JSC; diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index 966c82d383e0..9a482ea14352 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -224,7 +224,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("../config.zig"); -const URL = @import("../../url.zig").URL; +const URL = bun.URL; const Transpiler = bun.JSC.API.JSTranspiler; const JSBundler = bun.JSC.API.JSBundler; const VirtualMachine = JSC.VirtualMachine; diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index 234b588887ba..b02e4d48b1e2 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -70,7 +70,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("../config.zig"); -const URL = @import("../../url.zig").URL; +const URL = bun.URL; const VirtualMachine = JSC.VirtualMachine; const IOTask = JSC.IOTask; const ComptimeStringMap = @import("../../comptime_string_map.zig").ComptimeStringMap; @@ -317,9 +317,9 @@ pub const FFI = struct { }; }; }; - + var size = symbols.values().len; - if(size >= 63) { + if (size >= 63) { size = 0; } var obj = JSC.JSValue.createEmptyObject(global, size); diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index f3306629842e..febb8ff7e98a 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -2,9 +2,9 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const http = @import("../../bun_dev_http_server.zig"); const JavaScript = @import("../javascript.zig"); -const QueryStringMap = @import("../../url.zig").QueryStringMap; -const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; +const QueryStringMap = bun.QueryStringMap; +const CombinedScanner = bun.CombinedScanner; const string = bun.string; const JSC = @import("root").bun.JSC; const js = JSC.C; @@ -26,7 +26,7 @@ const To = Base.To; const Request = WebCore.Request; const URLPath = @import("../../http/url_path.zig"); -const URL = @import("../../url.zig").URL; +const URL = bun.URL; const Log = @import("root").bun.logger; const Resolver = @import("../../resolver/resolver.zig").Resolver; const Router = @import("../../router.zig"); diff --git a/src/bun.js/api/server.classes.ts b/src/bun.js/api/server.classes.ts index 544f37ce6a1e..0d3298bb2947 100644 --- a/src/bun.js/api/server.classes.ts +++ b/src/bun.js/api/server.classes.ts @@ -47,6 +47,9 @@ function generate(name) { development: { getter: "getDevelopment", }, + url: { + getter: "getURL", + }, }, klass: {}, finalize: true, diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 173693c1edfa..10b4b9db0a96 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -69,7 +69,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("../config.zig"); -const URL = @import("../../url.zig").URL; +const URL = bun.URL; const VirtualMachine = JSC.VirtualMachine; const IOTask = JSC.IOTask; const is_bindgen = JSC.is_bindgen; @@ -5217,6 +5217,14 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp return JSC.JSValue.jsBoolean(debug_mode); } + pub fn getURL( + this: *ThisServer, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + const pathParts = [_]string{ this.cached_hostname.toUTF8(this.allocator), this.getPort().toString().toUTF8(this.allocator) }; + return URL.fromString(this.allocator, strings.concat(this.allocator, &pathParts)).toJS(globalThis); + } + pub fn onRequestComplete(this: *ThisServer) void { this.vm.eventLoop().processGCTimer(); diff --git a/src/bun.js/bindings/BunString.cpp b/src/bun.js/bindings/BunString.cpp index 416d5d334080..829415b43cf3 100644 --- a/src/bun.js/bindings/BunString.cpp +++ b/src/bun.js/bindings/BunString.cpp @@ -337,23 +337,6 @@ extern "C" BunString URL__getFileURLString(BunString* filePath) return Bun::toStringRef(WTF::URL::fileURLWithFileSystemPath(Bun::toWTFString(*filePath)).stringWithoutFragmentIdentifier()); } -extern "C" WTF::URL* URL__fromJS(EncodedJSValue encodedValue, JSC::JSGlobalObject* globalObject) -{ - auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); - JSC::JSValue value = JSC::JSValue::decode(encodedValue); - auto str = value.toWTFString(globalObject); - RETURN_IF_EXCEPTION(throwScope, nullptr); - if (str.isEmpty()) { - return nullptr; - } - - auto url = WTF::URL(str); - if (!url.isValid() || url.isNull()) - return nullptr; - - return new WTF::URL(WTFMove(url)); -} - extern "C" BunString URL__getHrefFromJS(EncodedJSValue encodedValue, JSC::JSGlobalObject* globalObject) { auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); @@ -392,16 +375,6 @@ extern "C" BunString URL__getHrefJoin(BunString* baseStr, BunString *relativeStr return Bun::toStringRef(url.string()); } -extern "C" WTF::URL* URL__fromString(BunString* input) -{ - auto&& str = Bun::toWTFString(*input); - auto url = WTF::URL(str); - if (!url.isValid()) - return nullptr; - - return new WTF::URL(WTFMove(url)); -} - extern "C" BunString URL__protocol(WTF::URL* url) { return Bun::toStringRef(url->protocol().toStringWithoutCopying()); diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h index cef5c512a7c5..57d74af4e1d4 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h @@ -49,4 +49,5 @@ std::unique_ptr m_clientSubspaceForTextChunk; std::unique_ptr m_clientSubspaceForTextDecoder; std::unique_ptr m_clientSubspaceForTextDecoderConstructor;std::unique_ptr m_clientSubspaceForTimeout; std::unique_ptr m_clientSubspaceForTranspiler; -std::unique_ptr m_clientSubspaceForTranspilerConstructor; \ No newline at end of file +std::unique_ptr m_clientSubspaceForTranspilerConstructor;std::unique_ptr m_clientSubspaceForURL; +std::unique_ptr m_clientSubspaceForURLConstructor; \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h index d06451eda044..3cc6b92f945d 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h @@ -49,4 +49,5 @@ std::unique_ptr m_subspaceForTextChunk; std::unique_ptr m_subspaceForTextDecoder; std::unique_ptr m_subspaceForTextDecoderConstructor;std::unique_ptr m_subspaceForTimeout; std::unique_ptr m_subspaceForTranspiler; -std::unique_ptr m_subspaceForTranspilerConstructor; \ No newline at end of file +std::unique_ptr m_subspaceForTranspilerConstructor;std::unique_ptr m_subspaceForURL; +std::unique_ptr m_subspaceForURLConstructor; \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h index 381378262f36..98a994c5e670 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h @@ -201,4 +201,8 @@ JSC::Structure* JSTimeoutStructure() { return m_JSTimeout.getInitializedOnMainTh JSC::Structure* JSTranspilerStructure() { return m_JSTranspiler.getInitializedOnMainThread(this); } JSC::JSObject* JSTranspilerConstructor() { return m_JSTranspiler.constructorInitializedOnMainThread(this); } JSC::JSValue JSTranspilerPrototype() { return m_JSTranspiler.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSTranspiler; \ No newline at end of file + JSC::LazyClassStructure m_JSTranspiler; +JSC::Structure* JSURLStructure() { return m_JSURL.getInitializedOnMainThread(this); } + JSC::JSObject* JSURLConstructor() { return m_JSURL.constructorInitializedOnMainThread(this); } + JSC::JSValue JSURLPrototype() { return m_JSURL.prototypeInitializedOnMainThread(this); } + JSC::LazyClassStructure m_JSURL; \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h index 84d3df7a0542..5cf191133a33 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h @@ -305,6 +305,12 @@ ALWAYS_INLINE void GlobalObject::initGeneratedLazyClasses() { init.setStructure(WebCore::JSTranspiler::createStructure(init.vm, init.global, init.prototype)); init.setConstructor(WebCore::JSTranspiler::createConstructor(init.vm, init.global, init.prototype)); }); + m_JSURL.initLater( + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSURL::createPrototype(init.vm, reinterpret_cast(init.global))); + init.setStructure(WebCore::JSURL::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSURL::createConstructor(init.vm, init.global, init.prototype)); + }); } template void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor) @@ -360,4 +366,5 @@ void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& thisObject->m_JSTextDecoder.visit(visitor); thisObject->m_JSTimeout.visit(visitor); thisObject->m_JSTranspiler.visit(visitor); + thisObject->m_JSURL.visit(visitor); } \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index b84c1cd1644b..162d30ac03f1 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -4203,6 +4203,9 @@ JSC_DECLARE_HOST_FUNCTION(DebugHTTPSServerPrototype__stopCallback); extern "C" EncodedJSValue DebugHTTPSServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(DebugHTTPSServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue DebugHTTPSServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(DebugHTTPSServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDebugHTTPSServerPrototype, JSDebugHTTPSServerPrototype::Base); static const HashTableValue JSDebugHTTPSServerPrototypeTableValues[] = { @@ -4217,7 +4220,8 @@ static const HashTableValue JSDebugHTTPSServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, DebugHTTPSServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSDebugHTTPSServerPrototype::s_info = { "DebugHTTPSServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDebugHTTPSServerPrototype) }; @@ -4496,6 +4500,18 @@ JSC_DEFINE_HOST_FUNCTION(DebugHTTPSServerPrototype__upgradeCallback, (JSGlobalOb return DebugHTTPSServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(DebugHTTPSServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSDebugHTTPSServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = DebugHTTPSServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSDebugHTTPSServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -4685,6 +4701,9 @@ JSC_DECLARE_HOST_FUNCTION(DebugHTTPServerPrototype__stopCallback); extern "C" EncodedJSValue DebugHTTPServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(DebugHTTPServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue DebugHTTPServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(DebugHTTPServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDebugHTTPServerPrototype, JSDebugHTTPServerPrototype::Base); static const HashTableValue JSDebugHTTPServerPrototypeTableValues[] = { @@ -4699,7 +4718,8 @@ static const HashTableValue JSDebugHTTPServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, DebugHTTPServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSDebugHTTPServerPrototype::s_info = { "DebugHTTPServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDebugHTTPServerPrototype) }; @@ -4978,6 +4998,18 @@ JSC_DEFINE_HOST_FUNCTION(DebugHTTPServerPrototype__upgradeCallback, (JSGlobalObj return DebugHTTPServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(DebugHTTPServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSDebugHTTPServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = DebugHTTPServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSDebugHTTPServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -11626,6 +11658,9 @@ JSC_DECLARE_HOST_FUNCTION(HTTPSServerPrototype__stopCallback); extern "C" EncodedJSValue HTTPSServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(HTTPSServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue HTTPSServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(HTTPSServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSHTTPSServerPrototype, JSHTTPSServerPrototype::Base); static const HashTableValue JSHTTPSServerPrototypeTableValues[] = { @@ -11640,7 +11675,8 @@ static const HashTableValue JSHTTPSServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, HTTPSServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSHTTPSServerPrototype::s_info = { "HTTPSServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTTPSServerPrototype) }; @@ -11919,6 +11955,18 @@ JSC_DEFINE_HOST_FUNCTION(HTTPSServerPrototype__upgradeCallback, (JSGlobalObject return HTTPSServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(HTTPSServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSHTTPSServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = HTTPSServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSHTTPSServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -12108,6 +12156,9 @@ JSC_DECLARE_HOST_FUNCTION(HTTPServerPrototype__stopCallback); extern "C" EncodedJSValue HTTPServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(HTTPServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue HTTPServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(HTTPServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSHTTPServerPrototype, JSHTTPServerPrototype::Base); static const HashTableValue JSHTTPServerPrototypeTableValues[] = { @@ -12122,7 +12173,8 @@ static const HashTableValue JSHTTPServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, HTTPServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSHTTPServerPrototype::s_info = { "HTTPServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTTPServerPrototype) }; @@ -12401,6 +12453,18 @@ JSC_DEFINE_HOST_FUNCTION(HTTPServerPrototype__upgradeCallback, (JSGlobalObject * return HTTPServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(HTTPServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSHTTPServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = HTTPServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSHTTPServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -27565,6 +27629,247 @@ extern "C" EncodedJSValue Transpiler__create(Zig::GlobalObject* globalObject, vo return JSValue::encode(instance); } +class JSURLPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + + static JSURLPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) + { + JSURLPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSURLPrototype(vm, globalObject, structure); + ptr->finishCreation(vm, globalObject); + return ptr; + } + + DECLARE_INFO; + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + 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: + JSURLPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + : Base(vm, structure) + { + } + + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; + +class JSURLConstructor final : public JSC::InternalFunction { +public: + using Base = JSC::InternalFunction; + static JSURLConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSURLPrototype* prototype); + + static constexpr unsigned StructureFlags = Base::StructureFlags; + static constexpr bool needsDestruction = false; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); + } + + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForURLConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForURLConstructor = std::forward(space); }, + [](auto& spaces) { return spaces.m_subspaceForURLConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForURLConstructor = std::forward(space); }); + } + + void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype); + + // Must be defined for each specialization class. + static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*); + + DECLARE_EXPORT_INFO; + +private: + JSURLConstructor(JSC::VM& vm, JSC::Structure* structure); + void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype); +}; + +extern "C" void* URLClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*); +JSC_DECLARE_CUSTOM_GETTER(jsURLConstructor); + +extern "C" void URLClass__finalize(void*); + +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSURLPrototype, JSURLPrototype::Base); + +static const HashTableValue JSURLPrototypeTableValues[] = {}; + +const ClassInfo JSURLPrototype::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLPrototype) }; + +JSC_DEFINE_CUSTOM_GETTER(jsURLConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* globalObject = reinterpret_cast(lexicalGlobalObject); + auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); + + if (UNLIKELY(!prototype)) + return throwVMTypeError(lexicalGlobalObject, throwScope, "Cannot get constructor for URL"_s); + return JSValue::encode(globalObject->JSURLConstructor()); +} + +void JSURLPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) +{ + Base::finishCreation(vm); + + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +void JSURLConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype) +{ + Base::finishCreation(vm, 0, "URL"_s, PropertyAdditionMode::WithoutStructureTransition); + + putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); + ASSERT(inherits(info())); +} + +JSURLConstructor::JSURLConstructor(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure, construct, construct) +{ +} + +JSURLConstructor* JSURLConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSURLPrototype* prototype) +{ + JSURLConstructor* ptr = new (NotNull, JSC::allocateCell(vm)) JSURLConstructor(vm, structure); + ptr->finishCreation(vm, globalObject, prototype); + return ptr; +} + +JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSURLConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + JSC::VM& vm = globalObject->vm(); + JSObject* newTarget = asObject(callFrame->newTarget()); + auto* constructor = globalObject->JSURLConstructor(); + Structure* structure = globalObject->JSURLStructure(); + if (constructor != newTarget) { + auto scope = DECLARE_THROW_SCOPE(vm); + + auto* functionGlobalObject = reinterpret_cast( + // ShadowRealm functions belong to a different global object. + getFunctionRealm(globalObject, newTarget)); + RETURN_IF_EXCEPTION(scope, {}); + structure = InternalFunction::createSubclassStructure( + globalObject, + newTarget, + functionGlobalObject->JSURLStructure()); + } + + void* ptr = URLClass__construct(globalObject, callFrame); + + if (UNLIKELY(!ptr)) { + return JSValue::encode(JSC::jsUndefined()); + } + + JSURL* instance = JSURL::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} + +void JSURLConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype) +{ +} + +const ClassInfo JSURLConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLConstructor) }; + +extern "C" EncodedJSValue URL__getConstructor(Zig::GlobalObject* globalObject) +{ + return JSValue::encode(globalObject->JSURLConstructor()); +} + +JSURL::~JSURL() +{ + if (m_ctx) { + URLClass__finalize(m_ctx); + } +} +void JSURL::destroy(JSCell* cell) +{ + static_cast(cell)->JSURL::~JSURL(); +} + +const ClassInfo JSURL::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURL) }; + +void JSURL::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(info())); +} + +JSURL* JSURL::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) +{ + JSURL* ptr = new (NotNull, JSC::allocateCell(vm)) JSURL(vm, structure, ctx); + ptr->finishCreation(vm); + return ptr; +} + +extern "C" void* URL__fromJS(JSC::EncodedJSValue value) +{ + JSC::JSValue decodedValue = JSC::JSValue::decode(value); + if (decodedValue.isEmpty() || !decodedValue.isCell()) + return nullptr; + + JSC::JSCell* cell = decodedValue.asCell(); + JSURL* object = JSC::jsDynamicCast(cell); + + if (!object) + return nullptr; + + return object->wrapped(); +} + +extern "C" bool URL__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) +{ + JSURL* object = JSC::jsDynamicCast(JSValue::decode(value)); + if (!object) + return false; + + object->m_ctx = ptr; + return true; +} + +extern "C" const size_t URL__ptrOffset = JSURL::offsetOfWrapped(); + +void JSURL::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast(cell); + if (void* wrapped = thisObject->wrapped()) { + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + } + Base::analyzeHeap(cell, analyzer); +} + +JSObject* JSURL::createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype) +{ + return WebCore::JSURLConstructor::create(vm, globalObject, WebCore::JSURLConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast(prototype)); +} + +JSObject* JSURL::createPrototype(VM& vm, JSDOMGlobalObject* globalObject) +{ + return JSURLPrototype::create(vm, globalObject, JSURLPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); +} + +extern "C" EncodedJSValue URL__create(Zig::GlobalObject* globalObject, void* ptr) +{ + auto& vm = globalObject->vm(); + JSC::Structure* structure = globalObject->JSURLStructure(); + JSURL* instance = JSURL::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} std::optional StructuredCloneableSerialize::fromJS(JSC::JSValue value) { if (auto* result = jsDynamicCast(value)) { diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index 33aa5848775a..901d26e8c476 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -2952,6 +2952,56 @@ class JSTranspiler final : public JSC::JSDestructibleObject { void finishCreation(JSC::VM&); }; +class JSURL final : public JSC::JSDestructibleObject { +public: + using Base = JSC::JSDestructibleObject; + static JSURL* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); + + DECLARE_EXPORT_INFO; + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForURL.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForURL = std::forward(space); }, + [](auto& spaces) { return spaces.m_subspaceForURL.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForURL = std::forward(space); }); + } + + static void destroy(JSC::JSCell*); + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast(0b11101110), StructureFlags), info()); + } + + static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); + static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype); + + ~JSURL(); + + void* wrapped() const { return m_ctx; } + + void detach() + { + m_ctx = nullptr; + } + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSURL, m_ctx); } + + void* m_ctx { nullptr }; + + JSURL(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) + : Base(vm, structure) + { + m_ctx = sinkPtr; + } + + void finishCreation(JSC::VM&); +}; + class StructuredCloneableSerialize { public: void (*cppWriteBytes)(CloneSerializer*, const uint8_t*, uint32_t); diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 3a0b369e9e81..ed2390644d17 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -21,6 +21,7 @@ const MutableString = bun.MutableString; const JestPrettyFormat = @import("../test/pretty_format.zig").JestPrettyFormat; const String = bun.String; const ErrorableString = JSC.ErrorableString; +const URL = JSC.URL; pub const JSObject = extern struct { pub const shim = Shimmer("JSC", "JSObject", @This()); bytes: shim.Bytes, @@ -5479,9 +5480,7 @@ pub fn untrackFunction( return private.Bun__untrackFFIFunction(globalObject, value); } -pub const URL = opaque { - extern fn URL__fromJS(JSValue, *JSC.JSGlobalObject) ?*URL; - extern fn URL__fromString(*bun.String) ?*URL; +pub const CppURL = opaque { extern fn URL__protocol(*URL) String; extern fn URL__href(*URL) String; extern fn URL__username(*URL) String; @@ -5523,19 +5522,6 @@ pub const URL = opaque { return URL__getHrefFromJS(value, globalObject); } - pub fn fromJS(value: JSValue, globalObject: *JSC.JSGlobalObject) ?*URL { - JSC.markBinding(@src()); - return URL__fromJS(value, globalObject); - } - - pub fn fromUTF8(input: []const u8) ?*URL { - return fromString(String.fromUTF8(input)); - } - pub fn fromString(str: bun.String) ?*URL { - JSC.markBinding(@src()); - var input = str; - return URL__fromString(&input); - } pub fn protocol(url: *URL) String { JSC.markBinding(@src()); return URL__protocol(url); diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index 10326bc7c1b2..6ab8c3c451de 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -3,7 +3,7 @@ const Fs = @import("../../fs.zig"); const CAPI = JSC.C; const JS = @import("../javascript.zig"); const JSBase = @import("../base.zig"); -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const std = @import("std"); diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 581d4a5f398a..50ff62dc3aeb 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -1331,6 +1331,9 @@ pub const JSDebugHTTPSServer = struct { @compileLog("Expected DebugHTTPSServer.doStop to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPSServer.doStop))); if (@TypeOf(DebugHTTPSServer.doUpgrade) != CallbackType) @compileLog("Expected DebugHTTPSServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPSServer.doUpgrade))); + if (@TypeOf(DebugHTTPSServer.getURL) != GetterType) + @compileLog("Expected DebugHTTPSServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(DebugHTTPSServer.doFetch, .{ .name = "DebugHTTPSServerPrototype__doFetch" }); @export(DebugHTTPSServer.doPublish, .{ .name = "DebugHTTPSServerPrototype__doPublish" }); @@ -1345,6 +1348,7 @@ pub const JSDebugHTTPSServer = struct { @export(DebugHTTPSServer.getPendingWebSockets, .{ .name = "DebugHTTPSServerPrototype__getPendingWebSockets" }); @export(DebugHTTPSServer.getPort, .{ .name = "DebugHTTPSServerPrototype__getPort" }); @export(DebugHTTPSServer.getProtocol, .{ .name = "DebugHTTPSServerPrototype__getProtocol" }); + @export(DebugHTTPSServer.getURL, .{ .name = "DebugHTTPSServerPrototype__getURL" }); } } }; @@ -1474,6 +1478,9 @@ pub const JSDebugHTTPServer = struct { @compileLog("Expected DebugHTTPServer.doStop to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPServer.doStop))); if (@TypeOf(DebugHTTPServer.doUpgrade) != CallbackType) @compileLog("Expected DebugHTTPServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPServer.doUpgrade))); + if (@TypeOf(DebugHTTPServer.getURL) != GetterType) + @compileLog("Expected DebugHTTPServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(DebugHTTPServer.doFetch, .{ .name = "DebugHTTPServerPrototype__doFetch" }); @export(DebugHTTPServer.doPublish, .{ .name = "DebugHTTPServerPrototype__doPublish" }); @@ -1488,6 +1495,7 @@ pub const JSDebugHTTPServer = struct { @export(DebugHTTPServer.getPendingWebSockets, .{ .name = "DebugHTTPServerPrototype__getPendingWebSockets" }); @export(DebugHTTPServer.getPort, .{ .name = "DebugHTTPServerPrototype__getPort" }); @export(DebugHTTPServer.getProtocol, .{ .name = "DebugHTTPServerPrototype__getProtocol" }); + @export(DebugHTTPServer.getURL, .{ .name = "DebugHTTPServerPrototype__getURL" }); } } }; @@ -3281,6 +3289,9 @@ pub const JSHTTPSServer = struct { @compileLog("Expected HTTPSServer.doStop to be a callback but received " ++ @typeName(@TypeOf(HTTPSServer.doStop))); if (@TypeOf(HTTPSServer.doUpgrade) != CallbackType) @compileLog("Expected HTTPSServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(HTTPSServer.doUpgrade))); + if (@TypeOf(HTTPSServer.getURL) != GetterType) + @compileLog("Expected HTTPSServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(HTTPSServer.doFetch, .{ .name = "HTTPSServerPrototype__doFetch" }); @export(HTTPSServer.doPublish, .{ .name = "HTTPSServerPrototype__doPublish" }); @@ -3295,6 +3306,7 @@ pub const JSHTTPSServer = struct { @export(HTTPSServer.getPendingWebSockets, .{ .name = "HTTPSServerPrototype__getPendingWebSockets" }); @export(HTTPSServer.getPort, .{ .name = "HTTPSServerPrototype__getPort" }); @export(HTTPSServer.getProtocol, .{ .name = "HTTPSServerPrototype__getProtocol" }); + @export(HTTPSServer.getURL, .{ .name = "HTTPSServerPrototype__getURL" }); } } }; @@ -3424,6 +3436,9 @@ pub const JSHTTPServer = struct { @compileLog("Expected HTTPServer.doStop to be a callback but received " ++ @typeName(@TypeOf(HTTPServer.doStop))); if (@TypeOf(HTTPServer.doUpgrade) != CallbackType) @compileLog("Expected HTTPServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(HTTPServer.doUpgrade))); + if (@TypeOf(HTTPServer.getURL) != GetterType) + @compileLog("Expected HTTPServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(HTTPServer.doFetch, .{ .name = "HTTPServerPrototype__doFetch" }); @export(HTTPServer.doPublish, .{ .name = "HTTPServerPrototype__doPublish" }); @@ -3438,6 +3453,7 @@ pub const JSHTTPServer = struct { @export(HTTPServer.getPendingWebSockets, .{ .name = "HTTPServerPrototype__getPendingWebSockets" }); @export(HTTPServer.getPort, .{ .name = "HTTPServerPrototype__getPort" }); @export(HTTPServer.getProtocol, .{ .name = "HTTPServerPrototype__getProtocol" }); + @export(HTTPServer.getURL, .{ .name = "HTTPServerPrototype__getURL" }); } } }; @@ -7067,6 +7083,74 @@ pub const JSTranspiler = struct { } } }; +pub const JSURL = struct { + const URL = Classes.URL; + const GetterType = fn (*URL, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const GetterTypeWithThisValue = fn (*URL, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const SetterType = fn (*URL, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const SetterTypeWithThisValue = fn (*URL, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const CallbackType = fn (*URL, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue; + + /// Return the pointer to the wrapped object. + /// If the object does not match the type, return null. + pub fn fromJS(value: JSC.JSValue) ?*URL { + JSC.markBinding(@src()); + return URL__fromJS(value); + } + + /// Get the URL constructor value. + /// This loads lazily from the global object. + pub fn getConstructor(globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + return URL__getConstructor(globalObject); + } + + /// Create a new instance of URL + pub fn toJS(this: *URL, globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + if (comptime Environment.allow_assert) { + const value__ = URL__create(globalObject, this); + std.debug.assert(value__.as(URL).? == this); // If this fails, likely a C ABI issue. + return value__; + } else { + return URL__create(globalObject, this); + } + } + + /// Modify the internal ptr to point to a new instance of URL. + pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*URL) bool { + JSC.markBinding(@src()); + return URL__dangerouslySetPtr(value, ptr); + } + + /// Detach the ptr from the thisValue + pub fn detachPtr(_: *URL, value: JSC.JSValue) void { + JSC.markBinding(@src()); + std.debug.assert(URL__dangerouslySetPtr(value, null)); + } + + extern fn URL__fromJS(JSC.JSValue) ?*URL; + extern fn URL__getConstructor(*JSC.JSGlobalObject) JSC.JSValue; + + extern fn URL__create(globalObject: *JSC.JSGlobalObject, ptr: ?*URL) JSC.JSValue; + + extern fn URL__dangerouslySetPtr(JSC.JSValue, ?*URL) bool; + + comptime { + if (@TypeOf(URL.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*URL)) { + @compileLog("URL.constructor is not a constructor"); + } + + if (@TypeOf(URL.finalize) != (fn (*URL) callconv(.C) void)) { + @compileLog("URL.finalize is not a finalizer"); + } + + if (!JSC.is_bindgen) { + @export(URL.constructor, .{ .name = "URLClass__construct" }); + @export(URL.finalize, .{ .name = "URLClass__finalize" }); + } + } +}; comptime { _ = JSAttributeIterator; @@ -7120,4 +7204,5 @@ comptime { _ = JSTextDecoder; _ = JSTimeout; _ = JSTranspiler; + _ = JSURL; } diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig index 3b45f33b880f..5bcd79ed2bb8 100644 --- a/src/bun.js/bindings/generated_classes_list.zig +++ b/src/bun.js/bindings/generated_classes_list.zig @@ -55,4 +55,5 @@ pub const Classes = struct { pub const DebugHTTPSServer = JSC.API.DebugHTTPSServer; pub const Crypto = JSC.WebCore.Crypto; pub const FFI = JSC.FFI; + pub const URL = JSC.URL; }; diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index caa7d3cd8ef2..1ef67248f3e4 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -78,7 +78,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("./config.zig"); -const URL = @import("../url.zig").URL; +const URL = bun.URL; const Bun = JSC.API.Bun; const EventLoop = JSC.EventLoop; const PendingResolution = @import("../resolver/resolver.zig").PendingResolution; diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index ca066450d2d9..9b56c3d64f9e 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -76,7 +76,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("./config.zig"); -const URL = @import("../url.zig").URL; +const URL = bun.URL; const Bun = JSC.API.Bun; const EventLoop = JSC.EventLoop; const PendingResolution = @import("../resolver/resolver.zig").PendingResolution; diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 96d1a00eff45..d01ec5c28360 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -14,7 +14,7 @@ pub const Buffer = JSC.MarkedArrayBuffer; const IdentityContext = @import("../../identity_context.zig").IdentityContext; const logger = @import("root").bun.logger; const Fs = @import("../../fs.zig"); -const URL = @import("../../url.zig").URL; +const URL = bun.URL; const Shimmer = @import("../bindings/shimmer.zig").Shimmer; const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false; const meta = bun.meta; diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 3617d5961337..476d85c232eb 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -4,7 +4,7 @@ const js_parser = bun.js_parser; const js_ast = bun.JSAst; const Api = @import("../../api/schema.zig").Api; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const Environment = bun.Environment; diff --git a/src/bun.js/url.classes.ts b/src/bun.js/url.classes.ts new file mode 100644 index 000000000000..6638b4430e1e --- /dev/null +++ b/src/bun.js/url.classes.ts @@ -0,0 +1,14 @@ +import { define } from "./scripts/class-definitions"; + +export default [ + define({ + name: "URL", + construct: true, + finalize: true, + configurable: false, + klass: {}, + JSType: "0b11101110", + proto: { + }, + }) +] \ No newline at end of file diff --git a/src/url.zig b/src/bun.js/url.zig similarity index 98% rename from src/url.zig rename to src/bun.js/url.zig index 064481257e22..b454dde1f1eb 100644 --- a/src/url.zig +++ b/src/bun.js/url.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const Api = @import("./api/schema.zig").Api; -const resolve_path = @import("./resolver/resolve_path.zig"); +const Api = @import("../api/schema.zig").Api; +const resolve_path = @import("../resolver/resolve_path.zig"); const bun = @import("root").bun; const string = bun.string; const Output = bun.Output; @@ -12,6 +12,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const JSC = bun.JSC; +const CppURL = @import("./bindings/bindings.zig").CppURL; // This is close to WHATWG URL, but we don't want the validation errors pub const URL = struct { @@ -36,17 +37,29 @@ pub const URL = struct { username: string = "", port_was_automatically_set: bool = false, - pub fn isFile(this: *const URL) bool { - return strings.eqlComptime(this.protocol, "file"); + pub usingnamespace JSC.Codegen.JSURL; + pub usingnamespace CppURL; + + pub fn constructor( + globalThis: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) ?*URL { + globalThis.throw("URL is not constructable", .{}); + return null; } - pub fn fromJS(js_value: JSC.JSValue, globalObject: *JSC.JSGlobalObject, allocator: std.mem.Allocator) !URL { - var href = JSC.URL.hrefFromJS(globalObject, js_value); - if (href.tag == .Dead) { - return error.InvalidURL; - } + pub fn finalize(_: *URL) callconv(.C) void {} - return URL.parse(try href.toOwnedSlice(allocator)); + pub fn create( + globalThis: *JSC.JSGlobalObject, + allocator: std.mem.Allocator, + ) JSC.JSValue { + var build_error = allocator.create(JSC.URL) catch unreachable; + return build_error.toJS(globalThis, allocator); + } + + pub fn isFile(this: *const URL) bool { + return strings.eqlComptime(this.protocol, "file"); } pub fn fromString(allocator: std.mem.Allocator, input: bun.String) !URL { @@ -1270,7 +1283,7 @@ pub const FormData = struct { } }; -const ParamsList = @import("./router.zig").Param.List; +const ParamsList = @import("../router.zig").Param.List; pub const CombinedScanner = struct { query: Scanner, pathname: PathnameScanner, diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index b0f1df935df3..fdfc769d739c 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index bbdf21d5d135..66cc04b8738c 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig index 8ffbd3fd0f13..74c5236be52c 100644 --- a/src/bun.js/webcore/encoding.zig +++ b/src/bun.js/webcore/encoding.zig @@ -1,7 +1,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig index db073fccc52f..c76fef7e7cfe 100644 --- a/src/bun.js/webcore/request.zig +++ b/src/bun.js/webcore/request.zig @@ -3,7 +3,7 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const RequestContext = @import("../../bun_dev_http_server.zig").RequestContext; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 0e80adfc4a54..5e5086614ea1 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -3,7 +3,7 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const RequestContext = @import("../../bun_dev_http_server.zig").RequestContext; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const HTTPClient = @import("root").bun.HTTP; const FetchRedirect = HTTPClient.FetchRedirect; const NetworkThread = HTTPClient.NetworkThread; @@ -1970,7 +1970,7 @@ pub const Fetch = struct { if (is_file_url) { defer allocator.free(url_proxy_buffer); var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - const PercentEncoding = @import("../../url.zig").PercentEncoding; + const PercentEncoding = bun.PercentEncoding; var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; var stream = std.io.fixedBufferStream(&path_buf2); const url_path_decoded = path_buf2[0 .. PercentEncoding.decode( diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index b96721e6e17a..c38c78585f56 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = @import("../../url.zig").URL; +const ZigURL = bun.URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.zig b/src/bun.zig index c7b15340e21d..844fb9e8b376 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -1034,8 +1034,11 @@ pub fn zero(comptime Type: type) Type { return @as(Type, @bitCast(out)); } pub const c_ares = @import("./deps/c_ares.zig"); -pub const URL = @import("./url.zig").URL; -pub const FormData = @import("./url.zig").FormData; +pub const URL = @import("./bun.js/url.zig").URL; +pub const FormData = @import("./bun.js/url.zig").FormData; +pub const QueryStringMap = @import("./bun.js/url.zig").QueryStringMap; +pub const PercentEncoding = @import("./bun.js/url.zig").PercentEncoding; +pub const CombinedScanner = @import("./bun.js/url.zig").CombinedScanner; var needs_proc_self_workaround: bool = false; diff --git a/src/bun_dev_http_server.zig b/src/bun_dev_http_server.zig index 6dfc24889e04..2c4fb5aae7b2 100644 --- a/src/bun_dev_http_server.zig +++ b/src/bun_dev_http_server.zig @@ -67,7 +67,7 @@ const JavaScriptCore = JavaScriptCore.C; const Syscall = bun.sys; const Router = @import("./router.zig"); pub const Watcher = watcher.NewWatcher(*Server); -const ZigURL = @import("./url.zig").URL; +const ZigURL = bun.URL; const HTTPStatusCode = u10; const URLPath = @import("./http/url_path.zig"); diff --git a/src/bundler.zig b/src/bundler.zig index 920f658c3705..70e42700b094 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -45,7 +45,7 @@ const Lock = @import("./lock.zig").Lock; const NodeFallbackModules = @import("./node_fallbacks.zig"); const CacheEntry = @import("./cache.zig").FsCacheEntry; const Analytics = @import("./analytics/analytics_thread.zig"); -const URL = @import("./url.zig").URL; +const URL = bun.URL; const Report = @import("./report.zig"); const Linker = linker.Linker; const Resolver = _resolver.Resolver; diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index e5b73814c5bf..bb26ebfb518a 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -96,7 +96,7 @@ const Lock = @import("../lock.zig").Lock; const NodeFallbackModules = @import("../node_fallbacks.zig"); const CacheEntry = @import("../cache.zig").FsCacheEntry; const Analytics = @import("../analytics/analytics_thread.zig"); -const URL = @import("../url.zig").URL; +const URL = bun.URL; const Report = @import("../report.zig"); const Linker = linker.Linker; const Resolver = _resolver.Resolver; diff --git a/src/bunfig.zig b/src/bunfig.zig index a777475da521..a436c11f5963 100644 --- a/src/bunfig.zig +++ b/src/bunfig.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const URL = @import("./url.zig").URL; +const URL = bun.URL; const C = bun.C; const options = @import("./options.zig"); const logger = @import("root").bun.logger; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index b052a11df624..a8977e0215d7 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -28,7 +28,7 @@ const Command = @import("../cli.zig").Command; const bundler = bun.bundler; const fs = @import("../fs.zig"); -const URL = @import("../url.zig").URL; +const URL = bun.URL; const HTTP = @import("root").bun.HTTP; const NetworkThread = HTTP.NetworkThread; const ParseJSON = @import("../json_parser.zig").ParseJSONUTF8; diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index 1d67a7b39aa6..6c24a8877bdd 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -27,7 +27,7 @@ const Command = @import("../cli.zig").Command; const bundler = bun.bundler; const fs = @import("../fs.zig"); -const URL = @import("../url.zig").URL; +const URL = bun.URL; const ParseJSON = @import("../json_parser.zig").ParseJSON; const Archive = @import("../libarchive/libarchive.zig").Archive; const Zlib = @import("../zlib.zig"); diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index 60ae953d3946..bafeb4abeb00 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -27,7 +27,7 @@ const Command = @import("../cli.zig").Command; const bundler = bun.bundler; const fs = @import("../fs.zig"); -const URL = @import("../url.zig").URL; +const URL = bun.URL; const HTTP = @import("root").bun.HTTP; const ParseJSON = @import("../json_parser.zig").ParseJSONUTF8; const Archive = @import("../libarchive/libarchive.zig").Archive; diff --git a/src/css_scanner.zig b/src/css_scanner.zig index 45651d84956f..31e82aa9058b 100644 --- a/src/css_scanner.zig +++ b/src/css_scanner.zig @@ -19,7 +19,7 @@ const logger = @import("root").bun.logger; const Options = options; const resolver = @import("./resolver/resolver.zig"); const _linker = @import("./linker.zig"); -const URL = @import("./url.zig").URL; +const URL = bun.URL; const replacementCharacter: CodePoint = 0xFFFD; pub const Chunk = struct { diff --git a/src/env_loader.zig b/src/env_loader.zig index 213d14ab89fa..0754b9e884a9 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -14,7 +14,7 @@ const C = bun.C; const CodepointIterator = @import("./string_immutable.zig").CodepointIterator; const Analytics = @import("./analytics/analytics_thread.zig"); const Fs = @import("./fs.zig"); -const URL = @import("./url.zig").URL; +const URL = bun.URL; const Api = @import("./api/schema.zig").Api; const which = @import("./which.zig").which; diff --git a/src/http/url_path.zig b/src/http/url_path.zig index a48700671ea7..09d671e50c4b 100644 --- a/src/http/url_path.zig +++ b/src/http/url_path.zig @@ -10,7 +10,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; -const PercentEncoding = @import("../url.zig").PercentEncoding; +const PercentEncoding = bun.PercentEncoding; const std = @import("std"); const allocators = @import("../allocators.zig"); const URLPath = @This(); diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 1b03483a005f..56a8ef2f61b2 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -14,8 +14,8 @@ const Loc = bun.logger.Loc; const Log = bun.logger.Log; const DotEnv = @import("./env_loader.zig"); const std = @import("std"); -const URL = @import("./url.zig").URL; -const PercentEncoding = @import("./url.zig").PercentEncoding; +const URL = bun.URL; +const PercentEncoding = bun.PercentEncoding; pub const Method = @import("./http/method.zig").Method; const Api = @import("./api/schema.zig").Api; const Lock = @import("./lock.zig").Lock; diff --git a/src/install/install.zig b/src/install/install.zig index 96f6f7b3e109..3946af009dec 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -33,7 +33,7 @@ const Run = @import("../bun_js.zig").Run; const Fs = @import("../fs.zig"); const FileSystem = Fs.FileSystem; const Lock = @import("../lock.zig").Lock; -const URL = @import("../url.zig").URL; +const URL = bun.URL; const HTTP = bun.HTTP; const AsyncHTTP = HTTP.AsyncHTTP; const HTTPChannel = HTTP.HTTPChannel; diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index fd742d559181..0ff7761e7e32 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -37,7 +37,7 @@ const HeaderBuilder = bun.HTTP.HeaderBuilder; const Fs = @import("../fs.zig"); const FileSystem = Fs.FileSystem; const Lock = @import("../lock.zig").Lock; -const URL = @import("../url.zig").URL; +const URL = bun.URL; const AsyncHTTP = bun.HTTP.AsyncHTTP; const HTTPChannel = bun.HTTP.HTTPChannel; const NetworkThread = bun.HTTP.NetworkThread; diff --git a/src/install/npm.zig b/src/install/npm.zig index 24e6318361f3..10ddab7b9756 100644 --- a/src/install/npm.zig +++ b/src/install/npm.zig @@ -1,4 +1,4 @@ -const URL = @import("../url.zig").URL; +const URL = bun.URL; const bun = @import("root").bun; const std = @import("std"); const MutableString = @import("../string_mutable.zig").MutableString; diff --git a/src/jsc.zig b/src/jsc.zig index e5be26321001..0e91815a8f24 100644 --- a/src/jsc.zig +++ b/src/jsc.zig @@ -13,6 +13,7 @@ pub usingnamespace @import("./bun.js/module_loader.zig"); pub const C = @import("./bun.js/javascript_core_c_api.zig"); pub const WebCore = @import("./bun.js/webcore.zig"); pub const BuildMessage = @import("./bun.js/BuildMessage.zig").BuildMessage; +pub const URL = @import("./bun.js/url.zig").URL; pub const ResolveMessage = @import("./bun.js/ResolveMessage.zig").ResolveMessage; pub const Cloudflare = struct { pub const HTMLRewriter = @import("./bun.js/api/html_rewriter.zig").HTMLRewriter; diff --git a/src/linker.zig b/src/linker.zig index e4cf171c092a..854327819d01 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -38,7 +38,7 @@ const ResolveQueue = _bundler.ResolveQueue; const ResolverType = Resolver.Resolver; const ESModule = @import("./resolver/package_json.zig").ESModule; const Runtime = @import("./runtime.zig").Runtime; -const URL = @import("url.zig").URL; +const URL = bun.URL; const JSC = @import("root").bun.JSC; const PluginRunner = bun.bundler.PluginRunner; pub const CSSResolveError = error{ResolveMessage}; diff --git a/src/options.zig b/src/options.zig index 73ca9a64bf36..7159efaa83dd 100644 --- a/src/options.zig +++ b/src/options.zig @@ -9,7 +9,7 @@ const api = @import("./api/schema.zig"); const Api = api.Api; const defines = @import("./defines.zig"); const resolve_path = @import("./resolver/resolve_path.zig"); -const URL = @import("./url.zig").URL; +const URL = bun.URL; const ConditionsMap = @import("./resolver/package_json.zig").ESModule.ConditionsMap; const bun = @import("root").bun; const string = bun.string; diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 165da7b5301a..7bac9f53b9f3 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -1478,7 +1478,7 @@ pub const ESModule = struct { // If resolved contains any percent encodings of "/" or "\" ("%2f" and "%5C" // respectively), then throw an Invalid Module Specifier error. - const PercentEncoding = @import("../url.zig").PercentEncoding; + const PercentEncoding = bun.PercentEncoding; var fbs = std.io.fixedBufferStream(&resolved_path_buf_percent); var writer = fbs.writer(); const len = PercentEncoding.decode(@TypeOf(&writer), &writer, result.path) catch return Resolution{ diff --git a/src/router.zig b/src/router.zig index 51047d9b5e5e..74341b44bd4f 100644 --- a/src/router.zig +++ b/src/router.zig @@ -25,7 +25,7 @@ const Fs = @import("./fs.zig"); const Options = @import("./options.zig"); const allocators = @import("./allocators.zig"); const URLPath = @import("./http/url_path.zig"); -const PathnameScanner = @import("./url.zig").PathnameScanner; +const PathnameScanner = bun.PathnameScanner; const CodepointIterator = @import("./string_immutable.zig").CodepointIterator; const index_route_hash = @as(u32, @truncate(bun.hash("$$/index-route$$-!(@*@#&*%-901823098123"))); diff --git a/test/bun.lockb b/test/bun.lockb index 8abf35b6ff041640b56fbf2c031e2a1a6b78ed18..8013f6948caddf4b895a42192ce1e7bd22c61fd5 100755 GIT binary patch delta 26416 zcmeHw2Yi&p*7q|D3wZ*8KnNskLI^!Tdcr0Ivh<#WDjiK(VAC5Vv@9rs2m(Ih(7Vba zh^Poykb3C?Vxx#42tsgYq7g*?NNofe!k zTuB076>>*GPD;8xwJ;5Op5XKCsUve7`AWXMASZLQU5Q1b0gBSn8Hxl|6bP&W9GOgg zLvJ7?Lk6P)GB629y&VW^$e@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k>w4J#T`G;E4cB^E46l6~_&8p1Sy;5!DkBh7XKNM?Q}fdP0G=%ko!)-c9zX zv_m(qf11tV=gH6@UiB8tX7EP0uwG5%dABelOVaq(Tg&~PdxAr z%83Bd8b#U%vVdOA$WEKK0`X->_*A6@9~!Eq_1KPmK^As_)x1YUAK++(zF$ z;e$s0wW_X@dmVC~;HlrjS$*rS;Rb=ed;8&q(oK+C*5gFxjj?${x!u10HB-ydg8J6& z$Mk)>MgR)REAw5eH%uLI+r8e2Qq{XrJnTChnDxC|uSDOz{qRe}r0-CPaVh`c8u!%7 z0p8!2meludKYW0}#;rHRxYu8czZpE@ndfGesxIO8VTre9yYe&h$5~jlPqVlDe^yZMqvid*CP=i{DhTdEgINql}BD&s?9ygBPqn zR;poKMZIFng^ZFxz1EcGgz!;6pq<9u)wOD_yte7pz}lq>Px4hzz#GV~0{o4;uScac ztu!qs8I3fYSf9hcCMS$br)%7OZ2b|B4?Wzl_TsY~=9F za$h@FjL#B3L8~gX_RaaOo%dIH2TQdo@v0?Qj($(UV^1+dN8{Vt627biv;9H|i*%lE zE9Tsc*qC?OgvTBjH`bRt+abQ{TWjAO>=>=T>(*$;Cui$_#1_%T Date: Sun, 24 Sep 2023 01:27:10 -0400 Subject: [PATCH 2/9] progress2 --- src/bun.js/api/server.zig | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 10b4b9db0a96..08258712d6f7 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -5221,10 +5221,29 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp this: *ThisServer, globalThis: *JSC.JSGlobalObject, ) callconv(.C) JSC.JSValue { - const pathParts = [_]string{ this.cached_hostname.toUTF8(this.allocator), this.getPort().toString().toUTF8(this.allocator) }; - return URL.fromString(this.allocator, strings.concat(this.allocator, &pathParts)).toJS(globalThis); - } - + const protocol = this.getProtocol(globalThis).toSlice(globalThis, this.allocator).slice(); + const hostname = this.getHostname(globalThis).toSlice(globalThis, this.allocator).slice(); + const port = this.getPort(globalThis).toSlice(globalThis, this.allocator).slice(); + const url_string = strings.concat(this.allocator, &.{ protocol, hostname, ":", port }) catch "http://www.google.com"; + var tmp = URL.parse(url_string); + return tmp.toJS(globalThis); + } + + // pub fn getURL( + // this: *ThisServer, + // globalThis: *JSC.JSGlobalObject, + // ) callconv(.C) JSC.JSValue { + // const protocol = this.getProtocol(globalThis).toSlice(globalThis, this.allocator).slice(); + // const hostname = this.getHostname(globalThis).toSlice(globalThis, this.allocator).slice(); + // const port = this.getPort(globalThis).toSlice(globalThis, this.allocator).slice(); + + // if (strings.concat(this.allocator, &.{ protocol, hostname, ":", port })) |url_string| { + // if (URL.fromUTF8(this.allocator, url_string)) |url| { + // return url.toJS(globalThis); + // } + // } + // return JSValue.jsUndefined(); + // } pub fn onRequestComplete(this: *ThisServer) void { this.vm.eventLoop().processGCTimer(); From 0a1878042c406d21d2fd563369ca1ea000c1da89 Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Sun, 24 Sep 2023 14:19:02 -0400 Subject: [PATCH 3/9] check in --- src/bun.js/api/server.zig | 19 +++++++++- src/bun.js/bindings/ZigGeneratedClasses.cpp | 37 ++++++++++++++++++- src/bun.js/bindings/generated_classes.zig | 3 ++ src/bun.js/url.classes.ts | 4 ++ src/bun.js/url.zig | 24 ++++++++++++ test/js/bun/ffi/ffi.test.fixture.callback.c | 3 -- .../prisma/prisma/postgres/schema.prisma | 2 +- .../prisma/prisma/sqlite/schema.prisma | 2 +- 8 files changed, 86 insertions(+), 8 deletions(-) diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 08258712d6f7..830f195fab32 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -5226,7 +5226,24 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp const port = this.getPort(globalThis).toSlice(globalThis, this.allocator).slice(); const url_string = strings.concat(this.allocator, &.{ protocol, hostname, ":", port }) catch "http://www.google.com"; var tmp = URL.parse(url_string); - return tmp.toJS(globalThis); + var url = bun.default_allocator.create(URL) catch @panic("Unable to allocate URL"); + url.* = URL{ + .hash = tmp.hash, + .host = tmp.host, + .hostname = tmp.hostname, + .href = tmp.href, + .origin = tmp.origin, + .password = tmp.password, + .pathname = tmp.pathname, + .path = tmp.path, + .port = tmp.port, + .protocol = tmp.protocol, + .search = tmp.search, + .searchParams = null, // FIXME + .username = tmp.username, + .port_was_automatically_set = tmp.port_was_automatically_set, + }; + return url.toJS(globalThis); } // pub fn getURL( diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index 162d30ac03f1..4c85121ca80f 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -27702,9 +27702,14 @@ JSC_DECLARE_CUSTOM_GETTER(jsURLConstructor); extern "C" void URLClass__finalize(void*); +extern "C" EncodedJSValue URLPrototype__toJSON(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(URLPrototype__toJSONCallback); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSURLPrototype, JSURLPrototype::Base); -static const HashTableValue JSURLPrototypeTableValues[] = {}; +static const HashTableValue JSURLPrototypeTableValues[] = { + { "toJSON"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, URLPrototype__toJSONCallback, 0 } } +}; const ClassInfo JSURLPrototype::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLPrototype) }; @@ -27720,10 +27725,38 @@ JSC_DEFINE_CUSTOM_GETTER(jsURLConstructor, (JSGlobalObject * lexicalGlobalObject return JSValue::encode(globalObject->JSURLConstructor()); } +JSC_DEFINE_HOST_FUNCTION(URLPrototype__toJSONCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSURL* thisObject = jsDynamicCast(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + throwVMTypeError(lexicalGlobalObject, throwScope, "Expected 'this' to be instanceof URL"_s); + return JSValue::encode({}); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return URLPrototype__toJSON(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + void JSURLPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); - + reifyStaticProperties(vm, JSURL::info(), JSURLPrototypeTableValues, *this); JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); } diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 50ff62dc3aeb..62614f75061d 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -7145,9 +7145,12 @@ pub const JSURL = struct { @compileLog("URL.finalize is not a finalizer"); } + if (@TypeOf(URL.toJSON) != CallbackType) + @compileLog("Expected URL.toJSON to be a callback but received " ++ @typeName(@TypeOf(URL.toJSON))); if (!JSC.is_bindgen) { @export(URL.constructor, .{ .name = "URLClass__construct" }); @export(URL.finalize, .{ .name = "URLClass__finalize" }); + @export(URL.toJSON, .{ .name = "URLPrototype__toJSON" }); } } }; diff --git a/src/bun.js/url.classes.ts b/src/bun.js/url.classes.ts index 6638b4430e1e..9c040f66020d 100644 --- a/src/bun.js/url.classes.ts +++ b/src/bun.js/url.classes.ts @@ -9,6 +9,10 @@ export default [ klass: {}, JSType: "0b11101110", proto: { + ["toJSON"]: { + fn: "toJSON", + length: 0, + }, }, }) ] \ No newline at end of file diff --git a/src/bun.js/url.zig b/src/bun.js/url.zig index b454dde1f1eb..03ccfb6a3af1 100644 --- a/src/bun.js/url.zig +++ b/src/bun.js/url.zig @@ -12,6 +12,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const JSC = bun.JSC; +const ZigString = JSC.ZigString; const CppURL = @import("./bindings/bindings.zig").CppURL; // This is close to WHATWG URL, but we don't want the validation errors @@ -50,6 +51,29 @@ pub const URL = struct { pub fn finalize(_: *URL) callconv(.C) void {} + pub fn toJSON( + this: *URL, + globalThis: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + var object = JSC.JSValue.createEmptyObject(globalThis, 3); + object.put(globalThis, ZigString.static("name"), ZigString.init("URL").toValueGC(globalThis)); + object.put(globalThis, ZigString.static("hash"), ZigString.init(this.hash).toValueGC(globalThis)); + object.put(globalThis, ZigString.static("host"), ZigString.init(this.host).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("hostname"), ZigString.init(this.hostname).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("href"), ZigString.init(this.href).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("origin"), ZigString.init(this.origin).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("password"), ZigString.init(this.password).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("pathname"), ZigString.init(this.pathname).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("port"), ZigString.init(this.port).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("protocol"), ZigString.init(this.protocol).toValueGC(globalThis)); + // object.put(globalThis, ZigString.static("search"), ZigString.init(this.search).toValueGC(globalThis)); + // // object.put(globalThis, ZigString.static("searchParams"), this.searchParams); + // object.put(globalThis, ZigString.static("username"), ZigString.init(this.username).toValueGC(globalThis)); + + return object; + } + pub fn create( globalThis: *JSC.JSGlobalObject, allocator: std.mem.Allocator, diff --git a/test/js/bun/ffi/ffi.test.fixture.callback.c b/test/js/bun/ffi/ffi.test.fixture.callback.c index 3b9a46577770..624f6cdd018b 100644 --- a/test/js/bun/ffi/ffi.test.fixture.callback.c +++ b/test/js/bun/ffi/ffi.test.fixture.callback.c @@ -286,9 +286,6 @@ ZIG_REPR_TYPE JSFunctionCall(void* jsGlobalObject, void* callFrame); bool my_callback_function(void* arg0); bool my_callback_function(void* arg0) { -#ifdef INJECT_BEFORE -INJECT_BEFORE; -#endif ZIG_REPR_TYPE arguments[1]; arguments[0] = PTR_TO_JSVALUE(arg0).asZigRepr; return (bool)JSVALUE_TO_BOOL(_FFI_Callback_call((void*)0x0000000000000000ULL, 1, arguments)); diff --git a/test/js/third_party/prisma/prisma/postgres/schema.prisma b/test/js/third_party/prisma/prisma/postgres/schema.prisma index afbd6f39a63d..753a23847f76 100644 --- a/test/js/third_party/prisma/prisma/postgres/schema.prisma +++ b/test/js/third_party/prisma/prisma/postgres/schema.prisma @@ -4,7 +4,7 @@ generator client { provider = "prisma-client-js" output = "client" - %binaryTargets% + binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl", "linux-musl-openssl-3.0.x"] } datasource db { diff --git a/test/js/third_party/prisma/prisma/sqlite/schema.prisma b/test/js/third_party/prisma/prisma/sqlite/schema.prisma index bbe3292cbf33..267947ce1286 100644 --- a/test/js/third_party/prisma/prisma/sqlite/schema.prisma +++ b/test/js/third_party/prisma/prisma/sqlite/schema.prisma @@ -4,7 +4,7 @@ generator client { provider = "prisma-client-js" output = "client" - %binaryTargets% + binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl", "linux-musl-openssl-3.0.x"] } datasource db { From 8c33e38f6e41bc760776d44fd50da0e5810459a6 Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Tue, 26 Sep 2023 01:12:40 -0400 Subject: [PATCH 4/9] check in --- packages/bun-types/bun.d.ts | 5 + src/bun.js/api/server.zig | 50 ++--- src/bun.js/bindings/ZigGeneratedClasses.cpp | 194 +++++++++++++++++++- src/bun.js/bindings/generated_classes.zig | 48 +++++ src/bun.js/url.classes.ts | 36 ++++ src/bun.js/url.zig | 102 ++++++++-- test/js/bun/http/bun-server.test.ts | 54 ++++++ 7 files changed, 438 insertions(+), 51 deletions(-) diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index 35f206634b86..713f6067718c 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -2373,6 +2373,11 @@ declare module "bun" { * When bun is not started with the `--hot` flag, this ID is currently unused. */ readonly id: string; + + /** + * A URL object representing the address the server is listening on. + */ + readonly url: URL; } /** diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 830f195fab32..7b55f13de19f 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -5221,46 +5221,28 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp this: *ThisServer, globalThis: *JSC.JSGlobalObject, ) callconv(.C) JSC.JSValue { - const protocol = this.getProtocol(globalThis).toSlice(globalThis, this.allocator).slice(); - const hostname = this.getHostname(globalThis).toSlice(globalThis, this.allocator).slice(); - const port = this.getPort(globalThis).toSlice(globalThis, this.allocator).slice(); - const url_string = strings.concat(this.allocator, &.{ protocol, hostname, ":", port }) catch "http://www.google.com"; - var tmp = URL.parse(url_string); + var base_url = this.config.base_url; var url = bun.default_allocator.create(URL) catch @panic("Unable to allocate URL"); + url.* = URL{ - .hash = tmp.hash, - .host = tmp.host, - .hostname = tmp.hostname, - .href = tmp.href, - .origin = tmp.origin, - .password = tmp.password, - .pathname = tmp.pathname, - .path = tmp.path, - .port = tmp.port, - .protocol = tmp.protocol, - .search = tmp.search, - .searchParams = null, // FIXME - .username = tmp.username, - .port_was_automatically_set = tmp.port_was_automatically_set, + .hash = base_url.hash, + .host = base_url.host, + .hostname = base_url.hostname, + .href = base_url.href, + .origin = base_url.origin, + .password = base_url.password, + .pathname = base_url.pathname, + .path = base_url.path, + .port = base_url.port, + .protocol = base_url.protocol, + .search = base_url.search, + .searchParams = null, // no search params for server URL + .username = base_url.username, + .port_was_automatically_set = base_url.port_was_automatically_set, }; return url.toJS(globalThis); } - // pub fn getURL( - // this: *ThisServer, - // globalThis: *JSC.JSGlobalObject, - // ) callconv(.C) JSC.JSValue { - // const protocol = this.getProtocol(globalThis).toSlice(globalThis, this.allocator).slice(); - // const hostname = this.getHostname(globalThis).toSlice(globalThis, this.allocator).slice(); - // const port = this.getPort(globalThis).toSlice(globalThis, this.allocator).slice(); - - // if (strings.concat(this.allocator, &.{ protocol, hostname, ":", port })) |url_string| { - // if (URL.fromUTF8(this.allocator, url_string)) |url| { - // return url.toJS(globalThis); - // } - // } - // return JSValue.jsUndefined(); - // } pub fn onRequestComplete(this: *ThisServer) void { this.vm.eventLoop().processGCTimer(); diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index 4c85121ca80f..07bed7d344d2 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -27702,13 +27702,61 @@ JSC_DECLARE_CUSTOM_GETTER(jsURLConstructor); extern "C" void URLClass__finalize(void*); +extern "C" JSC::EncodedJSValue URLPrototype__getHash(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hashGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getHost(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hostGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getHostname(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hostnameGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getHref(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hrefGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getOrigin(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__originGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getPassword(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__passwordGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getPathname(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__pathnameGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getPortJS(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__portGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getProtocol(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__protocolGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getSearch(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__searchGetterWrap); + +extern "C" JSC::EncodedJSValue URLPrototype__getSearchParams(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__searchParamsGetterWrap); + extern "C" EncodedJSValue URLPrototype__toJSON(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(URLPrototype__toJSONCallback); +extern "C" JSC::EncodedJSValue URLPrototype__getUsername(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(URLPrototype__usernameGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSURLPrototype, JSURLPrototype::Base); static const HashTableValue JSURLPrototypeTableValues[] = { - { "toJSON"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, URLPrototype__toJSONCallback, 0 } } + { "hash"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hashGetterWrap, 0 } }, + { "host"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hostGetterWrap, 0 } }, + { "hostname"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hostnameGetterWrap, 0 } }, + { "href"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hrefGetterWrap, 0 } }, + { "origin"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__originGetterWrap, 0 } }, + { "password"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__passwordGetterWrap, 0 } }, + { "pathname"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__pathnameGetterWrap, 0 } }, + { "port"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__portGetterWrap, 0 } }, + { "protocol"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__protocolGetterWrap, 0 } }, + { "search"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__searchGetterWrap, 0 } }, + { "searchParams"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__searchParamsGetterWrap, 0 } }, + { "toJSON"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, URLPrototype__toJSONCallback, 0 } }, + { "username"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__usernameGetterWrap, 0 } } }; const ClassInfo JSURLPrototype::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLPrototype) }; @@ -27725,6 +27773,138 @@ JSC_DEFINE_CUSTOM_GETTER(jsURLConstructor, (JSGlobalObject * lexicalGlobalObject return JSValue::encode(globalObject->JSURLConstructor()); } +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hashGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getHash(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hostGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getHost(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hostnameGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getHostname(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hrefGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getHref(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__originGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getOrigin(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__passwordGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getPassword(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__pathnameGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getPathname(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__portGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getPortJS(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__protocolGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getProtocol(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__searchGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getSearch(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__searchParamsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getSearchParams(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + JSC_DEFINE_HOST_FUNCTION(URLPrototype__toJSONCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) { auto& vm = lexicalGlobalObject->vm(); @@ -27753,6 +27933,18 @@ JSC_DEFINE_HOST_FUNCTION(URLPrototype__toJSONCallback, (JSGlobalObject * lexical return URLPrototype__toJSON(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(URLPrototype__usernameGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSURL* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = URLPrototype__getUsername(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSURLPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 62614f75061d..5817394c65ed 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -7145,11 +7145,59 @@ pub const JSURL = struct { @compileLog("URL.finalize is not a finalizer"); } + if (@TypeOf(URL.getHash) != GetterType) + @compileLog("Expected URL.getHash to be a getter"); + + if (@TypeOf(URL.getHost) != GetterType) + @compileLog("Expected URL.getHost to be a getter"); + + if (@TypeOf(URL.getHostname) != GetterType) + @compileLog("Expected URL.getHostname to be a getter"); + + if (@TypeOf(URL.getHref) != GetterType) + @compileLog("Expected URL.getHref to be a getter"); + + if (@TypeOf(URL.getOrigin) != GetterType) + @compileLog("Expected URL.getOrigin to be a getter"); + + if (@TypeOf(URL.getPassword) != GetterType) + @compileLog("Expected URL.getPassword to be a getter"); + + if (@TypeOf(URL.getPathname) != GetterType) + @compileLog("Expected URL.getPathname to be a getter"); + + if (@TypeOf(URL.getPortJS) != GetterType) + @compileLog("Expected URL.getPortJS to be a getter"); + + if (@TypeOf(URL.getProtocol) != GetterType) + @compileLog("Expected URL.getProtocol to be a getter"); + + if (@TypeOf(URL.getSearch) != GetterType) + @compileLog("Expected URL.getSearch to be a getter"); + + if (@TypeOf(URL.getSearchParams) != GetterType) + @compileLog("Expected URL.getSearchParams to be a getter"); + if (@TypeOf(URL.toJSON) != CallbackType) @compileLog("Expected URL.toJSON to be a callback but received " ++ @typeName(@TypeOf(URL.toJSON))); + if (@TypeOf(URL.getUsername) != GetterType) + @compileLog("Expected URL.getUsername to be a getter"); + if (!JSC.is_bindgen) { @export(URL.constructor, .{ .name = "URLClass__construct" }); @export(URL.finalize, .{ .name = "URLClass__finalize" }); + @export(URL.getHash, .{ .name = "URLPrototype__getHash" }); + @export(URL.getHost, .{ .name = "URLPrototype__getHost" }); + @export(URL.getHostname, .{ .name = "URLPrototype__getHostname" }); + @export(URL.getHref, .{ .name = "URLPrototype__getHref" }); + @export(URL.getOrigin, .{ .name = "URLPrototype__getOrigin" }); + @export(URL.getPassword, .{ .name = "URLPrototype__getPassword" }); + @export(URL.getPathname, .{ .name = "URLPrototype__getPathname" }); + @export(URL.getPortJS, .{ .name = "URLPrototype__getPortJS" }); + @export(URL.getProtocol, .{ .name = "URLPrototype__getProtocol" }); + @export(URL.getSearch, .{ .name = "URLPrototype__getSearch" }); + @export(URL.getSearchParams, .{ .name = "URLPrototype__getSearchParams" }); + @export(URL.getUsername, .{ .name = "URLPrototype__getUsername" }); @export(URL.toJSON, .{ .name = "URLPrototype__toJSON" }); } } diff --git a/src/bun.js/url.classes.ts b/src/bun.js/url.classes.ts index 9c040f66020d..8c4a96d6c70b 100644 --- a/src/bun.js/url.classes.ts +++ b/src/bun.js/url.classes.ts @@ -9,6 +9,42 @@ export default [ klass: {}, JSType: "0b11101110", proto: { + hash: { + getter: "getHash", + }, + host: { + getter: "getHost", + }, + hostname: { + getter: "getHostname", + }, + href: { + getter: "getHref", + }, + origin: { + getter: "getOrigin", + }, + password: { + getter: "getPassword", + }, + pathname: { + getter: "getPathname", + }, + port: { + getter: "getPortJS", + }, + protocol: { + getter: "getProtocol", + }, + search: { + getter: "getSearch", + }, + searchParams: { + getter: "getSearchParams", + }, + username: { + getter: "getUsername", + }, ["toJSON"]: { fn: "toJSON", length: 0, diff --git a/src/bun.js/url.zig b/src/bun.js/url.zig index 03ccfb6a3af1..3a2c7613feaf 100644 --- a/src/bun.js/url.zig +++ b/src/bun.js/url.zig @@ -51,27 +51,97 @@ pub const URL = struct { pub fn finalize(_: *URL) callconv(.C) void {} + pub fn getHash( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.hash).toJSConst(globalThis); + } + + pub fn getHost( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.host).toJSConst(globalThis); + } + + pub fn getHostname( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.hostname).toJSConst(globalThis); + } + + pub fn getHref( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.href).toJSConst(globalThis); + } + + pub fn getOrigin( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.origin).toJSConst(globalThis); + } + + pub fn getPassword( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.password).toJSConst(globalThis); + } + + pub fn getPathname( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.pathname).toJSConst(globalThis); + } + + pub fn getPortJS( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.port).toJSConst(globalThis); + } + + pub fn getProtocol( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.protocol).toJSConst(globalThis); + } + + pub fn getSearch( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.search).toJSConst(globalThis); + } + + pub fn getSearchParams( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + _ = this; + return JSC.JSValue.createEmptyObject(globalThis, 0); + } + + pub fn getUsername( + this: *URL, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return bun.String.init(this.username).toJSConst(globalThis); + } + pub fn toJSON( this: *URL, globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { - var object = JSC.JSValue.createEmptyObject(globalThis, 3); - object.put(globalThis, ZigString.static("name"), ZigString.init("URL").toValueGC(globalThis)); - object.put(globalThis, ZigString.static("hash"), ZigString.init(this.hash).toValueGC(globalThis)); - object.put(globalThis, ZigString.static("host"), ZigString.init(this.host).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("hostname"), ZigString.init(this.hostname).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("href"), ZigString.init(this.href).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("origin"), ZigString.init(this.origin).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("password"), ZigString.init(this.password).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("pathname"), ZigString.init(this.pathname).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("port"), ZigString.init(this.port).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("protocol"), ZigString.init(this.protocol).toValueGC(globalThis)); - // object.put(globalThis, ZigString.static("search"), ZigString.init(this.search).toValueGC(globalThis)); - // // object.put(globalThis, ZigString.static("searchParams"), this.searchParams); - // object.put(globalThis, ZigString.static("username"), ZigString.init(this.username).toValueGC(globalThis)); - - return object; + return this.getHref(globalThis); } pub fn create( diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index e82e2cab00cf..f08c4cf02e8d 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -379,4 +379,58 @@ describe("Server", () => { await proc.exited; expect(proc.exitCode).toBe(0); }); + + test("server should have URL fields set", async () => { + const server = Bun.serve({ + fetch(req) { + return new Response("Hello World!"); + }, + }); + try { + expect(server.url.hash).toBe(""); + expect(server.url.host).toBe(`0.0.0.0:${server.port}`); + expect(server.url.hostname).toBe("0.0.0.0"); + expect(server.url.href).toBe(`http://0.0.0.0:${server.port}/`); + expect(server.url.origin).toBe(`http://0.0.0.0:${server.port}`); + expect(server.url.password).toBe(""); + expect(server.url.pathname).toBe("/"); + expect(server.url.port).toBe(`${server.port}`); + expect(server.url.protocol).toBe("http"); + expect(server.url.search).toBe(""); + expect(server.url.username).toBe(""); + expect(server.url.searchParams).toEqual({}); + expect(server.url.toJSON()).toBe(`http://0.0.0.0:${server.port}/`); + } finally { + server.stop(true); + } + }); + + + test("server should have URL fields set with IPv6", async () => { + const server = Bun.serve({ + hostname: "[::1]", + fetch() { + return new Response("Hello"); + }, + port: 0, + }); + try { + expect(server.url.hash).toBe(""); + expect(server.url.host).toStartWith("[::1]"); + expect(server.url.hostname).toBe("[::1]"); + expect(server.url.href).toStartWith("http://[::1]:"); + expect(server.url.href).toEndWith("/"); + expect(server.url.origin).toStartWith("http://[::1]:"); + expect(server.url.password).toBe(""); + expect(server.url.pathname).toBe("/"); + expect(server.url.port).toBeDefined(); + expect(server.url.protocol).toBe("http"); + expect(server.url.search).toBe(""); + expect(server.url.username).toBe(""); + expect(server.url.searchParams).toEqual({}); + expect(server.url.toJSON()).toStartWith("http://[::1]:"); + } finally { + server.stop(true); + } + }); }); From 86a3e2f7394ed82e5b893a9c996668dc2f09442c Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Tue, 26 Sep 2023 01:27:53 -0400 Subject: [PATCH 5/9] format --- src/bun.js/url.classes.ts | 102 ++++++++++++++-------------- test/js/bun/http/bun-server.test.ts | 1 - 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/bun.js/url.classes.ts b/src/bun.js/url.classes.ts index 8c4a96d6c70b..12ed62428d26 100644 --- a/src/bun.js/url.classes.ts +++ b/src/bun.js/url.classes.ts @@ -1,54 +1,54 @@ import { define } from "./scripts/class-definitions"; export default [ - define({ - name: "URL", - construct: true, - finalize: true, - configurable: false, - klass: {}, - JSType: "0b11101110", - proto: { - hash: { - getter: "getHash", - }, - host: { - getter: "getHost", - }, - hostname: { - getter: "getHostname", - }, - href: { - getter: "getHref", - }, - origin: { - getter: "getOrigin", - }, - password: { - getter: "getPassword", - }, - pathname: { - getter: "getPathname", - }, - port: { - getter: "getPortJS", - }, - protocol: { - getter: "getProtocol", - }, - search: { - getter: "getSearch", - }, - searchParams: { - getter: "getSearchParams", - }, - username: { - getter: "getUsername", - }, - ["toJSON"]: { - fn: "toJSON", - length: 0, - }, - }, - }) -] \ No newline at end of file + define({ + name: "URL", + construct: true, + finalize: true, + configurable: false, + klass: {}, + JSType: "0b11101110", + proto: { + hash: { + getter: "getHash", + }, + host: { + getter: "getHost", + }, + hostname: { + getter: "getHostname", + }, + href: { + getter: "getHref", + }, + origin: { + getter: "getOrigin", + }, + password: { + getter: "getPassword", + }, + pathname: { + getter: "getPathname", + }, + port: { + getter: "getPortJS", + }, + protocol: { + getter: "getProtocol", + }, + search: { + getter: "getSearch", + }, + searchParams: { + getter: "getSearchParams", + }, + username: { + getter: "getUsername", + }, + ["toJSON"]: { + fn: "toJSON", + length: 0, + }, + }, + }), +]; diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index f08c4cf02e8d..48f29056ef8f 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -405,7 +405,6 @@ describe("Server", () => { } }); - test("server should have URL fields set with IPv6", async () => { const server = Bun.serve({ hostname: "[::1]", From 091d5e4f0488444f8adf04519699023d6e8c8c59 Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Tue, 26 Sep 2023 01:42:40 -0400 Subject: [PATCH 6/9] revert third_party file change --- test/js/third_party/prisma/prisma/postgres/schema.prisma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js/third_party/prisma/prisma/postgres/schema.prisma b/test/js/third_party/prisma/prisma/postgres/schema.prisma index 753a23847f76..afbd6f39a63d 100644 --- a/test/js/third_party/prisma/prisma/postgres/schema.prisma +++ b/test/js/third_party/prisma/prisma/postgres/schema.prisma @@ -4,7 +4,7 @@ generator client { provider = "prisma-client-js" output = "client" - binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl", "linux-musl-openssl-3.0.x"] + %binaryTargets% } datasource db { From 4e8429e8b44bcfc683a4fce4ddbf63e9e33c3ef7 Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Tue, 26 Sep 2023 21:36:38 -0400 Subject: [PATCH 7/9] restore lockfile to prior state --- test/bun.lockb | Bin 163311 -> 162926 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/bun.lockb b/test/bun.lockb index 8013f6948caddf4b895a42192ce1e7bd22c61fd5..8abf35b6ff041640b56fbf2c031e2a1a6b78ed18 100755 GIT binary patch delta 26659 zcmeHw30zgx_W#*eu5wUv00q1#AP%7dGI>FiE6%9koI|1_UiB&p0uDIci^F?brsC1I z=9HH6Y?fk~(qIl*scD&0R+@8JSwRlJ?>c)Q;q{u{`@Q#mzyJT&`Ly`%wf5R;uf6x$ z!@c*o`|2n4_K)iPu#o&3d2hd5{k55IwQO{;&h_mEG;^q8178_(M^5J85%%=lp3tiTKHHu?Jkyb_WZQExGsfAK5L6nVD9u~}NRXkb zz{h~Y)2MA|4TR)KCm0|HZ9r;m61*XY7HF%OkJ<|&;yP+YEWp_qI$q%H6YS|}u+a$y ziEjxct<2H(T*oN8GRiT^ksdm9bTs5-Gb=53c<4xb-s6%F08*XRfaHTakbJxkhU|LP8}L17XB98%RyLhmzC<7h#bs?W+A~yhDd(qz&5up5(b{S!sha>`J(7 zdOaYu2xDds9Wq$)1y5c46Dp|%w2!lo&PB+a1`m&%u1P_nKsJ#2&fuMBJ~?s_iWHH% zfaK76QP4FvSaeM>kSfdvQbnVHP;sRJsmTRksEft}sev)|MUVvotJ4^~iv$_)0HU$3 z?hS;YFY74^Y`6{q5&EuV7$64<9v3Y!g(wP=u7QyI0y{PoV-p3W3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p8Xn*qB7Yy-u+abcl`lqs_W*yX z_kq3Xr_?d8-xH1XpU6}0vOAvn_TicMU%v!r*$b1?k_(eJ55C8udo}&7I5ar)x1wP2 N<>KbN9;W-D{{=kTvTgtX From c679d406edba93f6892507b7278a3322a8389323 Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Tue, 26 Sep 2023 21:54:33 -0400 Subject: [PATCH 8/9] revert all changes --- misctools/fetch.zig | 2 +- misctools/http_bench.zig | 2 +- misctools/machbench.zig | 2 +- packages/bun-types/bun.d.ts | 5 - src/analytics/analytics_thread.zig | 2 +- src/bun.js/api/JSBundler.zig | 4 +- src/bun.js/api/JSTranspiler.zig | 4 +- src/bun.js/api/bun.zig | 2 +- src/bun.js/api/ffi.zig | 6 +- src/bun.js/api/filesystem_router.zig | 6 +- src/bun.js/api/server.classes.ts | 3 - src/bun.js/api/server.zig | 28 +- src/bun.js/bindings/BunString.cpp | 27 + ...igGeneratedClasses+DOMClientIsoSubspaces.h | 3 +- .../ZigGeneratedClasses+DOMIsoSubspaces.h | 3 +- .../ZigGeneratedClasses+lazyStructureHeader.h | 6 +- .../ZigGeneratedClasses+lazyStructureImpl.h | 7 - src/bun.js/bindings/ZigGeneratedClasses.cpp | 538 +----------------- src/bun.js/bindings/ZigGeneratedClasses.h | 50 -- src/bun.js/bindings/bindings.zig | 18 +- src/bun.js/bindings/exports.zig | 2 +- src/bun.js/bindings/generated_classes.zig | 136 ----- .../bindings/generated_classes_list.zig | 1 - src/bun.js/javascript.zig | 2 +- src/bun.js/module_loader.zig | 2 +- src/bun.js/node/types.zig | 2 +- src/bun.js/test/jest.zig | 2 +- src/bun.js/url.classes.ts | 54 -- src/bun.js/webcore/blob.zig | 2 +- src/bun.js/webcore/body.zig | 2 +- src/bun.js/webcore/encoding.zig | 2 +- src/bun.js/webcore/request.zig | 2 +- src/bun.js/webcore/response.zig | 4 +- src/bun.js/webcore/streams.zig | 2 +- src/bun.zig | 7 +- src/bun_dev_http_server.zig | 2 +- src/bundler.zig | 2 +- src/bundler/bundle_v2.zig | 2 +- src/bunfig.zig | 2 +- src/cli/create_command.zig | 2 +- src/cli/install_completions_command.zig | 2 +- src/cli/upgrade_command.zig | 2 +- src/css_scanner.zig | 2 +- src/env_loader.zig | 2 +- src/http/url_path.zig | 2 +- src/http_client_async.zig | 4 +- src/install/install.zig | 2 +- src/install/lockfile.zig | 2 +- src/install/npm.zig | 2 +- src/jsc.zig | 1 - src/linker.zig | 2 +- src/options.zig | 2 +- src/resolver/package_json.zig | 2 +- src/router.zig | 2 +- src/{bun.js => }/url.zig | 129 +---- test/js/bun/ffi/ffi.test.fixture.callback.c | 3 + test/js/bun/http/bun-server.test.ts | 53 -- .../prisma/prisma/sqlite/schema.prisma | 2 +- 58 files changed, 114 insertions(+), 1052 deletions(-) delete mode 100644 src/bun.js/url.classes.ts rename src/{bun.js => }/url.zig (95%) diff --git a/misctools/fetch.zig b/misctools/fetch.zig index ac6cf575d4cf..347ce8cde841 100644 --- a/misctools/fetch.zig +++ b/misctools/fetch.zig @@ -13,7 +13,7 @@ pub usingnamespace @import("root").bun; const clap = bun.clap; -const URL = bun.URL; +const URL = @import("../src/url.zig").URL; const Headers = @import("root").bun.HTTP.Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; diff --git a/misctools/http_bench.zig b/misctools/http_bench.zig index fe98027fad8c..1759e630dddf 100644 --- a/misctools/http_bench.zig +++ b/misctools/http_bench.zig @@ -11,7 +11,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const clap = @import("../src/deps/zig-clap/clap.zig"); -const URL = bun.URL; +const URL = @import("../src/url.zig").URL; const Headers = @import("../src/bun.js/webcore/response.zig").Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; diff --git a/misctools/machbench.zig b/misctools/machbench.zig index 569bcdec5c0c..5da20b5bad7d 100644 --- a/misctools/machbench.zig +++ b/misctools/machbench.zig @@ -13,7 +13,7 @@ const C = bun.C; const clap = @import("../src/deps/zig-clap/clap.zig"); const AsyncIO = @import("root").bun.AsyncIO; -const URL = bun.URL; +const URL = @import("../src/url.zig").URL; const Headers = @import("root").bun.HTTP.Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index 713f6067718c..35f206634b86 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -2373,11 +2373,6 @@ declare module "bun" { * When bun is not started with the `--hot` flag, this ID is currently unused. */ readonly id: string; - - /** - * A URL object representing the address the server is listening on. - */ - readonly url: URL; } /** diff --git a/src/analytics/analytics_thread.zig b/src/analytics/analytics_thread.zig index 53c420683217..b0ee2cdbc02a 100644 --- a/src/analytics/analytics_thread.zig +++ b/src/analytics/analytics_thread.zig @@ -14,7 +14,7 @@ const sync = @import("../sync.zig"); const std = @import("std"); const HTTP = @import("root").bun.HTTP; const NetworkThread = HTTP.NetworkThread; -const URL = bun.URL; +const URL = @import("../url.zig").URL; const Fs = @import("../fs.zig"); const Analytics = @import("./analytics_schema.zig").analytics; const Writer = @import("./analytics_schema.zig").Writer; diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 14a72f8fa80b..4a4d10f0f2a8 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -2,8 +2,8 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const http = @import("../../bun_dev_http_server.zig"); const JavaScript = @import("../javascript.zig"); -const QueryStringMap = bun.QueryStringMap; -const CombinedScanner = bun.CombinedScanner; +const QueryStringMap = @import("../../url.zig").QueryStringMap; +const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; const string = bun.string; const JSC = bun.JSC; diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig index 51f75f623692..8cec025eb4be 100644 --- a/src/bun.js/api/JSTranspiler.zig +++ b/src/bun.js/api/JSTranspiler.zig @@ -2,8 +2,8 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const http = @import("../../bun_dev_http_server.zig"); const JavaScript = @import("../javascript.zig"); -const QueryStringMap = bun.QueryStringMap; -const CombinedScanner = bun.CombinedScanner; +const QueryStringMap = @import("../../url.zig").QueryStringMap; +const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; const string = bun.string; const JSC = bun.JSC; diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index 9a482ea14352..966c82d383e0 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -224,7 +224,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("../config.zig"); -const URL = bun.URL; +const URL = @import("../../url.zig").URL; const Transpiler = bun.JSC.API.JSTranspiler; const JSBundler = bun.JSC.API.JSBundler; const VirtualMachine = JSC.VirtualMachine; diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index b02e4d48b1e2..234b588887ba 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -70,7 +70,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("../config.zig"); -const URL = bun.URL; +const URL = @import("../../url.zig").URL; const VirtualMachine = JSC.VirtualMachine; const IOTask = JSC.IOTask; const ComptimeStringMap = @import("../../comptime_string_map.zig").ComptimeStringMap; @@ -317,9 +317,9 @@ pub const FFI = struct { }; }; }; - + var size = symbols.values().len; - if (size >= 63) { + if(size >= 63) { size = 0; } var obj = JSC.JSValue.createEmptyObject(global, size); diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index febb8ff7e98a..f3306629842e 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -2,9 +2,9 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const http = @import("../../bun_dev_http_server.zig"); const JavaScript = @import("../javascript.zig"); +const QueryStringMap = @import("../../url.zig").QueryStringMap; +const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; -const QueryStringMap = bun.QueryStringMap; -const CombinedScanner = bun.CombinedScanner; const string = bun.string; const JSC = @import("root").bun.JSC; const js = JSC.C; @@ -26,7 +26,7 @@ const To = Base.To; const Request = WebCore.Request; const URLPath = @import("../../http/url_path.zig"); -const URL = bun.URL; +const URL = @import("../../url.zig").URL; const Log = @import("root").bun.logger; const Resolver = @import("../../resolver/resolver.zig").Resolver; const Router = @import("../../router.zig"); diff --git a/src/bun.js/api/server.classes.ts b/src/bun.js/api/server.classes.ts index 0d3298bb2947..544f37ce6a1e 100644 --- a/src/bun.js/api/server.classes.ts +++ b/src/bun.js/api/server.classes.ts @@ -47,9 +47,6 @@ function generate(name) { development: { getter: "getDevelopment", }, - url: { - getter: "getURL", - }, }, klass: {}, finalize: true, diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 7470e381783c..14e636a2b4ae 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -69,7 +69,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("../config.zig"); -const URL = bun.URL; +const URL = @import("../../url.zig").URL; const VirtualMachine = JSC.VirtualMachine; const IOTask = JSC.IOTask; const is_bindgen = JSC.is_bindgen; @@ -5226,32 +5226,6 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp return JSC.JSValue.jsBoolean(debug_mode); } - pub fn getURL( - this: *ThisServer, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - var base_url = this.config.base_url; - var url = bun.default_allocator.create(URL) catch @panic("Unable to allocate URL"); - - url.* = URL{ - .hash = base_url.hash, - .host = base_url.host, - .hostname = base_url.hostname, - .href = base_url.href, - .origin = base_url.origin, - .password = base_url.password, - .pathname = base_url.pathname, - .path = base_url.path, - .port = base_url.port, - .protocol = base_url.protocol, - .search = base_url.search, - .searchParams = null, // no search params for server URL - .username = base_url.username, - .port_was_automatically_set = base_url.port_was_automatically_set, - }; - return url.toJS(globalThis); - } - pub fn onRequestComplete(this: *ThisServer) void { this.vm.eventLoop().processGCTimer(); diff --git a/src/bun.js/bindings/BunString.cpp b/src/bun.js/bindings/BunString.cpp index 829415b43cf3..416d5d334080 100644 --- a/src/bun.js/bindings/BunString.cpp +++ b/src/bun.js/bindings/BunString.cpp @@ -337,6 +337,23 @@ extern "C" BunString URL__getFileURLString(BunString* filePath) return Bun::toStringRef(WTF::URL::fileURLWithFileSystemPath(Bun::toWTFString(*filePath)).stringWithoutFragmentIdentifier()); } +extern "C" WTF::URL* URL__fromJS(EncodedJSValue encodedValue, JSC::JSGlobalObject* globalObject) +{ + auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); + JSC::JSValue value = JSC::JSValue::decode(encodedValue); + auto str = value.toWTFString(globalObject); + RETURN_IF_EXCEPTION(throwScope, nullptr); + if (str.isEmpty()) { + return nullptr; + } + + auto url = WTF::URL(str); + if (!url.isValid() || url.isNull()) + return nullptr; + + return new WTF::URL(WTFMove(url)); +} + extern "C" BunString URL__getHrefFromJS(EncodedJSValue encodedValue, JSC::JSGlobalObject* globalObject) { auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); @@ -375,6 +392,16 @@ extern "C" BunString URL__getHrefJoin(BunString* baseStr, BunString *relativeStr return Bun::toStringRef(url.string()); } +extern "C" WTF::URL* URL__fromString(BunString* input) +{ + auto&& str = Bun::toWTFString(*input); + auto url = WTF::URL(str); + if (!url.isValid()) + return nullptr; + + return new WTF::URL(WTFMove(url)); +} + extern "C" BunString URL__protocol(WTF::URL* url) { return Bun::toStringRef(url->protocol().toStringWithoutCopying()); diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h index 57d74af4e1d4..cef5c512a7c5 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h @@ -49,5 +49,4 @@ std::unique_ptr m_clientSubspaceForTextChunk; std::unique_ptr m_clientSubspaceForTextDecoder; std::unique_ptr m_clientSubspaceForTextDecoderConstructor;std::unique_ptr m_clientSubspaceForTimeout; std::unique_ptr m_clientSubspaceForTranspiler; -std::unique_ptr m_clientSubspaceForTranspilerConstructor;std::unique_ptr m_clientSubspaceForURL; -std::unique_ptr m_clientSubspaceForURLConstructor; \ No newline at end of file +std::unique_ptr m_clientSubspaceForTranspilerConstructor; \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h index 3cc6b92f945d..d06451eda044 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h @@ -49,5 +49,4 @@ std::unique_ptr m_subspaceForTextChunk; std::unique_ptr m_subspaceForTextDecoder; std::unique_ptr m_subspaceForTextDecoderConstructor;std::unique_ptr m_subspaceForTimeout; std::unique_ptr m_subspaceForTranspiler; -std::unique_ptr m_subspaceForTranspilerConstructor;std::unique_ptr m_subspaceForURL; -std::unique_ptr m_subspaceForURLConstructor; \ No newline at end of file +std::unique_ptr m_subspaceForTranspilerConstructor; \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h index 98a994c5e670..381378262f36 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h @@ -201,8 +201,4 @@ JSC::Structure* JSTimeoutStructure() { return m_JSTimeout.getInitializedOnMainTh JSC::Structure* JSTranspilerStructure() { return m_JSTranspiler.getInitializedOnMainThread(this); } JSC::JSObject* JSTranspilerConstructor() { return m_JSTranspiler.constructorInitializedOnMainThread(this); } JSC::JSValue JSTranspilerPrototype() { return m_JSTranspiler.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSTranspiler; -JSC::Structure* JSURLStructure() { return m_JSURL.getInitializedOnMainThread(this); } - JSC::JSObject* JSURLConstructor() { return m_JSURL.constructorInitializedOnMainThread(this); } - JSC::JSValue JSURLPrototype() { return m_JSURL.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSURL; \ No newline at end of file + JSC::LazyClassStructure m_JSTranspiler; \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h index 5cf191133a33..84d3df7a0542 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h @@ -305,12 +305,6 @@ ALWAYS_INLINE void GlobalObject::initGeneratedLazyClasses() { init.setStructure(WebCore::JSTranspiler::createStructure(init.vm, init.global, init.prototype)); init.setConstructor(WebCore::JSTranspiler::createConstructor(init.vm, init.global, init.prototype)); }); - m_JSURL.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSURL::createPrototype(init.vm, reinterpret_cast(init.global))); - init.setStructure(WebCore::JSURL::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSURL::createConstructor(init.vm, init.global, init.prototype)); - }); } template void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor) @@ -366,5 +360,4 @@ void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& thisObject->m_JSTextDecoder.visit(visitor); thisObject->m_JSTimeout.visit(visitor); thisObject->m_JSTranspiler.visit(visitor); - thisObject->m_JSURL.visit(visitor); } \ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index 07bed7d344d2..b84c1cd1644b 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -4203,9 +4203,6 @@ JSC_DECLARE_HOST_FUNCTION(DebugHTTPSServerPrototype__stopCallback); extern "C" EncodedJSValue DebugHTTPSServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(DebugHTTPSServerPrototype__upgradeCallback); -extern "C" JSC::EncodedJSValue DebugHTTPSServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(DebugHTTPSServerPrototype__urlGetterWrap); - STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDebugHTTPSServerPrototype, JSDebugHTTPSServerPrototype::Base); static const HashTableValue JSDebugHTTPSServerPrototypeTableValues[] = { @@ -4220,8 +4217,7 @@ static const HashTableValue JSDebugHTTPSServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__upgradeCallback, 1 } }, - { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, DebugHTTPSServerPrototype__urlGetterWrap, 0 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__upgradeCallback, 1 } } }; const ClassInfo JSDebugHTTPSServerPrototype::s_info = { "DebugHTTPSServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDebugHTTPSServerPrototype) }; @@ -4500,18 +4496,6 @@ JSC_DEFINE_HOST_FUNCTION(DebugHTTPSServerPrototype__upgradeCallback, (JSGlobalOb return DebugHTTPSServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } -JSC_DEFINE_CUSTOM_GETTER(DebugHTTPSServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSDebugHTTPSServer* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = DebugHTTPSServerPrototype__getURL(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - void JSDebugHTTPSServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -4701,9 +4685,6 @@ JSC_DECLARE_HOST_FUNCTION(DebugHTTPServerPrototype__stopCallback); extern "C" EncodedJSValue DebugHTTPServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(DebugHTTPServerPrototype__upgradeCallback); -extern "C" JSC::EncodedJSValue DebugHTTPServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(DebugHTTPServerPrototype__urlGetterWrap); - STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDebugHTTPServerPrototype, JSDebugHTTPServerPrototype::Base); static const HashTableValue JSDebugHTTPServerPrototypeTableValues[] = { @@ -4718,8 +4699,7 @@ static const HashTableValue JSDebugHTTPServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__upgradeCallback, 1 } }, - { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, DebugHTTPServerPrototype__urlGetterWrap, 0 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__upgradeCallback, 1 } } }; const ClassInfo JSDebugHTTPServerPrototype::s_info = { "DebugHTTPServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDebugHTTPServerPrototype) }; @@ -4998,18 +4978,6 @@ JSC_DEFINE_HOST_FUNCTION(DebugHTTPServerPrototype__upgradeCallback, (JSGlobalObj return DebugHTTPServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } -JSC_DEFINE_CUSTOM_GETTER(DebugHTTPServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSDebugHTTPServer* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = DebugHTTPServerPrototype__getURL(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - void JSDebugHTTPServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -11658,9 +11626,6 @@ JSC_DECLARE_HOST_FUNCTION(HTTPSServerPrototype__stopCallback); extern "C" EncodedJSValue HTTPSServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(HTTPSServerPrototype__upgradeCallback); -extern "C" JSC::EncodedJSValue HTTPSServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(HTTPSServerPrototype__urlGetterWrap); - STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSHTTPSServerPrototype, JSHTTPSServerPrototype::Base); static const HashTableValue JSHTTPSServerPrototypeTableValues[] = { @@ -11675,8 +11640,7 @@ static const HashTableValue JSHTTPSServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__upgradeCallback, 1 } }, - { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, HTTPSServerPrototype__urlGetterWrap, 0 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__upgradeCallback, 1 } } }; const ClassInfo JSHTTPSServerPrototype::s_info = { "HTTPSServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTTPSServerPrototype) }; @@ -11955,18 +11919,6 @@ JSC_DEFINE_HOST_FUNCTION(HTTPSServerPrototype__upgradeCallback, (JSGlobalObject return HTTPSServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } -JSC_DEFINE_CUSTOM_GETTER(HTTPSServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSHTTPSServer* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = HTTPSServerPrototype__getURL(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - void JSHTTPSServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -12156,9 +12108,6 @@ JSC_DECLARE_HOST_FUNCTION(HTTPServerPrototype__stopCallback); extern "C" EncodedJSValue HTTPServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(HTTPServerPrototype__upgradeCallback); -extern "C" JSC::EncodedJSValue HTTPServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(HTTPServerPrototype__urlGetterWrap); - STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSHTTPServerPrototype, JSHTTPServerPrototype::Base); static const HashTableValue JSHTTPServerPrototypeTableValues[] = { @@ -12173,8 +12122,7 @@ static const HashTableValue JSHTTPServerPrototypeTableValues[] = { { "publish"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__publishCallback, 3 } }, { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__reloadCallback, 2 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__upgradeCallback, 1 } }, - { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, HTTPServerPrototype__urlGetterWrap, 0 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__upgradeCallback, 1 } } }; const ClassInfo JSHTTPServerPrototype::s_info = { "HTTPServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTTPServerPrototype) }; @@ -12453,18 +12401,6 @@ JSC_DEFINE_HOST_FUNCTION(HTTPServerPrototype__upgradeCallback, (JSGlobalObject * return HTTPServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } -JSC_DEFINE_CUSTOM_GETTER(HTTPServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSHTTPServer* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = HTTPServerPrototype__getURL(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - void JSHTTPServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -27629,472 +27565,6 @@ extern "C" EncodedJSValue Transpiler__create(Zig::GlobalObject* globalObject, vo return JSValue::encode(instance); } -class JSURLPrototype final : public JSC::JSNonFinalObject { -public: - using Base = JSC::JSNonFinalObject; - - static JSURLPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) - { - JSURLPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSURLPrototype(vm, globalObject, structure); - ptr->finishCreation(vm, globalObject); - return ptr; - } - - DECLARE_INFO; - template - static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - return &vm.plainObjectSpace(); - } - 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: - JSURLPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) - : Base(vm, structure) - { - } - - void finishCreation(JSC::VM&, JSC::JSGlobalObject*); -}; - -class JSURLConstructor final : public JSC::InternalFunction { -public: - using Base = JSC::InternalFunction; - static JSURLConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSURLPrototype* prototype); - - static constexpr unsigned StructureFlags = Base::StructureFlags; - static constexpr bool needsDestruction = false; - - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) - { - return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); - } - - template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - if constexpr (mode == JSC::SubspaceAccess::Concurrently) - return nullptr; - return WebCore::subspaceForImpl( - vm, - [](auto& spaces) { return spaces.m_clientSubspaceForURLConstructor.get(); }, - [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForURLConstructor = std::forward(space); }, - [](auto& spaces) { return spaces.m_subspaceForURLConstructor.get(); }, - [](auto& spaces, auto&& space) { spaces.m_subspaceForURLConstructor = std::forward(space); }); - } - - void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype); - - // Must be defined for each specialization class. - static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*); - - DECLARE_EXPORT_INFO; - -private: - JSURLConstructor(JSC::VM& vm, JSC::Structure* structure); - void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype); -}; - -extern "C" void* URLClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*); -JSC_DECLARE_CUSTOM_GETTER(jsURLConstructor); - -extern "C" void URLClass__finalize(void*); - -extern "C" JSC::EncodedJSValue URLPrototype__getHash(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hashGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getHost(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hostGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getHostname(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hostnameGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getHref(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__hrefGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getOrigin(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__originGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getPassword(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__passwordGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getPathname(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__pathnameGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getPortJS(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__portGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getProtocol(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__protocolGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getSearch(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__searchGetterWrap); - -extern "C" JSC::EncodedJSValue URLPrototype__getSearchParams(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__searchParamsGetterWrap); - -extern "C" EncodedJSValue URLPrototype__toJSON(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); -JSC_DECLARE_HOST_FUNCTION(URLPrototype__toJSONCallback); - -extern "C" JSC::EncodedJSValue URLPrototype__getUsername(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); -JSC_DECLARE_CUSTOM_GETTER(URLPrototype__usernameGetterWrap); - -STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSURLPrototype, JSURLPrototype::Base); - -static const HashTableValue JSURLPrototypeTableValues[] = { - { "hash"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hashGetterWrap, 0 } }, - { "host"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hostGetterWrap, 0 } }, - { "hostname"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hostnameGetterWrap, 0 } }, - { "href"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__hrefGetterWrap, 0 } }, - { "origin"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__originGetterWrap, 0 } }, - { "password"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__passwordGetterWrap, 0 } }, - { "pathname"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__pathnameGetterWrap, 0 } }, - { "port"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__portGetterWrap, 0 } }, - { "protocol"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__protocolGetterWrap, 0 } }, - { "search"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__searchGetterWrap, 0 } }, - { "searchParams"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__searchParamsGetterWrap, 0 } }, - { "toJSON"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, URLPrototype__toJSONCallback, 0 } }, - { "username"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, URLPrototype__usernameGetterWrap, 0 } } -}; - -const ClassInfo JSURLPrototype::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLPrototype) }; - -JSC_DEFINE_CUSTOM_GETTER(jsURLConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) -{ - VM& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto* globalObject = reinterpret_cast(lexicalGlobalObject); - auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - - if (UNLIKELY(!prototype)) - return throwVMTypeError(lexicalGlobalObject, throwScope, "Cannot get constructor for URL"_s); - return JSValue::encode(globalObject->JSURLConstructor()); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hashGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getHash(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hostGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getHost(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hostnameGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getHostname(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__hrefGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getHref(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__originGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getOrigin(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__passwordGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getPassword(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__pathnameGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getPathname(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__portGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getPortJS(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__protocolGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getProtocol(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__searchGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getSearch(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__searchParamsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getSearchParams(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -JSC_DEFINE_HOST_FUNCTION(URLPrototype__toJSONCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - auto& vm = lexicalGlobalObject->vm(); - - JSURL* thisObject = jsDynamicCast(callFrame->thisValue()); - - if (UNLIKELY(!thisObject)) { - auto throwScope = DECLARE_THROW_SCOPE(vm); - throwVMTypeError(lexicalGlobalObject, throwScope, "Expected 'this' to be instanceof URL"_s); - return JSValue::encode({}); - } - - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - -#ifdef BUN_DEBUG - /** View the file name of the JS file that called this function - * from a debugger */ - SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); - const char* fileName = sourceOrigin.string().utf8().data(); - static const char* lastFileName = nullptr; - if (lastFileName != fileName) { - lastFileName = fileName; - } -#endif - - return URLPrototype__toJSON(thisObject->wrapped(), lexicalGlobalObject, callFrame); -} - -JSC_DEFINE_CUSTOM_GETTER(URLPrototype__usernameGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) -{ - auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSURL* thisObject = jsCast(JSValue::decode(thisValue)); - JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); - JSC::EncodedJSValue result = URLPrototype__getUsername(thisObject->wrapped(), globalObject); - RETURN_IF_EXCEPTION(throwScope, {}); - RELEASE_AND_RETURN(throwScope, result); -} - -void JSURLPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) -{ - Base::finishCreation(vm); - reifyStaticProperties(vm, JSURL::info(), JSURLPrototypeTableValues, *this); - JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); -} - -void JSURLConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype) -{ - Base::finishCreation(vm, 0, "URL"_s, PropertyAdditionMode::WithoutStructureTransition); - - putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); - ASSERT(inherits(info())); -} - -JSURLConstructor::JSURLConstructor(JSC::VM& vm, JSC::Structure* structure) - : Base(vm, structure, construct, construct) -{ -} - -JSURLConstructor* JSURLConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSURLPrototype* prototype) -{ - JSURLConstructor* ptr = new (NotNull, JSC::allocateCell(vm)) JSURLConstructor(vm, structure); - ptr->finishCreation(vm, globalObject, prototype); - return ptr; -} - -JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSURLConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) -{ - Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); - JSC::VM& vm = globalObject->vm(); - JSObject* newTarget = asObject(callFrame->newTarget()); - auto* constructor = globalObject->JSURLConstructor(); - Structure* structure = globalObject->JSURLStructure(); - if (constructor != newTarget) { - auto scope = DECLARE_THROW_SCOPE(vm); - - auto* functionGlobalObject = reinterpret_cast( - // ShadowRealm functions belong to a different global object. - getFunctionRealm(globalObject, newTarget)); - RETURN_IF_EXCEPTION(scope, {}); - structure = InternalFunction::createSubclassStructure( - globalObject, - newTarget, - functionGlobalObject->JSURLStructure()); - } - - void* ptr = URLClass__construct(globalObject, callFrame); - - if (UNLIKELY(!ptr)) { - return JSValue::encode(JSC::jsUndefined()); - } - - JSURL* instance = JSURL::create(vm, globalObject, structure, ptr); - - return JSValue::encode(instance); -} - -void JSURLConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSURLPrototype* prototype) -{ -} - -const ClassInfo JSURLConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURLConstructor) }; - -extern "C" EncodedJSValue URL__getConstructor(Zig::GlobalObject* globalObject) -{ - return JSValue::encode(globalObject->JSURLConstructor()); -} - -JSURL::~JSURL() -{ - if (m_ctx) { - URLClass__finalize(m_ctx); - } -} -void JSURL::destroy(JSCell* cell) -{ - static_cast(cell)->JSURL::~JSURL(); -} - -const ClassInfo JSURL::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSURL) }; - -void JSURL::finishCreation(VM& vm) -{ - Base::finishCreation(vm); - ASSERT(inherits(info())); -} - -JSURL* JSURL::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) -{ - JSURL* ptr = new (NotNull, JSC::allocateCell(vm)) JSURL(vm, structure, ctx); - ptr->finishCreation(vm); - return ptr; -} - -extern "C" void* URL__fromJS(JSC::EncodedJSValue value) -{ - JSC::JSValue decodedValue = JSC::JSValue::decode(value); - if (decodedValue.isEmpty() || !decodedValue.isCell()) - return nullptr; - - JSC::JSCell* cell = decodedValue.asCell(); - JSURL* object = JSC::jsDynamicCast(cell); - - if (!object) - return nullptr; - - return object->wrapped(); -} - -extern "C" bool URL__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) -{ - JSURL* object = JSC::jsDynamicCast(JSValue::decode(value)); - if (!object) - return false; - - object->m_ctx = ptr; - return true; -} - -extern "C" const size_t URL__ptrOffset = JSURL::offsetOfWrapped(); - -void JSURL::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) -{ - auto* thisObject = jsCast(cell); - if (void* wrapped = thisObject->wrapped()) { - // if (thisObject->scriptExecutionContext()) - // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); - } - Base::analyzeHeap(cell, analyzer); -} - -JSObject* JSURL::createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype) -{ - return WebCore::JSURLConstructor::create(vm, globalObject, WebCore::JSURLConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast(prototype)); -} - -JSObject* JSURL::createPrototype(VM& vm, JSDOMGlobalObject* globalObject) -{ - return JSURLPrototype::create(vm, globalObject, JSURLPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); -} - -extern "C" EncodedJSValue URL__create(Zig::GlobalObject* globalObject, void* ptr) -{ - auto& vm = globalObject->vm(); - JSC::Structure* structure = globalObject->JSURLStructure(); - JSURL* instance = JSURL::create(vm, globalObject, structure, ptr); - - return JSValue::encode(instance); -} std::optional StructuredCloneableSerialize::fromJS(JSC::JSValue value) { if (auto* result = jsDynamicCast(value)) { diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index 901d26e8c476..33aa5848775a 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -2952,56 +2952,6 @@ class JSTranspiler final : public JSC::JSDestructibleObject { void finishCreation(JSC::VM&); }; -class JSURL final : public JSC::JSDestructibleObject { -public: - using Base = JSC::JSDestructibleObject; - static JSURL* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); - - DECLARE_EXPORT_INFO; - template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - if constexpr (mode == JSC::SubspaceAccess::Concurrently) - return nullptr; - return WebCore::subspaceForImpl( - vm, - [](auto& spaces) { return spaces.m_clientSubspaceForURL.get(); }, - [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForURL = std::forward(space); }, - [](auto& spaces) { return spaces.m_subspaceForURL.get(); }, - [](auto& spaces, auto&& space) { spaces.m_subspaceForURL = std::forward(space); }); - } - - static void destroy(JSC::JSCell*); - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) - { - return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast(0b11101110), StructureFlags), info()); - } - - static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); - static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype); - - ~JSURL(); - - void* wrapped() const { return m_ctx; } - - void detach() - { - m_ctx = nullptr; - } - - static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); - static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSURL, m_ctx); } - - void* m_ctx { nullptr }; - - JSURL(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) - : Base(vm, structure) - { - m_ctx = sinkPtr; - } - - void finishCreation(JSC::VM&); -}; - class StructuredCloneableSerialize { public: void (*cppWriteBytes)(CloneSerializer*, const uint8_t*, uint32_t); diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 7688e97f3232..60f8f9376610 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -21,7 +21,6 @@ const MutableString = bun.MutableString; const JestPrettyFormat = @import("../test/pretty_format.zig").JestPrettyFormat; const String = bun.String; const ErrorableString = JSC.ErrorableString; -const URL = JSC.URL; pub const JSObject = extern struct { pub const shim = Shimmer("JSC", "JSObject", @This()); bytes: shim.Bytes, @@ -5480,7 +5479,9 @@ pub fn untrackFunction( return private.Bun__untrackFFIFunction(globalObject, value); } -pub const CppURL = opaque { +pub const URL = opaque { + extern fn URL__fromJS(JSValue, *JSC.JSGlobalObject) ?*URL; + extern fn URL__fromString(*bun.String) ?*URL; extern fn URL__protocol(*URL) String; extern fn URL__href(*URL) String; extern fn URL__username(*URL) String; @@ -5522,6 +5523,19 @@ pub const CppURL = opaque { return URL__getHrefFromJS(value, globalObject); } + pub fn fromJS(value: JSValue, globalObject: *JSC.JSGlobalObject) ?*URL { + JSC.markBinding(@src()); + return URL__fromJS(value, globalObject); + } + + pub fn fromUTF8(input: []const u8) ?*URL { + return fromString(String.fromUTF8(input)); + } + pub fn fromString(str: bun.String) ?*URL { + JSC.markBinding(@src()); + var input = str; + return URL__fromString(&input); + } pub fn protocol(url: *URL) String { JSC.markBinding(@src()); return URL__protocol(url); diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index 6ab8c3c451de..10326bc7c1b2 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -3,7 +3,7 @@ const Fs = @import("../../fs.zig"); const CAPI = JSC.C; const JS = @import("../javascript.zig"); const JSBase = @import("../base.zig"); -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const std = @import("std"); diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 5817394c65ed..581d4a5f398a 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -1331,9 +1331,6 @@ pub const JSDebugHTTPSServer = struct { @compileLog("Expected DebugHTTPSServer.doStop to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPSServer.doStop))); if (@TypeOf(DebugHTTPSServer.doUpgrade) != CallbackType) @compileLog("Expected DebugHTTPSServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPSServer.doUpgrade))); - if (@TypeOf(DebugHTTPSServer.getURL) != GetterType) - @compileLog("Expected DebugHTTPSServer.getURL to be a getter"); - if (!JSC.is_bindgen) { @export(DebugHTTPSServer.doFetch, .{ .name = "DebugHTTPSServerPrototype__doFetch" }); @export(DebugHTTPSServer.doPublish, .{ .name = "DebugHTTPSServerPrototype__doPublish" }); @@ -1348,7 +1345,6 @@ pub const JSDebugHTTPSServer = struct { @export(DebugHTTPSServer.getPendingWebSockets, .{ .name = "DebugHTTPSServerPrototype__getPendingWebSockets" }); @export(DebugHTTPSServer.getPort, .{ .name = "DebugHTTPSServerPrototype__getPort" }); @export(DebugHTTPSServer.getProtocol, .{ .name = "DebugHTTPSServerPrototype__getProtocol" }); - @export(DebugHTTPSServer.getURL, .{ .name = "DebugHTTPSServerPrototype__getURL" }); } } }; @@ -1478,9 +1474,6 @@ pub const JSDebugHTTPServer = struct { @compileLog("Expected DebugHTTPServer.doStop to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPServer.doStop))); if (@TypeOf(DebugHTTPServer.doUpgrade) != CallbackType) @compileLog("Expected DebugHTTPServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPServer.doUpgrade))); - if (@TypeOf(DebugHTTPServer.getURL) != GetterType) - @compileLog("Expected DebugHTTPServer.getURL to be a getter"); - if (!JSC.is_bindgen) { @export(DebugHTTPServer.doFetch, .{ .name = "DebugHTTPServerPrototype__doFetch" }); @export(DebugHTTPServer.doPublish, .{ .name = "DebugHTTPServerPrototype__doPublish" }); @@ -1495,7 +1488,6 @@ pub const JSDebugHTTPServer = struct { @export(DebugHTTPServer.getPendingWebSockets, .{ .name = "DebugHTTPServerPrototype__getPendingWebSockets" }); @export(DebugHTTPServer.getPort, .{ .name = "DebugHTTPServerPrototype__getPort" }); @export(DebugHTTPServer.getProtocol, .{ .name = "DebugHTTPServerPrototype__getProtocol" }); - @export(DebugHTTPServer.getURL, .{ .name = "DebugHTTPServerPrototype__getURL" }); } } }; @@ -3289,9 +3281,6 @@ pub const JSHTTPSServer = struct { @compileLog("Expected HTTPSServer.doStop to be a callback but received " ++ @typeName(@TypeOf(HTTPSServer.doStop))); if (@TypeOf(HTTPSServer.doUpgrade) != CallbackType) @compileLog("Expected HTTPSServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(HTTPSServer.doUpgrade))); - if (@TypeOf(HTTPSServer.getURL) != GetterType) - @compileLog("Expected HTTPSServer.getURL to be a getter"); - if (!JSC.is_bindgen) { @export(HTTPSServer.doFetch, .{ .name = "HTTPSServerPrototype__doFetch" }); @export(HTTPSServer.doPublish, .{ .name = "HTTPSServerPrototype__doPublish" }); @@ -3306,7 +3295,6 @@ pub const JSHTTPSServer = struct { @export(HTTPSServer.getPendingWebSockets, .{ .name = "HTTPSServerPrototype__getPendingWebSockets" }); @export(HTTPSServer.getPort, .{ .name = "HTTPSServerPrototype__getPort" }); @export(HTTPSServer.getProtocol, .{ .name = "HTTPSServerPrototype__getProtocol" }); - @export(HTTPSServer.getURL, .{ .name = "HTTPSServerPrototype__getURL" }); } } }; @@ -3436,9 +3424,6 @@ pub const JSHTTPServer = struct { @compileLog("Expected HTTPServer.doStop to be a callback but received " ++ @typeName(@TypeOf(HTTPServer.doStop))); if (@TypeOf(HTTPServer.doUpgrade) != CallbackType) @compileLog("Expected HTTPServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(HTTPServer.doUpgrade))); - if (@TypeOf(HTTPServer.getURL) != GetterType) - @compileLog("Expected HTTPServer.getURL to be a getter"); - if (!JSC.is_bindgen) { @export(HTTPServer.doFetch, .{ .name = "HTTPServerPrototype__doFetch" }); @export(HTTPServer.doPublish, .{ .name = "HTTPServerPrototype__doPublish" }); @@ -3453,7 +3438,6 @@ pub const JSHTTPServer = struct { @export(HTTPServer.getPendingWebSockets, .{ .name = "HTTPServerPrototype__getPendingWebSockets" }); @export(HTTPServer.getPort, .{ .name = "HTTPServerPrototype__getPort" }); @export(HTTPServer.getProtocol, .{ .name = "HTTPServerPrototype__getProtocol" }); - @export(HTTPServer.getURL, .{ .name = "HTTPServerPrototype__getURL" }); } } }; @@ -7083,125 +7067,6 @@ pub const JSTranspiler = struct { } } }; -pub const JSURL = struct { - const URL = Classes.URL; - const GetterType = fn (*URL, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; - const GetterTypeWithThisValue = fn (*URL, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; - const SetterType = fn (*URL, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; - const SetterTypeWithThisValue = fn (*URL, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; - const CallbackType = fn (*URL, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue; - - /// Return the pointer to the wrapped object. - /// If the object does not match the type, return null. - pub fn fromJS(value: JSC.JSValue) ?*URL { - JSC.markBinding(@src()); - return URL__fromJS(value); - } - - /// Get the URL constructor value. - /// This loads lazily from the global object. - pub fn getConstructor(globalObject: *JSC.JSGlobalObject) JSC.JSValue { - JSC.markBinding(@src()); - return URL__getConstructor(globalObject); - } - - /// Create a new instance of URL - pub fn toJS(this: *URL, globalObject: *JSC.JSGlobalObject) JSC.JSValue { - JSC.markBinding(@src()); - if (comptime Environment.allow_assert) { - const value__ = URL__create(globalObject, this); - std.debug.assert(value__.as(URL).? == this); // If this fails, likely a C ABI issue. - return value__; - } else { - return URL__create(globalObject, this); - } - } - - /// Modify the internal ptr to point to a new instance of URL. - pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*URL) bool { - JSC.markBinding(@src()); - return URL__dangerouslySetPtr(value, ptr); - } - - /// Detach the ptr from the thisValue - pub fn detachPtr(_: *URL, value: JSC.JSValue) void { - JSC.markBinding(@src()); - std.debug.assert(URL__dangerouslySetPtr(value, null)); - } - - extern fn URL__fromJS(JSC.JSValue) ?*URL; - extern fn URL__getConstructor(*JSC.JSGlobalObject) JSC.JSValue; - - extern fn URL__create(globalObject: *JSC.JSGlobalObject, ptr: ?*URL) JSC.JSValue; - - extern fn URL__dangerouslySetPtr(JSC.JSValue, ?*URL) bool; - - comptime { - if (@TypeOf(URL.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*URL)) { - @compileLog("URL.constructor is not a constructor"); - } - - if (@TypeOf(URL.finalize) != (fn (*URL) callconv(.C) void)) { - @compileLog("URL.finalize is not a finalizer"); - } - - if (@TypeOf(URL.getHash) != GetterType) - @compileLog("Expected URL.getHash to be a getter"); - - if (@TypeOf(URL.getHost) != GetterType) - @compileLog("Expected URL.getHost to be a getter"); - - if (@TypeOf(URL.getHostname) != GetterType) - @compileLog("Expected URL.getHostname to be a getter"); - - if (@TypeOf(URL.getHref) != GetterType) - @compileLog("Expected URL.getHref to be a getter"); - - if (@TypeOf(URL.getOrigin) != GetterType) - @compileLog("Expected URL.getOrigin to be a getter"); - - if (@TypeOf(URL.getPassword) != GetterType) - @compileLog("Expected URL.getPassword to be a getter"); - - if (@TypeOf(URL.getPathname) != GetterType) - @compileLog("Expected URL.getPathname to be a getter"); - - if (@TypeOf(URL.getPortJS) != GetterType) - @compileLog("Expected URL.getPortJS to be a getter"); - - if (@TypeOf(URL.getProtocol) != GetterType) - @compileLog("Expected URL.getProtocol to be a getter"); - - if (@TypeOf(URL.getSearch) != GetterType) - @compileLog("Expected URL.getSearch to be a getter"); - - if (@TypeOf(URL.getSearchParams) != GetterType) - @compileLog("Expected URL.getSearchParams to be a getter"); - - if (@TypeOf(URL.toJSON) != CallbackType) - @compileLog("Expected URL.toJSON to be a callback but received " ++ @typeName(@TypeOf(URL.toJSON))); - if (@TypeOf(URL.getUsername) != GetterType) - @compileLog("Expected URL.getUsername to be a getter"); - - if (!JSC.is_bindgen) { - @export(URL.constructor, .{ .name = "URLClass__construct" }); - @export(URL.finalize, .{ .name = "URLClass__finalize" }); - @export(URL.getHash, .{ .name = "URLPrototype__getHash" }); - @export(URL.getHost, .{ .name = "URLPrototype__getHost" }); - @export(URL.getHostname, .{ .name = "URLPrototype__getHostname" }); - @export(URL.getHref, .{ .name = "URLPrototype__getHref" }); - @export(URL.getOrigin, .{ .name = "URLPrototype__getOrigin" }); - @export(URL.getPassword, .{ .name = "URLPrototype__getPassword" }); - @export(URL.getPathname, .{ .name = "URLPrototype__getPathname" }); - @export(URL.getPortJS, .{ .name = "URLPrototype__getPortJS" }); - @export(URL.getProtocol, .{ .name = "URLPrototype__getProtocol" }); - @export(URL.getSearch, .{ .name = "URLPrototype__getSearch" }); - @export(URL.getSearchParams, .{ .name = "URLPrototype__getSearchParams" }); - @export(URL.getUsername, .{ .name = "URLPrototype__getUsername" }); - @export(URL.toJSON, .{ .name = "URLPrototype__toJSON" }); - } - } -}; comptime { _ = JSAttributeIterator; @@ -7255,5 +7120,4 @@ comptime { _ = JSTextDecoder; _ = JSTimeout; _ = JSTranspiler; - _ = JSURL; } diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig index 5bcd79ed2bb8..3b45f33b880f 100644 --- a/src/bun.js/bindings/generated_classes_list.zig +++ b/src/bun.js/bindings/generated_classes_list.zig @@ -55,5 +55,4 @@ pub const Classes = struct { pub const DebugHTTPSServer = JSC.API.DebugHTTPSServer; pub const Crypto = JSC.WebCore.Crypto; pub const FFI = JSC.FFI; - pub const URL = JSC.URL; }; diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 1ef67248f3e4..caa7d3cd8ef2 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -78,7 +78,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("./config.zig"); -const URL = bun.URL; +const URL = @import("../url.zig").URL; const Bun = JSC.API.Bun; const EventLoop = JSC.EventLoop; const PendingResolution = @import("../resolver/resolver.zig").PendingResolution; diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 9b56c3d64f9e..ca066450d2d9 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -76,7 +76,7 @@ const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; const VM = @import("root").bun.JSC.VM; const JSFunction = @import("root").bun.JSC.JSFunction; const Config = @import("./config.zig"); -const URL = bun.URL; +const URL = @import("../url.zig").URL; const Bun = JSC.API.Bun; const EventLoop = JSC.EventLoop; const PendingResolution = @import("../resolver/resolver.zig").PendingResolution; diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index d01ec5c28360..96d1a00eff45 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -14,7 +14,7 @@ pub const Buffer = JSC.MarkedArrayBuffer; const IdentityContext = @import("../../identity_context.zig").IdentityContext; const logger = @import("root").bun.logger; const Fs = @import("../../fs.zig"); -const URL = bun.URL; +const URL = @import("../../url.zig").URL; const Shimmer = @import("../bindings/shimmer.zig").Shimmer; const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false; const meta = bun.meta; diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 476d85c232eb..3617d5961337 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -4,7 +4,7 @@ const js_parser = bun.js_parser; const js_ast = bun.JSAst; const Api = @import("../../api/schema.zig").Api; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const Environment = bun.Environment; diff --git a/src/bun.js/url.classes.ts b/src/bun.js/url.classes.ts deleted file mode 100644 index 12ed62428d26..000000000000 --- a/src/bun.js/url.classes.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { define } from "./scripts/class-definitions"; - -export default [ - define({ - name: "URL", - construct: true, - finalize: true, - configurable: false, - klass: {}, - JSType: "0b11101110", - proto: { - hash: { - getter: "getHash", - }, - host: { - getter: "getHost", - }, - hostname: { - getter: "getHostname", - }, - href: { - getter: "getHref", - }, - origin: { - getter: "getOrigin", - }, - password: { - getter: "getPassword", - }, - pathname: { - getter: "getPathname", - }, - port: { - getter: "getPortJS", - }, - protocol: { - getter: "getProtocol", - }, - search: { - getter: "getSearch", - }, - searchParams: { - getter: "getSearchParams", - }, - username: { - getter: "getUsername", - }, - ["toJSON"]: { - fn: "toJSON", - length: 0, - }, - }, - }), -]; diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index fdfc769d739c..b0f1df935df3 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index 66cc04b8738c..bbdf21d5d135 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig index 74c5236be52c..8ffbd3fd0f13 100644 --- a/src/bun.js/webcore/encoding.zig +++ b/src/bun.js/webcore/encoding.zig @@ -1,7 +1,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig index c76fef7e7cfe..db073fccc52f 100644 --- a/src/bun.js/webcore/request.zig +++ b/src/bun.js/webcore/request.zig @@ -3,7 +3,7 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const RequestContext = @import("../../bun_dev_http_server.zig").RequestContext; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 5e5086614ea1..0e80adfc4a54 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -3,7 +3,7 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const RequestContext = @import("../../bun_dev_http_server.zig").RequestContext; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const HTTPClient = @import("root").bun.HTTP; const FetchRedirect = HTTPClient.FetchRedirect; const NetworkThread = HTTPClient.NetworkThread; @@ -1970,7 +1970,7 @@ pub const Fetch = struct { if (is_file_url) { defer allocator.free(url_proxy_buffer); var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - const PercentEncoding = bun.PercentEncoding; + const PercentEncoding = @import("../../url.zig").PercentEncoding; var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; var stream = std.io.fixedBufferStream(&path_buf2); const url_path_decoded = path_buf2[0 .. PercentEncoding.decode( diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index c38c78585f56..b96721e6e17a 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = @import("../../bun_dev_http_server.zig").MimeType; -const ZigURL = bun.URL; +const ZigURL = @import("../../url.zig").URL; const HTTPClient = @import("root").bun.HTTP; const NetworkThread = HTTPClient.NetworkThread; const AsyncIO = NetworkThread.AsyncIO; diff --git a/src/bun.zig b/src/bun.zig index 56c596e5bbe4..3f09277bbd7c 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -1034,11 +1034,8 @@ pub fn zero(comptime Type: type) Type { return @as(Type, @bitCast(out)); } pub const c_ares = @import("./deps/c_ares.zig"); -pub const URL = @import("./bun.js/url.zig").URL; -pub const FormData = @import("./bun.js/url.zig").FormData; -pub const QueryStringMap = @import("./bun.js/url.zig").QueryStringMap; -pub const PercentEncoding = @import("./bun.js/url.zig").PercentEncoding; -pub const CombinedScanner = @import("./bun.js/url.zig").CombinedScanner; +pub const URL = @import("./url.zig").URL; +pub const FormData = @import("./url.zig").FormData; var needs_proc_self_workaround: bool = false; diff --git a/src/bun_dev_http_server.zig b/src/bun_dev_http_server.zig index 2c4fb5aae7b2..6dfc24889e04 100644 --- a/src/bun_dev_http_server.zig +++ b/src/bun_dev_http_server.zig @@ -67,7 +67,7 @@ const JavaScriptCore = JavaScriptCore.C; const Syscall = bun.sys; const Router = @import("./router.zig"); pub const Watcher = watcher.NewWatcher(*Server); -const ZigURL = bun.URL; +const ZigURL = @import("./url.zig").URL; const HTTPStatusCode = u10; const URLPath = @import("./http/url_path.zig"); diff --git a/src/bundler.zig b/src/bundler.zig index 70e42700b094..920f658c3705 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -45,7 +45,7 @@ const Lock = @import("./lock.zig").Lock; const NodeFallbackModules = @import("./node_fallbacks.zig"); const CacheEntry = @import("./cache.zig").FsCacheEntry; const Analytics = @import("./analytics/analytics_thread.zig"); -const URL = bun.URL; +const URL = @import("./url.zig").URL; const Report = @import("./report.zig"); const Linker = linker.Linker; const Resolver = _resolver.Resolver; diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index bb26ebfb518a..e5b73814c5bf 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -96,7 +96,7 @@ const Lock = @import("../lock.zig").Lock; const NodeFallbackModules = @import("../node_fallbacks.zig"); const CacheEntry = @import("../cache.zig").FsCacheEntry; const Analytics = @import("../analytics/analytics_thread.zig"); -const URL = bun.URL; +const URL = @import("../url.zig").URL; const Report = @import("../report.zig"); const Linker = linker.Linker; const Resolver = _resolver.Resolver; diff --git a/src/bunfig.zig b/src/bunfig.zig index a436c11f5963..a777475da521 100644 --- a/src/bunfig.zig +++ b/src/bunfig.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const URL = bun.URL; +const URL = @import("./url.zig").URL; const C = bun.C; const options = @import("./options.zig"); const logger = @import("root").bun.logger; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index b0d4d5a8bf9b..b112d58999ca 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -28,7 +28,7 @@ const Command = @import("../cli.zig").Command; const bundler = bun.bundler; const fs = @import("../fs.zig"); -const URL = bun.URL; +const URL = @import("../url.zig").URL; const HTTP = @import("root").bun.HTTP; const NetworkThread = HTTP.NetworkThread; const ParseJSON = @import("../json_parser.zig").ParseJSONUTF8; diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index 6c24a8877bdd..1d67a7b39aa6 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -27,7 +27,7 @@ const Command = @import("../cli.zig").Command; const bundler = bun.bundler; const fs = @import("../fs.zig"); -const URL = bun.URL; +const URL = @import("../url.zig").URL; const ParseJSON = @import("../json_parser.zig").ParseJSON; const Archive = @import("../libarchive/libarchive.zig").Archive; const Zlib = @import("../zlib.zig"); diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index bafeb4abeb00..60ae953d3946 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -27,7 +27,7 @@ const Command = @import("../cli.zig").Command; const bundler = bun.bundler; const fs = @import("../fs.zig"); -const URL = bun.URL; +const URL = @import("../url.zig").URL; const HTTP = @import("root").bun.HTTP; const ParseJSON = @import("../json_parser.zig").ParseJSONUTF8; const Archive = @import("../libarchive/libarchive.zig").Archive; diff --git a/src/css_scanner.zig b/src/css_scanner.zig index 31e82aa9058b..45651d84956f 100644 --- a/src/css_scanner.zig +++ b/src/css_scanner.zig @@ -19,7 +19,7 @@ const logger = @import("root").bun.logger; const Options = options; const resolver = @import("./resolver/resolver.zig"); const _linker = @import("./linker.zig"); -const URL = bun.URL; +const URL = @import("./url.zig").URL; const replacementCharacter: CodePoint = 0xFFFD; pub const Chunk = struct { diff --git a/src/env_loader.zig b/src/env_loader.zig index 0754b9e884a9..213d14ab89fa 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -14,7 +14,7 @@ const C = bun.C; const CodepointIterator = @import("./string_immutable.zig").CodepointIterator; const Analytics = @import("./analytics/analytics_thread.zig"); const Fs = @import("./fs.zig"); -const URL = bun.URL; +const URL = @import("./url.zig").URL; const Api = @import("./api/schema.zig").Api; const which = @import("./which.zig").which; diff --git a/src/http/url_path.zig b/src/http/url_path.zig index 09d671e50c4b..a48700671ea7 100644 --- a/src/http/url_path.zig +++ b/src/http/url_path.zig @@ -10,7 +10,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; -const PercentEncoding = bun.PercentEncoding; +const PercentEncoding = @import("../url.zig").PercentEncoding; const std = @import("std"); const allocators = @import("../allocators.zig"); const URLPath = @This(); diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 56a8ef2f61b2..1b03483a005f 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -14,8 +14,8 @@ const Loc = bun.logger.Loc; const Log = bun.logger.Log; const DotEnv = @import("./env_loader.zig"); const std = @import("std"); -const URL = bun.URL; -const PercentEncoding = bun.PercentEncoding; +const URL = @import("./url.zig").URL; +const PercentEncoding = @import("./url.zig").PercentEncoding; pub const Method = @import("./http/method.zig").Method; const Api = @import("./api/schema.zig").Api; const Lock = @import("./lock.zig").Lock; diff --git a/src/install/install.zig b/src/install/install.zig index 855e5de6f4f6..2044039b22c5 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -33,7 +33,7 @@ const Run = @import("../bun_js.zig").Run; const Fs = @import("../fs.zig"); const FileSystem = Fs.FileSystem; const Lock = @import("../lock.zig").Lock; -const URL = bun.URL; +const URL = @import("../url.zig").URL; const HTTP = bun.HTTP; const AsyncHTTP = HTTP.AsyncHTTP; const HTTPChannel = HTTP.HTTPChannel; diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index e50348c320a3..47bae07355c2 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -37,7 +37,7 @@ const HeaderBuilder = bun.HTTP.HeaderBuilder; const Fs = @import("../fs.zig"); const FileSystem = Fs.FileSystem; const Lock = @import("../lock.zig").Lock; -const URL = bun.URL; +const URL = @import("../url.zig").URL; const AsyncHTTP = bun.HTTP.AsyncHTTP; const HTTPChannel = bun.HTTP.HTTPChannel; const NetworkThread = bun.HTTP.NetworkThread; diff --git a/src/install/npm.zig b/src/install/npm.zig index 9be17dc28bc5..57fcf72b9f9c 100644 --- a/src/install/npm.zig +++ b/src/install/npm.zig @@ -1,4 +1,4 @@ -const URL = bun.URL; +const URL = @import("../url.zig").URL; const bun = @import("root").bun; const std = @import("std"); const MutableString = @import("../string_mutable.zig").MutableString; diff --git a/src/jsc.zig b/src/jsc.zig index 0e91815a8f24..e5be26321001 100644 --- a/src/jsc.zig +++ b/src/jsc.zig @@ -13,7 +13,6 @@ pub usingnamespace @import("./bun.js/module_loader.zig"); pub const C = @import("./bun.js/javascript_core_c_api.zig"); pub const WebCore = @import("./bun.js/webcore.zig"); pub const BuildMessage = @import("./bun.js/BuildMessage.zig").BuildMessage; -pub const URL = @import("./bun.js/url.zig").URL; pub const ResolveMessage = @import("./bun.js/ResolveMessage.zig").ResolveMessage; pub const Cloudflare = struct { pub const HTMLRewriter = @import("./bun.js/api/html_rewriter.zig").HTMLRewriter; diff --git a/src/linker.zig b/src/linker.zig index 854327819d01..e4cf171c092a 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -38,7 +38,7 @@ const ResolveQueue = _bundler.ResolveQueue; const ResolverType = Resolver.Resolver; const ESModule = @import("./resolver/package_json.zig").ESModule; const Runtime = @import("./runtime.zig").Runtime; -const URL = bun.URL; +const URL = @import("url.zig").URL; const JSC = @import("root").bun.JSC; const PluginRunner = bun.bundler.PluginRunner; pub const CSSResolveError = error{ResolveMessage}; diff --git a/src/options.zig b/src/options.zig index 7159efaa83dd..73ca9a64bf36 100644 --- a/src/options.zig +++ b/src/options.zig @@ -9,7 +9,7 @@ const api = @import("./api/schema.zig"); const Api = api.Api; const defines = @import("./defines.zig"); const resolve_path = @import("./resolver/resolve_path.zig"); -const URL = bun.URL; +const URL = @import("./url.zig").URL; const ConditionsMap = @import("./resolver/package_json.zig").ESModule.ConditionsMap; const bun = @import("root").bun; const string = bun.string; diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 7bac9f53b9f3..165da7b5301a 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -1478,7 +1478,7 @@ pub const ESModule = struct { // If resolved contains any percent encodings of "/" or "\" ("%2f" and "%5C" // respectively), then throw an Invalid Module Specifier error. - const PercentEncoding = bun.PercentEncoding; + const PercentEncoding = @import("../url.zig").PercentEncoding; var fbs = std.io.fixedBufferStream(&resolved_path_buf_percent); var writer = fbs.writer(); const len = PercentEncoding.decode(@TypeOf(&writer), &writer, result.path) catch return Resolution{ diff --git a/src/router.zig b/src/router.zig index 74341b44bd4f..51047d9b5e5e 100644 --- a/src/router.zig +++ b/src/router.zig @@ -25,7 +25,7 @@ const Fs = @import("./fs.zig"); const Options = @import("./options.zig"); const allocators = @import("./allocators.zig"); const URLPath = @import("./http/url_path.zig"); -const PathnameScanner = bun.PathnameScanner; +const PathnameScanner = @import("./url.zig").PathnameScanner; const CodepointIterator = @import("./string_immutable.zig").CodepointIterator; const index_route_hash = @as(u32, @truncate(bun.hash("$$/index-route$$-!(@*@#&*%-901823098123"))); diff --git a/src/bun.js/url.zig b/src/url.zig similarity index 95% rename from src/bun.js/url.zig rename to src/url.zig index 3a2c7613feaf..064481257e22 100644 --- a/src/bun.js/url.zig +++ b/src/url.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const Api = @import("../api/schema.zig").Api; -const resolve_path = @import("../resolver/resolve_path.zig"); +const Api = @import("./api/schema.zig").Api; +const resolve_path = @import("./resolver/resolve_path.zig"); const bun = @import("root").bun; const string = bun.string; const Output = bun.Output; @@ -12,8 +12,6 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const JSC = bun.JSC; -const ZigString = JSC.ZigString; -const CppURL = @import("./bindings/bindings.zig").CppURL; // This is close to WHATWG URL, but we don't want the validation errors pub const URL = struct { @@ -38,122 +36,17 @@ pub const URL = struct { username: string = "", port_was_automatically_set: bool = false, - pub usingnamespace JSC.Codegen.JSURL; - pub usingnamespace CppURL; - - pub fn constructor( - globalThis: *JSC.JSGlobalObject, - _: *JSC.CallFrame, - ) callconv(.C) ?*URL { - globalThis.throw("URL is not constructable", .{}); - return null; - } - - pub fn finalize(_: *URL) callconv(.C) void {} - - pub fn getHash( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.hash).toJSConst(globalThis); - } - - pub fn getHost( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.host).toJSConst(globalThis); - } - - pub fn getHostname( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.hostname).toJSConst(globalThis); - } - - pub fn getHref( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.href).toJSConst(globalThis); - } - - pub fn getOrigin( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.origin).toJSConst(globalThis); - } - - pub fn getPassword( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.password).toJSConst(globalThis); - } - - pub fn getPathname( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.pathname).toJSConst(globalThis); - } - - pub fn getPortJS( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.port).toJSConst(globalThis); - } - - pub fn getProtocol( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.protocol).toJSConst(globalThis); - } - - pub fn getSearch( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.search).toJSConst(globalThis); - } - - pub fn getSearchParams( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - _ = this; - return JSC.JSValue.createEmptyObject(globalThis, 0); - } - - pub fn getUsername( - this: *URL, - globalThis: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return bun.String.init(this.username).toJSConst(globalThis); - } - - pub fn toJSON( - this: *URL, - globalThis: *JSC.JSGlobalObject, - _: *JSC.CallFrame, - ) callconv(.C) JSC.JSValue { - return this.getHref(globalThis); + pub fn isFile(this: *const URL) bool { + return strings.eqlComptime(this.protocol, "file"); } - pub fn create( - globalThis: *JSC.JSGlobalObject, - allocator: std.mem.Allocator, - ) JSC.JSValue { - var build_error = allocator.create(JSC.URL) catch unreachable; - return build_error.toJS(globalThis, allocator); - } + pub fn fromJS(js_value: JSC.JSValue, globalObject: *JSC.JSGlobalObject, allocator: std.mem.Allocator) !URL { + var href = JSC.URL.hrefFromJS(globalObject, js_value); + if (href.tag == .Dead) { + return error.InvalidURL; + } - pub fn isFile(this: *const URL) bool { - return strings.eqlComptime(this.protocol, "file"); + return URL.parse(try href.toOwnedSlice(allocator)); } pub fn fromString(allocator: std.mem.Allocator, input: bun.String) !URL { @@ -1377,7 +1270,7 @@ pub const FormData = struct { } }; -const ParamsList = @import("../router.zig").Param.List; +const ParamsList = @import("./router.zig").Param.List; pub const CombinedScanner = struct { query: Scanner, pathname: PathnameScanner, diff --git a/test/js/bun/ffi/ffi.test.fixture.callback.c b/test/js/bun/ffi/ffi.test.fixture.callback.c index 624f6cdd018b..3b9a46577770 100644 --- a/test/js/bun/ffi/ffi.test.fixture.callback.c +++ b/test/js/bun/ffi/ffi.test.fixture.callback.c @@ -286,6 +286,9 @@ ZIG_REPR_TYPE JSFunctionCall(void* jsGlobalObject, void* callFrame); bool my_callback_function(void* arg0); bool my_callback_function(void* arg0) { +#ifdef INJECT_BEFORE +INJECT_BEFORE; +#endif ZIG_REPR_TYPE arguments[1]; arguments[0] = PTR_TO_JSVALUE(arg0).asZigRepr; return (bool)JSVALUE_TO_BOOL(_FFI_Callback_call((void*)0x0000000000000000ULL, 1, arguments)); diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index 48f29056ef8f..e82e2cab00cf 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -379,57 +379,4 @@ describe("Server", () => { await proc.exited; expect(proc.exitCode).toBe(0); }); - - test("server should have URL fields set", async () => { - const server = Bun.serve({ - fetch(req) { - return new Response("Hello World!"); - }, - }); - try { - expect(server.url.hash).toBe(""); - expect(server.url.host).toBe(`0.0.0.0:${server.port}`); - expect(server.url.hostname).toBe("0.0.0.0"); - expect(server.url.href).toBe(`http://0.0.0.0:${server.port}/`); - expect(server.url.origin).toBe(`http://0.0.0.0:${server.port}`); - expect(server.url.password).toBe(""); - expect(server.url.pathname).toBe("/"); - expect(server.url.port).toBe(`${server.port}`); - expect(server.url.protocol).toBe("http"); - expect(server.url.search).toBe(""); - expect(server.url.username).toBe(""); - expect(server.url.searchParams).toEqual({}); - expect(server.url.toJSON()).toBe(`http://0.0.0.0:${server.port}/`); - } finally { - server.stop(true); - } - }); - - test("server should have URL fields set with IPv6", async () => { - const server = Bun.serve({ - hostname: "[::1]", - fetch() { - return new Response("Hello"); - }, - port: 0, - }); - try { - expect(server.url.hash).toBe(""); - expect(server.url.host).toStartWith("[::1]"); - expect(server.url.hostname).toBe("[::1]"); - expect(server.url.href).toStartWith("http://[::1]:"); - expect(server.url.href).toEndWith("/"); - expect(server.url.origin).toStartWith("http://[::1]:"); - expect(server.url.password).toBe(""); - expect(server.url.pathname).toBe("/"); - expect(server.url.port).toBeDefined(); - expect(server.url.protocol).toBe("http"); - expect(server.url.search).toBe(""); - expect(server.url.username).toBe(""); - expect(server.url.searchParams).toEqual({}); - expect(server.url.toJSON()).toStartWith("http://[::1]:"); - } finally { - server.stop(true); - } - }); }); diff --git a/test/js/third_party/prisma/prisma/sqlite/schema.prisma b/test/js/third_party/prisma/prisma/sqlite/schema.prisma index 267947ce1286..bbe3292cbf33 100644 --- a/test/js/third_party/prisma/prisma/sqlite/schema.prisma +++ b/test/js/third_party/prisma/prisma/sqlite/schema.prisma @@ -4,7 +4,7 @@ generator client { provider = "prisma-client-js" output = "client" - binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl", "linux-musl-openssl-3.0.x"] + %binaryTargets% } datasource db { From 2b067dab1726c9b54b5f2efb723740d6a707c3f0 Mon Sep 17 00:00:00 2001 From: Gabriel Dougherty Date: Tue, 3 Oct 2023 09:10:11 -0400 Subject: [PATCH 9/9] Progress implementing with WTF::URL --- packages/bun-types/bun.d.ts | 5 ++ src/bun.js/api/server.classes.ts | 3 + src/bun.js/api/server.zig | 10 +++ src/bun.js/bindings/BunString.cpp | 6 ++ src/bun.js/bindings/ZigGeneratedClasses.cpp | 72 +++++++++++++++++++-- src/bun.js/bindings/bindings.zig | 6 ++ src/bun.js/bindings/generated_classes.zig | 16 +++++ src/bun.js/bindings/headers-handwritten.h | 1 + test/js/bun/http/bun-server.test.ts | 54 ++++++++++++++++ 9 files changed, 169 insertions(+), 4 deletions(-) diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index d8d8fd20407d..a0755b050c7b 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -2423,6 +2423,11 @@ declare module "bun" { * When bun is not started with the `--hot` flag, this ID is currently unused. */ readonly id: string; + + /** + * A URL object representing the address the server is listening on. + */ + readonly url: URL; } /** diff --git a/src/bun.js/api/server.classes.ts b/src/bun.js/api/server.classes.ts index 80449ed27a1b..c01cbc352a7a 100644 --- a/src/bun.js/api/server.classes.ts +++ b/src/bun.js/api/server.classes.ts @@ -51,6 +51,9 @@ function generate(name) { development: { getter: "getDevelopment", }, + url: { + getter: "getURL", + }, }, klass: {}, finalize: true, diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 3fe411f39a7a..ab7b244238a3 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -5897,6 +5897,16 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp }, } } + + pub fn getURL( + this: *ThisServer, + globalThis: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + var href_ = bun.String.init(this.config.base_url.href); + var href = href_.toJS(globalThis).toBunString(globalThis); + const url = JSC.URL.fromString(href) orelse return JSValue.jsUndefined(); + return JSC.URL.toJS(url, globalThis); + } }; } diff --git a/src/bun.js/bindings/BunString.cpp b/src/bun.js/bindings/BunString.cpp index 31b331111fbb..2326a5fe682c 100644 --- a/src/bun.js/bindings/BunString.cpp +++ b/src/bun.js/bindings/BunString.cpp @@ -338,6 +338,12 @@ extern "C" WTF::URL* URL__fromJS(EncodedJSValue encodedValue, JSC::JSGlobalObjec return new WTF::URL(WTFMove(url)); } +extern "C" EncodedJSValue URL__toJS(WTF::URL* wtfUrl, JSC::JSGlobalObject* globalObject) +{ + auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); + return JSC::JSValue::encode(jsString(globalObject->vm(), wtfUrl->string())); +} + extern "C" BunString URL__getHrefFromJS(EncodedJSValue encodedValue, JSC::JSGlobalObject* globalObject) { auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index 45d60d379724..c8373f1e12a1 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -4206,6 +4206,9 @@ JSC_DECLARE_HOST_FUNCTION(DebugHTTPSServerPrototype__stopCallback); extern "C" EncodedJSValue DebugHTTPSServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(DebugHTTPSServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue DebugHTTPSServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(DebugHTTPSServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDebugHTTPSServerPrototype, JSDebugHTTPSServerPrototype::Base); static const HashTableValue JSDebugHTTPSServerPrototypeTableValues[] = { @@ -4221,7 +4224,8 @@ static const HashTableValue JSDebugHTTPSServerPrototypeTableValues[] = { { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__reloadCallback, 2 } }, { "requestIP"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__requestIPCallback, 1 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPSServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, DebugHTTPSServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSDebugHTTPSServerPrototype::s_info = { "DebugHTTPSServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDebugHTTPSServerPrototype) }; @@ -4528,6 +4532,18 @@ JSC_DEFINE_HOST_FUNCTION(DebugHTTPSServerPrototype__upgradeCallback, (JSGlobalOb return DebugHTTPSServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(DebugHTTPSServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSDebugHTTPSServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = DebugHTTPSServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSDebugHTTPSServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -4720,6 +4736,9 @@ JSC_DECLARE_HOST_FUNCTION(DebugHTTPServerPrototype__stopCallback); extern "C" EncodedJSValue DebugHTTPServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(DebugHTTPServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue DebugHTTPServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(DebugHTTPServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDebugHTTPServerPrototype, JSDebugHTTPServerPrototype::Base); static const HashTableValue JSDebugHTTPServerPrototypeTableValues[] = { @@ -4735,7 +4754,8 @@ static const HashTableValue JSDebugHTTPServerPrototypeTableValues[] = { { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__reloadCallback, 2 } }, { "requestIP"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__requestIPCallback, 1 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, DebugHTTPServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, DebugHTTPServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSDebugHTTPServerPrototype::s_info = { "DebugHTTPServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDebugHTTPServerPrototype) }; @@ -5042,6 +5062,18 @@ JSC_DEFINE_HOST_FUNCTION(DebugHTTPServerPrototype__upgradeCallback, (JSGlobalObj return DebugHTTPServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(DebugHTTPServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSDebugHTTPServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = DebugHTTPServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSDebugHTTPServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -11693,6 +11725,9 @@ JSC_DECLARE_HOST_FUNCTION(HTTPSServerPrototype__stopCallback); extern "C" EncodedJSValue HTTPSServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(HTTPSServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue HTTPSServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(HTTPSServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSHTTPSServerPrototype, JSHTTPSServerPrototype::Base); static const HashTableValue JSHTTPSServerPrototypeTableValues[] = { @@ -11708,7 +11743,8 @@ static const HashTableValue JSHTTPSServerPrototypeTableValues[] = { { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__reloadCallback, 2 } }, { "requestIP"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__requestIPCallback, 1 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPSServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, HTTPSServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSHTTPSServerPrototype::s_info = { "HTTPSServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTTPSServerPrototype) }; @@ -12015,6 +12051,18 @@ JSC_DEFINE_HOST_FUNCTION(HTTPSServerPrototype__upgradeCallback, (JSGlobalObject return HTTPSServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(HTTPSServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSHTTPSServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = HTTPSServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSHTTPSServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -12207,6 +12255,9 @@ JSC_DECLARE_HOST_FUNCTION(HTTPServerPrototype__stopCallback); extern "C" EncodedJSValue HTTPServerPrototype__doUpgrade(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(HTTPServerPrototype__upgradeCallback); +extern "C" JSC::EncodedJSValue HTTPServerPrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(HTTPServerPrototype__urlGetterWrap); + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSHTTPServerPrototype, JSHTTPServerPrototype::Base); static const HashTableValue JSHTTPServerPrototypeTableValues[] = { @@ -12222,7 +12273,8 @@ static const HashTableValue JSHTTPServerPrototypeTableValues[] = { { "reload"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__reloadCallback, 2 } }, { "requestIP"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__requestIPCallback, 1 } }, { "stop"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__stopCallback, 1 } }, - { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__upgradeCallback, 1 } } + { "upgrade"_s, static_cast(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, HTTPServerPrototype__upgradeCallback, 1 } }, + { "url"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, HTTPServerPrototype__urlGetterWrap, 0 } } }; const ClassInfo JSHTTPServerPrototype::s_info = { "HTTPServer"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTTPServerPrototype) }; @@ -12529,6 +12581,18 @@ JSC_DEFINE_HOST_FUNCTION(HTTPServerPrototype__upgradeCallback, (JSGlobalObject * return HTTPServerPrototype__doUpgrade(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(HTTPServerPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSHTTPServer* thisObject = jsCast(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = HTTPServerPrototype__getURL(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + void JSHTTPServerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index f274f72d7ea4..59c78a9a4e4b 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -5481,6 +5481,7 @@ pub fn untrackFunction( pub const URL = opaque { extern fn URL__fromJS(JSValue, *JSC.JSGlobalObject) ?*URL; + extern fn URL__toJS(globalObject: *JSC.JSGlobalObject, in: *URL) JSC.JSValue; extern fn URL__fromString(*bun.String) ?*URL; extern fn URL__protocol(*URL) String; extern fn URL__href(*URL) String; @@ -5535,6 +5536,11 @@ pub const URL = opaque { return URL__fromJS(value, globalObject); } + pub fn toJS(url: *URL, globalObject: *JSC.JSGlobalObject) JSValue { + JSC.markBinding(@src()); + return URL__toJS(globalObject, url); + } + pub fn fromUTF8(input: []const u8) ?*URL { return fromString(String.fromUTF8(input)); } diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index da93b270691f..dd63ce9e9a9d 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -1333,6 +1333,9 @@ pub const JSDebugHTTPSServer = struct { @compileLog("Expected DebugHTTPSServer.doStop to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPSServer.doStop))); if (@TypeOf(DebugHTTPSServer.doUpgrade) != CallbackType) @compileLog("Expected DebugHTTPSServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPSServer.doUpgrade))); + if (@TypeOf(DebugHTTPSServer.getURL) != GetterType) + @compileLog("Expected DebugHTTPSServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(DebugHTTPSServer.doFetch, .{ .name = "DebugHTTPSServerPrototype__doFetch" }); @export(DebugHTTPSServer.doPublish, .{ .name = "DebugHTTPSServerPrototype__doPublish" }); @@ -1348,6 +1351,7 @@ pub const JSDebugHTTPSServer = struct { @export(DebugHTTPSServer.getPendingWebSockets, .{ .name = "DebugHTTPSServerPrototype__getPendingWebSockets" }); @export(DebugHTTPSServer.getPort, .{ .name = "DebugHTTPSServerPrototype__getPort" }); @export(DebugHTTPSServer.getProtocol, .{ .name = "DebugHTTPSServerPrototype__getProtocol" }); + @export(DebugHTTPSServer.getURL, .{ .name = "DebugHTTPSServerPrototype__getURL" }); } } }; @@ -1479,6 +1483,9 @@ pub const JSDebugHTTPServer = struct { @compileLog("Expected DebugHTTPServer.doStop to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPServer.doStop))); if (@TypeOf(DebugHTTPServer.doUpgrade) != CallbackType) @compileLog("Expected DebugHTTPServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(DebugHTTPServer.doUpgrade))); + if (@TypeOf(DebugHTTPServer.getURL) != GetterType) + @compileLog("Expected DebugHTTPServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(DebugHTTPServer.doFetch, .{ .name = "DebugHTTPServerPrototype__doFetch" }); @export(DebugHTTPServer.doPublish, .{ .name = "DebugHTTPServerPrototype__doPublish" }); @@ -1494,6 +1501,7 @@ pub const JSDebugHTTPServer = struct { @export(DebugHTTPServer.getPendingWebSockets, .{ .name = "DebugHTTPServerPrototype__getPendingWebSockets" }); @export(DebugHTTPServer.getPort, .{ .name = "DebugHTTPServerPrototype__getPort" }); @export(DebugHTTPServer.getProtocol, .{ .name = "DebugHTTPServerPrototype__getProtocol" }); + @export(DebugHTTPServer.getURL, .{ .name = "DebugHTTPServerPrototype__getURL" }); } } }; @@ -3289,6 +3297,9 @@ pub const JSHTTPSServer = struct { @compileLog("Expected HTTPSServer.doStop to be a callback but received " ++ @typeName(@TypeOf(HTTPSServer.doStop))); if (@TypeOf(HTTPSServer.doUpgrade) != CallbackType) @compileLog("Expected HTTPSServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(HTTPSServer.doUpgrade))); + if (@TypeOf(HTTPSServer.getURL) != GetterType) + @compileLog("Expected HTTPSServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(HTTPSServer.doFetch, .{ .name = "HTTPSServerPrototype__doFetch" }); @export(HTTPSServer.doPublish, .{ .name = "HTTPSServerPrototype__doPublish" }); @@ -3304,6 +3315,7 @@ pub const JSHTTPSServer = struct { @export(HTTPSServer.getPendingWebSockets, .{ .name = "HTTPSServerPrototype__getPendingWebSockets" }); @export(HTTPSServer.getPort, .{ .name = "HTTPSServerPrototype__getPort" }); @export(HTTPSServer.getProtocol, .{ .name = "HTTPSServerPrototype__getProtocol" }); + @export(HTTPSServer.getURL, .{ .name = "HTTPSServerPrototype__getURL" }); } } }; @@ -3435,6 +3447,9 @@ pub const JSHTTPServer = struct { @compileLog("Expected HTTPServer.doStop to be a callback but received " ++ @typeName(@TypeOf(HTTPServer.doStop))); if (@TypeOf(HTTPServer.doUpgrade) != CallbackType) @compileLog("Expected HTTPServer.doUpgrade to be a callback but received " ++ @typeName(@TypeOf(HTTPServer.doUpgrade))); + if (@TypeOf(HTTPServer.getURL) != GetterType) + @compileLog("Expected HTTPServer.getURL to be a getter"); + if (!JSC.is_bindgen) { @export(HTTPServer.doFetch, .{ .name = "HTTPServerPrototype__doFetch" }); @export(HTTPServer.doPublish, .{ .name = "HTTPServerPrototype__doPublish" }); @@ -3450,6 +3465,7 @@ pub const JSHTTPServer = struct { @export(HTTPServer.getPendingWebSockets, .{ .name = "HTTPServerPrototype__getPendingWebSockets" }); @export(HTTPServer.getPort, .{ .name = "HTTPServerPrototype__getPort" }); @export(HTTPServer.getProtocol, .{ .name = "HTTPServerPrototype__getProtocol" }); + @export(HTTPServer.getURL, .{ .name = "HTTPServerPrototype__getURL" }); } } }; diff --git a/src/bun.js/bindings/headers-handwritten.h b/src/bun.js/bindings/headers-handwritten.h index cef5d0804d20..cc08950175b8 100644 --- a/src/bun.js/bindings/headers-handwritten.h +++ b/src/bun.js/bindings/headers-handwritten.h @@ -234,6 +234,7 @@ extern "C" void Bun__WTFStringImpl__deref(WTF::StringImpl* impl); extern "C" void Bun__WTFStringImpl__ref(WTF::StringImpl* impl); extern "C" bool BunString__fromJS(JSC::JSGlobalObject*, JSC::EncodedJSValue, BunString*); extern "C" JSC::EncodedJSValue BunString__toJS(JSC::JSGlobalObject*, BunString*); +extern "C" JSC::EncodedJSValue URL__toJS(WTF::URL*, JSC::JSGlobalObject*); extern "C" void BunString__toWTFString(BunString*); namespace Bun { diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index e82e2cab00cf..bc217b26dfaa 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -379,4 +379,58 @@ describe("Server", () => { await proc.exited; expect(proc.exitCode).toBe(0); }); + + + test("server should have URL fields set", async () => { + const server = Bun.serve({ + fetch(req) { + return new Response("Hello World!"); + }, + }); + try { + expect(server.url.hash).toBe(""); + expect(server.url.host).toBe(`0.0.0.0:${server.port}`); + expect(server.url.hostname).toBe("0.0.0.0"); + expect(server.url.href).toBe(`http://0.0.0.0:${server.port}/`); + expect(server.url.origin).toBe(`http://0.0.0.0:${server.port}`); + expect(server.url.password).toBe(""); + expect(server.url.pathname).toBe("/"); + expect(server.url.port).toBe(`${server.port}`); + expect(server.url.protocol).toBe("http"); + expect(server.url.search).toBe(""); + expect(server.url.username).toBe(""); + expect(server.url.searchParams).toEqual({}); + expect(server.url.toJSON()).toBe(`http://0.0.0.0:${server.port}/`); + } finally { + server.stop(true); + } + }); + + test("server should have URL fields set with IPv6", async () => { + const server = Bun.serve({ + hostname: "[::1]", + fetch() { + return new Response("Hello"); + }, + port: 0, + }); + try { + expect(server.url.hash).toBe(""); + expect(server.url.host).toStartWith("[::1]"); + expect(server.url.hostname).toBe("[::1]"); + expect(server.url.href).toStartWith("http://[::1]:"); + expect(server.url.href).toEndWith("/"); + expect(server.url.origin).toStartWith("http://[::1]:"); + expect(server.url.password).toBe(""); + expect(server.url.pathname).toBe("/"); + expect(server.url.port).toBeDefined(); + expect(server.url.protocol).toBe("http"); + expect(server.url.search).toBe(""); + expect(server.url.username).toBe(""); + expect(server.url.searchParams).toEqual({}); + expect(server.url.toJSON()).toStartWith("http://[::1]:"); + } finally { + server.stop(true); + } + }); });