JsRun() private method

private JsRun ( JsValue script, JsSourceContext sourceContext, JsValue sourceUrl, JsParseScriptAttributes parseAttributes, JsValue &result ) : JsErrorCode
script JsValue
sourceContext JsSourceContext
sourceUrl JsValue
parseAttributes JsParseScriptAttributes
result JsValue
return JsErrorCode
        public static unsafe JsValue RunScriptUtf16Buffer(
            ReadOnlySpan <char> scriptBuffer,
            JsSourceContext sourceContext,
            ReadOnlySpan <char> sourceUrl)
        {
            //not work, because fixed.. https://github.com/dotnet/corefx/issues/31651 PInvoke marshaling will pin the pointer for ref byte hash arguments that will pin the whole block as side-effect

            fixed(char *scriptBufferPtr = &MemoryMarshal.GetReference(scriptBuffer))
            fixed(char *sourceUrlPtr = &MemoryMarshal.GetReference(sourceUrl))
            {
                JsErrorHelpers.ThrowIfError(NativeMethods.JsCreateStringUtf16((IntPtr)scriptBufferPtr, (uint)scriptBuffer.Length, out var scriptValue));
                scriptValue.AddRef();

                JsErrorHelpers.ThrowIfError(NativeMethods.JsCreateStringUtf16((IntPtr)sourceUrlPtr, (uint)sourceUrl.Length, out var sourceUrlValue));
                sourceUrlValue.AddRef();

                JsValue result;

                try
                {
                    JsErrorHelpers.ThrowIfError(NativeMethods.JsRun(scriptValue, sourceContext, sourceUrlValue, JsParseScriptAttributes.None, out result));
                }
                finally
                {
                    scriptValue.Release();
                    sourceUrlValue.Release();
                }

                return(result);
            }
        }
        /// <summary>
        /// Executes a script
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="script">The script to run</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>
        /// <param name="parseAttributes">Attribute mask for parsing the script</param>
        /// <returns>The result of the script, if any</returns>
        public static JsValue RunScript(string script, JsSourceContext sourceContext, string sourceUrl,
                                        ref JsParseScriptAttributes parseAttributes)
        {
            JsValue scriptValue = JsValue.FromString(script);

            scriptValue.AddRef();

            JsValue sourceUrlValue = JsValue.FromString(sourceUrl);

            sourceUrlValue.AddRef();

            JsValue result;

            try
            {
                JsErrorCode errorCode = NativeMethods.JsRun(scriptValue, sourceContext, sourceUrlValue,
                                                            parseAttributes, out result);
                JsErrorHelpers.ThrowIfError(errorCode);
            }
            finally
            {
                scriptValue.Release();
                sourceUrlValue.Release();
            }

            return(result);
        }
        /// <summary>
        /// Executes a script
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="script">The script to run</param>
        /// <param name="sourceContext">The cookie identifying the script that can be used
        /// by script contexts that have debugging enabled</param>
        /// <param name="sourceName">The location the script came from</param>
        /// <returns>The result of the script, if any</returns>
        public static JsValue RunScript(string script, JsSourceContext sourceContext, string sourceName)
        {
            JsValue     result;
            JsErrorCode errorCode;

            if (Utils.IsWindows())
            {
                errorCode = NativeMethods.JsRunScript(script, sourceContext, sourceName, out result);
                JsErrorHelpers.ThrowIfError(errorCode);
            }
            else
            {
                JsValue scriptValue = JsValue.FromString(script);
                scriptValue.AddRef();

                JsValue sourceUrlValue = JsValue.FromString(sourceName);
                sourceUrlValue.AddRef();

                try
                {
                    errorCode = NativeMethods.JsRun(scriptValue, sourceContext, sourceUrlValue,
                                                    JsParseScriptAttributes.None, out result);
                    JsErrorHelpers.ThrowIfError(errorCode);
                }
                finally
                {
                    scriptValue.Release();
                    sourceUrlValue.Release();
                }
            }

            return(result);
        }