mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
8 years ago
committed by
GitHub
18 changed files with 338 additions and 6 deletions
@ -0,0 +1,66 @@ |
|||
/* |
|||
* new.target in eval code |
|||
*/ |
|||
|
|||
/*=== |
|||
direct eval in program code |
|||
SyntaxError |
|||
indirect eval in program code |
|||
SyntaxError |
|||
direct eval in function code |
|||
undefined |
|||
false |
|||
function |
|||
true |
|||
indirect eval in function code |
|||
SyntaxError |
|||
eval-in-eval in function code |
|||
undefined |
|||
false |
|||
function |
|||
true |
|||
===*/ |
|||
|
|||
var myEval = eval; // indirect eval call
|
|||
|
|||
// Not allowed in direct or indirect eval outside of a function.
|
|||
try { |
|||
print('direct eval in program code'); |
|||
eval('print(typeof new.target)'); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
|||
try { |
|||
print('indirect eval in program code'); |
|||
myEval('print(typeof new.target)'); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
|||
|
|||
// Allowed in direct eval inside a function call.
|
|||
try { |
|||
print('direct eval in function code'); |
|||
eval('(function test() { eval("print(typeof new.target); print(new.target === test);"); })()'); |
|||
eval('new (function test() { eval("print(typeof new.target); print(new.target === test);"); })'); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
|||
|
|||
// Not allowed in indirect eval inside a function call.
|
|||
try { |
|||
print('indirect eval in function code'); |
|||
eval('new (function test() { myEval("print(typeof new.target);"); })'); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
|||
|
|||
// This should be allowed (Firefox allows this) because GetNewTarget() just
|
|||
// looks up [[NewTarget]] from the lexical environment and nested direct
|
|||
// eval() calls just inherit the surrounding function's environment.
|
|||
try { |
|||
print('eval-in-eval in function code'); |
|||
eval('(function test() { eval("eval(\\"print(typeof new.target); print(new.target === test);\\");"); })()'); |
|||
eval('new (function test() { eval("eval(\\"print(typeof new.target); print(new.target === test);\\");"); })'); |
|||
} catch (e) { |
|||
print(e.stack); |
|||
} |
@ -0,0 +1,15 @@ |
|||
/*=== |
|||
undefined |
|||
function |
|||
===*/ |
|||
|
|||
function test() { |
|||
print(typeof new.target); |
|||
} |
|||
|
|||
try { |
|||
test(); |
|||
new test(); |
|||
} catch (e) { |
|||
print(e.stack || e); |
|||
} |
@ -0,0 +1,18 @@ |
|||
/*=== |
|||
start |
|||
ReferenceError |
|||
===*/ |
|||
|
|||
function test() { |
|||
new.target = 123; |
|||
} |
|||
|
|||
// Currently causes a runtime ReferenceError.
|
|||
// XXX: in Firefox the error is compile time.
|
|||
try { |
|||
print('start'); |
|||
test(); |
|||
print('done'); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
@ -0,0 +1,9 @@ |
|||
/*=== |
|||
SyntaxError |
|||
===*/ |
|||
|
|||
try { |
|||
eval('new (function test() { print(typeof new.foo); })'); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
@ -0,0 +1,17 @@ |
|||
/* |
|||
* new.target not allowed in program code; this fails without print() |
|||
* calls due to script SyntaxError. |
|||
*/ |
|||
|
|||
/*--- |
|||
{ |
|||
"intended_uncaught": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
===*/ |
|||
|
|||
print('start'); |
|||
print(typeof new.target); |
|||
print('done'); |
@ -0,0 +1,80 @@ |
|||
/* |
|||
* new.target |
|||
*/ |
|||
|
|||
/*=== |
|||
MyFunc called |
|||
undefined |
|||
false |
|||
false |
|||
MyFunc called |
|||
function |
|||
true |
|||
false |
|||
MyFunc called |
|||
undefined |
|||
false |
|||
false |
|||
MyFunc called |
|||
function |
|||
true |
|||
false |
|||
foo called |
|||
undefined |
|||
foo called |
|||
target-prop-value |
|||
outer function |
|||
inner undefined |
|||
===*/ |
|||
|
|||
var bound; |
|||
|
|||
function MyFunc() { |
|||
print('MyFunc called'); |
|||
print(typeof new.target); |
|||
print(new |
|||
. |
|||
target === MyFunc); |
|||
print(new /* comment */ . // another comment
|
|||
target === bound); |
|||
} |
|||
|
|||
function test() { |
|||
bound = MyFunc.bind(null, 123); |
|||
|
|||
MyFunc(); |
|||
new MyFunc(); |
|||
|
|||
bound(); |
|||
new bound(); |
|||
|
|||
function foo() { |
|||
print('foo called'); |
|||
if (new.target) { |
|||
print(new.target.target); |
|||
} else { |
|||
print('undefined'); |
|||
} |
|||
} |
|||
foo.target = 'target-prop-value'; |
|||
foo(); |
|||
new foo(); |
|||
|
|||
// Inner function doesn't see outer function new.target.
|
|||
|
|||
function outer() { |
|||
print('outer', typeof new.target); |
|||
|
|||
function inner() { |
|||
print('inner', typeof new.target); |
|||
} |
|||
inner(); |
|||
} |
|||
new outer(); |
|||
} |
|||
|
|||
try { |
|||
test(); |
|||
} catch (e) { |
|||
print(e.stack || e); |
|||
} |
@ -0,0 +1,18 @@ |
|||
summary: new.target eval handling limitations |
|||
--- |
|||
direct eval in program code |
|||
undefined |
|||
indirect eval in program code |
|||
undefined |
|||
direct eval in function code |
|||
undefined |
|||
false |
|||
function |
|||
true |
|||
indirect eval in function code |
|||
undefined |
|||
eval-in-eval in function code |
|||
undefined |
|||
false |
|||
function |
|||
true |
Loading…
Reference in new issue