Exemple #1
0
        /// <summary>
        /// https://tc39.es/ecma262/#sec-getvaluefrombuffer
        /// </summary>
        internal TypedArrayValue GetValueFromBuffer(
            int byteIndex,
            TypedArrayElementType type,
            bool isTypedArray,
            ArrayBufferOrder order,
            bool?isLittleEndian = null)
        {
            if (!IsSharedArrayBuffer)
            {
                // If isLittleEndian is not present, set isLittleEndian to the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
                return(RawBytesToNumeric(type, byteIndex, isLittleEndian ?? BitConverter.IsLittleEndian));
            }

            /*
             *  Let execution be the [[CandidateExecution]] field of the surrounding agent's Agent EsprimaExtensions.Record.
             *  b. Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier().
             *  c. If isTypedArray is true and IsNoTearConfiguration(type, order) is true, let noTear be true; otherwise let noTear be false.
             *  d. Let rawValue be a List of length elementSize whose elements are nondeterministically chosen byte values.
             *  e. NOTE: In implementations, rawValue is the result of a non-atomic or atomic read instruction on the underlying hardware. The nondeterminism is a semantic prescription of the memory model to describe observable behaviour of hardware with weak consistency.
             *  f. Let readEvent be ReadSharedMemory { [[Order]]: order, [[NoTear]]: noTear, [[Block]]: block, [[ByteIndex]]: byteIndex, [[ElementSize]]: elementSize }.
             *  g. Append readEvent to eventList.
             *  h. Append Chosen Value EsprimaExtensions.Record { [[Event]]: readEvent, [[ChosenValue]]: rawValue } to execution.[[ChosenValues]].
             */
            ExceptionHelper.ThrowNotImplementedException("SharedArrayBuffer not implemented");
            return(default);
Exemple #2
0
        /// <summary>
        /// https://tc39.es/ecma262/#sec-getviewvalue
        /// </summary>
        private JsValue GetViewValue(
            JsValue view,
            JsValue requestIndex,
            JsValue isLittleEndian,
            TypedArrayElementType type)
        {
            var dataView = view as DataViewInstance;

            if (dataView is null)
            {
                ExceptionHelper.ThrowTypeError(_realm, "Method called on incompatible receiver " + view);
            }

            var getIndex = (int)TypeConverter.ToIndex(_realm, requestIndex);
            var isLittleEndianBoolean = TypeConverter.ToBoolean(isLittleEndian);
            var buffer = dataView._viewedArrayBuffer;

            buffer.AssertNotDetached();

            var viewOffset  = dataView._byteOffset;
            var viewSize    = dataView._byteLength;
            var elementSize = type.GetElementSize();

            if (getIndex + elementSize > viewSize)
            {
                ExceptionHelper.ThrowRangeError(_realm, "Offset is outside the bounds of the DataView");
            }

            var bufferIndex = (int)(getIndex + viewOffset);

            return(buffer.GetValueFromBuffer(bufferIndex, type, false, ArrayBufferOrder.Unordered, isLittleEndianBoolean).ToJsValue());
        }
 internal TypedArrayPrototype(
     Engine engine,
     IntrinsicTypedArrayPrototype objectPrototype,
     TypedArrayConstructor constructor,
     TypedArrayElementType type) : base(engine)
 {
     _prototype        = objectPrototype;
     _constructor      = constructor;
     _arrayElementType = type;
 }
        internal TypedArrayInstance(
            Engine engine,
            Intrinsics intrinsics,
            TypedArrayElementType type,
            uint length) : this(engine, intrinsics)
        {
            _arrayElementType = type;
            _arrayLength      = length;

            _contentType = type != TypedArrayElementType.BigInt64 && type != TypedArrayElementType.BigUint64
                ? TypedArrayContentType.Number
                : TypedArrayContentType.BigInt;
        }
        internal TypedArrayConstructor(
            Engine engine,
            Realm realm,
            IntrinsicTypedArrayConstructor functionPrototype,
            IntrinsicTypedArrayPrototype objectPrototype,
            TypedArrayElementType type) : base(engine, realm, new JsString(type.GetTypedArrayName()))
        {
            _arrayElementType = type;

            _prototype           = functionPrototype;
            PrototypeObject      = new TypedArrayPrototype(engine, objectPrototype, this, type);
            _length              = new PropertyDescriptor(JsNumber.PositiveThree, PropertyFlag.Configurable);
            _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
        }
 internal static byte GetElementSize(this TypedArrayElementType type)
 {
     return(type switch
     {
         TypedArrayElementType.Int8 => 1,
         TypedArrayElementType.Uint8 => 1,
         TypedArrayElementType.Uint8C => 1,
         TypedArrayElementType.Int16 => 2,
         TypedArrayElementType.Uint16 => 2,
         TypedArrayElementType.Int32 => 4,
         TypedArrayElementType.Uint32 => 4,
         TypedArrayElementType.BigInt64 => 8,
         TypedArrayElementType.BigUint64 => 8,
         TypedArrayElementType.Float32 => 4,
         TypedArrayElementType.Float64 => 8,
         _ => 0
     });