Skip to content

Commit 578826c

Browse files
committed
Adds definitions for the es2017 Atomics global object
1 parent 8491ad9 commit 578826c

File tree

2 files changed

+120
-21
lines changed

2 files changed

+120
-21
lines changed

src/lib/es2017.sharedmemory.d.ts

+92-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,96 @@ interface SharedArrayBufferConstructor {
2323
readonly prototype: SharedArrayBuffer;
2424
new (byteLength: number): SharedArrayBuffer;
2525
}
26+
declare var SharedArrayBuffer: SharedArrayBufferConstructor;
2627

27-
declare var SharedArrayBuffer: SharedArrayBufferConstructor;
28+
interface ArrayBufferTypes {
29+
SharedArrayBuffer: SharedArrayBuffer;
30+
}
31+
32+
interface Atomics {
33+
/**
34+
* Adds a value to the value at the given position in the array, returning the original value.
35+
* Until this atomic operation completes, any other read or write operation against the array
36+
* will block.
37+
*/
38+
add(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
39+
40+
/**
41+
* Stores the bitwise AND of a value with the value at the given position in the array,
42+
* returning the original value. Until this atomic operation completes, any other read or
43+
* write operation against the array will block.
44+
*/
45+
and(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
46+
47+
/**
48+
* Replaces the value at the given position in the array if the original value equals the given
49+
* expected value, returning the original value. Until this atomic operation completes, any
50+
* other read or write operation against the array will block.
51+
*/
52+
compareExchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, expectedValue: number, replacementValue: number): number;
53+
54+
/**
55+
* Replaces the value at the given position in the array, returning the original value. Until
56+
* this atomic operation completes, any other read or write operation against the array will
57+
* block.
58+
*/
59+
exchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
60+
61+
/**
62+
* Returns a value indicating whether high-performance algorithms can use atomic operations
63+
* (`true`) or must use locks (`false`) for the given number of bytes-per-element of a typed
64+
* array.
65+
*/
66+
isLockFree(size: number): boolean;
67+
68+
/**
69+
* Returns the value at the given position in the array. Until this atomic operation completes,
70+
* any other read or write operation against the array will block.
71+
*/
72+
load(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number): number;
73+
74+
/**
75+
* Stores the bitwise OR of a value with the value at the given position in the array,
76+
* returning the original value. Until this atomic operation completes, any other read or write
77+
* operation against the array will block.
78+
*/
79+
or(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
80+
81+
/**
82+
* Stores a value at the given position in the array, returning the new value. Until this
83+
* atomic operation completes, any other read or write operation against the array will block.
84+
*/
85+
store(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
86+
87+
/**
88+
* Subtracts a value from the value at the given position in the array, returning the original
89+
* value. Until this atomic operation completes, any other read or write operation against the
90+
* array will block.
91+
*/
92+
sub(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
93+
94+
/**
95+
* If the value at the given position in the array is equal to the provided value, the current
96+
* agent is put to sleep causing execution to suspend until the timeout expires (returning
97+
* `"timed-out"`) or until the agent is awoken (returning `"ok"`); otherwise, returns
98+
* `"not-equal"`.
99+
*/
100+
wait(typedArray: Int32Array, index: number, value: number, timeout?: number): "ok" | "not-equal" | "timed-out";
101+
102+
/**
103+
* Wakes up sleeping agents that are waiting on the given index of the array, returning the
104+
* number of agents that were awoken.
105+
*/
106+
wake(typedArray: Int32Array, index: number, count: number): number;
107+
108+
/**
109+
* Stores the bitwise XOR of a value with the value at the given position in the array,
110+
* returning the original value. Until this atomic operation completes, any other read or write
111+
* operation against the array will block.
112+
*/
113+
xor(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
114+
115+
readonly [Symbol.toStringTag]: "Atomics";
116+
}
117+
118+
declare var Atomics: Atomics;

src/lib/es5.d.ts

+28-20
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,14 @@ interface ArrayBuffer {
13861386
slice(begin: number, end?: number): ArrayBuffer;
13871387
}
13881388

1389+
/**
1390+
* Allowed ArrayBuffer types for the buffer of an ArrayBufferView and related Typed Arrays.
1391+
*/
1392+
interface ArrayBufferTypes {
1393+
ArrayBuffer: ArrayBuffer;
1394+
}
1395+
type ArrayBufferLike = ArrayBufferTypes[keyof ArrayBufferTypes];
1396+
13891397
interface ArrayBufferConstructor {
13901398
readonly prototype: ArrayBuffer;
13911399
new (byteLength: number): ArrayBuffer;
@@ -1397,7 +1405,7 @@ interface ArrayBufferView {
13971405
/**
13981406
* The ArrayBuffer instance referenced by the array.
13991407
*/
1400-
buffer: ArrayBuffer;
1408+
buffer: ArrayBufferLike;
14011409

14021410
/**
14031411
* The length in bytes of the array.
@@ -1539,7 +1547,7 @@ interface DataView {
15391547
}
15401548

15411549
interface DataViewConstructor {
1542-
new (buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): DataView;
1550+
new (buffer: ArrayBufferLike, byteOffset?: number, byteLength?: number): DataView;
15431551
}
15441552
declare const DataView: DataViewConstructor;
15451553

@@ -1556,7 +1564,7 @@ interface Int8Array {
15561564
/**
15571565
* The ArrayBuffer instance referenced by the array.
15581566
*/
1559-
readonly buffer: ArrayBuffer;
1567+
readonly buffer: ArrayBufferLike;
15601568

15611569
/**
15621570
* The length in bytes of the array.
@@ -1799,7 +1807,7 @@ interface Int8ArrayConstructor {
17991807
readonly prototype: Int8Array;
18001808
new (length: number): Int8Array;
18011809
new (array: ArrayLike<number>): Int8Array;
1802-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int8Array;
1810+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Int8Array;
18031811

18041812
/**
18051813
* The size in bytes of each element in the array.
@@ -1840,7 +1848,7 @@ interface Uint8Array {
18401848
/**
18411849
* The ArrayBuffer instance referenced by the array.
18421850
*/
1843-
readonly buffer: ArrayBuffer;
1851+
readonly buffer: ArrayBufferLike;
18441852

18451853
/**
18461854
* The length in bytes of the array.
@@ -2084,7 +2092,7 @@ interface Uint8ArrayConstructor {
20842092
readonly prototype: Uint8Array;
20852093
new (length: number): Uint8Array;
20862094
new (array: ArrayLike<number>): Uint8Array;
2087-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8Array;
2095+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint8Array;
20882096

20892097
/**
20902098
* The size in bytes of each element in the array.
@@ -2125,7 +2133,7 @@ interface Uint8ClampedArray {
21252133
/**
21262134
* The ArrayBuffer instance referenced by the array.
21272135
*/
2128-
readonly buffer: ArrayBuffer;
2136+
readonly buffer: ArrayBufferLike;
21292137

21302138
/**
21312139
* The length in bytes of the array.
@@ -2369,7 +2377,7 @@ interface Uint8ClampedArrayConstructor {
23692377
readonly prototype: Uint8ClampedArray;
23702378
new (length: number): Uint8ClampedArray;
23712379
new (array: ArrayLike<number>): Uint8ClampedArray;
2372-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8ClampedArray;
2380+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint8ClampedArray;
23732381

23742382
/**
23752383
* The size in bytes of each element in the array.
@@ -2409,7 +2417,7 @@ interface Int16Array {
24092417
/**
24102418
* The ArrayBuffer instance referenced by the array.
24112419
*/
2412-
readonly buffer: ArrayBuffer;
2420+
readonly buffer: ArrayBufferLike;
24132421

24142422
/**
24152423
* The length in bytes of the array.
@@ -2653,7 +2661,7 @@ interface Int16ArrayConstructor {
26532661
readonly prototype: Int16Array;
26542662
new (length: number): Int16Array;
26552663
new (array: ArrayLike<number>): Int16Array;
2656-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int16Array;
2664+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Int16Array;
26572665

26582666
/**
26592667
* The size in bytes of each element in the array.
@@ -2694,7 +2702,7 @@ interface Uint16Array {
26942702
/**
26952703
* The ArrayBuffer instance referenced by the array.
26962704
*/
2697-
readonly buffer: ArrayBuffer;
2705+
readonly buffer: ArrayBufferLike;
26982706

26992707
/**
27002708
* The length in bytes of the array.
@@ -2938,7 +2946,7 @@ interface Uint16ArrayConstructor {
29382946
readonly prototype: Uint16Array;
29392947
new (length: number): Uint16Array;
29402948
new (array: ArrayLike<number>): Uint16Array;
2941-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint16Array;
2949+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint16Array;
29422950

29432951
/**
29442952
* The size in bytes of each element in the array.
@@ -2978,7 +2986,7 @@ interface Int32Array {
29782986
/**
29792987
* The ArrayBuffer instance referenced by the array.
29802988
*/
2981-
readonly buffer: ArrayBuffer;
2989+
readonly buffer: ArrayBufferLike;
29822990

29832991
/**
29842992
* The length in bytes of the array.
@@ -3222,7 +3230,7 @@ interface Int32ArrayConstructor {
32223230
readonly prototype: Int32Array;
32233231
new (length: number): Int32Array;
32243232
new (array: ArrayLike<number>): Int32Array;
3225-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int32Array;
3233+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Int32Array;
32263234

32273235
/**
32283236
* The size in bytes of each element in the array.
@@ -3262,7 +3270,7 @@ interface Uint32Array {
32623270
/**
32633271
* The ArrayBuffer instance referenced by the array.
32643272
*/
3265-
readonly buffer: ArrayBuffer;
3273+
readonly buffer: ArrayBufferLike;
32663274

32673275
/**
32683276
* The length in bytes of the array.
@@ -3506,7 +3514,7 @@ interface Uint32ArrayConstructor {
35063514
readonly prototype: Uint32Array;
35073515
new (length: number): Uint32Array;
35083516
new (array: ArrayLike<number>): Uint32Array;
3509-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint32Array;
3517+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint32Array;
35103518

35113519
/**
35123520
* The size in bytes of each element in the array.
@@ -3546,7 +3554,7 @@ interface Float32Array {
35463554
/**
35473555
* The ArrayBuffer instance referenced by the array.
35483556
*/
3549-
readonly buffer: ArrayBuffer;
3557+
readonly buffer: ArrayBufferLike;
35503558

35513559
/**
35523560
* The length in bytes of the array.
@@ -3790,7 +3798,7 @@ interface Float32ArrayConstructor {
37903798
readonly prototype: Float32Array;
37913799
new (length: number): Float32Array;
37923800
new (array: ArrayLike<number>): Float32Array;
3793-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float32Array;
3801+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Float32Array;
37943802

37953803
/**
37963804
* The size in bytes of each element in the array.
@@ -3831,7 +3839,7 @@ interface Float64Array {
38313839
/**
38323840
* The ArrayBuffer instance referenced by the array.
38333841
*/
3834-
readonly buffer: ArrayBuffer;
3842+
readonly buffer: ArrayBufferLike;
38353843

38363844
/**
38373845
* The length in bytes of the array.
@@ -4075,7 +4083,7 @@ interface Float64ArrayConstructor {
40754083
readonly prototype: Float64Array;
40764084
new (length: number): Float64Array;
40774085
new (array: ArrayLike<number>): Float64Array;
4078-
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float64Array;
4086+
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Float64Array;
40794087

40804088
/**
40814089
* The size in bytes of each element in the array.

0 commit comments

Comments
 (0)