Semantics of VariableStatement in ECMAScript

The product of VariableStatement:

var VariableDeclarationList ; 

evaluated as follows:

  • Rate it VariableDeclarationList.
  • To return (normal, empty, empty).

I want to know about the meaning of normal and empty.

+5
source share
1 answer

ECMAScript describes an internal type for explaining the behavior of statements, which is called the Type of Completion Specification .

Values ​​of the completion type are triples of the form (type, value, target), where:

  • typeIt can be normal, break, continue, returnor throw.
  • valuecan be any language value or empty.
  • targetmay be any Identifieror empty.

VariableStatement , , .

, , , , Block, Empty Statement, ExpressionStatement, debugger statement ( ) ..

A FunctionDeclaration ( , SourceElement) (normal, empty, empty), , :

eval("function f(){}"); // returns undefined

eval function , normal, empty, undefined (. 7 eval), :

eval("(function f(){})"); // returns a function object

PrimaryExpression, ExpressionStatement, (normal, GetValue(exprRef), empty), expRef FunctionExpression.

type, normal, " ".

:

function foo() {
  return 5;
}
foo();

return foo , (return, 4, empty).

target break continue, LabelledStatement, :

foo: while(true) {
  while(true) {
    break foo;
  }
}

break (break, empty, foo), while , foo.

, , , break, continue, return throw.

+7

All Articles