예제 #1
0
        public void ToString(RuntimeFunction toString)
        {
            IsUnconstructableFunctionWLength(toString, "toString", 0);

            EcmaValue obj = new EcmaObject();

            DefineProperty(obj, Symbol.ToStringTag, get: ThrowTest262Exception);
            Case(obj, Throws.Test262);

            EcmaValue args = default;

            FunctionLiteral(() => args = Arguments).Call();
            Case(args, "[object Arguments]");

            Case(new EcmaArray(), "[object Array]");

            Case(true, "[object Boolean]");
            Case(Boolean.Call(_, true), "[object Boolean]");
            Case(Boolean.Construct(true), "[object Boolean]");
            Case(Object.Call(_, true), "[object Boolean]");
            Case(Object.Call(_, Boolean.Call(true)), "[object Boolean]");
            Case(Object.Call(_, Boolean.Construct(true)), "[object Boolean]");

            Case(new EcmaDate(), "[object Date]");
            Case(Object.Call(_, new EcmaDate()), "[object Date]");

            Case(FunctionLiteral(() => Undefined), "[object Function]");

            Case(Null, "[object Null]");

            Case(42, "[object Number]");
            Case(Number.Call(_, 42), "[object Number]");
            Case(Number.Construct(42), "[object Number]");
            Case(Object.Call(_, 42), "[object Number]");
            Case(Object.Call(_, Number.Call(42)), "[object Number]");
            Case(Object.Call(_, Number.Construct(42)), "[object Number]");

            Case(Object.Prototype, "[object Object]");
            Case(new EcmaObject(), "[object Object]");

            Case(RegExp.Construct("."), "[object RegExp]");

            Case("", "[object String]");
            Case(String.Call(_, ""), "[object String]");
            Case(String.Construct(""), "[object String]");
            Case(Object.Call(_, ""), "[object String]");
            Case(Object.Call(_, String.Call("")), "[object String]");
            Case(Object.Call(_, String.Construct("")), "[object String]");

            Case(Undefined, "[object Undefined]");

            Case(Proxy.Construct(Array.Construct(), Object.Construct()), "[object Array]");

            // Non-string values of `@@toStringTag` property are ignored
            Case(CreateObject((Symbol.ToStringTag, Undefined)), "[object Object]");
            Case(CreateObject((Symbol.ToStringTag, Null)), "[object Object]");
            Case(CreateObject((Symbol.ToStringTag, Symbol.ToStringTag)), "[object Object]");
            Case(CreateObject((Symbol.ToStringTag, 42)), "[object Object]");
            Case(CreateObject((Symbol.ToStringTag, String.Construct(""))), "[object Object]");
            Case(CreateObject((Symbol.ToStringTag, new EcmaObject())), "[object Object]");
            Case(CreateObject((Symbol.ToStringTag, FunctionLiteral(() => ""))), "[object Object]");
        }