src: elevate v8 namespaces of referenced artifacts

PR-URL: https://github.com/nodejs/node/pull/24424
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Kanika Singhal 2018-11-17 17:10:27 +05:30 committed by Refael Ackermann
parent 6adbe9a9a0
commit 451fb04b3c

View File

@ -10,17 +10,24 @@ namespace performance {
using v8::Array; using v8::Array;
using v8::Context; using v8::Context;
using v8::DontDelete;
using v8::Function; using v8::Function;
using v8::FunctionCallbackInfo; using v8::FunctionCallbackInfo;
using v8::FunctionTemplate; using v8::FunctionTemplate;
using v8::GCCallbackFlags;
using v8::GCType;
using v8::HandleScope; using v8::HandleScope;
using v8::Integer; using v8::Integer;
using v8::Isolate; using v8::Isolate;
using v8::Local; using v8::Local;
using v8::Name; using v8::Name;
using v8::NewStringType;
using v8::Number; using v8::Number;
using v8::Object; using v8::Object;
using v8::PropertyAttribute;
using v8::ReadOnly;
using v8::String; using v8::String;
using v8::Uint32Array;
using v8::Value; using v8::Value;
// Microseconds in a second, as a float. // Microseconds in a second, as a float.
@ -36,7 +43,7 @@ uint64_t performance_node_start;
uint64_t performance_v8_start; uint64_t performance_v8_start;
uint64_t performance_last_gc_start_mark_ = 0; 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, void performance_state::Mark(enum PerformanceMilestone milestone,
uint64_t ts) { uint64_t ts) {
@ -69,13 +76,13 @@ inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) {
Environment* env = entry.env(); Environment* env = entry.env();
Isolate* isolate = env->isolate(); Isolate* isolate = env->isolate();
Local<Context> context = env->context(); Local<Context> context = env->context();
v8::PropertyAttribute attr = PropertyAttribute attr =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); static_cast<PropertyAttribute>(ReadOnly | DontDelete);
obj->DefineOwnProperty(context, obj->DefineOwnProperty(context,
env->name_string(), env->name_string(),
String::NewFromUtf8(isolate, String::NewFromUtf8(isolate,
entry.name().c_str(), entry.name().c_str(),
v8::NewStringType::kNormal) NewStringType::kNormal)
.ToLocalChecked(), .ToLocalChecked(),
attr) attr)
.FromJust(); .FromJust();
@ -83,7 +90,7 @@ inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) {
env->entry_type_string(), env->entry_type_string(),
String::NewFromUtf8(isolate, String::NewFromUtf8(isolate,
entry.type().c_str(), entry.type().c_str(),
v8::NewStringType::kNormal) NewStringType::kNormal)
.ToLocalChecked(), .ToLocalChecked(),
attr) attr)
.FromJust(); .FromJust();
@ -124,7 +131,7 @@ void PerformanceEntry::Notify(Environment* env,
PerformanceEntryType type, PerformanceEntryType type,
Local<Value> object) { Local<Value> object) {
Context::Scope scope(env->context()); Context::Scope scope(env->context());
AliasedBuffer<uint32_t, v8::Uint32Array>& observers = AliasedBuffer<uint32_t, Uint32Array>& observers =
env->performance_state()->observers; env->performance_state()->observers;
if (type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID && if (type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID &&
observers[type]) { observers[type]) {
@ -242,12 +249,12 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
HandleScope scope(env->isolate()); HandleScope scope(env->isolate());
Local<Context> context = env->context(); Local<Context> context = env->context();
AliasedBuffer<uint32_t, v8::Uint32Array>& observers = AliasedBuffer<uint32_t, Uint32Array>& observers =
env->performance_state()->observers; env->performance_state()->observers;
if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) { if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) {
Local<Object> obj = entry->ToObject(); Local<Object> obj = entry->ToObject();
v8::PropertyAttribute attr = PropertyAttribute attr =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); static_cast<PropertyAttribute>(ReadOnly | DontDelete);
obj->DefineOwnProperty(context, obj->DefineOwnProperty(context,
env->kind_string(), env->kind_string(),
Integer::New(env->isolate(), entry->gckind()), Integer::New(env->isolate(), entry->gckind()),
@ -260,16 +267,16 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
// Marks the start of a GC cycle // Marks the start of a GC cycle
void MarkGarbageCollectionStart(Isolate* isolate, void MarkGarbageCollectionStart(Isolate* isolate,
v8::GCType type, GCType type,
v8::GCCallbackFlags flags) { GCCallbackFlags flags) {
performance_last_gc_start_mark_ = PERFORMANCE_NOW(); performance_last_gc_start_mark_ = PERFORMANCE_NOW();
performance_last_gc_type_ = type; performance_last_gc_type_ = type;
} }
// Marks the end of a GC cycle // Marks the end of a GC cycle
void MarkGarbageCollectionEnd(Isolate* isolate, void MarkGarbageCollectionEnd(Isolate* isolate,
v8::GCType type, GCType type,
v8::GCCallbackFlags flags, GCCallbackFlags flags,
void* data) { void* data) {
Environment* env = static_cast<Environment*>(data); Environment* env = static_cast<Environment*>(data);
// If no one is listening to gc performance entries, do not create them. // If no one is listening to gc performance entries, do not create them.
@ -341,7 +348,7 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
return; return;
args.GetReturnValue().Set(ret.ToLocalChecked()); args.GetReturnValue().Set(ret.ToLocalChecked());
AliasedBuffer<uint32_t, v8::Uint32Array>& observers = AliasedBuffer<uint32_t, Uint32Array>& observers =
env->performance_state()->observers; env->performance_state()->observers;
if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION]) if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])
return; return;
@ -414,18 +421,18 @@ void Initialize(Local<Object> target,
NODE_PERFORMANCE_MILESTONES(V) NODE_PERFORMANCE_MILESTONES(V)
#undef V #undef V
v8::PropertyAttribute attr = PropertyAttribute attr =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); static_cast<PropertyAttribute>(ReadOnly | DontDelete);
target->DefineOwnProperty(context, target->DefineOwnProperty(context,
FIXED_ONE_BYTE_STRING(isolate, "timeOrigin"), FIXED_ONE_BYTE_STRING(isolate, "timeOrigin"),
v8::Number::New(isolate, timeOrigin / 1e6), Number::New(isolate, timeOrigin / 1e6),
attr).ToChecked(); attr).ToChecked();
target->DefineOwnProperty( target->DefineOwnProperty(
context, context,
FIXED_ONE_BYTE_STRING(isolate, "timeOriginTimestamp"), FIXED_ONE_BYTE_STRING(isolate, "timeOriginTimestamp"),
v8::Number::New(isolate, timeOriginTimestamp / MICROS_PER_MILLIS), Number::New(isolate, timeOriginTimestamp / MICROS_PER_MILLIS),
attr).ToChecked(); attr).ToChecked();
target->DefineOwnProperty(context, target->DefineOwnProperty(context,