diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 05:12:56 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 05:12:56 +0000 |
commit | efc593a5fa03e12f555164e8670d8af028b686fc (patch) | |
tree | d54e50f9515da5499468b299576868d561324598 /webkit/extensions | |
parent | aa08c7a6cb05e2490eacaa5d7a925e4ff78345a6 (diff) | |
download | chromium_src-efc593a5fa03e12f555164e8670d8af028b686fc.zip chromium_src-efc593a5fa03e12f555164e8670d8af028b686fc.tar.gz chromium_src-efc593a5fa03e12f555164e8670d8af028b686fc.tar.bz2 |
Reland interval change.
Move the chromium.Interval to chrome.Interval as part of the benchmarking
extension. This means that users will need to use --enable-benchmarking
to access it. It really shouldn't be part of the exposed API.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3240001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57638 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/extensions')
-rw-r--r-- | webkit/extensions/v8/benchmarking_extension.cc | 29 | ||||
-rw-r--r-- | webkit/extensions/v8/interval_extension.cc | 58 | ||||
-rw-r--r-- | webkit/extensions/v8/interval_extension.h | 22 |
3 files changed, 29 insertions, 80 deletions
diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc index 31bb080..1a30968 100644 --- a/webkit/extensions/v8/benchmarking_extension.cc +++ b/webkit/extensions/v8/benchmarking_extension.cc @@ -4,6 +4,7 @@ #include "base/command_line.h" #include "base/stats_table.h" +#include "base/time.h" #include "net/http/http_network_layer.h" #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" #include "webkit/extensions/v8/benchmarking_extension.h" @@ -45,6 +46,26 @@ class BenchmarkingWrapper : public v8::Extension { " native function IsSingleProcess();" " return IsSingleProcess();" "};" + "chrome.Interval = function() {" + " var start_ = 0;" + " var stop_ = 0;" + " native function HiResTime();" + " this.start = function() {" + " stop_ = 0;" + " start_ = HiResTime();" + " };" + " this.stop = function() {" + " stop_ = HiResTime();" + " if (start_ == 0)" + " stop_ = 0;" + " };" + " this.microseconds = function() {" + " var stop = stop_;" + " if (stop == 0 && start_ != 0)" + " stop = HiResTime();" + " return Math.ceil(stop - start_);" + " };" + "}" ) {} virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( @@ -59,7 +80,10 @@ class BenchmarkingWrapper : public v8::Extension { return v8::FunctionTemplate::New(GetCounter); } else if (name->Equals(v8::String::New("IsSingleProcess"))) { return v8::FunctionTemplate::New(IsSingleProcess); + } else if (name->Equals(v8::String::New("HiResTime"))) { + return v8::FunctionTemplate::New(HiResTime); } + return v8::Handle<v8::FunctionTemplate>(); } @@ -99,6 +123,11 @@ class BenchmarkingWrapper : public v8::Extension { static v8::Handle<v8::Value> IsSingleProcess(const v8::Arguments& args) { return v8::Boolean::New(webkit_glue::IsSingleProcess()); } + + static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { + return v8::Number::New( + static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); + } }; v8::Extension* BenchmarkingExtension::Get() { diff --git a/webkit/extensions/v8/interval_extension.cc b/webkit/extensions/v8/interval_extension.cc deleted file mode 100644 index 95b69a5..0000000 --- a/webkit/extensions/v8/interval_extension.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/extensions/v8/interval_extension.h" -#include "base/time.h" - -namespace extensions_v8 { - -const char* kIntervalExtensionName = "v8/Interval"; - -class IntervalExtensionWrapper : public v8::Extension { - public: - IntervalExtensionWrapper() - : v8::Extension( - kIntervalExtensionName, - "var chromium;" - "if (!chromium)" - " chromium = {};" - "chromium.Interval = function() {" - " var start_ = 0;" - " var stop_ = 0;" - " native function HiResTime();" - " this.start = function() {" - " stop_ = 0;" - " start_ = HiResTime();" - " };" - " this.stop = function() {" - " stop_ = HiResTime();" - " if (start_ == 0)" - " stop_ = 0;" - " };" - " this.microseconds = function() {" - " var stop = stop_;" - " if (stop == 0 && start_ != 0)" - " stop = HiResTime();" - " return Math.ceil((stop - start_) * 1000000);" - " };" - "}") {} - - virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( - v8::Handle<v8::String> name) { - if (name->Equals(v8::String::New("HiResTime"))) { - return v8::FunctionTemplate::New(HiResTime); - } - return v8::Handle<v8::FunctionTemplate>(); - } - - static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { - return v8::Number::New(base::Time::Now().ToDoubleT()); - } -}; - -v8::Extension* IntervalExtension::Get() { - return new IntervalExtensionWrapper(); -} - -} // namespace extensions_v8 diff --git a/webkit/extensions/v8/interval_extension.h b/webkit/extensions/v8/interval_extension.h deleted file mode 100644 index 83e37bc..0000000 --- a/webkit/extensions/v8/interval_extension.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// The IntervalExtension is a v8 extension to implement a simple interval -// class for measuring microsecond intervals. - -#ifndef WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_ -#define WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_ - -#include "v8/include/v8.h" - -namespace extensions_v8 { - -class IntervalExtension { - public: - static v8::Extension* Get(); -}; - -} // namespace extensions_v8 - -#endif // WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_ |