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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,7 @@ <h1><span class="secnum">3</span> Map.prototype methods</h1>

<emu-clause id="Map.prototype.mapValues">
<h1><span class="secnum">3.1</span> Map.prototype.mapValues( <var>callbackfn</var>, [ <var>thisArg</var> ] )</h1>
<emu-import href="./map/prototype-map-values.html"><emu-note type="editor"><span class="note">Editor's Note</span><div class="note-contents">
This code serves as placeholder until formal spec is written for this method.
</div></emu-note><pre><code class="javascript hljs"><span class="hljs-keyword">function</span> <span class="hljs-title function_">mapValues</span>(<span class="hljs-params">callbackFn, thisArg</span>) {
<span class="hljs-title function_">assert</span>(<span class="hljs-title function_">isObject</span>(<span class="hljs-variable language_">this</span>), <span class="hljs-string">'this is not an object'</span>);
<span class="hljs-title function_">assert</span>(<span class="hljs-title function_">isCallable</span>(callbackFn), <span class="hljs-string">'callback is not a function'</span>);
<span class="hljs-keyword">const</span> <span class="hljs-title class_">Ctor</span> = <span class="hljs-title class_">SpeciesConstructor</span>(<span class="hljs-variable language_">this</span>, <span class="hljs-title class_">Map</span>);
<span class="hljs-keyword">const</span> retObj = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Ctor</span>();
<span class="hljs-keyword">const</span> _set = retObj.<span class="hljs-property">set</span>;
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">const</span> [key, value] <span class="hljs-keyword">of</span> <span class="hljs-variable language_">this</span>) {
<span class="hljs-keyword">const</span> newValue = <span class="hljs-title class_">Reflect</span>.<span class="hljs-title function_">apply</span>(callbackFn, thisArg, [value, key, <span class="hljs-variable language_">this</span>])
<span class="hljs-title class_">Reflect</span>.<span class="hljs-title function_">apply</span>(_set, retObj, [key, newValue]);
}
<span class="hljs-keyword">return</span> retObj;
}</code></pre></emu-import>
<emu-import href="./map/prototype-map-values.html"><emu-alg><ol><li>Let <var>M</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;RequireInternalSlot(<var>M</var>, <var class="field">[[MapData]]</var>).</li><li>If IsCallable(<var>callbackfn</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>result</var> be !&nbsp;Construct(%Map%).</li><li>For each Record { <var class="field">[[Key]]</var>, <var class="field">[[Value]]</var>&nbsp;} <var>e</var> of <var>M</var>.<var class="field">[[MapData]]</var>, do<ol><li>If <var>e</var>.<var class="field">[[Key]]</var> is not <emu-const>empty</emu-const>, then</li><li>Let <var>newValue</var> be ?&nbsp;Call(<var>callbackfn</var>, <var>T</var>, « <var>e</var>.<var class="field">[[Value]]</var>, <var>e</var>.<var class="field">[[Key]]</var>, <var>map</var>&nbsp;»)</li><li>Let <var>p</var> be the Record { <var class="field">[[Key]]</var>: <var>e</var>.<var class="field">[[Key]]</var>, <var class="field">[[Value]]</var>: <var>newValue</var>&nbsp;}</li><li>Append <var>p</var> to <var>result</var>.<var class="field">[[MapData]]</var></li></ol></li><li>Return <var>result</var>.</li></ol></emu-alg></emu-import>
</emu-clause>

<emu-clause id="Map.prototype.mapKeys">
Expand Down
30 changes: 12 additions & 18 deletions spec/map/prototype-map-values.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<!DOCTYPE html>
<emu-note type="editor">
This code serves as placeholder until formal spec is written for this method.
</emu-note>

<pre><code class="javascript">
function mapValues(callbackFn, thisArg) {
assert(isObject(this), 'this is not an object');
assert(isCallable(callbackFn), 'callback is not a function');
const Ctor = SpeciesConstructor(this, Map);
const retObj = new Ctor();
const _set = retObj.set;
for(const [key, value] of this) {
const newValue = Reflect.apply(callbackFn, thisArg, [value, key, this])
Reflect.apply(_set, retObj, [key, newValue]);
}
return retObj;
}
</code></pre>
<emu-alg>
1. Let _M_ be the *this* value.
1. Perform ? RequireInternalSlot(_M_, [[MapData]]).
1. If IsCallable(_callbackfn_) is *false*, throw a *TypeError* exception.
1. Let _result_ be ! Construct(%Map%).
1. For each Record { [[Key]], [[Value]] } _e_ of _M_.[[MapData]], do
1. If _e_.[[Key]] is not ~empty~, then
1. Let _newValue_ be ? Call(_callbackfn_, _T_, « _e_.[[Value]], _e_.[[Key]], _map_ »)
1. Let _p_ be the Record { [[Key]]: _e_.[[Key]], [[Value]]: _newValue_ }
1. Append _p_ to _result_.[[MapData]]
1. Return _result_.
</emu-alg>