// Copyright (c) 2013 GitHub, Inc. All rights reserved. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. #include "atom/common/api/object_life_monitor.h" #include "native_mate/dictionary.h" #include "v8/include/v8-profiler.h" #include "atom/common/node_includes.h" namespace { v8::Handle CreateObjectWithName(v8::Isolate* isolate, v8::Handle name) { v8::Local t = v8::FunctionTemplate::New(isolate); t->SetClassName(name); return t->GetFunction()->NewInstance(); } v8::Handle GetHiddenValue(v8::Handle object, v8::Handle key) { return object->GetHiddenValue(key); } void SetHiddenValue(v8::Handle object, v8::Handle key, v8::Handle value) { object->SetHiddenValue(key, value); } int32_t GetObjectHash(v8::Handle object) { return object->GetIdentityHash(); } void SetDestructor(v8::Isolate* isolate, v8::Handle object, v8::Handle callback) { atom::ObjectLifeMonitor::BindTo(isolate, object, callback); } void TakeHeapSnapshot(v8::Isolate* isolate) { isolate->GetHeapProfiler()->TakeHeapSnapshot( mate::StringToV8(isolate, "test")); } void Initialize(v8::Handle exports) { mate::Dictionary dict(v8::Isolate::GetCurrent(), exports); dict.SetMethod("createObjectWithName", &CreateObjectWithName); dict.SetMethod("getHiddenValue", &GetHiddenValue); dict.SetMethod("setHiddenValue", &SetHiddenValue); dict.SetMethod("getObjectHash", &GetObjectHash); dict.SetMethod("setDestructor", &SetDestructor); dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot); } } // namespace NODE_MODULE_X(atom_common_v8_util, Initialize, NULL, NM_F_BUILTIN)