-
Notifications
You must be signed in to change notification settings - Fork 156
Add performance.{now,timeOrigin} #83
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
Conversation
@bnoordhuis Is this what you had in mind or would you rather not add it to the default context? Maybe a compile time flag? A new |
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.
Nice!
// TODO(saghul) Windows support. | ||
struct timespec ts; | ||
clock_gettime(CLOCK_MONOTONIC, &ts); | ||
return (((uint64_t) ts.tv_sec) * 1000 + ts.tv_nsec / 1e6); |
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.
return (((uint64_t) ts.tv_sec) * 1000 + ts.tv_nsec / 1e6); | |
return (uint64_t) ts.tv_sec * 1000 + ts.tv_nsec / 1e6; |
You could also write it as return ts.tv_sec * 1000ull + ts.tv_nsec / 1e6;
JS_DefinePropertyValueStr(ctx, performance, "timeOrigin", | ||
JS_NewFloat64(ctx, ctx->time_origin), | ||
JS_PROP_ENUMERABLE); | ||
JS_DefinePropertyValueStr(ctx, ctx->global_obj, "performance", | ||
JS_DupValue(ctx, performance), | ||
JS_PROP_ENUMERABLE); |
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.
JS_DefinePropertyValueStr(ctx, performance, "timeOrigin", | |
JS_NewFloat64(ctx, ctx->time_origin), | |
JS_PROP_ENUMERABLE); | |
JS_DefinePropertyValueStr(ctx, ctx->global_obj, "performance", | |
JS_DupValue(ctx, performance), | |
JS_PROP_ENUMERABLE); | |
JS_DefinePropertyValueStr(ctx, performance, "timeOrigin", | |
JS_NewFloat64(ctx, ctx->time_origin), | |
JS_PROP_ENUMERABLE); | |
JS_DefinePropertyValueStr(ctx, ctx->global_obj, "performance", | |
JS_DupValue(ctx, performance), | |
JS_PROP_ENUMERABLE); |
I was thinking of an opt-in (so not adding it by default) but, OTOH, it's probably fine. |
Ref: #16