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

Side by Side Diff: webkit/extensions/v8/interval_extension.cc

Issue 40132: Refactor v8 extensions to make registration avoid having to use ChromiumBridg... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | « webkit/extensions/v8/interval_extension.h ('k') | webkit/extensions/v8/playback_extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "base/time.h"
6 #include "Interval.h" 6 #include "webkit/extensions/v8/interval_extension.h"
darin (slow to review) 2009/03/05 17:42:25 minor style nit: foo.cc should list the foo.h incl
7 #include "wtf/CurrentTime.h"
8 7
9 namespace WebCore { 8 namespace extensions_v8 {
10 9
11 const char* kIntervalExtensionName = "v8/Interval"; 10 const char* kIntervalExtensionName = "v8/Interval";
12 11
13 class IntervalExtensionWrapper : public v8::Extension { 12 class IntervalExtensionWrapper : public v8::Extension {
14 public: 13 public:
15 IntervalExtensionWrapper() : 14 IntervalExtensionWrapper()
16 v8::Extension(kIntervalExtensionName, 15 : v8::Extension(
17 "var chromium;" 16 kIntervalExtensionName,
18 "if (!chromium)" 17 "var chromium;"
19 " chromium = {};" 18 "if (!chromium)"
20 "chromium.Interval = function() {" 19 " chromium = {};"
21 " var start_ = 0;" 20 "chromium.Interval = function() {"
22 " var stop_ = 0;" 21 " var start_ = 0;"
23 " native function HiResTime();" 22 " var stop_ = 0;"
24 " this.start = function() {" 23 " native function HiResTime();"
25 " stop_ = 0;" 24 " this.start = function() {"
26 " start_ = HiResTime();" 25 " stop_ = 0;"
27 " };" 26 " start_ = HiResTime();"
28 " this.stop = function() {" 27 " };"
29 " stop_ = HiResTime();" 28 " this.stop = function() {"
30 " if (start_ == 0)" 29 " stop_ = HiResTime();"
31 " stop_ = 0;" 30 " if (start_ == 0)"
32 " };" 31 " stop_ = 0;"
33 " this.microseconds = function() {" 32 " };"
34 " var stop = stop_;" 33 " this.microseconds = function() {"
35 " if (stop == 0 && start_ != 0)" 34 " var stop = stop_;"
36 " stop = HiResTime();" 35 " if (stop == 0 && start_ != 0)"
37 " return Math.ceil((stop - start_) * 1000000);" 36 " stop = HiResTime();"
38 " };" 37 " return Math.ceil((stop - start_) * 1000000);"
39 "}") {}; 38 " };"
39 "}") {}
40 40
41 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(v8::Handle<v8::St ring> name) { 41 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
42 if (name->Equals(v8::String::New("HiResTime"))) 42 v8::Handle<v8::String> name) {
43 return v8::FunctionTemplate::New(HiResTime); 43 if (name->Equals(v8::String::New("HiResTime"))) {
44 return v8::Handle<v8::FunctionTemplate>(); 44 return v8::FunctionTemplate::New(HiResTime);
45 }
46 return v8::Handle<v8::FunctionTemplate>();
45 } 47 }
46 48
47 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { 49 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) {
48 return v8::Number::New(WTF::currentTime()); 50 return v8::Number::New(base::Time::Now().ToDoubleT());
49 } 51 }
50 }; 52 };
51 53
52 v8::Extension* IntervalExtension::Get() { 54 v8::Extension* IntervalExtension::Get() {
53 return new IntervalExtensionWrapper(); 55 return new IntervalExtensionWrapper();
54 } 56 }
55 57
56 } 58 } // namespace extensions_v8
57 59
OLDNEW
« no previous file with comments | « webkit/extensions/v8/interval_extension.h ('k') | webkit/extensions/v8/playback_extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698