Esempio n. 1
0
        public static PromiseCapability CreateFromConstructor(RuntimeObject constructor)
        {
            Guard.ArgumentNotNull(constructor, "constructor");
            PromiseCapability capability = new PromiseCapability();

            capability.Promise = constructor.Construct((Action <EcmaValue, EcmaValue>)capability.Executor);
            capability.EnsureValidResolver();
            return(capability);
        }
Esempio n. 2
0
        public ArrayBuffer Slice(long start, long end)
        {
            ThrowIfBufferDetached();

            long thisLength = buffer.Buffer.Length;

            start = start < 0 ? Math.Max(thisLength + start, 0) : Math.Min(start, thisLength);
            end   = end < 0 ? Math.Max(thisLength + end, 0) : Math.Min(end, thisLength);

            long          newLength   = Math.Max(end - start, 0);
            RuntimeObject constructor = GetSpeciesConstructor(this, this.IsShared ? WellKnownObject.SharedArrayBuffer : WellKnownObject.ArrayBuffer);
            ArrayBuffer   other       = constructor.Construct(newLength).GetUnderlyingObject <ArrayBuffer>();

            if (other == this)
            {
                throw new EcmaTypeErrorException(InternalString.Error.BufferSubClassReturnThis, this.GetType().Name);
            }
            if (other.IsShared != this.IsShared)
            {
                throw new EcmaTypeErrorException(InternalString.Error.BufferIncompatible, this.GetType().Name);
            }
            CopyBytes(this, start, other, 0, newLength);
            return(other);
        }
Esempio n. 3
0
        public static TypedArray SpeciesCreate(TypedArray source, params EcmaValue[] args)
        {
            RuntimeObject constructor = RuntimeObject.GetSpeciesConstructor(source, TypedArrayInfo.GetDefaultConstructor(source.ArrayKind));

            return(constructor.Construct(args).GetUnderlyingObject <TypedArray>());
        }