forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargumentsResolution.js
More file actions
140 lines (126 loc) · 4.09 KB
/
argumentsResolution.js
File metadata and controls
140 lines (126 loc) · 4.09 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
function generateTestFunctionAndCall(
functionTypeAndName, // integer: 0 is declaration, 1 is declaration named 'arguments', 2 is unnamed expression, 3 is expression named 'arguments'
parameterArguments, // boolean
nestedFunctionType, // integer: 0 is no nested function, 1 is nested function declaration, 2 is nested function expression
varDeclarationArgumentsType, // integer: 0 is no var declaration, 1 is var declaration, 2 is initialized var declaration
callsEval) // boolean
{
var typeMap =
{
"function": "function",
"number": "parameter",
"string": "var",
"object": "arguments"
};
// The generated function will look something like this:
// safeCall(function ()
// {
// function arguments(arguments)
// {
// eval("");
// (function arguments() { });
// var arguments = "hi";
// writeLine(typeMap[typeof (arguments)]);
// }
// arguments(1);
// });
var functionCode = "";
switch (functionTypeAndName)
{
case 2:
case 3:
functionCode += "(";
}
functionCode += "function";
var functionName = "";
switch (functionTypeAndName)
{
case 0:
functionName = "foo";
break;
case 1:
case 3:
functionName = "arguments";
}
functionCode += " " + functionName + "(";
if (parameterArguments)
functionCode += "arguments";
functionCode += "){";
if (callsEval)
functionCode += 'eval("");';
switch (nestedFunctionType)
{
case 1:
functionCode += "function arguments(){}";
break;
case 2:
functionCode += "(function arguments(){});";
}
switch (varDeclarationArgumentsType)
{
case 1:
case 2:
functionCode += "var arguments";
if (varDeclarationArgumentsType === 2)
functionCode += '="hi"';
functionCode += ";";
}
functionCode += "writeLine(typeMap[typeof(arguments)]);}";
switch (functionTypeAndName)
{
case 0:
case 1:
functionCode += functionName;
break;
case 2:
case 3:
functionCode += ")";
}
functionCode += "(1);";
writeLine(functionCode);
eval("safeCall(function(){" + functionCode + "});");
}
var booleans = [false, true];
for (var functionTypeAndName = 0; functionTypeAndName <= 3; ++functionTypeAndName)
{
for (var parameterArgumentsIndex in booleans)
{
for (var nestedFunctionType = 0; nestedFunctionType <= 2; ++nestedFunctionType)
{
for (var varDeclarationArgumentsType = 0; varDeclarationArgumentsType <= 2; ++varDeclarationArgumentsType)
{
for (var callsEvalIndex in booleans)
{
var parameterArguments = booleans[parameterArgumentsIndex];
var callsEval = booleans[callsEvalIndex];
generateTestFunctionAndCall(
functionTypeAndName,
parameterArguments,
nestedFunctionType,
varDeclarationArgumentsType,
callsEval);
}
}
}
}
}
// Helpers
function writeLine(str)
{
WScript.Echo("" + str);
}
function safeCall(func)
{
try
{
return func();
}
catch (ex)
{
writeLine(ex.name + ": " + ex.message);
}
}