FromString() public static method

Creates a String value from a string pointer
Requires an active script context.
public static FromString ( string value ) : JsValue
value string The string to convert to a String value
return JsValue
        /// <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);
        }
        private static JsValue CreateErrorFromWrapperException(WrapperException exception)
        {
            var         originalException = exception.InnerException as JsException;
            JsErrorCode errorCode         = originalException != null ?
                                            originalException.ErrorCode : JsErrorCode.NoError;
            string description = exception.Description;

            JsValue innerErrorValue = JsErrorHelpers.CreateError(description);

            innerErrorValue.SetProperty("description", JsValue.FromString(description), true);

            JsValue metadataValue = JsValue.CreateObject();

            var scriptException = exception as WrapperScriptException;

            if (scriptException != null)
            {
                string type         = scriptException.Type;
                string documentName = scriptException.DocumentName;
                int    lineNumber   = scriptException.LineNumber;
                if (lineNumber > 0)
                {
                    lineNumber--;
                }
                int columnNumber = scriptException.ColumnNumber;
                if (columnNumber > 0)
                {
                    columnNumber--;
                }
                string sourceFragment = scriptException.SourceFragment;

                innerErrorValue.SetProperty("name", JsValue.FromString(type), true);

                var runtimeException = scriptException as WrapperRuntimeException;
                if (runtimeException != null)
                {
                    var    errorNumber = (int)errorCode;
                    string callStack   = runtimeException.CallStack;
                    string messageWithTypeAndCallStack = CoreErrorHelpers.GenerateScriptErrorMessage(type,
                                                                                                     description, callStack);

                    innerErrorValue.SetProperty("number", JsValue.FromInt32(errorNumber), true);
                    if (!string.IsNullOrWhiteSpace(callStack))
                    {
                        innerErrorValue.SetProperty("stack", JsValue.FromString(messageWithTypeAndCallStack), true);
                    }
                }
                else
                {
                    innerErrorValue.SetProperty("url", JsValue.FromString(documentName), true);
                    innerErrorValue.SetProperty("line", JsValue.FromInt32(lineNumber), true);
                    innerErrorValue.SetProperty("column", JsValue.FromInt32(columnNumber), true);
                    innerErrorValue.SetProperty("source", JsValue.FromString(sourceFragment), true);
                }

                metadataValue.SetProperty("url", JsValue.FromString(documentName), true);
                metadataValue.SetProperty("line", JsValue.FromInt32(lineNumber), true);
                metadataValue.SetProperty("column", JsValue.FromInt32(columnNumber), true);
                metadataValue.SetProperty("source", JsValue.FromString(sourceFragment), true);
            }

            innerErrorValue.SetProperty("metadata", metadataValue, true);

            JsValue errorValue = JsErrorHelpers.CreateError(description);

            errorValue.SetProperty("innerException", innerErrorValue, true);

            return(errorValue);
        }