-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
NativeFunction vs web reality #1941
Comments
Looks like we need a test262 test that covers this, since V8 supposedly passes all of the F.p.toString tests: https://test262.report/browse/built-ins/Function/prototype/toString
I'd be interested to know if any engines have chosen to wilfully violate the spec here or if this is just an implementation oversight. I assume that it's the latter because this portion of the spec was refined not long ago. |
The spec is just kind of nonsensical in this case (emphasis mine):
PropertyName cannot ever match |
Good catch. There’s no way for an implementation to adhere to both requirements, then, so this at least partly a spec issue. (Would add that PropertyName does match Related: is there any concept of a canonical representation of a property name? E.g. — pseudo algorithm — “if it could be the valid string value of IdentifierName or is a canonical numeric string, return it as is; otherwise if it is a string, return JSON.stringify(name); otherwise [do something with symbol]...” |
I think the canonical thing is |
No it's not. Pay attention to the first part of that sentence.
All Well-Known Intrinsic Objects that are functions have a
I am the author. The intention was that the synthesised string would be matched by |
@michaelficarra Are you saying that this works because no WKIOs are non-anonymous accessors (whose initial name values contain a space)? (If so, it seems a bit odd if this implies a hidden(?) requirement that e.g. %Map.prototype.size% must not become “well-known” on account of having a name that contains a space.) |
That is correct. |
@michaelficarra interesting. is that actually meant to be well known intrinsics and not all intrinsics? being a well known intrinsic is just whether or not we have a internal name for something, it's not detectable or anything. |
I’m surprised to hear that relationship; anything is eligible to be a well-known intrinsic, including getters and setters. |
See tc39/Function-prototype-toString-revision#29 for the thread about built-in getters and tc39/Function-prototype-toString-revision#10 about intrinsics. We can always make the requirement stronger by expanding it to other intrinsics. You're free to try to take on that work with a follow-on proposal. |
I’d personally prefer if we could get away with returning the |
There appears to be a majority desire on the committee for native accessors to be represented similarly to author-defined accessors, which manifest differently based on how they are defined:
Given that built-in accessors have "get " or "set " prepended to their |
Testing with
Map.prototype.__lookupGetter__('size').toString()
:function get size() {\n [native code]\n}
function size() {\n [native code]\n}
function get size() { [native code] }
The JSC and V8 results don’t conform to
NativeFunction
. The part between "function" and "(" isPropertyName[opt]
, which would allow for a computed name like e.g.["get size"]
, but not the two bare identifiersget size
. SpiderMonkey does seem to conform by omitting theget
.I’m not sure if this is an implementation issue for those engines or if the NativeFunction grammar itself is overconstrained. I believe (though I’m not certain) that the main objective of the NativeFunction requirement is to ensure the reported string cannot be successfully evaluated, and that property is maintained by the JSC and V8 results.
Results are similar for non-intrinsic native functions in platform APIs.
The text was updated successfully, but these errors were encountered: