Strict Mode and Function
On 02.06.2010 13:13, Dmitry A. Soshnikov wrote:
So, is it an err in the Annex C statement or the tests are incorrect? I don't see the same restriction in the exact 15.3.2 section as it mentioned in the Annex C.
Seems, it is correct in all cases, we've just found out it. Sorry for confusing.
var f = Function("eval", "'use strict'; alert(eval);");
that should throw an SyntaxError and exactly that is said in the Annex C I guess -- "...a strict mode /function/ using the Function constructor" which means that a "strict mode" directive should be inside the function. But still formulation of the annex bullet may confuse other.
Dmitry.
From: Dmitry A. Soshnikov
But he referenced to the conformance test suite -- es5conform.codeplex.com and in particular for these test cases -- vserver.rosseaux.net/stuff/tests
where is said that "arguments" and "eval" are allowed in such cases:
vserver.rosseaux.net/stuff/tests/15.3.2.1-11-7-s.js -- arguments vserver.rosseaux.net/stuff/tests/15.3.2.1-11-4-s.js -- eval
These tests are valid. The constructed function is not "strict" because its body does not contain a "use strict" directive. The strictness of the caller of the Function constructor does not affect the strictness of the constructed function. That's what these tests are verifying WRT strict function formal parameter restrictions.
Test 15.3.2.1-11-3-s.js verifies that using 'eval' as a formal parameter to a constructed function containing a "use strict" directive throws a SyntaxError. The need be another similar test for 'arguments'.
So, is it an err in the Annex C statement or the tests are incorrect? I don't see the same restriction in the exact 15.3.2 section as it mentioned in the Annex C.
See step 10 of 15.3.2.1
On 02.06.2010 22:22, Allen Wirfs-Brock wrote:
From: Dmitry A. Soshnikov
But he referenced to the conformance test suite -- es5conform.codeplex.com and in particular for these test cases -- vserver.rosseaux.net/stuff/tests
where is said that "arguments" and "eval" are allowed in such cases:
vserver.rosseaux.net/stuff/tests/15.3.2.1-11-7-s.js -- arguments vserver.rosseaux.net/stuff/tests/15.3.2.1-11-4-s.js -- eval
These tests are valid. The constructed function is not "strict" because its body does not contain a "use strict" directive.
Yeah, I've already found out it (mentioned it in the second letter right after the first one). But really, this sentence from the Annex C is confusing. And without attentive reading 15.3.2.1, it can confuse.
The strictness of the caller of the Function constructor does not affect the strictness of the constructed function.
That's not relates only for Function functions. The strictness of the caller does not affect any function. However, the strictness is inherited lexically for FD (function declaration) and FE (function expression). But not for the Function functions. And that exactly I was confused after reading only that bullet from the Annex C.
So, is it an err in the Annex C statement or the tests are incorrect? I don't see the same restriction in the exact 15.3.2 section as it mentioned in the Annex C.
See step 10 of 15.3.2.1
Yup, as I said, I've already found out it and updated the document. But, thanks anyway for additional clarifications -- I think it will be useful for other to avoid such confusions. Btw, step 9 of 15.3.2.1 already informs us that Function function do not inherit the strictness from surrounding context(s).
Dmitry.
Hello,
Recently I was writing an article about strict mode in ES5 (bit.ly/928Jwl).
At the moment, the only implementation for testing is already mentioned here -- BESEN engine. BESEN still has some bugs (some of them I’ve reported while was writing the article and glad to see that several bugs are already fixed), but it is a good candidate for ES5 programming and testing.
Nevertheless, the talk isn't about BESEN, but about inconsistent of the "Annex C (informative) The Strict Mode of ECMAScript" entry and the test suite cases related with the strict mode and functions created via the Function constructor.
That bullet of the Annex C statements:
"It is a SyntaxError to use within strict mode code the identifiers /eval/ or /arguments/ as the Identifier of a FunctionDeclaration or FunctionExpression or as a formal parameter name (13.1). Attempting to /dynamically define such a strict mode function using the Function constructor/ (15.3.2) will throw a /SyntaxError/ exception."
I've posted a bug to the BESEN's author -- bit.ly/bmkN1p
But he referenced to the conformance test suite