mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Import tests from Google V8 (Block Scoping)
These tests are derived from the following files within the Google V8 project: test/mjsunit/harmony/block-conflicts.js test/mjsunit/harmony/block-for.js test/mjsunit/harmony/block-leave.js test/mjsunit/harmony/block-let-declaration.js test/mjsunit/harmony/block-let-semantics.js test/mjsunit/harmony/block-scoping.js
This commit is contained in:
parent
2eca2c71e8
commit
3f9587a8ee
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
finally block let declaration only shadows outer parameter value 1
|
||||||
|
---*/
|
||||||
|
try {
|
||||||
|
(function(x) {
|
||||||
|
try {
|
||||||
|
let x = 'inner';
|
||||||
|
throw 0;
|
||||||
|
} finally {
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
}
|
||||||
|
})('outer');
|
||||||
|
} catch (e) {}
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
finally block let declaration only shadows outer parameter value 2
|
||||||
|
---*/
|
||||||
|
(function(x) {
|
||||||
|
try {
|
||||||
|
let x = 'middle';
|
||||||
|
{
|
||||||
|
let x = 'inner';
|
||||||
|
throw 0;
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
}
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for loop block let declaration only shadows outer parameter value 1
|
||||||
|
---*/
|
||||||
|
(function(x) {
|
||||||
|
for (var i = 0; i < 10; ++i) {
|
||||||
|
let x = 'inner' + i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for loop block let declaration only shadows outer parameter value 2
|
||||||
|
---*/
|
||||||
|
(function(x) {
|
||||||
|
label: for (var i = 0; i < 10; ++i) {
|
||||||
|
let x = 'middle' + i;
|
||||||
|
for (var j = 0; j < 10; ++j) {
|
||||||
|
let x = 'inner' + j;
|
||||||
|
continue label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
nested block let declaration only shadows outer parameter value 1
|
||||||
|
---*/
|
||||||
|
(function(x) {
|
||||||
|
label: {
|
||||||
|
let x = 'inner';
|
||||||
|
break label;
|
||||||
|
}
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
nested block let declaration only shadows outer parameter value 2
|
||||||
|
---*/
|
||||||
|
(function(x) {
|
||||||
|
label: {
|
||||||
|
let x = 'middle';
|
||||||
|
{
|
||||||
|
let x = 'inner';
|
||||||
|
break label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
outermost binding updated in catch block; nested block let declaration unseen outside of block
|
||||||
|
---*/
|
||||||
|
var caught = false;
|
||||||
|
try {
|
||||||
|
{
|
||||||
|
let xx = 18;
|
||||||
|
throw 25;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
caught = true;
|
||||||
|
assert.sameValue(e, 25);
|
||||||
|
(function () {
|
||||||
|
try {
|
||||||
|
// NOTE: This checks that the block scope containing xx has been
|
||||||
|
// removed from the context chain.
|
||||||
|
assert.sameValue(xx, undefined);
|
||||||
|
eval('xx');
|
||||||
|
assert(false); // should not reach here
|
||||||
|
} catch (e2) {
|
||||||
|
assert(e2 instanceof ReferenceError);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
assert(caught);
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
try block let declaration only shadows outer parameter value 1
|
||||||
|
---*/
|
||||||
|
(function(x) {
|
||||||
|
try {
|
||||||
|
let x = 'inner';
|
||||||
|
throw 0;
|
||||||
|
} catch (e) {
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
}
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
try block let declaration only shadows outer parameter value 2
|
||||||
|
---*/
|
||||||
|
(function(x) {
|
||||||
|
try {
|
||||||
|
let x = 'middle';
|
||||||
|
{
|
||||||
|
let x = 'inner';
|
||||||
|
throw 0;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
}
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
verify context in finally block 1
|
||||||
|
---*/
|
||||||
|
function f() {}
|
||||||
|
|
||||||
|
(function(x) {
|
||||||
|
try {
|
||||||
|
let x = 'inner';
|
||||||
|
throw 0;
|
||||||
|
} catch(e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
f();
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
}
|
||||||
|
})('outer');
|
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
verify context in for loop block 2
|
||||||
|
---*/
|
||||||
|
function f() {}
|
||||||
|
|
||||||
|
(function(x) {
|
||||||
|
for (var i = 0; i < 10; ++i) {
|
||||||
|
let x = 'inner';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
verify context in labelled block 1
|
||||||
|
---*/
|
||||||
|
function f() {}
|
||||||
|
|
||||||
|
(function(x) {
|
||||||
|
label: {
|
||||||
|
let x = 'inner';
|
||||||
|
break label;
|
||||||
|
}
|
||||||
|
f(); // The context could be restored from the stack after the call.
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
})('outer');
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
verify context in try block 1
|
||||||
|
---*/
|
||||||
|
function f() {}
|
||||||
|
|
||||||
|
(function(x) {
|
||||||
|
try {
|
||||||
|
let x = 'inner';
|
||||||
|
throw 0;
|
||||||
|
} catch (e) {
|
||||||
|
f();
|
||||||
|
assert.sameValue(x, 'outer');
|
||||||
|
}
|
||||||
|
})('outer');
|
||||||
|
|
17
test/language/block-scope/leave/x-after-break-to-label.js
Normal file
17
test/language/block-scope/leave/x-after-break-to-label.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
x after break to label
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
let x = 2;
|
||||||
|
L: {
|
||||||
|
let x = 3;
|
||||||
|
assert.sameValue(x, 3);
|
||||||
|
break L;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
assert.sameValue(x, 2);
|
||||||
|
}
|
18
test/language/block-scope/leave/x-before-continue.js
Normal file
18
test/language/block-scope/leave/x-before-continue.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
x before continue
|
||||||
|
---*/
|
||||||
|
do {
|
||||||
|
let x = 4;
|
||||||
|
assert.sameValue(x, 4);
|
||||||
|
{
|
||||||
|
let x = 5;
|
||||||
|
assert.sameValue(x, 5);
|
||||||
|
continue;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
} while (false);
|
||||||
|
|
16
test/language/block-scope/return-from/block-const.js
Normal file
16
test/language/block-scope/return-from/block-const.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
return from block
|
||||||
|
---*/
|
||||||
|
function fn() {
|
||||||
|
const u = 3;
|
||||||
|
{
|
||||||
|
const v = 6;
|
||||||
|
return u + v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.sameValue(fn(), 9);
|
||||||
|
|
16
test/language/block-scope/return-from/block-let.js
Normal file
16
test/language/block-scope/return-from/block-let.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
return from block
|
||||||
|
---*/
|
||||||
|
function fn() {
|
||||||
|
let x = 3;
|
||||||
|
{
|
||||||
|
let y = 6;
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.sameValue(fn(), 9);
|
||||||
|
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: block local closure [[Get]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
function f() { return x + 1; }
|
||||||
|
f();
|
||||||
|
const x = 1;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: block local use before initialization in declaration statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
const x = x + 1;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: block local use before initialization in prior statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
x; const x = 1;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: function local closure [[Get]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
(function() {
|
||||||
|
function f() { return x + 1; }
|
||||||
|
f();
|
||||||
|
const x = 1;
|
||||||
|
}());
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: function local use before initialization in declaration statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
(function() {
|
||||||
|
const x = x + 1;
|
||||||
|
}());
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: function local use before initialization in prior statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
(function() {
|
||||||
|
x; const x = 1;
|
||||||
|
}());
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: global closure [[Get]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
function f() { return x + 1; }
|
||||||
|
f();
|
||||||
|
const x = 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: global use before initialization in declaration statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
const x = x + 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: global use before initialization in prior statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
x; const x = 1;
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: block local closure [[Get]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
function f() { return x + 1; }
|
||||||
|
f();
|
||||||
|
let x;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: block local closure [[Set]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
function f() { x = 1; }
|
||||||
|
f();
|
||||||
|
let x;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: block local use before initialization in declaration statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
let x = x + 1;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: block local use before initialization in prior statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
x; let x;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: function local closure [[Get]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
(function() {
|
||||||
|
function f() { return x + 1; }
|
||||||
|
f();
|
||||||
|
let x;
|
||||||
|
}());
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: function local closure [[Set]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
(function() {
|
||||||
|
function f() { x = 1; }
|
||||||
|
f();
|
||||||
|
let x;
|
||||||
|
}());
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: function local use before initialization in declaration statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
(function() {
|
||||||
|
let x = x + 1;
|
||||||
|
}());
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: function local use before initialization in prior statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
(function() {
|
||||||
|
x; let x;
|
||||||
|
}());
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: global closure [[Get]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
function f() { return x + 1; }
|
||||||
|
f();
|
||||||
|
let x;
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: global closure [[Set]] before initialization.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
function f() { x = 1; }
|
||||||
|
f();
|
||||||
|
let x;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: global use before initialization in declaration statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
let x = x + 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: global use before initialization in prior statement.
|
||||||
|
(TDZ, Temporal Dead Zone)
|
||||||
|
negative: ReferenceError
|
||||||
|
---*/
|
||||||
|
x; let x;
|
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
catch parameter shadowing catch parameter
|
||||||
|
---*/
|
||||||
|
function fn() {
|
||||||
|
var c = 1;
|
||||||
|
try {
|
||||||
|
throw 'stuff3';
|
||||||
|
} catch (c) {
|
||||||
|
try {
|
||||||
|
throw 'stuff4';
|
||||||
|
} catch(c) {
|
||||||
|
assert.sameValue(c,'stuff4');
|
||||||
|
// catch parameter shadowing catch parameter
|
||||||
|
c = 3;
|
||||||
|
assert.sameValue(c, 3);
|
||||||
|
}
|
||||||
|
assert.sameValue(c, 'stuff3');
|
||||||
|
}
|
||||||
|
assert.sameValue(c, 1);
|
||||||
|
}
|
||||||
|
fn(1);
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
catch parameter shadowing function parameter name
|
||||||
|
---*/
|
||||||
|
function fn(a) {
|
||||||
|
try {
|
||||||
|
throw 'stuff1';
|
||||||
|
} catch (a) {
|
||||||
|
assert.sameValue(a, 'stuff1');
|
||||||
|
// catch parameter shadowing function parameter name
|
||||||
|
a = 2;
|
||||||
|
assert.sameValue(a, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn(1);
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
catch parameter shadowing let declaration
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
let a = 3;
|
||||||
|
try {
|
||||||
|
throw 'stuff2';
|
||||||
|
} catch (a) {
|
||||||
|
assert.sameValue(a, 'stuff2');
|
||||||
|
// catch parameter shadowing let declaration
|
||||||
|
a = 4;
|
||||||
|
assert.sameValue(a, 4);
|
||||||
|
}
|
||||||
|
assert.sameValue(a, 3);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
catch parameter shadowing var variable
|
||||||
|
---*/
|
||||||
|
function fn() {
|
||||||
|
var a = 1;
|
||||||
|
try {
|
||||||
|
throw 'stuff3';
|
||||||
|
} catch (a) {
|
||||||
|
// catch parameter shadowing var variable
|
||||||
|
assert.sameValue(a, 'stuff3');
|
||||||
|
}
|
||||||
|
assert.sameValue(a, 1);
|
||||||
|
}
|
||||||
|
fn();
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declaration shadowing catch parameter
|
||||||
|
---*/
|
||||||
|
function fn() {
|
||||||
|
var a = 1;
|
||||||
|
try {
|
||||||
|
throw 'stuff3';
|
||||||
|
} catch (a) {
|
||||||
|
{
|
||||||
|
// const declaration shadowing catch parameter
|
||||||
|
const a = 3;
|
||||||
|
assert.sameValue(a, 3);
|
||||||
|
}
|
||||||
|
assert.sameValue(a, 'stuff3');
|
||||||
|
}
|
||||||
|
assert.sameValue(a, 1);
|
||||||
|
}
|
||||||
|
fn();
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations shadowing parameter name, let, const and var variables
|
||||||
|
---*/
|
||||||
|
function fn(a) {
|
||||||
|
let b = 1;
|
||||||
|
var c = 1;
|
||||||
|
const d = 1;
|
||||||
|
{
|
||||||
|
const a = 2;
|
||||||
|
const b = 2;
|
||||||
|
const c = 2;
|
||||||
|
const d = 2;
|
||||||
|
assert.sameValue(a, 2);
|
||||||
|
assert.sameValue(b, 2);
|
||||||
|
assert.sameValue(c, 2);
|
||||||
|
assert.sameValue(d, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(a, 1);
|
||||||
|
assert.sameValue(b, 1);
|
||||||
|
assert.sameValue(c, 1);
|
||||||
|
assert.sameValue(d, 1);
|
||||||
|
}
|
||||||
|
fn(1);
|
||||||
|
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
dynamic lookup from closure
|
||||||
|
---*/
|
||||||
|
function fn(one) {
|
||||||
|
var x = one + 1;
|
||||||
|
let y = one + 2;
|
||||||
|
const u = one + 4;
|
||||||
|
{
|
||||||
|
let z = one + 3;
|
||||||
|
const v = one + 5;
|
||||||
|
function f() {
|
||||||
|
assert.sameValue(one, 1);
|
||||||
|
assert.sameValue(x, 2);
|
||||||
|
assert.sameValue(y, 3);
|
||||||
|
assert.sameValue(z, 4);
|
||||||
|
assert.sameValue(u, 5);
|
||||||
|
assert.sameValue(v, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn(1);
|
||||||
|
|
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
dynamic lookup in and through block contexts
|
||||||
|
---*/
|
||||||
|
function fn(one) {
|
||||||
|
var x = one + 1;
|
||||||
|
let y = one + 2;
|
||||||
|
const u = one + 4;
|
||||||
|
{
|
||||||
|
let z = one + 3;
|
||||||
|
const v = one + 5;
|
||||||
|
assert.sameValue(one, 1);
|
||||||
|
assert.sameValue(x, 2);
|
||||||
|
assert.sameValue(y, 3);
|
||||||
|
assert.sameValue(z, 4);
|
||||||
|
assert.sameValue(u, 5);
|
||||||
|
assert.sameValue(v, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn(1);
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
hoisting var declarations out of blocks
|
||||||
|
---*/
|
||||||
|
function fn() {
|
||||||
|
{
|
||||||
|
var x = 1;
|
||||||
|
var y;
|
||||||
|
}
|
||||||
|
assert.sameValue(x, 1);
|
||||||
|
assert.sameValue(y, undefined);
|
||||||
|
}
|
||||||
|
fn();
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let declaration shadowing catch parameter
|
||||||
|
---*/
|
||||||
|
try {
|
||||||
|
throw 'stuff1';
|
||||||
|
} catch (a) {
|
||||||
|
{
|
||||||
|
// let declaration shadowing catch parameter
|
||||||
|
let a = 3;
|
||||||
|
assert.sameValue(a, 3);
|
||||||
|
}
|
||||||
|
assert.sameValue(a, 'stuff1');
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let declarations shadowing parameter name, let, const and var
|
||||||
|
---*/
|
||||||
|
function fn(a) {
|
||||||
|
let b = 1;
|
||||||
|
var c = 1;
|
||||||
|
const d = 1;
|
||||||
|
{
|
||||||
|
let a = 2;
|
||||||
|
let b = 2;
|
||||||
|
let c = 2;
|
||||||
|
let d = 2;
|
||||||
|
assert.sameValue(a, 2);
|
||||||
|
assert.sameValue(b, 2);
|
||||||
|
assert.sameValue(c, 2);
|
||||||
|
assert.sameValue(d, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn(1);
|
||||||
|
|
28
test/language/block-scope/shadowing/lookup-from-closure.js
Normal file
28
test/language/block-scope/shadowing/lookup-from-closure.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
lookup from closure
|
||||||
|
---*/
|
||||||
|
function f5(one) {
|
||||||
|
var x = one + 1;
|
||||||
|
let y = one + 2;
|
||||||
|
const u = one + 4;
|
||||||
|
{
|
||||||
|
let z = one + 3;
|
||||||
|
const v = one + 5;
|
||||||
|
function f() {
|
||||||
|
assert.sameValue(one, 1);
|
||||||
|
assert.sameValue(x, 2);
|
||||||
|
assert.sameValue(y, 3);
|
||||||
|
assert.sameValue(z, 4);
|
||||||
|
assert.sameValue(u, 5);
|
||||||
|
assert.sameValue(v, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f5(1);
|
||||||
|
|
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
lookup in and through block contexts
|
||||||
|
---*/
|
||||||
|
function fn(one) {
|
||||||
|
var x = one + 1;
|
||||||
|
let y = one + 2;
|
||||||
|
const u = one + 4;
|
||||||
|
{
|
||||||
|
let z = one + 3;
|
||||||
|
const v = one + 5;
|
||||||
|
assert.sameValue(one, 1);
|
||||||
|
assert.sameValue(x, 2);
|
||||||
|
assert.sameValue(y, 3);
|
||||||
|
assert.sameValue(z, 4);
|
||||||
|
assert.sameValue(u, 5);
|
||||||
|
assert.sameValue(v, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn(1);
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
parameter name shadowing catch parameter
|
||||||
|
---*/
|
||||||
|
function fn() {
|
||||||
|
var c = 1;
|
||||||
|
try {
|
||||||
|
throw 'stuff3';
|
||||||
|
} catch (c) {
|
||||||
|
(function(c) {
|
||||||
|
// parameter name shadowing catch parameter
|
||||||
|
c = 3;
|
||||||
|
assert.sameValue(c, 3);
|
||||||
|
})();
|
||||||
|
assert.sameValue(c, 'stuff3');
|
||||||
|
}
|
||||||
|
assert.sameValue(c, 1);
|
||||||
|
}
|
||||||
|
fn();
|
||||||
|
|
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
parameter name shadowing parameter name, let, const and var
|
||||||
|
---*/
|
||||||
|
function fn(a) {
|
||||||
|
let b = 1;
|
||||||
|
var c = 1;
|
||||||
|
const d = 1;
|
||||||
|
|
||||||
|
(function(a, b, c, d) {
|
||||||
|
a = 2;
|
||||||
|
b = 2;
|
||||||
|
c = 2;
|
||||||
|
d = 2;
|
||||||
|
|
||||||
|
assert.sameValue(a, 2);
|
||||||
|
assert.sameValue(b, 2);
|
||||||
|
assert.sameValue(c, 2);
|
||||||
|
assert.sameValue(d, 2);
|
||||||
|
})(1, 1);
|
||||||
|
|
||||||
|
assert.sameValue(a, 1);
|
||||||
|
assert.sameValue(b, 1);
|
||||||
|
assert.sameValue(c, 1);
|
||||||
|
assert.sameValue(d, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn(1);
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations mixed: with, without initialiser
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
const x = 1, y;
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations mixed: without, with initialiser
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
const x, y = 1;
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialiser
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
const x;
|
||||||
|
|
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
case Expression : StatementList
|
||||||
|
---*/
|
||||||
|
switch (true) { case true: const x = 1; }
|
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
default : StatementList
|
||||||
|
---*/
|
||||||
|
switch (true) { default: const x = 1; }
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
do Statement while ( Expression )
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
do const x = 1; while (false)
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
for ( ;;) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (;false;) const x = 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
if ( Expression ) Statement else Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
if (true) {} else const x = 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
if ( Expression ) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
if (true) const x = 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
label: Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
label: const x = 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations with initialisers in statement positions:
|
||||||
|
while ( Expression ) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
while (false) const x = 1;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
case Expression : StatementList
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
switch (true) { case true: const x; }
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
default : StatementList
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
switch (true) { default: const x; }
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
do Statement while ( Expression )
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
do const x; while (false)
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
for ( ;;) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (;false;) const x;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
if ( Expression ) Statement else Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
if (true) {} else const x;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
if ( Expression ) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
if (true) const x;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
label: Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
label: const x;
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const declarations without initialisers in statement positions:
|
||||||
|
while ( Expression ) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
while (false) const x;
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for-in to acquire properties from array
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
function props(x) {
|
||||||
|
var array = [];
|
||||||
|
for (let p in x) array.push(p);
|
||||||
|
return array.sort();
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(props([]).length, 0);
|
||||||
|
assert.sameValue(props([1]).length, 1);
|
||||||
|
assert.sameValue(props([1,2]).length, 2);
|
||||||
|
|
||||||
|
assert(compareArray(props([1]), ["0"]));
|
||||||
|
assert(compareArray(props([1,2]), ["0", "1"]));
|
||||||
|
assert(compareArray(props([1,2,3]), ["0", "1", "2"]));
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for-in to acquire properties from object
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
function props(x) {
|
||||||
|
var array = [];
|
||||||
|
for (let p in x) array.push(p);
|
||||||
|
return array.sort();
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(props({}).length, 0);
|
||||||
|
assert.sameValue(props({x:1}).length, 1);
|
||||||
|
assert.sameValue(props({x:1, y:2}).length, 2);
|
||||||
|
|
||||||
|
assert(compareArray(props({x:1}), ["x"]));
|
||||||
|
assert(compareArray(props({x:1, y:2}), ["x", "y"]));
|
||||||
|
assert(compareArray(props({x:1, y:2, zoom:3}), ["x", "y", "zoom"]));
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for declaration:
|
||||||
|
disallow initialization assignment
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (let x = 3 in {}) { }
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for declaration:
|
||||||
|
disallow multiple lexical bindings, with and without initializer
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (let x = 3, y in {}) { }
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for declaration:
|
||||||
|
disallow multiple lexical bindings, with initializer
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (let x = 3, y = 4 in {}) { }
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for declaration:
|
||||||
|
disallow multiple lexical bindings, without and with initializer
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (let x, y = 4 in {}) { }
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for declaration:
|
||||||
|
disallow multiple lexical bindings
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (let x, y in {}) { }
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
for declaration:
|
||||||
|
missing identifier, "let" disallowed as bound name
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
for (let in {}) { }
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
Mixed values in iteration
|
||||||
|
---*/
|
||||||
|
"use strict";
|
||||||
|
function fn(x) {
|
||||||
|
let a = [];
|
||||||
|
for (let p in x) {
|
||||||
|
a.push(function () { return p; });
|
||||||
|
}
|
||||||
|
let k = 0;
|
||||||
|
for (let q in x) {
|
||||||
|
assert.sameValue(q, a[k]());
|
||||||
|
++k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn({a : [0], b : 1, c : {v : 1}, get d() {}, set e(x) {}});
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2015 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
const: invalid assignment in next expression
|
||||||
|
negative: TypeError
|
||||||
|
---*/
|
||||||
|
|
||||||
|
for (const i = 0; i < 1; i++) { }
|
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
outer const binding unchanged by for-loop const binding
|
||||||
|
---*/
|
||||||
|
//
|
||||||
|
|
||||||
|
const x = "outer_x";
|
||||||
|
const y = "outer_y";
|
||||||
|
var i = 0;
|
||||||
|
|
||||||
|
for (const x = "inner_x"; i < 1; i++) {
|
||||||
|
const y = "inner_y";
|
||||||
|
|
||||||
|
assert.sameValue(x, "inner_x");
|
||||||
|
assert.sameValue(y, "inner_y");
|
||||||
|
}
|
||||||
|
assert.sameValue(x, "outer_x");
|
||||||
|
assert.sameValue(y, "outer_y");
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: closure inside for loop condition
|
||||||
|
---*/
|
||||||
|
let a = [];
|
||||||
|
for (let i = 0; a.push(function () { return i; }), i < 5; ++i) { }
|
||||||
|
for (let k = 0; k < 5; ++k) {
|
||||||
|
assert.sameValue(k, a[k]());
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: closure inside for loop initialization
|
||||||
|
---*/
|
||||||
|
let a = [];
|
||||||
|
for (let i = 0, f = function() { return i }; i < 5; ++i) {
|
||||||
|
a.push(f);
|
||||||
|
}
|
||||||
|
for (let k = 0; k < 5; ++k) {
|
||||||
|
assert.sameValue(0, a[k]());
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let: closure inside for loop next-expression
|
||||||
|
---*/
|
||||||
|
let a = [];
|
||||||
|
for (let i = 0; i < 5; a.push(function () { return i; }), ++i) { }
|
||||||
|
for (let k = 0; k < 5; ++k) {
|
||||||
|
assert.sameValue(k + 1, a[k]());
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
In a normal for statement the iteration variable is freshly allocated for each iteration. Multi let binding
|
||||||
|
---*/
|
||||||
|
let a = [], b = [];
|
||||||
|
for (let i = 0, j = 10; i < 5; ++i, ++j) {
|
||||||
|
a.push(function () { return i; });
|
||||||
|
b.push(function () { return j; });
|
||||||
|
}
|
||||||
|
for (let k = 0; k < 5; ++k) {
|
||||||
|
assert.sameValue(k, a[k]());
|
||||||
|
assert.sameValue(k + 10, b[k]());
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
In a normal for statement the iteration variable is freshly allocated for each iteration. Single let binding
|
||||||
|
---*/
|
||||||
|
let a = [];
|
||||||
|
for (let i = 0; i < 5; ++i) {
|
||||||
|
a.push(function () { return i; });
|
||||||
|
}
|
||||||
|
for (let j = 0; j < 5; ++j) {
|
||||||
|
assert.sameValue(j, a[j]());
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
outer let binding unchanged by for-loop let binding
|
||||||
|
---*/
|
||||||
|
//
|
||||||
|
|
||||||
|
let x = "outer_x";
|
||||||
|
let y = "outer_y";
|
||||||
|
|
||||||
|
for (let x = "inner_x", i = 0; i < 1; i++) {
|
||||||
|
let y = "inner_y";
|
||||||
|
|
||||||
|
assert.sameValue(x, "inner_x");
|
||||||
|
assert.sameValue(y, "inner_y");
|
||||||
|
}
|
||||||
|
assert.sameValue(x, "outer_x");
|
||||||
|
assert.sameValue(y, "outer_y");
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
case Expression : StatementList
|
||||||
|
---*/
|
||||||
|
switch (true) { case true: function g() {} }
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
default : StatementList
|
||||||
|
---*/
|
||||||
|
switch (true) { default: function g() {} }
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
do Statement while ( Expression )
|
||||||
|
negative: SyntaxError
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
do function g() {} while (false)
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
for ( ;;) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
for (;false;) function g() {}
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
if ( Expression ) Statement else Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
if (true) {} else function g() {}
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
if ( Expression ) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
if (true) function g() {}
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
label: Statement
|
||||||
|
---*/
|
||||||
|
label: function g() {}
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
function declarations in statement position in strict mode:
|
||||||
|
while ( Expression ) Statement
|
||||||
|
negative: SyntaxError
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
while (false) function g() {}
|
||||||
|
|
21
test/language/block-scope/syntax/global-and-block/const.js
Normal file
21
test/language/block-scope/syntax/global-and-block/const.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
global and block scope const
|
||||||
|
---*/
|
||||||
|
const z = 4;
|
||||||
|
|
||||||
|
// Block local
|
||||||
|
{
|
||||||
|
const z = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(z, 4);
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
const z = 1;
|
||||||
|
assert.sameValue(z, 1);
|
||||||
|
}
|
||||||
|
|
24
test/language/block-scope/syntax/global-and-block/let.js
Normal file
24
test/language/block-scope/syntax/global-and-block/let.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
global and block scope let
|
||||||
|
---*/
|
||||||
|
let x;
|
||||||
|
let y = 2;
|
||||||
|
|
||||||
|
// Block local
|
||||||
|
{
|
||||||
|
let y;
|
||||||
|
let x = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(x, undefined);
|
||||||
|
assert.sameValue(y, 2);
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
let y;
|
||||||
|
assert.sameValue(y, undefined);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Copyright 2011 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1
|
||||||
|
description: >
|
||||||
|
let declarations with initialisers in statement positions:
|
||||||
|
case Expression : StatementList
|
||||||
|
---*/
|
||||||
|
switch (true) { case true: let x = 1; }
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user