private CreateObject ( |
||
engine | ||
managedObjectID | ||
return | HandleProxy* |
/// <summary> /// Creates a new CLR object which will be tracked by a new V8 native object. /// </summary> /// <param name="initialize">If true (default) then then 'IV8NativeObject.Initialize()' is called on the created wrapper before returning.</param> /// <typeparam name="T">A custom 'V8NativeObject' type, or just use 'V8NativeObject' as a default.</typeparam> public T CreateObject <T>(bool initialize = true) where T : V8NativeObject, new() { // ... create the new managed JavaScript object and store it (to get the "ID")... var obj = _CreateManagedObject <T>(null, null); try { // ... create a new native object and associated it with the new managed object ID ... obj._Handle._Set(V8NetProxy.CreateObject(_NativeV8EngineProxy, obj.ID)); /* The V8 object will have an associated internal field set to the index of the created managed object above for quick lookup. This index is used * to locate the associated managed object when a call-back occurs. The lookup is a fast O(1) operation using the custom 'IndexedObjectList' manager. */ } catch (Exception ex) { // ... something went wrong, so remove the new managed object ... _RemoveObjectWeakReference(obj.ID); throw ex; } if (initialize) { obj.Initialize(false, null); } return((T)obj); }
/// <summary> /// Creates a new native V8 object only. /// </summary> /// <param name="objectID">You can associate arbitrary NEGATIVE numbers with objects to use for tracking purposes. The numbers have to be less than or /// equal to -2. Values greater or equal to 0 are used for internal tracking of V8NativeObject instances. -1 is a default value that is set automatically /// when new objects are created (which simply means "no ID is set").</param> public InternalHandle CreateObject(Int32 objectID = -2) { if (objectID > -2) { throw new InvalidOperationException("Object IDs must be <= -2."); } return(V8NetProxy.CreateObject(_NativeV8EngineProxy, objectID)); }