Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 92 additions & 1 deletion src/lib/es2017.sharedmemory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,96 @@ interface SharedArrayBufferConstructor {
readonly prototype: SharedArrayBuffer;
new (byteLength: number): SharedArrayBuffer;
}
declare var SharedArrayBuffer: SharedArrayBufferConstructor;

declare var SharedArrayBuffer: SharedArrayBufferConstructor;
interface ArrayBufferTypes {
SharedArrayBuffer: SharedArrayBuffer;
}

interface Atomics {
/**
* Adds a value to the value at the given position in the array, returning the original value.
* Until this atomic operation completes, any other read or write operation against the array
* will block.
*/
add(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;

/**
* Stores the bitwise AND of a value with the value at the given position in the array,
* returning the original value. Until this atomic operation completes, any other read or
* write operation against the array will block.
*/
and(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;

/**
* Replaces the value at the given position in the array if the original value equals the given
* expected value, returning the original value. Until this atomic operation completes, any
* other read or write operation against the array will block.
*/
compareExchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, expectedValue: number, replacementValue: number): number;

/**
* Replaces the value at the given position in the array, returning the original value. Until
* this atomic operation completes, any other read or write operation against the array will
* block.
*/
exchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;

/**
* Returns a value indicating whether high-performance algorithms can use atomic operations
* (`true`) or must use locks (`false`) for the given number of bytes-per-element of a typed
* array.
*/
isLockFree(size: number): boolean;

/**
* Returns the value at the given position in the array. Until this atomic operation completes,
* any other read or write operation against the array will block.
*/
load(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number): number;

/**
* Stores the bitwise OR of a value with the value at the given position in the array,
* returning the original value. Until this atomic operation completes, any other read or write
* operation against the array will block.
*/
or(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;

/**
* Stores a value at the given position in the array, returning the new value. Until this
* atomic operation completes, any other read or write operation against the array will block.
*/
store(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;

/**
* Subtracts a value from the value at the given position in the array, returning the original
* value. Until this atomic operation completes, any other read or write operation against the
* array will block.
*/
sub(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;

/**
* If the value at the given position in the array is equal to the provided value, the current
* agent is put to sleep causing execution to suspend until the timeout expires (returning
* `"timed-out"`) or until the agent is awoken (returning `"ok"`); otherwise, returns
* `"not-equal"`.
*/
wait(typedArray: Int32Array, index: number, value: number, timeout?: number): "ok" | "not-equal" | "timed-out";

/**
* Wakes up sleeping agents that are waiting on the given index of the array, returning the
* number of agents that were awoken.
*/
wake(typedArray: Int32Array, index: number, count: number): number;

/**
* Stores the bitwise XOR of a value with the value at the given position in the array,
* returning the original value. Until this atomic operation completes, any other read or write
* operation against the array will block.
*/
xor(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;

readonly [Symbol.toStringTag]: "Atomics";
}

declare var Atomics: Atomics;
48 changes: 28 additions & 20 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,14 @@ interface ArrayBuffer {
slice(begin: number, end?: number): ArrayBuffer;
}

/**
* Allowed ArrayBuffer types for the buffer of an ArrayBufferView and related Typed Arrays.
*/
interface ArrayBufferTypes {
ArrayBuffer: ArrayBuffer;
}
type ArrayBufferLike = ArrayBufferTypes[keyof ArrayBufferTypes];

interface ArrayBufferConstructor {
readonly prototype: ArrayBuffer;
new (byteLength: number): ArrayBuffer;
Expand All @@ -1397,7 +1405,7 @@ interface ArrayBufferView {
/**
* The ArrayBuffer instance referenced by the array.
*/
buffer: ArrayBuffer;
buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -1539,7 +1547,7 @@ interface DataView {
}

interface DataViewConstructor {
new (buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): DataView;
new (buffer: ArrayBufferLike, byteOffset?: number, byteLength?: number): DataView;
}
declare const DataView: DataViewConstructor;

Expand All @@ -1556,7 +1564,7 @@ interface Int8Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -1799,7 +1807,7 @@ interface Int8ArrayConstructor {
readonly prototype: Int8Array;
new (length: number): Int8Array;
new (array: ArrayLike<number>): Int8Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int8Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Int8Array;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -1840,7 +1848,7 @@ interface Uint8Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -2084,7 +2092,7 @@ interface Uint8ArrayConstructor {
readonly prototype: Uint8Array;
new (length: number): Uint8Array;
new (array: ArrayLike<number>): Uint8Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint8Array;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -2125,7 +2133,7 @@ interface Uint8ClampedArray {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -2369,7 +2377,7 @@ interface Uint8ClampedArrayConstructor {
readonly prototype: Uint8ClampedArray;
new (length: number): Uint8ClampedArray;
new (array: ArrayLike<number>): Uint8ClampedArray;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8ClampedArray;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint8ClampedArray;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -2409,7 +2417,7 @@ interface Int16Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -2653,7 +2661,7 @@ interface Int16ArrayConstructor {
readonly prototype: Int16Array;
new (length: number): Int16Array;
new (array: ArrayLike<number>): Int16Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int16Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Int16Array;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -2694,7 +2702,7 @@ interface Uint16Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -2938,7 +2946,7 @@ interface Uint16ArrayConstructor {
readonly prototype: Uint16Array;
new (length: number): Uint16Array;
new (array: ArrayLike<number>): Uint16Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint16Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint16Array;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -2978,7 +2986,7 @@ interface Int32Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -3222,7 +3230,7 @@ interface Int32ArrayConstructor {
readonly prototype: Int32Array;
new (length: number): Int32Array;
new (array: ArrayLike<number>): Int32Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int32Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Int32Array;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -3262,7 +3270,7 @@ interface Uint32Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -3506,7 +3514,7 @@ interface Uint32ArrayConstructor {
readonly prototype: Uint32Array;
new (length: number): Uint32Array;
new (array: ArrayLike<number>): Uint32Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint32Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint32Array;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -3546,7 +3554,7 @@ interface Float32Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -3790,7 +3798,7 @@ interface Float32ArrayConstructor {
readonly prototype: Float32Array;
new (length: number): Float32Array;
new (array: ArrayLike<number>): Float32Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float32Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Float32Array;

/**
* The size in bytes of each element in the array.
Expand Down Expand Up @@ -3831,7 +3839,7 @@ interface Float64Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBuffer;
readonly buffer: ArrayBufferLike;

/**
* The length in bytes of the array.
Expand Down Expand Up @@ -4075,7 +4083,7 @@ interface Float64ArrayConstructor {
readonly prototype: Float64Array;
new (length: number): Float64Array;
new (array: ArrayLike<number>): Float64Array;
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float64Array;
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Float64Array;

/**
* The size in bytes of each element in the array.
Expand Down