mirror of https://github.com/tc39/test262.git
Add equivalent tests for eval code
For each test that asserts the behavior of either "direct" or "indirect" eval (but not both), introduce an equivalent test for the opposite case.
This commit is contained in:
parent
364d6433e2
commit
2872537136
|
@ -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.
|
||||
/*---
|
||||
esid: sec-performeval
|
||||
es5id: 10.4.2.1-4-s
|
||||
description: >
|
||||
Non-stict mode direct eval code cannot instantiate functions in the
|
||||
variable environment of the caller
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var typeofInside;
|
||||
|
||||
(function() {
|
||||
eval('function fun() {}');
|
||||
typeofInside = typeof fun;
|
||||
}());
|
||||
|
||||
assert.sameValue(typeofInside, 'function');
|
||||
assert.sameValue(typeof fun, 'undefined');
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty, then return
|
||||
the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T1
|
||||
description: Block statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)("{}"), undefined);
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty,
|
||||
then return the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T6
|
||||
description: do-while statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)("do ; while(false)"), undefined);
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty,
|
||||
then return the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T3
|
||||
description: Empty statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)(";"), undefined);
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty,
|
||||
then return the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T8
|
||||
description: for statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)("for(false;false;false);"), undefined);
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty,
|
||||
then return the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T4
|
||||
description: If statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)("if (false) ;"), undefined);
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty,
|
||||
then return the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T5
|
||||
description: Switch statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)("switch(1){}"), undefined);
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty,
|
||||
then return the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T2
|
||||
description: Var statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)("var x = 1"), undefined);
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is empty,
|
||||
then return the value undefined
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.2_T7
|
||||
description: while statement
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)("while(false);"), undefined);
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is a value V,
|
||||
then return the value V
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.1_T2
|
||||
description: Expression statement. Eval return object value
|
||||
---*/
|
||||
|
||||
var x = {};
|
||||
var y;
|
||||
|
||||
assert.sameValue((0,eval)("y = x"), x, 'AssignmentExpression');
|
||||
|
||||
assert.sameValue((0,eval)("x"), x, 'IdentifierReference');
|
|
@ -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.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is normal and its completion value is a value V,
|
||||
then return the value V
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.1_T1
|
||||
description: Expression statement. Eval return primitive value
|
||||
---*/
|
||||
|
||||
var x;
|
||||
assert.sameValue((0,eval)("x = 1"), 1, 'AssignmentExpression');
|
||||
|
||||
assert.sameValue((0,eval)("1"), 1, 'NumericLiteral');
|
||||
|
||||
assert.sameValue((0,eval)("'1'"), '1', 'StringLiteral');
|
||||
|
||||
x = 1;
|
||||
assert.sameValue((0,eval)("++x"), 2, 'UpdateExpression');
|
|
@ -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: The `export` declaration may not appear within eval code
|
||||
esid: sec-scripts
|
||||
flags: [module]
|
||||
info: |
|
||||
Eval code is the source text supplied to the built-in eval function. More
|
||||
precisely, if the parameter to the built-in eval function is a String, it
|
||||
is treated as an ECMAScript Script. The eval code for a particular
|
||||
invocation of eval is the global code portion of that Script.
|
||||
|
||||
A.5 Scripts and Modules
|
||||
|
||||
Script:
|
||||
ScriptBodyopt
|
||||
|
||||
ScriptBody:
|
||||
StatementList
|
||||
---*/
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
(0,eval)('export default null;');
|
||||
});
|
|
@ -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: The `import` declaration may not appear within eval code
|
||||
esid: sec-scripts
|
||||
flags: [module]
|
||||
info: |
|
||||
Eval code is the source text supplied to the built-in eval function. More
|
||||
precisely, if the parameter to the built-in eval function is a String, it
|
||||
is treated as an ECMAScript Script. The eval code for a particular
|
||||
invocation of eval is the global code portion of that Script.
|
||||
|
||||
A.5 Scripts and Modules
|
||||
|
||||
Script:
|
||||
ScriptBodyopt
|
||||
|
||||
ScriptBody:
|
||||
StatementList
|
||||
---*/
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
(0,eval)('import v from "./import.js";');
|
||||
});
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-evaldeclarationinstantiation
|
||||
es6id: 18.2.1.2
|
||||
description: >
|
||||
Global functions are not created if conflicting function declarations were
|
||||
detected.
|
||||
info: |
|
||||
Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
|
||||
|
||||
...
|
||||
8. For each d in varDeclarations, in reverse list order do
|
||||
a. If d is neither a VariableDeclaration or a ForBinding, then
|
||||
i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration.
|
||||
ii. NOTE If there are multiple FunctionDeclarations for the same name,
|
||||
the last declaration is used.
|
||||
iii. Let fn be the sole element of the BoundNames of d.
|
||||
iv. If fn is not an element of declaredFunctionNames, then
|
||||
1. If varEnvRec is a global Environment Record, then
|
||||
a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn).
|
||||
b. ReturnIfAbrupt(fnDefinable).
|
||||
c. If fnDefinable is false, throw TypeError exception.
|
||||
...
|
||||
14. For each production f in functionsToInitialize, do
|
||||
a. Let fn be the sole element of the BoundNames of f.
|
||||
b. Let fo be the result of performing InstantiateFunctionObject for f with argument lexEnv.
|
||||
c. If varEnvRec is a global Environment Record, then
|
||||
i. Let status be varEnvRec.CreateGlobalFunctionBinding(fn, fo, true).
|
||||
ii. ReturnIfAbrupt(status).
|
||||
...
|
||||
---*/
|
||||
|
||||
try {
|
||||
(0,eval)("function shouldNotBeDefined1() {} function NaN() {} function shouldNotBeDefined2() {}");
|
||||
} catch (e) {
|
||||
// Ignore TypeError exception.
|
||||
}
|
||||
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined1"),
|
||||
undefined,
|
||||
"declaration preceeding"
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined2"),
|
||||
undefined,
|
||||
"declaration following"
|
||||
);
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-evaldeclarationinstantiation
|
||||
es6id: 18.2.1.2
|
||||
description: >
|
||||
Global variables are not created if conflicting function declarations were
|
||||
detected.
|
||||
info: |
|
||||
Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
|
||||
|
||||
...
|
||||
8. For each d in varDeclarations, in reverse list order do
|
||||
a. If d is neither a VariableDeclaration or a ForBinding, then
|
||||
i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration.
|
||||
ii. NOTE If there are multiple FunctionDeclarations for the same name, the last declaration is used.
|
||||
iii. Let fn be the sole element of the BoundNames of d.
|
||||
iv. If fn is not an element of declaredFunctionNames, then
|
||||
1. If varEnvRec is a global Environment Record, then
|
||||
a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn).
|
||||
b. ReturnIfAbrupt(fnDefinable).
|
||||
c. If fnDefinable is false, throw TypeError exception.
|
||||
...
|
||||
15. For each String vn in declaredVarNames, in list order do
|
||||
a. If varEnvRec is a global Environment Record, then
|
||||
i. Let status be varEnvRec.CreateGlobalVarBinding(vn, true).
|
||||
ii. ReturnIfAbrupt(status).
|
||||
...
|
||||
---*/
|
||||
|
||||
try {
|
||||
(0,eval)("var shouldNotBeDefined1; function NaN() {} var shouldNotBeDefined2;");
|
||||
} catch (e) {
|
||||
// Ignore TypeError exception.
|
||||
}
|
||||
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined1"),
|
||||
undefined,
|
||||
"declaration preceeding"
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined2"),
|
||||
undefined,
|
||||
"declaration following"
|
||||
);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-evaldeclarationinstantiation
|
||||
es6id: 18.2.1.2
|
||||
description: Throws a TypeError if a global function cannot be defined.
|
||||
info: |
|
||||
Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
|
||||
|
||||
...
|
||||
8. For each d in varDeclarations, in reverse list order do
|
||||
a. If d is neither a VariableDeclaration or a ForBinding, then
|
||||
i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration.
|
||||
ii. NOTE If there are multiple FunctionDeclarations for the same name,
|
||||
the last declaration is used.
|
||||
iii. Let fn be the sole element of the BoundNames of d.
|
||||
iv. If fn is not an element of declaredFunctionNames, then
|
||||
1. If varEnvRec is a global Environment Record, then
|
||||
a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn).
|
||||
b. ReturnIfAbrupt(fnDefinable).
|
||||
c. If fnDefinable is false, throw TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
(0,eval)("function NaN() {}");
|
||||
});
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-evaldeclarationinstantiation
|
||||
es6id: 18.2.1.2
|
||||
description: Throws a TypeError if a global generator function cannot be defined.
|
||||
info: |
|
||||
Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
|
||||
|
||||
...
|
||||
8. For each d in varDeclarations, in reverse list order do
|
||||
a. If d is neither a VariableDeclaration or a ForBinding, then
|
||||
i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration.
|
||||
ii. NOTE If there are multiple FunctionDeclarations for the same name,
|
||||
the last declaration is used.
|
||||
iii. Let fn be the sole element of the BoundNames of d.
|
||||
iv. If fn is not an element of declaredFunctionNames, then
|
||||
1. If varEnvRec is a global Environment Record, then
|
||||
a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn).
|
||||
b. ReturnIfAbrupt(fnDefinable).
|
||||
c. If fnDefinable is false, throw TypeError exception.
|
||||
...
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
(0,eval)("function* NaN() {}");
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-evaldeclarationinstantiation
|
||||
es6id: 18.2.1.2
|
||||
description: Throws a TypeError if a global variable cannot be defined.
|
||||
info: |
|
||||
Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
|
||||
|
||||
...
|
||||
10. For each d in varDeclarations, do
|
||||
a. If d is a VariableDeclaration or a ForBinding, then
|
||||
i. For each String vn in the BoundNames of d, do
|
||||
1. If vn is not an element of declaredFunctionNames, then
|
||||
a. If varEnvRec is a global Environment Record, then
|
||||
i. Let vnDefinable be varEnvRec.CanDeclareGlobalVar(vn).
|
||||
ii. ReturnIfAbrupt(vnDefinable).
|
||||
iii. If vnDefinable is false, throw TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var nonExtensible;
|
||||
try {
|
||||
Object.preventExtensions(this);
|
||||
nonExtensible = !Object.isExtensible(this);
|
||||
} catch (e) {
|
||||
nonExtensible = false;
|
||||
}
|
||||
|
||||
// Run test if global object is non-extensible.
|
||||
if (nonExtensible) {
|
||||
assert.throws(TypeError, function() {
|
||||
(0,eval)("var unlikelyVariableName;");
|
||||
});
|
||||
}
|
|
@ -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.
|
||||
/*---
|
||||
info: If x is not a string value, return x
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A1.1_T2
|
||||
description: Checking all objects
|
||||
---*/
|
||||
|
||||
var x = {};
|
||||
assert.sameValue((0,eval)(x), x, 'ordinary object');
|
||||
|
||||
x = new Number(1);
|
||||
assert.sameValue((0,eval)(x), x, 'Number object');
|
||||
|
||||
x = new Boolean(true);
|
||||
assert.sameValue((0,eval)(x), x, 'Boolean object');
|
||||
|
||||
x = new String("1+1");
|
||||
assert.sameValue((0,eval)(x), x, 'String object');
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: If x is not a string value, return x
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A1.1_T1
|
||||
description: Checking all primitives
|
||||
---*/
|
||||
|
||||
var x = 1;
|
||||
assert.sameValue((0,eval)(x), x, 'Reference');
|
||||
|
||||
assert.sameValue((0,eval)(1), 1, 'number');
|
||||
|
||||
assert.sameValue((0,eval)(true), true, 'boolean');
|
||||
|
||||
assert.sameValue((0,eval)(null), null, 'null');
|
||||
|
||||
assert.sameValue((0,eval)(undefined), undefined, 'undefined');
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: If the parse fails, throw a SyntaxError exception (but see also clause 16)
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A2_T1
|
||||
description: >
|
||||
Checking if execution of "(0,eval)("x = 1; x\u000A++"), catch SyntaxError"
|
||||
passes
|
||||
---*/
|
||||
|
||||
var x;
|
||||
assert.throws(SyntaxError, function() {
|
||||
(0,eval)("x = 1; x\u000A++");
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: If the parse fails, throw a SyntaxError exception (but see also clause 16)
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A2_T2
|
||||
description: Checking if execution of "(0,eval)("x = 1; x\u000A++")" fails
|
||||
negative: SyntaxError
|
||||
---*/
|
||||
|
||||
var x;
|
||||
(0,eval)("x = 1; x\u000A++");
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is not normal, then Result(3).type must be throw.
|
||||
Throw Result(3).value as an exception
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.3_T1
|
||||
description: Continue statement
|
||||
---*/
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
(0,eval)("continue;");
|
||||
});
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
for (var i = 0; i <= 1; i++) {
|
||||
(0,eval)("continue;");
|
||||
$ERROR("First iteration should not complete");
|
||||
}
|
||||
$ERROR("Iteration should not complete");
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is not normal, then Result(3).type must be throw.
|
||||
Throw Result(3).value as an exception
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.3_T2
|
||||
description: Break statement
|
||||
---*/
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
(0,eval)("break;");
|
||||
});
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
for (var i = 0; i <= 1; i++) {
|
||||
(0,eval)("break;");
|
||||
$ERROR("First iteration should not complete");
|
||||
}
|
||||
$ERROR("Iteration should not complete");
|
||||
});
|
|
@ -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.
|
||||
/*---
|
||||
info: >
|
||||
If Result(3).type is not normal, then Result(3).type must be throw.
|
||||
Throw Result(3).value as an exception
|
||||
esid: sec-performeval
|
||||
es5id: 15.1.2.1_A3.3_T3
|
||||
description: Return statement
|
||||
---*/
|
||||
|
||||
var value;
|
||||
|
||||
try {
|
||||
value = (0,eval)("return;");
|
||||
$ERROR('#1.1: return must throw SyntaxError. Actual: ' + value);
|
||||
} catch(e) {
|
||||
if ((e instanceof SyntaxError) !== true) {
|
||||
$ERROR('#1.2: return must throw SyntaxError. Actual: ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
(0,eval)("return;");
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Direct eval code has the same `this` binding as the calling context
|
||||
(non-strict function scope)
|
||||
esid: sec-performeval
|
||||
---*/
|
||||
|
||||
var thisValue;
|
||||
|
||||
(function() {
|
||||
thisValue = (0,eval)('this;');
|
||||
}());
|
||||
|
||||
assert.sameValue(thisValue, this);
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Direct eval code has the same `this` binding as the calling context (global
|
||||
scope)
|
||||
esid: sec-performeval
|
||||
---*/
|
||||
|
||||
assert.sameValue((0,eval)('this;'), this);
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-performeval
|
||||
es5id: 10.4.2-2-s
|
||||
description: >
|
||||
Non-stict mode indirect eval code cannot instantiate functions in the
|
||||
variable environment of the caller
|
||||
---*/
|
||||
|
||||
var typeofInside;
|
||||
|
||||
(function() {
|
||||
(0,eval)("function fun() {}");
|
||||
typeofInside = typeof fun;
|
||||
}());
|
||||
|
||||
assert.sameValue(typeofInside, "function");
|
||||
assert.sameValue(typeof fun, "function");
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-performeval
|
||||
es5id: 10.4.2.1-4-s
|
||||
description: >
|
||||
Strict Mode - Strict mode eval code cannot instantiate functions
|
||||
in the variable environment of the caller to eval.
|
||||
---*/
|
||||
|
||||
var typeofInside;
|
||||
|
||||
(function() {
|
||||
(0,eval)("'use strict'; function fun(){}");
|
||||
typeofInside = typeof fun;
|
||||
}());
|
||||
|
||||
assert.sameValue(typeofInside, "undefined");
|
||||
assert.sameValue(typeof fun, "undefined");
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-performeval
|
||||
es5id: 10.4.2-2-c-1
|
||||
description: Indirect eval code cannot instantiate variable in calling context
|
||||
---*/
|
||||
|
||||
(function() {
|
||||
var x = 0;
|
||||
(0,eval)("var x = 1;");
|
||||
assert.sameValue(x, 0, "x");
|
||||
}());
|
||||
|
||||
assert.sameValue(x, 1);
|
Loading…
Reference in New Issue