Esempio n. 1
0
        public void Tanh(RuntimeFunction tanh)
        {
            IsUnconstructableFunctionWLength(tanh, "tanh", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), -1);
            Case((_, Infinity), 1);
            Case((_, -0d), -0d);
            Case((_, 0), 0);
        }
Esempio n. 2
0
        public void Sinh(RuntimeFunction sinh)
        {
            IsUnconstructableFunctionWLength(sinh, "sinh", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), -Infinity);
            Case((_, Infinity), Infinity);
            Case((_, -0d), -0d);
            Case((_, 0), 0);
        }
Esempio n. 3
0
        public void Expm1(RuntimeFunction expm1)
        {
            IsUnconstructableFunctionWLength(expm1, "expm1", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), -1);
            Case((_, Infinity), Infinity);
            Case((_, -0d), -0d);
            Case((_, 0), 0);
        }
Esempio n. 4
0
        public void Cosh(RuntimeFunction cosh)
        {
            IsUnconstructableFunctionWLength(cosh, "cosh", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), Infinity);
            Case((_, Infinity), Infinity);
            Case((_, -0d), 1);
            Case((_, 0), 1);
        }
Esempio n. 5
0
        public void Cbrt(RuntimeFunction cbrt)
        {
            IsUnconstructableFunctionWLength(cbrt, "cbrt", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), -Infinity);
            Case((_, Infinity), Infinity);
            Case((_, -0d), -0d);
            Case((_, 0), 0);
        }
Esempio n. 6
0
        public void Random(RuntimeFunction random)
        {
            IsUnconstructableFunctionWLength(random, "random", 0);

            for (int i = 0; i < 100; i++)
            {
                EcmaValue value = random.Call();
                That(value, Is.TypeOf("number"));
                That(value, Is.GreaterThanOrEqualTo(0).And.LessThan(1));
            }
        }
Esempio n. 7
0
        private RuntimeFunction EnsureHomedMethod(EcmaValue value, RuntimeObject target, int requiredLength, string notFunctionError, string incorrectLengthError)
        {
            Guard.ArgumentIsCallable(value, notFunctionError);
            RuntimeFunction fn = value.GetUnderlyingObject <RuntimeFunction>();

            if (fn[WellKnownProperty.Length] != requiredLength)
            {
                throw new EcmaSyntaxErrorException(incorrectLengthError);
            }
            return(fn.AsHomedMethodOf(target));
        }
Esempio n. 8
0
        public void Apply(RuntimeFunction apply)
        {
            IsUnconstructableFunctionWLength(apply, "apply", 3);
            That(Reflect, Has.OwnProperty("apply", apply, EcmaPropertyAttributes.DefaultMethodProperty));

            It("should return abrupt if argumentsList is not an ArrayLike object", () => {
                EcmaValue fn = Function.Construct();
                EcmaValue o  = CreateObject(("length", get: ThrowTest262Exception, set: null));
                Case((_, fn, 1, o), Throws.Test262);
                Case((_, fn, 1, 1), Throws.TypeError);
            });
Esempio n. 9
0
        public void Clear(RuntimeFunction clear)
        {
            IsUnconstructableFunctionWLength(clear, "clear", 0);

            It("should throw a TypeError when this is not an object", () => {
                Case(Undefined, Throws.TypeError);
                Case(Null, Throws.TypeError);
                Case(false, Throws.TypeError);
                Case(0, Throws.TypeError);
                Case("", Throws.TypeError);
                Case(new Symbol(), Throws.TypeError);
            });

            It("should throw a TypeError when this object has no [[MapData]] internal slot", () => {
                Case(EcmaArray.Of(), Throws.TypeError);
                Case(Map.Prototype, Throws.TypeError);
                Case(Object.Construct(), Throws.TypeError);
                Case(Global.Set.Construct(), Throws.TypeError);
                Case(WeakSet.Construct(), Throws.TypeError);
            });

            It("should clear a Map object", () => {
                EcmaValue map = Map.Construct(EcmaArray.Of(
                                                  EcmaArray.Of("foo", "bar"),
                                                  EcmaArray.Of(1, 1)
                                                  ));
                clear.Call(map);
                That(map["size"], Is.EqualTo(0));

                map = Map.Construct();
                map.Invoke("set", "foo", "bar");
                map.Invoke("set", 1, 1);
                clear.Call(map);
                That(map["size"], Is.EqualTo(0));
            });

            It("should return undefined", () => {
                EcmaValue map = Map.Construct();
                Case(map, Undefined);
                Case(map, Undefined);
            });

            It("should not break iterator", () => {
                EcmaValue map = Map.Construct(EcmaArray.Of(
                                                  EcmaArray.Of("a", 1),
                                                  EcmaArray.Of("b", 2),
                                                  EcmaArray.Of("c", 3)
                                                  ));
                EcmaValue iterator = map.Invoke("entries");
                iterator.Invoke("next");
                clear.Call(map);
                VerifyIteratorResult(iterator.Invoke("next"), true);
            });
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            Function.newContext();
            Function.printCompilerSource = true;
            //Function.turnOnAllSimplification();

            Program prog = new Program();

            //int T = 10;
            //Function[][] X = new Function[T][];
            //Function[][] U = new Function[T-1][];

            //Function[] x = new Function[] {-4, 2};
            //Function[] u = new Function[] {0.214285714285714, -0.285714285714286};
            //Function[,] Sigma = new Function[,] { { 1, 0 }, { 0, 1 } };

            Variable[] vars = new Variable[8];
            for (int i = 0; i < 8; ++i)
            {
                vars[i] = new Variable("vars_" + i);
            }
            Function[] x = new Function[] { vars[0], vars[1] };
            Function[] u = new Function[] { vars[2], vars[3] };
            Function[,] Sigma = VM.identity <Function>(2, 0, 1);

            Function[] q_t = new Function[] { vars[4], vars[5] };
            Function[] r_t = new Function[] { vars[6], vars[7] };

            Function[] x_tp1;
            Function[,] Sigma_tp1;

            prog.EKF(x, Sigma, u, q_t, r_t, out x_tp1, out Sigma_tp1);

            Function[] packed    = VM.concatenate <Function>(x_tp1, VM.matrixToVector <Function>(Sigma_tp1));
            Function   beliefvec = Function.derivative(packed);

            beliefvec.printOperatorCounts();

            bool[] invDynInputVarIndices;
            vars = initializeInputVariables(beliefvec, vars, out invDynInputVarIndices);
            beliefvec.orderVariablesInDomain(vars);

            RuntimeFunction brun = beliefvec.compile();

            double[] result = new double[6], varvals = { -4, 2, 0.214285714285714, -0.285714285714286, 0, 0 };
            brun.eval(result, varvals);
            for (int i = 0; i < 6; ++i)
            {
                Console.Write("b[" + i + "]: " + result[i] + " ");
            }
            Console.WriteLine();

            Console.Read();
        }
Esempio n. 11
0
        public void Sqrt(RuntimeFunction sqrt)
        {
            IsUnconstructableFunctionWLength(sqrt, "sqrt", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), NaN);
            Case((_, Infinity), Infinity);
            Case((_, -0.000000000000001), NaN);
            Case((_, -1), NaN);
            Case((_, -0d), -0d);
            Case((_, 0), 0);
        }
Esempio n. 12
0
        public void Species(RuntimeFunction species)
        {
            That(SharedArrayBuffer, Has.OwnProperty(WellKnownSymbol.Species, EcmaPropertyAttributes.Configurable));
            That(SharedArrayBuffer.GetOwnProperty(WellKnownSymbol.Species).Set, Is.Undefined);

            IsUnconstructableFunctionWLength(species, "get [Symbol.species]", 0);
            Case(SharedArrayBuffer, Is.EqualTo(SharedArrayBuffer));

            EcmaValue thisValue = new EcmaObject();

            Case(thisValue, Is.EqualTo(thisValue));
        }
Esempio n. 13
0
        public void Iterator(RuntimeFunction iterator)
        {
            IsUnconstructableFunctionWLength(iterator, "[Symbol.iterator]", 0);

            EcmaValue iterProto = Object.Invoke("getPrototypeOf", Object.Invoke("getPrototypeOf", Array.Construct().Invoke(Symbol.Iterator)));

            That(iterProto, Has.OwnProperty(Symbol.Iterator, iterator, EcmaPropertyAttributes.DefaultMethodProperty));

            EcmaValue thisValue = Object.Construct();

            Case(thisValue, thisValue);
        }
Esempio n. 14
0
 public EcmaValue this[EcmaPropertyKey key] {
     set {
         if (key == WellKnownProperty.Constructor)
         {
             constructor = value.GetUnderlyingObject <RuntimeFunction>();
         }
         else
         {
             EnsureBuilder(ref properties).Add(key, value);
         }
     }
 }
Esempio n. 15
0
        public void Delete(RuntimeFunction delete)
        {
            IsUnconstructableFunctionWLength(delete, "delete", 1);

            It("should throw a TypeError when this is not an object", () => {
                Case((Undefined, 1), Throws.TypeError);
                Case((Null, 1), Throws.TypeError);
                Case((false, 1), Throws.TypeError);
                Case((0, 1), Throws.TypeError);
                Case(("", 1), Throws.TypeError);
                Case((new Symbol(), 1), Throws.TypeError);
            });
Esempio n. 16
0
        public void Acosh(RuntimeFunction acosh)
        {
            IsUnconstructableFunctionWLength(acosh, "acosh", 1);

            Case((_, Infinity), Infinity);
            Case((_, +1), 0, "Math.acosh should produce 0 for +1");
            Case((_, NaN), NaN, "NaN");
            Case((_, 0.999999), NaN, "0.999999");
            Case((_, 0), NaN, "0");
            Case((_, -1), NaN, "-1");
            Case((_, -Infinity), NaN, "-Infinity");
        }
Esempio n. 17
0
        public void Add(RuntimeFunction add)
        {
            IsUnconstructableFunctionWLength(add, "add", 1);

            It("should throw a TypeError when this is not an object", () => {
                Case((Undefined, Object.Construct()), Throws.TypeError);
                Case((Null, Object.Construct()), Throws.TypeError);
                Case((false, Object.Construct()), Throws.TypeError);
                Case((0, Object.Construct()), Throws.TypeError);
                Case(("", Object.Construct()), Throws.TypeError);
                Case((new Symbol(), Object.Construct()), Throws.TypeError);
            });
Esempio n. 18
0
        public void Trunc(RuntimeFunction trunc)
        {
            IsUnconstructableFunctionWLength(trunc, "trunc", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), -Infinity);
            Case((_, Infinity), Infinity);
            Case((_, -0.9), -0d);
            Case((_, 0.9), 0);
            Case((_, 4578.584949), 4578);
            Case((_, 0), 0);

            Case((_, 0.02047410048544407), 0,
                 "Math.trunc should produce +0 for values between 0 and 1");
            Case((_, 0.00000000000000001), 0,
                 "Math.trunc should produce +0 for values between 0 and 1");
            Case((_, 0.9999999999999999), 0,
                 "Math.trunc should produce +0 for values between 0 and 1");
            Case((_, Number.Get("EPSILON")), 0,
                 "Math.trunc should produce +0 for values between 0 and 1");
            Case((_, Number.Get("MIN_VALUE")), 0,
                 "Math.trunc should produce +0 for values between 0 and 1");

            Case((_, -0.02047410048544407), -0d,
                 "Math.trunc should produce -0 for values between -1 and 0");
            Case((_, -0.00000000000000001), -0d,
                 "Math.trunc should produce -0 for values between -1 and 0");
            Case((_, -0.9999999999999999), -0d,
                 "Math.trunc should produce -0 for values between -1 and 0");
            Case((_, -Number.Get("EPSILON")), -0d,
                 "Math.trunc should produce -0 for values between -1 and 0");
            Case((_, -Number.Get("MIN_VALUE")), -0d,
                 "Math.trunc should produce -0 for values between -1 and 0");

            Case((_, Number.Get("MAX_VALUE")), Math.Invoke("floor", Number.Get("MAX_VALUE")),
                 "Math.trunc produces incorrect result for Number.MAX_VALUE");
            Case((_, 10), Math.Invoke("floor", 10),
                 "Math.trunc produces incorrect result for 10");
            Case((_, 3.9), Math.Invoke("floor", 3.9),
                 "Math.trunc produces incorrect result for 3.9");
            Case((_, 4.9), Math.Invoke("floor", 4.9),
                 "Math.trunc produces incorrect result for 4.9");

            Case((_, -Number.Get("MAX_VALUE")), Math.Invoke("ceil", -Number.Get("MAX_VALUE")),
                 "Math.trunc produces incorrect result for -Number.MAX_VALUE");
            Case((_, -10), Math.Invoke("ceil", -10),
                 "Math.trunc produces incorrect result for -10");
            Case((_, -3.9), Math.Invoke("ceil", -3.9),
                 "Math.trunc produces incorrect result for -3.9");
            Case((_, -4.9), Math.Invoke("ceil", -4.9),
                 "Math.trunc produces incorrect result for -4.9");
        }
Esempio n. 19
0
        public void Acos(RuntimeFunction acos)
        {
            IsUnconstructableFunctionWLength(acos, "acos", 1);

            Case((_, NaN), NaN);
            Case((_, 1.000000000000001), NaN, "1.000000000000001");
            Case((_, 2), NaN, "2");
            Case((_, Infinity), NaN, "Infinity");
            Case((_, -1.000000000000001), NaN, "-1.000000000000001");
            Case((_, -2), NaN, "-2");
            Case((_, -Infinity), NaN, "-Infinity");
            Case((_, 1), 0);
        }
Esempio n. 20
0
        public void AsyncIterator(RuntimeFunction asyncIterator)
        {
            IsUnconstructableFunctionWLength(asyncIterator, "[Symbol.asyncIterator]", 0);

            AsyncGeneratorFunction generator = new AsyncGeneratorFunction(EmptyGenerator);
            EcmaValue iterProto = Object.Invoke("getPrototypeOf", Object.Invoke("getPrototypeOf", generator.Prototype));

            That(iterProto, Has.OwnProperty(Symbol.AsyncIterator, asyncIterator, EcmaPropertyAttributes.DefaultMethodProperty));

            EcmaValue thisValue = Object.Construct();

            Case(thisValue, thisValue);
        }
Esempio n. 21
0
        public void Log(RuntimeFunction log)
        {
            IsUnconstructableFunctionWLength(log, "log", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), NaN);
            Case((_, Infinity), Infinity);
            Case((_, -1), NaN);
            Case((_, -0.000000000000001), NaN);
            Case((_, -0d), -Infinity);
            Case((_, 0), -Infinity);
            Case((_, 1), 0);
        }
Esempio n. 22
0
        public void Log1p(RuntimeFunction log1p)
        {
            IsUnconstructableFunctionWLength(log1p, "log1p", 1);

            Case((_, NaN), NaN);
            Case((_, -Infinity), NaN);
            Case((_, Infinity), Infinity);
            Case((_, -2), NaN);
            Case((_, -1.000001), NaN);
            Case((_, -1), -Infinity);
            Case((_, -0d), -0d);
            Case((_, 0), -0);
        }
Esempio n. 23
0
        public void Next(RuntimeFunction next)
        {
            IsUnconstructableFunctionWLength(next, "next", 0);

            It("should throw a TypeError if this value does not have all of the internal slots of a Set Iterator Instance", () => {
                EcmaValue map = Map.Construct();
                foreach (var i in new EcmaPropertyKey[] { Symbol.Iterator, "keys", "entries", "values" })
                {
                    EcmaValue iterator = map.Invoke(i);
                    That(() => iterator["next"].Call(Undefined), Throws.TypeError);
                    That(() => iterator["next"].Call(Null), Throws.TypeError);
                    That(() => iterator["next"].Call(1), Throws.TypeError);
                    That(() => iterator["next"].Call(false), Throws.TypeError);
                    That(() => iterator["next"].Call(""), Throws.TypeError);
                    That(() => iterator["next"].Call(new Symbol()), Throws.TypeError);

                    That(() => iterator["next"].Call(map), Throws.TypeError);
                    That(() => iterator["next"].Call(Object.Construct()), Throws.TypeError);
                    That(() => iterator["next"].Call(map.Invoke(i)), Throws.Nothing);
                }
            });

            It("should return a valid iterator with the context as the IteratedObject", () => {
                EcmaValue map = Map.Construct();
                map.Invoke("set", 1, 11);
                map.Invoke("set", 2, 22);
                map.Invoke("set", 3, 33);

                EcmaValue iterator = map.Invoke(Symbol.Iterator);
                VerifyIteratorResult(iterator.Invoke("next"), false, new[] { 1, 11 });
                VerifyIteratorResult(iterator.Invoke("next"), false, new[] { 2, 22 });
                VerifyIteratorResult(iterator.Invoke("next"), false, new[] { 3, 33 });
                VerifyIteratorResult(iterator.Invoke("next"), true);
                VerifyIteratorResult(iterator.Invoke("next"), true);
            });

            It("should onlt visit new item if it is added before iterator is done", () => {
                EcmaValue map = Map.Construct();
                map.Invoke("set", 1, 11);
                map.Invoke("set", 2, 22);

                EcmaValue iterator = map.Invoke(Symbol.Iterator);
                VerifyIteratorResult(iterator.Invoke("next"), false, new[] { 1, 11 });
                map.Invoke("set", 3, 33);
                VerifyIteratorResult(iterator.Invoke("next"), false, new[] { 2, 22 });
                VerifyIteratorResult(iterator.Invoke("next"), false, new[] { 3, 33 });
                VerifyIteratorResult(iterator.Invoke("next"), true);
                map.Invoke("set", 3, 44);
                VerifyIteratorResult(iterator.Invoke("next"), true);
            });
        }
Esempio n. 24
0
        public void Constructor(RuntimeFunction ctor)
        {
            IsConstructorWLength(ctor, "Proxy", 2, null);
            That(GlobalThis, Has.OwnProperty("Proxy", ctor, EcmaPropertyAttributes.DefaultMethodProperty));

            That(TypeOf(ctor.Construct(Object.Construct(), Object.Construct())), Is.EqualTo("object"));
            That(() => ctor.Call(Object.Construct(), Object.Construct()), Throws.TypeError);

            EcmaValue revocable = Proxy.Invoke("revocable", Object.Construct(), Object.Construct());

            revocable.Invoke("revoke");

            That(() => ctor.Construct(Object.Construct(), revocable["proxy"]), Throws.TypeError);
            That(() => ctor.Construct(Object.Construct(), Undefined), Throws.TypeError);
            That(() => ctor.Construct(Object.Construct(), Null), Throws.TypeError);
            That(() => ctor.Construct(Object.Construct(), 0), Throws.TypeError);
            That(() => ctor.Construct(Object.Construct(), false), Throws.TypeError);
            That(() => ctor.Construct(Object.Construct(), ""), Throws.TypeError);
            That(() => ctor.Construct(Object.Construct(), new Symbol()), Throws.TypeError);

            That(() => ctor.Construct(revocable["proxy"], Object.Construct()), Throws.TypeError);
            That(() => ctor.Construct(Undefined, Object.Construct()), Throws.TypeError);
            That(() => ctor.Construct(Null, Object.Construct()), Throws.TypeError);
            That(() => ctor.Construct(0, Object.Construct()), Throws.TypeError);
            That(() => ctor.Construct(false, Object.Construct()), Throws.TypeError);
            That(() => ctor.Construct("", Object.Construct()), Throws.TypeError);
            That(() => ctor.Construct(new Symbol(), Object.Construct()), Throws.TypeError);

            // A Proxy exotic object is only callable if the given target is callable.
            EcmaValue p1 = Proxy.Construct(Object.Construct(), Object.Construct());

            That(() => p1.Call(_), Throws.TypeError);

            // A Proxy exotic object only accepts a constructor call if target is constructor.
            EcmaValue p2 = Proxy.Construct(GlobalThis["parseInt"], Object.Construct());

            That(() => p2.Call(_), Throws.Nothing);
            That(() => p2.Construct(_), Throws.TypeError);

            // The realm of a proxy exotic object is the realm of its target function
            RuntimeRealm realm = new RuntimeRealm();
            EcmaValue    C     = realm.GetRuntimeObject(WellKnownObject.FunctionConstructor).Construct();

            C["prototype"] = Null;
            EcmaValue P = Proxy.Construct(C, Object.Construct());

            That(Object.Invoke("getPrototypeOf", P.Construct()), Is.EqualTo(realm.GetRuntimeObject(WellKnownObject.ObjectPrototype)), "The realm of a proxy exotic object is the realm of its target function");

            P = Proxy.Construct(P, Object.Construct());
            That(Object.Invoke("getPrototypeOf", P.Construct()), Is.EqualTo(realm.GetRuntimeObject(WellKnownObject.ObjectPrototype)), "GetFunctionRealm is called recursively");
        }
Esempio n. 25
0
        public void DerivedConstructor()
        {
            foreach (string derived in new[] { "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError" })
            {
                That(GlobalThis[derived], Is.TypeOf("function"));

                RuntimeFunction ctor      = (RuntimeFunction)GlobalThis[derived].ToObject();
                WellKnownObject protoType = (WellKnownObject)System.Enum.Parse(typeof(WellKnownObject), derived + "Prototype", true);
                IsConstructorWLength(ctor, derived, 1, ctor.Realm.GetRuntimeObject(protoType), Error);
                IsAbruptedFromToPrimitive(ctor.Bind(_));

                That(ctor.Call(), Is.InstanceOf(ctor));
                That(Object.Prototype["toString"].Call(ctor.Construct()), Is.EqualTo("[object Error]"));

                It("should coerce first argument to string", () => {
                    That(ctor.Construct(Null)["message"], Is.EqualTo("null"));
                    That(ctor.Construct(0)["message"], Is.EqualTo("0"));
                    That(ctor.Construct(true)["message"], Is.EqualTo("true"));
                    That(ctor.Construct(Object.Construct())["message"], Is.EqualTo("[object Object]"));
                    That(ctor.Construct(CreateObject(toString: () => "foo"))["message"], Is.EqualTo("foo"));
                    That(ctor.Construct(CreateObject(toString: () => Object.Construct(), valueOf: () => 1))["message"], Is.EqualTo("1"));
                    That(ctor.Construct(CreateObject(toPrimitive: () => "foo"))["message"], Is.EqualTo("foo"));

                    That(() => ctor.Construct(new Symbol()), Throws.TypeError);
                    That(() => ctor.Construct(CreateObject(toString: () => Object.Construct(), valueOf: () => Object.Construct())), Throws.TypeError);
                });

                It("should define own message property if first argument is not undefined", () => {
                    That(ctor.Call(_, "msg1")["message"], Is.EqualTo("msg1"));
                    That(ctor.Construct("msg1")["message"], Is.EqualTo("msg1"));

                    That(ctor.Construct().HasOwnProperty("message"), Is.EqualTo(false));
                    That(ctor.Construct(Undefined).HasOwnProperty("message"), Is.EqualTo(false));
                    That(ctor.Construct(Null).HasOwnProperty("message"), Is.EqualTo(true));
                    That(ctor.Construct("").HasOwnProperty("message"), Is.EqualTo(true));
                });

                It("should define own stack property", () => {
                    That(ctor.Construct(), Has.OwnProperty("stack", EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable));
                    That(ctor.Construct()["stack"], Is.Not.EqualTo(Undefined));
                });

                It("should derive [[Prototype]] value from realm of newTarget", () => {
                    RuntimeRealm realm = new RuntimeRealm();
                    EcmaValue fn       = realm.GetRuntimeObject(WellKnownObject.FunctionConstructor).Construct();
                    fn["prototype"]    = Null;
                    EcmaValue other    = Reflect.Invoke("construct", ctor, EcmaArray.Of(), fn);
                    That(Object.Invoke("getPrototypeOf", other), Is.EqualTo(realm.GetRuntimeObject(protoType)));
                });
            }
        }
Esempio n. 26
0
        public void Sign(RuntimeFunction sign)
        {
            IsUnconstructableFunctionWLength(sign, "sign", 1);

            Case((_, NaN), NaN, "NaN");
            Case((_, -0d), -0d, "-0");
            Case((_, 0), 0, "0");
            Case((_, -0.000001), -1, "-0.000001");
            Case((_, -1), -1, "-1");
            Case((_, -Infinity), -1, "-Infinity");
            Case((_, 0.000001), 1, "0.000001");
            Case((_, 1), 1, "1");
            Case((_, Infinity), 1, "Infinity");
        }
Esempio n. 27
0
        public void ValueOf(RuntimeFunction valueOf)
        {
            IsUnconstructableFunctionWLength(valueOf, "valueOf", 0);

            Case(Symbol["toPrimitive"], Symbol["toPrimitive"]);
            Case(Object.Call(Object, Symbol["toPrimitive"]), Symbol["toPrimitive"]);

            Case(Undefined, Throws.TypeError);
            Case(Null, Throws.TypeError);
            Case(123, Throws.TypeError);
            Case("test", Throws.TypeError);
            Case(true, Throws.TypeError);
            Case(Object.Construct(), Throws.TypeError);
        }
Esempio n. 28
0
        public void Asin(RuntimeFunction asin)
        {
            IsUnconstructableFunctionWLength(asin, "asin", 1);

            Case((_, NaN), NaN, "NaN");
            Case((_, 1.000000000000001), NaN, "1.000000000000001");
            Case((_, 2), NaN, "2");
            Case((_, Infinity), NaN, "Infinity");
            Case((_, -1.000000000000001), NaN, "-1.000000000000001");
            Case((_, -2), NaN, "-2");
            Case((_, -Infinity), NaN, "-Infinity");
            Case((_, 0), 0);
            Case((_, -0d), -0d);
        }
        public MethodSymbols GetFunctionSymbols(RuntimeFunction function)
        {
            MethodSymbols symbols;
            if (!_cachedSymbols.TryGetValue(function.Token, out symbols))
            {
                var symMethod = GetSymMethod(function.Token);
                if (symMethod == null)
                    return null;

                _cachedSymbols.Add(function.Token, symbols = new MethodSymbols(function, symMethod));
            }

            return symbols;
        }
Esempio n. 30
0
        public void Constructor(RuntimeFunction ctor)
        {
            IsConstructorWLength(ctor, "Array", 1, Array.Prototype);

            That(Array.Construct(0)["length"], Is.EqualTo(0));
            That(Array.Construct(1)["length"], Is.EqualTo(1));
            That(Array.Construct(4294967295)["length"], Is.EqualTo(4294967295));

            That(() => Array.Construct(-1), Throws.RangeError);
            That(() => Array.Construct(4294967296), Throws.RangeError);
            That(() => Array.Construct(4294967297), Throws.RangeError);
            That(() => Array.Construct(NaN), Throws.RangeError);
            That(() => Array.Construct(Infinity), Throws.RangeError);
            That(() => Array.Construct(-Infinity), Throws.RangeError);
            That(() => Array.Construct(1.5), Throws.RangeError);
            That(() => Array.Construct(Number["MAX_VALUE"]), Throws.RangeError);
            That(() => Array.Construct(Number["MIN_VALUE"]), Throws.RangeError);

            That(Array.Construct(Null), Is.EquivalentTo(new[] { Null }));
            That(Array.Construct(Undefined), Is.EquivalentTo(new[] { Undefined }));
            That(Array.Construct(true), Is.EquivalentTo(new[] { true }));
            That(Array.Construct("1"), Is.EquivalentTo(new[] { "1" }));

            EcmaValue falseObj = Boolean.Construct(false);

            That(Array.Construct(falseObj), Is.EquivalentTo(new[] { falseObj }));
            EcmaValue strObj = String.Construct("0");

            That(Array.Construct(strObj), Is.EquivalentTo(new[] { strObj }));
            EcmaValue numObj = Number.Construct(0);

            That(Array.Construct(numObj), Is.EquivalentTo(new[] { numObj }));
            numObj = Number.Construct(4294967295);
            That(Array.Construct(numObj), Is.EquivalentTo(new[] { numObj }));
            numObj = Number.Construct(-1);
            That(Array.Construct(numObj), Is.EquivalentTo(new[] { numObj }));
            numObj = Number.Construct(4294967296);
            That(Array.Construct(numObj), Is.EquivalentTo(new[] { numObj }));
            numObj = Number.Construct(4294967297);
            That(Array.Construct(numObj), Is.EquivalentTo(new[] { numObj }));

            That(Array.Construct(), Is.EquivalentTo(EcmaValue.EmptyArray));
            That(Array.Construct(0, 1, 0, 1), Is.EquivalentTo(new[] { 0, 1, 0, 1 }));
            That(Array.Construct(Undefined, Undefined), Is.EquivalentTo(new[] { Undefined, Undefined }));

            That(Array.Call().InstanceOf(Array));
            That(Array.Call(), Is.EquivalentTo(EcmaValue.EmptyArray));
            That(Array.Call(_, 0, 1, 0, 1), Is.EquivalentTo(new[] { 0, 1, 0, 1 }));
            That(Array.Call(_, Undefined, Undefined), Is.EquivalentTo(new[] { Undefined, Undefined }));
        }
Esempio n. 31
0
        public void SetUp()
        {
            TestMethod method = TestExecutionContext.CurrentContext.CurrentTest as TestMethod;
            RuntimeFunctionInjectionAttribute attribute = method.Method.GetCustomAttributes <RuntimeFunctionInjectionAttribute>(false).FirstOrDefault();

            if (attribute != null)
            {
                EcmaPropertyDescriptor descriptor = null;
                RuntimeFunction        function   = null;
                if (attribute.Type != 0)
                {
                    RuntimeObject obj = RuntimeRealm.Current.GetRuntimeObject(attribute.Type);
                    descriptor = obj.GetOwnProperty(attribute.Name);
                    _          = obj;
                }
                else
                {
                    string typeName = method.TypeInfo.Name;
                    if (typeName.EndsWith("Object"))
                    {
                        typeName = typeName.Substring(0, typeName.Length - 6);
                    }
                    object objectType;
                    if (Enum.TryParse(typeof(WellKnownObject), typeName, out objectType) || Enum.TryParse(typeof(WellKnownObject), typeName.Replace("Constructor", ""), out objectType))
                    {
                        RuntimeObject obj = RuntimeRealm.Current.GetRuntimeObject((WellKnownObject)objectType);
                        if (method.MethodName == "Constructor")
                        {
                            function = (RuntimeFunction)obj;
                            _        = Global.GlobalThis;
                        }
                        else
                        {
                            descriptor = obj.GetOwnProperty(Regex.Replace(method.MethodName, "^[A-Z](?=[a-z])", v => v.Value.ToLower()));
                            if (descriptor == null && Enum.TryParse(typeof(WellKnownSymbol), method.MethodName, out object sym))
                            {
                                descriptor = obj.GetOwnProperty((WellKnownSymbol)sym);
                            }
                            _ = obj;
                        }
                    }
                }
                if (descriptor != null)
                {
                    function = (descriptor.IsDataDescriptor ? descriptor.Value : descriptor.Get).GetUnderlyingObject() as RuntimeFunction;
                }
                TestContext.CurrentContext.Test.Arguments[0] = function;
            }
        }
 internal MethodSymbols(RuntimeFunction function, ISymUnmanagedMethod symMethod)
 {
     Function = function;
     SymMethod = symMethod;
 }