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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/d8-performance-now.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; 159 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
160 CounterCollection Shell::local_counters_; 160 CounterCollection Shell::local_counters_;
161 CounterCollection* Shell::counters_ = &local_counters_; 161 CounterCollection* Shell::counters_ = &local_counters_;
162 i::Mutex Shell::context_mutex_; 162 i::Mutex Shell::context_mutex_;
163 Persistent<Context> Shell::utility_context_; 163 Persistent<Context> Shell::utility_context_;
164 #endif // V8_SHARED 164 #endif // V8_SHARED
165 165
166 Persistent<Context> Shell::evaluation_context_; 166 Persistent<Context> Shell::evaluation_context_;
167 ShellOptions Shell::options; 167 ShellOptions Shell::options;
168 const char* Shell::kPrompt = "d8> "; 168 const char* Shell::kPrompt = "d8> ";
169 const i::TimeTicks Shell::kInitialTicks = i::TimeTicks::HighResolutionNow();
169 170
170 171
171 const int MB = 1024 * 1024; 172 const int MB = 1024 * 1024;
172 173
173 174
174 #ifndef V8_SHARED 175 #ifndef V8_SHARED
175 bool CounterMap::Match(void* key1, void* key2) { 176 bool CounterMap::Match(void* key1, void* key2) {
176 const char* name1 = reinterpret_cast<const char*>(key1); 177 const char* name1 = reinterpret_cast<const char*>(key1);
177 const char* name2 = reinterpret_cast<const char*>(key2); 178 const char* name2 = reinterpret_cast<const char*>(key2);
178 return strcmp(name1, name2) == 0; 179 return strcmp(name1, name2) == 0;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 283
283 284
284 int PerIsolateData::RealmFind(Handle<Context> context) { 285 int PerIsolateData::RealmFind(Handle<Context> context) {
285 for (int i = 0; i < realm_count_; ++i) { 286 for (int i = 0; i < realm_count_; ++i) {
286 if (realms_[i] == context) return i; 287 if (realms_[i] == context) return i;
287 } 288 }
288 return -1; 289 return -1;
289 } 290 }
290 291
291 292
293 // window.performance.now() returns a time stamp as double, measured in
294 // milliseconds.
295 void Shell::WindowPerformanceNow(
296 const v8::FunctionCallbackInfo<v8::Value>& args) {
297 i::TimeDelta delta = i::TimeTicks::HighResolutionNow() - kInitialTicks;
298 args.GetReturnValue().Set(delta.InMillisecondsF());
299 }
300
301
292 // Realm.current() returns the index of the currently active realm. 302 // Realm.current() returns the index of the currently active realm.
293 void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) { 303 void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) {
294 Isolate* isolate = args.GetIsolate(); 304 Isolate* isolate = args.GetIsolate();
295 PerIsolateData* data = PerIsolateData::Get(isolate); 305 PerIsolateData* data = PerIsolateData::Get(isolate);
296 int index = data->RealmFind(isolate->GetEnteredContext()); 306 int index = data->RealmFind(isolate->GetEnteredContext());
297 if (index == -1) return; 307 if (index == -1) return;
298 args.GetReturnValue().Set(index); 308 args.GetReturnValue().Set(index);
299 } 309 }
300 310
301 311
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 realm_template->Set(String::New("dispose"), 875 realm_template->Set(String::New("dispose"),
866 FunctionTemplate::New(RealmDispose)); 876 FunctionTemplate::New(RealmDispose));
867 realm_template->Set(String::New("switch"), 877 realm_template->Set(String::New("switch"),
868 FunctionTemplate::New(RealmSwitch)); 878 FunctionTemplate::New(RealmSwitch));
869 realm_template->Set(String::New("eval"), 879 realm_template->Set(String::New("eval"),
870 FunctionTemplate::New(RealmEval)); 880 FunctionTemplate::New(RealmEval));
871 realm_template->SetAccessor(String::New("shared"), 881 realm_template->SetAccessor(String::New("shared"),
872 RealmSharedGet, RealmSharedSet); 882 RealmSharedGet, RealmSharedSet);
873 global_template->Set(String::New("Realm"), realm_template); 883 global_template->Set(String::New("Realm"), realm_template);
874 884
885 Handle<ObjectTemplate> window_template = ObjectTemplate::New();
886 Handle<ObjectTemplate> performance_template = ObjectTemplate::New();
887 performance_template->Set(String::New("now"),
888 FunctionTemplate::New(WindowPerformanceNow));
889 window_template->Set(String::New("performance"), performance_template);
890 global_template->Set(String::New("window"), window_template);
891
875 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) 892 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64)
876 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 893 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
877 AddOSMethods(os_templ); 894 AddOSMethods(os_templ);
878 global_template->Set(String::New("os"), os_templ); 895 global_template->Set(String::New("os"), os_templ);
879 #endif // V8_SHARED 896 #endif // V8_SHARED
880 897
881 return global_template; 898 return global_template;
882 } 899 }
883 900
884 901
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 } 1755 }
1739 1756
1740 } // namespace v8 1757 } // namespace v8
1741 1758
1742 1759
1743 #ifndef GOOGLE3 1760 #ifndef GOOGLE3
1744 int main(int argc, char* argv[]) { 1761 int main(int argc, char* argv[]) {
1745 return v8::Shell::Main(argc, argv); 1762 return v8::Shell::Main(argc, argv);
1746 } 1763 }
1747 #endif 1764 #endif
OLDNEW
« 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