Skip to content

Fix fromCharCodes & fromCodePoints polyfills #1340

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

Merged
merged 10 commits into from
Jun 14, 2020
Merged
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
32 changes: 30 additions & 2 deletions std/portable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,39 @@ globalScope["changetype"] = function changetype(value) {
};

String["fromCharCodes"] = function fromCharCodes(arr) {
return String.fromCharCode.apply(String, arr);
const CHUNKSIZE = 1 << 13;
const len = arr.length;
if (len <= CHUNKSIZE) {
return String.fromCharCode.apply(String, arr);
}
let index = 0;
let parts = '';
while (index < len) {
parts += String.fromCharCode.apply(
String,
arr.slice(index, Math.min(index + CHUNKSIZE, len))
);
index += CHUNKSIZE;
}
return parts;
};

String["fromCodePoints"] = function fromCodePoints(arr) {
return String.fromCodePoint.apply(String, arr);
const CHUNKSIZE = 1 << 13;
const len = arr.length;
if (len <= CHUNKSIZE) {
return String.fromCodePoint.apply(String, arr);
}
let index = 0;
let parts = '';
while (index < len) {
parts += String.fromCodePoint.apply(
String,
arr.slice(index, Math.min(index + CHUNKSIZE, len))
);
index += CHUNKSIZE;
}
return parts;
};

if (!String.prototype.replaceAll) {
Expand Down