Exemple #1
0
        public void Properties()
        {
            EcmaValue argumentsDesc  = Object.Invoke("getOwnPropertyDescriptor", Function.Prototype, "arguments");
            EcmaValue callerDesc     = Object.Invoke("getOwnPropertyDescriptor", Function.Prototype, "caller");
            EcmaValue throwTypeError = argumentsDesc["get"];

            That(throwTypeError, Is.TypeOf("function"));
            That(throwTypeError["name"], Is.EqualTo(""));
            That(throwTypeError["length"], Is.EqualTo(0));
            That(Object.Invoke("isExtensible", throwTypeError), Is.False, "%ThrowTypeError% is not extensible");
            That(Object.Invoke("isFrozen", throwTypeError), Is.True, "The integrity level of %ThrowTypeError% is \"frozen\"");
            That(Object.Invoke("getPrototypeOf", throwTypeError), Is.EqualTo(Function.Prototype));

            It("should throw a TypeError when called", () => {
                That(() => throwTypeError.Call(), Throws.TypeError);
            });

            It("does not have own caller and arguments property", () => {
                That(throwTypeError.Invoke("hasOwnProperty", "caller"), Is.False, "caller");
                That(throwTypeError.Invoke("hasOwnProperty", "arguments"), Is.False, "arguments");
            });

            It("is defined once for each realm", () => {
                That(argumentsDesc["get"], Is.EqualTo(throwTypeError), "arguments.get");
                That(argumentsDesc["get"], Is.EqualTo(throwTypeError), "arguments.set");
                That(callerDesc["get"], Is.EqualTo(throwTypeError), "caller.set");
                That(callerDesc["get"], Is.EqualTo(throwTypeError), "caller.get");

                RuntimeRealm other       = new RuntimeRealm();
                EcmaValue argumentsDesc1 = Object.Invoke("getOwnPropertyDescriptor", Function.Prototype, "arguments");
                EcmaValue argumentsDesc2 = Object.Invoke("getOwnPropertyDescriptor", other.Global["Function"]["prototype"], "arguments");
                That(argumentsDesc1["get"], Is.Not.EqualTo(argumentsDesc2["get"]));
            });
        }
Exemple #2
0
        public static EcmaValue LastMatch([This] EcmaValue thisValue)
        {
            MatchInfo cur = CheckAndPopulate(RuntimeRealm.GetRealm(thisValue));

            if (cur != null)
            {
                return(cur.LastValue);
            }
            return(default);
Exemple #3
0
        public void Properties()
        {
            RuntimeRealm realm   = new RuntimeRealm();
            EcmaValue    Symbol  = Global.Symbol;
            EcmaValue    OSymbol = realm.GetRuntimeObject(WellKnownObject.SymbolConstructor);

            foreach (var i in new[] { "asyncIterator", "hasInstance", "isConcatSpreadable", "iterator", "match", "matchAll", "replace", "search", "species", "split", "toPrimitive", "toStringTag", "unscopables" })
            {
                That(Symbol, Has.OwnProperty(i, EcmaPropertyAttributes.None), "Symbol.{0} descriptor", i);
                That(Symbol[i], Is.EqualTo(OSymbol[i]), "well-known symbols values are shared by all realms");
            }
        }
Exemple #4
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");
        }
Exemple #5
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)));
                });
            }
        }
Exemple #6
0
        public void Constructor(RuntimeFunction ctor)
        {
            IsConstructorWLength(ctor, "Error", 1, Error.Prototype);
            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"), Has.OwnProperty("message", "msg1", EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable));
                That(ctor.Construct("msg1"), Has.OwnProperty("message", "msg1", EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable));

                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(WellKnownObject.ErrorPrototype)));
            });
        }
Exemple #7
0
        static IntlModule()
        {
            IntlModule module = RuntimeRealm.RegisterModule <IntlModule>();

            Intl                        = module.GetSharedObjectHandle(IntlObjectKind.Intl);
            Locale                      = module.GetSharedObjectHandle(IntlObjectKind.Locale);
            LocalePrototype             = module.GetSharedObjectHandle(IntlObjectKind.LocalePrototype);
            Collator                    = module.GetSharedObjectHandle(IntlObjectKind.Collator);
            CollatorPrototype           = module.GetSharedObjectHandle(IntlObjectKind.CollatorPrototype);
            NumberFormat                = module.GetSharedObjectHandle(IntlObjectKind.NumberFormat);
            NumberFormatPrototype       = module.GetSharedObjectHandle(IntlObjectKind.NumberFormatPrototype);
            DateTimeFormat              = module.GetSharedObjectHandle(IntlObjectKind.DateTimeFormat);
            DateTimeFormatPrototype     = module.GetSharedObjectHandle(IntlObjectKind.DateTimeFormatPrototype);
            PluralRules                 = module.GetSharedObjectHandle(IntlObjectKind.PluralRules);
            PluralRulesPrototype        = module.GetSharedObjectHandle(IntlObjectKind.PluralRulesPrototype);
            ListFormat                  = module.GetSharedObjectHandle(IntlObjectKind.ListFormat);
            ListFormatPrototype         = module.GetSharedObjectHandle(IntlObjectKind.ListFormatPrototype);
            RelativeTimeFormat          = module.GetSharedObjectHandle(IntlObjectKind.RelativeTimeFormat);
            RelativeTimeFormatPrototype = module.GetSharedObjectHandle(IntlObjectKind.RelativeTimeFormatPrototype);
        }
Exemple #8
0
        public static EcmaValue CloneValue(EcmaValue value, EcmaValue[] transfer, RuntimeRealm targetRealm)
        {
            Guard.ArgumentNotNull(targetRealm, "targetRealm");
            bool isPrimitive = value.Type != EcmaValueType.Object;

            RuntimeObject[] transferList = transfer != null?transfer.Select(v => v.ToObject()).ToArray() : new RuntimeObject[0];

            RuntimeObject obj;

            if (isPrimitive)
            {
                obj     = new EcmaObject();
                obj[""] = value;
            }
            else
            {
                obj = value.ToObject();
            }
            obj = obj.Clone(targetRealm, transferList);
            return(isPrimitive ? obj[""] : obj);
        }
Exemple #9
0
        public void Constructor(RuntimeFunction ctor)
        {
            IsConstructorWLength(ctor, "SharedArrayBuffer", 1, SharedArrayBuffer.Prototype);
            That(GlobalThis, Has.OwnProperty("SharedArrayBuffer", ctor, EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable));

            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(Noop), fn);
                That(Object.Invoke("getPrototypeOf", other), Is.EqualTo(realm.GetRuntimeObject(WellKnownObject.SharedArrayBufferPrototype)));
            });

            It("should derive [[Prototype]] internal slot from NewTarget", () => {
                EcmaValue arrayBuffer = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(8), Object);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(Object.Prototype));

                EcmaValue newTarget = FunctionLiteral(Noop).Invoke("bind", Null);
                Object.Invoke("defineProperty", newTarget, "prototype", CreateObject(new { get = FunctionLiteral(() => Array.Prototype) }));
                arrayBuffer = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(16), newTarget);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(Array.Prototype));
            });

            It("should use %SharedArrayBufferPrototype% if NewTarget.prototype is not an object", () => {
                EcmaValue arrayBuffer;
                EcmaValue newTarget    = FunctionLiteral(Noop);
                newTarget["prototype"] = Undefined;
                arrayBuffer            = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(1), newTarget);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(SharedArrayBuffer.Prototype), "newTarget.prototype is undefined");

                newTarget["prototype"] = Null;
                arrayBuffer            = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(2), newTarget);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(SharedArrayBuffer.Prototype), "newTarget.prototype is null");

                newTarget["prototype"] = true;
                arrayBuffer            = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(3), newTarget);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(SharedArrayBuffer.Prototype), "newTarget.prototype is a Boolean");

                newTarget["prototype"] = "";
                arrayBuffer            = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(4), newTarget);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(SharedArrayBuffer.Prototype), "newTarget.prototype is a String");

                newTarget["prototype"] = new Symbol();
                arrayBuffer            = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(5), newTarget);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(SharedArrayBuffer.Prototype), "newTarget.prototype is a Symbol");

                newTarget["prototype"] = 1;
                arrayBuffer            = Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(6), newTarget);
                That(Object.Invoke("getPrototypeOf", arrayBuffer), Is.EqualTo(SharedArrayBuffer.Prototype), "newTarget.prototype is a Number");
            });

            It("should throw a TypeError if ArrayBuffer is called as a function", () => {
                That(() => SharedArrayBuffer.Call(Undefined), Throws.TypeError);
                That(() => SharedArrayBuffer.Call(Undefined, 42), Throws.TypeError);
            });

            It("should convert the `length` parameter to a value numeric index value", () => {
                EcmaValue obj1 = CreateObject(valueOf: () => 42);
                EcmaValue obj2 = CreateObject(toString: () => 42);
                That(SharedArrayBuffer.Construct(obj1)["byteLength"], Is.EqualTo(42), "object's valueOf");
                That(SharedArrayBuffer.Construct(obj2)["byteLength"], Is.EqualTo(42), "object's toString");
                That(SharedArrayBuffer.Construct("")["byteLength"], Is.EqualTo(0), "the Empty string");
                That(SharedArrayBuffer.Construct("0")["byteLength"], Is.EqualTo(0), "string '0'");
                That(SharedArrayBuffer.Construct("1")["byteLength"], Is.EqualTo(1), "string '1'");
                That(SharedArrayBuffer.Construct(true)["byteLength"], Is.EqualTo(1), "true");
                That(SharedArrayBuffer.Construct(false)["byteLength"], Is.EqualTo(0), "false");
                That(SharedArrayBuffer.Construct(NaN)["byteLength"], Is.EqualTo(0), "NaN");
                That(SharedArrayBuffer.Construct(Null)["byteLength"], Is.EqualTo(0), "null");
                That(SharedArrayBuffer.Construct(Undefined)["byteLength"], Is.EqualTo(0), "undefined");
                That(SharedArrayBuffer.Construct(0.1)["byteLength"], Is.EqualTo(0), "0.1");
                That(SharedArrayBuffer.Construct(0.9)["byteLength"], Is.EqualTo(0), "0.9");
                That(SharedArrayBuffer.Construct(1.1)["byteLength"], Is.EqualTo(1), "1.1");
                That(SharedArrayBuffer.Construct(1.9)["byteLength"], Is.EqualTo(1), "1.9");
                That(SharedArrayBuffer.Construct(-0.1)["byteLength"], Is.EqualTo(0), "-0.1");
                That(SharedArrayBuffer.Construct(-0.99999)["byteLength"], Is.EqualTo(0), "-0.99999");
            });

            It("should return an empty instance if length is absent", () => {
                That(SharedArrayBuffer.Construct()["byteLength"], Is.EqualTo(0));
            });

            It("should accept zero as the `length` parameter", () => {
                That(SharedArrayBuffer.Construct(0)["byteLength"], Is.EqualTo(0));
                That(SharedArrayBuffer.Construct(-0d)["byteLength"], Is.EqualTo(0));
            });

            It("should throw a RangeError if length represents an integer < 0", () => {
                That(() => SharedArrayBuffer.Construct(-1), Throws.RangeError);
                That(() => SharedArrayBuffer.Construct(-1.1), Throws.RangeError);
                That(() => SharedArrayBuffer.Construct(-Infinity), Throws.RangeError);
            });

            It("should throw a RangeError if requested Data Block is too large", () => {
                That(() => SharedArrayBuffer.Construct(9007199254740992), Throws.RangeError);
                That(() => SharedArrayBuffer.Construct(Infinity), Throws.RangeError);
            });

            It("should return abrupt from ToIndex(length)", () => {
                That(() => SharedArrayBuffer.Construct(new Symbol()), Throws.TypeError);
                That(() => SharedArrayBuffer.Construct(CreateObject(valueOf: ThrowTest262Exception)), Throws.Test262);
            });

            It("should create the new ArrayBuffer instance prior to allocating the Data Block", () => {
                EcmaValue newTarget = FunctionLiteral(Noop).Invoke("bind", Null);
                Object.Invoke("defineProperty", newTarget, "prototype", CreateObject(new { get = ThrowTest262Exception }));
                That(() => Reflect.Invoke("construct", SharedArrayBuffer, EcmaArray.Of(9007199254740992), newTarget), Throws.Test262);
            });

            It("should initialize all bytes to zero", () => {
                EcmaValue view = DataView.Construct(SharedArrayBuffer.Construct(9));
                That(view.Invoke("getUint8", 0), Is.EqualTo(0));
                That(view.Invoke("getUint8", 1), Is.EqualTo(0));
                That(view.Invoke("getUint8", 2), Is.EqualTo(0));
                That(view.Invoke("getUint8", 3), Is.EqualTo(0));
                That(view.Invoke("getUint8", 4), Is.EqualTo(0));
                That(view.Invoke("getUint8", 5), Is.EqualTo(0));
                That(view.Invoke("getUint8", 6), Is.EqualTo(0));
                That(view.Invoke("getUint8", 7), Is.EqualTo(0));
                That(view.Invoke("getUint8", 8), Is.EqualTo(0));
            });
        }
Exemple #10
0
        public void Constructor(RuntimeFunction ctor)
        {
            IsConstructorWLength(ctor, "DataView", 1, DataView.Prototype);
            That(GlobalThis, Has.OwnProperty("DataView", ctor, EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable));

            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(ArrayBuffer.Construct(8)), fn);
                That(Object.Invoke("getPrototypeOf", other), Is.EqualTo(realm.GetRuntimeObject(WellKnownObject.DataViewPrototype)));
            });

            It("should throw a TypeError if ArrayBuffer is called as a function", () => {
                EcmaValue obj     = CreateObject(valueOf: ThrowTest262WithMessage("NewTarget should be verified before byteOffset"));
                EcmaValue buffer  = ArrayBuffer.Construct(8);
                EcmaValue sbuffer = SharedArrayBuffer.Construct(8);
                That(() => DataView.Call(Undefined, buffer, obj), Throws.TypeError);
                That(() => DataView.Call(Undefined, sbuffer, obj), Throws.TypeError);
            });

            It("should throw a TypeError if buffer is not Object", () => {
                EcmaValue obj = CreateObject(valueOf: ThrowTest262WithMessage("buffer should be verified before byteOffset"));
                That(() => DataView.Construct(0, obj), Throws.TypeError);
                That(() => DataView.Construct(1, obj), Throws.TypeError);
                That(() => DataView.Construct("", obj), Throws.TypeError);
                That(() => DataView.Construct("buffer", obj), Throws.TypeError);
                That(() => DataView.Construct(true, obj), Throws.TypeError);
                That(() => DataView.Construct(false, obj), Throws.TypeError);
                That(() => DataView.Construct(NaN, obj), Throws.TypeError);
                That(() => DataView.Construct(new Symbol(), obj), Throws.TypeError);
            });

            It("should throw a TypeError if buffer does not have [[ArrayBufferData]]", () => {
                EcmaValue obj = CreateObject(valueOf: ThrowTest262WithMessage("buffer should be verified before byteOffset"));
                That(() => DataView.Construct(Object.Construct(), obj), Throws.TypeError, "{}");
                That(() => DataView.Construct(EcmaArray.Of(), obj), Throws.TypeError, "[]");
                That(() => DataView.Construct(Global.Int8Array.Construct(), obj), Throws.TypeError, "typedArray instance");
                That(() => DataView.Construct(DataView.Construct(ArrayBuffer.Construct(0)), obj), Throws.TypeError, "dataView instance");
                That(() => DataView.Construct(DataView.Construct(SharedArrayBuffer.Construct(0)), obj), Throws.TypeError, "dataView instance");
            });

            It("should throw a TypeError if the buffer is detached", () => {
                EcmaValue obj    = CreateObject(valueOf: Intercept(() => 0));
                EcmaValue buffer = ArrayBuffer.Construct();
                DetachBuffer(buffer);

                That(() => DataView.Construct(buffer, obj), Throws.TypeError);
                That(Logs.Count, Is.EqualTo(1));
            });

            It("should reuse buffer argument instead of making a new clone", () => {
                EcmaValue buffer = ArrayBuffer.Construct(8);
                That(DataView.Construct(buffer, 0)["buffer"], Is.EqualTo(buffer));
                That(DataView.Construct(buffer, 0)["buffer"], Is.EqualTo(buffer));

                EcmaValue sbuffer = SharedArrayBuffer.Construct(8);
                That(DataView.Construct(sbuffer, 0)["buffer"], Is.EqualTo(sbuffer));
                That(DataView.Construct(sbuffer, 0)["buffer"], Is.EqualTo(sbuffer));
            });

            It("should throw a RangeError if ToInteger(byteOffset) < 0", () => {
                EcmaValue buffer = ArrayBuffer.Construct(8);
                That(() => DataView.Construct(buffer, -1), Throws.RangeError);
                That(() => DataView.Construct(buffer, -Infinity), Throws.RangeError);

                EcmaValue sbuffer = SharedArrayBuffer.Construct(8);
                That(() => DataView.Construct(sbuffer, -1), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, -Infinity), Throws.RangeError);
            });

            It("should throw if buffer is detached during OrdinaryCreateFromConstructor", () => {
                EcmaValue buffer     = ArrayBuffer.Construct(8);
                EcmaValue called     = false;
                EcmaValue byteOffset = CreateObject(valueOf: () => Return(called = true, 0));
                EcmaValue newTarget  = FunctionLiteral(Noop).Invoke("bind", Null);
                Object.Invoke("defineProperty", newTarget, "prototype", CreateObject(new {
                    get = Intercept(() => {
                        DetachBuffer(buffer);
                        return(DataView.Prototype);
                    })
                }));

                That(() => Reflect.Invoke("construct", DataView, EcmaArray.Of(buffer, byteOffset), newTarget), Throws.TypeError);
                That(called, Is.EqualTo(true));
            });

            It("should return abrupt from newTarget's custom constructor prototype", () => {
                EcmaValue newTarget = FunctionLiteral(Noop).Invoke("bind", Null);
                Object.Invoke("defineProperty", newTarget, "prototype", CreateObject(new { get = ThrowTest262Exception }));

                EcmaValue buffer = ArrayBuffer.Construct(8);
                That(() => Reflect.Invoke("construct", DataView, EcmaArray.Of(buffer, 0), newTarget), Throws.Test262);

                EcmaValue sbuffer = SharedArrayBuffer.Construct(8);
                That(() => Reflect.Invoke("construct", DataView, EcmaArray.Of(sbuffer, 0), newTarget), Throws.Test262);
            });

            It("should use DataView.Prototype if newTarget's prototype is not an Object", () => {
                EcmaValue newTarget    = FunctionLiteral(Noop);
                newTarget["prototype"] = Null;

                EcmaValue buffer = ArrayBuffer.Construct(8);
                EcmaValue result = Reflect.Invoke("construct", DataView, EcmaArray.Of(buffer, 0), newTarget);
                That(result["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", result), Is.EqualTo(DataView.Prototype));

                EcmaValue sbuffer = SharedArrayBuffer.Construct(8);
                EcmaValue sresult = Reflect.Invoke("construct", DataView, EcmaArray.Of(sbuffer, 0), newTarget);
                That(sresult["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sresult), Is.EqualTo(DataView.Prototype));
            });

            It("should use newTarget's custom constructor prototype if Object", () => {
                EcmaValue newTarget    = FunctionLiteral(Noop);
                EcmaValue proto        = Object.Construct();
                newTarget["prototype"] = proto;

                EcmaValue buffer = ArrayBuffer.Construct(8);
                EcmaValue result = Reflect.Invoke("construct", DataView, EcmaArray.Of(buffer, 0), newTarget);
                That(result["constructor"], Is.EqualTo(Object));
                That(Object.Invoke("getPrototypeOf", result), Is.EqualTo(proto));

                EcmaValue sbuffer = SharedArrayBuffer.Construct(8);
                EcmaValue sresult = Reflect.Invoke("construct", DataView, EcmaArray.Of(sbuffer, 0), newTarget);
                That(sresult["constructor"], Is.EqualTo(Object));
                That(Object.Invoke("getPrototypeOf", sresult), Is.EqualTo(proto));
            });

            It("should return new instance from defined offset", () => {
                EcmaValue sample;
                EcmaValue buffer = ArrayBuffer.Construct(4);

                sample = DataView.Construct(buffer, 0);
                That(sample["byteLength"], Is.EqualTo(4), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 1);
                That(sample["byteLength"], Is.EqualTo(3), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 2);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(2), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 3);
                That(sample["byteLength"], Is.EqualTo(1), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(3), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 4);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(4), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, Undefined);
                That(sample["byteLength"], Is.EqualTo(4), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 1, Undefined);
                That(sample["byteLength"], Is.EqualTo(3), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 2, Undefined);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(2), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 3, Undefined);
                That(sample["byteLength"], Is.EqualTo(1), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(3), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 4, Undefined);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(4), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                buffer = SharedArrayBuffer.Construct(4);
                sample = DataView.Construct(buffer, 0);
                That(sample["byteLength"], Is.EqualTo(4), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 1);
                That(sample["byteLength"], Is.EqualTo(3), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 2);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(2), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 3);
                That(sample["byteLength"], Is.EqualTo(1), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(3), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 4);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(4), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, Undefined);
                That(sample["byteLength"], Is.EqualTo(4), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 1, Undefined);
                That(sample["byteLength"], Is.EqualTo(3), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 2, Undefined);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(2), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 3, Undefined);
                That(sample["byteLength"], Is.EqualTo(1), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(3), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 4, Undefined);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(4), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));
            });

            It("should return new instance from defined length and offset", () => {
                EcmaValue sample;
                EcmaValue buffer = ArrayBuffer.Construct(3);

                sample = DataView.Construct(buffer, 1, 2);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 1, 0);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, 3);
                That(sample["byteLength"], Is.EqualTo(3), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 3, 0);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(3), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, 1);
                That(sample["byteLength"], Is.EqualTo(1), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, 2);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                buffer = SharedArrayBuffer.Construct(3);
                sample = DataView.Construct(buffer, 1, 2);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 1, 0);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(1), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, 3);
                That(sample["byteLength"], Is.EqualTo(3), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 3, 0);
                That(sample["byteLength"], Is.EqualTo(0), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(3), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, 1);
                That(sample["byteLength"], Is.EqualTo(1), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));

                sample = DataView.Construct(buffer, 0, 2);
                That(sample["byteLength"], Is.EqualTo(2), "sample.byteLength");
                That(sample["byteOffset"], Is.EqualTo(0), "sample.byteOffset");
                That(sample["buffer"], Is.EqualTo(buffer), "sample.buffer");
                That(sample["constructor"], Is.EqualTo(DataView));
                That(Object.Invoke("getPrototypeOf", sample), Is.EqualTo(DataView.Prototype));
            });

            It("should throw a RangeError if offset > bufferByteLength", () => {
                EcmaValue buffer = ArrayBuffer.Construct(1);
                That(() => DataView.Construct(buffer, 2), Throws.RangeError);
                That(() => DataView.Construct(buffer, Infinity), Throws.RangeError);

                EcmaValue sbuffer = SharedArrayBuffer.Construct(1);
                That(() => DataView.Construct(sbuffer, 2), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, Infinity), Throws.RangeError);
            });

            It("should throw a RangeError if offset + viewByteLength > bufferByteLength", () => {
                EcmaValue buffer = ArrayBuffer.Construct(3);
                That(() => DataView.Construct(buffer, 0, 4), Throws.RangeError);
                That(() => DataView.Construct(buffer, 1, 3), Throws.RangeError);
                That(() => DataView.Construct(buffer, 2, 2), Throws.RangeError);
                That(() => DataView.Construct(buffer, 3, 1), Throws.RangeError);
                That(() => DataView.Construct(buffer, 4, 0), Throws.RangeError);
                That(() => DataView.Construct(buffer, 4, -1), Throws.RangeError);
                That(() => DataView.Construct(buffer, 4, -Infinity), Throws.RangeError);
                That(() => DataView.Construct(buffer, 0, Infinity), Throws.RangeError);

                EcmaValue sbuffer = SharedArrayBuffer.Construct(3);
                That(() => DataView.Construct(sbuffer, 0, 4), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 1, 3), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 2, 2), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 3, 1), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 4, 0), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 4, -1), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 4, -Infinity), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 0, Infinity), Throws.RangeError);
            });

            It("should throw a RangeError if ToInteger(byteOffset) < 0", () => {
                EcmaValue buffer = ArrayBuffer.Construct(2);
                That(() => DataView.Construct(buffer, -1), Throws.RangeError);
                That(() => DataView.Construct(buffer, -Infinity), Throws.RangeError);

                EcmaValue sbuffer = SharedArrayBuffer.Construct(2);
                That(() => DataView.Construct(sbuffer, -1), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, -Infinity), Throws.RangeError);
            });

            It("should throw a RangeError if ToInteger(byteLength) < 0", () => {
                EcmaValue buffer = ArrayBuffer.Construct(2);
                That(() => DataView.Construct(buffer, 0, -1), Throws.RangeError);
                That(() => DataView.Construct(buffer, 0, -Infinity), Throws.RangeError);
                That(() => DataView.Construct(buffer, 1, -1), Throws.RangeError);
                That(() => DataView.Construct(buffer, 2, -Infinity), Throws.RangeError);

                EcmaValue sbuffer = SharedArrayBuffer.Construct(2);
                That(() => DataView.Construct(sbuffer, -1), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, -Infinity), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 1, -1), Throws.RangeError);
                That(() => DataView.Construct(sbuffer, 2, -Infinity), Throws.RangeError);
            });

            It("should perform ToIndex conversions on byteOffset", () => {
                EcmaValue obj1 = CreateObject(valueOf: () => 3);
                EcmaValue obj2 = CreateObject(valueOf: () => 4);
                EcmaValue ab   = ArrayBuffer.Construct(42);
                EcmaValue sample;

                sample = DataView.Construct(ab, -0);
                That(sample["byteOffset"], Is.EqualTo(0), "-0");

                sample = DataView.Construct(ab, obj1);
                That(sample["byteOffset"], Is.EqualTo(3), "object's valueOf");

                sample = DataView.Construct(ab, obj2);
                That(sample["byteOffset"], Is.EqualTo(4), "object's toString");

                sample = DataView.Construct(ab, "");
                That(sample["byteOffset"], Is.EqualTo(0), "the Empty string");

                sample = DataView.Construct(ab, "0");
                That(sample["byteOffset"], Is.EqualTo(0), "string '0'");

                sample = DataView.Construct(ab, "1");
                That(sample["byteOffset"], Is.EqualTo(1), "string '1'");

                sample = DataView.Construct(ab, true);
                That(sample["byteOffset"], Is.EqualTo(1), "true");

                sample = DataView.Construct(ab, false);
                That(sample["byteOffset"], Is.EqualTo(0), "false");

                sample = DataView.Construct(ab, NaN);
                That(sample["byteOffset"], Is.EqualTo(0), "NaN");

                sample = DataView.Construct(ab, Null);
                That(sample["byteOffset"], Is.EqualTo(0), "null");

                sample = DataView.Construct(ab, Undefined);
                That(sample["byteOffset"], Is.EqualTo(0), "undefined");

                sample = DataView.Construct(ab, 0.1);
                That(sample["byteOffset"], Is.EqualTo(0), "0.1");

                sample = DataView.Construct(ab, 0.9);
                That(sample["byteOffset"], Is.EqualTo(0), "0.9");

                sample = DataView.Construct(ab, 1.1);
                That(sample["byteOffset"], Is.EqualTo(1), "1.1");

                sample = DataView.Construct(ab, 1.9);
                That(sample["byteOffset"], Is.EqualTo(1), "1.9");

                sample = DataView.Construct(ab, -0.1);
                That(sample["byteOffset"], Is.EqualTo(0), "-0.1");

                sample = DataView.Construct(ab, -0.99999);
                That(sample["byteOffset"], Is.EqualTo(0), "-0.99999");
            });

            It("should perform ToIndex conversions on byteLength", () => {
                EcmaValue obj1 = CreateObject(valueOf: () => 3);
                EcmaValue obj2 = CreateObject(valueOf: () => 4);
                EcmaValue ab   = ArrayBuffer.Construct(42);
                EcmaValue sample;

                sample = DataView.Construct(ab, 0, -0);
                That(sample["byteLength"], Is.EqualTo(0), "-0");

                sample = DataView.Construct(ab, 0, obj1);
                That(sample["byteLength"], Is.EqualTo(3), "object's valueOf");

                sample = DataView.Construct(ab, 0, obj2);
                That(sample["byteLength"], Is.EqualTo(4), "object's toString");

                sample = DataView.Construct(ab, 0, "");
                That(sample["byteLength"], Is.EqualTo(0), "the Empty string");

                sample = DataView.Construct(ab, 0, "0");
                That(sample["byteLength"], Is.EqualTo(0), "string '0'");

                sample = DataView.Construct(ab, 0, "1");
                That(sample["byteLength"], Is.EqualTo(1), "string '1'");

                sample = DataView.Construct(ab, 0, true);
                That(sample["byteLength"], Is.EqualTo(1), "true");

                sample = DataView.Construct(ab, 0, false);
                That(sample["byteLength"], Is.EqualTo(0), "false");

                sample = DataView.Construct(ab, 0, NaN);
                That(sample["byteLength"], Is.EqualTo(0), "NaN");

                sample = DataView.Construct(ab, 0, Null);
                That(sample["byteLength"], Is.EqualTo(0), "null");

                sample = DataView.Construct(ab, 0, 0.1);
                That(sample["byteLength"], Is.EqualTo(0), "0.1");

                sample = DataView.Construct(ab, 0, 0.9);
                That(sample["byteLength"], Is.EqualTo(0), "0.9");

                sample = DataView.Construct(ab, 0, 1.1);
                That(sample["byteLength"], Is.EqualTo(1), "1.1");

                sample = DataView.Construct(ab, 0, 1.9);
                That(sample["byteLength"], Is.EqualTo(1), "1.9");

                sample = DataView.Construct(ab, 0, -0.1);
                That(sample["byteLength"], Is.EqualTo(0), "-0.1");

                sample = DataView.Construct(ab, 0, -0.99999);
                That(sample["byteLength"], Is.EqualTo(0), "-0.99999");
            });

            It("should return abrupt from ToNumber(byteOffset)", () => {
                EcmaValue obj = CreateObject(valueOf: ThrowTest262Exception);
                EcmaValue ab  = ArrayBuffer.Construct(0);
                That(() => DataView.Construct(ab, obj), Throws.Test262);
                That(() => DataView.Construct(ab, new Symbol()), Throws.TypeError);
            });

            It("should return abrupt from ToNumber(byteLength)", () => {
                EcmaValue obj1 = CreateObject(valueOf: ThrowTest262Exception);
                EcmaValue obj2 = CreateObject(toString: ThrowTest262Exception);
                EcmaValue ab   = ArrayBuffer.Construct(0);
                That(() => DataView.Construct(ab, 0, obj1), Throws.Test262);
                That(() => DataView.Construct(ab, 0, obj2), Throws.Test262);
                That(() => DataView.Construct(ab, 0, new Symbol()), Throws.TypeError);
            });
        }
Exemple #11
0
        public void StructuredSerialize()
        {
            RuntimeRealm other = new RuntimeRealm();

            It("should clone object with own non-symbol properties", () => {
                EcmaValue obj     = new EcmaObject();
                obj["boolean"]    = true;
                obj["number"]     = 1;
                obj["string"]     = "";
                obj["circular"]   = obj;
                obj["booleanObj"] = Boolean.Construct(false);
                obj["numberObj"]  = Number.Construct(0);
                obj["stringObj"]  = String.Construct("");
                obj[new Symbol()] = "foo";
                Object.Invoke("defineProperty", obj, "foo", CreateObject(new { enumerable = true, value = 1 }));
                Object.Invoke("defineProperty", obj, "bar", CreateObject(new { enumerable = true, get = FunctionLiteral(() => 0) }));
                Object.Invoke("defineProperty", obj, "baz", CreateObject(new { enumerable = false, value = 1 }));

                other.Execute(() => {
                    EcmaValue clone = obj.ToObject().Clone(other);
                    That(clone != obj);
                    That(Object.Invoke("getPrototypeOf", clone), Is.EqualTo(Object.Prototype), "prototype is derived from target realm");

                    That(clone["boolean"], Is.EqualTo(true));
                    That(clone["number"], Is.EqualTo(1));
                    That(clone["string"], Is.EqualTo(""));

                    That(clone["booleanObj"], Is.InstanceOf(Boolean), "Boolean object is copied");
                    That(clone["numberObj"], Is.InstanceOf(Number), "Number object is copied");
                    That(clone["stringObj"], Is.InstanceOf(String), "String object is copied");

                    That(clone["circular"], Is.EqualTo(clone), "circular reference is preserved");
                    That(clone, Has.OwnProperty("foo", 1, EcmaPropertyAttributes.DefaultDataProperty), "non-writable and non-configurable flag is not copied");
                    That(clone, Has.OwnProperty("bar", 0, EcmaPropertyAttributes.DefaultDataProperty), "accessor is copied as data");
                    That(Object.Invoke("getOwnPropertyDescriptor", clone, "baz"), Is.Undefined, "non-enumerable property is not copied");
                    That(Object.Invoke("getOwnPropertySymbols", clone)["length"], Is.Zero, "symbol property is not copied");
                });
            });

            It("should not clone prototype chain", () => {
                EcmaValue obj         = new EcmaObject();
                EcmaValue customProto = Object.Invoke("create", obj);
                obj["foo"]            = "bar";

                Assume.That(Object.Invoke("getPrototypeOf", customProto), Is.EqualTo(obj));
                Assume.That(customProto["foo"], Is.EqualTo("bar"));

                other.Execute(() => {
                    EcmaValue clone = customProto.ToObject().Clone(other);
                    That(clone != customProto);
                    That(Object.Invoke("getPrototypeOf", clone), Is.EqualTo(Object.Prototype), "prototype chain is ignored");
                    That(Object.Invoke("getOwnPropertyNames", clone)["length"], Is.Zero, "inherited properties are not copied");
                    That(clone["foo"], Is.Undefined);
                });
            });

            It("should throw if property values are not cloneable", () => {
                EcmaValue poisoned = new EcmaObject();
                poisoned["foo"]    = new Symbol();
                other.Execute(() => {
                    That(() => poisoned.ToObject().Clone(other), Throws.Exception, "symbol value causes exception");
                });
            });

            It("should shallow clone primitive objects", () => {
                EcmaValue boolObj = Boolean.Construct(false);
                EcmaValue numObj  = Number.Construct(0);
                EcmaValue strObj  = String.Construct("");

                boolObj["foo"] = 1;
                numObj["foo"]  = 1;
                strObj["foo"]  = 1;

                Assume.That(Object.Invoke("getOwnPropertyNames", boolObj)["length"], Is.EqualTo(1));
                Assume.That(Object.Invoke("getOwnPropertyNames", numObj)["length"], Is.EqualTo(1));
                Assume.That(Object.Invoke("getOwnPropertyNames", strObj)["length"], Is.EqualTo(1));

                other.Execute(() => {
                    EcmaValue cboolObj = boolObj.ToObject().Clone(other);
                    That(cboolObj, Is.TypeOf("object"));
                    That(Object.Invoke("getOwnPropertyNames", cboolObj)["length"], Is.Zero);

                    EcmaValue cnumObj = numObj.ToObject().Clone(other);
                    That(cnumObj, Is.TypeOf("object"));
                    That(Object.Invoke("getOwnPropertyNames", cnumObj)["length"], Is.Zero);

                    EcmaValue cstrObj = strObj.ToObject().Clone(other);
                    That(cstrObj, Is.TypeOf("object"));
                    That(Object.Invoke("getOwnPropertyNames", cstrObj)["length"], Is.Zero);
                });
            });

            It("should shallow clone Date object", () => {
                EcmaValue date = Date.Construct(2020, 0, 1);
                EcmaValue ts   = +date;
                date["foo"]    = 1;

                other.Execute(() => {
                    EcmaValue clone = date.ToObject().Clone(other);
                    That(clone, Is.InstanceOf(Date));
                    That(+clone, Is.EqualTo(ts));
                    That(Object.Invoke("getOwnPropertyDescriptor", clone, "foo"), Is.Undefined);
                });
            });

            It("should deeply clone [[MapData]]", () => {
                EcmaValue map = Map.Construct();
                map.Invoke("set", map, map);
                map.Invoke("set", "bar", "baz");
                map["foo"] = 1;

                other.Execute(() => {
                    EcmaValue clone = map.ToObject().Clone(other);
                    That(clone, Is.InstanceOf(Map));
                    That(clone.Invoke("get", clone), Is.EqualTo(clone));
                    That(Object.Invoke("getOwnPropertyDescriptor", clone, "foo"), Is.Undefined, "own property is not copied");

                    clone.Invoke("set", map, 1);
                    clone.Invoke("delete", "bar");
                    clone.Invoke("set", "baz", true);
                });
                That(map.Invoke("get", map), Is.EqualTo(map), "original value is unchanged");
                That(map.Invoke("get", "bar"), Is.EqualTo("baz"), "original entry is not deleted");
                That(map.Invoke("has", "baz"), Is.False, "key added in clone is not added in original map");
            });

            It("should deeply clone [[SetData]]", () => {
                EcmaValue set = Set.Construct();
                set.Invoke("add", set);
                set.Invoke("add", true);
                set["foo"] = 1;

                other.Execute(() => {
                    EcmaValue clone = set.ToObject().Clone(other);
                    That(clone, Is.InstanceOf(Set));
                    That(clone.Invoke("has", clone), Is.True);
                    That(Object.Invoke("getOwnPropertyDescriptor", clone, "foo"), Is.Undefined, "own property is not copied");

                    clone.Invoke("delete", true);
                    clone.Invoke("add", false);
                });
                That(set.Invoke("has", true), Is.True);
                That(set.Invoke("has", false), Is.False);
            });

            It("should clone [[ArrayBufferData]] with same byte contents", () => {
                EcmaValue buffer = Global.ArrayBuffer.Construct(4);
                EcmaValue view   = Global.Uint8Array.Construct(buffer);
                view[1]          = 1;
                view[2]          = 2;
                view[3]          = 3;
                buffer["foo"]    = 1;

                other.Execute(() => {
                    EcmaValue clone     = buffer.ToObject().Clone(other);
                    EcmaValue cloneView = Global.Uint8Array.Construct(clone);
                    That(cloneView, Is.EquivalentTo(new[] { 0, 1, 2, 3 }));
                    That(Object.Invoke("getOwnPropertyDescriptor", clone, "foo"), Is.Undefined, "own property is not copied");
                    cloneView[0] = 42;
                });
                That(view, Is.EquivalentTo(new[] { 0, 1, 2, 3 }));
            });

            It("should clone [[ArrayBufferData]] with same data block if it is shared", () => {
                EcmaValue buffer = Global.SharedArrayBuffer.Construct(4);
                EcmaValue view   = Global.Uint8Array.Construct(buffer);
                view[1]          = 1;
                view[2]          = 2;
                view[3]          = 3;
                buffer["foo"]    = 1;

                other.Execute(() => {
                    EcmaValue clone     = buffer.ToObject().Clone(other);
                    EcmaValue cloneView = Global.Uint8Array.Construct(clone);
                    That(cloneView, Is.EquivalentTo(new[] { 0, 1, 2, 3 }));
                    That(Object.Invoke("getOwnPropertyDescriptor", clone, "foo"), Is.Undefined, "own property is not copied");
                    cloneView[0] = 42;
                });
                That(view, Is.EquivalentTo(new[] { 42, 1, 2, 3 }));
            });

            It("should clone [[ViewedArrayBuffer]] with same byte contents", () => {
                EcmaValue buffer = Global.ArrayBuffer.Construct(4);
                EcmaValue view   = Global.Uint8Array.Construct(buffer);
                view[1]          = 1;
                view[2]          = 2;
                view[3]          = 3;
                view["foo"]      = 1;

                other.Execute(() => {
                    EcmaValue cloneView = view.ToObject().Clone(other);
                    That(cloneView, Is.EquivalentTo(new[] { 0, 1, 2, 3 }));
                    That(Object.Invoke("getOwnPropertyDescriptor", cloneView, "foo"), Is.Undefined, "own property is not copied");
                    cloneView[0] = 42;
                });
                That(view, Is.EquivalentTo(new[] { 0, 1, 2, 3 }));
            });

            It("should clone [[ViewedArrayBuffer]] with same data block if it is shared", () => {
                EcmaValue buffer = Global.SharedArrayBuffer.Construct(4);
                EcmaValue view   = Global.Uint8Array.Construct(buffer);
                view[1]          = 1;
                view[2]          = 2;
                view[3]          = 3;
                view["foo"]      = 1;

                other.Execute(() => {
                    EcmaValue cloneView = view.ToObject().Clone(other);
                    That(cloneView, Is.EquivalentTo(new[] { 0, 1, 2, 3 }));
                    That(Object.Invoke("getOwnPropertyDescriptor", cloneView, "foo"), Is.Undefined, "own property is not copied");
                    cloneView[0] = 42;
                });
                That(view, Is.EquivalentTo(new[] { 42, 1, 2, 3 }));
            });

            It("should throw if object is callable", () => {
                EcmaValue fn = FunctionLiteral(Noop);
                That(() => fn.ToObject().Clone(other), Throws.Exception);
            });

            It("should throw if object has other internal slots", () => {
                EcmaValue symObj = Object.Construct(new Symbol());
                That(() => symObj.ToObject().Clone(other), Throws.Exception);
            });

            It("should detach array buffer if it is in the transfer list", () => {
                EcmaValue buffer = Global.ArrayBuffer.Construct(4);
                EcmaValue view   = Global.Uint8Array.Construct(buffer);
                view[1]          = 1;
                view[2]          = 2;
                view[3]          = 3;

                other.Execute(() => {
                    EcmaValue clone     = buffer.ToObject().Clone(other, buffer.ToObject());
                    EcmaValue cloneView = Global.Uint8Array.Construct(clone);
                    That(cloneView, Is.EquivalentTo(new[] { 0, 1, 2, 3 }));
                });
                That(() => view[1], Throws.TypeError);
            });

            It("should throw if object in transfer list is not transferable", () => {
                EcmaValue buffer = Global.ArrayBuffer.Construct(4);
                That(() => buffer.ToObject().Clone(other, new EcmaObject()), Throws.Exception);
            });

            It("should throw if array buffer in transfer list is detached", () => {
                EcmaValue buffer   = Global.ArrayBuffer.Construct(4);
                EcmaValue detached = Global.ArrayBuffer.Construct(4);
                DetachBuffer(detached);
                That(() => buffer.ToObject().Clone(other, detached.ToObject()), Throws.Exception);
            });
        }
Exemple #12
0
        public void ObjectHosting()
        {
            It("should return different instances on different execution thread", () => {
                TestObject obj   = new TestObject();
                RuntimeObject v0 = RuntimeRealm.Current.ResolveRuntimeObject(obj);

                RuntimeExecution.CreateWorkerThread(parentRealm => {
                    Assume.That(parentRealm, Is.Not.EqualTo(RuntimeRealm.Current), "realm should be different");

                    RuntimeObject v1 = RuntimeRealm.Current.ResolveRuntimeObject(obj);
                    That(v0 != v1, "returned object should be different");
                    That(v0.Realm, Is.EqualTo(parentRealm));
                    That(v1.Realm, Is.EqualTo(RuntimeRealm.Current));

                    That(v0.GetPrototypeOf() != v1.GetPrototypeOf(), "the prototype of returned object should be different");
                    That(v0.GetPrototypeOf().Realm, Is.EqualTo(parentRealm));
                    That(v1.GetPrototypeOf().Realm, Is.EqualTo(RuntimeRealm.Current));

                    That(v0.GetPrototypeOf().GetPrototypeOf() != v1.GetPrototypeOf().GetPrototypeOf(), "all prototype ancestors of returned object should be different");

                    That(v0["MyMethod"], Is.TypeOf("function"));
                    That(v0["MyMethod"], Is.Not.EqualTo(v1["MyMethod"]), "property value of object type should be different");
                }, true).Thread.Join();
            });

            It("should return different instances on different realm of the same execution thread", () => {
                TestObject obj           = new TestObject();
                RuntimeObject v0         = RuntimeRealm.Current.ResolveRuntimeObject(obj);
                RuntimeRealm parentRealm = RuntimeRealm.Current;
                RuntimeRealm other       = new RuntimeRealm();

                other.Enqueue(() => {
                    Assume.That(RuntimeRealm.Current, Is.Not.EqualTo(parentRealm), "realm should be different");
                    Assume.That(RuntimeRealm.Current, Is.EqualTo(other));

                    RuntimeObject v1 = RuntimeRealm.Current.ResolveRuntimeObject(obj);
                    That(v0 != v1, "returned object should be different");
                    That(v0.Realm, Is.EqualTo(parentRealm));
                    That(v1.Realm, Is.EqualTo(RuntimeRealm.Current));

                    That(v0.GetPrototypeOf() != v1.GetPrototypeOf(), "the prototype of returned object should be different");
                    That(v0.GetPrototypeOf().Realm, Is.EqualTo(parentRealm));
                    That(v1.GetPrototypeOf().Realm, Is.EqualTo(RuntimeRealm.Current));

                    That(v0.GetPrototypeOf().GetPrototypeOf() != v1.GetPrototypeOf().GetPrototypeOf(), "all prototype ancestors of returned object should be different");

                    That(v0["MyMethod"], Is.TypeOf("function"));
                    That(v0["MyMethod"], Is.Not.EqualTo(v1["MyMethod"]), "property value of object type should be different");
                });
                RuntimeExecution.ContinueUntilEnd();
            });

            It("should expose native properties as getters and setters on protoype", () => {
                TestObject obj  = new TestObject();
                EcmaValue value = new EcmaValue(obj);
                value["Value"]  = 1;

                That(value["Value"], Is.EqualTo(1));
                That(obj.Value, Is.EqualTo(1), "Value should be reflected on native object");
                That(() => value["ReadOnlyValue"] = 2, Throws.Nothing, "Setting a readonly property does not throw exception");
                That(value["ReadOnlyValue"], Is.EqualTo(1), "Value should not be changed");

                RuntimeObject testObjectPrototype = value.ToObject().GetPrototypeOf();
                That(testObjectPrototype.GetOwnProperty("Value"), Is.Not.EqualTo(EcmaValue.Undefined), "Property should be defined on the reflected prototype object");
                That(testObjectPrototype.GetOwnProperty("Value").Get, Is.Not.EqualTo(EcmaValue.Undefined), "Property should be defined as getter/setter");
                That(testObjectPrototype.GetOwnProperty("ReadOnlyValue").Set, Is.Undefined, "Readonly property should have no setter");
            });

            It("should expose IList as an Array exotic object", () => {
                EcmaValue list = new EcmaValue(new List <object> {
                    1, 2, 3, new EcmaObject()
                });
                That(list["length"], Is.EqualTo(4));
                That(list.ToString(), Is.EqualTo("1,2,3,[object Object]"));
                That(Global.Json.Invoke("stringify", list), Is.EqualTo("[1,2,3,{}]"));
            });

            It("should expose IDictionary as an ordinary object for valid EcmaPropertyKey", () => {
                Hashtable ht  = new Hashtable();
                EcmaValue obj = new EcmaValue(ht);
                obj["prop"]   = 1;
                That(obj["prop"], Is.EqualTo(1));
                That(Global.Json.Invoke("stringify", obj), Is.EqualTo("{\"prop\":1}"));
            });
        }
Exemple #13
0
        public void Constructor(RuntimeFunction ctor)
        {
            IsConstructorWLength(ctor, "Date", 7, Date.Prototype);

            It("should get [[DateValue]] from Date objects without calling object's method", () => {
                EcmaValue date   = Date.Construct(1438560000000);
                date["toString"] = ThrowTest262Exception;
                date["valueOf"]  = ThrowTest262Exception;
                date["getTime"]  = ThrowTest262Exception;
                That(Date.Construct(date).Invoke("getTime"), Is.EqualTo(1438560000000));
            });

            It("should invoke @@toPrimitive and coerce returned value", () => {
                That(Date.Construct(CreateObject(toPrimitive: () => 8)).Invoke("getTime"), Is.EqualTo(8));
                That(Date.Construct(CreateObject(toPrimitive: () => Undefined)).Invoke("getTime"), Is.EqualTo(NaN));
                That(Date.Construct(CreateObject(toPrimitive: () => true)).Invoke("getTime"), Is.EqualTo(1));
                That(Date.Construct(CreateObject(toPrimitive: () => false)).Invoke("getTime"), Is.EqualTo(0));
                That(Date.Construct(CreateObject(toPrimitive: () => Null)).Invoke("getTime"), Is.EqualTo(0));
                That(Date.Construct(CreateObject(toPrimitive: () => "2016-06-05T18:40:00.000Z")).Invoke("getTime"), Is.EqualTo(1465152000000));

                That(() => Date.Construct(CreateObject(toPrimitive: () => new Symbol())), Throws.TypeError);
                That(() => Date.Construct(CreateObject(toPrimitive: () => new EcmaObject())), Throws.TypeError);
                That(() => Date.Construct(CreateObject(toPrimitive: () => new EcmaArray())), Throws.TypeError);
                That(() => Date.Construct(CreateObject(toPrimitive: ThrowTest262Exception)), Throws.Test262);
            });

            It("should coerce input value in the correct order", () => {
                Logs.Clear();
                Date.Construct(Undefined,
                               CreateObject(toString: Intercept(() => 0, "year")),
                               CreateObject(toString: Intercept(() => 0, "month")),
                               CreateObject(toString: Intercept(() => 0, "date")),
                               CreateObject(toString: Intercept(() => 0, "hours")),
                               CreateObject(toString: Intercept(() => 0, "minutes")),
                               CreateObject(toString: Intercept(() => 0, "seconds")),
                               CreateObject(toString: Intercept(() => 0, "ms")));
                CollectionAssert.AreEqual(new[] { "year", "month", "date", "hours", "minutes", "seconds", "ms" }, Logs);
            });

            It("should return a string representing the current time if Date is called as a function", () => {
                That(Date.Call(Date), Is.TypeOf("string"));
                That(Date.Call(Date, 1), Is.TypeOf("string"));
                That(Date.Call(Date, 1970, 1), Is.TypeOf("string"));
                That(Date.Call(Date, 1970, 1, 1), Is.TypeOf("string"));
                That(Date.Call(Date, 1970, 1, 1, 1), Is.TypeOf("string"));
                That(Date.Call(Date, 1970, 1, 1, 1, 0), Is.TypeOf("string"));
                That(Date.Call(Date, 1970, 1, 1, 1, 0, 0), Is.TypeOf("string"));
                That(Date.Call(Date, 1970, 1, 1, 1, 0, 0, 0), Is.TypeOf("string"));
                That(Date.Call(Date, NaN), Is.TypeOf("string"));
                That(Date.Call(Date, Infinity), Is.TypeOf("string"));
                That(Date.Call(Date, -Infinity), Is.TypeOf("string"));
                That(Date.Call(Date, Undefined), Is.TypeOf("string"));
                That(Date.Call(Date, Null), Is.TypeOf("string"));

                That(Date.Construct() - Date.Construct(Date.Call(Date)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, 1)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, 1970, 1)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, 1970, 1, 1)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, 1970, 1, 1, 1)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, 1970, 1, 1, 1, 0)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, 1970, 1, 1, 1, 0, 0)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, 1970, 1, 1, 1, 0, 0, 0)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, NaN)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, Infinity)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, -Infinity)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, Undefined)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
                That(Date.Construct() - Date.Construct(Date.Call(Date, Null)).Invoke("getTime"), Is.AtLeast(-1000).And.AtMost(1000));
            });

            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(WellKnownObject.DatePrototype)));
            });
        }