Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up`Reflect.construct`: "is not present" → "is not undefined"? #647
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jmdyck
Jul 27, 2016
Collaborator
In general it seems like we've tried to change "presence" to "isn't undefined" in the spec.
It does? In the current spec, I count 64 occurrences of "is present" and 57 of "is not present" (plus 6 of "is absent"). Those are quite close to the counts for ES6, and way more than the counts for ES5.
The count for "undefined" is up by about 4% since ES6, but offhand, it doesn't look like much (if any) of the increase is in places where "is [not] present" might otherwise have been used.
(Note that this isn't arguing against the merits of the proposed change, just against the notion that it's a general trend.)
It does? In the current spec, I count 64 occurrences of "is present" and 57 of "is not present" (plus 6 of "is absent"). Those are quite close to the counts for ES6, and way more than the counts for ES5. The count for "undefined" is up by about 4% since ES6, but offhand, it doesn't look like much (if any) of the increase is in places where "is [not] present" might otherwise have been used. (Note that this isn't arguing against the merits of the proposed change, just against the notion that it's a general trend.) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Jul 28, 2016
Contributor
Here is an argument for the current semantics "is absent".
Let’s say I write
function Bar() {
// ....
const obj = Reflect.construct(Foo, args, new.target)
// ...
return obj
}assuming that new.target is an object. Now suppose that it happens once that new.target is undefined (because a consumer forgot to write new). With the current semantics, I get a TypeError, which is fine. With the semantics "defaults to the first argument", there is a good chance that I get an unwanted result.
Another argument is consistency with Reflect.get and Reflect.set.
|
Here is an argument for the current semantics "is absent". Let’s say I write function Bar() {
// ....
const obj = Reflect.construct(Foo, args, new.target)
// ...
return obj
}assuming that Another argument is consistency with Reflect.get and Reflect.set. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Jul 28, 2016
Contributor
It does? In the current spec, I count 64 occurrences of "is present" and 57 of "is not present" (plus 6 of "is absent"). Those are quite close to the counts for ES6, and way more than the counts for ES5.
@jmdyck Your counting is flawed. If you look closely, you'll see that only 4 of the 57 occurrences of "is present" has to do with a supplied argument to a function of the standard library. On the other hand, you missed "is supplied" (Date.UTC), "number of actual arguments" (String.prototype.splice), etc.
@jmdyck Your counting is flawed. If you look closely, you'll see that only 4 of the 57 occurrences of "is present" has to do with a supplied argument to a function of the standard library. On the other hand, you missed "is supplied" (Date.UTC), "number of actual arguments" (String.prototype.splice), etc. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jmdyck
Jul 28, 2016
Collaborator
only 4 of the 57 occurrences of "is present" has to do with a supplied argument to a function of the standard library
The original post didn't make that restriction, so I didn't either.
you missed "is supplied", "number of actual arguments", etc
Yup. The original post only talked about "presence", so I only looked for "is [not] present/absent".
The original post didn't make that restriction, so I didn't either.
Yup. The original post only talked about "presence", so I only looked for "is [not] present/absent". |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bterlson
Sep 12, 2016
Member
There is a distinction for built-in functions between "is not present" and "is present but undefined" that I don't think we want to remove at this time.
|
There is a distinction for built-in functions between "is not present" and "is present but undefined" that I don't think we want to remove at this time. |
ljharb commentedJul 27, 2016
https://tc39.github.io/ecma262/#sec-reflect.construct step 2.
In general it seems like we've tried to change "presence" to "isn't undefined" in the spec. Is this an oversight, or intentional?