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

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

Issue 3126029: Move the chromium.Interval to chrome.Interval as part of the benchmarking... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: One more missing file!! Created 10 years, 4 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/glue/webkit_glue.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/extensions/v8/interval_extension.h"
6 #include "base/time.h"
7
8 namespace extensions_v8 {
9
10 const char* kIntervalExtensionName = "v8/Interval";
11
12 class IntervalExtensionWrapper : public v8::Extension {
13 public:
14 IntervalExtensionWrapper()
15 : v8::Extension(
16 kIntervalExtensionName,
17 "var chromium;"
18 "if (!chromium)"
19 " chromium = {};"
20 "chromium.Interval = function() {"
21 " var start_ = 0;"
22 " var stop_ = 0;"
23 " native function HiResTime();"
24 " this.start = function() {"
25 " stop_ = 0;"
26 " start_ = HiResTime();"
27 " };"
28 " this.stop = function() {"
29 " stop_ = HiResTime();"
30 " if (start_ == 0)"
31 " stop_ = 0;"
32 " };"
33 " this.microseconds = function() {"
34 " var stop = stop_;"
35 " if (stop == 0 && start_ != 0)"
36 " stop = HiResTime();"
37 " return Math.ceil((stop - start_) * 1000000);"
38 " };"
39 "}") {}
40
41 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
42 v8::Handle<v8::String> name) {
43 if (name->Equals(v8::String::New("HiResTime"))) {
44 return v8::FunctionTemplate::New(HiResTime);
45 }
46 return v8::Handle<v8::FunctionTemplate>();
47 }
48
49 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) {
50 return v8::Number::New(base::Time::Now().ToDoubleT());
51 }
52 };
53
54 v8::Extension* IntervalExtension::Get() {
55 return new IntervalExtensionWrapper();
56 }
57
58 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « webkit/extensions/v8/interval_extension.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698