Skip to content

Update URL & Request & XMLHttpRequest interface to accept Location - #2552

Open
Adam Naji (Bashamega) wants to merge 9 commits into
microsoft:mainfrom
Bashamega:fix/location-issue
Open

Update URL & Request & XMLHttpRequest interface to accept Location#2552
Adam Naji (Bashamega) wants to merge 9 commits into
microsoft:mainfrom
Bashamega:fix/location-issue

Conversation

@Bashamega

@Bashamega Adam Naji (Bashamega) commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

closes #2536

Also, I couldn't figure out how to override fetch

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by Kagami Sascha Rosylight (@saschanaz) - if they write a comment saying "LGTM" then it will be merged.

@Bashamega

Copy link
Copy Markdown
Contributor Author

Should i handle the fallback to WorkerLocation in the emitter or what should i do in this situation?

method parse signatureIndex=0 {
param base overrideType="string | URL | Location"
}
}

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

This comment was marked as resolved.

Signed-off-by: Bashamega <adambashaahmednaji@gmail.com>
@bddjr

Copy link
Copy Markdown

🤔It seems that we need to separately make webworker.generated.d.ts exempt from this change.
I don't know how to do that, so I didn't submit a PR.

Comment thread inputfiles/patches/url.kdl Outdated

interface URL {
constructor signatureIndex=0 {
param url overrideType="string | URL | Location"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not additionalTypes? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because location is not supported in web worker, i don't know how to handle web worker

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exposure checker should autoremove them... but maybe we don't do that for additionalTypes? 🤔

…ethod parameters across multiple baseline files
@Bashamega

Copy link
Copy Markdown
Contributor Author

It wasn't implemented, but I have added it Kagami Sascha Rosylight (@saschanaz)

@turansky

Copy link
Copy Markdown

Also, I couldn't figure out how to override fetch

Adam Naji (@Bashamega) should it also affect Request in that case?

@bddjr

Copy link
Copy Markdown

should it also affect Request in that case?

yes

new Request(location)

@Bashamega Adam Naji (Bashamega) changed the title Update URL & interface to accept Location XMLHttpRequest Update URL & Request & XMLHttpRequest interface to accept Location Sep 10, 2026
@Bashamega

Copy link
Copy Markdown
Contributor Author

I have updated it. What do you think Kagami Sascha Rosylight (@saschanaz)

@bddjr

Copy link
Copy Markdown

ChatGPT suggested adding the type for fetch(location) like this:

 inputfiles/overridingTypes.jsonc

 "WindowOrWorkerGlobalScope": {
     "methods": {
         "method": {
+            "fetch": {
+                "signature": {
+                    "0": {
+                        "param": [
+                            {
+                                "name": "input",
+                                "additionalTypes": ["Location"]
+                            }
+                        ]
+                    }
+                }
+            },
             ...

…e baseline files

Signed-off-by: Bashamega <adambashaahmednaji@gmail.com>
@Bashamega

Copy link
Copy Markdown
Contributor Author

Thanks for the help 半岛的蒟蒻bddjr (@bddjr) ... Updated

@bddjr

半岛的蒟蒻bddjr (bddjr) commented Sep 10, 2026

Copy link
Copy Markdown

Review by Gemini 3.8 Flash:

Thanks for working on this! A few findings during the review:

1. Typo in inputfiles/patches/fetch.kdl

In inputfiles/patches/fetch.kdl:

interface Request {
  constructor signatureIndex=0 {
    param input {
      additionalTypes input Location
    }
  }
}

input was accidentally included as a type in additionalTypes. It should be:

      additionalTypes Location

(It was silently stripped only because isKnownType("input") is false).

2. filterAdditionalTypes in src/build/expose.ts didn't actually affect parameters

In filterUnknownTypeFromSignature, param.push({ ...p, type: flattenType(filtered) }) spreads p rather than using the filtered additionalTypes from filtered[0]. In addition, deepClone returns early at method signatures and does not recurse into param directly.
As a result, additionalTypes on parameters remained unfiltered until isKnownType in emitter.ts.
To properly filter additionalTypes in expose.ts:

const additionalTypes = filterAdditionalTypes(p.additionalTypes, unexposedTypes);
param.push({
  ...p,
  type: flattenType(filtered),
  additionalTypes: additionalTypes?.length ? additionalTypes : undefined,
});

3. Supporting WorkerLocation in Web Workers

Regarding your question about WorkerLocation:

Should i handle the fallback to WorkerLocation in the emitter or what should i do in this situation?

Once expose.ts properly filters additionalTypes, we can simply specify:

additionalTypes Location WorkerLocation
  • For DOM lib: WorkerLocation is unexposed and filtered out $\rightarrow$ results in Location.
  • For Worker lib: Location is unexposed and filtered out $\rightarrow$ results in WorkerLocation.
    This allows workers to naturally accept location without any special fallback in emitter.ts!

@bddjr

Copy link
Copy Markdown

Review by Gemini 3.8 Flash:

Nice work on adding WorkerLocation! The generated baselines look spot on now.

Just one architectural detail regarding src/build/expose.ts:

Currently, the changes in src/build/expose.ts are actually dead code because:

  1. deepClone returns early on o.signature and never traverses down into param objects.
  2. In filterUnknownTypeFromSignature, param.push({ ...p, type: flattenType(filtered) }) spreads p (the original param) rather than preserving filtered[0].additionalTypes.

The reason the baselines generated correctly is actually due to filter((t) => isKnownType(t)) in src/build/emitter.ts.

To clean this up, we have two options:

  • Option 1 (Recommended): Make expose.ts actually handle additionalTypes on parameters:
    // In filterUnknownTypeFromSignature in src/build/expose.ts
    const additionalTypes = filterAdditionalTypes(p.additionalTypes, unexposedTypes);
    param.push({
      ...p,
      type: flattenType(filtered),
      additionalTypes: additionalTypes?.length ? additionalTypes : undefined,
    });
    (and remove the unreachable if (o.additionalTypes) at the top of deepClone).
  • Option 2: If filtering via isKnownType in emitter.ts is deemed sufficient, revert the changes in src/build/expose.ts completely so we don't leave unused code in expose.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Web API type definition issue] URL, fetch, and XMLHttpRequest.prototype.open should accept Location as an argument

4 participants