private JSObjectHandle(object target, IJSObjectMetadata metadata) { _metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); _target = new WeakReference <object>(target ?? throw new ArgumentNullException(nameof(target))); _managedGcHandle = GCHandle.Alloc(this, GCHandleType.Weak); _managedHandle = GCHandle.ToIntPtr(_managedGcHandle); _jsHandle = _metadata.CreateNativeInstance(_managedHandle); }
/// <summary> /// Creates a new <see cref="JSObjectHandle"/> for the provided object by specifying the <see cref="IJSObjectMetadata"/> of the target. /// </summary> /// <param name="target">The object to marshal to javascript</param> /// <param name="metadata">Metadat of the <paramref name="target"/>.</param> /// <returns></returns> public static JSObjectHandle Create(IJSObject target, IJSObjectMetadata metadata) => new JSObjectHandle(target, metadata);