JsSerialize() private method

private JsSerialize ( JsValue script, JsValue &buffer, JsParseScriptAttributes parseAttributes ) : JsErrorCode
script JsValue
buffer JsValue
parseAttributes JsParseScriptAttributes
return JsErrorCode
        /// <summary>
        /// Serializes a parsed script to a buffer than can be reused
        /// </summary>
        /// <remarks>
        /// <para>
        /// SerializeScript parses a script and then stores the parsed form of the script in a
        /// runtime-independent format. The serialized script then can be deserialized in any
        /// runtime without requiring the script to be re-parsed.
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <param name="script">The script to serialize</param>
        /// <param name="buffer">The buffer to put the serialized script into. Can be null</param>
        /// <returns>The size of the buffer, in bytes, required to hold the serialized script</returns>
        public static ulong SerializeScript(string script, byte[] buffer)
        {
            var         bufferSize = (ulong)buffer.Length;
            JsErrorCode errorCode;

            if (Utils.IsWindows())
            {
                errorCode = NativeMethods.JsSerializeScript(script, buffer, ref bufferSize);
                JsErrorHelpers.ThrowIfError(errorCode);
            }
            else
            {
                JsValue scriptValue = JsValue.FromString(script);
                scriptValue.AddRef();

                JsValue bufferValue;

                try
                {
                    errorCode = NativeMethods.JsSerialize(scriptValue, out bufferValue,
                                                          JsParseScriptAttributes.None);
                    JsErrorHelpers.ThrowIfError(errorCode);
                }
                finally
                {
                    scriptValue.Release();
                }

                JsValue lengthValue = bufferValue.GetProperty("length");
                bufferSize = Convert.ToUInt64(lengthValue.ConvertToNumber().ToDouble());
            }

            return(bufferSize);
        }
        /// <summary>
        /// Serializes a parsed script to a buffer than can be reused
        /// </summary>
        /// <remarks>
        /// <para>
        /// <c>SerializeScript</c> parses a script and then stores the parsed form of the script in a
        /// runtime-independent format. The serialized script then can be deserialized in any
        /// runtime without requiring the script to be re-parsed.
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <param name="script">The script to serialize</param>
        /// <param name="parseAttributes">Attribute mask for parsing the script</param>
        /// <returns>The buffer to put the serialized script into</returns>
        public static byte[] SerializeScript(string script, ref JsParseScriptAttributes parseAttributes)
        {
            JsValue scriptValue = JsValue.FromString(script);

            scriptValue.AddRef();

            JsValue bufferValue;

            try
            {
                JsErrorCode errorCode = NativeMethods.JsSerialize(scriptValue, out bufferValue, parseAttributes);
                JsErrorHelpers.ThrowIfError(errorCode);
            }
            finally
            {
                scriptValue.Release();
            }

            byte[] buffer = bufferValue.ArrayBufferBytes;

            return(buffer);
        }