mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 21:31:46 +00:00
767 lines
155 KiB
HTML
767 lines
155 KiB
HTML
<!DOCTYPE html><html lang="en-GB-oxendict"><head><meta name="viewport" content="width=device-width, initial-scale=1"><meta charset="utf-8"><meta property="og:image" content="https://tc39.es/ecmarkup/ecma-logo.png"><meta property="og:title" content="ECMAScript® 2026 Language Specification"><meta property="og:description" content="Introduction
|
||
This Ecma Standard defines the ECMAScript 2026 Language. It is the seventeenth edition of the ECMAScript Language Specification. ECMAScript is based on several originating technologies, the most well-known being JavaScript (Netscape) and JScript (Microsoft). The language was invent">
|
||
<link rel="icon" href="../img/favicon.ico">
|
||
<link rel="stylesheet" href="../assets/css/ecmarkup.css"><link rel="stylesheet" href="../assets/css/print.css" media="print">
|
||
|
||
<title>ECMAScript® 2026 Language Specification</title><script src="../assets/js/multipage.js?cache=Wu2V1pj2" defer=""></script><script src="../assets/js/ecmarkup.js?cache=BPFBckdu" defer=""></script><link rel="canonical" href="../#sec-keyed-collections"></head>
|
||
<body><div id="spec-container"><emu-clause id="sec-keyed-collections" oldids="sec-keyed-collection"><span id="sec-keyed-collection"></span>
|
||
<h1><span class="secnum">24</span> Keyed Collections</h1>
|
||
|
||
<emu-clause id="sec-map-objects">
|
||
<h1><span class="secnum">24.1</span> Map Objects</h1>
|
||
<p>Maps are collections of key/value pairs where both the keys and values may be arbitrary <emu-xref href="#sec-ecmascript-language-types" id="_ref_14119"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref>. A distinct key value may only occur in one key/value pair within the Map's collection. Distinct key values are discriminated using the semantics of the <emu-xref aoid="SameValueZero" id="_ref_14120"><a href="abstract-operations.html#sec-samevaluezero">SameValueZero</a></emu-xref> comparison algorithm.</p>
|
||
<p>Maps must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structure used in this specification is only intended to describe the required observable semantics of Maps. It is not intended to be a viable implementation model.</p>
|
||
|
||
<emu-clause id="sec-map-constructor">
|
||
<h1><span class="secnum">24.1.1</span> The Map Constructor</h1>
|
||
<p>The Map <emu-xref href="#constructor" id="_ref_14121"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%Map%</dfn>.</li>
|
||
<li>is the initial value of the <emu-val>"Map"</emu-val> property of the <emu-xref href="#sec-global-object" id="_ref_14122"><a href="global-object.html#sec-global-object">global object</a></emu-xref>.</li>
|
||
<li>creates and initializes a new Map when called as a <emu-xref href="#constructor" id="_ref_14123"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>.</li>
|
||
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
|
||
<li>may be used as the value in an <code>extends</code> clause of a class definition. Subclass <emu-xref href="#constructor" id="_ref_14124"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that intend to inherit the specified Map behaviour must include a <code>super</code> call to the Map <emu-xref href="#constructor" id="_ref_14125"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to create and initialize the subclass instance with the internal state necessary to support the <code>Map.prototype</code> built-in methods.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-map-iterable" type="built-in function">
|
||
<h1><span class="secnum">24.1.1.1</span> Map ( [ <var>iterable</var> ] )</h1>
|
||
<p>This function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>If NewTarget is <emu-val>undefined</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>map</var> be ? <emu-xref aoid="OrdinaryCreateFromConstructor" id="_ref_14126"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinarycreatefromconstructor" class="e-user-code">OrdinaryCreateFromConstructor</a></emu-xref>(NewTarget, <emu-val>"%Map.prototype%"</emu-val>, « <var class="field">[[MapData]]</var> »).</li><li>Set <var>map</var>.<var class="field">[[MapData]]</var> to a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14127"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>If <var>iterable</var> is either <emu-val>undefined</emu-val> or <emu-val>null</emu-val>, return <var>map</var>.</li><li>Let <var>adder</var> be ? <emu-xref aoid="Get" id="_ref_14128"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>map</var>, <emu-val>"set"</emu-val>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14129"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>adder</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Return ? <emu-xref aoid="AddEntriesFromIterable" id="_ref_14130"><a href="keyed-collections.html#sec-add-entries-from-iterable" class="e-user-code">AddEntriesFromIterable</a></emu-xref>(<var>map</var>, <var>iterable</var>, <var>adder</var>).</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>If the parameter <var>iterable</var> is present, it is expected to be an object that implements a <emu-xref href="#sec-well-known-symbols" id="_ref_14131"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref> method that returns an <emu-xref href="#sec-iterator-interface" id="_ref_14132"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator object</a></emu-xref> that produces a two element <emu-xref href="#sec-lengthofarraylike" id="_ref_14133"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref> whose first element is a value that will be used as a Map key and whose second element is the value to associate with that key.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-add-entries-from-iterable" type="abstract operation" aoid="AddEntriesFromIterable">
|
||
<h1><span class="secnum">24.1.1.2</span> AddEntriesFromIterable ( <var>target</var>, <var>iterable</var>, <var>adder</var> )</h1>
|
||
<p>The abstract operation AddEntriesFromIterable takes arguments <var>target</var> (an Object), <var>iterable</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14134"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>, but not <emu-val>undefined</emu-val> or <emu-val>null</emu-val>), and <var>adder</var> (a <emu-xref href="#function-object" id="_ref_14135"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14136"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14137"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14138"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. <var>adder</var> will be invoked, with <var>target</var> as the receiver. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>iteratorRecord</var> be ? <emu-xref aoid="GetIterator" id="_ref_14139"><a href="abstract-operations.html#sec-getiterator" class="e-user-code">GetIterator</a></emu-xref>(<var>iterable</var>, <emu-const>sync</emu-const>).</li><li>Repeat,<ol><li>Let <var>next</var> be ? <emu-xref aoid="IteratorStepValue" id="_ref_14140"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>iteratorRecord</var>).</li><li>If <var>next</var> is <emu-const>done</emu-const>, return <var>target</var>.</li><li>If <var>next</var> <emu-xref href="#sec-object-type" id="_ref_14141"><a href="ecmascript-data-types-and-values.html#sec-object-type">is not an Object</a></emu-xref>, then<ol><li>Let <var>error</var> be <emu-xref aoid="ThrowCompletion" id="_ref_14142"><a href="ecmascript-data-types-and-values.html#sec-throwcompletion">ThrowCompletion</a></emu-xref>(a newly created <emu-val>TypeError</emu-val> object).</li><li>Return ? <emu-xref aoid="IteratorClose" id="_ref_14143"><a href="abstract-operations.html#sec-iteratorclose" class="e-user-code">IteratorClose</a></emu-xref>(<var>iteratorRecord</var>, <var>error</var>).</li></ol></li><li>Let <var>k</var> be <emu-xref aoid="Completion" id="_ref_14144"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Get" id="_ref_14145"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>next</var>, <emu-val>"0"</emu-val>)).</li><li><emu-xref aoid="IfAbruptCloseIterator" id="_ref_14146"><a href="abstract-operations.html#sec-ifabruptcloseiterator" class="e-user-code">IfAbruptCloseIterator</a></emu-xref>(<var>k</var>, <var>iteratorRecord</var>).</li><li>Let <var>v</var> be <emu-xref aoid="Completion" id="_ref_14147"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Get" id="_ref_14148"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>next</var>, <emu-val>"1"</emu-val>)).</li><li><emu-xref aoid="IfAbruptCloseIterator" id="_ref_14149"><a href="abstract-operations.html#sec-ifabruptcloseiterator" class="e-user-code">IfAbruptCloseIterator</a></emu-xref>(<var>v</var>, <var>iteratorRecord</var>).</li><li>Let <var>status</var> be <emu-xref aoid="Completion" id="_ref_14150"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Call" id="_ref_14151"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>adder</var>, <var>target</var>, « <var>k</var>, <var>v</var> »)).</li><li><emu-xref aoid="IfAbruptCloseIterator" id="_ref_14152"><a href="abstract-operations.html#sec-ifabruptcloseiterator" class="e-user-code">IfAbruptCloseIterator</a></emu-xref>(<var>status</var>, <var>iteratorRecord</var>).</li></ol></li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>The parameter <var>iterable</var> is expected to be an object that implements a <emu-xref href="#sec-well-known-symbols" id="_ref_14153"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref> method that returns an <emu-xref href="#sec-iterator-interface" id="_ref_14154"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator object</a></emu-xref> that produces a two element <emu-xref href="#sec-lengthofarraylike" id="_ref_14155"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref> whose first element is a value that will be used as a Map key and whose second element is the value to associate with that key.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-map-constructor">
|
||
<h1><span class="secnum">24.1.2</span> Properties of the Map Constructor</h1>
|
||
<p>The Map <emu-xref href="#constructor" id="_ref_14156"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-function-prototype-object" id="_ref_14157"><a href="fundamental-objects.html#sec-properties-of-the-function-prototype-object">%Function.prototype%</a></emu-xref>.</li>
|
||
<li>has the following properties:</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-map.groupby" type="built-in function">
|
||
<h1><span class="secnum">24.1.2.1</span> Map.groupBy ( <var>items</var>, <var>callback</var> )</h1>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p><var>callback</var> should be a function that accepts two arguments. <code>groupBy</code> calls <var>callback</var> once for each element in <var>items</var>, in ascending order, and constructs a new Map. Each value returned by <var>callback</var> is used as a key in the Map. For each such key, the result Map has an entry whose key is that key and whose value is an array containing all the elements for which <var>callback</var> returned that key.</p>
|
||
<p><var>callback</var> is called with two arguments: the value of the element and the index of the element.</p>
|
||
<p>The return value of <code>groupBy</code> is a Map.</p>
|
||
</div></emu-note>
|
||
<p>This function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>groups</var> be ? <emu-xref aoid="GroupBy" id="_ref_14158"><a href="abstract-operations.html#sec-groupby" class="e-user-code">GroupBy</a></emu-xref>(<var>items</var>, <var>callback</var>, <emu-const>collection</emu-const>).</li><li>Let <var>map</var> be ! <emu-xref aoid="Construct" id="_ref_14159"><a href="abstract-operations.html#sec-construct">Construct</a></emu-xref>(<emu-xref href="#sec-map-constructor" id="_ref_14160"><a href="keyed-collections.html#sec-map-constructor">%Map%</a></emu-xref>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14161"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Elements]]</var> } <var>g</var> of <var>groups</var>, do<ol><li>Let <var>elements</var> be <emu-xref aoid="CreateArrayFromList" id="_ref_14162"><a href="abstract-operations.html#sec-createarrayfromlist">CreateArrayFromList</a></emu-xref>(<var>g</var>.<var class="field">[[Elements]]</var>).</li><li>Let <var>entry</var> be the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14163"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>: <var>g</var>.<var class="field">[[Key]]</var>, <var class="field">[[Value]]</var>: <var>elements</var> }.</li><li>Append <var>entry</var> to <var>map</var>.<var class="field">[[MapData]]</var>.</li></ol></li><li>Return <var>map</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype">
|
||
<h1><span class="secnum">24.1.2.2</span> Map.prototype</h1>
|
||
<p>The initial value of <code>Map.prototype</code> is the <emu-xref href="#sec-properties-of-the-map-prototype-object" id="_ref_14164"><a href="keyed-collections.html#sec-properties-of-the-map-prototype-object">Map prototype object</a></emu-xref>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-get-map-@@species" id="sec-get-map-%symbol.species%" type="built-in function"><span id="sec-get-map-@@species"></span>
|
||
<h1><span class="secnum">24.1.2.3</span> get Map [ %Symbol.species% ]</h1>
|
||
<p><code>Map[%Symbol.species%]</code> is an <emu-xref href="#sec-object-type" id="_ref_14165"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Return the <emu-val>this</emu-val> value.</li></ol></emu-alg>
|
||
<p>The value of the <emu-val>"name"</emu-val> property of this function is <emu-val>"get [Symbol.species]"</emu-val>.</p>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>Methods that create derived collection objects should call <emu-xref href="#sec-well-known-symbols" id="_ref_14166"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref> to determine the <emu-xref href="#constructor" id="_ref_14167"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to use to create the derived objects. Subclass <emu-xref href="#constructor" id="_ref_14168"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> may over-ride <emu-xref href="#sec-well-known-symbols" id="_ref_14169"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref> to change the default <emu-xref href="#constructor" id="_ref_14170"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> assignment.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-map-prototype-object">
|
||
<h1><span class="secnum">24.1.3</span> Properties of the Map Prototype Object</h1>
|
||
<p>The <dfn tabindex="-1">Map prototype object</dfn>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%Map.prototype%</dfn>.</li>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_14171"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>.</li>
|
||
<li>is an <emu-xref href="#ordinary-object" id="_ref_14172"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
|
||
<li>does not have a <var class="field">[[MapData]]</var> internal slot.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-map.prototype.clear" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.1</span> Map.prototype.clear ( )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14173"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14174"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>Set <var>p</var>.<var class="field">[[Key]]</var> to <emu-const>empty</emu-const>.</li><li>Set <var>p</var>.<var class="field">[[Value]]</var> to <emu-const>empty</emu-const>.</li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>The existing <var class="field">[[MapData]]</var> <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14175"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> is preserved because there may be existing <emu-xref href="#sec-map-iterator-objects" id="_ref_14176"><a href="keyed-collections.html#sec-map-iterator-objects">Map Iterator objects</a></emu-xref> that are suspended midway through iterating over that <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14177"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.constructor">
|
||
<h1><span class="secnum">24.1.3.2</span> Map.prototype.constructor</h1>
|
||
<p>The initial value of <code>Map.prototype.constructor</code> is <emu-xref href="#sec-map-constructor" id="_ref_14178"><a href="keyed-collections.html#sec-map-constructor">%Map%</a></emu-xref>.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.delete" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.3</span> Map.prototype.delete ( <var>key</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14179"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>Set <var>key</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14180"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>key</var>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14181"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14182"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, then<ol><li>Set <var>p</var>.<var class="field">[[Key]]</var> to <emu-const>empty</emu-const>.</li><li>Set <var>p</var>.<var class="field">[[Value]]</var> to <emu-const>empty</emu-const>.</li><li>Return <emu-val>true</emu-val>.</li></ol></li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>The value <emu-const>empty</emu-const> is used as a specification device to indicate that an entry has been deleted. Actual implementations may take other actions such as physically removing the entry from internal data structures.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.entries" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.4</span> Map.prototype.entries ( )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Return ? <emu-xref aoid="CreateMapIterator" id="_ref_14183"><a href="keyed-collections.html#sec-createmapiterator">CreateMapIterator</a></emu-xref>(<var>M</var>, <emu-const>key+value</emu-const>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.foreach" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.5</span> Map.prototype.forEach ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14184"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14185"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>entries</var> be <var>M</var>.<var class="field">[[MapData]]</var>.</li><li>Let <var>numEntries</var> be the number of elements in <var>entries</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> < <var>numEntries</var>,<ol><li>Let <var>e</var> be <var>entries</var>[<var>index</var>].</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>e</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const>, then<ol><li>Perform ? <emu-xref aoid="Call" id="_ref_14186"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>e</var>.<var class="field">[[Value]]</var>, <var>e</var>.<var class="field">[[Key]]</var>, <var>M</var> »).</li><li>NOTE: The number of elements in <var>entries</var> may have increased during execution of <var>callback</var>.</li><li>Set <var>numEntries</var> to the number of elements in <var>entries</var>.</li></ol></li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p><var>callback</var> should be a function that accepts three arguments. <code>forEach</code> calls <var>callback</var> once for each key/value pair present in the Map, in key insertion order. <var>callback</var> is called only for keys of the Map which actually exist; it is not called for keys that have been deleted from the Map.</p>
|
||
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callback</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
|
||
<p><var>callback</var> is called with three arguments: the value of the item, the key of the item, and the Map being traversed.</p>
|
||
<p><code>forEach</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>. Each entry of a map's <var class="field">[[MapData]]</var> is only visited once. New keys added after the call to <code>forEach</code> begins are visited. A key will be revisited if it is deleted after it has been visited and then re-added before the <code>forEach</code> call completes. Keys that are deleted after the call to <code>forEach</code> begins and before being visited are not visited unless the key is added again before the <code>forEach</code> call completes.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.get" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.6</span> Map.prototype.get ( <var>key</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14187"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>Set <var>key</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14188"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>key</var>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14189"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14190"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <var>p</var>.<var class="field">[[Value]]</var>.</li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.getorinsert" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.7</span> Map.prototype.getOrInsert ( <var>key</var>, <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14191"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>Set <var>key</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14192"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>key</var>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14193"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14194"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <var>p</var>.<var class="field">[[Value]]</var>.</li></ol></li><li>Let <var>p</var> be the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14195"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>: <var>key</var>, <var class="field">[[Value]]</var>: <var>value</var> }.</li><li>Append <var>p</var> to <var>M</var>.<var class="field">[[MapData]]</var>.</li><li>Return <var>value</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.getorinsertcomputed" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.8</span> Map.prototype.getOrInsertComputed ( <var>key</var>, <var>callback</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14196"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14197"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Set <var>key</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14198"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>key</var>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14199"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14200"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <var>p</var>.<var class="field">[[Value]]</var>.</li></ol></li><li>Let <var>value</var> be ? <emu-xref aoid="Call" id="_ref_14201"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <emu-val>undefined</emu-val>, « <var>key</var> »).</li><li>NOTE: The Map may have been modified during execution of <var>callback</var>.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14202"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14203"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, then<ol><li>Set <var>p</var>.<var class="field">[[Value]]</var> to <var>value</var>.</li><li>Return <var>value</var>.</li></ol></li></ol></li><li>Let <var>p</var> be the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14204"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>: <var>key</var>, <var class="field">[[Value]]</var>: <var>value</var> }.</li><li>Append <var>p</var> to <var>M</var>.<var class="field">[[MapData]]</var>.</li><li>Return <var>value</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.has" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.9</span> Map.prototype.has ( <var>key</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14205"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>Set <var>key</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14206"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>key</var>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14207"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14208"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.keys" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.10</span> Map.prototype.keys ( )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Return ? <emu-xref aoid="CreateMapIterator" id="_ref_14209"><a href="keyed-collections.html#sec-createmapiterator">CreateMapIterator</a></emu-xref>(<var>M</var>, <emu-const>key</emu-const>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.set" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.11</span> Map.prototype.set ( <var>key</var>, <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14210"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>Set <var>key</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14211"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>key</var>).</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14212"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14213"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, then<ol><li>Set <var>p</var>.<var class="field">[[Value]]</var> to <var>value</var>.</li><li>Return <var>M</var>.</li></ol></li></ol></li><li>Let <var>p</var> be the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14214"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>: <var>key</var>, <var class="field">[[Value]]</var>: <var>value</var> }.</li><li>Append <var>p</var> to <var>M</var>.<var class="field">[[MapData]]</var>.</li><li>Return <var>M</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-get-map.prototype.size" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.12</span> get Map.prototype.size</h1>
|
||
<p><code>Map.prototype.size</code> is an <emu-xref href="#sec-object-type" id="_ref_14215"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14216"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>Let <var>count</var> be 0.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14217"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const>, set <var>count</var> to <var>count</var> + 1.</li></ol></li><li>Return <emu-xref aoid="𝔽" id="_ref_14218"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>count</var>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map.prototype.values" type="built-in function">
|
||
<h1><span class="secnum">24.1.3.13</span> Map.prototype.values ( )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Return ? <emu-xref aoid="CreateMapIterator" id="_ref_14219"><a href="keyed-collections.html#sec-createmapiterator">CreateMapIterator</a></emu-xref>(<var>M</var>, <emu-const>value</emu-const>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-map.prototype-@@iterator" id="sec-map.prototype-%symbol.iterator%" type="built-in function"><span id="sec-map.prototype-@@iterator"></span>
|
||
<h1><span class="secnum">24.1.3.14</span> Map.prototype [ %Symbol.iterator% ] ( )</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14220"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref> property is %Map.prototype.entries%, defined in <emu-xref href="#sec-map.prototype.entries" id="_ref_779"><a href="keyed-collections.html#sec-map.prototype.entries">24.1.3.4</a></emu-xref>.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-map.prototype-@@tostringtag" id="sec-map.prototype-%symbol.tostringtag%"><span id="sec-map.prototype-@@tostringtag"></span>
|
||
<h1><span class="secnum">24.1.3.15</span> Map.prototype [ %Symbol.toStringTag% ]</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14221"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.toStringTag%</a></emu-xref> property is the String value <emu-val>"Map"</emu-val>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-map-instances">
|
||
<h1><span class="secnum">24.1.4</span> Properties of Map Instances</h1>
|
||
<p>Map instances are <emu-xref href="#ordinary-object" id="_ref_14222"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary objects</a></emu-xref> that inherit properties from the <emu-xref href="#sec-properties-of-the-map-prototype-object" id="_ref_14223"><a href="keyed-collections.html#sec-properties-of-the-map-prototype-object">Map prototype object</a></emu-xref>. Map instances also have a <var class="field">[[MapData]]</var> internal slot.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-map-iterator-objects">
|
||
<h1><span class="secnum">24.1.5</span> Map Iterator Objects</h1>
|
||
<p>A <dfn variants="Map Iterators,Map Iterator object,Map Iterator objects" tabindex="-1">Map Iterator</dfn> is an object that represents a specific iteration over some specific Map instance object. There is not a named <emu-xref href="#constructor" id="_ref_14224"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> for Map Iterator objects. Instead, Map Iterator objects are created by calling certain methods of Map instance objects.</p>
|
||
|
||
<emu-clause id="sec-createmapiterator" type="abstract operation" oldids="sec-properties-of-map-iterator-instances,table-50,table-internal-slots-of-map-iterator-instances" aoid="CreateMapIterator"><span id="table-internal-slots-of-map-iterator-instances"></span><span id="table-50"></span><span id="sec-properties-of-map-iterator-instances"></span>
|
||
<h1><span class="secnum">24.1.5.1</span> CreateMapIterator ( <var>map</var>, <var>kind</var> )</h1>
|
||
<p>The abstract operation CreateMapIterator takes arguments <var>map</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14225"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and <var>kind</var> (<emu-const>key+value</emu-const>, <emu-const>key</emu-const>, or <emu-const>value</emu-const>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14226"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a Generator or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14227"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It is used to create <emu-xref href="#sec-iterator-interface" id="_ref_14228"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator objects</a></emu-xref> for Map methods that return such <emu-xref href="#sec-iterator-interface" id="_ref_14229"><a href="control-abstraction-objects.html#sec-iterator-interface">iterators</a></emu-xref>. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14230"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>map</var>, <var class="field">[[MapData]]</var>).</li><li>Let <var>closure</var> be a new <emu-xref href="#sec-abstract-closure" id="_ref_14231"><a href="ecmascript-data-types-and-values.html#sec-abstract-closure">Abstract Closure</a></emu-xref> with no parameters that captures <var>map</var> and <var>kind</var> and performs the following steps when called:<ol><li>Let <var>entries</var> be <var>map</var>.<var class="field">[[MapData]]</var>.</li><li>Let <var>index</var> be 0.</li><li>Let <var>numEntries</var> be the number of elements in <var>entries</var>.</li><li>Repeat, while <var>index</var> < <var>numEntries</var>,<ol><li>Let <var>e</var> be <var>entries</var>[<var>index</var>].</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>e</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const>, then<ol><li>If <var>kind</var> is <emu-const>key</emu-const>, then<ol><li>Let <var>result</var> be <var>e</var>.<var class="field">[[Key]]</var>.</li></ol></li><li>Else if <var>kind</var> is <emu-const>value</emu-const>, then<ol><li>Let <var>result</var> be <var>e</var>.<var class="field">[[Value]]</var>.</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_14232"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>kind</var> is <emu-const>key+value</emu-const>.</li><li>Let <var>result</var> be <emu-xref aoid="CreateArrayFromList" id="_ref_14233"><a href="abstract-operations.html#sec-createarrayfromlist">CreateArrayFromList</a></emu-xref>(« <var>e</var>.<var class="field">[[Key]]</var>, <var>e</var>.<var class="field">[[Value]]</var> »).</li></ol></li><li>Perform ? <emu-xref aoid="GeneratorYield" id="_ref_14234"><a href="control-abstraction-objects.html#sec-generatoryield">GeneratorYield</a></emu-xref>(<emu-xref aoid="CreateIteratorResultObject" id="_ref_14235"><a href="abstract-operations.html#sec-createiterresultobject">CreateIteratorResultObject</a></emu-xref>(<var>result</var>, <emu-val>false</emu-val>)).</li><li>NOTE: The number of elements in <var>entries</var> may have increased while execution of this abstract operation was paused by <emu-xref aoid="GeneratorYield" id="_ref_14236"><a href="control-abstraction-objects.html#sec-generatoryield">GeneratorYield</a></emu-xref>.</li><li>Set <var>numEntries</var> to the number of elements in <var>entries</var>.</li></ol></li></ol></li><li>Return <emu-xref aoid="NormalCompletion" id="_ref_14237"><a href="ecmascript-data-types-and-values.html#sec-normalcompletion">NormalCompletion</a></emu-xref>(<emu-const>unused</emu-const>).</li></ol></li><li>Return <emu-xref aoid="CreateIteratorFromClosure" id="_ref_14238"><a href="control-abstraction-objects.html#sec-createiteratorfromclosure">CreateIteratorFromClosure</a></emu-xref>(<var>closure</var>, <emu-val>"%MapIteratorPrototype%"</emu-val>, <emu-xref href="#sec-%mapiteratorprototype%-object" id="_ref_14239"><a href="keyed-collections.html#sec-%mapiteratorprototype%-object">%MapIteratorPrototype%</a></emu-xref>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-%mapiteratorprototype%-object">
|
||
<h1><span class="secnum">24.1.5.2</span> The %MapIteratorPrototype% Object</h1>
|
||
<p>The <dfn tabindex="-1">%MapIteratorPrototype%</dfn> object:</p>
|
||
<ul>
|
||
<li>has properties that are inherited by all <emu-xref href="#sec-map-iterator-objects" id="_ref_14240"><a href="keyed-collections.html#sec-map-iterator-objects">Map Iterator objects</a></emu-xref>.</li>
|
||
<li>is an <emu-xref href="#ordinary-object" id="_ref_14241"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-%iterator.prototype%-object" id="_ref_14242"><a href="control-abstraction-objects.html#sec-%iterator.prototype%-object">%Iterator.prototype%</a></emu-xref>.</li>
|
||
<li>has the following properties:</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-%mapiteratorprototype%.next" type="built-in function">
|
||
<h1><span class="secnum">24.1.5.2.1</span> %MapIteratorPrototype%.next ( )</h1>
|
||
<emu-alg><ol><li>Return ? <emu-xref aoid="GeneratorResume" id="_ref_14243"><a href="control-abstraction-objects.html#sec-generatorresume">GeneratorResume</a></emu-xref>(<emu-val>this</emu-val> value, <emu-const>empty</emu-const>, <emu-val>"%MapIteratorPrototype%"</emu-val>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-%mapiteratorprototype%-@@tostringtag" id="sec-%mapiteratorprototype%-%symbol.tostringtag%"><span id="sec-%mapiteratorprototype%-@@tostringtag"></span>
|
||
<h1><span class="secnum">24.1.5.2.2</span> %MapIteratorPrototype% [ %Symbol.toStringTag% ]</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14244"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.toStringTag%</a></emu-xref> property is the String value <emu-val>"Map Iterator"</emu-val>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set-objects">
|
||
<h1><span class="secnum">24.2</span> Set Objects</h1>
|
||
<p><dfn variants="Set object" tabindex="-1">Set objects</dfn> are collections of <emu-xref href="#sec-ecmascript-language-types" id="_ref_14245"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref>. A Set may contain each distinct value at most once. Distinct values are discriminated using the semantics of the <emu-xref aoid="SameValueZero" id="_ref_14246"><a href="abstract-operations.html#sec-samevaluezero">SameValueZero</a></emu-xref> comparison algorithm.</p>
|
||
<p>Set objects must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structure used in this specification is only intended to describe the required observable semantics of Set objects. It is not intended to be a viable implementation model.</p>
|
||
|
||
<emu-clause id="sec-abstract-operations-for-set-objects">
|
||
<h1><span class="secnum">24.2.1</span> Abstract Operations For Set Objects</h1>
|
||
|
||
<emu-clause id="sec-set-records">
|
||
<h1><span class="secnum">24.2.1.1</span> Set Records</h1>
|
||
<p>A <dfn variants="Set Records" tabindex="-1">Set Record</dfn> is a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14247"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> value used to encapsulate the interface of a Set or similar object.</p>
|
||
<p>Set Records have the fields listed in <emu-xref href="#table-set-record-fields" id="_ref_780"><a href="keyed-collections.html#table-set-record-fields">Table 71</a></emu-xref>.</p>
|
||
<emu-table id="table-set-record-fields" caption="Set Record Fields"><figure><figcaption>Table 71: <emu-xref href="#sec-set-records" id="_ref_14248"><a href="keyed-collections.html#sec-set-records">Set Record</a></emu-xref> Fields</figcaption>
|
||
<table>
|
||
<tbody><tr>
|
||
<th>
|
||
Field Name
|
||
</th>
|
||
<th>
|
||
Value
|
||
</th>
|
||
<th>
|
||
Meaning
|
||
</th>
|
||
</tr>
|
||
<tr>
|
||
<td>
|
||
<var class="field">[[SetObject]]</var>
|
||
</td>
|
||
<td>
|
||
an Object
|
||
</td>
|
||
<td>
|
||
the Set or similar object.
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td>
|
||
<var class="field">[[Size]]</var>
|
||
</td>
|
||
<td>
|
||
a non-negative <emu-xref href="#integer" id="_ref_14249"><a href="notational-conventions.html#integer">integer</a></emu-xref> or +∞
|
||
</td>
|
||
<td>
|
||
The reported size of the object.
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td>
|
||
<var class="field">[[Has]]</var>
|
||
</td>
|
||
<td>
|
||
a <emu-xref href="#function-object" id="_ref_14250"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref>
|
||
</td>
|
||
<td>
|
||
The <code>has</code> method of the object.
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td>
|
||
<var class="field">[[Keys]]</var>
|
||
</td>
|
||
<td>
|
||
a <emu-xref href="#function-object" id="_ref_14251"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref>
|
||
</td>
|
||
<td>
|
||
The <code>keys</code> method of the object.
|
||
</td>
|
||
</tr>
|
||
</tbody></table>
|
||
</figure></emu-table>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-getsetrecord" type="abstract operation" aoid="GetSetRecord">
|
||
<h1><span class="secnum">24.2.1.2</span> GetSetRecord ( <var>obj</var> )</h1>
|
||
<p>The abstract operation GetSetRecord takes argument <var>obj</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14252"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14253"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#sec-set-records" id="_ref_14254"><a href="keyed-collections.html#sec-set-records">Set Record</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14255"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>If <var>obj</var> <emu-xref href="#sec-object-type" id="_ref_14256"><a href="ecmascript-data-types-and-values.html#sec-object-type">is not an Object</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>rawSize</var> be ? <emu-xref aoid="Get" id="_ref_14257"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>obj</var>, <emu-val>"size"</emu-val>).</li><li>Let <var>numSize</var> be ? <emu-xref aoid="ToNumber" id="_ref_14258"><a href="abstract-operations.html#sec-tonumber" class="e-user-code">ToNumber</a></emu-xref>(<var>rawSize</var>).</li><li>NOTE: If <var>rawSize</var> is <emu-val>undefined</emu-val>, then <var>numSize</var> will be <emu-val>NaN</emu-val>.</li><li>If <var>numSize</var> is <emu-val>NaN</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>intSize</var> be ! <emu-xref aoid="ToIntegerOrInfinity" id="_ref_14259"><a href="abstract-operations.html#sec-tointegerorinfinity">ToIntegerOrInfinity</a></emu-xref>(<var>numSize</var>).</li><li>If <var>intSize</var> < 0, throw a <emu-val>RangeError</emu-val> exception.</li><li>Let <var>has</var> be ? <emu-xref aoid="Get" id="_ref_14260"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>obj</var>, <emu-val>"has"</emu-val>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14261"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>has</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>keys</var> be ? <emu-xref aoid="Get" id="_ref_14262"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>obj</var>, <emu-val>"keys"</emu-val>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14263"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>keys</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Return a new <emu-xref href="#sec-set-records" id="_ref_14264"><a href="keyed-collections.html#sec-set-records">Set Record</a></emu-xref> { <var class="field">[[SetObject]]</var>: <var>obj</var>, <var class="field">[[Size]]</var>: <var>intSize</var>, <var class="field">[[Has]]</var>: <var>has</var>, <var class="field">[[Keys]]</var>: <var>keys</var> }.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-setdatahas" type="abstract operation" aoid="SetDataHas">
|
||
<h1><span class="secnum">24.2.1.3</span> SetDataHas ( <var>setData</var>, <var>value</var> )</h1>
|
||
<p>The abstract operation SetDataHas takes arguments <var>setData</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14265"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of either <emu-xref href="#sec-ecmascript-language-types" id="_ref_14266"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref> or <emu-const>empty</emu-const>) and <var>value</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14267"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns a Boolean. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>If <emu-xref aoid="SetDataIndex" id="_ref_14268"><a href="keyed-collections.html#sec-setdataindex">SetDataIndex</a></emu-xref>(<var>setData</var>, <var>value</var>) is <emu-const>not-found</emu-const>, return <emu-val>false</emu-val>.</li><li>Return <emu-val>true</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-setdataindex" type="abstract operation" aoid="SetDataIndex">
|
||
<h1><span class="secnum">24.2.1.4</span> SetDataIndex ( <var>setData</var>, <var>value</var> )</h1>
|
||
<p>The abstract operation SetDataIndex takes arguments <var>setData</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14269"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of either <emu-xref href="#sec-ecmascript-language-types" id="_ref_14270"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref> or <emu-const>empty</emu-const>) and <var>value</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14271"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns a non-negative <emu-xref href="#integer" id="_ref_14272"><a href="notational-conventions.html#integer">integer</a></emu-xref> or <emu-const>not-found</emu-const>. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Set <var>value</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14273"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>value</var>).</li><li>Let <var>size</var> be the number of elements in <var>setData</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> < <var>size</var>,<ol><li>Let <var>e</var> be <var>setData</var>[<var>index</var>].</li><li>If <var>e</var> is not <emu-const>empty</emu-const> and <var>e</var> is <var>value</var>, then<ol><li>Return <var>index</var>.</li></ol></li><li>Set <var>index</var> to <var>index</var> + 1.</li></ol></li><li>Return <emu-const>not-found</emu-const>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-setdatasize" type="abstract operation" aoid="SetDataSize">
|
||
<h1><span class="secnum">24.2.1.5</span> SetDataSize ( <var>setData</var> )</h1>
|
||
<p>The abstract operation SetDataSize takes argument <var>setData</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14274"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of either <emu-xref href="#sec-ecmascript-language-types" id="_ref_14275"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref> or <emu-const>empty</emu-const>) and returns a non-negative <emu-xref href="#integer" id="_ref_14276"><a href="notational-conventions.html#integer">integer</a></emu-xref>. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>count</var> be 0.</li><li>For each element <var>e</var> of <var>setData</var>, do<ol><li>If <var>e</var> is not <emu-const>empty</emu-const>, set <var>count</var> to <var>count</var> + 1.</li></ol></li><li>Return <var>count</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set-constructor">
|
||
<h1><span class="secnum">24.2.2</span> The Set Constructor</h1>
|
||
<p>The Set <emu-xref href="#constructor" id="_ref_14277"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%Set%</dfn>.</li>
|
||
<li>is the initial value of the <emu-val>"Set"</emu-val> property of the <emu-xref href="#sec-global-object" id="_ref_14278"><a href="global-object.html#sec-global-object">global object</a></emu-xref>.</li>
|
||
<li>creates and initializes a new <emu-xref href="#sec-set-objects" id="_ref_14279"><a href="keyed-collections.html#sec-set-objects">Set object</a></emu-xref> when called as a <emu-xref href="#constructor" id="_ref_14280"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>.</li>
|
||
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
|
||
<li>may be used as the value in an <code>extends</code> clause of a class definition. Subclass <emu-xref href="#constructor" id="_ref_14281"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that intend to inherit the specified Set behaviour must include a <code>super</code> call to the Set <emu-xref href="#constructor" id="_ref_14282"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to create and initialize the subclass instance with the internal state necessary to support the <code>Set.prototype</code> built-in methods.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-set-iterable" type="built-in function">
|
||
<h1><span class="secnum">24.2.2.1</span> Set ( [ <var>iterable</var> ] )</h1>
|
||
<p>This function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>If NewTarget is <emu-val>undefined</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>set</var> be ? <emu-xref aoid="OrdinaryCreateFromConstructor" id="_ref_14283"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinarycreatefromconstructor" class="e-user-code">OrdinaryCreateFromConstructor</a></emu-xref>(NewTarget, <emu-val>"%Set.prototype%"</emu-val>, « <var class="field">[[SetData]]</var> »).</li><li>Set <var>set</var>.<var class="field">[[SetData]]</var> to a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14284"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>If <var>iterable</var> is either <emu-val>undefined</emu-val> or <emu-val>null</emu-val>, return <var>set</var>.</li><li>Let <var>adder</var> be ? <emu-xref aoid="Get" id="_ref_14285"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>set</var>, <emu-val>"add"</emu-val>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14286"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>adder</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>iteratorRecord</var> be ? <emu-xref aoid="GetIterator" id="_ref_14287"><a href="abstract-operations.html#sec-getiterator" class="e-user-code">GetIterator</a></emu-xref>(<var>iterable</var>, <emu-const>sync</emu-const>).</li><li>Repeat,<ol><li>Let <var>next</var> be ? <emu-xref aoid="IteratorStepValue" id="_ref_14288"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>iteratorRecord</var>).</li><li>If <var>next</var> is <emu-const>done</emu-const>, return <var>set</var>.</li><li>Let <var>status</var> be <emu-xref aoid="Completion" id="_ref_14289"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Call" id="_ref_14290"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>adder</var>, <var>set</var>, « <var>next</var> »)).</li><li><emu-xref aoid="IfAbruptCloseIterator" id="_ref_14291"><a href="abstract-operations.html#sec-ifabruptcloseiterator" class="e-user-code">IfAbruptCloseIterator</a></emu-xref>(<var>status</var>, <var>iteratorRecord</var>).</li></ol></li></ol></emu-alg>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-set-constructor">
|
||
<h1><span class="secnum">24.2.3</span> Properties of the Set Constructor</h1>
|
||
<p>The Set <emu-xref href="#constructor" id="_ref_14292"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-function-prototype-object" id="_ref_14293"><a href="fundamental-objects.html#sec-properties-of-the-function-prototype-object">%Function.prototype%</a></emu-xref>.</li>
|
||
<li>has the following properties:</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-set.prototype">
|
||
<h1><span class="secnum">24.2.3.1</span> Set.prototype</h1>
|
||
<p>The initial value of <code>Set.prototype</code> is the <emu-xref href="#sec-properties-of-the-set-prototype-object" id="_ref_14294"><a href="keyed-collections.html#sec-properties-of-the-set-prototype-object">Set prototype object</a></emu-xref>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-get-set-@@species" id="sec-get-set-%symbol.species%" type="built-in function"><span id="sec-get-set-@@species"></span>
|
||
<h1><span class="secnum">24.2.3.2</span> get Set [ %Symbol.species% ]</h1>
|
||
<p><code>Set[%Symbol.species%]</code> is an <emu-xref href="#sec-object-type" id="_ref_14295"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Return the <emu-val>this</emu-val> value.</li></ol></emu-alg>
|
||
<p>The value of the <emu-val>"name"</emu-val> property of this function is <emu-val>"get [Symbol.species]"</emu-val>.</p>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>Methods that create derived collection objects should call <emu-xref href="#sec-well-known-symbols" id="_ref_14296"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref> to determine the <emu-xref href="#constructor" id="_ref_14297"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to use to create the derived objects. Subclass <emu-xref href="#constructor" id="_ref_14298"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> may over-ride <emu-xref href="#sec-well-known-symbols" id="_ref_14299"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref> to change the default <emu-xref href="#constructor" id="_ref_14300"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> assignment.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-set-prototype-object">
|
||
<h1><span class="secnum">24.2.4</span> Properties of the Set Prototype Object</h1>
|
||
<p>The <dfn tabindex="-1">Set prototype object</dfn>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%Set.prototype%</dfn>.</li>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_14301"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>.</li>
|
||
<li>is an <emu-xref href="#ordinary-object" id="_ref_14302"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
|
||
<li>does not have a <var class="field">[[SetData]]</var> internal slot.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-set.prototype.add" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.1</span> Set.prototype.add ( <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14303"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[SetData]]</var>).</li><li>Set <var>value</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14304"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>value</var>).</li><li>For each element <var>e</var> of <var>S</var>.<var class="field">[[SetData]]</var>, do<ol><li>If <var>e</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14305"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>e</var>, <var>value</var>) is <emu-val>true</emu-val>, then<ol><li>Return <var>S</var>.</li></ol></li></ol></li><li>Append <var>value</var> to <var>S</var>.<var class="field">[[SetData]]</var>.</li><li>Return <var>S</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.clear" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.2</span> Set.prototype.clear ( )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14306"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[SetData]]</var>).</li><li>For each element <var>e</var> of <var>S</var>.<var class="field">[[SetData]]</var>, do<ol><li>Replace the element of <var>S</var>.<var class="field">[[SetData]]</var> whose value is <var>e</var> with an element whose value is <emu-const>empty</emu-const>.</li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>The existing <var class="field">[[SetData]]</var> <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14307"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> is preserved because there may be existing <emu-xref href="#sec-set-iterator-objects" id="_ref_14308"><a href="keyed-collections.html#sec-set-iterator-objects">Set Iterator objects</a></emu-xref> that are suspended midway through iterating over that <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14309"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.constructor">
|
||
<h1><span class="secnum">24.2.4.3</span> Set.prototype.constructor</h1>
|
||
<p>The initial value of <code>Set.prototype.constructor</code> is <emu-xref href="#sec-set-constructor" id="_ref_14310"><a href="keyed-collections.html#sec-set-constructor">%Set%</a></emu-xref>.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.delete" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.4</span> Set.prototype.delete ( <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14311"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[SetData]]</var>).</li><li>Set <var>value</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14312"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>value</var>).</li><li>For each element <var>e</var> of <var>S</var>.<var class="field">[[SetData]]</var>, do<ol><li>If <var>e</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14313"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>e</var>, <var>value</var>) is <emu-val>true</emu-val>, then<ol><li>Replace the element of <var>S</var>.<var class="field">[[SetData]]</var> whose value is <var>e</var> with an element whose value is <emu-const>empty</emu-const>.</li><li>Return <emu-val>true</emu-val>.</li></ol></li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>The value <emu-const>empty</emu-const> is used as a specification device to indicate that an entry has been deleted. Actual implementations may take other actions such as physically removing the entry from internal data structures.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.difference" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.5</span> Set.prototype.difference ( <var>other</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14314"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>otherRec</var> be ? <emu-xref aoid="GetSetRecord" id="_ref_14315"><a href="keyed-collections.html#sec-getsetrecord" class="e-user-code">GetSetRecord</a></emu-xref>(<var>other</var>).</li><li>Let <var>resultSetData</var> be a copy of <var>O</var>.<var class="field">[[SetData]]</var>.</li><li>If <emu-xref aoid="SetDataSize" id="_ref_14316"><a href="keyed-collections.html#sec-setdatasize">SetDataSize</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>) ≤ <var>otherRec</var>.<var class="field">[[Size]]</var>, then<ol><li>Let <var>thisSize</var> be the number of elements in <var>O</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> < <var>thisSize</var>,<ol><li>Let <var>e</var> be <var>resultSetData</var>[<var>index</var>].</li><li>If <var>e</var> is not <emu-const>empty</emu-const>, then<ol><li>Let <var>inOther</var> be <emu-xref aoid="ToBoolean" id="_ref_14317"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_14318"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>otherRec</var>.<var class="field">[[Has]]</var>, <var>otherRec</var>.<var class="field">[[SetObject]]</var>, « <var>e</var> »)).</li><li>If <var>inOther</var> is <emu-val>true</emu-val>, then<ol><li>Set <var>resultSetData</var>[<var>index</var>] to <emu-const>empty</emu-const>.</li></ol></li></ol></li><li>Set <var>index</var> to <var>index</var> + 1.</li></ol></li></ol></li><li>Else,<ol><li>Let <var>keysIter</var> be ? <emu-xref aoid="GetIteratorFromMethod" id="_ref_14319"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>otherRec</var>.<var class="field">[[SetObject]]</var>, <var>otherRec</var>.<var class="field">[[Keys]]</var>).</li><li>Let <var>next</var> be <emu-const>not-started</emu-const>.</li><li>Repeat, while <var>next</var> is not <emu-const>done</emu-const>,<ol><li>Set <var>next</var> to ? <emu-xref aoid="IteratorStepValue" id="_ref_14320"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>keysIter</var>).</li><li>If <var>next</var> is not <emu-const>done</emu-const>, then<ol><li>Set <var>next</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14321"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>next</var>).</li><li>Let <var>valueIndex</var> be <emu-xref aoid="SetDataIndex" id="_ref_14322"><a href="keyed-collections.html#sec-setdataindex">SetDataIndex</a></emu-xref>(<var>resultSetData</var>, <var>next</var>).</li><li>If <var>valueIndex</var> is not <emu-const>not-found</emu-const>, then<ol><li>Set <var>resultSetData</var>[<var>valueIndex</var>] to <emu-const>empty</emu-const>.</li></ol></li></ol></li></ol></li></ol></li><li>Let <var>result</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_14323"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-set-prototype-object" id="_ref_14324"><a href="keyed-collections.html#sec-properties-of-the-set-prototype-object">%Set.prototype%</a></emu-xref>, « <var class="field">[[SetData]]</var> »).</li><li>Set <var>result</var>.<var class="field">[[SetData]]</var> to <var>resultSetData</var>.</li><li>Return <var>result</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.entries" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.6</span> Set.prototype.entries ( )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Return ? <emu-xref aoid="CreateSetIterator" id="_ref_14325"><a href="keyed-collections.html#sec-createsetiterator">CreateSetIterator</a></emu-xref>(<var>S</var>, <emu-const>key+value</emu-const>).</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>For iteration purposes, a Set appears similar to a Map where each entry has the same value for its key and value.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.foreach" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.7</span> Set.prototype.forEach ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14326"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[SetData]]</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14327"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>entries</var> be <var>S</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>numEntries</var> be the number of elements in <var>entries</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> < <var>numEntries</var>,<ol><li>Let <var>e</var> be <var>entries</var>[<var>index</var>].</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>e</var> is not <emu-const>empty</emu-const>, then<ol><li>Perform ? <emu-xref aoid="Call" id="_ref_14328"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>e</var>, <var>e</var>, <var>S</var> »).</li><li>NOTE: The number of elements in <var>entries</var> may have increased during execution of <var>callback</var>.</li><li>Set <var>numEntries</var> to the number of elements in <var>entries</var>.</li></ol></li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p><var>callback</var> should be a function that accepts three arguments. <code>forEach</code> calls <var>callback</var> once for each value present in the <emu-xref href="#sec-set-objects" id="_ref_14329"><a href="keyed-collections.html#sec-set-objects">Set object</a></emu-xref>, in value insertion order. <var>callback</var> is called only for values of the Set which actually exist; it is not called for keys that have been deleted from the set.</p>
|
||
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callback</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
|
||
<p><var>callback</var> is called with three arguments: the first two arguments are a value contained in the Set. The same value is passed for both arguments. The <emu-xref href="#sec-set-objects" id="_ref_14330"><a href="keyed-collections.html#sec-set-objects">Set object</a></emu-xref> being traversed is passed as the third argument.</p>
|
||
<p>The <var>callback</var> is called with three arguments to be consistent with the call back functions used by <code>forEach</code> methods for Map and Array. For Sets, each item value is considered to be both the key and the value.</p>
|
||
<p><code>forEach</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
|
||
<p>Each value is normally visited only once. However, a value will be revisited if it is deleted after it has been visited and then re-added before the <code>forEach</code> call completes. Values that are deleted after the call to <code>forEach</code> begins and before being visited are not visited unless the value is added again before the <code>forEach</code> call completes. New values added after the call to <code>forEach</code> begins are visited.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.has" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.8</span> Set.prototype.has ( <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14331"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[SetData]]</var>).</li><li>Set <var>value</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14332"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>value</var>).</li><li>For each element <var>e</var> of <var>S</var>.<var class="field">[[SetData]]</var>, do<ol><li>If <var>e</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14333"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>e</var>, <var>value</var>) is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.intersection" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.9</span> Set.prototype.intersection ( <var>other</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14334"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>otherRec</var> be ? <emu-xref aoid="GetSetRecord" id="_ref_14335"><a href="keyed-collections.html#sec-getsetrecord" class="e-user-code">GetSetRecord</a></emu-xref>(<var>other</var>).</li><li>Let <var>resultSetData</var> be a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14336"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>If <emu-xref aoid="SetDataSize" id="_ref_14337"><a href="keyed-collections.html#sec-setdatasize">SetDataSize</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>) ≤ <var>otherRec</var>.<var class="field">[[Size]]</var>, then<ol><li>Let <var>thisSize</var> be the number of elements in <var>O</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> < <var>thisSize</var>,<ol><li>Let <var>e</var> be <var>O</var>.<var class="field">[[SetData]]</var>[<var>index</var>].</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>e</var> is not <emu-const>empty</emu-const>, then<ol><li>Let <var>inOther</var> be <emu-xref aoid="ToBoolean" id="_ref_14338"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_14339"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>otherRec</var>.<var class="field">[[Has]]</var>, <var>otherRec</var>.<var class="field">[[SetObject]]</var>, « <var>e</var> »)).</li><li>If <var>inOther</var> is <emu-val>true</emu-val>, then<ol><li>NOTE: It is possible for earlier calls to <var>otherRec</var>.<var class="field">[[Has]]</var> to remove and re-add an element of <var>O</var>.<var class="field">[[SetData]]</var>, which can cause the same element to be visited twice during this iteration.</li><li>If <emu-xref aoid="SetDataHas" id="_ref_14340"><a href="keyed-collections.html#sec-setdatahas">SetDataHas</a></emu-xref>(<var>resultSetData</var>, <var>e</var>) is <emu-val>false</emu-val>, then<ol><li>Append <var>e</var> to <var>resultSetData</var>.</li></ol></li></ol></li><li>NOTE: The number of elements in <var>O</var>.<var class="field">[[SetData]]</var> may have increased during execution of <var>otherRec</var>.<var class="field">[[Has]]</var>.</li><li>Set <var>thisSize</var> to the number of elements in <var>O</var>.<var class="field">[[SetData]]</var>.</li></ol></li></ol></li></ol></li><li>Else,<ol><li>Let <var>keysIter</var> be ? <emu-xref aoid="GetIteratorFromMethod" id="_ref_14341"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>otherRec</var>.<var class="field">[[SetObject]]</var>, <var>otherRec</var>.<var class="field">[[Keys]]</var>).</li><li>Let <var>next</var> be <emu-const>not-started</emu-const>.</li><li>Repeat, while <var>next</var> is not <emu-const>done</emu-const>,<ol><li>Set <var>next</var> to ? <emu-xref aoid="IteratorStepValue" id="_ref_14342"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>keysIter</var>).</li><li>If <var>next</var> is not <emu-const>done</emu-const>, then<ol><li>Set <var>next</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14343"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>next</var>).</li><li>Let <var>inThis</var> be <emu-xref aoid="SetDataHas" id="_ref_14344"><a href="keyed-collections.html#sec-setdatahas">SetDataHas</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>, <var>next</var>).</li><li>If <var>inThis</var> is <emu-val>true</emu-val>, then<ol><li>NOTE: Because <var>other</var> is an arbitrary object, it is possible for its <emu-val>"keys"</emu-val> <emu-xref href="#sec-iterator-interface" id="_ref_14345"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator</a></emu-xref> to produce the same value more than once.</li><li>If <emu-xref aoid="SetDataHas" id="_ref_14346"><a href="keyed-collections.html#sec-setdatahas">SetDataHas</a></emu-xref>(<var>resultSetData</var>, <var>next</var>) is <emu-val>false</emu-val>, then<ol><li>Append <var>next</var> to <var>resultSetData</var>.</li></ol></li></ol></li></ol></li></ol></li></ol></li><li>Let <var>result</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_14347"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-set-prototype-object" id="_ref_14348"><a href="keyed-collections.html#sec-properties-of-the-set-prototype-object">%Set.prototype%</a></emu-xref>, « <var class="field">[[SetData]]</var> »).</li><li>Set <var>result</var>.<var class="field">[[SetData]]</var> to <var>resultSetData</var>.</li><li>Return <var>result</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.isdisjointfrom" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.10</span> Set.prototype.isDisjointFrom ( <var>other</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14349"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>otherRec</var> be ? <emu-xref aoid="GetSetRecord" id="_ref_14350"><a href="keyed-collections.html#sec-getsetrecord" class="e-user-code">GetSetRecord</a></emu-xref>(<var>other</var>).</li><li>If <emu-xref aoid="SetDataSize" id="_ref_14351"><a href="keyed-collections.html#sec-setdatasize">SetDataSize</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>) ≤ <var>otherRec</var>.<var class="field">[[Size]]</var>, then<ol><li>Let <var>thisSize</var> be the number of elements in <var>O</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> < <var>thisSize</var>,<ol><li>Let <var>e</var> be <var>O</var>.<var class="field">[[SetData]]</var>[<var>index</var>].</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>e</var> is not <emu-const>empty</emu-const>, then<ol><li>Let <var>inOther</var> be <emu-xref aoid="ToBoolean" id="_ref_14352"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_14353"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>otherRec</var>.<var class="field">[[Has]]</var>, <var>otherRec</var>.<var class="field">[[SetObject]]</var>, « <var>e</var> »)).</li><li>If <var>inOther</var> is <emu-val>true</emu-val>, return <emu-val>false</emu-val>.</li><li>NOTE: The number of elements in <var>O</var>.<var class="field">[[SetData]]</var> may have increased during execution of <var>otherRec</var>.<var class="field">[[Has]]</var>.</li><li>Set <var>thisSize</var> to the number of elements in <var>O</var>.<var class="field">[[SetData]]</var>.</li></ol></li></ol></li></ol></li><li>Else,<ol><li>Let <var>keysIter</var> be ? <emu-xref aoid="GetIteratorFromMethod" id="_ref_14354"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>otherRec</var>.<var class="field">[[SetObject]]</var>, <var>otherRec</var>.<var class="field">[[Keys]]</var>).</li><li>Let <var>next</var> be <emu-const>not-started</emu-const>.</li><li>Repeat, while <var>next</var> is not <emu-const>done</emu-const>,<ol><li>Set <var>next</var> to ? <emu-xref aoid="IteratorStepValue" id="_ref_14355"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>keysIter</var>).</li><li>If <var>next</var> is not <emu-const>done</emu-const>, then<ol><li>If <emu-xref aoid="SetDataHas" id="_ref_14356"><a href="keyed-collections.html#sec-setdatahas">SetDataHas</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>, <var>next</var>) is <emu-val>true</emu-val>, then<ol><li>Perform ? <emu-xref aoid="IteratorClose" id="_ref_14357"><a href="abstract-operations.html#sec-iteratorclose" class="e-user-code">IteratorClose</a></emu-xref>(<var>keysIter</var>, <emu-xref aoid="NormalCompletion" id="_ref_14358"><a href="ecmascript-data-types-and-values.html#sec-normalcompletion">NormalCompletion</a></emu-xref>(<emu-const>unused</emu-const>)).</li><li>Return <emu-val>false</emu-val>.</li></ol></li></ol></li></ol></li></ol></li><li>Return <emu-val>true</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.issubsetof" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.11</span> Set.prototype.isSubsetOf ( <var>other</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14359"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>otherRec</var> be ? <emu-xref aoid="GetSetRecord" id="_ref_14360"><a href="keyed-collections.html#sec-getsetrecord" class="e-user-code">GetSetRecord</a></emu-xref>(<var>other</var>).</li><li>If <emu-xref aoid="SetDataSize" id="_ref_14361"><a href="keyed-collections.html#sec-setdatasize">SetDataSize</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>) > <var>otherRec</var>.<var class="field">[[Size]]</var>, return <emu-val>false</emu-val>.</li><li>Let <var>thisSize</var> be the number of elements in <var>O</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> < <var>thisSize</var>,<ol><li>Let <var>e</var> be <var>O</var>.<var class="field">[[SetData]]</var>[<var>index</var>].</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>e</var> is not <emu-const>empty</emu-const>, then<ol><li>Let <var>inOther</var> be <emu-xref aoid="ToBoolean" id="_ref_14362"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_14363"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>otherRec</var>.<var class="field">[[Has]]</var>, <var>otherRec</var>.<var class="field">[[SetObject]]</var>, « <var>e</var> »)).</li><li>If <var>inOther</var> is <emu-val>false</emu-val>, return <emu-val>false</emu-val>.</li><li>NOTE: The number of elements in <var>O</var>.<var class="field">[[SetData]]</var> may have increased during execution of <var>otherRec</var>.<var class="field">[[Has]]</var>.</li><li>Set <var>thisSize</var> to the number of elements in <var>O</var>.<var class="field">[[SetData]]</var>.</li></ol></li></ol></li><li>Return <emu-val>true</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.issupersetof" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.12</span> Set.prototype.isSupersetOf ( <var>other</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14364"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>otherRec</var> be ? <emu-xref aoid="GetSetRecord" id="_ref_14365"><a href="keyed-collections.html#sec-getsetrecord" class="e-user-code">GetSetRecord</a></emu-xref>(<var>other</var>).</li><li>If <emu-xref aoid="SetDataSize" id="_ref_14366"><a href="keyed-collections.html#sec-setdatasize">SetDataSize</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>) < <var>otherRec</var>.<var class="field">[[Size]]</var>, return <emu-val>false</emu-val>.</li><li>Let <var>keysIter</var> be ? <emu-xref aoid="GetIteratorFromMethod" id="_ref_14367"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>otherRec</var>.<var class="field">[[SetObject]]</var>, <var>otherRec</var>.<var class="field">[[Keys]]</var>).</li><li>Let <var>next</var> be <emu-const>not-started</emu-const>.</li><li>Repeat, while <var>next</var> is not <emu-const>done</emu-const>,<ol><li>Set <var>next</var> to ? <emu-xref aoid="IteratorStepValue" id="_ref_14368"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>keysIter</var>).</li><li>If <var>next</var> is not <emu-const>done</emu-const>, then<ol><li>If <emu-xref aoid="SetDataHas" id="_ref_14369"><a href="keyed-collections.html#sec-setdatahas">SetDataHas</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>, <var>next</var>) is <emu-val>false</emu-val>, then<ol><li>Perform ? <emu-xref aoid="IteratorClose" id="_ref_14370"><a href="abstract-operations.html#sec-iteratorclose" class="e-user-code">IteratorClose</a></emu-xref>(<var>keysIter</var>, <emu-xref aoid="NormalCompletion" id="_ref_14371"><a href="ecmascript-data-types-and-values.html#sec-normalcompletion">NormalCompletion</a></emu-xref>(<emu-const>unused</emu-const>)).</li><li>Return <emu-val>false</emu-val>.</li></ol></li></ol></li></ol></li><li>Return <emu-val>true</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.keys" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.13</span> Set.prototype.keys ( )</h1>
|
||
<p>The initial value of the <emu-val>"keys"</emu-val> property is %Set.prototype.values%, defined in <emu-xref href="#sec-set.prototype.values" id="_ref_781"><a href="keyed-collections.html#sec-set.prototype.values">24.2.4.17</a></emu-xref>.</p>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>For iteration purposes, a Set appears similar to a Map where each entry has the same value for its key and value.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-get-set.prototype.size" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.14</span> get Set.prototype.size</h1>
|
||
<p><code>Set.prototype.size</code> is an <emu-xref href="#sec-object-type" id="_ref_14372"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14373"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>size</var> be <emu-xref aoid="SetDataSize" id="_ref_14374"><a href="keyed-collections.html#sec-setdatasize">SetDataSize</a></emu-xref>(<var>S</var>.<var class="field">[[SetData]]</var>).</li><li>Return <emu-xref aoid="𝔽" id="_ref_14375"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>size</var>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.symmetricdifference" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.15</span> Set.prototype.symmetricDifference ( <var>other</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14376"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>otherRec</var> be ? <emu-xref aoid="GetSetRecord" id="_ref_14377"><a href="keyed-collections.html#sec-getsetrecord" class="e-user-code">GetSetRecord</a></emu-xref>(<var>other</var>).</li><li>Let <var>keysIter</var> be ? <emu-xref aoid="GetIteratorFromMethod" id="_ref_14378"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>otherRec</var>.<var class="field">[[SetObject]]</var>, <var>otherRec</var>.<var class="field">[[Keys]]</var>).</li><li>Let <var>resultSetData</var> be a copy of <var>O</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>next</var> be <emu-const>not-started</emu-const>.</li><li>Repeat, while <var>next</var> is not <emu-const>done</emu-const>,<ol><li>Set <var>next</var> to ? <emu-xref aoid="IteratorStepValue" id="_ref_14379"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>keysIter</var>).</li><li>If <var>next</var> is not <emu-const>done</emu-const>, then<ol><li>Set <var>next</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14380"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>next</var>).</li><li>Let <var>resultIndex</var> be <emu-xref aoid="SetDataIndex" id="_ref_14381"><a href="keyed-collections.html#sec-setdataindex">SetDataIndex</a></emu-xref>(<var>resultSetData</var>, <var>next</var>).</li><li>If <var>resultIndex</var> is <emu-const>not-found</emu-const>, let <var>alreadyInResult</var> be <emu-val>false</emu-val>; else let <var>alreadyInResult</var> be <emu-val>true</emu-val>.</li><li>If <emu-xref aoid="SetDataHas" id="_ref_14382"><a href="keyed-collections.html#sec-setdatahas">SetDataHas</a></emu-xref>(<var>O</var>.<var class="field">[[SetData]]</var>, <var>next</var>) is <emu-val>true</emu-val>, then<ol><li>If <var>alreadyInResult</var> is <emu-val>true</emu-val>, set <var>resultSetData</var>[<var>resultIndex</var>] to <emu-const>empty</emu-const>.</li></ol></li><li>Else,<ol><li>If <var>alreadyInResult</var> is <emu-val>false</emu-val>, append <var>next</var> to <var>resultSetData</var>.</li></ol></li></ol></li></ol></li><li>Let <var>result</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_14383"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-set-prototype-object" id="_ref_14384"><a href="keyed-collections.html#sec-properties-of-the-set-prototype-object">%Set.prototype%</a></emu-xref>, « <var class="field">[[SetData]]</var> »).</li><li>Set <var>result</var>.<var class="field">[[SetData]]</var> to <var>resultSetData</var>.</li><li>Return <var>result</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.union" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.16</span> Set.prototype.union ( <var>other</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14385"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>otherRec</var> be ? <emu-xref aoid="GetSetRecord" id="_ref_14386"><a href="keyed-collections.html#sec-getsetrecord" class="e-user-code">GetSetRecord</a></emu-xref>(<var>other</var>).</li><li>Let <var>keysIter</var> be ? <emu-xref aoid="GetIteratorFromMethod" id="_ref_14387"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>otherRec</var>.<var class="field">[[SetObject]]</var>, <var>otherRec</var>.<var class="field">[[Keys]]</var>).</li><li>Let <var>resultSetData</var> be a copy of <var>O</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>next</var> be <emu-const>not-started</emu-const>.</li><li>Repeat, while <var>next</var> is not <emu-const>done</emu-const>,<ol><li>Set <var>next</var> to ? <emu-xref aoid="IteratorStepValue" id="_ref_14388"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>keysIter</var>).</li><li>If <var>next</var> is not <emu-const>done</emu-const>, then<ol><li>Set <var>next</var> to <emu-xref aoid="CanonicalizeKeyedCollectionKey" id="_ref_14389"><a href="keyed-collections.html#sec-canonicalizekeyedcollectionkey">CanonicalizeKeyedCollectionKey</a></emu-xref>(<var>next</var>).</li><li>If <emu-xref aoid="SetDataHas" id="_ref_14390"><a href="keyed-collections.html#sec-setdatahas">SetDataHas</a></emu-xref>(<var>resultSetData</var>, <var>next</var>) is <emu-val>false</emu-val>, then<ol><li>Append <var>next</var> to <var>resultSetData</var>.</li></ol></li></ol></li></ol></li><li>Let <var>result</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_14391"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-set-prototype-object" id="_ref_14392"><a href="keyed-collections.html#sec-properties-of-the-set-prototype-object">%Set.prototype%</a></emu-xref>, « <var class="field">[[SetData]]</var> »).</li><li>Set <var>result</var>.<var class="field">[[SetData]]</var> to <var>resultSetData</var>.</li><li>Return <var>result</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set.prototype.values" type="built-in function">
|
||
<h1><span class="secnum">24.2.4.17</span> Set.prototype.values ( )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Return ? <emu-xref aoid="CreateSetIterator" id="_ref_14393"><a href="keyed-collections.html#sec-createsetiterator">CreateSetIterator</a></emu-xref>(<var>S</var>, <emu-const>value</emu-const>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-set.prototype-@@iterator" id="sec-set.prototype-%symbol.iterator%" type="built-in function"><span id="sec-set.prototype-@@iterator"></span>
|
||
<h1><span class="secnum">24.2.4.18</span> Set.prototype [ %Symbol.iterator% ] ( )</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14394"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref> property is %Set.prototype.values%, defined in <emu-xref href="#sec-set.prototype.values" id="_ref_782"><a href="keyed-collections.html#sec-set.prototype.values">24.2.4.17</a></emu-xref>.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-set.prototype-@@tostringtag" id="sec-set.prototype-%symbol.tostringtag%"><span id="sec-set.prototype-@@tostringtag"></span>
|
||
<h1><span class="secnum">24.2.4.19</span> Set.prototype [ %Symbol.toStringTag% ]</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14395"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.toStringTag%</a></emu-xref> property is the String value <emu-val>"Set"</emu-val>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-set-instances">
|
||
<h1><span class="secnum">24.2.5</span> Properties of Set Instances</h1>
|
||
<p>Set instances are <emu-xref href="#ordinary-object" id="_ref_14396"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary objects</a></emu-xref> that inherit properties from the <emu-xref href="#sec-properties-of-the-set-prototype-object" id="_ref_14397"><a href="keyed-collections.html#sec-properties-of-the-set-prototype-object">Set prototype object</a></emu-xref>. Set instances also have a <var class="field">[[SetData]]</var> internal slot.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-set-iterator-objects">
|
||
<h1><span class="secnum">24.2.6</span> Set Iterator Objects</h1>
|
||
<p>A <dfn variants="Set Iterators,Set Iterator object,Set Iterator objects" tabindex="-1">Set Iterator</dfn> is an <emu-xref href="#ordinary-object" id="_ref_14398"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>, with the structure defined below, that represents a specific iteration over some specific Set instance object. There is not a named <emu-xref href="#constructor" id="_ref_14399"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> for Set Iterator objects. Instead, Set Iterator objects are created by calling certain methods of Set instance objects.</p>
|
||
|
||
<emu-clause id="sec-createsetiterator" type="abstract operation" oldids="sec-properties-of-set-iterator-instances,table-51,table-internal-slots-of-set-iterator-instances" aoid="CreateSetIterator"><span id="table-internal-slots-of-set-iterator-instances"></span><span id="table-51"></span><span id="sec-properties-of-set-iterator-instances"></span>
|
||
<h1><span class="secnum">24.2.6.1</span> CreateSetIterator ( <var>set</var>, <var>kind</var> )</h1>
|
||
<p>The abstract operation CreateSetIterator takes arguments <var>set</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14400"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and <var>kind</var> (<emu-const>key+value</emu-const> or <emu-const>value</emu-const>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14401"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a Generator or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14402"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It is used to create <emu-xref href="#sec-iterator-interface" id="_ref_14403"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator objects</a></emu-xref> for Set methods that return such <emu-xref href="#sec-iterator-interface" id="_ref_14404"><a href="control-abstraction-objects.html#sec-iterator-interface">iterators</a></emu-xref>. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14405"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>set</var>, <var class="field">[[SetData]]</var>).</li><li>Let <var>closure</var> be a new <emu-xref href="#sec-abstract-closure" id="_ref_14406"><a href="ecmascript-data-types-and-values.html#sec-abstract-closure">Abstract Closure</a></emu-xref> with no parameters that captures <var>set</var> and <var>kind</var> and performs the following steps when called:<ol><li>Let <var>index</var> be 0.</li><li>Let <var>entries</var> be <var>set</var>.<var class="field">[[SetData]]</var>.</li><li>Let <var>numEntries</var> be the number of elements in <var>entries</var>.</li><li>Repeat, while <var>index</var> < <var>numEntries</var>,<ol><li>Let <var>e</var> be <var>entries</var>[<var>index</var>].</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>e</var> is not <emu-const>empty</emu-const>, then<ol><li>If <var>kind</var> is <emu-const>key+value</emu-const>, then<ol><li>Let <var>result</var> be <emu-xref aoid="CreateArrayFromList" id="_ref_14407"><a href="abstract-operations.html#sec-createarrayfromlist">CreateArrayFromList</a></emu-xref>(« <var>e</var>, <var>e</var> »).</li><li>Perform ? <emu-xref aoid="GeneratorYield" id="_ref_14408"><a href="control-abstraction-objects.html#sec-generatoryield">GeneratorYield</a></emu-xref>(<emu-xref aoid="CreateIteratorResultObject" id="_ref_14409"><a href="abstract-operations.html#sec-createiterresultobject">CreateIteratorResultObject</a></emu-xref>(<var>result</var>, <emu-val>false</emu-val>)).</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_14410"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>kind</var> is <emu-const>value</emu-const>.</li><li>Perform ? <emu-xref aoid="GeneratorYield" id="_ref_14411"><a href="control-abstraction-objects.html#sec-generatoryield">GeneratorYield</a></emu-xref>(<emu-xref aoid="CreateIteratorResultObject" id="_ref_14412"><a href="abstract-operations.html#sec-createiterresultobject">CreateIteratorResultObject</a></emu-xref>(<var>e</var>, <emu-val>false</emu-val>)).</li></ol></li><li>NOTE: The number of elements in <var>entries</var> may have increased while execution of this abstract operation was paused by <emu-xref aoid="GeneratorYield" id="_ref_14413"><a href="control-abstraction-objects.html#sec-generatoryield">GeneratorYield</a></emu-xref>.</li><li>Set <var>numEntries</var> to the number of elements in <var>entries</var>.</li></ol></li></ol></li><li>Return <emu-xref aoid="NormalCompletion" id="_ref_14414"><a href="ecmascript-data-types-and-values.html#sec-normalcompletion">NormalCompletion</a></emu-xref>(<emu-const>unused</emu-const>).</li></ol></li><li>Return <emu-xref aoid="CreateIteratorFromClosure" id="_ref_14415"><a href="control-abstraction-objects.html#sec-createiteratorfromclosure">CreateIteratorFromClosure</a></emu-xref>(<var>closure</var>, <emu-val>"%SetIteratorPrototype%"</emu-val>, <emu-xref href="#sec-%setiteratorprototype%-object" id="_ref_14416"><a href="keyed-collections.html#sec-%setiteratorprototype%-object">%SetIteratorPrototype%</a></emu-xref>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-%setiteratorprototype%-object">
|
||
<h1><span class="secnum">24.2.6.2</span> The %SetIteratorPrototype% Object</h1>
|
||
<p>The <dfn tabindex="-1">%SetIteratorPrototype%</dfn> object:</p>
|
||
<ul>
|
||
<li>has properties that are inherited by all <emu-xref href="#sec-set-iterator-objects" id="_ref_14417"><a href="keyed-collections.html#sec-set-iterator-objects">Set Iterator objects</a></emu-xref>.</li>
|
||
<li>is an <emu-xref href="#ordinary-object" id="_ref_14418"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-%iterator.prototype%-object" id="_ref_14419"><a href="control-abstraction-objects.html#sec-%iterator.prototype%-object">%Iterator.prototype%</a></emu-xref>.</li>
|
||
<li>has the following properties:</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-%setiteratorprototype%.next" type="built-in function">
|
||
<h1><span class="secnum">24.2.6.2.1</span> %SetIteratorPrototype%.next ( )</h1>
|
||
<emu-alg><ol><li>Return ? <emu-xref aoid="GeneratorResume" id="_ref_14420"><a href="control-abstraction-objects.html#sec-generatorresume">GeneratorResume</a></emu-xref>(<emu-val>this</emu-val> value, <emu-const>empty</emu-const>, <emu-val>"%SetIteratorPrototype%"</emu-val>).</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-%setiteratorprototype%-@@tostringtag" id="sec-%setiteratorprototype%-%symbol.tostringtag%"><span id="sec-%setiteratorprototype%-@@tostringtag"></span>
|
||
<h1><span class="secnum">24.2.6.2.2</span> %SetIteratorPrototype% [ %Symbol.toStringTag% ]</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14421"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.toStringTag%</a></emu-xref> property is the String value <emu-val>"Set Iterator"</emu-val>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakmap-objects">
|
||
<h1><span class="secnum">24.3</span> WeakMap Objects</h1>
|
||
<p>WeakMaps are collections of key/value pairs where the keys are objects and/or symbols and values may be arbitrary <emu-xref href="#sec-ecmascript-language-types" id="_ref_14422"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref>. A WeakMap may be queried to see if it contains a key/value pair with a specific key, but no mechanism is provided for enumerating the values it holds as keys. In certain conditions, values which are not <emu-xref href="#sec-liveness" id="_ref_14423"><a href="executable-code-and-execution-contexts.html#sec-liveness">live</a></emu-xref> are removed as WeakMap keys, as described in <emu-xref href="#sec-weakref-execution" id="_ref_783"><a href="executable-code-and-execution-contexts.html#sec-weakref-execution">9.9.3</a></emu-xref>.</p>
|
||
<p>An implementation may impose an arbitrarily determined latency between the time a key/value pair of a WeakMap becomes inaccessible and the time when the key/value pair is removed from the WeakMap. If this latency was observable to ECMAScript program, it would be a source of indeterminacy that could impact program execution. For that reason, an ECMAScript implementation must not provide any means to observe a key of a WeakMap that does not require the observer to present the observed key.</p>
|
||
<p>WeakMaps must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of key/value pairs in the collection. The data structure used in this specification is only intended to describe the required observable semantics of WeakMaps. It is not intended to be a viable implementation model.</p>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>WeakMap and WeakSet are intended to provide mechanisms for dynamically associating state with an object or symbol in a manner that does not “leak” memory resources if, in the absence of the WeakMap or WeakSet instance, the object or symbol otherwise became inaccessible and subject to resource reclamation by the implementation's garbage collection mechanisms. This characteristic can be achieved by using an inverted per-object/symbol mapping of WeakMap or WeakSet instances to keys. Alternatively, each WeakMap or WeakSet instance may internally store its key and value data, but this approach requires coordination between the WeakMap or WeakSet implementation and the garbage collector. The following references describe mechanism that may be useful to implementations of WeakMap and WeakSet:</p>
|
||
<p>Barry Hayes. 1997. Ephemerons: a new finalization mechanism. In <i>Proceedings of the 12th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA '97)</i>, A. Michael Berman (Ed.). ACM, New York, NY, USA, 176-183, <a href="http://doi.acm.org/10.1145/263698.263733">http://doi.acm.org/10.1145/263698.263733</a>.</p>
|
||
<p>Alexandra Barros, Roberto Ierusalimschy, Eliminating Cycles in Weak Tables. Journal of Universal Computer Science - J.UCS, vol. 14, no. 21, pp. 3481-3497, 2008, <a href="http://www.jucs.org/jucs_14_21/eliminating_cycles_in_weak">http://www.jucs.org/jucs_14_21/eliminating_cycles_in_weak</a></p>
|
||
</div></emu-note>
|
||
|
||
<emu-clause id="sec-weakmap-constructor">
|
||
<h1><span class="secnum">24.3.1</span> The WeakMap Constructor</h1>
|
||
<p>The WeakMap <emu-xref href="#constructor" id="_ref_14424"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%WeakMap%</dfn>.</li>
|
||
<li>is the initial value of the <emu-val>"WeakMap"</emu-val> property of the <emu-xref href="#sec-global-object" id="_ref_14425"><a href="global-object.html#sec-global-object">global object</a></emu-xref>.</li>
|
||
<li>creates and initializes a new WeakMap when called as a <emu-xref href="#constructor" id="_ref_14426"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>.</li>
|
||
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
|
||
<li>may be used as the value in an <code>extends</code> clause of a class definition. Subclass <emu-xref href="#constructor" id="_ref_14427"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that intend to inherit the specified WeakMap behaviour must include a <code>super</code> call to the WeakMap <emu-xref href="#constructor" id="_ref_14428"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to create and initialize the subclass instance with the internal state necessary to support the <code>WeakMap.prototype</code> built-in methods.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-weakmap-iterable" type="built-in function">
|
||
<h1><span class="secnum">24.3.1.1</span> WeakMap ( [ <var>iterable</var> ] )</h1>
|
||
<p>This function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>If NewTarget is <emu-val>undefined</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>map</var> be ? <emu-xref aoid="OrdinaryCreateFromConstructor" id="_ref_14429"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinarycreatefromconstructor" class="e-user-code">OrdinaryCreateFromConstructor</a></emu-xref>(NewTarget, <emu-val>"%WeakMap.prototype%"</emu-val>, « <var class="field">[[WeakMapData]]</var> »).</li><li>Set <var>map</var>.<var class="field">[[WeakMapData]]</var> to a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14430"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>If <var>iterable</var> is either <emu-val>undefined</emu-val> or <emu-val>null</emu-val>, return <var>map</var>.</li><li>Let <var>adder</var> be ? <emu-xref aoid="Get" id="_ref_14431"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>map</var>, <emu-val>"set"</emu-val>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14432"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>adder</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Return ? <emu-xref aoid="AddEntriesFromIterable" id="_ref_14433"><a href="keyed-collections.html#sec-add-entries-from-iterable" class="e-user-code">AddEntriesFromIterable</a></emu-xref>(<var>map</var>, <var>iterable</var>, <var>adder</var>).</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>If the parameter <var>iterable</var> is present, it is expected to be an object that implements a <emu-xref href="#sec-well-known-symbols" id="_ref_14434"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref> method that returns an <emu-xref href="#sec-iterator-interface" id="_ref_14435"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator object</a></emu-xref> that produces a two element <emu-xref href="#sec-lengthofarraylike" id="_ref_14436"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref> 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.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-weakmap-constructor">
|
||
<h1><span class="secnum">24.3.2</span> Properties of the WeakMap Constructor</h1>
|
||
<p>The WeakMap <emu-xref href="#constructor" id="_ref_14437"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-function-prototype-object" id="_ref_14438"><a href="fundamental-objects.html#sec-properties-of-the-function-prototype-object">%Function.prototype%</a></emu-xref>.</li>
|
||
<li>has the following properties:</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-weakmap.prototype">
|
||
<h1><span class="secnum">24.3.2.1</span> WeakMap.prototype</h1>
|
||
<p>The initial value of <code>WeakMap.prototype</code> is the <emu-xref href="#sec-properties-of-the-weakmap-prototype-object" id="_ref_14439"><a href="keyed-collections.html#sec-properties-of-the-weakmap-prototype-object">WeakMap prototype object</a></emu-xref>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-weakmap-prototype-object">
|
||
<h1><span class="secnum">24.3.3</span> Properties of the WeakMap Prototype Object</h1>
|
||
<p>The <dfn tabindex="-1">WeakMap prototype object</dfn>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%WeakMap.prototype%</dfn>.</li>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_14440"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>.</li>
|
||
<li>is an <emu-xref href="#ordinary-object" id="_ref_14441"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
|
||
<li>does not have a <var class="field">[[WeakMapData]]</var> internal slot.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-weakmap.prototype.constructor">
|
||
<h1><span class="secnum">24.3.3.1</span> WeakMap.prototype.constructor</h1>
|
||
<p>The initial value of <code>WeakMap.prototype.constructor</code> is <emu-xref href="#sec-weakmap-constructor" id="_ref_14442"><a href="keyed-collections.html#sec-weakmap-constructor">%WeakMap%</a></emu-xref>.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakmap.prototype.delete" type="built-in function">
|
||
<h1><span class="secnum">24.3.3.2</span> WeakMap.prototype.delete ( <var>key</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14443"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[WeakMapData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14444"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>key</var>) is <emu-val>false</emu-val>, return <emu-val>false</emu-val>.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14445"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[WeakMapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14446"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, then<ol><li>Set <var>p</var>.<var class="field">[[Key]]</var> to <emu-const>empty</emu-const>.</li><li>Set <var>p</var>.<var class="field">[[Value]]</var> to <emu-const>empty</emu-const>.</li><li>Return <emu-val>true</emu-val>.</li></ol></li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>The value <emu-const>empty</emu-const> is used as a specification device to indicate that an entry has been deleted. Actual implementations may take other actions such as physically removing the entry from internal data structures.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakmap.prototype.get" type="built-in function">
|
||
<h1><span class="secnum">24.3.3.3</span> WeakMap.prototype.get ( <var>key</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14447"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[WeakMapData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14448"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>key</var>) is <emu-val>false</emu-val>, return <emu-val>undefined</emu-val>.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14449"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[WeakMapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14450"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <var>p</var>.<var class="field">[[Value]]</var>.</li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakmap.prototype.getorinsert" type="built-in function">
|
||
<h1><span class="secnum">24.3.3.4</span> WeakMap.prototype.getOrInsert ( <var>key</var>, <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14451"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[WeakMapData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14452"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>key</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14453"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[WeakMapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14454"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <var>p</var>.<var class="field">[[Value]]</var>.</li></ol></li><li>Let <var>p</var> be the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14455"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>: <var>key</var>, <var class="field">[[Value]]</var>: <var>value</var> }.</li><li>Append <var>p</var> to <var>M</var>.<var class="field">[[WeakMapData]]</var>.</li><li>Return <var>value</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakmap.prototype.getorinsertcomputed" type="built-in function">
|
||
<h1><span class="secnum">24.3.3.5</span> WeakMap.prototype.getOrInsertComputed ( <var>key</var>, <var>callback</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14456"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[WeakMapData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14457"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>key</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <emu-xref aoid="IsCallable" id="_ref_14458"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14459"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[WeakMapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14460"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <var>p</var>.<var class="field">[[Value]]</var>.</li></ol></li><li>Let <var>value</var> be ? <emu-xref aoid="Call" id="_ref_14461"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <emu-val>undefined</emu-val>, « <var>key</var> »).</li><li>NOTE: The WeakMap may have been modified during execution of <var>callback</var>.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14462"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[WeakMapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14463"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, then<ol><li>Set <var>p</var>.<var class="field">[[Value]]</var> to <var>value</var>.</li><li>Return <var>value</var>.</li></ol></li></ol></li><li>Let <var>p</var> be the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14464"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>: <var>key</var>, <var class="field">[[Value]]</var>: <var>value</var> }.</li><li>Append <var>p</var> to <var>M</var>.<var class="field">[[WeakMapData]]</var>.</li><li>Return <var>value</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakmap.prototype.has" type="built-in function">
|
||
<h1><span class="secnum">24.3.3.6</span> WeakMap.prototype.has ( <var>key</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14465"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[WeakMapData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14466"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>key</var>) is <emu-val>false</emu-val>, return <emu-val>false</emu-val>.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14467"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[WeakMapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14468"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakmap.prototype.set" type="built-in function">
|
||
<h1><span class="secnum">24.3.3.7</span> WeakMap.prototype.set ( <var>key</var>, <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14469"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>M</var>, <var class="field">[[WeakMapData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14470"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>key</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>For each <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14471"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var> } <var>p</var> of <var>M</var>.<var class="field">[[WeakMapData]]</var>, do<ol><li>If <var>p</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14472"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>p</var>.<var class="field">[[Key]]</var>, <var>key</var>) is <emu-val>true</emu-val>, then<ol><li>Set <var>p</var>.<var class="field">[[Value]]</var> to <var>value</var>.</li><li>Return <var>M</var>.</li></ol></li></ol></li><li>Let <var>p</var> be the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14473"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Key]]</var>: <var>key</var>, <var class="field">[[Value]]</var>: <var>value</var> }.</li><li>Append <var>p</var> to <var>M</var>.<var class="field">[[WeakMapData]]</var>.</li><li>Return <var>M</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-weakmap.prototype-@@tostringtag" id="sec-weakmap.prototype-%symbol.tostringtag%"><span id="sec-weakmap.prototype-@@tostringtag"></span>
|
||
<h1><span class="secnum">24.3.3.8</span> WeakMap.prototype [ %Symbol.toStringTag% ]</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14474"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.toStringTag%</a></emu-xref> property is the String value <emu-val>"WeakMap"</emu-val>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-weakmap-instances">
|
||
<h1><span class="secnum">24.3.4</span> Properties of WeakMap Instances</h1>
|
||
<p>WeakMap instances are <emu-xref href="#ordinary-object" id="_ref_14475"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary objects</a></emu-xref> that inherit properties from the <emu-xref href="#sec-properties-of-the-weakmap-prototype-object" id="_ref_14476"><a href="keyed-collections.html#sec-properties-of-the-weakmap-prototype-object">WeakMap prototype object</a></emu-xref>. WeakMap instances also have a <var class="field">[[WeakMapData]]</var> internal slot.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakset-objects">
|
||
<h1><span class="secnum">24.4</span> WeakSet Objects</h1>
|
||
<p>WeakSets are collections of objects and/or symbols. A distinct object or symbol may only occur once as an element of a WeakSet's collection. A WeakSet may be queried to see if it contains a specific value, but no mechanism is provided for enumerating the values it holds. In certain conditions, values which are not <emu-xref href="#sec-liveness" id="_ref_14477"><a href="executable-code-and-execution-contexts.html#sec-liveness">live</a></emu-xref> are removed as WeakSet elements, as described in <emu-xref href="#sec-weakref-execution" id="_ref_784"><a href="executable-code-and-execution-contexts.html#sec-weakref-execution">9.9.3</a></emu-xref>.</p>
|
||
<p>An implementation may impose an arbitrarily determined latency between the time a value contained in a WeakSet becomes inaccessible and the time when the value is removed from the WeakSet. If this latency was observable to ECMAScript program, it would be a source of indeterminacy that could impact program execution. For that reason, an ECMAScript implementation must not provide any means to determine if a WeakSet contains a particular value that does not require the observer to present the observed value.</p>
|
||
<p>WeakSets must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structure used in this specification is only intended to describe the required observable semantics of WeakSets. It is not intended to be a viable implementation model.</p>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>See the NOTE in <emu-xref href="#sec-weakmap-objects" id="_ref_785"><a href="keyed-collections.html#sec-weakmap-objects">24.3</a></emu-xref>.</p>
|
||
</div></emu-note>
|
||
|
||
<emu-clause id="sec-weakset-constructor">
|
||
<h1><span class="secnum">24.4.1</span> The WeakSet Constructor</h1>
|
||
<p>The WeakSet <emu-xref href="#constructor" id="_ref_14478"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%WeakSet%</dfn>.</li>
|
||
<li>is the initial value of the <emu-val>"WeakSet"</emu-val> property of the <emu-xref href="#sec-global-object" id="_ref_14479"><a href="global-object.html#sec-global-object">global object</a></emu-xref>.</li>
|
||
<li>creates and initializes a new WeakSet when called as a <emu-xref href="#constructor" id="_ref_14480"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>.</li>
|
||
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
|
||
<li>may be used as the value in an <code>extends</code> clause of a class definition. Subclass <emu-xref href="#constructor" id="_ref_14481"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that intend to inherit the specified WeakSet behaviour must include a <code>super</code> call to the WeakSet <emu-xref href="#constructor" id="_ref_14482"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to create and initialize the subclass instance with the internal state necessary to support the <code>WeakSet.prototype</code> built-in methods.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-weakset-iterable" type="built-in function">
|
||
<h1><span class="secnum">24.4.1.1</span> WeakSet ( [ <var>iterable</var> ] )</h1>
|
||
<p>This function performs the following steps when called:</p>
|
||
<emu-alg><ol><li>If NewTarget is <emu-val>undefined</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>set</var> be ? <emu-xref aoid="OrdinaryCreateFromConstructor" id="_ref_14483"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinarycreatefromconstructor" class="e-user-code">OrdinaryCreateFromConstructor</a></emu-xref>(NewTarget, <emu-val>"%WeakSet.prototype%"</emu-val>, « <var class="field">[[WeakSetData]]</var> »).</li><li>Set <var>set</var>.<var class="field">[[WeakSetData]]</var> to a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14484"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>If <var>iterable</var> is either <emu-val>undefined</emu-val> or <emu-val>null</emu-val>, return <var>set</var>.</li><li>Let <var>adder</var> be ? <emu-xref aoid="Get" id="_ref_14485"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>set</var>, <emu-val>"add"</emu-val>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_14486"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>adder</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>iteratorRecord</var> be ? <emu-xref aoid="GetIterator" id="_ref_14487"><a href="abstract-operations.html#sec-getiterator" class="e-user-code">GetIterator</a></emu-xref>(<var>iterable</var>, <emu-const>sync</emu-const>).</li><li>Repeat,<ol><li>Let <var>next</var> be ? <emu-xref aoid="IteratorStepValue" id="_ref_14488"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>iteratorRecord</var>).</li><li>If <var>next</var> is <emu-const>done</emu-const>, return <var>set</var>.</li><li>Let <var>status</var> be <emu-xref aoid="Completion" id="_ref_14489"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Call" id="_ref_14490"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>adder</var>, <var>set</var>, « <var>next</var> »)).</li><li><emu-xref aoid="IfAbruptCloseIterator" id="_ref_14491"><a href="abstract-operations.html#sec-ifabruptcloseiterator" class="e-user-code">IfAbruptCloseIterator</a></emu-xref>(<var>status</var>, <var>iteratorRecord</var>).</li></ol></li></ol></emu-alg>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-weakset-constructor">
|
||
<h1><span class="secnum">24.4.2</span> Properties of the WeakSet Constructor</h1>
|
||
<p>The WeakSet <emu-xref href="#constructor" id="_ref_14492"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
|
||
<ul>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-function-prototype-object" id="_ref_14493"><a href="fundamental-objects.html#sec-properties-of-the-function-prototype-object">%Function.prototype%</a></emu-xref>.</li>
|
||
<li>has the following properties:</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-weakset.prototype">
|
||
<h1><span class="secnum">24.4.2.1</span> WeakSet.prototype</h1>
|
||
<p>The initial value of <code>WeakSet.prototype</code> is the <emu-xref href="#sec-properties-of-the-weakset-prototype-object" id="_ref_14494"><a href="keyed-collections.html#sec-properties-of-the-weakset-prototype-object">WeakSet prototype object</a></emu-xref>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-the-weakset-prototype-object">
|
||
<h1><span class="secnum">24.4.3</span> Properties of the WeakSet Prototype Object</h1>
|
||
<p>The <dfn tabindex="-1">WeakSet prototype object</dfn>:</p>
|
||
<ul>
|
||
<li>is <dfn tabindex="-1">%WeakSet.prototype%</dfn>.</li>
|
||
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_14495"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>.</li>
|
||
<li>is an <emu-xref href="#ordinary-object" id="_ref_14496"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
|
||
<li>does not have a <var class="field">[[WeakSetData]]</var> internal slot.</li>
|
||
</ul>
|
||
|
||
<emu-clause id="sec-weakset.prototype.add" type="built-in function">
|
||
<h1><span class="secnum">24.4.3.1</span> WeakSet.prototype.add ( <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14497"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[WeakSetData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14498"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>value</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>For each element <var>e</var> of <var>S</var>.<var class="field">[[WeakSetData]]</var>, do<ol><li>If <var>e</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14499"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>e</var>, <var>value</var>) is <emu-val>true</emu-val>, then<ol><li>Return <var>S</var>.</li></ol></li></ol></li><li>Append <var>value</var> to <var>S</var>.<var class="field">[[WeakSetData]]</var>.</li><li>Return <var>S</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakset.prototype.constructor">
|
||
<h1><span class="secnum">24.4.3.2</span> WeakSet.prototype.constructor</h1>
|
||
<p>The initial value of <code>WeakSet.prototype.constructor</code> is <emu-xref href="#sec-weakset-constructor" id="_ref_14500"><a href="keyed-collections.html#sec-weakset-constructor">%WeakSet%</a></emu-xref>.</p>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakset.prototype.delete" type="built-in function">
|
||
<h1><span class="secnum">24.4.3.3</span> WeakSet.prototype.delete ( <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14501"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[WeakSetData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14502"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>value</var>) is <emu-val>false</emu-val>, return <emu-val>false</emu-val>.</li><li>For each element <var>e</var> of <var>S</var>.<var class="field">[[WeakSetData]]</var>, do<ol><li>If <var>e</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14503"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>e</var>, <var>value</var>) is <emu-val>true</emu-val>, then<ol><li>Replace the element of <var>S</var>.<var class="field">[[WeakSetData]]</var> whose value is <var>e</var> with an element whose value is <emu-const>empty</emu-const>.</li><li>Return <emu-val>true</emu-val>.</li></ol></li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
<emu-note><span class="note">Note</span><div class="note-contents">
|
||
<p>The value <emu-const>empty</emu-const> is used as a specification device to indicate that an entry has been deleted. Actual implementations may take other actions such as physically removing the entry from internal data structures.</p>
|
||
</div></emu-note>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-weakset.prototype.has" type="built-in function">
|
||
<h1><span class="secnum">24.4.3.4</span> WeakSet.prototype.has ( <var>value</var> )</h1>
|
||
<p>This method performs the following steps when called:</p>
|
||
<emu-alg><ol><li>Let <var>S</var> be the <emu-val>this</emu-val> value.</li><li>Perform ? <emu-xref aoid="RequireInternalSlot" id="_ref_14504"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>S</var>, <var class="field">[[WeakSetData]]</var>).</li><li>If <emu-xref aoid="CanBeHeldWeakly" id="_ref_14505"><a href="executable-code-and-execution-contexts.html#sec-canbeheldweakly">CanBeHeldWeakly</a></emu-xref>(<var>value</var>) is <emu-val>false</emu-val>, return <emu-val>false</emu-val>.</li><li>For each element <var>e</var> of <var>S</var>.<var class="field">[[WeakSetData]]</var>, do<ol><li>If <var>e</var> is not <emu-const>empty</emu-const> and <emu-xref aoid="SameValue" id="_ref_14506"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>e</var>, <var>value</var>) is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
|
||
<emu-clause oldids="sec-weakset.prototype-@@tostringtag" id="sec-weakset.prototype-%symbol.tostringtag%"><span id="sec-weakset.prototype-@@tostringtag"></span>
|
||
<h1><span class="secnum">24.4.3.5</span> WeakSet.prototype [ %Symbol.toStringTag% ]</h1>
|
||
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_14507"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.toStringTag%</a></emu-xref> property is the String value <emu-val>"WeakSet"</emu-val>.</p>
|
||
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-properties-of-weakset-instances">
|
||
<h1><span class="secnum">24.4.4</span> Properties of WeakSet Instances</h1>
|
||
<p>WeakSet instances are <emu-xref href="#ordinary-object" id="_ref_14508"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary objects</a></emu-xref> that inherit properties from the <emu-xref href="#sec-properties-of-the-weakset-prototype-object" id="_ref_14509"><a href="keyed-collections.html#sec-properties-of-the-weakset-prototype-object">WeakSet prototype object</a></emu-xref>. WeakSet instances also have a <var class="field">[[WeakSetData]]</var> internal slot.</p>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
|
||
<emu-clause id="sec-abstract-operations-for-keyed-collections">
|
||
<h1><span class="secnum">24.5</span> Abstract Operations for Keyed Collections</h1>
|
||
|
||
<emu-clause id="sec-canonicalizekeyedcollectionkey" type="abstract operation" aoid="CanonicalizeKeyedCollectionKey">
|
||
<h1><span class="secnum">24.5.1</span> CanonicalizeKeyedCollectionKey ( <var>key</var> )</h1>
|
||
<p>The abstract operation CanonicalizeKeyedCollectionKey takes argument <var>key</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14510"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14511"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>. It performs the following steps when called:</p>
|
||
<emu-alg><ol><li>If <var>key</var> is <emu-val>-0</emu-val><sub>𝔽</sub>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>Return <var>key</var>.</li></ol></emu-alg>
|
||
</emu-clause>
|
||
</emu-clause>
|
||
</emu-clause></div></body></html> |