Skip to content

Commit

Permalink
src: elevate v8 namespaces of referenced artifacts
Browse files Browse the repository at this point in the history
PR-URL: #24424
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
singhalkanika198 authored and codebytere committed Jan 29, 2019
1 parent 5d2dadc commit fa52ba6
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ namespace performance {

using v8::Array;
using v8::Context;
using v8::DontDelete;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::GCCallbackFlags;
using v8::GCType;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Name;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::PropertyAttribute;
using v8::ReadOnly;
using v8::String;
using v8::Uint32Array;
using v8::Value;

// Microseconds in a second, as a float.
Expand All @@ -36,7 +43,7 @@ uint64_t performance_node_start;
uint64_t performance_v8_start;

uint64_t performance_last_gc_start_mark_ = 0;
v8::GCType performance_last_gc_type_ = v8::GCType::kGCTypeAll;
GCType performance_last_gc_type_ = GCType::kGCTypeAll;

void performance_state::Mark(enum PerformanceMilestone milestone,
uint64_t ts) {
Expand Down Expand Up @@ -69,21 +76,21 @@ inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) {
Environment* env = entry.env();
Isolate* isolate = env->isolate();
Local<Context> context = env->context();
v8::PropertyAttribute attr =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
PropertyAttribute attr =
static_cast<PropertyAttribute>(ReadOnly | DontDelete);
obj->DefineOwnProperty(context,
env->name_string(),
String::NewFromUtf8(isolate,
entry.name().c_str(),
v8::NewStringType::kNormal)
NewStringType::kNormal)
.ToLocalChecked(),
attr)
.FromJust();
obj->DefineOwnProperty(context,
env->entry_type_string(),
String::NewFromUtf8(isolate,
entry.type().c_str(),
v8::NewStringType::kNormal)
NewStringType::kNormal)
.ToLocalChecked(),
attr)
.FromJust();
Expand Down Expand Up @@ -124,7 +131,7 @@ void PerformanceEntry::Notify(Environment* env,
PerformanceEntryType type,
Local<Value> object) {
Context::Scope scope(env->context());
AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
AliasedBuffer<uint32_t, Uint32Array>& observers =
env->performance_state()->observers;
if (type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID &&
observers[type]) {
Expand Down Expand Up @@ -242,12 +249,12 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
HandleScope scope(env->isolate());
Local<Context> context = env->context();

AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
AliasedBuffer<uint32_t, Uint32Array>& observers =
env->performance_state()->observers;
if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) {
Local<Object> obj = entry->ToObject();
v8::PropertyAttribute attr =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
PropertyAttribute attr =
static_cast<PropertyAttribute>(ReadOnly | DontDelete);
obj->DefineOwnProperty(context,
env->kind_string(),
Integer::New(env->isolate(), entry->gckind()),
Expand All @@ -260,16 +267,16 @@ void PerformanceGCCallback(Environment* env, void* ptr) {

// Marks the start of a GC cycle
void MarkGarbageCollectionStart(Isolate* isolate,
v8::GCType type,
v8::GCCallbackFlags flags) {
GCType type,
GCCallbackFlags flags) {
performance_last_gc_start_mark_ = PERFORMANCE_NOW();
performance_last_gc_type_ = type;
}

// Marks the end of a GC cycle
void MarkGarbageCollectionEnd(Isolate* isolate,
v8::GCType type,
v8::GCCallbackFlags flags,
GCType type,
GCCallbackFlags flags,
void* data) {
Environment* env = static_cast<Environment*>(data);
// If no one is listening to gc performance entries, do not create them.
Expand Down Expand Up @@ -341,7 +348,7 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
return;
args.GetReturnValue().Set(ret.ToLocalChecked());

AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
AliasedBuffer<uint32_t, Uint32Array>& observers =
env->performance_state()->observers;
if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])
return;
Expand Down Expand Up @@ -414,18 +421,18 @@ void Initialize(Local<Object> target,
NODE_PERFORMANCE_MILESTONES(V)
#undef V

v8::PropertyAttribute attr =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
PropertyAttribute attr =
static_cast<PropertyAttribute>(ReadOnly | DontDelete);

target->DefineOwnProperty(context,
FIXED_ONE_BYTE_STRING(isolate, "timeOrigin"),
v8::Number::New(isolate, timeOrigin / 1e6),
Number::New(isolate, timeOrigin / 1e6),
attr).ToChecked();

target->DefineOwnProperty(
context,
FIXED_ONE_BYTE_STRING(isolate, "timeOriginTimestamp"),
v8::Number::New(isolate, timeOriginTimestamp / MICROS_PER_MILLIS),
Number::New(isolate, timeOriginTimestamp / MICROS_PER_MILLIS),
attr).ToChecked();

target->DefineOwnProperty(context,
Expand Down

0 comments on commit fa52ba6

Please sign in to comment.