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

intl: Add more versions from ICU #9266

Closed
wants to merge 1 commit into from

Conversation

srl295
Copy link
Member

@srl295 srl295 commented Oct 25, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

intl, bootstrap_node.js

Description of change
  • Adds process.versions.cldr, .tz, and .unicode
  • Changes how process.versions.icu is loaded
  • Lazy loads the process.versions.* values for these
  • Note: "node -p process.versions" shows "[Getter]" for these values

Fixes: #9237

@srl295 srl295 self-assigned this Oct 25, 2016
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Oct 25, 2016
@srl295 srl295 force-pushed the icu-more-versions branch 3 times, most recently from be6c2d7 to 1ee56e5 Compare October 25, 2016 02:27
@srl295 srl295 added the i18n-api Issues and PRs related to the i18n implementation. label Oct 25, 2016
@@ -304,6 +306,40 @@
};
}

function setupProcessICUVersions() {
const icu = process.binding('icu');
if (icu) {
Copy link
Member

Choose a reason for hiding this comment

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

I usually find if (!icu) return; a bit easier to read, but maybe that’s only because it avoids the extra indentation level, so feel free to keep this as it is.

const object = process.versions;
// if ICU is present, fetch additional versions
// TODO(srl295): should this be a comma separated list or something else?
const versionTypes = icu.getVersion().split(',');
Copy link
Member

Choose a reason for hiding this comment

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

I think a comma-separated list is fine for this, but maybe the preceding comment should contain a quick reminder that icu.getVersion() without arguments returns the list of available different versions.


return realValue;
},
// set: setReal,
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just drop this line

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. I'd think the original caller wouldn't get a value, but I'll try it.

Copy link
Member

Choose a reason for hiding this comment

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

@srl295 I’m referring to the comment, in case that’s not clear :)

Copy link
Member Author

Choose a reason for hiding this comment

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

> process.versions.icu
undefined
> process.versions.icu
'57.1'

so, I think I need this…

Copy link
Member

Choose a reason for hiding this comment

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

@srl295 what part did you remove? What I meant was the // set: setReal, comment, because that’s a leftover from copying, and it seems a bit confusing given that there is no setReal defined here

* @param status ICU error status. If failure, assume result is undefined.
* @return version number, or NULL. May or may not be buf.
*/
static const char *GetVersion(const char *type,
Copy link
Member

Choose a reason for hiding this comment

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

I think the prevalent style in this codebase is having the * on the left, i.e. const char* everywhere

* @return version number, or NULL. May or may not be buf.
*/
static const char *GetVersion(const char *type,
char buf[U_MAX_VERSION_STRING_LENGTH],
Copy link
Member

Choose a reason for hiding this comment

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

Could you indent this so that the parameters align vertically?

Copy link
Member Author

Choose a reason for hiding this comment

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

giving up on trying to use the ICU convention of "UErrorCode& status" here… I can't keep the NOLINT, arg indent, AND stay under the line width. What does cpplint have against non-const references? 👎

if (U_SUCCESS(status)) {
u_versionToString(versionArray, buf);
}
return buf;
Copy link
Member

Choose a reason for hiding this comment

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

I would probably prefer an explicit return NULL; in the case of failure here.

Copy link
Member

Choose a reason for hiding this comment

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

(whispers) nullptr

@srl295
Copy link
Member Author

srl295 commented Oct 25, 2016

well, this isn't good:

$ configure --without-intl
$ ./node 
bootstrap_node.js:310
    const icu = process.binding('icu');
                        ^

Error: No such module: icu
    at setupProcessICUVersions (bootstrap_node.js:310:25)
    at startup (bootstrap_node.js:29:5)
    at bootstrap_node.js:533:3

What's that about breaking non-intl builds? Looks like from url.js it seems I need a try/catch here…  or is it better to check v8_enable_i18n_support or something?

@addaleax
Copy link
Member

Looks like from url.js it seems I need a try/catch here

Sounds reasonable to me

Note: "node -p process.versions" shows "[Getter]" for these values

Yeah, we probably should override util.inspect for process.versions. There’s some info about how to do that in the docs and a WIP PR with a more sophisticated example, if it helps.

Or, if somebody else thinks that makes sense, we could add another Symbol that could be used for tagging objects so that util.inspect knows that it should resolve getters on that object, e.g.:

const foobar = Object.create({}, {
  a: {
    get() { return 42; },
    enumerable: true
  }
});

console.log(foobar); // prints `{ a: [Getter] }`

foobar[util.inspect.resolveGetters] = true;

console.log(foobar); // prints `{ a: 42 }`

@srl295
Copy link
Member Author

srl295 commented Oct 25, 2016

@addaleax I'll look at those examples, and push what I have. I'd probably go for overriding in this PR and it can be made a tag later? Seems like that would want some more design than the low-level stuff I'm doing now.

Update: It doesn't seem to work to require('util') from within bootstrap_node.js … 

This sort of works, but I don't know where it can be executed:

process.versions[util.inspect.custom] = (depth) => JSON.stringify(process.versions);

update update i found a place to run it… 

Also , rebased because of #9038

@srl295 srl295 force-pushed the icu-more-versions branch 2 times, most recently from ad20744 to 9b5a808 Compare October 25, 2016 18:10
@@ -304,6 +306,40 @@
};
}

function setupProcessICUVersions() {
var icu;
Copy link
Member

Choose a reason for hiding this comment

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

You can also check process.binding('config').hasIntl here... e.g.

const icu = process.binding('config').hasIntl ?
  process.binding('icu') : undefined;

Copy link
Member Author

Choose a reason for hiding this comment

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

yes… that's what I wanted.

String::NewFromUtf8(env->isolate(),
versionString));
} else {
// Fail => undefined
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be necessary to set explicitly. The function will return undefined automatically if no return value is set.

@srl295
Copy link
Member Author

srl295 commented Oct 25, 2016

by the way - I verified with lsof that ICU data is not loaded until after process.versions.cldr, etc, is called. So, the laziness is working.

if (!icu) return; // no Intl/ICU: nothing to add here.
// With no argument, getVersion() returns a comma separated list
// of possible types.
const versionTypes = icu.getVersion().split(',');
Copy link
Member

Choose a reason for hiding this comment

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

Why not have icu.getVersion() simply return an Array? Or perhaps (even better) an object with the keys and values already set so that there is only one call to the binding layer?

Copy link
Member

Choose a reason for hiding this comment

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

Oh... I see... nevermind, lazy loading and all that...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it could return an Array from C++ instead.


// process.versions needs a custom function as some values are lazy-evaluated.
process.versions[exports.inspect.custom] =
(depth) => exports.format(JSON.parse(JSON.stringify(process.versions)));
Copy link
Member Author

Choose a reason for hiding this comment

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

Just making sure - should this be "if intlEnabled"? It doesn't need to be, but just a question.

* Adds process.versions.cldr, .tz, and .unicode
* Changes how process.versions.icu is loaded
* Lazy loads the process.versions.* values for these
* add an exception to util.js
   to cause 'node -p process.versions' to still work
* update process.version docs

Fixes: nodejs#9237
@srl295
Copy link
Member Author

srl295 commented Oct 27, 2016

Landed in 4fb27d4

@srl295 srl295 closed this Oct 27, 2016
@srl295 srl295 deleted the icu-more-versions branch October 27, 2016 02:28
@srl295
Copy link
Member Author

srl295 commented Oct 27, 2016

@sam-github pointed out that 4fb27d4 was landed with bad formatting.

@sam-github
Copy link
Contributor

The PR and Reviewed-By metadata didn't get added during merge.

@srl295 did you get the collaborator onboarding? Or was it long ago, and you forgot? :-)

addaleax referenced this pull request Oct 28, 2016
* Adds process.versions.cldr, .tz, and .unicode
* Changes how process.versions.icu is loaded
* Lazy loads the process.versions.* values for these
* add an exception to util.js
   to cause 'node -p process.versions' to still work
* update process.version docs

Fixes: #9237
@addaleax
Copy link
Member

addaleax commented Oct 28, 2016

@srl295 Since I’ve found it helpful that others added the metadata as a github comment on commits where I had forgotten to add it, I’ve gone ahead and did the same + took the liberty to add me as a reviewer. :)

(Also: Is this semver-minor?)

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Oct 29, 2016
@jasnell
Copy link
Member

jasnell commented Oct 29, 2016

Yes, this would be semver-minor, good catch. I added the label.

@srl295
Copy link
Member Author

srl295 commented Oct 29, 2016

Thanks and yes minor

On Friday, October 28, 2016, James M Snell notifications@github.com wrote:

Yes, this would be semver-minor, good catch. I added the label.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9266 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AA0Ms5-Lz-YtCXwpHMtT-2fImF87w6ISks5q4pjigaJpZM4Kfeak
.

evanlucas pushed a commit that referenced this pull request Nov 3, 2016
* Adds process.versions.cldr, .tz, and .unicode
* Changes how process.versions.icu is loaded
* Lazy loads the process.versions.* values for these
* add an exception to util.js
   to cause 'node -p process.versions' to still work
* update process.version docs

PR-URL: #9266
Fixes: #9237
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

adding don't land for v4.x

is this something we would want to consider in a future minor to v6?

@gibfahn
Copy link
Member

gibfahn commented Jun 17, 2017

is this something we would want to consider in a future minor to v6?

ping @srl295

@gibfahn
Copy link
Member

gibfahn commented Sep 24, 2017

Should land with #13221 if it lands on v6.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. i18n-api Issues and PRs related to the i18n implementation. lib / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants