tc39 / proposal-function-implementation-hiding

JavaScript language proposal: function implementation hiding
https://ci.tc39.es/preview/tc39/ecma262/pull/1739
MIT License
98 stars 7 forks source link

GetDirectiveContext broken? #36

Closed waldemarhorwat closed 4 years ago

waldemarhorwat commented 4 years ago

I'm having trouble reviewing what GetDirectiveContext is doing. It seems to make some unstated assumptions about what happens to be on the execution context stack at the time it is called. I can't tell whether that matches the lexical scope for all of the possible call paths and whether that will continue to be the case in the future.

Assuming that GetDirectiveContext does produce lexical scoping, its current implementation is broken because it only looks up one level. Consider the code:

function A() {
  "hide implementation";
  return function B() {
    ...
    return function C() {...}
  }
}

Function A's implementation will be hidden (via step 5 of FunctionInitialize), as will function B's (via GetDirectiveContext and step 7b of FunctionInitialize). However, function C's implementation will not be hidden. This seems strange.

allenwb commented 4 years ago

I don't understand why the execution context stack is involved.

The presence or absence of a "directive" is a static characteristic of the source text (or surrounding source text) of a function. The specification should not require a code execution context in order to determine whether a directive is present for any function.

michaelficarra commented 4 years ago

I'm going to close this issue to keep discussion related to how we specify this within the spec repo. See you in https://github.com/tc39/ecma262/pull/1739.