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

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

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
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 "config.h"
6 #include "Interval.h"
7 #include "wtf/CurrentTime.h"
8
9 namespace WebCore {
10
11 const char* kIntervalExtensionName = "v8/Interval";
12
13 class IntervalExtensionWrapper : public v8::Extension {
14 public:
15 IntervalExtensionWrapper() :
16 v8::Extension(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(v8::Handle<v8::St ring> name) {
42 if (name->Equals(v8::String::New("HiResTime")))
43 return v8::FunctionTemplate::New(HiResTime);
44 return v8::Handle<v8::FunctionTemplate>();
45 }
46
47 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) {
48 return v8::Number::New(WTF::currentTime());
49 }
50 };
51
52 v8::Extension* IntervalExtension::Get() {
53 return new IntervalExtensionWrapper();
54 }
55
56 }
57
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698