-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathevalDeferred.js
75 lines (66 loc) · 1.65 KB
/
evalDeferred.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
var s1 =
'function f1() {' +
' var a = "a";' +
' function g1() {' +
' WScript.Echo(a);' +
' }' +
' return g1;' +
'}';
eval(s1);
WScript.Echo('done s1');
var foo1 = f1();
WScript.Echo('done f1');
foo1();
var s2 =
'var a = "global a";' +
'function f2(i) {' +
' with ({a:"with a"}) {' +
' var g2 = function() {' +
' WScript.Echo(a);' +
' };' +
' function g2_() {' +
' WScript.Echo(a);' +
' }' +
' }' +
' switch(i) {' +
' case 0: return g2;' +
' case 1: return g2_;' +
' }' +
'}';
eval(s2);
WScript.Echo('done s2');
var foo2 = f2(0);
var foo2_ = f2(1);
WScript.Echo('done f2');
foo2();
foo2_();
var s3 =
'function f3(i) {' +
' var a = "f3 a";' +
' function g3(i) {' +
' try {' +
' throw "catch";' +
' }' +
' catch(a) {' +
' function g4_() {' +
' WScript.Echo(a);' +
' }' +
' var g4 = function() {' +
' WScript.Echo(a);' +
' };' +
' return i == 0 ? g4 : g4_;' +
' }' +
' }' +
' return g3(i);' +
'}';
eval(s3);
WScript.Echo('done s3');
var foo3 = f3(0);
var foo3_ = f3(1);
WScript.Echo('done f3');
foo3();
foo3_();