archives

« Bugzilla Issues Index

#3523 — 7.3.21 SpeciesConstructor and 9.4.2.3 ArraySpeciesCreate: discrepancy on the condition under which the @@species property is examined


7.3.21 SpeciesConstructor
9.4.2.3 ArraySpeciesCreate

Beyond necessary hacks in ArraySpeciesCreate for ensuring backward web compatibility, there is the following discrepancy between the two abstract operations:

originalObj[@@constructor][@@species] is examined:
* in SpeciesConstructor, when originalObj[@@constructor] is an object, but
* in ArraySpeciesCreate, when originalObj[@@constructor] is a constructor.

(In fact, when originalObj[@@constructor] is a non-constructor object, the algorithm of ArraySpeciesCreate terminates with a TypeError in step 8.)

The following patch will remove that difference. Remove step 6.c.iv and replace it with the following:

6.d. If Type(C) is Object, then
1. Let C be Get(C, @@species).
2. ReturnIfAbrupt(C).


(An interesting feature of that patch is that it becomes easy for a user-defined Array subclass to avoid the realm check:

class MyArray extends Array { /* ... */ }
MyArray.prototype.constructor = { [Symbol.species]: MyArray }

)


In Comment 0, read "constructor" instead of @@constructor.


fixed in rev31 editor's draft


In Rev31