mirror of https://github.com/tc39/test262.git
Add tests for Annex B.3.3/B.3.4
These tests ensure that the annex B extensions for function declarations are *not* observed in strict mode code.
This commit is contained in:
parent
613d33adbb
commit
4766365dc6
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.2
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
Block statement in eval code containing a function declaration
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
eval('{ function f() {} }');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.2
|
||||||
|
info: >
|
||||||
|
Block statement in eval code containing a function declaration
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
eval('"use strict";{ function f() {} }');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.3
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
Function declaration in the `case` clause of a `switch` statement in eval
|
||||||
|
code
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
eval('\
|
||||||
|
switch (1) {\
|
||||||
|
case 1:\
|
||||||
|
function f() { }\
|
||||||
|
}\
|
||||||
|
');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.3
|
||||||
|
info: >
|
||||||
|
Function declaration in the `case` clause of a `switch` statement in eval
|
||||||
|
code
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
eval('\
|
||||||
|
"use strict";\
|
||||||
|
switch (1) {\
|
||||||
|
case 1:\
|
||||||
|
function f() { }\
|
||||||
|
}\
|
||||||
|
');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.3
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
Function declaration in the `default` clause of a `switch` statement in
|
||||||
|
eval code
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
eval('\
|
||||||
|
switch (1) {\
|
||||||
|
default:\
|
||||||
|
function f() { }\
|
||||||
|
}\
|
||||||
|
');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.3
|
||||||
|
info: >
|
||||||
|
Function declaration in the `default` clause of a `switch` statement in
|
||||||
|
eval code
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
eval('\
|
||||||
|
"use strict";\
|
||||||
|
switch (1) {\
|
||||||
|
default:\
|
||||||
|
function f() { }\
|
||||||
|
}\
|
||||||
|
');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.2
|
||||||
|
info: >
|
||||||
|
Block statement in eval code containing a function declaration
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
(0,eval)('"use strict";{ function f() {} }');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.3
|
||||||
|
info: >
|
||||||
|
Function declaration in the `case` clause of a `switch` statement in eval
|
||||||
|
code
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
(0,eval)('\
|
||||||
|
"use strict";\
|
||||||
|
switch (1) {\
|
||||||
|
case 1:\
|
||||||
|
function f() { }\
|
||||||
|
}\
|
||||||
|
');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.3
|
||||||
|
info: >
|
||||||
|
Function declaration in the `default` clause of a `switch` statement in
|
||||||
|
eval code
|
||||||
|
|
||||||
|
B.3.3.3 Changes to EvalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err;
|
||||||
|
|
||||||
|
(0,eval)('\
|
||||||
|
"use strict";\
|
||||||
|
switch (1) {\
|
||||||
|
default:\
|
||||||
|
function f() { }\
|
||||||
|
}\
|
||||||
|
');
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(err.constructor, ReferenceError);
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.1
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
Block statement in function code containing a function declaration
|
||||||
|
|
||||||
|
B.3.3.1 Changes to FunctionDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err1, err2;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err1 = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
function f() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err2 = exception;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
|
assert.sameValue(err1.constructor, ReferenceError);
|
||||||
|
assert.sameValue(err2.constructor, ReferenceError);
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.1
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
Function declaration in the `case` clause of a `switch` statement in
|
||||||
|
function code
|
||||||
|
|
||||||
|
B.3.3.1 Changes to FunctionDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err1, err2;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err1 = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (1) {
|
||||||
|
case 1:
|
||||||
|
function f() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err2 = exception;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
|
assert.sameValue(err1.constructor, ReferenceError);
|
||||||
|
assert.sameValue(err2.constructor, ReferenceError);
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode
|
||||||
|
es6id: B.3.3.1
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
Function declaration in the `default` clause of a `switch` statement in
|
||||||
|
function code
|
||||||
|
|
||||||
|
B.3.3.1 Changes to FunctionDeclarationInstantiation
|
||||||
|
|
||||||
|
1. If strict is false, then
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var err1, err2;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err1 = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (1) {
|
||||||
|
default:
|
||||||
|
function f() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
f;
|
||||||
|
} catch (exception) {
|
||||||
|
err2 = exception;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
|
assert.sameValue(err1.constructor, ReferenceError);
|
||||||
|
assert.sameValue(err2.constructor, ReferenceError);
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode (Block statement in the global scope containing a function declaration)
|
||||||
|
es6id: B.3.3.2
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
B.3.3.2 Changes to GlobalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. 1. Let strict be IsStrict of script
|
||||||
|
2. If strict is *false*, then
|
||||||
|
[...]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
f;
|
||||||
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
function f() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
f;
|
||||||
|
});
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode (Function declaration in the `case` clause of a `switch` statement in the global scope)
|
||||||
|
es6id: B.3.3.2
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
B.3.3.2 Changes to GlobalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. 1. Let strict be IsStrict of script
|
||||||
|
2. If strict is *false*, then
|
||||||
|
[...]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
f;
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (1) {
|
||||||
|
case 1:
|
||||||
|
function f() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
f;
|
||||||
|
});
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode (Funtion declaration in the `default` clause of a `switch` statement in the global scope)
|
||||||
|
es6id: B.3.3.2
|
||||||
|
flags: [onlyStrict]
|
||||||
|
info: >
|
||||||
|
B.3.3.2 Changes to GlobalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. 1. Let strict be IsStrict of script
|
||||||
|
2. If strict is *false*, then
|
||||||
|
[...]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
f;
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (1) {
|
||||||
|
default:
|
||||||
|
function f() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
f;
|
||||||
|
});
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode (IfStatement with a declaration in both statement positions in the global scope)
|
||||||
|
es6id: B.3.4
|
||||||
|
flags: [onlyStrict]
|
||||||
|
negative: SyntaxError
|
||||||
|
info: >
|
||||||
|
The following rules for IfStatement augment those in 13.6:
|
||||||
|
|
||||||
|
IfStatement[Yield, Return]:
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
|
||||||
|
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
|
||||||
|
|
||||||
|
The above rules are only applied when parsing code that is not strict mode code.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
if (true) function f() { } else function _f() {}
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode (IfStatement with a declaration in the first statement position in the global scope)
|
||||||
|
es6id: B.3.4
|
||||||
|
flags: [onlyStrict]
|
||||||
|
negative: SyntaxError
|
||||||
|
info: >
|
||||||
|
The following rules for IfStatement augment those in 13.6:
|
||||||
|
|
||||||
|
IfStatement[Yield, Return]:
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
|
||||||
|
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
|
||||||
|
|
||||||
|
The above rules are only applied when parsing code that is not strict mode code.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
if (true) function f() { } else ;
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode (IfStatement without an else clause in the global scope)
|
||||||
|
es6id: B.3.4
|
||||||
|
flags: [onlyStrict]
|
||||||
|
negative: SyntaxError
|
||||||
|
info: >
|
||||||
|
The following rules for IfStatement augment those in 13.6:
|
||||||
|
|
||||||
|
IfStatement[Yield, Return]:
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
|
||||||
|
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
|
||||||
|
|
||||||
|
The above rules are only applied when parsing code that is not strict mode code.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
if (true) function f() { }
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: AnnexB extension not honored in strict mode (IfStatement with a declaration in the second statement position in the global scope)
|
||||||
|
es6id: B.3.4
|
||||||
|
flags: [onlyStrict]
|
||||||
|
negative: SyntaxError
|
||||||
|
info: >
|
||||||
|
The following rules for IfStatement augment those in 13.6:
|
||||||
|
|
||||||
|
IfStatement[Yield, Return]:
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
|
||||||
|
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
|
||||||
|
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
|
||||||
|
|
||||||
|
B.3.3.2 Changes to GlobalDeclarationInstantiation
|
||||||
|
|
||||||
|
1. 1. Let strict be IsStrict of script
|
||||||
|
2. If strict is *false*, then
|
||||||
|
[...]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
if (false) ; else function f() { }
|
Loading…
Reference in New Issue