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
[TIMOB-13379] Implement console.time/timeEnd #9909
Conversation
|
||
exports.time = function (label) { | ||
if (times[label]) { | ||
exports.warn('Label ' + label + ' already exists'); |
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.
imo, this would read nicer using template literals. Which are supported by the v8 version I believe. What're our best practices for the JS code on Android. The eslint options specify ES5
"parserOptions": {
"ecmaVersion": 5,
"sourceType": "script"
}
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'm fine with that since it's supported.
Generated by 🚫 dangerJS |
iphone/Classes/TiConsole.m
Outdated
if (!_times) { | ||
_times = [[NSMutableDictionary alloc] init]; | ||
} | ||
NSString *label = [args componentsJoinedByString:@""] ?: @"default"; |
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.
Should a developer be able to pass an array of argumenzts, e.g. console.time(['test', 'foo'])
? If not, change the arg-type to id
and use ENSURE_SINGLE_ARG(args, NSString);
to force a string directly. Example:
- (void)time:(id)label
{
ENSURE_SINGLE_ARG(label, NSString);
...
}
Same for timeEnd
probably.
@@ -25,6 +25,7 @@ function join(args) { | |||
}).join(' '); | |||
} | |||
|
|||
var times = {}; |
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 move this to the top of console.js
?
apidoc/Global/console/console.yml
Outdated
and a warning will be logged to the console. | ||
parameters: | ||
- name: label | ||
summary: The label to track the timer by, defaults to "default". |
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.
Isn't there an actual default
property you can set 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.
Wasn't aware of that, updated to include default and optional in docs. Making a note to familiarise myself with our doc stuff too :)
if (!label) { | ||
label = 'default'; | ||
} | ||
var startTime = times[label]; |
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.
vars should be declared at top of scope, since they get hoisted up there.
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.
Also, given that we know V8 is newer and can support ES6 natively, is there any reason we can't start making use of es6 syntax in runtime JS code? (i.e. template strings here, use of const/let)
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.
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.
@sgtcoolguy Updated to use template literals, const and a Map instead of a plain object
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.
FYI I filed https://jira.appcelerator.org/browse/TIMOB-25892 to hook the linting up in this folder as grunt lint
doesn't include it currently
[TIMOB-13379] Fix log message, lint code
[TIMOB-13379] Fix lint issue
Make label in double quotes when logging warning, add dealloc, simplify obj-c code when setting default value
'ES6-ify' code, add default and optional to documentation
Windows PR: appcelerator/titanium_mobile_windows#1209 |
JIRA: https://jira.appcelerator.org/browse/TIMOB-13379
Implement console.time/timeEnd according to https://console.spec.whatwg.org/#time, with the optional log on
console.time('duplicate label')
implemented, and a slight deviation to log a warning when callingconsole.timeEnd('does not exist')
.iOS can do a higher precision on the timing due to the implementation being in native but I nerfed for parity, happy to un-nerf though.
Test code
Output