2013-04-25 08:30:31 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/api/object_life_monitor.h"
|
2013-08-27 09:47:44 +00:00
|
|
|
#include "v8/include/v8-profiler.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/v8/node_common.h"
|
2013-04-25 08:30:31 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
void CreateObjectWithName(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
|
2013-04-25 08:30:31 +00:00
|
|
|
t->SetClassName(args[0]->ToString());
|
2013-12-11 07:48:19 +00:00
|
|
|
args.GetReturnValue().Set(t->GetFunction()->NewInstance());
|
2013-04-25 08:30:31 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
void GetHiddenValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
args.GetReturnValue().Set(
|
|
|
|
args[0]->ToObject()->GetHiddenValue(args[1]->ToString()));
|
2013-04-25 08:30:31 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
void SetHiddenValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2013-04-25 08:30:31 +00:00
|
|
|
args[0]->ToObject()->SetHiddenValue(args[1]->ToString(), args[2]);
|
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
void GetObjectHash(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
args.GetReturnValue().Set(args[0]->ToObject()->GetIdentityHash());
|
2013-04-25 08:30:31 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
void SetDestructor(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2013-04-25 10:25:18 +00:00
|
|
|
ObjectLifeMonitor::BindTo(args[0]->ToObject(), args[1]);
|
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
void TakeHeapSnapshot(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2013-08-27 09:47:44 +00:00
|
|
|
node::node_isolate->GetHeapProfiler()->TakeHeapSnapshot(
|
|
|
|
v8::String::New("test"));
|
|
|
|
}
|
|
|
|
|
2013-04-25 08:30:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void InitializeV8Util(v8::Handle<v8::Object> target) {
|
|
|
|
NODE_SET_METHOD(target, "createObjectWithName", CreateObjectWithName);
|
|
|
|
NODE_SET_METHOD(target, "getHiddenValue", GetHiddenValue);
|
|
|
|
NODE_SET_METHOD(target, "setHiddenValue", SetHiddenValue);
|
|
|
|
NODE_SET_METHOD(target, "getObjectHash", GetObjectHash);
|
2013-04-25 10:25:18 +00:00
|
|
|
NODE_SET_METHOD(target, "setDestructor", SetDestructor);
|
2013-08-27 09:47:44 +00:00
|
|
|
NODE_SET_METHOD(target, "takeHeapSnapshot", TakeHeapSnapshot);
|
2013-04-25 08:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
NODE_MODULE(atom_common_v8_util, atom::api::InitializeV8Util)
|