Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1877322.0HhiMAB5S9@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 13 Oct 2012 21:55:08 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 153 NNTP-Posting-Date: 13 Oct 2012 21:55:08 CEST NNTP-Posting-Host: 2f6ade72.newsspool4.arcor-online.net X-Trace: DXC=\dI[OQ9=9N9NTD55K=4IUKDZm8W4\YJNK02;Jo[T\CQb5W[[7HSFnmU? X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:16606 Patricia Shanahan wrote: > John G Harris wrote: >> Patricia Shanahan wrote: >> >>> According to the grammar in >>> http://www.ecma-international.org/ecma-262/5.1/, Statement can be >>> expanded to Block, so some blocks are statements. On the other hand, >>> there are contexts which require Block rather than Statement, for >>> example in a TryStatement. A block that appears where a statement is not >>> permitted cannot be a statement. >> >> >> I don't agree with your reasoning there. The standard says 'try' must be >> followed by a block statement. If it said that 'try' must be followed by > > Could you give me a reference for where you are getting the phrase > "block statement"? > > I've searched both http://www.ecma-international.org/ecma-262/5.1/ and a > recently downloaded copy of > http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf, > and without finding the phrase. Maybe there is some other document I > should be consulting. If so, please give me a pointer. Section "12.1 Block" of the ECMAScript Language Specification, 5.1 Edition (and all previous Editions; section numbering may differ) is a subsection of section "12 Statements". That, the productions for the /Statement/ goal symbol defined in the latter section – | Statement : | Block | VariableStatement | EmptyStatement | ExpressionStatement | IfStatement | IterationStatement | ContinueStatement | BreakStatement | ReturnStatement | WithStatement | LabelledStatement | SwitchStatement | ThrowStatement | TryStatement | DebuggerStatement (previous Editions contain the productions starting from LabelledStatement to a varying degree) –, and that an ECMAScript program is produced from | 14 Program | | Syntax | | Program : | SourceElements_opt | | SourceElements : | SourceElement | SourceElements SourceElement | | SourceElement : | Statement | FunctionDeclaration specify that what can be produced from the Block goal symbol is considered a statement, or, IOW, that there is a Block statement. This may be colloquially written "block statement". The syntax for "12.14 The try Statement" (which *also* is a subsection of section 12) is: | TryStatement : | try Block Catch | try Block Finally | try Block Catch Finally | | Catch : | catch ( Identifier ) Block | | Finally : | finally Block This means that the `try' keyword must be followed by a statement, specifically a Block statement. That there is a Block statement and a LabelledStatement in ECMAScript is one reason why return { foo: "bar" }; produces unexpected results as it is equivalent to return; { foo: "bar"; }; where the `undefined' value is returned and `foo' is considered a label for the "bar" ExpressionStatement. Which has been correctly observed by Crockford, among others. [His conclusion from that, that Allman style is inappropriate on the whole in ECMAScript implementations is premature and fallacious, though. For it is exactly the ambiguity between Block statements and Object initializers, and Function declarations and Function expressions that makes it a good idea to format them differently: if (foo) { bar(); } but return { foo: "bar" }; and function foo (bar) { baz(); } but var foo = function (bar) { baz(); }; and, by extension, var foo = (function (baz) { return function bar (foobar) { return foobar(bar, baz); }; }(42)); ] PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1 ) // Plone, register_function.js:16