Jurassic.Library.ObjectInstance.ToStringJS C# (CSharp) Method

ToStringJS() private method

private ToStringJS ( ScriptEngine engine, object thisObject ) : string
engine ScriptEngine
thisObject object
return string
        public static string ToStringJS(ScriptEngine engine, object thisObject)
        {
            if (thisObject == null || thisObject == Undefined.Value)
                return "[object Undefined]";
            if (thisObject == Null.Value)
                return "[object Null]";
            var obj = TypeConverter.ToObject(engine, thisObject);

            // ES6 - if the value of @@toStringTag is a string, use it to form the result.
            object tag = obj.GetPropertyValue(engine.Symbol.ToStringTag);
            if (tag is string)
                return $"[object {tag}]";

            // Fall back to previous behaviour.
            if (obj is ArrayInstance)
                return "[object Array]";
            if (obj is StringInstance)
                return "[object String]";
            if (obj is ArgumentsInstance)
                return "[object Arguments]";
            if (obj is FunctionInstance)
                return "[object Function]";
            if (obj is ErrorInstance)
                return "[object Error]";
            if (obj is BooleanInstance)
                return "[object Boolean]";
            if (obj is NumberInstance)
                return "[object Number]";
            if (obj is DateInstance)
                return "[object Date]";
            if (obj is RegExpInstance)
                return "[object RegExp]";
            return "[object Object]";
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Returns a string representing this object.
        /// </summary>
        /// <returns> A string representing this object. </returns>
        public override string ToString()
        {
            // Try calling WrappedInstance.join().
            object result;

            if (WrappedInstance.TryCallMemberFunction(out result, "join") == true)
            {
                return(TypeConverter.ToString(result));
            }

            // Otherwise, use the default Object.prototype.toString() method.
            return(ObjectInstance.ToStringJS(Engine, WrappedInstance));
        }