public void For(RuntimeFunction @for) { IsUnconstructableFunctionWLength(@for, "for", 1); It("should return same symbol using Symbol.for", () => { EcmaValue canonical = @for.Call(_, "s"); Case((_, "s"), canonical); That(Symbol.Call(_, "s"), Is.Not.EqualTo(canonical)); That(Symbol.Call(_, "s"), Is.Not.EqualTo(@for.Call(_, "y"))); });
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); }); }
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))); }); } }
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))); }); }
public void Catch(RuntimeFunction @catch) { IsUnconstructableFunctionWLength(@catch, "catch", 1); IsAbruptedFromToObject(@catch); That(Promise.Prototype, Has.OwnProperty("catch", @catch, EcmaPropertyAttributes.DefaultMethodProperty)); It("should invoke then method", () => { EcmaValue target = new EcmaObject(); EcmaValue returnValue = new EcmaObject(); EcmaValue thisValue = Null; EcmaValue args = Null; target["then"] = Intercept((a, b) => { thisValue = This; args = Arguments; return(returnValue); }); Case((target, 1, 2, 3), returnValue, "Returns the result of the invocation of `then`"); That(Logs.Count, Is.EqualTo(1), "Invokes `then` method exactly once"); That(thisValue, Is.EqualTo(target), "Invokes `then` method with the instance as the `this` value"); That(args, Is.EquivalentTo(new[] { Undefined, 1 })); using (TempProperty(Boolean.Prototype, "then", Intercept(_ => _))) { Logs.Clear(); @catch.Call(true); That(Logs.Count, Is.EqualTo(1)); } using (TempProperty(Number.Prototype, "then", Intercept(_ => _))) { Logs.Clear(); @catch.Call(34); That(Logs.Count, Is.EqualTo(1)); } using (TempProperty(String.Prototype, "then", Intercept(_ => _))) { Logs.Clear(); @catch.Call(""); That(Logs.Count, Is.EqualTo(1)); } using (TempProperty(Global.Symbol.Prototype, "then", Intercept(_ => _))) { Logs.Clear(); @catch.Call(new Symbol()); That(Logs.Count, Is.EqualTo(1)); } });
public void Parse(RuntimeFunction parse) { IsUnconstructableFunctionWLength(parse, "parse", 1); It("should return value limited to specified time value maximum range", () => { EcmaValue minDateStr = "-271821-04-20T00:00:00.000Z"; EcmaValue minDate = Date.Construct(-8640000000000000); That(minDate.Invoke("toISOString"), Is.EqualTo(minDateStr), "minDateStr"); That(parse.Call(_, minDateStr), Is.EqualTo(minDate.Invoke("valueOf")), "parse minDateStr"); EcmaValue maxDateStr = "+275760-09-13T00:00:00.000Z"; EcmaValue maxDate = Date.Construct(8640000000000000); That(maxDate.Invoke("toISOString"), Is.EqualTo(maxDateStr), "maxDateStr"); That(parse.Call(_, maxDateStr), Is.EqualTo(maxDate.Invoke("valueOf")), "parse maxDateStr"); EcmaValue belowRange = "-271821-04-19T23:59:59.999Z"; EcmaValue aboveRange = "+275760-09-13T00:00:00.001Z"; Case((_, belowRange), NaN, "parse below minimum time value"); Case((_, aboveRange), NaN, "parse above maximum time value"); });
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)); } }
public void Revocable(RuntimeFunction revocable) { IsUnconstructableFunctionWLength(revocable, "revocable", 2); That(Proxy, Has.OwnProperty("revocable", revocable, EcmaPropertyAttributes.DefaultMethodProperty)); It("The returned object has a proxy property which is the created Proxy object built with the given target and handler given parameters", () => { EcmaValue target = CreateObject(new { attr = "foo" }); EcmaValue r = revocable.Call(_, target, CreateObject(new { get = FunctionLiteral((t, prop) => t[prop] + "!") })); That(r["proxy"]["attr"], Is.EqualTo("foo!")); }); It("The property of Proxy Revocation functions", () => { EcmaValue revocationFunction = revocable.Call(_, Object.Construct(), Object.Construct())["revoke"]; IsUnconstructableFunctionWLength(revocationFunction, null, 0); That(Object.Invoke("isExtensible", revocationFunction), Is.EqualTo(true)); EcmaValue r = revocable.Call(_, Object.Construct(), Object.Construct()); That(r.Invoke("revoke"), Is.Undefined); That(r.Invoke("revoke"), Is.Undefined); }); }
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"); }
public void Floor(RuntimeFunction floor) { IsUnconstructableFunctionWLength(floor, "floor", 1); Case((_, NaN), NaN); Case((_, -Infinity), -Infinity); Case((_, Infinity), Infinity); Case((_, -0d), -0d); Case((_, 0), 0); Case((_, 0.000000000000001), -0, "-0.000000000000001"); Case((_, 0.999999999999999), -0, "-0.999999999999999"); Case((_, 0.5), -0, "-0.5"); for (double i = -1000; i < 1000; i++) { double x = i / 10.0; That(floor.Call(_, x) == -Math.Invoke("ceil", -x), x.ToString()); } }
public void Constructor(RuntimeFunction ctor) { IsConstructorWLength(Symbol, "Symbol", 0, Symbol.Prototype); That(GlobalThis, Has.OwnProperty("Symbol", Symbol, EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable)); It("should return a unique value", () => { That(ctor.Call(_), Is.Not.EqualTo(ctor.Call(_))); That(ctor.Call(_, ""), Is.Not.EqualTo(ctor.Call(_, ""))); That(ctor.Call(_, "x"), Is.Not.EqualTo(ctor.Call(_, "x"))); That(ctor.Call(_, Null), Is.Not.EqualTo(ctor.Call(_, Null))); }); It("should coerce first argument to a string value", () => { That(() => ctor.Call(_, ctor.Call(_, "1")), Throws.TypeError); Logs.Clear(); ctor.Call(_, CreateObject(toString: Intercept(() => Object.Construct(), "toString"), valueOf: Intercept(() => Undefined, "valueOf"))); That(Logs, Is.EquivalentTo(new[] { "toString", "valueOf" })); Logs.Clear(); ctor.Call(_, CreateObject(toString: Intercept(() => Undefined, "toString"), valueOf: Intercept(() => Undefined, "valueOf"))); That(Logs, Is.EquivalentTo(new[] { "toString" })); Logs.Clear(); ctor.Call(_, CreateObject(new { toString = Null, valueOf = Intercept(() => Undefined, "valueOf") })); That(Logs, Is.EquivalentTo(new[] { "valueOf" })); Logs.Clear(); That(() => ctor.Call(_, CreateObject(new { toString = Null, valueOf = Intercept(() => Object.Construct(), "valueOf") })), Throws.TypeError); That(Logs, Is.EquivalentTo(new[] { "valueOf" })); Logs.Clear(); That(() => ctor.Call(_, CreateObject(toString: Intercept(() => Object.Construct(), "toString"), valueOf: Intercept(() => Object.Construct(), "valueOf"))), Throws.TypeError); That(Logs, Is.EquivalentTo(new[] { "toString", "valueOf" })); }); It("should not be invoked with new", () => { That(() => ctor.Construct(), Throws.TypeError); That(() => ctor.Construct(""), Throws.TypeError); }); }
public void Slice(RuntimeFunction slice) { IsUnconstructableFunctionWLength(slice, "slice", 2); That(SharedArrayBuffer.Prototype, Has.OwnProperty("slice", slice, EcmaPropertyAttributes.DefaultMethodProperty)); 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 exception when `this` does not have a [[ArrayBufferData]]", () => { Case(SharedArrayBuffer.Prototype, Throws.TypeError); Case(Object.Construct(), Throws.TypeError); Case(EcmaArray.Of(), Throws.TypeError); Case(Global.Int8Array.Construct(8), Throws.TypeError); Case(Global.DataView.Construct(SharedArrayBuffer.Construct(8), 0), Throws.TypeError); }); It("should throw a TypeError if `this` is a ArrayBuffer", () => { Case(Global.ArrayBuffer.Construct(0), Throws.TypeError); }); It("should default the `start` index to 0 if absent", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer)["byteLength"], Is.EqualTo(8)); That(slice.Call(arrayBuffer, Undefined, 6)["byteLength"], Is.EqualTo(6)); }); It("should return zero-length buffer if `start` index exceeds `end` index", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, 5, 4)["byteLength"], Is.EqualTo(0)); }); It("should clamp large `start` index to [[ArrayBufferByteLength]]", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, 10, 8)["byteLength"], Is.EqualTo(0)); That(slice.Call(arrayBuffer, 0x100000000, 7)["byteLength"], Is.EqualTo(0)); That(slice.Call(arrayBuffer, Infinity, 6)["byteLength"], Is.EqualTo(0)); }); It("should normalize negative `start` index relative to [[ArrayBufferByteLength]]", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, -5, 6)["byteLength"], Is.EqualTo(3)); That(slice.Call(arrayBuffer, -12, 6)["byteLength"], Is.EqualTo(6)); That(slice.Call(arrayBuffer, -Infinity, 6)["byteLength"], Is.EqualTo(6)); }); It("should convert the `start` index parameter to an integral numeric value", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, 4.5, 8)["byteLength"], Is.EqualTo(4)); That(slice.Call(arrayBuffer, NaN, 8)["byteLength"], Is.EqualTo(8)); }); It("should default the `end` index to [[ArrayBufferByteLength]] if absent", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, 6)["byteLength"], Is.EqualTo(2)); That(slice.Call(arrayBuffer, 6, Undefined)["byteLength"], Is.EqualTo(2)); }); It("should clamp large `end` index to [[ArrayBufferByteLength]]", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, 1, 12)["byteLength"], Is.EqualTo(7)); That(slice.Call(arrayBuffer, 2, 0x100000000)["byteLength"], Is.EqualTo(6)); That(slice.Call(arrayBuffer, 3, Infinity)["byteLength"], Is.EqualTo(5)); }); It("should normalize negative `end` index relative to [[ArrayBufferByteLength]]", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, 2, -4)["byteLength"], Is.EqualTo(2)); That(slice.Call(arrayBuffer, 2, -10)["byteLength"], Is.EqualTo(0)); That(slice.Call(arrayBuffer, 2, -Infinity)["byteLength"], Is.EqualTo(0)); }); It("should convert the `end` index parameter to an integral numeric value", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); That(slice.Call(arrayBuffer, 0, 4.5)["byteLength"], Is.EqualTo(4)); That(slice.Call(arrayBuffer, 0, NaN)["byteLength"], Is.EqualTo(0)); }); It("should convert start and end index in correct order", () => { slice.Call(SharedArrayBuffer.Construct(8), CreateObject(new { valueOf = Intercept(() => 0, "start") }), CreateObject(new { valueOf = Intercept(() => 0, "end") })); That(Logs, Is.EquivalentTo(new[] { "start", "end" })); }); It("should throw a TypeError if `constructor` property is not an object", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); Case(Object.Invoke("assign", arrayBuffer, CreateObject(new { constructor = Null })), Throws.TypeError); Case(Object.Invoke("assign", arrayBuffer, CreateObject(new { constructor = true })), Throws.TypeError); Case(Object.Invoke("assign", arrayBuffer, CreateObject(new { constructor = "" })), Throws.TypeError); Case(Object.Invoke("assign", arrayBuffer, CreateObject(new { constructor = 1 })), Throws.TypeError); Case(Object.Invoke("assign", arrayBuffer, CreateObject(new { constructor = new Symbol() })), Throws.TypeError); }); It("should throw a TypeError if species constructor is not a constructor", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); EcmaValue speciesConstructor = Object.Construct(); arrayBuffer["constructor"] = speciesConstructor; speciesConstructor[Symbol.Species] = Object.Construct(); Case(arrayBuffer, Throws.TypeError); speciesConstructor[Symbol.Species] = Function.Prototype; Case(arrayBuffer, Throws.TypeError); }); It("should throw a TypeError if species constructor is not an object", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); EcmaValue speciesConstructor = Object.Construct(); arrayBuffer["constructor"] = speciesConstructor; speciesConstructor[Symbol.Species] = true; Case(arrayBuffer, Throws.TypeError); speciesConstructor[Symbol.Species] = ""; Case(arrayBuffer, Throws.TypeError); speciesConstructor[Symbol.Species] = 1; Case(arrayBuffer, Throws.TypeError); speciesConstructor[Symbol.Species] = new Symbol(); Case(arrayBuffer, Throws.TypeError); }); It("should use default constructor is `constructor` property is undefined", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); arrayBuffer["constructor"] = Undefined; That(Object.Invoke("getPrototypeOf", slice.Call(arrayBuffer)), Is.EqualTo(SharedArrayBuffer.Prototype)); }); It("should use default constructor if species constructor is null or undefined", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); EcmaValue speciesConstructor = Object.Construct(); arrayBuffer["constructor"] = speciesConstructor; speciesConstructor[Symbol.Species] = Null; That(Object.Invoke("getPrototypeOf", slice.Call(arrayBuffer)), Is.EqualTo(SharedArrayBuffer.Prototype)); speciesConstructor[Symbol.Species] = Undefined; That(Object.Invoke("getPrototypeOf", slice.Call(arrayBuffer)), Is.EqualTo(SharedArrayBuffer.Prototype)); }); It("does not throw TypeError if new SharedArrayBuffer is too large", () => { EcmaValue speciesConstructor = Object.Construct(); speciesConstructor[Symbol.Species] = FunctionLiteral((length) => { return(SharedArrayBuffer.Construct(10)); }); EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); arrayBuffer["constructor"] = speciesConstructor; That(slice.Call(arrayBuffer)["byteLength"], Is.EqualTo(10)); }); It("should throw a TypeError if new SharedArrayBuffer is too small", () => { EcmaValue speciesConstructor = Object.Construct(); speciesConstructor[Symbol.Species] = FunctionLiteral((length) => { return(SharedArrayBuffer.Construct(4)); }); EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); arrayBuffer["constructor"] = speciesConstructor; Case(arrayBuffer, Throws.TypeError); }); It("should throw a TypeError if new object is not an SharedArrayBuffer instance", () => { EcmaValue speciesConstructor = Object.Construct(); speciesConstructor[Symbol.Species] = FunctionLiteral((length) => { return(Object.Construct()); }); EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); arrayBuffer["constructor"] = speciesConstructor; Case(arrayBuffer, Throws.TypeError); }); It("should throw a TypeError if species constructor returns `this` value", () => { EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); EcmaValue speciesConstructor = Object.Construct(); speciesConstructor[Symbol.Species] = FunctionLiteral((length) => { return(arrayBuffer); }); arrayBuffer["constructor"] = speciesConstructor; Case(arrayBuffer, Throws.TypeError); }); It("should create new SharedArrayBuffer instance from SpeciesConstructor", () => { EcmaValue resultBuffer = default; EcmaValue speciesConstructor = Object.Construct(); speciesConstructor[Symbol.Species] = FunctionLiteral((length) => { return(resultBuffer = SharedArrayBuffer.Construct(length)); }); EcmaValue arrayBuffer = SharedArrayBuffer.Construct(8); arrayBuffer["constructor"] = speciesConstructor; EcmaValue result = slice.Call(arrayBuffer); That(result, Is.EqualTo(resultBuffer)); }); }
public void Now(RuntimeFunction now) { IsUnconstructableFunctionWLength(now, "now", 0); That(now.Call(), Is.TypeOf("number")); }