tc39 / ecma262

Status, process, and documents for ECMA-262
https://tc39.es/ecma262/
Other
15.03k stars 1.28k forks source link

ToObject should specify what realm it uses #1104

Open domenic opened 6 years ago

domenic commented 6 years ago

https://tc39.github.io/ecma262/#sec-toobject

Return a new Boolean object

Which Boolean constructor or %BooleanPrototype% should this use? The spec definitely means the current Realm, but it'd be nice to be explicit.

ljharb commented 5 years ago

@domenic would you consider it sufficiently explicit if the table said return a new %Boolean% object? if not, do you have a suggestion for text? I'm happy to make the PR to update all the similar cases in that section.

domenic commented 5 years ago

Hmm. I think probably we should close this. I'm not sure why I filed this issue to pick on this one particular instance of "a new X object" in the spec as not being specific enough. But in general this is a widespread "problem" in the spec, which is probably not worth fixing piecemeal, and likely not worth fixing at all.

If there is a solution, it'd be more general; something like defining "new X object" (similar to https://heycam.github.io/webidl/#internally-create-a-new-object-implementing-the-interface), and stating that by default the realm used is always the current realm. But that's a big project with dubious payoff, so I'd be fine closing this over-specific issue.

allenwb commented 5 years ago

All operations that don't explicitly reference a specific realm operate using the current realm. That's kind of implicit in the concept of a "current realm" but if you wanted to explicitly state it somewhere perhaps the into to Clause 7 would be a place to put it.

Note sure that mentioning %Boolean% etc. in ToObject would be appropriate as the intent isn't to actually call the constructor function. If you want to be more explicit then what is already in ToObject (a I'm not really sure that is necessary you should probably define Boolean, Number, and Symbol analogs to StringCreate ( value, prototype ) and use them in ToObject.

ljharb commented 5 years ago

It sounds like there’s a few possible ways forward here:

  1. Close the issue, status quo
  2. Add text to Clause 7 that explicitly mentions that the current realm is implied
  3. Replace (presumably all) instances of “a new X object” with a call into an abstract operation that explicitly references the current realm.
  4. Explicitly define the phrase “a new X object” a la https://heycam.github.io/webidl/#internally-create-a-new-object-implementing-the-interface

2 can happen whether 3/4 does or not, of course.

I don’t feel too strongly about the direction; but i do think it’s worth doing something especially if the implicitness here is a pervasive occurrence.

cc @zenparsing

allenwb commented 5 years ago

Note that the realm is only only used for choosing the value of the prototype object so passing a prototype as an argument to CreateXXX functions is sufficient.

But, I ssuggest just doing #2 so you have something to point at if this question is asked again.

jmdyck commented 5 years ago

Explicitly define the phrase “a new X object” ...

Note that #1453 and #1460 have a lot to do with the phrase "a newly created [X] object", so we'd probably want efforts to co-ordinated.