-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Conversation
be6c2d7
to
1ee56e5
Compare
@@ -304,6 +306,40 @@ | |||
}; | |||
} | |||
|
|||
function setupProcessICUVersions() { | |||
const icu = process.binding('icu'); | |||
if (icu) { |
There was a problem hiding this comment.
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(','); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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…
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(whispers) nullptr
well, this isn't good:
What's that about breaking non-intl builds? Looks like from |
Sounds reasonable to me
Yeah, we probably should override Or, if somebody else thinks that makes sense, we could add another Symbol that could be used for tagging objects so that 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 }` |
@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 This sort of works, but I don't know where it can be executed:
update update i found a place to run it… Also , rebased because of #9038 |
ad20744
to
9b5a808
Compare
@@ -304,6 +306,40 @@ | |||
}; | |||
} | |||
|
|||
function setupProcessICUVersions() { | |||
var icu; |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
by the way - I verified with |
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(','); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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
ed54858
to
e2a8cce
Compare
Landed in 4fb27d4 |
@sam-github pointed out that 4fb27d4 was landed with bad formatting. |
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? :-) |
* 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
@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 |
Yes, this would be semver-minor, good catch. I added the label. |
Thanks and yes minor On Friday, October 28, 2016, James M Snell notifications@github.com wrote:
|
* 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>
adding don't land for v4.x is this something we would want to consider in a future minor to v6? |
ping @srl295 |
Should land with #13221 if it lands on v6.x. |
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
intl, bootstrap_node.js
Description of change
Fixes: #9237