« 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: new Object ( [ value ] ) new Function (p1, p2, ..., pn, body) new Array ( [ item0 [ , item1 [ , ... ] ] ] ) new Array (len) new Map (iterable = [ ])

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


For instance, 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 (
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: new Date (year, month [, date [, hours etc ) new Date (value) new TypeArray(arg0 [, arg1 [, arg2 ] ) 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 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