Пример #1
0
        public static EcmaValue Wait(TypedArray array, EcmaValue index, EcmaValue value, EcmaValue timeout)
        {
            int  pos       = ValidateWaitableArrayAndIndex(array, index);
            bool isInt32   = array.ArrayKind == TypedArrayKind.Int32Array;
            long longValue = isInt32 ? value.ToInt32() : value.ToBigInt64().ToInt64();

            timeout = timeout.ToNumber();
            if (!RuntimeExecution.Current.CanSuspend)
            {
                throw new EcmaTypeErrorException("Atomics.wait cannot be called in this context");
            }
            bool comparandEquals, result;
            int  milliseconds        = timeout.IsNaN || timeout > Int32.MaxValue ? -1 : timeout < 0 ? 0 : timeout.ToInt32();
            SharedArrayBuffer buffer = (SharedArrayBuffer)array.Buffer;

            if (isInt32)
            {
                result = buffer.Wait(array.GetByteOffset(pos), (int)longValue, milliseconds, out comparandEquals);
            }
            else
            {
                result = buffer.Wait(array.GetByteOffset(pos), longValue, milliseconds, out comparandEquals);
            }
            return(result ? "ok" : comparandEquals ? "timed-out" : "not-equal");
        }