archives

« Bugzilla Issues Index

#4150 — "X is contained in strict code"


The spec has several conditions of the form:
"If X is contained in strict code or if its <child> is strict code, ..."
(I've appended a list.) I have a few comments about them.

----------
{1}
Presumably, the distinction that these conditions make between
"X is contained in strict code"
and
"Y is strict code"
relates to the fact that strictness can come "down from above" (inherited from
a strict parent) or "up from below" (via a Use Strict Directive in a Directive
Prologue). However, the definition of strict code covers this distinction, so
it shouldn't be necessary to repeat it elsewhere.

----------
{2}
In particular, if X is contained in strict code, then X *is* strict code
(though the converse is not always true, of course). And recursively, every
child of X is also strict code.

Thus, in each of the conditions under discussion, the first term implies the
second, so it suffices to check just the second.

----------
(3)
14.4.12 / groups 1 + 2:
GeneratorDeclaration : function * ... ( FormalParameters ) { GeneratorBody }
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
If the GeneratorDeclaration is contained in strict code
or if its GeneratorBody is strict code, ...

The condition's second term is presumably meant to mean "its GeneratorBody
begins with a 'use strict' directive", but it's debatable whether it achieves
that. Consider the derivation:

GeneratorDeclaration
-> GeneratorBody
-> FunctionBody
-> FunctionStatementList
-> StatementList
(-> Directive Prologue)
(-> Use Strict Directive)

In such a case, 10.2.1 tells us that the code within the *FunctionBody* is
strict code, but the GeneratorBody is not *within* the FunctionBody, so that
suggests it isn't strict code (unless, of course, it inherits strictness from
above).

You could get around this objection by changing the condition to
... or if _the_code_within_ its GeneratorBody is strict code, ...
because all of the source text of the GeneratorBody is within the FunctionBody,
even though the GeneratorBody itself isn't. However, I don't like this solution, because I don't like that strictness is supposedly defined as a property of source text, when it would make more sense as a property of parse tree nodes. So I'd prefer a solution in which the presence of the Use Strict Directive makes the whole GeneratorDeclaration strict, not just the FunctionBody. (E.g., see Bug 4146.) Then conditions like this don't have to reach down to the FunctionBody to determine if *it* is strict.

----------
{4}
14.2.16 / group 1 says:
ArrowFunction : ArrowParameters => ConciseBody
If the code of this ArrowFunction is contained in strict mode code
or if any of the conditions in 10.2.1 apply, ...
This isn't quite of the form outlined at the top, but I'm puzzled as to why it isn't. Of the various conditions in 10.2.1 that might apply, it seems there's only one (a FunctionBody that begins with "use strict") that's pertinent to this sentence, so why be vague?

(There are other conditions in 10.2.1 that might apply, e.g. the ArrowFunction might be in a module, but in that case, it would be true that "the code of this ArrowFunction is contained in strict mode code", and so there'd be no need to check the second term of the condition.)

--------------------------------------------------------------------------------

14.1.13 / group 1 / step 1:
FunctionStatementList : StatementList_opt
If this FunctionStatementList is contained in strict code
or if StatementList is strict code, ...

14.1.20 / group 1 / step 1:
FunctionDeclaration : function ... ( FormalParameters ) { FunctionBody }
If the FunctionDeclaration is contained in strict code
or if its FunctionBody is strict code, ...

14.1.20 / group 2:
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
If the FunctionDeclaration is contained in strict code
or if its FunctionBody is strict code, ...

14.1.21 / group 3:
FunctionExpression : function ( FormalParameters ) { FunctionBody }
If the FunctionExpression is contained in strict code
or if its FunctionBody is strict code, ...

14.1.21 / group 4:
FunctionExpression : function ... ( FormalParameters ) { FunctionBody }
If the FunctionExpression is contained in strict code
or if its FunctionBody is strict code, ...

14.2.16 / group 1:
ArrowFunction : ArrowParameters => ConciseBody
If the code of this ArrowFunction is contained in strict mode code
or if any of the conditions in 10.2.1 apply, ...

14.4.12 / group 1:
GeneratorDeclaration : function * .. ( FormalParameters ) { GeneratorBody }
If the GeneratorDeclaration is contained in strict code
or if its GeneratorBody is strict code, ...

14.4.12 / group 2:
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
If the GeneratorDeclaration is contained in strict code
or if its GeneratorBody is strict code, ...

15.1.2 / group 1:
ScriptBody : StatementList
If this ScriptBody is contained in strict code
or if StatementList is strict code, ...


fixed in rev36 editor's draft

some of this was fragments of incomplete work to provide a more formal definition of strict mode.

For now, I've normalized all of these uses to follow the pattern of:

If the function code for this GeneratorExpression is strict mode code, let strict be true. Otherwise let strict be false.

that along with the cleanup in 10.2 should be sufficient for now.

Also eliminated at the IsStrict abstract operations except for the one for Script


in rev36