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

fixes #25: add HostHasSourceTextAvailable hook #26

Closed michaelficarra closed 6 years ago

michaelficarra commented 6 years ago

If this is sufficient, this was way easier than I thought it would be.

/cc @domenic @phoddie

Fixes #25.

jdalton commented 6 years ago

@ljharb

"[unavailable code]"

Firefox OS (mobile) had something similar IIRC.

michaelficarra commented 6 years ago

@erights I invite you to voice any concerns you have in this PR.

michaelficarra commented 6 years ago

Ping @phoddie @erights

erights commented 6 years ago

Hi @michaelficarra I still don't like the host hook. I think it is a mistake. Most of what it legitimately tries to accomplish is better accomplished with the lexical directive. That said, in a world of scarce attention and "pick your battles" I am not inclined to pick this one.

phoddie commented 6 years ago

@michaelficarra, echoing @erights, I can live with the host hook but I don't know that it is needed at this point. Would it be enough to simply modify the existing specification text, e.g. "If the implementation cannot produce a source code string that meets these criteria then it must return NativeFunction"? This defers definition of mechanisms, such as those in the new censor proposal, while guaranteeing return of a consist string, which addresses the overall goal of this proposal, as I understand it.

domenic commented 6 years ago

That sounds like just an underspecified version of the host hook, which requires hosts to say "An implementation is unable to produce a source code string under the following circumstances:" instead of "An implementation defines HostHasSourceTextAvailable as:"

erights commented 6 years ago

Hi @phoddie I agree with @domenic on this point. The reason I think this whole mechanism is a mistake is its effect on what a correct program can assume. A correct program's correct behavior relies on some underlying platform obeying the contract the correct program correctly relies on.

Both the explicit host hook and your suggested text limits these contracts in the same painful way. But the host hook makes the pain explicit, which is better.

phoddie commented 6 years ago

@domenic it is exactly an underspecified version of the host hook, underspecified precisely consistent with the current spec text. As you, @erights, and @michaelficarra are comfortable adding the host hook now, we should move ahead with that.

michaelficarra commented 6 years ago

@phoddie In that case, can you review and approve this PR?

phoddie commented 6 years ago

@michaelficarra, done.