js/src/vm/Opcodes.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:b91fcff759a8
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=0 ft=c:
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8 #ifndef vm_Opcodes_h
9 #define vm_Opcodes_h
10
11 #include "mozilla/Attributes.h"
12
13 #include <stddef.h>
14
15 /*
16 * JavaScript operation bytecodes. Add a new bytecode by claiming one of the
17 * JSOP_UNUSED* here or by extracting the first unused opcode from
18 * FOR_EACH_TRAILING_UNUSED_OPCODE and updating js::detail::LastDefinedOpcode
19 * below.
20 *
21 * When changing the bytecode, don't forget to update XDR_BYTECODE_VERSION in
22 * vm/Xdr.h!
23 *
24 * Includers must define a macro with the following form:
25 *
26 * #define MACRO(op,val,name,image,length,nuses,ndefs,format) ...
27 *
28 * Then simply use FOR_EACH_OPCODE(MACRO) to invoke MACRO for every opcode.
29 * Selected arguments can be expanded in initializers.
30 *
31 * Field Description
32 * op Bytecode name, which is the JSOp enumerator name
33 * value Bytecode value, which is the JSOp enumerator value
34 * name C string containing name for disassembler
35 * image C string containing "image" for pretty-printer, null if ugly
36 * length Number of bytes including any immediate operands
37 * nuses Number of stack slots consumed by bytecode, -1 if variadic
38 * ndefs Number of stack slots produced by bytecode, -1 if variadic
39 * format Bytecode plus immediate operand encoding format
40 *
41 * This file is best viewed with 128 columns:
42 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
43 */
44
45 /*
46 * SpiderMonkey bytecode categorization (as used in generated documentation):
47 *
48 * [Index]
49 * [Statements]
50 * Jumps
51 * Switch Statement
52 * For-In Statement
53 * With Statement
54 * Exception Handling
55 * Function
56 * Generator
57 * Debugger
58 * [Variables and Scopes]
59 * Variables
60 * Free Variables
61 * Local Variables
62 * Aliased Variables
63 * Intrinsics
64 * Block-local Scope
65 * This
66 * Arguments
67 * [Operator]
68 * Comparison Operators
69 * Arithmetic Operators
70 * Bitwise Logical Operators
71 * Bitwise Shift Operators
72 * Logical Operators
73 * Special Operators
74 * Stack Operations
75 * [Literals]
76 * Constants
77 * Object
78 * Array
79 * RegExp
80 * [Other]
81 */
82
83 #define FOR_EACH_OPCODE(macro) \
84 /* legend: op val name image len use def format */ \
85 /*
86 * No operation is performed.
87 * Category: Other
88 * Operands:
89 * Stack: =>
90 */ \
91 macro(JSOP_NOP, 0, "nop", NULL, 1, 0, 0, JOF_BYTE) \
92 \
93 /* Long-standing JavaScript bytecodes. */ \
94 /*
95 * Pushes 'undefined' onto the stack.
96 * Category: Literals
97 * Type: Constants
98 * Operands:
99 * Stack: => undefined
100 */ \
101 macro(JSOP_UNDEFINED, 1, js_undefined_str, "", 1, 0, 1, JOF_BYTE) \
102 macro(JSOP_UNUSED2, 2, "unused2", NULL, 1, 1, 0, JOF_BYTE) \
103 macro(JSOP_ENTERWITH, 3, "enterwith", NULL, 5, 1, 0, JOF_OBJECT) \
104 macro(JSOP_LEAVEWITH, 4, "leavewith", NULL, 1, 0, 0, JOF_BYTE) \
105 /*
106 * Pops the top of stack value as 'rval', stops interpretation of current
107 * script and returns 'rval'.
108 * Category: Statements
109 * Type: Function
110 * Operands:
111 * Stack: rval =>
112 */ \
113 macro(JSOP_RETURN, 5, "return", NULL, 1, 1, 0, JOF_BYTE) \
114 macro(JSOP_GOTO, 6, "goto", NULL, 5, 0, 0, JOF_JUMP) \
115 macro(JSOP_IFEQ, 7, "ifeq", NULL, 5, 1, 0, JOF_JUMP|JOF_DETECTING) \
116 macro(JSOP_IFNE, 8, "ifne", NULL, 5, 1, 0, JOF_JUMP) \
117 \
118 /*
119 * Pushes the 'arguments' object for the current function activation.
120 *
121 * If 'JSScript' is not marked 'needsArgsObj', then a
122 * JS_OPTIMIZED_ARGUMENTS magic value is pushed. Otherwise, a proper
123 * arguments object is constructed and pushed.
124 *
125 * This opcode requires that the function does not have rest parameter.
126 * Category: Variables and Scopes
127 * Type: Arguments
128 * Operands:
129 * Stack: => arguments
130 */ \
131 macro(JSOP_ARGUMENTS, 9, "arguments", NULL, 1, 0, 1, JOF_BYTE) \
132 \
133 /*
134 * Swaps the top two values on the stack. This is useful for things like
135 * post-increment/decrement.
136 * Category: Operator
137 * Type: Stack Operations
138 * Operands:
139 * Stack: v1, v2 => v2, v1
140 */ \
141 macro(JSOP_SWAP, 10, "swap", NULL, 1, 2, 2, JOF_BYTE) \
142 /*
143 * Pops the top 'n' values from the stack.
144 * Category: Operator
145 * Type: Stack Operations
146 * Operands: uint16_t n
147 * Stack: v[n-1], ..., v[1], v[0] =>
148 * nuses: n
149 */ \
150 macro(JSOP_POPN, 11, "popn", NULL, 3, -1, 0, JOF_UINT16) \
151 \
152 /* More long-standing bytecodes. */ \
153 /*
154 * Pushes a copy of the top value on the stack.
155 * Category: Operator
156 * Type: Stack Operations
157 * Operands:
158 * Stack: v => v, v
159 */ \
160 macro(JSOP_DUP, 12, "dup", NULL, 1, 1, 2, JOF_BYTE) \
161 /*
162 * Duplicates the top two values on the stack.
163 * Category: Operator
164 * Type: Stack Operations
165 * Operands:
166 * Stack: v1, v2 => v1, v2, v1, v2
167 */ \
168 macro(JSOP_DUP2, 13, "dup2", NULL, 1, 2, 4, JOF_BYTE) \
169 /*
170 * Defines a readonly property on the frame's current variables-object (the
171 * scope object on the scope chain designated to receive new variables).
172 * Category: Variables and Scopes
173 * Type: Variables
174 * Operands: uint32_t nameIndex
175 * Stack: val => val
176 */ \
177 macro(JSOP_SETCONST, 14, "setconst", NULL, 5, 1, 1, JOF_ATOM|JOF_NAME|JOF_SET) \
178 /*
179 * Pops the top two values 'lval' and 'rval' from the stack, then pushes
180 * the result of the operation applied to the two operands, converting
181 * both to 32-bit signed integers if necessary.
182 * Category: Operator
183 * Type: Bitwise Logical Operators
184 * Operands:
185 * Stack: lval, rval => (lval OP rval)
186 */ \
187 macro(JSOP_BITOR, 15, "bitor", "|", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
188 macro(JSOP_BITXOR, 16, "bitxor", "^", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
189 macro(JSOP_BITAND, 17, "bitand", "&", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
190 /*
191 * Pops the top two values from the stack and pushes the result of
192 * comparing them.
193 * Category: Operator
194 * Type: Comparison Operators
195 * Operands:
196 * Stack: lval, rval => (lval OP rval)
197 */ \
198 macro(JSOP_EQ, 18, "eq", "==", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH|JOF_DETECTING) \
199 macro(JSOP_NE, 19, "ne", "!=", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH|JOF_DETECTING) \
200 macro(JSOP_LT, 20, "lt", "<", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
201 macro(JSOP_LE, 21, "le", "<=", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
202 macro(JSOP_GT, 22, "gt", ">", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
203 macro(JSOP_GE, 23, "ge", ">=", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
204 /*
205 * Pops the top two values 'lval' and 'rval' from the stack, then pushes
206 * the result of the operation applied to the operands.
207 * Category: Operator
208 * Type: Bitwise Shift Operators
209 * Operands:
210 * Stack: lval, rval => (lval OP rval)
211 */ \
212 macro(JSOP_LSH, 24, "lsh", "<<", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
213 macro(JSOP_RSH, 25, "rsh", ">>", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
214 /*
215 * Pops the top two values 'lval' and 'rval' from the stack, then pushes
216 * 'lval >>> rval'.
217 * Category: Operator
218 * Type: Bitwise Shift Operators
219 * Operands:
220 * Stack: lval, rval => (lval >>> rval)
221 */ \
222 macro(JSOP_URSH, 26, "ursh", ">>>", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
223 /*
224 * Pops the top two values 'lval' and 'rval' from the stack, then pushes
225 * the result of 'lval + rval'.
226 * Category: Operator
227 * Type: Arithmetic Operators
228 * Operands:
229 * Stack: lval, rval => (lval + rval)
230 */ \
231 macro(JSOP_ADD, 27, "add", "+", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
232 /*
233 * Pops the top two values 'lval' and 'rval' from the stack, then pushes
234 * the result of applying the arithmetic operation to them.
235 * Category: Operator
236 * Type: Arithmetic Operators
237 * Operands:
238 * Stack: lval, rval => (lval OP rval)
239 */ \
240 macro(JSOP_SUB, 28, "sub", "-", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
241 macro(JSOP_MUL, 29, "mul", "*", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
242 macro(JSOP_DIV, 30, "div", "/", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
243 macro(JSOP_MOD, 31, "mod", "%", 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC|JOF_ARITH) \
244 /*
245 * Pops the value 'val' from the stack, then pushes '!val'.
246 * Category: Operator
247 * Type: Logical Operators
248 * Operands:
249 * Stack: val => (!val)
250 */ \
251 macro(JSOP_NOT, 32, "not", "!", 1, 1, 1, JOF_BYTE|JOF_ARITH|JOF_DETECTING) \
252 /*
253 * Pops the value 'val' from the stack, then pushes '~val'.
254 * Category: Operator
255 * Type: Bitwise Logical Operators
256 * Operands:
257 * Stack: val => (~val)
258 */ \
259 macro(JSOP_BITNOT, 33, "bitnot", "~", 1, 1, 1, JOF_BYTE|JOF_ARITH) \
260 /*
261 * Pops the value 'val' from the stack, then pushes '-val'.
262 * Category: Operator
263 * Type: Arithmetic Operators
264 * Operands:
265 * Stack: val => (-val)
266 */ \
267 macro(JSOP_NEG, 34, "neg", "- ", 1, 1, 1, JOF_BYTE|JOF_ARITH) \
268 /*
269 * Pops the value 'val' from the stack, then pushes '+val'.
270 * ('+val' is the value converted to a number.)
271 * Category: Operator
272 * Type: Arithmetic Operators
273 * Operands:
274 * Stack: val => (+val)
275 */ \
276 macro(JSOP_POS, 35, "pos", "+ ", 1, 1, 1, JOF_BYTE|JOF_ARITH) \
277 /*
278 * Looks up name on the scope chain and deletes it, pushes 'true' onto the
279 * stack if succeeded (if the property was present and deleted or if the
280 * property wasn't present in the first place), 'false' if not.
281 *
282 * Strict mode code should never contain this opcode.
283 * Category: Variables and Scopes
284 * Type: Variables
285 * Operands: uint32_t nameIndex
286 * Stack: => succeeded
287 */ \
288 macro(JSOP_DELNAME, 36, "delname", NULL, 5, 0, 1, JOF_ATOM|JOF_NAME) \
289 /*
290 * Pops the top of stack value, deletes property from it, pushes 'true' onto
291 * the stack if succeeded, 'false' if not.
292 * Category: Literals
293 * Type: Object
294 * Operands: uint32_t nameIndex
295 * Stack: obj => succeeded
296 */ \
297 macro(JSOP_DELPROP, 37, "delprop", NULL, 5, 1, 1, JOF_ATOM|JOF_PROP) \
298 /*
299 * Pops the top two values on the stack as 'propval' and 'obj',
300 * deletes 'propval' property from 'obj', pushes 'true' onto the stack if
301 * succeeded, 'false' if not.
302 * Category: Literals
303 * Type: Object
304 * Operands:
305 * Stack: obj, propval => succeeded
306 */ \
307 macro(JSOP_DELELEM, 38, "delelem", NULL, 1, 2, 1, JOF_BYTE |JOF_ELEM) \
308 /*
309 * Pops the value 'val' from the stack, then pushes 'typeof val'.
310 * Category: Operator
311 * Type: Special Operators
312 * Operands:
313 * Stack: val => (typeof val)
314 */ \
315 macro(JSOP_TYPEOF, 39, js_typeof_str,NULL, 1, 1, 1, JOF_BYTE|JOF_DETECTING) \
316 /*
317 * Pops the top value on the stack and pushes 'undefined'.
318 * Category: Operator
319 * Type: Special Operators
320 * Operands:
321 * Stack: val => undefined
322 */ \
323 macro(JSOP_VOID, 40, js_void_str, NULL, 1, 1, 1, JOF_BYTE) \
324 \
325 /*
326 * spreadcall variant of JSOP_CALL.
327 *
328 * Invokes 'callee' with 'this' and 'args', pushes the return value onto
329 * the stack.
330 *
331 * 'args' is an Array object which contains actual arguments.
332 * Category: Statements
333 * Type: Function
334 * Operands:
335 * Stack: callee, this, args => rval
336 */ \
337 macro(JSOP_SPREADCALL,41, "spreadcall", NULL, 1, 3, 1, JOF_BYTE|JOF_INVOKE|JOF_TYPESET) \
338 /*
339 * spreadcall variant of JSOP_NEW
340 *
341 * Invokes 'callee' as a constructor with 'this' and 'args', pushes the
342 * return value onto the stack.
343 * Category: Statements
344 * Type: Function
345 * Operands:
346 * Stack: callee, this, args => rval
347 */ \
348 macro(JSOP_SPREADNEW, 42, "spreadnew", NULL, 1, 3, 1, JOF_BYTE|JOF_INVOKE|JOF_TYPESET) \
349 /*
350 * spreadcall variant of JSOP_EVAL
351 *
352 * Invokes 'eval' with 'args' and pushes the return value onto the stack.
353 *
354 * If 'eval' in global scope is not original one, invokes the function
355 * with 'this' and 'args', and pushes return value onto the stack.
356 * Category: Statements
357 * Type: Function
358 * Operands:
359 * Stack: callee, this, args => rval
360 */ \
361 macro(JSOP_SPREADEVAL,43, "spreadeval", NULL, 1, 3, 1, JOF_BYTE|JOF_INVOKE|JOF_TYPESET) \
362 \
363 /*
364 * Duplicates the Nth value from the top onto the stack.
365 * Category: Operator
366 * Type: Stack Operations
367 * Operands: uint24_t n
368 * Stack: v[n], v[n-1], ..., v[1], v[0] =>
369 * v[n], v[n-1], ..., v[1], v[0], v[n]
370 */ \
371 macro(JSOP_DUPAT, 44, "dupat", NULL, 4, 0, 1, JOF_UINT24) \
372 \
373 macro(JSOP_UNUSED45, 45, "unused45", NULL, 1, 0, 0, JOF_BYTE) \
374 macro(JSOP_UNUSED46, 46, "unused46", NULL, 1, 0, 0, JOF_BYTE) \
375 macro(JSOP_UNUSED47, 47, "unused47", NULL, 1, 0, 0, JOF_BYTE) \
376 macro(JSOP_UNUSED48, 48, "unused48", NULL, 1, 0, 0, JOF_BYTE) \
377 macro(JSOP_UNUSED49, 49, "unused49", NULL, 1, 0, 0, JOF_BYTE) \
378 macro(JSOP_UNUSED50, 50, "unused50", NULL, 1, 0, 0, JOF_BYTE) \
379 macro(JSOP_UNUSED51, 51, "unused51", NULL, 1, 0, 0, JOF_BYTE) \
380 macro(JSOP_UNUSED52, 52, "unused52", NULL, 1, 0, 0, JOF_BYTE) \
381 \
382 /*
383 * Pops the top of stack value, pushes property of it onto the stack.
384 * Category: Literals
385 * Type: Object
386 * Operands: uint32_t nameIndex
387 * Stack: obj => obj[name]
388 */ \
389 macro(JSOP_GETPROP, 53, "getprop", NULL, 5, 1, 1, JOF_ATOM|JOF_PROP|JOF_TYPESET|JOF_TMPSLOT3) \
390 /*
391 * Pops the top two values on the stack as 'val' and 'obj', sets property of
392 * 'obj' as 'val', pushes 'obj' onto the stack.
393 * Category: Literals
394 * Type: Object
395 * Operands: uint32_t nameIndex
396 * Stack: obj, val => val
397 */ \
398 macro(JSOP_SETPROP, 54, "setprop", NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_SET|JOF_DETECTING) \
399 /*
400 * Pops the top two values on the stack as 'propval' and 'obj', pushes
401 * 'propval' property of 'obj' onto the stack.
402 * Category: Literals
403 * Type: Object
404 * Operands:
405 * Stack: obj, propval => obj[propval]
406 */ \
407 macro(JSOP_GETELEM, 55, "getelem", NULL, 1, 2, 1, JOF_BYTE |JOF_ELEM|JOF_TYPESET|JOF_LEFTASSOC) \
408 /*
409 * Pops the top three values on the stack as 'val', 'propval' and 'obj',
410 * sets 'propval' property of 'obj' as 'val', pushes 'obj' onto the
411 * stack.
412 * Category: Literals
413 * Type: Object
414 * Operands:
415 * Stack: obj, propval, val => val
416 */ \
417 macro(JSOP_SETELEM, 56, "setelem", NULL, 1, 3, 1, JOF_BYTE |JOF_ELEM|JOF_SET|JOF_DETECTING) \
418 macro(JSOP_UNUSED57, 57, "unused57", NULL, 1, 0, 0, JOF_BYTE) \
419 /*
420 * Invokes 'callee' with 'this' and 'args', pushes return value onto the
421 * stack.
422 * Category: Statements
423 * Type: Function
424 * Operands: uint16_t argc
425 * Stack: callee, this, args[0], ..., args[argc-1] => rval
426 * nuses: (argc+2)
427 */ \
428 macro(JSOP_CALL, 58, "call", NULL, 3, -1, 1, JOF_UINT16|JOF_INVOKE|JOF_TYPESET) \
429 /*
430 * Looks up name on the scope chain and pushes its value onto the stack.
431 * Category: Variables and Scopes
432 * Type: Variables
433 * Operands: uint32_t nameIndex
434 * Stack: => val
435 */ \
436 macro(JSOP_NAME, 59, "name", NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_TYPESET) \
437 /*
438 * Pushes numeric constant onto the stack.
439 * Category: Literals
440 * Type: Constants
441 * Operands: uint32_t constIndex
442 * Stack: => val
443 */ \
444 macro(JSOP_DOUBLE, 60, "double", NULL, 5, 0, 1, JOF_DOUBLE) \
445 /*
446 * Pushes string constant onto the stack.
447 * Category: Literals
448 * Type: Constants
449 * Operands: uint32_t atomIndex
450 * Stack: => string
451 */ \
452 macro(JSOP_STRING, 61, "string", NULL, 5, 0, 1, JOF_ATOM) \
453 /*
454 * Pushes '0' onto the stack.
455 * Category: Literals
456 * Type: Constants
457 * Operands:
458 * Stack: => 0
459 */ \
460 macro(JSOP_ZERO, 62, "zero", "0", 1, 0, 1, JOF_BYTE) \
461 /*
462 * Pushes '1' onto the stack.
463 * Category: Literals
464 * Type: Constants
465 * Operands:
466 * Stack: => 1
467 */ \
468 macro(JSOP_ONE, 63, "one", "1", 1, 0, 1, JOF_BYTE) \
469 /*
470 * Pushes 'null' onto the stack.
471 * Category: Literals
472 * Type: Constants
473 * Operands:
474 * Stack: => null
475 */ \
476 macro(JSOP_NULL, 64, js_null_str, js_null_str, 1, 0, 1, JOF_BYTE) \
477 /*
478 * Pushes 'this' value for current stack frame onto the stack.
479 * Category: Variables and Scopes
480 * Type: This
481 * Operands:
482 * Stack: => this
483 */ \
484 macro(JSOP_THIS, 65, js_this_str, js_this_str, 1, 0, 1, JOF_BYTE) \
485 /*
486 * Pushes boolean value onto the stack.
487 * Category: Literals
488 * Type: Constants
489 * Operands:
490 * Stack: => true/false
491 */ \
492 macro(JSOP_FALSE, 66, js_false_str, js_false_str, 1, 0, 1, JOF_BYTE) \
493 macro(JSOP_TRUE, 67, js_true_str, js_true_str, 1, 0, 1, JOF_BYTE) \
494 macro(JSOP_OR, 68, "or", NULL, 5, 1, 1, JOF_JUMP|JOF_DETECTING|JOF_LEFTASSOC) \
495 macro(JSOP_AND, 69, "and", NULL, 5, 1, 1, JOF_JUMP|JOF_DETECTING|JOF_LEFTASSOC) \
496 \
497 /* The switch bytecodes have variable length. */ \
498 macro(JSOP_TABLESWITCH, 70, "tableswitch", NULL, -1, 1, 0, JOF_TABLESWITCH|JOF_DETECTING) \
499 \
500 /*
501 * Prologue emitted in scripts expected to run once, which deoptimizes code
502 * if it executes multiple times.
503 * Category: Statements
504 * Type: Function
505 * Operands:
506 * Stack: =>
507 */ \
508 macro(JSOP_RUNONCE, 71, "runonce", NULL, 1, 0, 0, JOF_BYTE) \
509 \
510 /* New, infallible/transitive identity ops. */ \
511 /*
512 * Pops the top two values from the stack, then pushes the result of
513 * applying the operator to the two values.
514 * Category: Operator
515 * Type: Comparison Operators
516 * Operands:
517 * Stack: lval, rval => (lval OP rval)
518 */ \
519 macro(JSOP_STRICTEQ, 72, "stricteq", "===", 1, 2, 1, JOF_BYTE|JOF_DETECTING|JOF_LEFTASSOC|JOF_ARITH) \
520 macro(JSOP_STRICTNE, 73, "strictne", "!==", 1, 2, 1, JOF_BYTE|JOF_DETECTING|JOF_LEFTASSOC|JOF_ARITH) \
521 \
522 /*
523 * Sometimes web pages do 'o.Item(i) = j'. This is not an early SyntaxError,
524 * for web compatibility. Instead we emit JSOP_SETCALL after the function
525 * call, an opcode that always throws.
526 * Category: Statements
527 * Type: Function
528 * Operands:
529 * Stack: =>
530 */ \
531 macro(JSOP_SETCALL, 74, "setcall", NULL, 1, 0, 0, JOF_BYTE) \
532 \
533 /*
534 * JSOP_ITER sets up a for-in or for-each-in loop using the JSITER_* flag bits
535 * in this op's uint8_t immediate operand. It replaces the top of stack value
536 * with an iterator for that value.
537 *
538 * JSOP_MOREITER stores the next iterated value into cx->iterValue and pushes
539 * true if another value is available, and false otherwise. It is followed
540 * immediately by JSOP_IFNE.
541 *
542 * JSOP_ENDITER cleans up after the loop. It uses the slot above the iterator
543 * for temporary GC rooting.
544 */ \
545 macro(JSOP_ITER, 75, "iter", NULL, 2, 1, 1, JOF_UINT8) \
546 macro(JSOP_MOREITER, 76, "moreiter", NULL, 1, 1, 2, JOF_BYTE) \
547 macro(JSOP_ITERNEXT, 77, "iternext", "<next>", 1, 0, 1, JOF_BYTE) \
548 macro(JSOP_ENDITER, 78, "enditer", NULL, 1, 1, 0, JOF_BYTE) \
549 \
550 /*
551 * Invokes 'callee' with 'this' and 'args', pushes return value onto the
552 * stack.
553 *
554 * This is for 'f.apply'.
555 * Category: Statements
556 * Type: Function
557 * Operands: uint16_t argc
558 * Stack: callee, this, args[0], ..., args[argc-1] => rval
559 * nuses: (argc+2)
560 */ \
561 macro(JSOP_FUNAPPLY, 79, "funapply", NULL, 3, -1, 1, JOF_UINT16|JOF_INVOKE|JOF_TYPESET) \
562 \
563 /*
564 * Pushes deep-cloned object literal or singleton onto the stack.
565 * Category: Literals
566 * Type: Object
567 * Operands: uint32_t objectIndex
568 * Stack: => obj
569 */ \
570 macro(JSOP_OBJECT, 80, "object", NULL, 5, 0, 1, JOF_OBJECT) \
571 \
572 /*
573 * Pops the top value off the stack.
574 * Category: Operator
575 * Type: Stack Operations
576 * Operands:
577 * Stack: v =>
578 */ \
579 macro(JSOP_POP, 81, "pop", NULL, 1, 1, 0, JOF_BYTE) \
580 \
581 /*
582 * Invokes 'callee' as a constructor with 'this' and 'args', pushes return
583 * value onto the stack.
584 * Category: Statements
585 * Type: Function
586 * Operands: uint16_t argc
587 * Stack: callee, this, args[0], ..., args[argc-1] => rval
588 * nuses: (argc+2)
589 */ \
590 macro(JSOP_NEW, 82, js_new_str, NULL, 3, -1, 1, JOF_UINT16|JOF_INVOKE|JOF_TYPESET) \
591 /*
592 * Pops the top three values on the stack as 'iterable', 'index' and 'obj',
593 * iterates over 'iterable' and stores the iteration values as 'index + i'
594 * elements of 'obj', pushes 'obj' and 'index + iteration count' onto the
595 * stack.
596 *
597 * This opcode is used in Array literals with spread and spreadcall
598 * arguments.
599 * Category: Literals
600 * Type: Array
601 * Operands:
602 * Stack: obj, index, iterable => obj, (index + iteration count)
603 */ \
604 macro(JSOP_SPREAD, 83, "spread", NULL, 1, 3, 2, JOF_BYTE|JOF_ELEM|JOF_SET) \
605 \
606 /*
607 * Fast get op for function arguments and local variables.
608 *
609 * Pushes 'arguments[argno]' onto the stack.
610 * Category: Variables and Scopes
611 * Type: Arguments
612 * Operands: uint16_t argno
613 * Stack: => arguments[argno]
614 */ \
615 macro(JSOP_GETARG, 84, "getarg", NULL, 3, 0, 1, JOF_QARG |JOF_NAME) \
616 /*
617 * Fast set op for function arguments and local variables.
618 *
619 * Sets 'arguments[argno]' as the top of stack value.
620 * Category: Variables and Scopes
621 * Type: Arguments
622 * Operands: uint16_t argno
623 * Stack: v => v
624 */ \
625 macro(JSOP_SETARG, 85, "setarg", NULL, 3, 1, 1, JOF_QARG |JOF_NAME|JOF_SET) \
626 /*
627 * Pushes the value of local variable onto the stack.
628 * Category: Variables and Scopes
629 * Type: Local Variables
630 * Operands: uint32_t localno
631 * Stack: => val
632 */ \
633 macro(JSOP_GETLOCAL, 86,"getlocal", NULL, 4, 0, 1, JOF_LOCAL|JOF_NAME) \
634 /*
635 * Stores the top stack value to the given local.
636 * Category: Variables and Scopes
637 * Type: Local Variables
638 * Operands: uint32_t localno
639 * Stack: v => v
640 */ \
641 macro(JSOP_SETLOCAL, 87,"setlocal", NULL, 4, 1, 1, JOF_LOCAL|JOF_NAME|JOF_SET|JOF_DETECTING) \
642 \
643 /*
644 * Pushes unsigned 16-bit int immediate integer operand onto the stack.
645 * Category: Literals
646 * Type: Constants
647 * Operands: uint16_t val
648 * Stack: => val
649 */ \
650 macro(JSOP_UINT16, 88, "uint16", NULL, 3, 0, 1, JOF_UINT16) \
651 \
652 /* Object and array literal support. */ \
653 /*
654 * Pushes newly created object onto the stack.
655 *
656 * This opcode takes the kind of initializer (JSProto_Array or
657 * JSProto_Object).
658 *
659 * This opcode has an extra byte so it can be exchanged with JSOP_NEWOBJECT
660 * during emit.
661 * Category: Literals
662 * Type: Object
663 * Operands: uint8_t kind (, uint24_t extra)
664 * Stack: => obj
665 */ \
666 macro(JSOP_NEWINIT, 89, "newinit", NULL, 5, 0, 1, JOF_UINT8) \
667 /*
668 * Pushes newly created array onto the stack.
669 *
670 * This opcode takes the final length, which is preallocated.
671 * Category: Literals
672 * Type: Array
673 * Operands: uint24_t length
674 * Stack: => obj
675 */ \
676 macro(JSOP_NEWARRAY, 90, "newarray", NULL, 4, 0, 1, JOF_UINT24) \
677 /*
678 * Pushes newly created object onto the stack.
679 *
680 * This opcode takes an object with the final shape, which can be set at
681 * the start and slots then filled in directly.
682 * Category: Literals
683 * Type: Object
684 * Operands: uint32_t baseobjIndex
685 * Stack: => obj
686 */ \
687 macro(JSOP_NEWOBJECT, 91, "newobject", NULL, 5, 0, 1, JOF_OBJECT) \
688 /*
689 * A no-operation bytecode.
690 *
691 * Indicates the end of object/array initialization, and used for
692 * Type-Inference, decompile, etc.
693 * Category: Literals
694 * Type: Object
695 * Operands:
696 * Stack: =>
697 */ \
698 macro(JSOP_ENDINIT, 92, "endinit", NULL, 1, 0, 0, JOF_BYTE) \
699 /*
700 * Initialize a named property in an object literal, like '{a: x}'.
701 *
702 * Pops the top two values on the stack as 'val' and 'obj', defines
703 * 'nameIndex' property of 'obj' as 'val', pushes 'obj' onto the stack.
704 * Category: Literals
705 * Type: Object
706 * Operands: uint32_t nameIndex
707 * Stack: obj, val => obj
708 */ \
709 macro(JSOP_INITPROP, 93, "initprop", NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_SET|JOF_DETECTING) \
710 \
711 /*
712 * Initialize a numeric property in an object literal, like '{1: x}'.
713 *
714 * Pops the top three values on the stack as 'val', 'id' and 'obj', defines
715 * 'id' property of 'obj' as 'val', pushes 'obj' onto the stack.
716 * Category: Literals
717 * Type: Object
718 * Operands:
719 * Stack: obj, id, val => obj
720 */ \
721 macro(JSOP_INITELEM, 94, "initelem", NULL, 1, 3, 1, JOF_BYTE|JOF_ELEM|JOF_SET|JOF_DETECTING) \
722 \
723 /*
724 * Pops the top three values on the stack as 'val', 'index' and 'obj', sets
725 * 'index' property of 'obj' as 'val', pushes 'obj' and 'index + 1' onto
726 * the stack.
727 *
728 * This opcode is used in Array literals with spread and spreadcall
729 * arguments.
730 * Category: Literals
731 * Type: Array
732 * Operands:
733 * Stack: obj, index, val => obj, (index + 1)
734 */ \
735 macro(JSOP_INITELEM_INC,95, "initelem_inc", NULL, 1, 3, 2, JOF_BYTE|JOF_ELEM|JOF_SET) \
736 \
737 /*
738 * Initialize an array element.
739 *
740 * Pops the top two values on the stack as 'val' and 'obj', sets 'index'
741 * property of 'obj' as 'val', pushes 'obj' onto the stack.
742 * Category: Literals
743 * Type: Array
744 * Operands: uint24_t index
745 * Stack: obj, val => obj
746 */ \
747 macro(JSOP_INITELEM_ARRAY,96, "initelem_array", NULL, 4, 2, 1, JOF_UINT24|JOF_ELEM|JOF_SET|JOF_DETECTING) \
748 \
749 /*
750 * Initialize a getter in an object literal.
751 *
752 * Pops the top two values on the stack as 'val' and 'obj', defines getter
753 * of 'obj' as 'val', pushes 'obj' onto the stack.
754 * Category: Literals
755 * Type: Object
756 * Operands: uint32_t nameIndex
757 * Stack: obj, val => obj
758 */ \
759 macro(JSOP_INITPROP_GETTER, 97, "initprop_getter", NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_SET|JOF_DETECTING) \
760 /*
761 * Initialize a setter in an object literal.
762 *
763 * Pops the top two values on the stack as 'val' and 'obj', defines setter
764 * of 'obj' as 'val', pushes 'obj' onto the stack.
765 * Category: Literals
766 * Type: Object
767 * Operands: uint32_t nameIndex
768 * Stack: obj, val => obj
769 */ \
770 macro(JSOP_INITPROP_SETTER, 98, "initprop_setter", NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_SET|JOF_DETECTING) \
771 /*
772 * Initialize a numeric getter in an object literal like
773 * '{get 2() {}}'.
774 *
775 * Pops the top three values on the stack as 'val', 'id' and 'obj', defines
776 * 'id' getter of 'obj' as 'val', pushes 'obj' onto the stack.
777 * Category: Literals
778 * Type: Object
779 * Operands:
780 * Stack: obj, id, val => obj
781 */ \
782 macro(JSOP_INITELEM_GETTER, 99, "initelem_getter", NULL, 1, 3, 1, JOF_BYTE|JOF_ELEM|JOF_SET|JOF_DETECTING) \
783 /*
784 * Initialize a numeric setter in an object literal like
785 * '{set 2(v) {}}'.
786 *
787 * Pops the top three values on the stack as 'val', 'id' and 'obj', defines
788 * 'id' setter of 'obj' as 'val', pushes 'obj' onto the stack.
789 * Category: Literals
790 * Type: Object
791 * Operands:
792 * Stack: obj, id, val => obj
793 */ \
794 macro(JSOP_INITELEM_SETTER, 100, "initelem_setter", NULL, 1, 3, 1, JOF_BYTE|JOF_ELEM|JOF_SET|JOF_DETECTING) \
795 \
796 macro(JSOP_UNUSED101, 101, "unused101", NULL, 1, 0, 0, JOF_BYTE) \
797 macro(JSOP_UNUSED102, 102, "unused102", NULL, 1, 0, 0, JOF_BYTE) \
798 macro(JSOP_UNUSED103, 103, "unused103", NULL, 1, 0, 0, JOF_BYTE) \
799 macro(JSOP_UNUSED104, 104, "unused104", NULL, 1, 0, 0, JOF_BYTE) \
800 macro(JSOP_UNUSED105, 105, "unused105", NULL, 1, 0, 0, JOF_BYTE) \
801 \
802 /* The argument is the offset to the next statement and is used by IonMonkey. */ \
803 macro(JSOP_LABEL, 106,"label", NULL, 5, 0, 0, JOF_JUMP) \
804 \
805 macro(JSOP_UNUSED107, 107,"unused107", NULL, 1, 0, 0, JOF_BYTE) \
806 \
807 /*
808 * Invokes 'callee' with 'this' and 'args', pushes return value onto the
809 * stack.
810 *
811 * If 'callee' is determined to be the canonical 'Function.prototype.call'
812 * function, then this operation is optimized to directly call 'callee'
813 * with 'args[0]' as 'this', and the remaining arguments as formal args
814 * to 'callee'.
815 *
816 * Like JSOP_FUNAPPLY but for 'f.call' instead of 'f.apply'.
817 * Category: Statements
818 * Type: Function
819 * Operands: uint16_t argc
820 * Stack: callee, this, args[0], ..., args[argc-1] => rval
821 * nuses: (argc+2)
822 */ \
823 macro(JSOP_FUNCALL, 108,"funcall", NULL, 3, -1, 1, JOF_UINT16|JOF_INVOKE|JOF_TYPESET) \
824 \
825 /* This opcode is the target of the backwards jump for some loop. */ \
826 macro(JSOP_LOOPHEAD, 109,"loophead", NULL, 1, 0, 0, JOF_BYTE) \
827 \
828 /* ECMA-compliant assignment ops. */ \
829 /*
830 * Looks up name on the scope chain and pushes the scope which contains
831 * the name onto the stack. If not found, pushes global scope onto the
832 * stack.
833 * Category: Variables and Scopes
834 * Type: Variables
835 * Operands: uint32_t nameIndex
836 * Stack: => scope
837 */ \
838 macro(JSOP_BINDNAME, 110,"bindname", NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_SET) \
839 /*
840 * Pops a scope and value from the stack, assigns value to the given name,
841 * and pushes the value back on the stack
842 * Category: Variables and Scopes
843 * Type: Variables
844 * Operands: uint32_t nameIndex
845 * Stack: scope, val => val
846 */ \
847 macro(JSOP_SETNAME, 111,"setname", NULL, 5, 2, 1, JOF_ATOM|JOF_NAME|JOF_SET|JOF_DETECTING) \
848 \
849 /* Exception handling ops. */ \
850 macro(JSOP_THROW, 112,js_throw_str, NULL, 1, 1, 0, JOF_BYTE) \
851 \
852 /*
853 * Pops the top two values 'id' and 'obj' from the stack, then pushes
854 * 'id in obj'. This will throw a 'TypeError' if 'obj' is not an object.
855 *
856 * Note that 'obj' is the top value.
857 * Category: Operator
858 * Type: Special Operators
859 * Operands:
860 * Stack: id, obj => (id in obj)
861 */ \
862 macro(JSOP_IN, 113,js_in_str, js_in_str, 1, 2, 1, JOF_BYTE|JOF_LEFTASSOC) \
863 /*
864 * Pops the top two values 'obj' and 'ctor' from the stack, then pushes
865 * 'obj instanceof ctor'. This will throw a 'TypeError' if 'obj' is not an
866 * object.
867 * Category: Operator
868 * Type: Special Operators
869 * Operands:
870 * Stack: obj, ctor => (obj instanceof ctor)
871 */ \
872 macro(JSOP_INSTANCEOF,114,js_instanceof_str,js_instanceof_str,1,2,1,JOF_BYTE|JOF_LEFTASSOC|JOF_TMPSLOT) \
873 \
874 /*
875 * Invokes debugger.
876 * Category: Statements
877 * Type: Debugger
878 * Operands:
879 * Stack: =>
880 */ \
881 macro(JSOP_DEBUGGER, 115,"debugger", NULL, 1, 0, 0, JOF_BYTE) \
882 \
883 /* gosub/retsub for finally handling */ \
884 macro(JSOP_GOSUB, 116,"gosub", NULL, 5, 0, 0, JOF_JUMP) \
885 macro(JSOP_RETSUB, 117,"retsub", NULL, 1, 2, 0, JOF_BYTE) \
886 \
887 /* More exception handling ops. */ \
888 macro(JSOP_EXCEPTION, 118,"exception", NULL, 1, 0, 1, JOF_BYTE) \
889 \
890 /*
891 * Embedded lineno to speedup 'pc->line' mapping.
892 * Category: Other
893 * Operands: uint32_t lineno
894 * Stack: =>
895 */ \
896 macro(JSOP_LINENO, 119,"lineno", NULL, 3, 0, 0, JOF_UINT16) \
897 \
898 /*
899 * ECMA-compliant switch statement ops.
900 * CONDSWITCH is a decompilable NOP; CASE is ===, POP, jump if true, re-push
901 * lval if false; and DEFAULT is POP lval and GOTO.
902 */ \
903 macro(JSOP_CONDSWITCH,120,"condswitch", NULL, 1, 0, 0, JOF_BYTE) \
904 macro(JSOP_CASE, 121,"case", NULL, 5, 2, 1, JOF_JUMP) \
905 macro(JSOP_DEFAULT, 122,"default", NULL, 5, 1, 0, JOF_JUMP) \
906 \
907 /* ECMA-compliant call to eval op. */ \
908 /*
909 * Invokes 'eval' with 'args' and pushes return value onto the stack.
910 *
911 * If 'eval' in global scope is not original one, invokes the function
912 * with 'this' and 'args', and pushes return value onto the stack.
913 * Category: Statements
914 * Type: Function
915 * Operands: uint16_t argc
916 * Stack: callee, this, args[0], ..., args[argc-1] => rval
917 * nuses: (argc+2)
918 */ \
919 macro(JSOP_EVAL, 123,"eval", NULL, 3, -1, 1, JOF_UINT16|JOF_INVOKE|JOF_TYPESET) \
920 \
921 macro(JSOP_UNUSED124, 124, "unused124", NULL, 1, 0, 0, JOF_BYTE) \
922 macro(JSOP_UNUSED125, 125, "unused125", NULL, 1, 0, 0, JOF_BYTE) \
923 macro(JSOP_UNUSED126, 126, "unused126", NULL, 1, 0, 0, JOF_BYTE) \
924 \
925 /*
926 * Defines the given function on the current scope.
927 *
928 * This is used for global scripts and also in some cases for function
929 * scripts where use of dynamic scoping inhibits optimization.
930 * Category: Variables and Scopes
931 * Type: Variables
932 * Operands: uint32_t funcIndex
933 * Stack: =>
934 */ \
935 macro(JSOP_DEFFUN, 127,"deffun", NULL, 5, 0, 0, JOF_OBJECT) \
936 /*
937 * Defines the new binding on the frame's current variables-object (the
938 * scope object on the scope chain designated to receive new variables)
939 * with 'READONLY' attribute.
940 *
941 * This is used for global scripts and also in some cases for function
942 * scripts where use of dynamic scoping inhibits optimization.
943 * Category: Variables and Scopes
944 * Type: Variables
945 * Operands: uint32_t nameIndex
946 * Stack: =>
947 */ \
948 macro(JSOP_DEFCONST, 128,"defconst", NULL, 5, 0, 0, JOF_ATOM) \
949 /*
950 * Defines the new binding on the frame's current variables-object (the
951 * scope object on the scope chain designated to receive new variables).
952 *
953 * This is used for global scripts and also in some cases for function
954 * scripts where use of dynamic scoping inhibits optimization.
955 * Category: Variables and Scopes
956 * Type: Variables
957 * Operands: uint32_t nameIndex
958 * Stack: =>
959 */ \
960 macro(JSOP_DEFVAR, 129,"defvar", NULL, 5, 0, 0, JOF_ATOM) \
961 \
962 /*
963 * Pushes a closure for a named or anonymous function expression onto the
964 * stack.
965 * Category: Statements
966 * Type: Function
967 * Operands: uint32_t funcIndex
968 * Stack: => obj
969 */ \
970 macro(JSOP_LAMBDA, 130, "lambda", NULL, 5, 0, 1, JOF_OBJECT) \
971 /*
972 * Pops the top of stack value as 'this', pushes an arrow function with
973 * 'this' onto the stack.
974 * Category: Statements
975 * Type: Function
976 * Operands: uint32_t funcIndex
977 * Stack: this => obj
978 */ \
979 macro(JSOP_LAMBDA_ARROW, 131, "lambda_arrow", NULL, 5, 1, 1, JOF_OBJECT) \
980 \
981 /*
982 * Pushes current callee onto the stack.
983 *
984 * Used for named function expression self-naming, if lightweight.
985 * Category: Variables and Scopes
986 * Type: Arguments
987 * Operands:
988 * Stack: => callee
989 */ \
990 macro(JSOP_CALLEE, 132, "callee", NULL, 1, 0, 1, JOF_BYTE) \
991 \
992 /*
993 * Picks the nth element from the stack and moves it to the top of the
994 * stack.
995 * Category: Operator
996 * Type: Stack Operations
997 * Operands: uint8_t n
998 * Stack: v[n], v[n-1], ..., v[1], v[0] => v[n-1], ..., v[1], v[0], v[n]
999 */ \
1000 macro(JSOP_PICK, 133, "pick", NULL, 2, 0, 0, JOF_UINT8|JOF_TMPSLOT2) \
1001 \
1002 /*
1003 * Exception handling no-op, for more economical byte-coding than SRC_TRYFIN
1004 * srcnote-annotated JSOP_NOPs and to simply stack balance handling.
1005 */ \
1006 macro(JSOP_TRY, 134,"try", NULL, 1, 0, 0, JOF_BYTE) \
1007 macro(JSOP_FINALLY, 135,"finally", NULL, 1, 0, 2, JOF_BYTE) \
1008 \
1009 /*
1010 * Pushes aliased variable onto the stack.
1011 *
1012 * An "aliased variable" is a var, let, or formal arg that is aliased.
1013 * Sources of aliasing include: nested functions accessing the vars of an
1014 * enclosing function, function statements that are conditionally executed,
1015 * 'eval', 'with', and 'arguments'. All of these cases require creating a
1016 * CallObject to own the aliased variable.
1017 *
1018 * An ALIASEDVAR opcode contains the following immediates:
1019 * uint8 hops: the number of scope objects to skip to find the ScopeObject
1020 * containing the variable being accessed
1021 * uint24 slot: the slot containing the variable in the ScopeObject (this
1022 * 'slot' does not include RESERVED_SLOTS).
1023 * Category: Variables and Scopes
1024 * Type: Aliased Variables
1025 * Operands: uint8_t hops, uint24_t slot
1026 * Stack: => aliasedVar
1027 */ \
1028 macro(JSOP_GETALIASEDVAR, 136,"getaliasedvar",NULL, 5, 0, 1, JOF_SCOPECOORD|JOF_NAME|JOF_TYPESET) \
1029 /*
1030 * Sets aliased variable as the top of stack value.
1031 * Category: Variables and Scopes
1032 * Type: Aliased Variables
1033 * Operands: uint8_t hops, uint24_t slot
1034 * Stack: v => v
1035 */ \
1036 macro(JSOP_SETALIASEDVAR, 137,"setaliasedvar",NULL, 5, 1, 1, JOF_SCOPECOORD|JOF_NAME|JOF_SET|JOF_DETECTING) \
1037 \
1038 macro(JSOP_UNUSED138, 138, "unused138", NULL, 1, 0, 0, JOF_BYTE) \
1039 macro(JSOP_UNUSED139, 139, "unused139", NULL, 1, 0, 0, JOF_BYTE) \
1040 macro(JSOP_UNUSED140, 140, "unused140", NULL, 1, 0, 0, JOF_BYTE) \
1041 macro(JSOP_UNUSED141, 141, "unused141", NULL, 1, 0, 0, JOF_BYTE) \
1042 macro(JSOP_UNUSED142, 142, "unused142", NULL, 1, 0, 0, JOF_BYTE) \
1043 \
1044 /*
1045 * Pushes the value of the intrinsic onto the stack.
1046 *
1047 * Intrinsic names are emitted instead of JSOP_*NAME ops when the
1048 * 'CompileOptions' flag 'selfHostingMode' is set.
1049 *
1050 * They are used in self-hosted code to access other self-hosted values and
1051 * intrinsic functions the runtime doesn't give client JS code access to.
1052 * Category: Variables and Scopes
1053 * Type: Intrinsics
1054 * Operands: uint32_t nameIndex
1055 * Stack: => intrinsic[name]
1056 */ \
1057 macro(JSOP_GETINTRINSIC, 143, "getintrinsic", NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_TYPESET) \
1058 /*
1059 * Pops the top two values on the stack as 'val' and 'scope', sets intrinsic
1060 * as 'val', and pushes 'val' onto the stack.
1061 *
1062 * 'scope' is not used.
1063 * Category: Variables and Scopes
1064 * Type: Intrinsics
1065 * Operands: uint32_t nameIndex
1066 * Stack: scope, val => val
1067 */ \
1068 macro(JSOP_SETINTRINSIC, 144, "setintrinsic", NULL, 5, 2, 1, JOF_ATOM|JOF_NAME|JOF_SET|JOF_DETECTING) \
1069 /*
1070 * Pushes 'intrinsicHolder' onto the stack.
1071 * Category: Variables and Scopes
1072 * Type: Intrinsics
1073 * Operands: uint32_t nameIndex
1074 * Stack: => intrinsicHolder
1075 */ \
1076 macro(JSOP_BINDINTRINSIC, 145, "bindintrinsic", NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_SET) \
1077 \
1078 /* Unused. */ \
1079 macro(JSOP_UNUSED146, 146,"unused146", NULL, 1, 0, 0, JOF_BYTE) \
1080 macro(JSOP_UNUSED147, 147,"unused147", NULL, 1, 0, 0, JOF_BYTE) \
1081 macro(JSOP_UNUSED148, 148,"unused148", NULL, 1, 0, 0, JOF_BYTE) \
1082 \
1083 /* Placeholders for a real jump opcode set during backpatch chain fixup. */ \
1084 macro(JSOP_BACKPATCH, 149,"backpatch", NULL, 5, 0, 0, JOF_JUMP) \
1085 macro(JSOP_UNUSED150, 150,"unused150", NULL, 1, 0, 0, JOF_BYTE) \
1086 \
1087 /* Set pending exception from the stack, to trigger rethrow. */ \
1088 macro(JSOP_THROWING, 151,"throwing", NULL, 1, 1, 0, JOF_BYTE) \
1089 \
1090 /*
1091 * Pops the top of stack value as 'rval', sets the return value in stack
1092 * frame as 'rval'.
1093 * Category: Statements
1094 * Type: Function
1095 * Operands:
1096 * Stack: rval =>
1097 */ \
1098 macro(JSOP_SETRVAL, 152,"setrval", NULL, 1, 1, 0, JOF_BYTE) \
1099 /*
1100 * Stops interpretation and returns value set by JSOP_SETRVAL. When not set,
1101 * returns 'undefined'.
1102 *
1103 * Also emitted at end of script so interpreter don't need to check if
1104 * opcode is still in script range.
1105 * Category: Statements
1106 * Type: Function
1107 * Operands:
1108 * Stack: =>
1109 */ \
1110 macro(JSOP_RETRVAL, 153,"retrval", NULL, 1, 0, 0, JOF_BYTE) \
1111 \
1112 /*
1113 * Looks up name on global scope and pushes its value onto the stack.
1114 *
1115 * Free variable references that must either be found on the global or a
1116 * ReferenceError.
1117 * Category: Variables and Scopes
1118 * Type: Free Variables
1119 * Operands: uint32_t nameIndex
1120 * Stack: => val
1121 */ \
1122 macro(JSOP_GETGNAME, 154,"getgname", NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_TYPESET|JOF_GNAME) \
1123 /*
1124 * Pops the top two values on the stack as 'val' and 'scope', sets property
1125 * of 'scope' as 'val' and pushes 'val' back on the stack.
1126 *
1127 * 'scope' should be the global scope.
1128 * Category: Variables and Scopes
1129 * Type: Free Variables
1130 * Operands: uint32_t nameIndex
1131 * Stack: scope, val => val
1132 */ \
1133 macro(JSOP_SETGNAME, 155,"setgname", NULL, 5, 2, 1, JOF_ATOM|JOF_NAME|JOF_SET|JOF_DETECTING|JOF_GNAME) \
1134 \
1135 macro(JSOP_UNUSED156, 156, "unused156", NULL, 1, 0, 0, JOF_BYTE) \
1136 macro(JSOP_UNUSED157, 157, "unused157", NULL, 1, 0, 0, JOF_BYTE) \
1137 macro(JSOP_UNUSED158, 158, "unused158", NULL, 1, 0, 0, JOF_BYTE) \
1138 macro(JSOP_UNUSED159, 159, "unused159", NULL, 1, 0, 0, JOF_BYTE) \
1139 \
1140 /*
1141 * Pushes a regular expression literal onto the stack.
1142 * It requires special "clone on exec" handling.
1143 * Category: Literals
1144 * Type: RegExp
1145 * Operands: uint32_t regexpIndex
1146 * Stack: => regexp
1147 */ \
1148 macro(JSOP_REGEXP, 160,"regexp", NULL, 5, 0, 1, JOF_REGEXP) \
1149 \
1150 macro(JSOP_UNUSED161, 161,"unused161", NULL, 1, 0, 0, JOF_BYTE) \
1151 macro(JSOP_UNUSED162, 162,"unused162", NULL, 1, 0, 0, JOF_BYTE) \
1152 macro(JSOP_UNUSED163, 163,"unused163", NULL, 1, 0, 0, JOF_BYTE) \
1153 macro(JSOP_UNUSED164, 164,"unused164", NULL, 1, 0, 0, JOF_BYTE) \
1154 macro(JSOP_UNUSED165, 165,"unused165", NULL, 1, 0, 0, JOF_BYTE) \
1155 macro(JSOP_UNUSED166, 166,"unused166", NULL, 1, 0, 0, JOF_BYTE) \
1156 macro(JSOP_UNUSED167, 167,"unused167", NULL, 1, 0, 0, JOF_BYTE) \
1157 macro(JSOP_UNUSED168, 168,"unused168", NULL, 1, 0, 0, JOF_BYTE) \
1158 macro(JSOP_UNUSED169, 169,"unused169", NULL, 1, 0, 0, JOF_BYTE) \
1159 macro(JSOP_UNUSED170, 170,"unused170", NULL, 1, 0, 0, JOF_BYTE) \
1160 macro(JSOP_UNUSED171, 171,"unused171", NULL, 1, 0, 0, JOF_BYTE) \
1161 macro(JSOP_UNUSED172, 172,"unused172", NULL, 1, 0, 0, JOF_BYTE) \
1162 macro(JSOP_UNUSED173, 173,"unused173", NULL, 1, 0, 0, JOF_BYTE) \
1163 macro(JSOP_UNUSED174, 174,"unused174", NULL, 1, 0, 0, JOF_BYTE) \
1164 macro(JSOP_UNUSED175, 175,"unused175", NULL, 1, 0, 0, JOF_BYTE) \
1165 macro(JSOP_UNUSED176, 176,"unused176", NULL, 1, 0, 0, JOF_BYTE) \
1166 macro(JSOP_UNUSED177, 177,"unused177", NULL, 1, 0, 0, JOF_BYTE) \
1167 macro(JSOP_UNUSED178, 178,"unused178", NULL, 1, 0, 0, JOF_BYTE) \
1168 macro(JSOP_UNUSED179, 179,"unused179", NULL, 1, 0, 0, JOF_BYTE) \
1169 macro(JSOP_UNUSED180, 180,"unused180", NULL, 1, 0, 0, JOF_BYTE) \
1170 macro(JSOP_UNUSED181, 181,"unused181", NULL, 1, 0, 0, JOF_BYTE) \
1171 macro(JSOP_UNUSED182, 182,"unused182", NULL, 1, 0, 0, JOF_BYTE) \
1172 macro(JSOP_UNUSED183, 183,"unused183", NULL, 1, 0, 0, JOF_BYTE) \
1173 \
1174 /*
1175 * Pops the top of stack value, pushes property of it onto the stack.
1176 *
1177 * Like JSOP_GETPROP but for call context.
1178 * Category: Literals
1179 * Type: Object
1180 * Operands: uint32_t nameIndex
1181 * Stack: obj => obj[name]
1182 */ \
1183 macro(JSOP_CALLPROP, 184,"callprop", NULL, 5, 1, 1, JOF_ATOM|JOF_PROP|JOF_TYPESET|JOF_TMPSLOT3) \
1184 \
1185 macro(JSOP_UNUSED185, 185,"unused185", NULL, 1, 0, 0, JOF_BYTE) \
1186 macro(JSOP_UNUSED186, 186,"unused186", NULL, 1, 0, 0, JOF_BYTE) \
1187 macro(JSOP_UNUSED187, 187,"unused187", NULL, 1, 0, 0, JOF_BYTE) \
1188 \
1189 /*
1190 * Pushes unsigned 24-bit int immediate integer operand onto the stack.
1191 * Category: Literals
1192 * Type: Constants
1193 * Operands: uint24_t val
1194 * Stack: => val
1195 */ \
1196 macro(JSOP_UINT24, 188,"uint24", NULL, 4, 0, 1, JOF_UINT24) \
1197 \
1198 macro(JSOP_UNUSED189, 189,"unused189", NULL, 1, 0, 0, JOF_BYTE) \
1199 macro(JSOP_UNUSED190, 190,"unused190", NULL, 1, 0, 0, JOF_BYTE) \
1200 macro(JSOP_UNUSED191, 191,"unused191", NULL, 1, 0, 0, JOF_BYTE) \
1201 macro(JSOP_UNUSED192, 192,"unused192", NULL, 1, 0, 0, JOF_BYTE) \
1202 \
1203 /*
1204 * Pops the top two values on the stack as 'propval' and 'obj', pushes
1205 * 'propval' property of 'obj' onto the stack.
1206 *
1207 * Like JSOP_GETELEM but for call context.
1208 * Category: Literals
1209 * Type: Object
1210 * Operands:
1211 * Stack: obj, propval => obj[propval]
1212 */ \
1213 macro(JSOP_CALLELEM, 193, "callelem", NULL, 1, 2, 1, JOF_BYTE |JOF_ELEM|JOF_TYPESET|JOF_LEFTASSOC) \
1214 \
1215 /*
1216 * '__proto__: v' inside an object initializer.
1217 *
1218 * Pops the top two values on the stack as 'newProto' and 'obj', sets
1219 * prototype of 'obj' as 'newProto', pushes 'true' onto the stack if
1220 * succeeded, 'false' if not.
1221 * Category: Literals
1222 * Type: Object
1223 * Operands:
1224 * Stack: obj, newProto => succeeded
1225 */ \
1226 macro(JSOP_MUTATEPROTO, 194, "mutateproto",NULL, 1, 2, 1, JOF_BYTE) \
1227 \
1228 /*
1229 * Pops the top of stack value, gets an extant property value of it,
1230 * throwing ReferenceError if the identified property does not exist.
1231 * Category: Literals
1232 * Type: Object
1233 * Operands: uint32_t nameIndex
1234 * Stack: obj => obj[name]
1235 */ \
1236 macro(JSOP_GETXPROP, 195,"getxprop", NULL, 5, 1, 1, JOF_ATOM|JOF_PROP|JOF_TYPESET) \
1237 \
1238 macro(JSOP_UNUSED196, 196,"unused196", NULL, 1, 0, 0, JOF_BYTE) \
1239 \
1240 /*
1241 * Pops the top stack value as 'val' and pushes 'typeof val'. Note that
1242 * this opcode isn't used when, in the original source code, 'val' is a
1243 * name -- see 'JSOP_TYPEOF' for that.
1244 * (This is because 'typeof undefinedName === "undefined"'.)
1245 * Category: Operator
1246 * Type: Special Operators
1247 * Operands:
1248 * Stack: val => (typeof val)
1249 */ \
1250 macro(JSOP_TYPEOFEXPR, 197,"typeofexpr", NULL, 1, 1, 1, JOF_BYTE|JOF_DETECTING) \
1251 \
1252 /* Block-local scope support. */ \
1253 /*
1254 * Pushes block onto the scope chain.
1255 * Category: Variables and Scopes
1256 * Type: Block-local Scope
1257 * Operands: uint32_t staticBlockObjectIndex
1258 * Stack: =>
1259 */ \
1260 macro(JSOP_PUSHBLOCKSCOPE,198,"pushblockscope", NULL, 5, 0, 0, JOF_OBJECT) \
1261 /*
1262 * Pops block from the scope chain.
1263 * Category: Variables and Scopes
1264 * Type: Block-local Scope
1265 * Operands:
1266 * Stack: =>
1267 */ \
1268 macro(JSOP_POPBLOCKSCOPE, 199,"popblockscope", NULL, 1, 0, 0, JOF_BYTE) \
1269 /*
1270 * The opcode to assist the debugger.
1271 * Category: Statements
1272 * Type: Debugger
1273 * Operands:
1274 * Stack: =>
1275 */ \
1276 macro(JSOP_DEBUGLEAVEBLOCK, 200,"debugleaveblock", NULL, 1, 0, 0, JOF_BYTE) \
1277 \
1278 macro(JSOP_UNUSED201, 201,"unused201", NULL, 1, 0, 0, JOF_BYTE) \
1279 \
1280 /*
1281 * Initializes generator frame, creates a generator, sets 'YIELDING' flag,
1282 * stops interpretation and returns the generator.
1283 * Category: Statements
1284 * Type: Generator
1285 * Operands:
1286 * Stack: =>
1287 */ \
1288 macro(JSOP_GENERATOR, 202,"generator", NULL, 1, 0, 0, JOF_BYTE) \
1289 /*
1290 * Pops the top of stack value as 'rval1', sets 'YIELDING' flag,
1291 * stops interpretation and returns 'rval1', pushes sent value from
1292 * 'send()' onto the stack.
1293 * Category: Statements
1294 * Type: Generator
1295 * Operands:
1296 * Stack: rval1 => rval2
1297 */ \
1298 macro(JSOP_YIELD, 203,"yield", NULL, 1, 1, 1, JOF_BYTE) \
1299 /*
1300 * Pops the top two values on the stack as 'obj' and 'v', pushes 'v' to
1301 * 'obj'.
1302 *
1303 * This opcode is used for Array Comprehension.
1304 * Category: Literals
1305 * Type: Array
1306 * Operands:
1307 * Stack: v, obj =>
1308 */ \
1309 macro(JSOP_ARRAYPUSH, 204,"arraypush", NULL, 1, 2, 0, JOF_BYTE) \
1310 \
1311 macro(JSOP_UNUSED205, 205, "unused205", NULL, 1, 0, 0, JOF_BYTE) \
1312 macro(JSOP_UNUSED206, 206, "unused206", NULL, 1, 0, 0, JOF_BYTE) \
1313 \
1314 macro(JSOP_UNUSED207, 207, "unused207", NULL, 1, 0, 0, JOF_BYTE) \
1315 macro(JSOP_UNUSED208, 208, "unused208", NULL, 1, 0, 0, JOF_BYTE) \
1316 macro(JSOP_UNUSED209, 209, "unused209", NULL, 1, 0, 0, JOF_BYTE) \
1317 macro(JSOP_UNUSED210, 210, "unused210", NULL, 1, 0, 0, JOF_BYTE) \
1318 macro(JSOP_UNUSED211, 211, "unused211", NULL, 1, 0, 0, JOF_BYTE) \
1319 macro(JSOP_UNUSED212, 212, "unused212", NULL, 1, 0, 0, JOF_BYTE) \
1320 macro(JSOP_UNUSED213, 213, "unused213", NULL, 1, 0, 0, JOF_BYTE) \
1321 /*
1322 * Pushes the global scope onto the stack.
1323 *
1324 * 'nameIndex' is not used.
1325 * Category: Variables and Scopes
1326 * Type: Free Variables
1327 * Operands: uint32_t nameIndex
1328 * Stack: => global
1329 */ \
1330 macro(JSOP_BINDGNAME, 214, "bindgname", NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_SET|JOF_GNAME) \
1331 \
1332 /*
1333 * Pushes 8-bit int immediate integer operand onto the stack.
1334 * Category: Literals
1335 * Type: Constants
1336 * Operands: int8_t val
1337 * Stack: => val
1338 */ \
1339 macro(JSOP_INT8, 215, "int8", NULL, 2, 0, 1, JOF_INT8) \
1340 /*
1341 * Pushes 32-bit int immediate integer operand onto the stack.
1342 * Category: Literals
1343 * Type: Constants
1344 * Operands: int32_t val
1345 * Stack: => val
1346 */ \
1347 macro(JSOP_INT32, 216, "int32", NULL, 5, 0, 1, JOF_INT32) \
1348 \
1349 /*
1350 * Pops the top of stack value, pushes the 'length' property of it onto the
1351 * stack.
1352 * Category: Literals
1353 * Type: Array
1354 * Operands: uint32_t nameIndex
1355 * Stack: obj => obj['length']
1356 */ \
1357 macro(JSOP_LENGTH, 217, "length", NULL, 5, 1, 1, JOF_ATOM|JOF_PROP|JOF_TYPESET|JOF_TMPSLOT3) \
1358 \
1359 /*
1360 * Pushes a JS_ELEMENTS_HOLE value onto the stack, representing an omitted
1361 * property in an array literal (e.g. property 0 in the array '[, 1]').
1362 *
1363 * This opcode is used with the JSOP_NEWARRAY opcode.
1364 * Category: Literals
1365 * Type: Array
1366 * Operands:
1367 * Stack: => hole
1368 */ \
1369 macro(JSOP_HOLE, 218, "hole", NULL, 1, 0, 1, JOF_BYTE) \
1370 \
1371 macro(JSOP_UNUSED219, 219,"unused219", NULL, 1, 0, 0, JOF_BYTE) \
1372 macro(JSOP_UNUSED220, 220,"unused220", NULL, 1, 0, 0, JOF_BYTE) \
1373 macro(JSOP_UNUSED221, 221,"unused221", NULL, 1, 0, 0, JOF_BYTE) \
1374 macro(JSOP_UNUSED222, 222,"unused222", NULL, 1, 0, 0, JOF_BYTE) \
1375 macro(JSOP_UNUSED223, 223,"unused223", NULL, 1, 0, 0, JOF_BYTE) \
1376 \
1377 /*
1378 * Creates rest parameter array for current function call, and pushes it
1379 * onto the stack.
1380 * Category: Variables and Scopes
1381 * Type: Arguments
1382 * Operands:
1383 * Stack: => rest
1384 */ \
1385 macro(JSOP_REST, 224, "rest", NULL, 1, 0, 1, JOF_BYTE|JOF_TYPESET) \
1386 \
1387 /*
1388 * Pops the top of stack value, converts it into a jsid (int or string), and
1389 * pushes it onto the stack.
1390 * Category: Literals
1391 * Type: Object
1392 * Operands:
1393 * Stack: obj, id => obj, (jsid of id)
1394 */ \
1395 macro(JSOP_TOID, 225, "toid", NULL, 1, 1, 1, JOF_BYTE) \
1396 \
1397 /*
1398 * Pushes the implicit 'this' value for calls to the associated name onto
1399 * the stack.
1400 * Category: Variables and Scopes
1401 * Type: This
1402 * Operands: uint32_t nameIndex
1403 * Stack: => this
1404 */ \
1405 macro(JSOP_IMPLICITTHIS, 226, "implicitthis", "", 5, 0, 1, JOF_ATOM) \
1406 \
1407 /*
1408 * This opcode is the target of the entry jump for some loop. The uint8
1409 * argument is a bitfield. The lower 7 bits of the argument indicate the
1410 * loop depth. This value starts at 1 and is just a hint: deeply nested
1411 * loops all have the same value. The upper bit is set if Ion should be
1412 * able to OSR at this point, which is true unless there is non-loop state
1413 * on the stack.
1414 */ \
1415 macro(JSOP_LOOPENTRY, 227, "loopentry", NULL, 2, 0, 0, JOF_UINT8)
1416
1417 /*
1418 * In certain circumstances it may be useful to "pad out" the opcode space to
1419 * a power of two. Use this macro to do so.
1420 */
1421 #define FOR_EACH_TRAILING_UNUSED_OPCODE(macro) \
1422 macro(228) \
1423 macro(229) \
1424 macro(230) \
1425 macro(231) \
1426 macro(232) \
1427 macro(233) \
1428 macro(234) \
1429 macro(235) \
1430 macro(236) \
1431 macro(237) \
1432 macro(238) \
1433 macro(239) \
1434 macro(240) \
1435 macro(241) \
1436 macro(242) \
1437 macro(243) \
1438 macro(244) \
1439 macro(245) \
1440 macro(246) \
1441 macro(247) \
1442 macro(248) \
1443 macro(249) \
1444 macro(250) \
1445 macro(251) \
1446 macro(252) \
1447 macro(253) \
1448 macro(254) \
1449 macro(255)
1450
1451 namespace js {
1452
1453 // Sanity check that opcode values and trailing unused opcodes completely cover
1454 // the [0, 256) range. Avert your eyes! You don't want to know how the
1455 // sausage gets made.
1456
1457 #define VALUE_AND_VALUE_PLUS_ONE(op, val, ...) \
1458 val) && (val + 1 ==
1459 #define TRAILING_VALUE_AND_VALUE_PLUS_ONE(val) \
1460 val) && (val + 1 ==
1461 static_assert((0 ==
1462 FOR_EACH_OPCODE(VALUE_AND_VALUE_PLUS_ONE)
1463 FOR_EACH_TRAILING_UNUSED_OPCODE(TRAILING_VALUE_AND_VALUE_PLUS_ONE)
1464 256),
1465 "opcode values and trailing unused opcode values monotonically "
1466 "increase from zero to 255");
1467 #undef TRAILING_VALUE_AND_VALUE_PLUS_ONE
1468 #undef VALUE_AND_VALUE_PLUS_ONE
1469
1470 // Define JSOP_*_LENGTH constants for all ops.
1471 #define DEFINE_LENGTH_CONSTANT(op, val, name, image, len, ...) \
1472 MOZ_CONSTEXPR_VAR size_t op##_LENGTH = len;
1473 FOR_EACH_OPCODE(DEFINE_LENGTH_CONSTANT)
1474 #undef DEFINE_LENGTH_CONSTANT
1475
1476 } // namespace js
1477
1478 #endif // vm_Opcodes_h

mercurial