| 
									
										
										
										
											2013-04-25 16:30:31 +08: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 08:30:26 +08:00
										 |  |  | #include "atom/common/api/object_life_monitor.h"
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | #include "native_mate/dictionary.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-27 17:47:44 +08:00
										 |  |  | #include "v8/include/v8-profiler.h"
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 13:45:14 +08:00
										 |  |  | #include "atom/common/node_includes.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-25 16:30:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | v8::Handle<v8::Object> CreateObjectWithName(v8::Handle<v8::String> name) { | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  |   v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  |   t->SetClassName(name); | 
					
						
							|  |  |  |   return t->GetFunction()->NewInstance(); | 
					
						
							| 
									
										
										
										
											2013-04-25 16:30:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | v8::Handle<v8::Value> GetHiddenValue(v8::Handle<v8::Object> object, | 
					
						
							|  |  |  |                                      v8::Handle<v8::String> key) { | 
					
						
							|  |  |  |   return object->GetHiddenValue(key); | 
					
						
							| 
									
										
										
										
											2013-04-25 16:30:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | void SetHiddenValue(v8::Handle<v8::Object> object, | 
					
						
							|  |  |  |                     v8::Handle<v8::String> key, | 
					
						
							|  |  |  |                     v8::Handle<v8::Value> value) { | 
					
						
							|  |  |  |   object->SetHiddenValue(key, value); | 
					
						
							| 
									
										
										
										
											2013-04-25 16:30:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | int32_t GetObjectHash(v8::Handle<v8::Object> object) { | 
					
						
							|  |  |  |   return object->GetIdentityHash(); | 
					
						
							| 
									
										
										
										
											2013-04-25 16:30:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | void SetDestructor(v8::Handle<v8::Object> object, | 
					
						
							|  |  |  |                    v8::Handle<v8::Function> callback) { | 
					
						
							|  |  |  |   atom::ObjectLifeMonitor::BindTo(object, callback); | 
					
						
							| 
									
										
										
										
											2013-04-25 18:25:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | void TakeHeapSnapshot() { | 
					
						
							| 
									
										
										
										
											2013-08-27 17:47:44 +08:00
										 |  |  |   node::node_isolate->GetHeapProfiler()->TakeHeapSnapshot( | 
					
						
							|  |  |  |       v8::String::New("test")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | void Initialize(v8::Handle<v8::Object> 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); | 
					
						
							| 
									
										
										
										
											2013-04-25 16:30:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | }  // namespace
 | 
					
						
							| 
									
										
										
										
											2013-04-25 16:30:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:31:59 +08:00
										 |  |  | NODE_MODULE(atom_common_v8_util, Initialize) |