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

%ThrowTypeError%.toString() is not clearly defined #14

Closed claudepache closed 7 years ago

claudepache commented 7 years ago

The Function.prototype.toString() definition says:

  1. If func is (...) a built-in Function object, etc. (...) Additionally, if func is a Well-known Intrinsic Object, the portion of the returned String that would be matched by BindingIdentifier must be the initial value of the name property of func.

However, the intrinsic %ThrowTypeError% is anonymous, and ECMA262 requires the name property only for non-anonymous built-in functions (Section 17)

In implementation reality, the name property of %ThrowTypeError% varies between undefined (Chakra) and "" (SM, V8, JSC).

Possible fix: use anonymous in place of the name for anonymous function.

claudepache commented 7 years ago

... or maybe the requirement should be only for non-anonymous well-known intrinsic objects.

michaelficarra commented 7 years ago

I think we should just make it an invariant that all well-known intrinsics that are functions be given names. Basically, add

The value of the name property of %ThrowTypeError% is "ThrowTypeError".

to 9.2.7.1. I'll open a PR.

michaelficarra commented 7 years ago

By the way @claudepache, how did you get a reference to this intrinsic in order to observe its name?

claudepache commented 7 years ago

how did you get a reference to this intrinsic in order to observe its name?

var ThrowTypeError = (function() { "use strict"; return Object.getOwnPropertyDescriptor(arguments, "callee").get })()