tc39 / Function-prototype-toString-revision

:fishing_pole_and_fish: ECMA-262 proposal to update Function.prototype.toString
https://tc39.github.io/Function-prototype-toString-revision
26 stars 10 forks source link

Spacing in NativeFunction underspecified #21

Open mgol opened 7 years ago

mgol commented 7 years ago

If I understand correctly, the specified syntax for NativeFunction:

function IdentifierNameopt ( FormalParameters ) { [ native code ] }

doesn't specify how spaces are laid out. I expect spaces in the above line are needed for readability of the output so the real spaces in the output should be determined by a special symbol like <SP>, shouldn't they?

For comparison, this is the output of Array.toString() in Chrome 55:

"function Array() { [native code] }"

In particular, there is no space after IdentifierNameopt or before & after native code.

michaelficarra commented 7 years ago

@mgol If you can show that there is already a reasonable compatibility for spacing between existing implementations and that a resolution of any incompatibilities will not be web-breaking, I would happily accept a PR to specify the spacing for the cases which are currently only required to be matched by NativeFunction.

mgol commented 7 years ago

From my tests, the stringification:

`function Array() { [native code] }`

is used by Chrome, Edge & the old Android Browser (4.1-4.3) while the one:

`function Array() {
    [native code]
}`

is used by Firefox, Safari & Android 2.3.

IE 11 uses:

`
function Array() {
    [native code]
}
`

(with an additional new line at the beginning and the end) but that shouldn't matter since Edge switched to match Chrome.

There are three options here:

  1. One of the two groups decides to switch to the other group's format (who can be pinged to provide us with their decisions?).
  2. The syntax is specified to allow one of the two formats but nothing else.
  3. We leave it as it is now.

I'd prefer (1), then (2), if (1) turns out not possible. What do you think?

EDIT: The 4th option would be to specify sth like:

function <SP> IdentifierNameopt <SP>opt ( FormalParameters ) <SP> { StrWhiteSpace [ native <SP> code ] StrWhiteSpace }

which is matched by all browsers (Edge included) except IE.

mgol commented 7 years ago

Also, do you have examples of native functions that either don't specify IdentifiedName or provide a non-empty FormalParameters list?

ExE-Boss commented 5 years ago

I agree with using function <SP> IdentifierNameopt <SP>opt ( FormalParameters ) <SP> { StrWhiteSpace [ native <SP> code ] StrWhiteSpace }.