New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`Reflect.construct`: "is not present" → "is not undefined"? #647

Closed
ljharb opened this Issue Jul 27, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@ljharb
Member

ljharb commented Jul 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?

@jmdyck

This comment has been minimized.

Show comment
Hide comment
@jmdyck

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.)

Collaborator

jmdyck commented Jul 27, 2016

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.)

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

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.

Contributor

claudepache commented Jul 28, 2016

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.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

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.

Contributor

claudepache commented Jul 28, 2016

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

This comment has been minimized.

Show comment
Hide comment
@jmdyck

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".

Collaborator

jmdyck commented Jul 28, 2016

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".

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

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.

Member

bterlson commented Sep 12, 2016

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.

@bterlson bterlson closed this Sep 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment