Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves URL polyfill to work without TypedArray.prototype.slice/indexOf #73

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions polyfills/ArrayBuffer/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ docs = "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global
[browsers]
android = "*"
bb = "*"
chrome = "<45"
chrome = "<32"
edge = "<14"
edge_mob = "<14"
firefox = "<44"
Expand All @@ -27,8 +27,8 @@ ie_mob = "*"
opera = "<19"
op_mob = "<19"
op_mini = "*"
safari = "<10.0"
ios_saf = "<10.0"
safari = "<7.0"
ios_saf = "<7.0"
samsung_mob = "<2.0"

[install]
Expand Down
2 changes: 0 additions & 2 deletions polyfills/ArrayBuffer/detect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// use "Int8Array" as a proxy for support of "TypedArray" subclasses
// confirm that the prototype of "Int8Array" is NOT the "Object" prototype, which is a bug in IE11 and maybe other old browsers
'ArrayBuffer' in self && 'DataView' in self && 'Int8Array' in self
// IE11 has an incomplete implementation that's missing `slice` and maybe others
&& 'slice' in self.Int8Array.prototype
// TODO: add back this check once we remove support for ie10 and below
// && Object.getPrototypeOf(self.Int8Array) !== Object.getPrototypeOf(Object)
20 changes: 10 additions & 10 deletions polyfills/URL/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,7 @@ function percentDecodeBytes(input) {
i += 2;
}
}
return output.slice(0, outputIndex);
return output.subarray(0, outputIndex);
}

// https://url.spec.whatwg.org/#string-percent-decode
Expand Down Expand Up @@ -3739,10 +3739,10 @@ function parseUrlencoded(input) {
}
var name = void 0,
value = void 0;
var indexOfEqual = bytes.indexOf(p("="));
var indexOfEqual = Array.prototype.indexOf.call(bytes, p("="));
if (indexOfEqual >= 0) {
name = bytes.slice(0, indexOfEqual);
value = bytes.slice(indexOfEqual + 1);
name = bytes.subarray(0, indexOfEqual);
value = bytes.subarray(indexOfEqual + 1);
} else {
name = bytes;
value = new Uint8Array(0);
Expand Down Expand Up @@ -3810,22 +3810,22 @@ function serializeUrlencoded(tuples) {
function strictlySplitByteSequence(buf, cp) {
var list = [];
var last = 0;
var i = buf.indexOf(cp);
var i = Array.prototype.indexOf.call(buf, cp);
while (i >= 0) {
list.push(buf.slice(last, i));
list.push(buf.subarray(last, i));
last = i + 1;
i = buf.indexOf(cp, last);
i = Array.prototype.indexOf.call(buf, cp, last);
}
if (last !== buf.length) {
list.push(buf.slice(last));
list.push(buf.subarray(last));
}
return list;
}
function replaceByteInByteSequence(buf, from, to) {
var i = buf.indexOf(from);
var i = Array.prototype.indexOf.call(buf, from);
while (i >= 0) {
buf[i] = to;
i = buf.indexOf(from, i + 1);
i = Array.prototype.indexOf.call(buf, from, i + 1);
}
return buf;
}
Expand Down
20 changes: 20 additions & 0 deletions polyfills/URL/update.task.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ const codeProcessors = [
'Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength")?.get ?? Object.getOwnPropertyDescriptor(new Uint8Array(), "byteLength")?.get;'
)
},
{
filename: "node_modules/whatwg-url/lib/percent-encoding.js",
description: "replace `typedArray.slice` with `typedArray.subarray`",
processor: (code) =>
code.replace(
/return output\.slice\(0, outputIndex\);/,
"return output.subarray(0, outputIndex);"
)
},
{
filename: "node_modules/whatwg-url/lib/urlencoded.js",
description:
"replace `typedArray.slice` with `typedArray.subarray` and `typedArray.indexOf` with `Array.prototype.indexOf`",
processor: (code) =>
code
.replace(/bytes\.slice\(/g, "bytes.subarray(")
.replace(/buf\.slice\(/g, "buf.subarray(")
.replace(/bytes\.indexOf\(/g, "Array.prototype.indexOf.call(bytes, ")
.replace(/buf\.indexOf\(/g, "Array.prototype.indexOf.call(buf, ")
},
{
filename: "node_modules/whatwg-url/lib/URL.js",
description:
Expand Down