archives

« Bugzilla Issues Index

#756 — built-in [[Construct]] behavior: recast as algorithms


Within section 15, I'm looking at the sections with titles like "new Foo(...)", i.e. the sections that define the behaviour that is bound to the [[Construct]] internal property of built-in constructor-objects.

For some of these, the behavior is given as an algorithm:
15.2.2.1 new Object ( [ value ] )
15.3.2.1 new Function (p1, p2, ..., pn, body)
15.4.2.1 new Array ( [ item0 [ , item1 [ , ... ] ] ] )
15.4.2.2 new Array (len)
15.14.3.1 new Map (iterable = [ ])

For the rest, the behaviour is given in prose, but could be straightforwardly recast as an algorithm.

---

For instance,
15.5.2.1 new String ( [ value ] )
could say (something like):
1. Let /S/ be a newly created ECMAScript object.
2. Set the [[Prototype]] internal property of /S/ to the standard
built-in String prototype object that is the initial value of
String.prototype (15.5.3.1).
3. Set the [[NativeBrand]] internal property of /S/ to StringWrapper.
4. Set the [[Extensible]] internal property of /S/ to true.
5. Set the [[PrimitiveValue]] internal property of /S/ to
ToString(/value/), or to the empty String if /value/ is not supplied.
6. Return /S/

As an algorithm, the behavior is more concrete and more uniformly expressed. It also clarifies that this method is responsible for creating (and returning) the object. (The existing prose simply refers to "the newly constructed object", which isn't very clear.)

---

In a few cases:
15.9.3.1 new Date (year, month [, date [, hours etc )
15.9.3.2 new Date (value)
15.13.6.2.1 new TypeArray(arg0 [, arg1 [, arg2 ] )
15.13.7.2.1 new DataView(buffer [, byteOffset [, byteLength]])
the [[Construct]] behavior is currently given partly in prose and partly in algorithm; here, the prose parts could be recast as steps and added to the algorithm.

Also, in
15.10.4.1 new RegExp(pattern, flags)
the behavior is given as an algorithm, but it's a single step that just calls RegExpCreate, and the latter is expressed in prose. But it looks like the prose could be fairly easily recast as an algorithm.


there has been a general rewrite of all built-in constructor definitions