Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #9759

Re: Simulate goto

Message-ID <1932615.aqSPkdTlGX@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2011-12-29 12:18 +0100
Subject Re: Simulate goto
Newsgroups comp.lang.javascript
References (1 earlier) <4ef9a823$0$6842$e4fe514c@news2.news.xs4all.nl> <1931071.aqSPkdTlGX@PointedEars.de> <OnnMPUAzo0+OFwwl@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD> <1367331.WGnKmheAe9@PointedEars.de> <9m1iteFodiU1@mid.uni-berlin.de>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Jake Jarvis wrote:

> On 28.12.2011 19:10, Thomas 'PointedEars' Lahn wrote:
>> AIUI, it should be possible to use an enclosing /Statement/ (like a
>> /Block/ statement) and a `break' statement here (section 12.8):
>>
>>    function testGoto()
>>    {
>>      var isFirst = true;
>>      if (true)
>>      {
>> skipPoint:
>>        window.alert("Using goto\n");
>>
>>        if (isFirst)
>>        {
>>          isFirst = false;
>>          break skipPoint;
>>          window.alert("This part is skipped");
>>        }
>>      }
>>    }
>>
>> However, Google V8 3.5.10.9+ in Chromium 15.0.874.121 (Developer Build
>> 109964 Linux) considers that a syntax error as well (same error message:
>> "SyntaxError: Undefined label 'skipPoint'").  Is this a bug?
> 
> No.
> Why should it work?
> I think there is slight confusion as to what it means for a statement to
> be 'enclosing' another.

No, but there was a misconception on my part as to the definition of a label 
set:

| 12 Statements
| 
| Semantics
| 
| A /Statement/ can be part of a /LabelledStatement/, which itself can be
| part of a /LabelledStatement/, and so on. The labels introduced this way
| are collectively referred to as the "current label set" when describing
| the semantics of individual statements. A /LabelledStatement/ has no
| semantic meaning other than the introduction of a label to a /label set/.
| The label set of an /IterationStatement/ or a /SwitchStatement/ initially
| contains the single element empty. The label set of any other statement is
| initially empty.
|
| […]
| 12.12 Labelled Statements 
| 
| The production /Identifier/ : /Statement/ is evaluated by adding
| /Identifier/ to the label set of /Statement/ and then evaluating
| /Statement/. If the /LabelledStatement/ itself has a non-empty label set,
| these labels are also added to the label set of /Statement/ before
| evaluating it. If the result of evaluating Statement is (break, V, L)
| where L is equal to /Identifier/, the production results in (normal, V,
| empty).
| 
| Prior to the evaluation of a /LabelledStatement/, the contained
| /Statement/ is regarded as possessing an empty label set, unless it is an
| /IterationStatement/ or a /SwitchStatement/, in which case it is regarded
| as possessing a label set consisting of the single element, empty.

That is, the label set of a statement consists of the labels used for *that* 
statement, _not_ the labels used *within* it.  Therefore, the following is 
syntactically correct and compiles in the named implementation without 
error:

  function testGoto()
  {
    var counter = 0;
    
    skipPoint:
    {
      window.alert(counter);

      if (counter === 0)
      {
        ++counter;
        break skipPoint;
        window.alert("This part is skipped");
      }
    }
  }

However, this does _not_ "simulate goto", i. e. the counter is only shown 
once.  That is – unless I am overlooking something – intended by the 
Specification: The `break' statement with /Identifier/ merely ends the 
evaluation of the so labelled statement prematurely:

| A /BreakStatement/ with an /Identifier/ is evaluated as follows:
| 
| 1. Return (break, empty, /Identifier/).

See section 12.12 quoted above on how that result affects the evaluation of 
the enclosing statement labelled with /Identifier/.


PointedEars
-- 
When all you know is jQuery, every problem looks $(olvable).

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Simulate goto Archos <raul.san@sent.com> - 2011-12-27 01:19 -0800
  Re: Simulate goto Archos <raul.san@sent.com> - 2011-12-27 01:50 -0800
    Re: Simulate goto Archos <raul.san@sent.com> - 2011-12-27 02:09 -0800
      Re: Simulate goto Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-12-27 11:31 +0100
  Re: Simulate goto "Tom de Neef" <tdeneef@qolor.nl> - 2011-12-27 12:12 +0100
    Re: Simulate goto Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-27 18:27 +0100
      Re: Simulate goto John G Harris <john@nospam.demon.co.uk> - 2011-12-28 16:56 +0000
        Re: Simulate goto Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-28 19:10 +0100
          Re: Simulate goto Jake Jarvis <pig_in_shoes@yahoo.com> - 2011-12-28 23:18 +0100
            Re: Simulate goto Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-29 12:18 +0100
              Re: Simulate goto John G Harris <john@nospam.demon.co.uk> - 2011-12-29 16:31 +0000
                Re: Simulate goto Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-29 17:47 +0100
                Re: Simulate goto John G Harris <john@nospam.demon.co.uk> - 2011-12-30 11:04 +0000
                Re: Simulate goto Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-30 16:10 +0100
  Re: Simulate goto John G Harris <john@nospam.demon.co.uk> - 2011-12-27 14:41 +0000
  Re: Simulate goto Denis McMahon <denismfmcmahon@gmail.com> - 2011-12-27 15:32 +0000
    Re: Simulate goto Gene Wirchenko <genew@ocis.net> - 2011-12-27 10:12 -0800
      Re: Simulate goto "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-27 19:55 +0000
        Re: Simulate goto Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2011-12-27 21:49 +0100
          Re: Simulate goto Denis McMahon <denismfmcmahon@gmail.com> - 2011-12-27 23:07 +0000
          Re: Simulate goto John G Harris <john@nospam.demon.co.uk> - 2011-12-28 16:28 +0000
            Re: Simulate goto Nomen Nescio <nobody@dizum.com> - 2011-12-28 22:33 +0100
        Re: Simulate goto Gene Wirchenko <genew@ocis.net> - 2011-12-27 13:19 -0800
          Re: Simulate goto "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-27 22:02 +0000
            Re: Simulate goto Tim Streater <timstreater@greenbee.net> - 2011-12-27 22:18 +0000
              Re: Simulate goto Mike Duffy <Use_guestbook_page@website.in.sig> - 2011-12-28 00:23 +0000
                Re: Simulate goto John G Harris <john@nospam.demon.co.uk> - 2011-12-28 16:37 +0000
                Re: Simulate goto Tim Streater <timstreater@greenbee.net> - 2011-12-28 17:44 +0000
                Re: Simulate goto Mike Duffy <Use_guestbook_page@website.in.sig> - 2011-12-29 01:16 +0000
                Re: Simulate goto Gene Wirchenko <genew@ocis.net> - 2011-12-28 17:34 -0800
                Re: Simulate goto "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-29 08:27 +0000
                Re: Simulate goto Dr J R Stockton <reply1152@merlyn.demon.co.uk> - 2011-12-30 20:54 +0000
                Re: Simulate goto Tim Streater <timstreater@greenbee.net> - 2011-12-31 11:55 +0000
            Re: Simulate goto Gene Wirchenko <genew@ocis.net> - 2011-12-27 14:50 -0800

csiph-web