Closed Bug 918341 Opened 11 years ago Closed 11 years ago

new Map(iterable) should check that iterator values are objects

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla27

People

(Reporter: wingo, Assigned: sankha)

References

Details

Attachments

(1 file, 1 obsolete file)

From http://people.mozilla.org/~jorendorff/es6-draft.html#sec-23.1.1, when building a map from an iterable, we should throw if the values are not objects.
Attached patch patch v1 (obsolete) — Splinter Review
Attachment #817639 - Flags: review?(jorendorff)
Comment on attachment 817639 [details] [diff] [review]
patch v1

Review of attachment 817639 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks! r=me with the comments addressed.

::: js/src/builtin/MapObject.cpp
@@ +1194,5 @@
>              if (!iter.next(&pairVal, &done))
>                  return false;
>              if (done)
>                  break;
> +            if (JSVAL_IS_PRIMITIVE(pairVal) || JSVAL_IS_NULL(pairVal)) {

Instead of this, please write:
    if (!pairVal.isObject()) {

@@ +1203,3 @@
>              pairObj = ToObject(cx, pairVal);
>              if (!pairObj)
>                  return false;

Please change this ToObject call to pairVal.toObject(), which is cheaper and can't fail. (This is possible because we just confirmed that pairVal really is an object.)

::: js/src/jit-test/tests/collections/Map-constructor-5.js
@@ +10,5 @@
> +
> +assertThrowsInstanceOf(function () { Map([1, 2, 3]); }, TypeError);
> +assertThrowsInstanceOf(function () {
> +	let s = new Set([1, 2, "abc"]);
> +	Map(s.values());

just `new Map(s);` please.  The values method is useless.
Attachment #817639 - Flags: review?(jorendorff) → review+
Attached patch patch v2Splinter Review
Assignee: general → sankha93
Attachment #817639 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/ae664f27e663
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: