André Bargull (2013-07-28T11:13:20.000Z)
domenic at domenicdenicola.com (2013-08-01T01:42:57.093Z)
> Looking at the ES6 spec draft, I've drawn the following conclusions > about Completion Records. Can someone confirm? > > If [[type]] is 'normal', 'return', or 'throw', > [[target]] must be 'empty' (can't be an identifier). > > Moreover, if [[type]] is 'return' or 'throw', > [[value]] must be a language value (can't be 'empty'). Looks reasonable but I haven't verified it myself. > If [[type]] is 'continue' or 'break', no restrictions: > [[target]] can be 'empty' or an Identifier, > [[value]] can be 'empty' or a language value, > and all combinations can occur. > > ... > > The only ones whose existence is less than obvious are those where: > [[type]] is 'continue' or 'break', and [[value]] is a language value > I can see in the pseudo-code the points where they could be created > (in 12.1.1.2, 12.11.1.2, and 14.1.2), but I haven't tried to reverse- > engineer a program that would cause it to happen. Could someone explain > why it's useful to allow such Completion Records, and post a snippet of > code that would cause one to be created? 12.1.1.2 is the important one here. For example take this test case which is expected to return "value": ``` L1: do { "value"; Completion {[[type]]: normal, [[value]]: "value", [[target]]: empty} break L1; Completion {[[type]]: break, [[value]]: empty, [[target]]: "L1"} } Completion {[[type]]: break, [[value]]: "value", [[target]]: "L1"} while(false); Completion {[[type]]: normal, [[value]]: "value", [[target]]: empty} ``` 'continue' works the same and just ignore for now that 12.6.1.1 step 2.c in the current draft is invalid (it needs to add an additional step to convert a break completion value to a normal completion value, cf. 12.6.1 in the ES5.1 spec). 14.1.2 is only needed to inspect the completion record value: `eval('L1: do { "value"; break L1; } while(false);') === "value"`