Giter Club home page Giter Club logo

Comments (3)

keeyipchan avatar keeyipchan commented on July 23, 2024

Hmm, I think this may be a false alarm. Comparing [3] and [4]'s scope objects, I noticed that they differ in the functionExpressionScope field

3: Scope
block: Object
directCallToEvalScope: false
dynamic: false
functionExpressionScope: true
left: null
references: Array[0]
set: Map
taints: Map
thisFound: false
through: Array[0]
type: "function"
upper: Scope
variableScope: Scope
variables: Array[1]
__proto__: Scope

4: Scope
block: Object
directCallToEvalScope: false
dynamic: false
functionExpressionScope: false
left: null
references: Array[0]
set: Map
taints: Map
thisFound: false
through: Array[0]
type: "function"
upper: Scope
variableScope: Scope
variables: Array[1]
__proto__: Scope

This means that [4].upper = [3], [4].variables = ['arguments'], [3].variables = ['move']

@Constellation Would you mind explaining why it's necessary to create a hierarchy for named function expressions rather than just having something like [4].variables = ['arguments', 'move']?

from escope.

Constellation avatar Constellation commented on July 23, 2024

This is because escope scope hierachy is very precise to ECMA262 5th spec.
According to the ECMA262 5th section 13

The production
FunctionExpression : function Identifier ( FormalParameterListopt ) { FunctionBody }
is evaluated as follows:

  1. Let funcEnv be the result of calling NewDeclarativeEnvironment passing the running execution context’s Lexical Environment as the argument
  2. Let envRec be funcEnv’s environment record.
  3. Call the CreateImmutableBinding concrete method of envRec passing the String value of Identifier as the argument.
  4. Let closure be the result of creating a new Function object as specified in 13.2 with parameters specified by FormalParameterListopt and body specified by FunctionBody. Pass in funcEnv as the Scope. Pass in true as the Strict flag if the FunctionExpression is contained in strict code or if its FunctionBody is strict code.
  5. Call the InitializeImmutableBinding concrete method of envRec passing the String value of Identifier and closure as the arguments.
  6. Return closure.

So escope creates scope for FunctionExpression's name.

from escope.

keeyipchan avatar keeyipchan commented on July 23, 2024

Thank you, that explains it.

from escope.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.