tc39 / proposal-binary-ast

Binary AST proposal for ECMAScript
965 stars 23 forks source link

.length property should be available for lazy function #49

Closed arai-a closed 6 years ago

arai-a commented 6 years ago

Currently FormalParameters params field is inside FunctionExpressionContents interface, which has [Lazy] attribute inside LazyFunctionExpression interface. Function object's .length property needs that information, even before executing the function.

interface LazyFunctionExpression : Node {
  attribute boolean isAsync;
  attribute boolean isGenerator;
  attribute BindingIdentifier? name;
  attribute FrozenArray<Directive> directives;
  [Lazy] attribute FunctionExpressionContents contents;
};

interface FunctionExpressionContents : Node {
  attribute boolean isFunctionNameCaptured;
  attribute boolean isThisCaptured;
  attribute AssertedParameterScope parameterScope;
  attribute FormalParameters params;
  attribute AssertedVarScope bodyScope;
  attribute FunctionBody body;
};

if we're going to entirely skip parsing FunctionExpressionContents contents field for lazy functions until executing the function, the length of formal parameters should be put into LazyFunctionExpression interface.

arai-a commented 6 years ago

@syg I'm about to add attribute unsigned long length; to LazyFunctionExpression (also declaration/method/etc). Do you think it's better adding it also to EagerFunctionDeclaration as well for consistency?

syg commented 6 years ago

@arai-a Missed this. Good question... I'd add it for both eager and lazy.

arai-a commented 6 years ago

thanks!