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

readline: use native codePointAt #825

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 5 additions & 4 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ Interface.prototype._getDisplayPos = function(str) {
var code;
str = stripVTControlCharacters(str);
for (var i = 0, len = str.length; i < len; i++) {
code = codePointAt(str, i);
code = str.codePointAt(i);
if (code >= 0x10000) { // surrogates
i++;
}
Expand Down Expand Up @@ -605,7 +605,7 @@ Interface.prototype._getCursorPos = function() {
// move the cursor to the beginning of the next line.
if (cols + 1 === columns &&
this.cursor < this.line.length &&
isFullWidthCodePoint(codePointAt(this.line, this.cursor))) {
isFullWidthCodePoint(this.line.codePointAt(this.cursor))) {
rows++;
cols = 0;
}
Expand Down Expand Up @@ -1251,7 +1251,7 @@ function getStringWidth(str) {
var width = 0;
str = stripVTControlCharacters(str);
for (var i = 0, len = str.length; i < len; i++) {
var code = codePointAt(str, i);
var code = str.codePointAt(i);
if (code >= 0x10000) { // surrogates
i++;
}
Expand Down Expand Up @@ -1331,7 +1331,8 @@ function codePointAt(str, index) {
}
return code;
}
exports.codePointAt = codePointAt;
exports.codePointAt = util.deprecate(codePointAt,
'codePointAt() is deprecated. Use String.prototype.codePointAt');
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of deprecating it, could we just alias it to Function.prototype.call.bind(String.prototype.codePointAt) and note that it's there for legacy reasons in the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is actually undocumented and is not supposed to be used anyway. Unfortunately we have a lot of private not underscored stuff

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's undocumented, isn't is subject to disappearing at any time? (I realize someone could be using it)

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I agree with @vkurchatkin. I believe the reason it was exported was so it could be unit-tested in the test suite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess that would a bit irresponsible. People use repl to discover stuff. We need a roadmap to avoid these in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes people use the repl and other reads the code to find and use undocumented apis. I've done it myself, but I do not expect that code to work between versions.



/**
Expand Down