Skip to content

Commit 2ecdf96

Browse files
committed
Switches URL polyfill to whatwg-url
1 parent 3701c8b commit 2ecdf96

File tree

8 files changed

+8425
-677
lines changed

8 files changed

+8425
-677
lines changed

package-lock.json

Lines changed: 4152 additions & 107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polyfills/URL/_entry.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* global require, self */
2+
const { URL, URLSearchParams } = require("whatwg-url");
3+
4+
// delete these, since they should come from other polyfills
5+
delete URL.prototype.toJSON;
6+
delete URL.canParse;
7+
delete URL.parse;
8+
9+
self.URL = URL;
10+
self.URLSearchParams = URLSearchParams;

polyfills/URL/_webidl-conversions.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* global exports */
2+
// this file is auto-generated by `update.task.js`
3+
4+
function makeException(ErrorType, message, options) {
5+
if (options.globals) {
6+
ErrorType = options.globals[ErrorType.name];
7+
}
8+
return new ErrorType(`${options.context ? options.context : "Value"} ${message}.`);
9+
}
10+
exports.USVString = (value, options = {}) => {
11+
const S = exports.DOMString(value, options);
12+
const n = S.length;
13+
const U = [];
14+
for (let i = 0; i < n; ++i) {
15+
const c = S.charCodeAt(i);
16+
if (c < 0xD800 || c > 0xDFFF) {
17+
U.push(String.fromCodePoint(c));
18+
} else if (0xDC00 <= c && c <= 0xDFFF) {
19+
U.push(String.fromCodePoint(0xFFFD));
20+
} else if (i === n - 1) {
21+
U.push(String.fromCodePoint(0xFFFD));
22+
} else {
23+
const d = S.charCodeAt(i + 1);
24+
if (0xDC00 <= d && d <= 0xDFFF) {
25+
const a = c & 0x3FF;
26+
const b = d & 0x3FF;
27+
U.push(String.fromCodePoint((2 << 15) + ((2 << 9) * a) + b));
28+
++i;
29+
} else {
30+
U.push(String.fromCodePoint(0xFFFD));
31+
}
32+
}
33+
}
34+
35+
return U.join("");
36+
};
37+
exports.DOMString = (value, options = {}) => {
38+
if (options.treatNullAsEmptyString && value === null) {
39+
return "";
40+
}
41+
42+
if (typeof value === "symbol") {
43+
throw makeException(TypeError, "is a symbol, which cannot be converted to a string", options);
44+
}
45+
46+
const StringCtor = options.globals ? options.globals.String : String;
47+
return StringCtor(value);
48+
};

polyfills/URL/config.toml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,25 @@ aliases = [
99
]
1010
dependencies = [
1111
"Array.from",
12-
"Symbol.iterator"
12+
"Array.prototype.@@iterator",
13+
"Array.prototype.entries",
14+
"ArrayBuffer.prototype.@@toStringTag",
15+
"Object.getOwnPropertyDescriptors",
16+
"Object.prototype.toString",
17+
"Reflect.defineProperty",
18+
"Reflect.getOwnPropertyDescriptor",
19+
"Reflect.ownKeys",
20+
"String.fromCodePoint",
21+
"String.prototype.@@iterator",
22+
"String.prototype.codePointAt",
23+
"String.prototype.normalize",
24+
"String.prototype.startsWith",
25+
"TextEncoder",
26+
"TypedArray.prototype.@@iterator",
1327
]
1428
notes = [ ]
15-
license = "CC0-1.0"
16-
repo = "https://github.com/inexorabletash/polyfill"
29+
license = "MIT"
30+
repo = "https://github.com/jsdom/whatwg-url"
1731
docs = "https://developer.mozilla.org/en-US/docs/Web/API/URL"
1832

1933
[browsers]
@@ -32,3 +46,8 @@ op_mini = "*"
3246
safari = "<12.0"
3347
ios_saf = "<12.0"
3448
samsung_mob = "<5.0"
49+
50+
[install]
51+
module = "whatwg-url"
52+
postinstall = "update.task.js"
53+
clean = [ "polyfill.js" ]

polyfills/URL/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@mrhenry/polyfill-library--url",
3+
"version": "0.0.0",
4+
"private": true,
5+
"devDependencies": {
6+
"@babel/core": "7.24.7",
7+
"@babel/preset-env": "7.24.7",
8+
"babelify": "10.0.0",
9+
"browserify": "17.0.0",
10+
"browserify-replace": "1.1.0",
11+
"webidl-conversions": "7.0.0",
12+
"whatwg-url": "14.0.0"
13+
},
14+
"volta": {
15+
"extends": "../../package.json"
16+
}
17+
}

0 commit comments

Comments
 (0)