Stage 1 Draft / September 20, 2023

Get Intrinsic

6 ECMAScript Data Types and Values

6.1 ECMAScript Language Types

6.1.7 The Object Type

6.1.7.4 Well-Known Intrinsic Objects

Well-known intrinsics are built-in objects that are explicitly referenced by the algorithms of this specification and which usually have realm-specific identities. Unless otherwise specified each intrinsic object actually corresponds to a set of similar objects, one per realm.

Within this specification a reference such as %name% means the intrinsic object, associated with the current realm, corresponding to the name. A reference such as %name.a.b% means, as if the "b" property of the value of the "a" property of the intrinsic object %name% was accessed prior to any ECMAScript code being evaluated. Determination of the current realm and its intrinsics is described in 9.4. The well-known intrinsics are listed in Table 1.

Table 1: Well-Known Intrinsic Objects
Intrinsic Name Global Name ECMAScript Language Association Directly Accessible to ECMAScript code
%AggregateError% AggregateError The AggregateError constructor (20.5.7.1)
%AsyncFromSyncIteratorPrototype% The prototype of async-from-sync iterator objects (27.1.4) No
%ForInIteratorPrototype% The prototype of For-In iterator objects (14.7.5.10) No

7 Abstract Operations

7.5 Miscellaneous

7.5.1 HostAddedIntrinsics ( )

The host-defined abstract operation HostAddedIntrinsics takes no arguments and returns a List of Records. It allows host environments to provide additional intrinsics for getIntrinsics to expose.

An implementation of HostAddedIntrinsics must conform to the following requirements:

  • Every item in the returned list must be a Record with fields [[Key]] (the intrinsic name) and [[Value]] (the intrinsic value itself).
  • An intrinsic name that describes a data property must have no prefix.
  • An intrinsic name that describes an accessor property must have the prefix "get " or "set ".
  • Every call to this abstract operation must return the same List contents, in the same order.

The default implementation of HostAddedIntrinsics is to return an empty List.

7.5.2 GetIntrinsicsMap ( )

The abstract operation GetIntrinsicsMap takes no arguments and returns a Map.

GetIntrinsicsMap returns a Map object. This Map is not directly observable from ECMAScript code.

Note
The returned Map object must be identical on successive calls to this abstract operation.
  1. Let intrinsics be a new empty List.
  2. Let baseIntrinsics be a list of each intrinsic name listed in 6.1.7.4.
  3. Sort baseIntrinsics alphabetically, with a case-insensitive ordering.
  4. For each baseIntrinsic of baseIntrinscs,
    1. Append Record { [[Key]]: baseIntrinsic, [[Value]]: the referenced intrinsic value } to intrinsics.
    2. Let nestedIntrinsics be a new empty List.
    3. For each intrinsic intrinsic that would be accessible from the value represented by baseIntrinsic in a new realm prior to any ECMAScript code being evaluated, via member access,
      1. Let P be the property key represented by intrinsic.
      2. Let X be the property represented by intrinsic.
      3. If P is neither "constructor" nor "__proto__",
        1. If X is a data property,
          1. Let value be the [[Value]] attribute of X.
          2. Append Record { [[Key]]: intrinsic, [[Value]]: value } to nestedIntrinsics.
        2. Else,
          1. Assert: X is an accessor property.
          2. Let get be the [[Get]] attribute of X.
          3. If get is not undefined,
            1. Let name be the string-concatenation of "get " and intrinsic.
            2. Append Record { [[Key]]: name, [[Value]]: get } to nestedIntrinsics.
          4. Let set be the [[Set]] attribute of X.
          5. If set is not undefined,
            1. Let name be the string-concatenation of "set " and intrinsic.
            2. Append Record { [[Key]]: name, [[Value]]: set } to nestedIntrinsics.
    4. TODO: find an easy way to sort that ignores the prefixes.
    5. Sort nestedIntrinsics in alphabetical order, based on the [[Key]] field of each Record.
    6. Append the contents of nestedIntrinsics to intrinsics.
  5. Append Record { [[Key]]: "globalThis", [[Value]]: GetThisBinding() } to intrinsics.
  6. Assert: intrinsics contains exactly one record with the [[Key]] "globalThis".
  7. Let hostIntrinsics be HostAddedIntrinsics().
  8. Let map be ! OrdinaryCreateFromConstructor(%Map%, "%Map.prototype%", « [[MapData]] »).
  9. Set map.[[MapData]] to the list-concatenation of intrinsics and hostIntrinsics.
  10. Return map.

7.5.3 CreateIntrinsicsIterator ( )

The abstract operation CreateIntrinsicsIterator takes no arguments and returns a Generator. It performs the following steps when called:

  1. Return ! CreateMapIterator(GetIntrinsicsMap(), key).

7.5.4 MapGet ( map, key )

The abstract operation MapGet takes arguments map (a Map) and key (an ECMAScript language value) and returns a Boolean. It performs the following steps when called:

  1. Let entries be the List that is map.[[MapData]].
  2. For each Record { [[Key]], [[Value]] } p of entries, do
    1. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return p.[[Value]].
  3. Return undefined.

7.5.5 MapHas ( map, key )

The abstract operation MapHas takes arguments map (a Map) and key (an ECMAScript language value) and returns a Boolean. It performs the following steps when called:

  1. Let entries be the List that is map.[[MapData]].
  2. For each Record { [[Key]], [[Value]] } p of entries, do
    1. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return true.
  3. Return false.

24 Keyed Collections

24.1 Map Objects

24.1.3 Properties of the Map Prototype Object

24.1.3.6 Map.prototype.get ( key )

This method performs the following steps when called:

  1. Let M be the this value.
  2. Perform ? RequireInternalSlot(M, [[MapData]]).
  3. Return MapGet(M, key).
  4. Let entries be the List that is M.[[MapData]].
  5. For each Record { [[Key]], [[Value]] } p of entries, do
    1. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return p.[[Value]].
  6. Return undefined.

24.1.3.7 Map.prototype.has ( key )

This method performs the following steps when called:

  1. Let M be the this value.
  2. Perform ? RequireInternalSlot(M, [[MapData]]).
  3. Return MapHas(M, key).
  4. Let entries be the List that is M.[[MapData]].
  5. For each Record { [[Key]], [[Value]] } p of entries, do
    1. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return p.[[Value]].
  6. Return undefined.

28 Reflection

28.1 The Reflect Object

28.1.6 Reflect.getIntrinsic ( name )

This function performs the following steps when called:

  1. If Type(name) is not String, throw a TypeError exception.
  2. Let map be GetIntrinsicsMap().
  3. If MapHas(map) is false, then
    1. Throw a TypeError exception.
  4. Return MapGet(map, name).
Note
When the name string succeeds in producing an intrinsic, the name string surrounded by "%" matches the intrinsic notation described in the specification in Well-Known Intrinsic Objects.

28.1.7 Reflect.getIntrinsics ( )

This function performs the following steps when called:

  1. Return CreateIntrinsicsIterator().

A Copyright & Software License

Copyright Notice

© 2023 Jordan Harband

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.