"use strict" after a template string in a Function should not be treated as a "use strict" directive

RESOLVED DUPLICATE of bug 1024748

Status

()

RESOLVED DUPLICATE of bug 1024748
4 years ago
4 years ago

People

(Reporter: gupta.rajagopal, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

4 years ago
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0 (Beta/Release)
Build ID: 20140610163407
(Reporter)

Updated

4 years ago
OS: Mac OS X → All
Hardware: x86 → All
(Reporter)

Comment 1

4 years ago
Created attachment 8440813 [details] [diff] [review]
Patch and test case for proper functioning of directives with template strings
Attachment #8440813 - Flags: review?(jorendorff)
Comment on attachment 8440813 [details] [diff] [review]
Patch and test case for proper functioning of directives with template strings

Review of attachment 8440813 [details] [diff] [review]:
-----------------------------------------------------------------

Nice. r=me with these comments fixed.

::: js/src/frontend/FullParseHandler.h
@@ +539,5 @@
>      JSAtom *isStringExprStatement(ParseNode *pn, TokenPos *pos) {
> +
> +#ifdef JS_HAS_TEMPLATE_STRINGS
> +    if (pn->getKind() == PNK_TEMPLATE_STRING)
> +        return nullptr;

Please fix the indentation --- the last two lines here should be four spaces further to the right.

::: js/src/tests/ecma_6/TemplateStrings/noSubstTests.js
@@ +135,5 @@
>  assertThrowsInstanceOf(() => JSON.parse('[1, `false`]'), SyntaxError);
>  
>  syntaxError('({get `name`() { return 10; }});');
> +
> +assertEq(5, eval('Function("`use strict`; return 05;")()'));

Wrapping this in eval() isn't necessary.

Also, please remember to put the expression that's being tested first, and the expected value second:

    assertEq(Function("`use strict`; return 05;")(), 5);

Otherwise, if this assertion ever fails in the future, the error message will be confusing.

@@ +136,5 @@
>  
>  syntaxError('({get `name`() { return 10; }});');
> +
> +assertEq(5, eval('Function("`use strict`; return 05;")()'));
> +assertEq(5, eval('Function("`ignored string`; \\"use strict\\";return 05;")()'));

Same two comments here.
Attachment #8440813 - Flags: review?(jorendorff) → review+
(Reporter)

Updated

4 years ago
Status: UNCONFIRMED → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1024748
You need to log in before you can comment on or make changes to this bug.