Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: src/d8.cc

Issue 32433010: Add performance.now() to the d8 shell. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comment Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/d8-performance-now.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 96407a897c98b1284a3f9b1dd78bb457c5b08bd7..0efaeb76af56f18e73ecceb23a898b9351aa2706 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -166,6 +166,7 @@ Persistent<Context> Shell::utility_context_;
Persistent<Context> Shell::evaluation_context_;
ShellOptions Shell::options;
const char* Shell::kPrompt = "d8> ";
+const i::TimeTicks Shell::kInitialTicks = i::TimeTicks::HighResolutionNow();
const int MB = 1024 * 1024;
@@ -289,6 +290,15 @@ int PerIsolateData::RealmFind(Handle<Context> context) {
}
+// window.performance.now() returns a time stamp as double, measured in
+// milliseconds.
+void Shell::WindowPerformanceNow(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ i::TimeDelta delta = i::TimeTicks::HighResolutionNow() - kInitialTicks;
+ args.GetReturnValue().Set(delta.InMillisecondsF());
+}
+
+
// Realm.current() returns the index of the currently active realm.
void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
@@ -872,6 +882,13 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
RealmSharedGet, RealmSharedSet);
global_template->Set(String::New("Realm"), realm_template);
+ Handle<ObjectTemplate> window_template = ObjectTemplate::New();
+ Handle<ObjectTemplate> performance_template = ObjectTemplate::New();
+ performance_template->Set(String::New("now"),
+ FunctionTemplate::New(WindowPerformanceNow));
+ window_template->Set(String::New("performance"), performance_template);
+ global_template->Set(String::New("window"), window_template);
+
#if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64)
Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
AddOSMethods(os_templ);
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/d8-performance-now.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698