예제 #1
0
        /// <summary>
        /// Creates a new instance of a Barista Runtime.
        /// </summary>
        public BaristaRuntime(IJavaScriptEngine engine, IBaristaContextFactory contextFactory, JavaScriptRuntimeSafeHandle runtimeHandle)
            : base(engine, runtimeHandle)
        {
            m_contextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory));

            JavaScriptMemoryAllocationCallback runtimeMemoryAllocationChanging = (IntPtr callbackState, JavaScriptMemoryEventType allocationEvent, UIntPtr allocationSize) =>
            {
                try
                {
                    return(OnRuntimeMemoryAllocationChanging(callbackState, allocationEvent, allocationSize));
                }
                catch
                {
                    //Do Nothing.
                    return(true);
                }
            };

            m_runtimeMemoryAllocationChangingDelegateHandle = GCHandle.Alloc(runtimeMemoryAllocationChanging);
            Engine.JsSetRuntimeMemoryAllocationCallback(runtimeHandle, IntPtr.Zero, runtimeMemoryAllocationChanging);

            JavaScriptBeforeCollectCallback beforeCollectCallback = (IntPtr callbackState) =>
            {
                try
                {
                    OnBeforeCollect(IntPtr.Zero, callbackState);
                }
                catch
                {
                    //Do Nothing.
                }
            };

            m_beforeCollectCallbackDelegateHandle = GCHandle.Alloc(beforeCollectCallback);
            Engine.JsSetRuntimeBeforeCollectCallback(runtimeHandle, IntPtr.Zero, beforeCollectCallback);
        }
예제 #2
0
 internal static extern JavaScriptErrorCode JsSetRuntimeBeforeCollectCallback(JavaScriptRuntime runtime, IntPtr callbackState, JavaScriptBeforeCollectCallback beforeCollectCallback);
예제 #3
0
 internal static extern JavaScriptErrorCode JsSetRuntimeBeforeCollectCallback(JavaScriptRuntime runtime, IntPtr callbackState, JavaScriptBeforeCollectCallback beforeCollectCallback);
예제 #4
0
 /// <summary>
 ///     Sets a callback function that is called by the runtime before garbage collection.
 /// </summary>
 /// <remarks>
 ///     <para>
 ///     The callback is invoked on the current runtime execution thread, therefore execution is
 ///     blocked until the callback completes.
 ///     </para>
 ///     <para>
 ///     The callback can be used by hosts to prepare for garbage collection. For example, by
 ///     releasing unnecessary references on Chakra objects.
 ///     </para>
 /// </remarks>
 /// <param name="callbackState">
 ///     User provided state that will be passed back to the callback.
 /// </param>
 /// <param name="beforeCollectCallback">The callback function being set.</param>
 public void SetBeforeCollectCallback(IntPtr callbackState, JavaScriptBeforeCollectCallback beforeCollectCallback)
 {
     Native.ThrowIfError(Native.JsSetRuntimeBeforeCollectCallback(this, callbackState, beforeCollectCallback));
 }
예제 #5
0
 /// <summary>
 /// Sets a callback function that is called by the runtime before garbage collection.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The callback is invoked on the current runtime execution thread, therefore execution is 
 /// blocked until the callback completes.
 /// </para>
 /// <para>
 /// The callback can be used by hosts to prepare for garbage collection. For example, by 
 /// releasing unnecessary references on Chakra objects.
 /// </para>
 /// </remarks>
 /// <param name="callbackState">
 /// User provided state that will be passed back to the callback.
 /// </param>
 /// <param name="beforeCollectCallback">The callback function being set.</param>
 public void SetBeforeCollectCallback(IntPtr callbackState, JavaScriptBeforeCollectCallback beforeCollectCallback)
 {
     Native.ThrowIfError(Native.JsSetRuntimeBeforeCollectCallback(this, callbackState, beforeCollectCallback));
 }