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

Side by Side Diff: webkit/port/bindings/v8/extensions/Interval.cpp

Issue 28201: Changes to the interval timer:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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/data/layout_tests/chrome/fast/dom/extensions/interval-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h"
6 #include "Interval.h" 6 #include "Interval.h"
7 #include "wtf/CurrentTime.h" 7 #include "wtf/CurrentTime.h"
8 8
9 namespace WebCore { 9 namespace WebCore {
10 10
11 const char* kIntervalExtensionName = "v8/Interval"; 11 const char* kIntervalExtensionName = "v8/Interval";
12 12
13 class IntervalExtensionWrapper : public v8::Extension { 13 class IntervalExtensionWrapper : public v8::Extension {
14 public: 14 public:
15 IntervalExtensionWrapper() : 15 IntervalExtensionWrapper() :
16 v8::Extension(kIntervalExtensionName, 16 v8::Extension(kIntervalExtensionName,
17 "native function HiResTime();" 17 "var chromium;"
18 "function Interval() {" 18 "if (!chromium)"
19 " chromium = {};"
20 "chromium.Interval = function() {"
19 " var start_ = 0;" 21 " var start_ = 0;"
20 " var stop_ = 0;" 22 " var stop_ = 0;"
23 " native function HiResTime();"
21 " this.start = function() {" 24 " this.start = function() {"
25 " stop_ = 0;"
22 " start_ = HiResTime();" 26 " start_ = HiResTime();"
23 " };" 27 " };"
24 " this.stop = function() {" 28 " this.stop = function() {"
25 " stop_ = HiResTime();" 29 " stop_ = HiResTime();"
26 " if (start_ == 0)" 30 " if (start_ == 0)"
27 " stop_ = 0;" 31 " stop_ = 0;"
28 " };" 32 " };"
29 " this.microseconds = function() {" 33 " this.microseconds = function() {"
30 " if (stop_ == 0)" 34 " var stop = stop_;"
31 " stop();" 35 " if (stop == 0 && start_ != 0)"
32 " return Math.ceil((stop_ - start_) * 1000000);" 36 " stop = HiResTime();"
37 " return Math.ceil((stop - start_) * 1000000);"
33 " };" 38 " };"
34 "}") {}; 39 "}") {};
35 40
36 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(v8::Handle<v8::St ring> name) { 41 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(v8::Handle<v8::St ring> name) {
37 if (name->Equals(v8::String::New("HiResTime"))) 42 if (name->Equals(v8::String::New("HiResTime")))
38 return v8::FunctionTemplate::New(HiResTime); 43 return v8::FunctionTemplate::New(HiResTime);
39 return v8::Handle<v8::FunctionTemplate>(); 44 return v8::Handle<v8::FunctionTemplate>();
40 } 45 }
41 46
42 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { 47 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) {
43 return v8::Number::New(WTF::currentTime()); 48 return v8::Number::New(WTF::currentTime());
44 } 49 }
45 }; 50 };
46 51
47 v8::Extension* IntervalExtension::Get() { 52 v8::Extension* IntervalExtension::Get() {
48 return new IntervalExtensionWrapper(); 53 return new IntervalExtensionWrapper();
49 } 54 }
50 55
51 } 56 }
52 57
OLDNEW
« no previous file with comments | « webkit/data/layout_tests/chrome/fast/dom/extensions/interval-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698