forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a monotonic_clock module for Mojo.js.
Am having trouble coming up with a satisfactory way to test. BUG= Review URL: https://codereview.chromium.org/129633005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244062 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
aa@chromium.org
committed
Jan 10, 2014
1 parent
2549d89
commit 89adefd
Showing
9 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2014 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 "mojo/apps/js/bindings/monotonic_clock.h" | ||
|
||
#include "gin/object_template_builder.h" | ||
#include "gin/per_isolate_data.h" | ||
#include "gin/public/wrapper_info.h" | ||
#include "mojo/public/system/core_cpp.h" | ||
|
||
namespace mojo { | ||
namespace apps { | ||
|
||
namespace { | ||
|
||
gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | ||
|
||
double GetMonotonicSeconds() { | ||
const double kMicrosecondsPerSecond = 1000000; | ||
return static_cast<double>(mojo::GetTimeTicksNow()) / kMicrosecondsPerSecond; | ||
} | ||
|
||
} // namespace | ||
|
||
const char MonotonicClock::kModuleName[] = "monotonic_clock"; | ||
|
||
v8::Local<v8::Value> MonotonicClock::GetModule(v8::Isolate* isolate) { | ||
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | ||
v8::Local<v8::ObjectTemplate> templ = | ||
data->GetObjectTemplate(&g_wrapper_info); | ||
if (templ.IsEmpty()) { | ||
templ = gin::ObjectTemplateBuilder(isolate) | ||
.SetMethod("seconds", GetMonotonicSeconds) | ||
.Build(); | ||
data->SetObjectTemplate(&g_wrapper_info, templ); | ||
} | ||
return templ->NewInstance(); | ||
} | ||
|
||
} // namespace apps | ||
} // namespace mojo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2014 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. | ||
|
||
#ifndef MOJO_APPS_JS_BINDING_MONOTONIC_CLOCK_H_ | ||
#define MOJO_APPS_JS_BINDING_MONOTONIC_CLOCK_H_ | ||
|
||
#include "v8/include/v8.h" | ||
|
||
namespace mojo { | ||
namespace apps { | ||
|
||
class MonotonicClock { | ||
public: | ||
static const char kModuleName[]; | ||
static v8::Local<v8::Value> GetModule(v8::Isolate* isolate); | ||
}; | ||
|
||
} // namespace apps | ||
} // namespace mojo | ||
|
||
#endif // MOJO_APPS_JS_BINDING_MONOTONIC_CLOCK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2014 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. | ||
|
||
define([ | ||
"console", | ||
"gin/test/expect", | ||
"monotonic_clock", | ||
"timer", | ||
"mojo/apps/js/bindings/threading" | ||
], function(console, expect, monotonicClock, timer, threading) { | ||
var global = this; | ||
var then = monotonicClock.seconds(); | ||
var t = timer.createOneShot(100, function() { | ||
var now = monotonicClock.seconds(); | ||
expect(now).toBeGreaterThan(then); | ||
global.result = "PASS"; | ||
threading.quit(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters