![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: |
|
If I understood correctly the following program should alert 'undefined': alert(eval('3;;')); The last source-element would be ";" (the empty statement), and this statement returns 'empty' as value (12.3) which is then transformed to 'undefined' by the eval (15.1.2.1). All engines I tried (Rhino, FF and Konqueror) however return '3', as if the the evaled body was in a block. (According to 12.1 inside a block the last statement not returning 'empty' is used as return value). |
#3
| |||
| |||
|
|
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;')); The last source-element would be ";" (the empty statement), and this statement returns 'empty' as value (12.3) which is then transformed to 'undefined' by the eval (15.1.2.1). All engines I tried (Rhino, FF and Konqueror) however return '3', as if the the evaled body was in a block. (According to 12.1 inside a block the last statement not returning 'empty' is used as return value). Is this a bug in these engines, or did I misinterpret the spec? Another question for VariableDeclarations: Why does the production 'VariableDeclaration: Identifier' and the production 'VariableDeclaration: Identifier Initialiser' return a sequence of characters? I can't find how these strings could be used. mfg, // florian loitsch |
#4
| |||
| |||
|
|
On Jan 3, 4:01 pm, florian.loit... (AT) gmail (DOT) com wrote: According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: Could you elaborate a little more on what you are talking about? What 'spec' do you mean? JavaScript specification? |
#5
| |||
| |||
|
|
On Jan 3, 4:01 pm, florian.loit... (AT) gmail (DOT) com wrote: According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;')); The last source-element would be ";" (the empty statement), and this statement returns 'empty' as value (12.3) which is then transformed to 'undefined' by the eval (15.1.2.1). All engines I tried (Rhino, FF and Konqueror) however return '3', as if the the evaled body was in a block. (According to 12.1 inside a block the last statement not returning 'empty' is used as return value). Is this a bug in these engines, or did I misinterpret the spec? [...] alert(eval('')); returns undefined as does alert(eval(';')); I suppose all of this may have something to do with the fact that ';' are not needed in javascript. But alert(eval('3\n\n')) returns three also. |
#6
| |||||
| |||||
|
|
(Sometimes when you don't have a single clue what the other person is talking about, it is better not to reply at all.) There is no JavaScript specification. |
|
The OP is referring to the ECMAScript Specification, of which Netscape/Mozilla.org's JavaScript is one implementation. |
|
You miss the point, which is the evaluation of the program "3;;". |
|
The last source-element would be ";" (the empty statement), and this statement returns 'empty' as value (12.3) which is then transformed to 'undefined' by the eval (15.1.2.1). |
|
I suppose all of this may have something to do with the fact that ';' are not needed in javascript. |
#7
| |||
| |||
|
|
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;')); The last source-element would be ";" (the empty statement), and this statement returns 'empty' as value (12.3) which is then transformed to 'undefined' by the eval (15.1.2.1). All engines I tried (Rhino, FF and Konqueror) however return '3', as if the the evaled body was in a block. (According to 12.1 inside a block the last statement not returning 'empty' is used as return value). Is this a bug in these engines, or did I misinterpret the spec? |
#8
| |||
| |||
|
|
On Jan 4, 1:01 am, florian.loit... (AT) gmail (DOT) com wrote: According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;')); The last source-element would be ";" (the empty statement), and this statement returns 'empty' as value (12.3) which is then transformed to 'undefined' by the eval (15.1.2.1). All engines I tried (Rhino, FF and Konqueror) however return '3', as if the the evaled body was in a block. (According to 12.1 inside a block the last statement not returning 'empty' is used as return value). Is this a bug in these engines, or did I misinterpret the spec? The specs are kind of OK, you are just mixing the runtime code execution and source text parsing. Semicolons do not constitute expressions in javascript: they are just "parsing helpers" for the parser [...] |
#9
| |||
| |||
|
|
[...] I'm going to refer to [the ECMAScript Specification] as the JavaScript specification. Because, in my lesser mind, even though ECMAScript is the standard, it would be the JavaScript specification. And it is also the JScript specification. And any other implementation. |
#10
| |||
| |||
|
|
VK wrote: On Jan 4, 1:01 am, florian.loit... (AT) gmail (DOT) com wrote: According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;')); The last source-element would be ";" (the empty statement), and this statement returns 'empty' as value (12.3) which is then transformed to 'undefined' by the eval (15.1.2.1). All engines I tried (Rhino, FF and Konqueror) however return '3', as if the the evaled body was in a block. (According to 12.1 inside a block the last statement not returning 'empty' is used as return value). Is this a bug in these engines, or did I misinterpret the spec? The specs are kind of OK, you are just mixing the runtime code execution and source text parsing. Semicolons do not constitute expressions in javascript: they are just "parsing helpers" for the parser [...] Wrong. The first semicolon is part of the StatementExpression that consists of the NumericLiteral followed by the semicolon. The second semicolon does indeed constitute what is produced by the EmptyStatement production. |
![]() |
| Thread Tools | |
| Display Modes | |
| |