Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: elevate v8 namespaces of referenced artifacts #24424

Merged
merged 1 commit into from
Nov 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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