electron/atom/common/api/atom_api_v8_util.cc

59 lines
1.9 KiB
C++
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT 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"
2014-04-16 07:31:59 +00:00
#include "native_mate/dictionary.h"
#include "v8/include/v8-profiler.h"
#include "atom/common/node_includes.h"
namespace {
2015-05-22 11:11:22 +00:00
v8::Local<v8::Object> CreateObjectWithName(v8::Isolate* isolate,
v8::Local<v8::String> name) {
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
2014-04-16 07:31:59 +00:00
t->SetClassName(name);
return t->GetFunction()->NewInstance();
}
2015-05-22 11:11:22 +00:00
v8::Local<v8::Value> GetHiddenValue(v8::Local<v8::Object> object,
v8::Local<v8::String> key) {
2014-04-16 07:31:59 +00:00
return object->GetHiddenValue(key);
}
2015-05-22 11:11:22 +00:00
void SetHiddenValue(v8::Local<v8::Object> object,
v8::Local<v8::String> key,
v8::Local<v8::Value> value) {
2014-04-16 07:31:59 +00:00
object->SetHiddenValue(key, value);
}
2015-05-22 11:11:22 +00:00
int32_t GetObjectHash(v8::Local<v8::Object> object) {
2014-04-16 07:31:59 +00:00
return object->GetIdentityHash();
}
void SetDestructor(v8::Isolate* isolate,
2015-05-22 11:11:22 +00:00
v8::Local<v8::Object> object,
v8::Local<v8::Function> callback) {
atom::ObjectLifeMonitor::BindTo(isolate, object, callback);
}
void TakeHeapSnapshot(v8::Isolate* isolate) {
2015-05-22 07:24:34 +00:00
isolate->GetHeapProfiler()->TakeHeapSnapshot();
}
2015-05-22 11:11:22 +00:00
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
2014-04-16 07:31:59 +00:00
dict.SetMethod("createObjectWithName", &CreateObjectWithName);
dict.SetMethod("getHiddenValue", &GetHiddenValue);
dict.SetMethod("setHiddenValue", &SetHiddenValue);
dict.SetMethod("getObjectHash", &GetObjectHash);
dict.SetMethod("setDestructor", &SetDestructor);
dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot);
}
2014-04-16 07:31:59 +00:00
} // namespace
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_v8_util, Initialize)