Ticket #69 (new defect)

Reporter


Reid Burke
Opened: 01/19/12
Last modified: 01/19/12
Status: new
Type: defect

Owner


Nicholas C. Zakas
Target Release:
Priority: P3 (normal)
Summary: Coverage instrumentation can change labelled statements causing a continue statement SyntaxError
Description:

Consider a JavaScript program that uses nested loops like this:


var i = 0;
for (var j = 0; j < 10; j++) {
testLoop:
while (i < 10) {
i++;
log.appendChild(p("Inner loop: i = " + i + ", j = " + j));
continue testLoop;
}
}

In this simple example, continue breaks to the while loop labelled with "testLoop". In JavaScript, an identifier used with continue can only reference a looping labeled statement (an
IterationStatement).

YUI Test Coverage would instrument the above labelled statement in this manner:


testLoop:
_yuitest_coverline();
while (i < 10) {
_yuitest_coverline();
i++;
_yuitest_coverline();
log.appendChild(p("Inner loop: i = " + i + ", j = " + j));
_yuitest_coverline();
continue testLoop;
_yuitest_coverline();
}

In this example, the testLoop label no longer references the while loop. This code is syntactically incorrect and will raise a SyntaxError at parse time.

For an interactive example, see: http://jsfiddle.net/reid/psphd/1/

For more about the behavior of the continue statement, see ECMA-262 Sec. 12.7, 3rd or 5th Edition or MDN's JS label reference.

Easy to read MDN reference: http://_Sdeveloper.mozilla.org/en/JavaScript/Reference/Statements/label

This bug prevents YUI's selector-css2 module from being used with YUI Test Coverage.

We use a labelled looping statement here: http://_Sgithub.com/yui/yui3/blob/master/build/selector-css2/selector-css2.js#L172

Type: defect Observed in Version: development master
Component: Coverage Severity: S2 (high)
Assigned To: Nicholas C. Zakas Target Release:
Location: Library Code Priority: P3 (normal)
Tags: Relates To:
Browsers: All
URL: http://jsfiddle.net/reid/psphd/1/
Test Information:

Change History

Reid Burke

YUI Developer

Posted: 01/19/12
  • blocks changed to 49

The bug was originally reported in #49.

I opened this bug to track this defect separately.

Apologies for the HTTPS URL mojibake in the description, I'm not sure why Trac does that.