forked from google/blockly-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter-externs.js
166 lines (143 loc) · 4.66 KB
/
interpreter-externs.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* @fileoverview Externs for JS-Interpreter.
* @externs
*/
/**
* Create a new interpreter.
* @param {string|!Object} code Raw JavaScript text or AST.
* @param {Function=} opt_initFunc Optional initialization function. Used to
* define APIs. When called it is passed the interpreter object and the
* global scope object.
* @constructor
*/
var Interpreter = function(code, opt_initFunc) {};
/**
* Typedef for JS values.
* @typedef {!Interpreter.Object|boolean|number|string|undefined|null}
*/
Interpreter.Value;
/**
* Class for a state.
* @param {!Object} node AST node for the state.
* @param {!Interpreter.Scope} scope Scope object for the state.
* @constructor
*/
Interpreter.State = function(node, scope) {};
/**
* Class for an object.
* @param {Interpreter.Object} proto Prototype object or null.
* @constructor
*/
Interpreter.Object = function(proto) {};
/**
* @type {!Object}
*/
Interpreter.prototype.OBJECT;
/**
* @type {!Object}
*/
Interpreter.prototype.ARRAY;
/**
* @type {!Object}
*/
Interpreter.prototype.FUNCTION;
/**
* @type {!Object}
*/
Interpreter.prototype.STRING;
/**
* @type {!Object}
*/
Interpreter.prototype.BOOLEAN;
/**
* @type {!Object}
*/
Interpreter.prototype.value;
/**
* @type {!Array.<!Interpreter.State>}
*/
Interpreter.prototype.stateStack;
/**
* @type {Interpreter.Scope}
*/
Interpreter.prototype.globalScope;
/**
* Add more code to the interpreter.
* @param {string|!Object} code Raw JavaScript text or AST.
*/
Interpreter.prototype.appendCode = function(code) {};
/**
* Execute one step of the interpreter.
* @return {boolean} True if a step was executed, false if no more instructions.
*/
Interpreter.prototype.step = function() {};
/**
* Execute the interpreter to program completion. Vulnerable to infinite loops.
* @return {boolean} True if a execution is asynchronously blocked,
* false if no more instructions.
*/
Interpreter.prototype.run = function() {};
/**
* Create a new data object based on a constructor's prototype.
* @param {Interpreter.Object} constructor Parent constructor function,
* or null if scope object.
* @return {!Interpreter.Object} New data object.
*/
Interpreter.prototype.createObject = function(constructor) {};
/**
* Create a new interpreted function.
* @param {!Object} node AST node defining the function.
* @param {!Interpreter.Scope} scope Parent scope.
* @return {!Interpreter.Object} New function.
*/
Interpreter.prototype.createFunction = function(node, scope) {};
/**
* Create a new native function.
* @param {!Function} nativeFunc JavaScript function.
* @param {boolean} isConstructor True if function can be used with 'new'.
* @return {!Interpreter.Object} New function.
*/
Interpreter.prototype.createNativeFunction =
function(nativeFunc, opt_constructor) {};
/**
* Create a new native asynchronous function.
* @param {!Function} asyncFunc JavaScript function.
* @return {!Interpreter.Object} New function.
*/
Interpreter.prototype.createAsyncFunction = function(asyncFunc) {};
/**
* Converts from a native JavaScript object or value to a JS-Interpreter object.
* Can handle JSON-style values, regular expressions, dates and functions.
* Does NOT handle cycles.
* @param {*} nativeObj The native JavaScript object to be converted.
* @return {Interpreter.Value} The equivalent JS-Interpreter object.
*/
Interpreter.prototype.nativeToPseudo = function(nativeObj) {};
/**
* Converts from a JS-Interpreter object to native JavaScript object.
* Can handle JSON-style values, regular expressions, and dates.
* Does handle cycles.
* @param {Interpreter.Value} pseudoObj The JS-Interpreter object to be
* converted.
* @param {Object=} opt_cycles Cycle detection (used in recursive calls).
* @return {*} The equivalent native JavaScript object or value.
*/
Interpreter.prototype.pseudoToNative = function(pseudoObj, opt_cycles) {};
/**
* Fetch a property value from a data object.
* @param {Interpreter.Value} obj Data object.
* @param {Interpreter.Value} name Name of property.
* @return {Interpreter.Value} Property value (may be undefined).
*/
Interpreter.prototype.getProperty = function(obj, name) {};
/**
* Set a property value on a data object.
* @param {!Interpreter.Object} obj Data object.
* @param {Interpreter.Value} name Name of property.
* @param {Interpreter.Value|ReferenceError} value New property value.
* Use ReferenceError if value is handled by descriptor instead.
* @param {Object=} opt_descriptor Optional descriptor object.
* @return {!Interpreter.Object|undefined} Returns a setter function if one
* needs to be called, otherwise undefined.
*/
Interpreter.prototype.setProperty = function(obj, name, value, opt_descriptor) {};