Skip to content

Commit

Permalink
Switches URL polyfill to whatwg-url
Browse files Browse the repository at this point in the history
  • Loading branch information
mhassan1 committed Jul 11, 2024
1 parent 3701c8b commit 2ecdf96
Show file tree
Hide file tree
Showing 8 changed files with 8,425 additions and 677 deletions.
4,259 changes: 4,152 additions & 107 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions polyfills/URL/_entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* global require, self */
const { URL, URLSearchParams } = require("whatwg-url");

// delete these, since they should come from other polyfills
delete URL.prototype.toJSON;
delete URL.canParse;
delete URL.parse;

self.URL = URL;
self.URLSearchParams = URLSearchParams;
48 changes: 48 additions & 0 deletions polyfills/URL/_webidl-conversions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* global exports */
// this file is auto-generated by `update.task.js`

function makeException(ErrorType, message, options) {
if (options.globals) {
ErrorType = options.globals[ErrorType.name];
}
return new ErrorType(`${options.context ? options.context : "Value"} ${message}.`);
}
exports.USVString = (value, options = {}) => {
const S = exports.DOMString(value, options);
const n = S.length;
const U = [];
for (let i = 0; i < n; ++i) {
const c = S.charCodeAt(i);
if (c < 0xD800 || c > 0xDFFF) {
U.push(String.fromCodePoint(c));
} else if (0xDC00 <= c && c <= 0xDFFF) {
U.push(String.fromCodePoint(0xFFFD));
} else if (i === n - 1) {
U.push(String.fromCodePoint(0xFFFD));
} else {
const d = S.charCodeAt(i + 1);
if (0xDC00 <= d && d <= 0xDFFF) {
const a = c & 0x3FF;
const b = d & 0x3FF;
U.push(String.fromCodePoint((2 << 15) + ((2 << 9) * a) + b));
++i;
} else {
U.push(String.fromCodePoint(0xFFFD));
}
}
}

return U.join("");
};
exports.DOMString = (value, options = {}) => {
if (options.treatNullAsEmptyString && value === null) {
return "";
}

if (typeof value === "symbol") {
throw makeException(TypeError, "is a symbol, which cannot be converted to a string", options);
}

const StringCtor = options.globals ? options.globals.String : String;
return StringCtor(value);
};
25 changes: 22 additions & 3 deletions polyfills/URL/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@ aliases = [
]
dependencies = [
"Array.from",
"Symbol.iterator"
"Array.prototype.@@iterator",
"Array.prototype.entries",
"ArrayBuffer.prototype.@@toStringTag",
"Object.getOwnPropertyDescriptors",
"Object.prototype.toString",
"Reflect.defineProperty",
"Reflect.getOwnPropertyDescriptor",
"Reflect.ownKeys",
"String.fromCodePoint",
"String.prototype.@@iterator",
"String.prototype.codePointAt",
"String.prototype.normalize",
"String.prototype.startsWith",
"TextEncoder",
"TypedArray.prototype.@@iterator",
]
notes = [ ]
license = "CC0-1.0"
repo = "https://github.com/inexorabletash/polyfill"
license = "MIT"
repo = "https://github.com/jsdom/whatwg-url"
docs = "https://developer.mozilla.org/en-US/docs/Web/API/URL"

[browsers]
Expand All @@ -32,3 +46,8 @@ op_mini = "*"
safari = "<12.0"
ios_saf = "<12.0"
samsung_mob = "<5.0"

[install]
module = "whatwg-url"
postinstall = "update.task.js"
clean = [ "polyfill.js" ]
17 changes: 17 additions & 0 deletions polyfills/URL/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@mrhenry/polyfill-library--url",
"version": "0.0.0",
"private": true,
"devDependencies": {
"@babel/core": "7.24.7",
"@babel/preset-env": "7.24.7",
"babelify": "10.0.0",
"browserify": "17.0.0",
"browserify-replace": "1.1.0",
"webidl-conversions": "7.0.0",
"whatwg-url": "14.0.0"
},
"volta": {
"extends": "../../package.json"
}
}
Loading

0 comments on commit 2ecdf96

Please sign in to comment.