MCPcopy
hub / github.com/nodejs/node / URL

Class URL

lib/internal/url.js:806–1177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

804const kCreateURLFromWindowsPathSymbol = Symbol('kCreateURLFromWindowsPath');
805
806class URL {
807 #context = new URLContext();
808 #searchParams;
809 #searchParamsModified;
810
811 static {
812 setURLSearchParamsModified = (obj) => {
813 // When URLSearchParams changes, we lazily update URL on the next read/write for performance.
814 obj.#searchParamsModified = true;
815
816 // If URL has an existing search, remove it without cascading back to URLSearchParams.
817 // Do this to avoid any internal confusion about whether URLSearchParams or URL is up-to-date.
818 if (obj.#context.hasSearch) {
819 obj.#updateContext(bindingUrl.update(obj.#context.href, updateActions.kSearch, ''));
820 }
821 };
822 }
823
824 constructor(input, base = undefined, parseSymbol = undefined) {
825 markTransferMode(this, false, false);
826
827 if (arguments.length === 0) {
828 throw new ERR_MISSING_ARGS('url');
829 }
830
831 // StringPrototypeToWellFormed is not needed.
832 input = `${input}`;
833
834 if (base !== undefined) {
835 base = `${base}`;
836 }
837
838 let href;
839 if (arguments.length < 3) {
840 href = bindingUrl.parse(input, base, true);
841 } else {
842 const raiseException = parseSymbol !== kParseURLSymbol;
843 const interpretAsWindowsPath = parseSymbol === kCreateURLFromWindowsPathSymbol;
844 const pathToFileURL = interpretAsWindowsPath || (parseSymbol === kCreateURLFromPosixPathSymbol);
845 href = pathToFileURL ?
846 bindingUrl.pathToFileURL(input, interpretAsWindowsPath, base) :
847 bindingUrl.parse(input, base, raiseException);
848 }
849 if (href) {
850 this.#updateContext(href);
851 }
852 }
853
854 static parse(input, base = undefined) {
855 if (arguments.length === 0) {
856 throw new ERR_MISSING_ARGS('url');
857 }
858 const parsedURLObject = new URL(input, base, kParseURLSymbol);
859 return parsedURLObject.href ? parsedURLObject : null;
860 }
861
862 [inspect.custom](depth, opts) {
863 if (typeof depth === 'number' && depth < 0)

Callers

nothing calls this directly

Calls 2

#updateContextMethod · 0.80
updateMethod · 0.65

Tested by

no test coverage detected