-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathPerformance.cpp
More file actions
63 lines (49 loc) · 1.82 KB
/
Copy pathPerformance.cpp
File metadata and controls
63 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "Performance.h"
#include "BuiltinLoader.h"
#include "Helpers.h"
#include "Runtime.h"
using namespace v8;
namespace tns {
void Performance::Init(v8::Local<v8::Context> context) {
Isolate* isolate = v8::Isolate::GetCurrent();
// kThrow so `new performance.now()` throws, as WebIDL operations must;
// kHasNoSideEffect so the debugger can call it during side-effect-free
// evaluation.
Local<v8::Function> now;
bool success = v8::Function::New(context, NowCallback, Local<Value>(), 0,
ConstructorBehavior::kThrow,
SideEffectType::kHasNoSideEffect)
.ToLocal(&now);
tns::Assert(success, isolate);
Local<Object> binding = Object::New(isolate);
success = binding->Set(context, tns::ToV8String(isolate, "now"), now)
.FromMaybe(false);
tns::Assert(success, isolate);
success = binding
->Set(context, tns::ToV8String(isolate, "timeOrigin"),
v8::Number::New(isolate, TimeOriginMillis(isolate)))
.FromMaybe(false);
tns::Assert(success, isolate);
Local<Value> result;
success = BuiltinLoader::RunBuiltin(context, BuiltinId::kPerformance, binding)
.ToLocal(&result);
tns::Assert(success, isolate);
}
double Performance::NowMillis(Isolate* isolate) {
Runtime* runtime = Runtime::GetRuntime(isolate);
if (runtime == nullptr) {
return 0.0;
}
return runtime->PerformanceNowMillis();
}
double Performance::TimeOriginMillis(Isolate* isolate) {
Runtime* runtime = Runtime::GetRuntime(isolate);
if (runtime == nullptr) {
return 0.0;
}
return runtime->TimeOriginMillis();
}
void Performance::NowCallback(const FunctionCallbackInfo<Value>& info) {
info.GetReturnValue().Set(NowMillis(info.GetIsolate()));
}
} // namespace tns