Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[Squash] const the things
  • Loading branch information
jasnell committed Dec 22, 2017
commit 76f26e70cbdbdfdc26194defd2af56753a181c32
22 changes: 11 additions & 11 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ uint64_t performance_last_gc_start_mark_ = 0;
v8::GCType performance_last_gc_type_ = v8::GCType::kGCTypeAll;

// Initialize the performance entry object properties
inline void InitObject(PerformanceEntry* entry, Local<Object> obj) {
Environment* env = entry->env();
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);
obj->DefineOwnProperty(context,
env->name_string(),
String::NewFromUtf8(isolate,
entry->name().c_str(),
entry.name().c_str(),
String::kNormalString),
attr).FromJust();
obj->DefineOwnProperty(context,
FIXED_ONE_BYTE_STRING(isolate, "entryType"),
String::NewFromUtf8(isolate,
entry->type().c_str(),
entry.type().c_str(),
String::kNormalString),
attr).FromJust();
obj->DefineOwnProperty(context,
FIXED_ONE_BYTE_STRING(isolate, "startTime"),
Number::New(isolate, entry->startTime()),
Number::New(isolate, entry.startTime()),
attr).FromJust();
obj->DefineOwnProperty(context,
FIXED_ONE_BYTE_STRING(isolate, "duration"),
Number::New(isolate, entry->duration()),
Number::New(isolate, entry.duration()),
attr).FromJust();
}

// Create a new PerformanceEntry object
Local<Object> PerformanceEntry::ToObject() {
const Local<Object> PerformanceEntry::ToObject() const {
Local<Object> obj =
env()->performance_entry_template()
->NewInstance(env()->context()).ToLocalChecked();
InitObject(this, obj);
env_->performance_entry_template()
->NewInstance(env_->context()).ToLocalChecked();
InitObject(*this, obj);
return obj;
}

Expand All @@ -76,7 +76,7 @@ void PerformanceEntry::New(const FunctionCallbackInfo<Value>& args) {
uint64_t now = PERFORMANCE_NOW();
PerformanceEntry entry(env, *name, *type, now, now);
Local<Object> obj = args.This();
InitObject(&entry, obj);
InitObject(entry, obj);
PerformanceEntry::Notify(env, entry.kind(), obj);
}

Expand Down
4 changes: 2 additions & 2 deletions src/node_perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class PerformanceEntry {

virtual ~PerformanceEntry() { }

virtual Local<Object> ToObject();
virtual const Local<Object> ToObject() const;

Environment* env() { return env_; }
Environment* env() const { return env_; }

const std::string& name() const { return name_; }

Expand Down