Skip to content

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

Merged
merged 1 commit into from
Nov 18, 2023
Merged

Add performance.{now,timeOrigin} #83

merged 1 commit into from
Nov 18, 2023

Conversation

saghul
Copy link
Contributor

@saghul saghul commented Nov 17, 2023

Ref: #16

@saghul saghul requested a review from bnoordhuis November 17, 2023 23:03
@saghul
Copy link
Contributor Author

saghul commented Nov 17, 2023

@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 JS_NewContext2(rt, flags) ?

Copy link
Contributor

@bnoordhuis bnoordhuis left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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;

Comment on lines +50253 to +50258
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);

@bnoordhuis
Copy link
Contributor

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 JS_NewContext2(rt, flags) ?

I was thinking of an opt-in (so not adding it by default) but, OTOH, it's probably fine.

@saghul saghul merged commit ea068d9 into master Nov 18, 2023
@saghul saghul deleted the performance branch November 18, 2023 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants