private ScriptValue IntegerIndexedElementGet(double index) { //https://tc39.github.io/ecma262/#sec-integerindexedelementget var buffer = ViewedArrayBuffer; if (ArrayBufferIntrinsics.IsDetachedBuffer(buffer)) { throw Agent.CreateTypeError(); } if (!Agent.IsInteger(index)) { return(ScriptValue.Undefined); } if (index == 0 && index.IsNegative()) { return(ScriptValue.Undefined); } var length = ArrayLength; if (index < 0 || index >= length) { return(ScriptValue.Undefined); } var indexedPosition = (long)index * Description.Size + ByteOffset; return(ArrayBufferIntrinsics.GetValueFromBuffer(Agent, buffer, indexedPosition, Description, true, OrderType.Unordered, Agent.LittleEndian)); }
private bool IntegerIndexedElementSet(double index, ScriptValue value) { //https://tc39.github.io/ecma262/#sec-integerindexedelementset var numberValue = Agent.ToNumber(value); var buffer = ViewedArrayBuffer; if (ArrayBufferIntrinsics.IsDetachedBuffer(buffer)) { throw Agent.CreateTypeError(); } if (!Agent.IsInteger(index)) { return(false); } if (index == 0 && index.IsNegative()) { return(false); } var length = ArrayLength; if (index < 0 || index >= length) { return(false); } var indexedPosition = (long)index * Description.Size + ByteOffset; ArrayBufferIntrinsics.SetValueInBuffer(Agent, buffer, indexedPosition, Description, numberValue, true, OrderType.Unordered, Agent.LittleEndian); return(true); }
/// <inheritdoc /> public override bool HasProperty(ScriptValue property) { //https://tc39.github.io/ecma262/#sec-integer-indexed-exotic-objects-hasproperty-p Debug.Assert(Agent.IsPropertyKey(property)); if (property.IsString) { var numericIndex = Agent.CanonicalNumericIndexString((string)property); if (numericIndex.HasValue) { var buffer = ViewedArrayBuffer; if (ArrayBufferIntrinsics.IsDetachedBuffer(buffer)) { throw Agent.CreateTypeError(); } if (!Agent.IsInteger(numericIndex.Value)) { return(false); } if (numericIndex.Value.IsNegative()) { return(false); } if (numericIndex.Value >= ArrayLength) { return(false); } return(true); } } return(base.HasProperty(property)); }
internal Realm([NotNull] Agent agent, string name) { this.name = name; Agent = agent; //https://tc39.github.io/ecma262/#sec-createrealm //https://tc39.github.io/ecma262/#sec-createintrinsics ObjectPrototype = Agent.ObjectCreate(this, null); ThrowTypeError = Agent.CreateBuiltinFunction(this, arguments => throw arguments.Agent.CreateTypeError(), null); FunctionPrototype = Agent.CreateBuiltinFunction(this, arguments => ScriptValue.Undefined, ObjectPrototype); ThrowTypeError.SetPrototypeOf(FunctionPrototype); AddRestrictedFunctionProperties(FunctionPrototype); IteratorPrototype = IteratorIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); (Array, ArrayPrototype, ArrayIteratorPrototype, ArrayProtoEntries, ArrayProtoForEach, ArrayProtoKeys, ArrayProtoValues) = ArrayIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); (ArrayBuffer, ArrayBufferPrototype) = ArrayBufferIntrinsics.Initialise(agent, this); (AsyncFunction, AsyncFunctionPrototype) = AsyncFunctionIntrinsics.Initialise(agent, this); Atomics = AtomicsIntrinsics.Initialise(agent, this); (Boolean, BooleanPrototype) = BooleanIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); (DataView, DataViewPrototype) = DataViewIntrinsics.Initialise(agent, this); (Date, DatePrototype) = DateIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); DecodeURI = Intrinsics.CreateBuiltinFunction(this, DecodeURIImplementation, FunctionPrototype, 1, "decodeURI"); DecodeURIComponent = Intrinsics.CreateBuiltinFunction(this, DecodeURIComponentImplementation, FunctionPrototype, 1, "decodeURIComponent"); EncodeURI = Intrinsics.CreateBuiltinFunction(this, EncodeURIImplementation, FunctionPrototype, 1, "encodeURI"); EncodeURIComponent = Intrinsics.CreateBuiltinFunction(this, EncodeURIComponentImplementation, FunctionPrototype, 1, "encodeURIComponent"); (Error, ErrorPrototype) = ErrorIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); Eval = Intrinsics.CreateBuiltinFunction(this, EvalImplementation, FunctionPrototype, 1, "eval"); (EvalError, EvalErrorPrototype) = ErrorIntrinsics.InitialiseNativeError(agent, "EvalError", this, Error, ErrorPrototype); Function = FunctionIntrinsics.Initialise(this, FunctionPrototype); (Generator, GeneratorPrototype, GeneratorFunction) = GeneratorInstrinsics.Initialise(agent, this, FunctionPrototype); IsFinite = Intrinsics.CreateBuiltinFunction(this, IsFiniteImplementation, FunctionPrototype, 1, "isFinite"); IsNaN = Intrinsics.CreateBuiltinFunction(this, IsNaNImplementation, FunctionPrototype, 1, "isNaN"); (Json, JsonParse) = JsonIntrinsics.Initialise(agent, this); (Map, MapPrototype, MapIteratorPrototype) = MapIntrinsics.Initialise(agent, this); Math = MathsIntrinsics.Initialise(agent, this); (Number, NumberPrototype) = NumberIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); (ObjectConstructor, ObjProtoToString, ObjProtoValueOf) = ObjectIntrinsics.Initialise(this, ObjectPrototype, FunctionPrototype); ParseFloat = Intrinsics.CreateBuiltinFunction(this, ParseFloatImplementation, FunctionPrototype, 1, "parseFloat"); ParseInt = Intrinsics.CreateBuiltinFunction(this, ParseIntImplementation, FunctionPrototype, 2, "parseInt"); (Promise, PromisePrototype, PromiseProtoThen, PromiseAll, PromiseReject, PromiseResolve) = PromiseIntrinsics.Initialise(agent, this); Proxy = ProxyIntrinsics.Initialise(this); (RangeError, RangeErrorPrototype) = ErrorIntrinsics.InitialiseNativeError(agent, "RangeError", this, Error, ErrorPrototype); (ReferenceError, ReferenceErrorPrototype) = ErrorIntrinsics.InitialiseNativeError(agent, "ReferenceError", this, Error, ErrorPrototype); Reflect = ReflectIntrinsics.Initialise(agent, this); (RegExp, RegExpPrototype) = RegExpIntrinsics.Initialise(agent, this); (Set, SetPrototype, SetIteratorPrototype) = SetIntrinsics.Initialise(agent, this); (SharedArrayBuffer, SharedArrayBufferPrototype) = SharedArrayBufferIntrinsics.Initialise(agent, this); (StringConstructor, StringIteratorPrototype, StringPrototype) = StringIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); (Symbol, SymbolPrototype) = SymbolIntrinsics.Initialise(agent, this, ObjectPrototype, FunctionPrototype); (SyntaxError, SyntaxErrorPrototype) = ErrorIntrinsics.InitialiseNativeError(agent, "SyntaxError", this, Error, ErrorPrototype); (TypeError, TypeErrorPrototype) = ErrorIntrinsics.InitialiseNativeError(agent, "TypeError", this, Error, ErrorPrototype); (TypedArray, TypedArrayPrototype) = TypedArrayIntrinsics.Initialise(agent, this); (UriError, UriErrorPrototype) = ErrorIntrinsics.InitialiseNativeError(agent, "UriError", this, Error, ErrorPrototype); (WeakMap, WeakMapPrototype) = WeakMapIntrinsics.Initialise(agent, this); (WeakSet, WeakSetPrototype) = WeakSetIntrinsics.Initialise(agent, this); (Float32Array, Float32ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <float>(agent, this); (Float64Array, Float64ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <double>(agent, this); (Int8Array, Int8ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <sbyte>(agent, this); (Int16Array, Int16ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <short>(agent, this); (Int32Array, Int32ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <int>(agent, this); (Uint8Array, Uint8ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <byte>(agent, this); (Uint8ClampedArray, Uint8ClampedArrayPrototype) = TypedArrayIntrinsics.InitialiseType <byte>(agent, this, true); (Uint16Array, Uint16ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <ushort>(agent, this); (Uint32Array, Uint32ArrayPrototype) = TypedArrayIntrinsics.InitialiseType <uint>(agent, this); }