Dereference remote objects with native code
Previously we rely on the v8util.setDestructor to dereference the remote objects in JavaScript, however as documented in V8, it is forbidden to call V8 APIs in object's destructor (e.g. the weak callback), and doing so would result in crashs. This commit removes the JavaScript setDestructor method, and avoids doing the dereference work with V8.
This commit is contained in:
		
					parent
					
						
							
								570dc7ca9b
							
						
					
				
			
			
				commit
				
					
						06cf0406fe
					
				
			
		
					 12 changed files with 272 additions and 61 deletions
				
			
		| 
						 | 
				
			
			@ -4,7 +4,9 @@
 | 
			
		|||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
#include "atom/common/api/object_life_monitor.h"
 | 
			
		||||
#include "atom/common/api/remote_callback_freer.h"
 | 
			
		||||
#include "atom/common/api/remote_object_freer.h"
 | 
			
		||||
#include "atom/common/native_mate_converters/content_converter.h"
 | 
			
		||||
#include "atom/common/node_includes.h"
 | 
			
		||||
#include "native_mate/dictionary.h"
 | 
			
		||||
#include "v8/include/v8-profiler.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -51,12 +53,6 @@ int32_t GetObjectHash(v8::Local<v8::Object> object) {
 | 
			
		|||
  return object->GetIdentityHash();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SetDestructor(v8::Isolate* isolate,
 | 
			
		||||
                   v8::Local<v8::Object> object,
 | 
			
		||||
                   v8::Local<v8::Function> callback) {
 | 
			
		||||
  atom::ObjectLifeMonitor::BindTo(isolate, object, callback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TakeHeapSnapshot(v8::Isolate* isolate) {
 | 
			
		||||
  isolate->GetHeapProfiler()->TakeHeapSnapshot();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -68,8 +64,9 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
 | 
			
		|||
  dict.SetMethod("setHiddenValue", &SetHiddenValue);
 | 
			
		||||
  dict.SetMethod("deleteHiddenValue", &DeleteHiddenValue);
 | 
			
		||||
  dict.SetMethod("getObjectHash", &GetObjectHash);
 | 
			
		||||
  dict.SetMethod("setDestructor", &SetDestructor);
 | 
			
		||||
  dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot);
 | 
			
		||||
  dict.SetMethod("setRemoteCallbackFreer", &atom::RemoteCallbackFreer::BindTo);
 | 
			
		||||
  dict.SetMethod("setRemoteObjectFreer", &atom::RemoteObjectFreer::BindTo);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue