recursal/MDN huggingface dataset:
Atomics.wait()
==============

 The **`Atomics.wait()`** static
 method verifies that a shared memory location still contains a
 given value and if so sleeps, awaiting a wake-up notification or times out. It returns a string which
 is either `"ok"`, `"not-equal"`, or `"timed-out"`.


**Note:** This operation only works with an `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`, and may not be allowed on the main thread.
 For a non-blocking, asynchronous version of this method, see `Atomics.waitAsync()`.


Syntax
------


```js
Atomics.wait(typedArray, index, value)
Atomics.wait(typedArray, index, value, timeout)
```

### Parameters

`typedArray`

An `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.

`index`

The position in the `typedArray` to wait on.

`value`

The expected value to test.

`timeout` Optional

Time to wait in milliseconds. `NaN` (and values that get converted to `NaN`, such as `undefined`) becomes `Infinity`. Negative values become `0`.

### Return value

A string which is either `"ok"`, `"not-equal"`, or `"timed-out"`.

### Exceptions

`TypeError`

Thrown in one of the following cases:

* If `typedArray` is not an `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.
* If the current thread cannot be blocked (for example, because it's the main thread).

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using wait()

Given a shared `Int32Array`:


```js
const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);
```


 A reading thread is sleeping and waiting on location 0 which is expected to be 0. As
 long as that is true, it will not go on. However, once the writing thread has stored a
 new value, it will be notified by the writing thread and return the new value (123).


```js
Atomics.wait(int32, 0, 0);
console.log(int32[0]); // 123
```


 A writing thread stores a new value and notifies the waiting thread once it has
 written:


```js
console.log(int32[0]); // 0;
Atomics.store(int32, 0, 123);
Atomics.notify(int32, 0, 1);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.wait |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.waitAsync()`
* `Atomics.notify()`
WeakMap.prototype.has()
=======================

 The **`has()`** method of `WeakMap` instances returns a boolean indicating whether an
 element with the specified key exists in this `WeakMap` or not.

Try it
------

Syntax
------


```js
has(key)
```

### Parameters

`key`

The key of the element to test for presence in the `WeakMap` object.

### Return value

Returns `true` if an element with the specified key exists in the `WeakMap` object; otherwise `false`. Always returns `false` if `key` is not an object or a non-registered symbol.

Examples
--------

### Using the has method


```js
const wm = new WeakMap();
wm.set(window, "foo");

wm.has(window); // returns true
wm.has("baz"); // returns false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-weakmap.prototype.has |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WeakMap`
* `WeakMap.prototype.set()`
* `WeakMap.prototype.get()`
WeakMap() constructor
=====================

The **`WeakMap()`** constructor creates `WeakMap` objects.

Syntax
------


```js
new WeakMap()
new WeakMap(iterable)
```


**Note:** `WeakMap()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`iterable`

An `Array` or other iterable object that implements an @@iterator method that returns an iterator object that produces a two-element array-like object whose first element is a value that will be used as a `WeakMap` key and whose second element is the value to associate with that key. Each key-value pair will be added to the new `WeakMap`. null is treated as undefined.

Examples
--------

### Using WeakMap


```js
const wm1 = new WeakMap();
const wm2 = new WeakMap();
const wm3 = new WeakMap();
const o1 = {};
const o2 = function () {};
const o3 = window;

wm1.set(o1, 37);
wm1.set(o2, "azerty");
wm2.set(o1, o2); // a value can be anything, including an object or a function
wm2.set(o3, undefined);
wm2.set(wm1, wm2); // keys and values can be any objects. Even WeakMaps!

wm1.get(o2); // "azerty"
wm2.get(o2); // undefined, because there is no key for o2 on wm2
wm2.get(o3); // undefined, because that is the set value

wm1.has(o2); // true
wm2.has(o2); // false
wm2.has(o3); // true (even if the value itself is 'undefined')

wm3.set(o1, 37);
wm3.get(o1); // 37

wm1.has(o1); // true
wm1.delete(o1);
wm1.has(o1); // false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-weakmap-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `WeakMap` in `core-js`
* `WeakMap` in the JavaScript guide
* Hiding Implementation Details with ECMAScript 6 WeakMaps
* `Map`
* `Set`
* `WeakSet`
WeakMap.prototype.get()
=======================

The **`get()`** method of `WeakMap` instances returns a specified element from this `WeakMap`.

Try it
------

Syntax
------


```js
get(key)
```

### Parameters

`key`

The key of the element to return from the `WeakMap` object.

### Return value

 The element associated with the specified key in the `WeakMap` object. If
 the key can't be found, `undefined` is returned. Always returns
 `undefined` if `key` is not an object or a non-registered symbol.

Examples
--------

### Using the get() method


```js
const wm = new WeakMap();
wm.set(window, "foo");

wm.get(window); // Returns "foo".
wm.get("baz"); // Returns undefined.
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-weakmap.prototype.get |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WeakMap`
* `WeakMap.prototype.set()`
* `WeakMap.prototype.has()`
WeakMap.prototype.delete()
==========================

The **`delete()`** method of `WeakMap` instances removes the specified element from this `WeakMap`.

Try it
------

Syntax
------


```js
weakMapInstance.delete(key)
```

### Parameters

`key`

The key of the element to remove from the `WeakMap` object.

### Return value

`true` if an element in the `WeakMap` object has been removed successfully. `false` if the key is not found in the `WeakMap`. Always returns `false` if `key` is not an object or a non-registered symbol.

Examples
--------

### Using the delete() method


```js
const wm = new WeakMap();
wm.set(window, "foo");

wm.delete(window); // Returns true. Successfully removed.

wm.has(window); // Returns false. The window object is no longer in the WeakMap.
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-weakmap.prototype.delete |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WeakMap`
WeakMap.prototype.set()
=======================

 The **`set()`** method of `WeakMap` instances adds a new element with a specified key
 and value to this `WeakMap`.

Try it
------

Syntax
------


```js
set(key, value)
```

### Parameters

`key`

Must be either an object or a non-registered symbol. The key of the entry to add to the `WeakMap` object.

`value`

Any value representing the value of the entry to add to the `WeakMap` object.

### Return value

The `WeakMap` object.

### Exceptions

`TypeError`

Thrown if `key` is not an object or a non-registered symbol.

Examples
--------

### Using the set() method


```js
const wm = new WeakMap();
const obj = {};

// Add new elements to the WeakMap
wm.set(obj, "foo").set(window, "bar"); // chainable

// Update an element in the WeakMap
wm.set(obj, "baz");

// Using a non-registered symbol as key
const sym = Symbol("foo");
wm.set(sym, "baz");
wm.set(Symbol.iterator, "qux");
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-weakmap.prototype.set |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WeakMap`
* `WeakMap.prototype.get()`
* `WeakMap.prototype.has()`
SharedArrayBuffer.prototype.growable
====================================

The **`growable`** accessor property of `SharedArrayBuffer` instances returns whether this `SharedArrayBuffer` can be grow or not.

Description
-----------

The `growable` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when the array is constructed. If a `maxByteLength` option was set in the constructor, `growable` will return `true`; if not, it will return `false`.

Examples
--------

### Using growable

In this example, we create a 8-byte buffer that is growable to a max length of 16 bytes, then check its `growable` property, growing it if `growable` returns `true`:


```js
const buffer = new SharedArrayBuffer(8, { maxByteLength: 16 });

if (buffer.growable) {
  console.log("SAB is growable!");
  buffer.grow(12);
}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-sharedarraybuffer.prototype.growable |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SharedArrayBuffer`
* `SharedArrayBuffer.prototype.grow()`
* `SharedArrayBuffer.prototype.maxByteLength`
SharedArrayBuffer[@@species]
============================

The **`SharedArrayBuffer[@@species]`** static accessor property returns the constructor used to construct return values from `SharedArrayBuffer` methods.

**Warning:** The existence of `@@species` allows execution of arbitrary code and may create security vulnerabilities. It also makes certain optimizations much harder. Engine implementers are investigating whether to remove this feature. Avoid relying on it if possible.

Syntax
------


```js
SharedArrayBuffer[Symbol.species]
```

### Return value

The value of the constructor (`this`) on which `get @@species` was called. The return value is used to construct return values from array buffer methods that create new array buffer.

Description
-----------

The `@@species` accessor property returns the default constructor for `SharedArrayBuffer` objects. Subclass constructors may override it to change the constructor assignment. The default implementation is basically:


```js
// Hypothetical underlying implementation for illustration
class SharedArrayBuffer {
  static get [Symbol.species]() {
    return this;
  }
}
```


Because of this polymorphic implementation, `@@species` of derived subclasses would also return the constructor itself by default.


```js
class SubArrayBuffer extends SharedArrayBuffer {}
SubArrayBuffer[Symbol.species] === SharedArrayBuffer; // true
```


When calling array buffer methods that do not mutate the existing array but return a new array buffer instance (for example, `slice()`), the array's `constructor[@@species]` will be accessed. The returned constructor will be used to construct the return value of the array buffer method.

Examples
--------

### Species in ordinary objects

The `@@species` property returns the default constructor function, which is the `SharedArrayBuffer` constructor for `SharedArrayBuffer`.


```js
SharedArrayBuffer[Symbol.species]; // function SharedArrayBuffer()
```

### Species in derived objects

In an instance of a custom `SharedArrayBuffer` subclass, such as `MySharedArrayBuffer`, the `MySharedArrayBuffer` species is the `MySharedArrayBuffer` constructor. However, you might want to overwrite this, in order to return parent `SharedArrayBuffer` objects in your derived class methods:


```js
class MySharedArrayBuffer extends SharedArrayBuffer {
  // Overwrite MySharedArrayBuffer species to the parent SharedArrayBuffer constructor
  static get [Symbol.species]() {
    return SharedArrayBuffer;
  }
}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-sharedarraybuffer-@@species |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SharedArrayBuffer`
* `Symbol.species`
SharedArrayBuffer() constructor
===============================

**Note:** The `SharedArrayBuffer` constructor may not always be globally available unless certain security requirements are met.

The **`SharedArrayBuffer()`** constructor creates `SharedArrayBuffer` objects.

Try it
------

Syntax
------


```js
new SharedArrayBuffer(length)
new SharedArrayBuffer(length, options)
```


**Note:** `SharedArrayBuffer()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`length`

The size, in bytes, of the array buffer to create.

`options` Optional

An object, which can contain the following properties:

`maxByteLength` Optional

The maximum size, in bytes, that the shared array buffer can be resized to.


### Return value

 A new `SharedArrayBuffer` object of the specified size, with its `maxByteLength` property set to the specified `maxByteLength` if one was specified. Its contents are
 initialized to 0.

Examples
--------

### Always use the new operator to create a SharedArrayBuffer

`SharedArrayBuffer` constructors are required to be constructed with a
 `new` operator. Calling a `SharedArrayBuffer`
 constructor as a function without `new` will throw a `TypeError`.


```js
const sab = SharedArrayBuffer(1024);
// TypeError: calling a builtin SharedArrayBuffer constructor
// without new is forbidden
```



```js
const sab = new SharedArrayBuffer(1024);
```

### Growing a growable SharedArrayBuffer

In this example, we create an 8-byte buffer that is growable to a max length of 16 bytes, then `grow()` it to 12 bytes:


```js
const buffer = new SharedArrayBuffer(8, { maxByteLength: 16 });

buffer.grow(12);
```


**Note:** It is recommended that `maxByteLength` is set to the smallest value possible for your use case. It should never exceed `1073741824` (1GB), to reduce the risk of out-of-memory errors.

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-sharedarraybuffer-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `ArrayBuffer`
* JavaScript typed arrays guide
SharedArrayBuffer.prototype.maxByteLength
=========================================

The **`maxByteLength`** accessor property of `SharedArrayBuffer` instances returns the maximum length (in bytes) that this `SharedArrayBuffer` can be grown to.

Description
-----------

The `maxByteLength` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when the shared array is constructed, set via the `maxByteLength` option of the `SharedArrayBuffer()` constructor, and cannot be changed.

If this `SharedArrayBuffer` was constructed without specifying a `maxByteLength` value, this property returns a value equal to the value of the `SharedArrayBuffer`'s `byteLength`.

Examples
--------

### Using maxByteLength

In this example, we create a 8-byte buffer that is resizable to a max length of 16 bytes, then return its `maxByteLength`:


```js
const buffer = new SharedArrayBuffer(8, { maxByteLength: 16 });

buffer.maxByteLength; // 16
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-sharedarraybuffer.prototype.maxbytelength |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SharedArrayBuffer`
SharedArrayBuffer.prototype.grow()
==================================

The **`grow()`** method of `SharedArrayBuffer` instances grows the `SharedArrayBuffer` to the specified size, in bytes.

Syntax
------


```js
grow(newLength)
```

### Parameters

`newLength`

The new length, in bytes, to resize the `SharedArrayBuffer` to.

### Return value

None (`undefined`).

### Exceptions

`TypeError`

Thrown if the `SharedArrayBuffer` is not growable.

`RangeError`

Thrown if `newLength` is larger than the `maxByteLength` of the `SharedArrayBuffer` or smaller than the `byteLength`.

Description
-----------

The `grow()` method grows a `SharedArrayBuffer` to the size specified by the `newLength` parameter, provided that the `SharedArrayBuffer` is growable and the new size is less than or equal to the `maxByteLength` of the `SharedArrayBuffer`. New bytes are initialized to 0.

Examples
--------

### Using grow()

In this example, we create a 8-byte buffer that is growable to a max length of 16 bytes, then check its `growable` property, growing it if `growable` returns `true`:


```js
const buffer = new SharedArrayBuffer(8, { maxByteLength: 16 });

if (buffer.growable) {
  console.log("SAB is growable!");
  buffer.grow(12);
}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-sharedarraybuffer.prototype.grow |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SharedArrayBuffer`
* `SharedArrayBuffer.prototype.growable`
* `SharedArrayBuffer.prototype.maxByteLength`
SharedArrayBuffer.prototype.slice()
===================================

The **`slice()`** method of `SharedArrayBuffer` instances returns a new `SharedArrayBuffer` whose contents are a copy of this `SharedArrayBuffer`'s bytes from `start`, inclusive, up to `end`, exclusive. If either `start` or `end` is negative, it refers to an index from the end of the array, as opposed to from the beginning.

Try it
------

Syntax
------


```js
slice()
slice(start)
slice(start, end)
```

### Parameters

`start` Optional

Zero-based index at which to start extraction, converted to an integer.

* Negative index counts back from the end of the buffer — if `start < 0`, `start + buffer.length` is used.
* If `start < -buffer.length` or `start` is omitted, `0` is used.
* If `start >= buffer.length`, nothing is extracted.

`end` Optional

Zero-based index at which to end extraction, converted to an integer. `slice()` extracts up to but not including `end`.

* Negative index counts back from the end of the buffer — if `end < 0`, `end + buffer.length` is used.
* If `end < -buffer.length`, `0` is used.
* If `end >= buffer.length` or `end` is omitted, `buffer.length` is used, causing all elements until the end to be extracted.
* If `end` is positioned before or at `start` after normalization, nothing is extracted.

### Return value

A new `SharedArrayBuffer` containing the extracted elements.

Examples
--------

### Using slice()


```js
const sab = new SharedArrayBuffer(1024);
sab.slice(); // SharedArrayBuffer { byteLength: 1024 }
sab.slice(2); // SharedArrayBuffer { byteLength: 1022 }
sab.slice(-2); // SharedArrayBuffer { byteLength: 2 }
sab.slice(0, 1); // SharedArrayBuffer { byteLength: 1 }
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-sharedarraybuffer.prototype.slice |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SharedArrayBuffer`
* `ArrayBuffer.prototype.slice()`
SharedArrayBuffer.prototype.byteLength
======================================

The **`byteLength`** accessor property of `SharedArrayBuffer` instances returns the length (in bytes) of this `SharedArrayBuffer`.

Try it
------

Description
-----------

The `byteLength` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when the shared array is constructed and cannot be changed.

Examples
--------

### Using byteLength


```js
const sab = new SharedArrayBuffer(1024);
sab.byteLength; // 1024
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-sharedarraybuffer.prototype.bytelength |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SharedArrayBuffer`
InternalError() constructor
===========================

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The **`InternalError()`** constructor creates `InternalError` objects.

Syntax
------


```js
new InternalError()
new InternalError(message)
new InternalError(message, options)
new InternalError(message, fileName)
new InternalError(message, fileName, lineNumber)

InternalError()
InternalError(message)
InternalError(message, options)
InternalError(message, fileName)
InternalError(message, fileName, lineNumber)
```


**Note:** `InternalError()` can be called with or without `new`. Both create a new `InternalError` instance.

### Parameters

`message` Optional

Human-readable description of the error.

`options` Optional

An object that has the following properties:

`cause` Optional

 A property indicating the specific cause of the error.
 When catching and re-throwing an error with a more-specific or useful error message, this property can be used to pass the original error.



`fileName` Optional 
Non-standard

The name of the file containing the code that caused the exception

`lineNumber` Optional 
Non-standard

The line number of the code that caused the exception

Examples
--------

### Creating a new InternalError


```js
new InternalError("Engine failure");
```

Specifications
--------------

Not part of any standard.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Error`