JavaScriptEngineSwitcher.ChakraCore.JsRt.JsValue.AddRef C# (CSharp) Метод

AddRef() публичный Метод

Adds a reference to the object
This only needs to be called on objects that are not going to be stored somewhere on the stack. Calling AddRef ensures that the JavaScript object the value refers to will not be freed until Release is called
public AddRef ( ) : uint
Результат uint
		public uint AddRef()
		{
			uint count;
			JsErrorHelpers.ThrowIfError(NativeMethods.JsAddRef(this, out count));

			return count;
		}

Usage Example

Пример #1
0
        /// <summary>
        /// Runs a serialized script
        /// </summary>
        /// <remarks>
        /// <para>Requires an active script context.</para>
        /// <para>The runtime will detach the data from the buffer and hold on to it until all
        /// instances of any functions created from the buffer are garbage collected.</para>
        /// </remarks>
        /// <param name="script">The source code of the serialized script</param>
        /// <param name="buffer">The serialized script</param>
        /// <param name="scriptLoadCallback">Callback to load the source code of the serialized script</param>
        /// <param name="sourceContext">A cookie identifying the script that can be used
        /// by debuggable script contexts</param>
        /// <param name="sourceUrl">The location the script came from</param>
        /// <returns>The result of running the script, if any</returns>
        public static JsValue RunSerializedScript(string script, byte[] buffer,
                                                  JsSerializedLoadScriptCallback scriptLoadCallback, JsSourceContext sourceContext, string sourceUrl)
        {
            JsValue bufferValue = JsValue.CreateExternalArrayBuffer(buffer);

            bufferValue.AddRef();

            JsValue sourceUrlValue = JsValue.FromString(sourceUrl);

            sourceUrlValue.AddRef();

            JsValue result;

            try
            {
                JsErrorCode errorCode = NativeMethods.JsRunSerialized(bufferValue, scriptLoadCallback,
                                                                      sourceContext, sourceUrlValue, out result);
                JsErrorHelpers.ThrowIfError(errorCode);
            }
            finally
            {
                bufferValue.Release();
                sourceUrlValue.Release();
            }

            return(result);
        }
All Usage Examples Of JavaScriptEngineSwitcher.ChakraCore.JsRt.JsValue::AddRef