1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=78:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla Communicator client code, released
20 * The Initial Developer of the Original Code is
21 * Netscape Communications Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 1998
23 * the Initial Developer. All Rights Reserved.
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
44 * JS parser definitions.
46 #include "jsversion.h"
55 * Parsing builds a tree of nodes that directs code generation. This tree is
56 * not a concrete syntax tree in all respects (for example, || and && are left
57 * associative, but (A && B && C) translates into the right-associated tree
58 * <A && <B && C>> so that code generation can emit a left-associative branch
59 * around <B && C> when A is false). Nodes are labeled by token type, with a
60 * JSOp secondary label when needed:
62 * Label Variant Members
63 * ----- ------- -------
65 * TOK_FUNCTION name pn_funbox: ptr to JSFunctionBox holding function
66 * object containing arg and var properties. We
67 * create the function object at parse (not emit)
68 * time to specialize arg and var bytecodes early.
69 * pn_body: TOK_UPVARS if the function's source body
70 * depends on outer names, else TOK_ARGSBODY
71 * if formal parameters, else TOK_LC node for
72 * function body statements, else TOK_RETURN
73 * for expression closure, else TOK_SEQ for
74 * expression closure with destructured
76 * pn_cookie: static level and var index for function
77 * pn_dflags: PND_* definition/use flags (see below)
78 * pn_blockid: block id number
79 * TOK_ARGSBODY list list of formal parameters followed by TOK_LC node
80 * for function body statements as final element
81 * pn_count: 1 + number of formal parameters
82 * TOK_UPVARS nameset pn_names: lexical dependencies (JSDefinitions)
83 * defined in enclosing scopes, or ultimately not
84 * defined (free variables, either global property
85 * references or reference errors).
86 * pn_tree: TOK_ARGSBODY or TOK_LC node
89 * TOK_LC list pn_head: list of pn_count statements
90 * TOK_IF ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else or null.
91 * In body of a comprehension or desugared generator
92 * expression, pn_kid2 is TOK_YIELD, TOK_ARRAYPUSH,
93 * or (if the push was optimized away) empty TOK_LC.
94 * TOK_SWITCH binary pn_left: discriminant
95 * pn_right: list of TOK_CASE nodes, with at most one
96 * TOK_DEFAULT node, or if there are let bindings
97 * in the top level of the switch body's cases, a
98 * TOK_LEXICALSCOPE node that contains the list of
100 * TOK_CASE, binary pn_left: case expr or null if TOK_DEFAULT
101 * TOK_DEFAULT pn_right: TOK_LC node for this case's statements
102 * pn_val: constant value if lookup or table switch
103 * TOK_WHILE binary pn_left: cond, pn_right: body
104 * TOK_DO binary pn_left: body, pn_right: cond
105 * TOK_FOR binary pn_left: either
106 * for/in loop: a binary TOK_IN node with
107 * pn_left: TOK_VAR or TOK_NAME to left of 'in'
108 * if TOK_VAR, its pn_xflags may have PNX_POPVAR
109 * and PNX_FORINVAR bits set
110 * pn_right: object expr to right of 'in'
111 * for(;;) loop: a ternary TOK_RESERVED node with
112 * pn_kid1: init expr before first ';'
113 * pn_kid2: cond expr before second ';'
114 * pn_kid3: update expr after second ';'
115 * any kid may be null
117 * TOK_THROW unary pn_op: JSOP_THROW, pn_kid: exception
118 * TOK_TRY ternary pn_kid1: try block
119 * pn_kid2: null or TOK_RESERVED list of
120 * TOK_LEXICALSCOPE nodes, each with pn_expr pointing
121 * to a TOK_CATCH node
122 * pn_kid3: null or finally block
123 * TOK_CATCH ternary pn_kid1: TOK_NAME, TOK_RB, or TOK_RC catch var node
124 * (TOK_RB or TOK_RC if destructuring)
125 * pn_kid2: null or the catch guard expression
126 * pn_kid3: catch block statements
127 * TOK_BREAK name pn_atom: label or null
128 * TOK_CONTINUE name pn_atom: label or null
129 * TOK_WITH binary pn_left: head expr, pn_right: body
130 * TOK_VAR list pn_head: list of TOK_NAME or TOK_ASSIGN nodes
133 * pn_atom: variable name
134 * pn_expr: initializer or null
135 * each assignment node has
136 * pn_left: TOK_NAME with pn_used true and
137 * pn_lexdef (NOT pn_expr) set
138 * pn_right: initializer
139 * TOK_RETURN unary pn_kid: return expr or null
140 * TOK_SEMI unary pn_kid: expr or null statement
141 * pn_prologue: true if Directive Prologue member
142 * in original source, not introduced via
143 * constant folding or other tree rewriting
144 * TOK_COLON name pn_atom: label, pn_expr: labeled statement
147 * All left-associated binary trees of the same type are optimized into lists
148 * to avoid recursion when processing expression chains.
149 * TOK_COMMA list pn_head: list of pn_count comma-separated exprs
150 * TOK_ASSIGN binary pn_left: lvalue, pn_right: rvalue
151 * pn_op: JSOP_ADD for +=, etc.
152 * TOK_HOOK ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else
153 * TOK_OR binary pn_left: first in || chain, pn_right: rest of chain
154 * TOK_AND binary pn_left: first in && chain, pn_right: rest of chain
155 * TOK_BITOR binary pn_left: left-assoc | expr, pn_right: ^ expr
156 * TOK_BITXOR binary pn_left: left-assoc ^ expr, pn_right: & expr
157 * TOK_BITAND binary pn_left: left-assoc & expr, pn_right: EQ expr
158 * TOK_EQOP binary pn_left: left-assoc EQ expr, pn_right: REL expr
159 * pn_op: JSOP_EQ, JSOP_NE,
160 * JSOP_STRICTEQ, JSOP_STRICTNE
161 * TOK_RELOP binary pn_left: left-assoc REL expr, pn_right: SH expr
162 * pn_op: JSOP_LT, JSOP_LE, JSOP_GT, JSOP_GE
163 * TOK_SHOP binary pn_left: left-assoc SH expr, pn_right: ADD expr
164 * pn_op: JSOP_LSH, JSOP_RSH, JSOP_URSH
165 * TOK_PLUS, binary pn_left: left-assoc ADD expr, pn_right: MUL expr
166 * pn_xflags: if a left-associated binary TOK_PLUS
167 * tree has been flattened into a list (see above
168 * under <Expressions>), pn_xflags will contain
169 * PNX_STRCAT if at least one list element is a
170 * string literal (TOK_STRING); if such a list has
171 * any non-string, non-number term, pn_xflags will
172 * contain PNX_CANTFOLD.
174 * TOK_MINUS pn_op: JSOP_ADD, JSOP_SUB
175 * TOK_STAR, binary pn_left: left-assoc MUL expr, pn_right: UNARY expr
176 * TOK_DIVOP pn_op: JSOP_MUL, JSOP_DIV, JSOP_MOD
177 * TOK_UNARYOP unary pn_kid: UNARY expr, pn_op: JSOP_NEG, JSOP_POS,
178 * JSOP_NOT, JSOP_BITNOT, JSOP_TYPEOF, JSOP_VOID
179 * TOK_INC, unary pn_kid: MEMBER expr
181 * TOK_NEW list pn_head: list of ctor, arg1, arg2, ... argN
182 * pn_count: 1 + N (where N is number of args)
183 * ctor is a MEMBER expr
184 * TOK_DELETE unary pn_kid: MEMBER expr
185 * TOK_DOT, name pn_expr: MEMBER expr to left of .
186 * TOK_DBLDOT pn_atom: name to right of .
187 * TOK_LB binary pn_left: MEMBER expr to left of [
188 * pn_right: expr between [ and ]
189 * TOK_LP list pn_head: list of call, arg1, arg2, ... argN
190 * pn_count: 1 + N (where N is number of args)
191 * call is a MEMBER expr naming a callable object
192 * TOK_RB list pn_head: list of pn_count array element exprs
193 * [,,] holes are represented by TOK_COMMA nodes
194 * pn_xflags: PN_ENDCOMMA if extra comma at end
195 * TOK_RC list pn_head: list of pn_count binary TOK_COLON nodes
196 * TOK_COLON binary key-value pair in object initializer or
198 * pn_left: property id, pn_right: value
199 * var {x} = object destructuring shorthand shares
200 * PN_NAME node for x on left and right of TOK_COLON
201 * node in TOK_RC's list, has PNX_DESTRUCT flag
202 * TOK_DEFSHARP unary pn_num: jsint value of n in #n=
203 * pn_kid: primary function, paren, name, object or
204 * array literal expressions
205 * TOK_USESHARP nullary pn_num: jsint value of n in #n#
206 * TOK_NAME, name pn_atom: name, string, or object atom
207 * TOK_STRING, pn_op: JSOP_NAME, JSOP_STRING, or JSOP_OBJECT, or
209 * TOK_REGEXP If JSOP_NAME, pn_op may be JSOP_*ARG or JSOP_*VAR
210 * with pn_cookie telling (staticLevel, slot) (see
211 * jsscript.h's UPVAR macros) and pn_dflags telling
212 * const-ness and static analysis results
213 * TOK_NAME name If pn_used, TOK_NAME uses the lexdef member instead
214 * of the expr member it overlays
215 * TOK_NUMBER dval pn_dval: double value of numeric literal
216 * TOK_PRIMARY nullary pn_op: JSOp bytecode
218 * <E4X node descriptions>
219 * TOK_DEFAULT name pn_atom: default XML namespace string literal
220 * TOK_FILTER binary pn_left: container expr, pn_right: filter expr
221 * TOK_DBLDOT binary pn_left: container expr, pn_right: selector expr
222 * TOK_ANYNAME nullary pn_op: JSOP_ANYNAME
223 * pn_atom: cx->runtime->atomState.starAtom
224 * TOK_AT unary pn_op: JSOP_TOATTRNAME; pn_kid attribute id/expr
225 * TOK_DBLCOLON binary pn_op: JSOP_QNAME
226 * pn_left: TOK_ANYNAME or TOK_NAME node
227 * pn_right: TOK_STRING "*" node, or expr within []
228 * name pn_op: JSOP_QNAMECONST
229 * pn_expr: TOK_ANYNAME or TOK_NAME left operand
230 * pn_atom: name on right of ::
231 * TOK_XMLELEM list XML element node
232 * pn_head: start tag, content1, ... contentN, end tag
233 * pn_count: 2 + N where N is number of content nodes
234 * N may be > x.length() if {expr} embedded
235 * After constant folding, these contents may be
236 * concatenated into string nodes.
237 * TOK_XMLLIST list XML list node
238 * pn_head: content1, ... contentN
239 * TOK_XMLSTAGO, list XML start, end, and point tag contents
240 * TOK_XMLETAGO, pn_head: tag name or {expr}, ... XML attrs ...
242 * TOK_XMLNAME nullary pn_atom: XML name, with no {expr} embedded
243 * TOK_XMLNAME list pn_head: tag name or {expr}, ... name or {expr}
244 * TOK_XMLATTR, nullary pn_atom: attribute value string; pn_op: JSOP_STRING
247 * TOK_XMLPI nullary pn_atom: XML processing instruction target
248 * pn_atom2: XML PI content, or null if no content
249 * TOK_XMLTEXT nullary pn_atom: marked-up text, or null if empty string
250 * TOK_LC unary {expr} in XML tag or content; pn_kid is expr
252 * So an XML tag with no {expr} and three attributes is a list with the form:
254 * (tagname attrname1 attrvalue1 attrname2 attrvalue2 attrname2 attrvalue3)
256 * An XML tag with embedded expressions like so:
258 * <name1{expr1} name2{expr2}name3={expr3}>
260 * would have the form:
262 * ((name1 {expr1}) (name2 {expr2} name3) {expr3})
264 * where () bracket a list with elements separated by spaces, and {expr} is a
265 * TOK_LC unary node with expr as its kid.
267 * Thus, the attribute name/value pairs occupy successive odd and even list
268 * locations, where pn_head is the TOK_XMLNAME node at list location 0. The
269 * parser builds the same sort of structures for elements:
271 * <a x={x}>Hi there!<b y={y}>How are you?</b><answer>{x + y}</answer></a>
275 * ((a x {x}) 'Hi there!' ((b y {y}) 'How are you?') ((answer) {x + y}))
277 * <Non-E4X node descriptions, continued>
279 * Label Variant Members
280 * ----- ------- -------
281 * TOK_LEXICALSCOPE name pn_op: JSOP_LEAVEBLOCK or JSOP_LEAVEBLOCKEXPR
282 * pn_objbox: block object in JSObjectBox holder
283 * pn_expr: block body
284 * TOK_ARRAYCOMP list pn_count: 1
285 * pn_head: list of 1 element, which is block
286 * enclosing for loop(s) and optionally
287 * if-guarded TOK_ARRAYPUSH
288 * TOK_ARRAYPUSH unary pn_op: JSOP_ARRAYCOMP
289 * pn_kid: array comprehension expression
291 typedef enum JSParseNodeArity
{
292 PN_NULLARY
, /* 0 kids, only pn_atom/pn_dval/etc. */
293 PN_UNARY
, /* one kid, plus a couple of scalars */
294 PN_BINARY
, /* two kids, plus a couple of scalars */
295 PN_TERNARY
, /* three kids */
296 PN_FUNC
, /* function definition node */
297 PN_LIST
, /* generic singly linked list */
298 PN_NAME
, /* name use or definition node */
299 PN_NAMESET
/* JSAtomList + JSParseNode ptr */
307 GlobalScope(JSContext
*cx
, JSObject
*globalObj
, JSCodeGenerator
*cg
)
308 : globalObj(globalObj
), cg(cg
), defs(ContextAllocPolicy(cx
))
312 JSAtom
*atom
; // If non-NULL, specifies the property name to add.
313 JSFunctionBox
*funbox
; // If non-NULL, function value for the property.
314 // This value is only set/used if atom is non-NULL.
315 uint32 knownSlot
; // If atom is NULL, this is the known shape slot.
318 GlobalDef(uint32 knownSlot
)
319 : atom(NULL
), knownSlot(knownSlot
)
321 GlobalDef(JSAtom
*atom
, JSFunctionBox
*box
) :
322 atom(atom
), funbox(box
)
330 * This is the table of global names encountered during parsing. Each
331 * global name appears in the list only once, and the |names| table
332 * maps back into |defs| for fast lookup.
334 * A definition may either specify an existing global property, or a new
335 * one that must be added after compilation succeeds.
337 Vector
<GlobalDef
, 16, ContextAllocPolicy
> defs
;
344 uint32 pn_type
:16, /* TOK_* type, see jsscan.h */
345 pn_op
:8, /* see JSOp enum and jsopcode.tbl */
346 pn_arity
:5, /* see JSParseNodeArity enum */
347 pn_parens
:1, /* this expr was enclosed in parens */
348 pn_used
:1, /* name node is on a use-chain */
349 pn_defn
:1; /* this node is a JSDefinition */
351 #define PN_OP(pn) ((JSOp)(pn)->pn_op)
352 #define PN_TYPE(pn) ((js::TokenKind)(pn)->pn_type)
354 js::TokenPos pn_pos
; /* two 16-bit pairs here, for 64 bits */
355 int32 pn_offset
; /* first generated bytecode offset */
356 JSParseNode
*pn_next
; /* intrinsic link in parent PN_LIST */
357 JSParseNode
*pn_link
; /* def/use link (alignment freebie);
358 also links JSFunctionBox::methods
359 lists of would-be |this| methods */
361 struct { /* list of next-linked nodes */
362 JSParseNode
*head
; /* first node in list */
363 JSParseNode
**tail
; /* ptr to ptr to last node in list */
364 uint32 count
; /* number of nodes in list */
365 uint32 xflags
:12, /* extra flags, see below */
366 blockid
:20; /* see name variant below */
368 struct { /* ternary: if, for(;;), ?: */
369 JSParseNode
*kid1
; /* condition, discriminant, etc. */
370 JSParseNode
*kid2
; /* then-part, case list, etc. */
371 JSParseNode
*kid3
; /* else-part, default case, etc. */
373 struct { /* two kids if binary */
376 js::Value
*pval
; /* switch case value */
377 uintN iflags
; /* JSITER_* flags for TOK_FOR node */
379 struct { /* one kid if unary */
381 jsint num
; /* -1 or sharp variable number */
382 JSBool hidden
; /* hidden genexp-induced JSOP_YIELD
383 or directive prologue member (as
386 struct { /* name, labeled statement, etc. */
388 JSAtom
*atom
; /* lexical name or label atom */
389 JSFunctionBox
*funbox
; /* function object */
390 JSObjectBox
*objbox
; /* block or regexp object */
393 JSParseNode
*expr
; /* function body, var initializer, or
394 base object of TOK_DOT */
395 JSDefinition
*lexdef
; /* lexical definition for this use */
397 js::UpvarCookie cookie
; /* upvar cookie with absolute frame
398 level (not relative skip), possibly
400 uint32 dflags
:12, /* definition/use flags, see below */
401 blockid
:20; /* block number, for subset dominance
404 struct { /* lexical dependencies + sub-tree */
405 JSAtomSet names
; /* set of names with JSDefinitions */
406 JSParseNode
*tree
; /* sub-tree containing name uses */
408 struct { /* PN_NULLARY variant for E4X */
409 JSAtom
*atom
; /* first atom in pair */
410 JSAtom
*atom2
; /* second atom in pair or null */
412 jsdouble dval
; /* aligned numeric literal value */
415 #define pn_funbox pn_u.name.funbox
416 #define pn_body pn_u.name.expr
417 #define pn_cookie pn_u.name.cookie
418 #define pn_dflags pn_u.name.dflags
419 #define pn_blockid pn_u.name.blockid
420 #define pn_index pn_u.name.blockid /* reuse as object table index */
421 #define pn_head pn_u.list.head
422 #define pn_tail pn_u.list.tail
423 #define pn_count pn_u.list.count
424 #define pn_xflags pn_u.list.xflags
425 #define pn_kid1 pn_u.ternary.kid1
426 #define pn_kid2 pn_u.ternary.kid2
427 #define pn_kid3 pn_u.ternary.kid3
428 #define pn_left pn_u.binary.left
429 #define pn_right pn_u.binary.right
430 #define pn_pval pn_u.binary.pval
431 #define pn_iflags pn_u.binary.iflags
432 #define pn_kid pn_u.unary.kid
433 #define pn_num pn_u.unary.num
434 #define pn_hidden pn_u.unary.hidden
435 #define pn_prologue pn_u.unary.hidden
436 #define pn_atom pn_u.name.atom
437 #define pn_objbox pn_u.name.objbox
438 #define pn_expr pn_u.name.expr
439 #define pn_lexdef pn_u.name.lexdef
440 #define pn_names pn_u.nameset.names
441 #define pn_tree pn_u.nameset.tree
442 #define pn_dval pn_u.dval
443 #define pn_atom2 pn_u.apair.atom2
446 void inline init(js::TokenKind type
, JSOp op
, JSParseNodeArity arity
) {
453 pn_next
= pn_link
= NULL
;
456 static JSParseNode
*create(JSParseNodeArity arity
, JSTreeContext
*tc
);
459 static JSParseNode
*newBinaryOrAppend(js::TokenKind tt
, JSOp op
, JSParseNode
*left
,
460 JSParseNode
*right
, JSTreeContext
*tc
);
463 * The pn_expr and lexdef members are arms of an unsafe union. Unless you
464 * know exactly what you're doing, use only the following methods to access
465 * them. For less overhead and assertions for protection, use pn->expr()
466 * and pn->lexdef(). Otherwise, use pn->maybeExpr() and pn->maybeLexDef().
468 JSParseNode
*expr() const {
470 JS_ASSERT(pn_arity
== PN_NAME
|| pn_arity
== PN_FUNC
);
474 JSDefinition
*lexdef() const {
475 JS_ASSERT(pn_used
|| isDeoptimized());
476 JS_ASSERT(pn_arity
== PN_NAME
);
480 JSParseNode
*maybeExpr() { return pn_used
? NULL
: expr(); }
481 JSDefinition
*maybeLexDef() { return pn_used
? lexdef() : NULL
; }
483 /* PN_FUNC and PN_NAME pn_dflags bits. */
484 #define PND_LET 0x01 /* let (block-scoped) binding */
485 #define PND_CONST 0x02 /* const binding (orthogonal to let) */
486 #define PND_INITIALIZED 0x04 /* initialized declaration */
487 #define PND_ASSIGNED 0x08 /* set if ever LHS of assignment */
488 #define PND_TOPLEVEL 0x10 /* see isTopLevel() below */
489 #define PND_BLOCKCHILD 0x20 /* use or def is direct block child */
490 #define PND_GVAR 0x40 /* gvar binding, can't close over
491 because it could be deleted */
492 #define PND_PLACEHOLDER 0x80 /* placeholder definition for lexdep */
493 #define PND_FUNARG 0x100 /* downward or upward funarg usage */
494 #define PND_BOUND 0x200 /* bound to a stack or global slot */
495 #define PND_DEOPTIMIZED 0x400 /* former pn_used name node, pn_lexdef
496 still valid, but this use no longer
497 optimizable via an upvar opcode */
498 #define PND_CLOSED 0x800 /* variable is closed over */
500 /* Flags to propagate from uses to definition. */
501 #define PND_USE2DEF_FLAGS (PND_ASSIGNED | PND_FUNARG | PND_CLOSED)
503 /* PN_LIST pn_xflags bits. */
504 #define PNX_STRCAT 0x01 /* TOK_PLUS list has string term */
505 #define PNX_CANTFOLD 0x02 /* TOK_PLUS list has unfoldable term */
506 #define PNX_POPVAR 0x04 /* TOK_VAR last result needs popping */
507 #define PNX_FORINVAR 0x08 /* TOK_VAR is left kid of TOK_IN node,
508 which is left kid of TOK_FOR */
509 #define PNX_ENDCOMMA 0x10 /* array literal has comma at end */
510 #define PNX_XMLROOT 0x20 /* top-most node in XML literal tree */
511 #define PNX_GROUPINIT 0x40 /* var [a, b] = [c, d]; unit list */
512 #define PNX_NEEDBRACES 0x80 /* braces necessary due to closure */
513 #define PNX_FUNCDEFS 0x100 /* contains top-level function statements */
514 #define PNX_SETCALL 0x100 /* call expression in lvalue context */
515 #define PNX_DESTRUCT 0x200 /* destructuring special cases:
516 1. shorthand syntax used, at present
517 object destructuring ({x,y}) only;
518 2. code evaluating destructuring
519 arguments occurs before function
521 #define PNX_HOLEY 0x400 /* array initialiser has holes */
522 #define PNX_NONCONST 0x800 /* initialiser has non-constants */
524 uintN
frameLevel() const {
525 JS_ASSERT(pn_arity
== PN_FUNC
|| pn_arity
== PN_NAME
);
526 return pn_cookie
.level();
529 uintN
frameSlot() const {
530 JS_ASSERT(pn_arity
== PN_FUNC
|| pn_arity
== PN_NAME
);
531 return pn_cookie
.slot();
534 inline bool test(uintN flag
) const;
536 bool isLet() const { return test(PND_LET
); }
537 bool isConst() const { return test(PND_CONST
); }
538 bool isInitialized() const { return test(PND_INITIALIZED
); }
539 bool isBlockChild() const { return test(PND_BLOCKCHILD
); }
540 bool isPlaceholder() const { return test(PND_PLACEHOLDER
); }
541 bool isDeoptimized() const { return test(PND_DEOPTIMIZED
); }
542 bool isAssigned() const { return test(PND_ASSIGNED
); }
543 bool isFunArg() const { return test(PND_FUNARG
); }
544 bool isClosed() const { return test(PND_CLOSED
); }
547 * True iff this definition creates a top-level binding in the overall
548 * script being compiled -- that is, it affects the whole program's
549 * bindings, not bindings for a specific function (unless this definition
550 * is in the outermost scope in eval code, executed within a function) or
551 * the properties of a specific object (through the with statement).
553 * NB: Function sub-statements found in overall program code and not nested
554 * within other functions are not currently top level, even though (if
555 * executed) they do create top-level bindings; there is no particular
556 * rationale for this behavior.
558 bool isTopLevel() const { return test(PND_TOPLEVEL
); }
560 /* Defined below, see after struct JSDefinition. */
563 void become(JSParseNode
*pn2
);
566 /* True if pn is a parsenode representing a literal constant. */
567 bool isLiteral() const {
568 return PN_TYPE(this) == js::TOK_NUMBER
||
569 PN_TYPE(this) == js::TOK_STRING
||
570 (PN_TYPE(this) == js::TOK_PRIMARY
&& PN_OP(this) != JSOP_THIS
);
574 * True if this statement node could be a member of a Directive Prologue: an
575 * expression statement consisting of a single string literal.
577 * This considers only the node and its children, not its context. After
578 * parsing, check the node's pn_prologue flag to see if it is indeed part of
579 * a directive prologue.
581 * Note that a Directive Prologue can contain statements that cannot
582 * themselves be directives (string literals that include escape sequences
583 * or escaped newlines, say). This member function returns true for such
584 * nodes; we use it to determine the extent of the prologue.
585 * isEscapeFreeStringLiteral, below, checks whether the node itself could be
588 bool isStringExprStatement() const {
589 if (PN_TYPE(this) == js::TOK_SEMI
) {
590 JS_ASSERT(pn_arity
== PN_UNARY
);
591 JSParseNode
*kid
= pn_kid
;
592 return kid
&& PN_TYPE(kid
) == js::TOK_STRING
&& !kid
->pn_parens
;
598 * Return true if this node, known to be a string literal, could be the
599 * string of a directive in a Directive Prologue. Directive strings never
600 * contain escape sequences or line continuations.
602 bool isEscapeFreeStringLiteral() const {
603 JS_ASSERT(pn_type
== js::TOK_STRING
&& !pn_parens
);
604 JSString
*str
= ATOM_TO_STRING(pn_atom
);
607 * If the string's length in the source code is its length as a value,
608 * accounting for the quotes, then it must not contain any escape
609 * sequences or line continuations.
611 return (pn_pos
.begin
.lineno
== pn_pos
.end
.lineno
&&
612 pn_pos
.begin
.index
+ str
->length() + 2 == pn_pos
.end
.index
);
615 /* Return true if this node appears in a Directive Prologue. */
616 bool isDirectivePrologueMember() const { return pn_prologue
; }
618 #ifdef JS_HAS_GENERATOR_EXPRS
620 * True if this node is a desugared generator expression.
622 bool isGeneratorExpr() const {
623 if (PN_TYPE(this) == js::TOK_LP
) {
624 JSParseNode
*callee
= this->pn_head
;
625 if (PN_TYPE(callee
) == js::TOK_FUNCTION
) {
626 JSParseNode
*body
= (PN_TYPE(callee
->pn_body
) == js::TOK_UPVARS
)
627 ? callee
->pn_body
->pn_tree
629 if (PN_TYPE(body
) == js::TOK_LEXICALSCOPE
)
636 JSParseNode
*generatorExpr() const {
637 JS_ASSERT(isGeneratorExpr());
638 JSParseNode
*callee
= this->pn_head
;
639 JSParseNode
*body
= PN_TYPE(callee
->pn_body
) == js::TOK_UPVARS
640 ? callee
->pn_body
->pn_tree
642 JS_ASSERT(PN_TYPE(body
) == js::TOK_LEXICALSCOPE
);
643 return body
->pn_expr
;
648 * Compute a pointer to the last element in a singly-linked list. NB: list
649 * must be non-empty for correct PN_LAST usage -- this is asserted!
651 JSParseNode
*last() const {
652 JS_ASSERT(pn_arity
== PN_LIST
);
653 JS_ASSERT(pn_count
!= 0);
654 return (JSParseNode
*)((char *)pn_tail
- offsetof(JSParseNode
, pn_next
));
658 JS_ASSERT(pn_arity
== PN_LIST
);
666 void initList(JSParseNode
*pn
) {
667 JS_ASSERT(pn_arity
== PN_LIST
);
669 pn_tail
= &pn
->pn_next
;
675 void append(JSParseNode
*pn
) {
676 JS_ASSERT(pn_arity
== PN_LIST
);
678 pn_tail
= &pn
->pn_next
;
682 bool getConstantValue(JSContext
*cx
, bool strictChecks
, js::Value
*vp
);
683 inline bool isConstant();
688 struct NullaryNode
: public JSParseNode
{
689 static inline NullaryNode
*create(JSTreeContext
*tc
) {
690 return (NullaryNode
*)JSParseNode::create(PN_NULLARY
, tc
);
694 struct UnaryNode
: public JSParseNode
{
695 static inline UnaryNode
*create(JSTreeContext
*tc
) {
696 return (UnaryNode
*)JSParseNode::create(PN_UNARY
, tc
);
700 struct BinaryNode
: public JSParseNode
{
701 static inline BinaryNode
*create(JSTreeContext
*tc
) {
702 return (BinaryNode
*)JSParseNode::create(PN_BINARY
, tc
);
706 struct TernaryNode
: public JSParseNode
{
707 static inline TernaryNode
*create(JSTreeContext
*tc
) {
708 return (TernaryNode
*)JSParseNode::create(PN_TERNARY
, tc
);
712 struct ListNode
: public JSParseNode
{
713 static inline ListNode
*create(JSTreeContext
*tc
) {
714 return (ListNode
*)JSParseNode::create(PN_LIST
, tc
);
718 struct FunctionNode
: public JSParseNode
{
719 static inline FunctionNode
*create(JSTreeContext
*tc
) {
720 return (FunctionNode
*)JSParseNode::create(PN_FUNC
, tc
);
724 struct NameNode
: public JSParseNode
{
725 static NameNode
*create(JSAtom
*atom
, JSTreeContext
*tc
);
727 void inline initCommon(JSTreeContext
*tc
);
730 struct NameSetNode
: public JSParseNode
{
731 static inline NameSetNode
*create(JSTreeContext
*tc
) {
732 return (NameSetNode
*)JSParseNode::create(PN_NAMESET
, tc
);
736 struct LexicalScopeNode
: public JSParseNode
{
737 static inline LexicalScopeNode
*create(JSTreeContext
*tc
) {
738 return (LexicalScopeNode
*)JSParseNode::create(PN_NAME
, tc
);
745 * JSDefinition is a degenerate subtype of the PN_FUNC and PN_NAME variants of
746 * JSParseNode, allocated only for function, var, const, and let declarations
747 * that define truly lexical bindings. This means that a child of a TOK_VAR
748 * list may be a JSDefinition instead of a JSParseNode. The pn_defn bit is set
749 * for all JSDefinitions, clear otherwise.
751 * Note that not all var declarations are definitions: JS allows multiple var
752 * declarations in a function or script, but only the first creates the hoisted
753 * binding. JS programmers do redeclare variables for good refactoring reasons,
758 * for (var i ...) ...;
760 * for (var i ...) ...;
764 * Not all definitions bind lexical variables, alas. In global and eval code
765 * var may re-declare a pre-existing property having any attributes, with or
766 * without JSPROP_PERMANENT. In eval code, indeed, ECMA-262 Editions 1 through
767 * 3 require function and var to bind deletable bindings. Global vars thus are
768 * properties of the global object, so they can be aliased even if they can't
771 * Only bindings within function code may be treated as lexical, of course with
772 * the caveat that hoisting means use before initialization is allowed. We deal
773 * with use before declaration in one pass as follows (error checking elided):
775 * for (each use of unqualified name x in parse order) {
776 * if (this use of x is a declaration) {
777 * if (x in tc->decls) { // redeclaring
778 * pn = allocate a PN_NAME JSParseNode;
779 * } else { // defining
780 * dn = lookup x in tc->lexdeps;
781 * if (dn) // use before def
782 * remove x from tc->lexdeps;
783 * else // def before use
784 * dn = allocate a PN_NAME JSDefinition;
785 * map x to dn via tc->decls;
788 * insert pn into its parent TOK_VAR list;
790 * pn = allocate a JSParseNode for this reference to x;
791 * dn = lookup x in tc's lexical scope chain;
793 * dn = lookup x in tc->lexdeps;
795 * dn = pre-allocate a JSDefinition for x;
796 * map x to dn in tc->lexdeps;
799 * append pn to dn's use chain;
803 * See jsemit.h for JSTreeContext and its top*Stmt, decls, and lexdeps members.
807 * 0. To avoid bloating JSParseNode, we steal a bit from pn_arity for pn_defn
808 * and set it on a JSParseNode instead of allocating a JSDefinition.
810 * 1. Due to hoisting, a definition cannot be eliminated even if its "Variable
811 * statement" (ECMA-262 12.2) can be proven to be dead code. RecycleTree in
812 * jsparse.cpp will not recycle a node whose pn_defn bit is set.
814 * 2. "lookup x in tc's lexical scope chain" gives up on def/use chaining if a
815 * with statement is found along the the scope chain, which includes tc,
816 * tc->parent, etc. Thus we eagerly connect an inner function's use of an
817 * outer's var x if the var x was parsed before the inner function.
819 * 3. A use may be eliminated as dead by the constant folder, which therefore
820 * must remove the dead name node from its singly-linked use chain, which
821 * would mean hashing to find the definition node and searching to update
822 * the pn_link pointing at the use to be removed. This is costly, so as for
823 * dead definitions, we do not recycle dead pn_used nodes.
825 * At the end of parsing a function body or global or eval program, tc->lexdeps
826 * holds the lexical dependencies of the parsed unit. The name to def/use chain
827 * mappings are then merged into the parent tc->lexdeps.
829 * Thus if a later var x is parsed in the outer function satisfying an earlier
830 * inner function's use of x, we will remove dn from tc->lexdeps and re-use it
831 * as the new definition node in the outer function's parse tree.
833 * When the compiler unwinds from the outermost tc, tc->lexdeps contains the
834 * definition nodes with use chains for all free variables. These are either
835 * global variables or reference errors.
837 * We analyze whether a binding is initialized, whether the bound names is ever
838 * assigned apart from its initializer, and if the bound name definition or use
839 * is in a direct child of a block. These PND_* flags allow a subset dominance
840 * computation telling whether an initialized var dominates its uses. An inner
841 * function using only such outer vars (and formal parameters) can be optimized
842 * into a flat closure. See JSOP_{GET,CALL}DSLOT.
844 * Another important subset dominance relation: ... { var x = ...; ... x ... }
845 * where x is not assigned after initialization and not used outside the block.
846 * This style is common in the absence of 'let'. Even though the var x is not
847 * at top level, we can tell its initialization dominates all uses cheaply,
848 * because the above one-pass algorithm sees the definition before any uses,
849 * and because all uses are contained in the same block as the definition.
851 * We also analyze function uses to flag upward/downward funargs, optimizing
852 * those lambdas that post-dominate their upvars inevitable only assignments or
853 * initializations as flat closures (after Chez Scheme's display closures).
855 #define dn_uses pn_link
857 struct JSDefinition
: public JSParseNode
860 * We store definition pointers in PN_NAMESET JSAtomLists in the AST, but
861 * due to redefinition these nodes may become uses of other definitions.
862 * This is unusual, so we simply chase the pn_lexdef link to find the final
863 * definition node. See methods called from Parser::analyzeFunctions.
865 * FIXME: MakeAssignment mutates for want of a parent link...
867 JSDefinition
*resolve() {
868 JSParseNode
*pn
= this;
869 while (!pn
->pn_defn
) {
870 if (pn
->pn_type
== js::TOK_ASSIGN
) {
876 return (JSDefinition
*) pn
;
879 bool isFreeVar() const {
881 return pn_cookie
.isFree() || test(PND_GVAR
);
884 bool isGlobal() const {
886 return test(PND_GVAR
);
889 // Grr, windows.h or something under it #defines CONST...
893 enum Kind
{ VAR
, CONST
, LET
, FUNCTION
, ARG
, UNKNOWN
};
895 bool isBindingForm() { return int(kind()) <= int(LET
); }
897 static const char *kindString(Kind kind
);
900 if (PN_TYPE(this) == js::TOK_FUNCTION
)
902 JS_ASSERT(PN_TYPE(this) == js::TOK_NAME
);
903 if (PN_OP(this) == JSOP_NOP
)
905 if (PN_OP(this) == JSOP_GETARG
)
916 JSParseNode::test(uintN flag
) const
918 JS_ASSERT(pn_defn
|| pn_arity
== PN_FUNC
|| pn_arity
== PN_NAME
);
920 if ((flag
& (PND_ASSIGNED
| PND_FUNARG
)) && pn_defn
&& !(pn_dflags
& flag
)) {
921 for (JSParseNode
*pn
= ((JSDefinition
*) this)->dn_uses
; pn
; pn
= pn
->pn_link
) {
922 JS_ASSERT(!pn
->pn_defn
);
923 JS_ASSERT(!(pn
->pn_dflags
& flag
));
927 return !!(pn_dflags
& flag
);
931 JSParseNode::setFunArg()
934 * pn_defn NAND pn_used must be true, per this chart:
937 * 0 0 anonymous function used implicitly, e.g. by
938 * hidden yield in a genexp
939 * 0 1 a use of a definition or placeholder
940 * 1 0 a definition or placeholder
941 * 1 1 error: this case must not be possible
943 JS_ASSERT(!(pn_defn
& pn_used
));
945 pn_lexdef
->pn_dflags
|= PND_FUNARG
;
946 pn_dflags
|= PND_FUNARG
;
950 JSObjectBox
*traceLink
;
951 JSObjectBox
*emitLink
;
958 #define JSFB_LEVEL_BITS 14
960 struct JSFunctionBox
: public JSObjectBox
963 JSFunctionBox
*siblings
;
965 JSFunctionBox
*parent
;
966 JSParseNode
*methods
; /* would-be methods set on this;
967 these nodes are linked via
968 pn_link, since lambdas are
969 neither definitions nor uses
971 js::Bindings bindings
; /* bindings for this function */
973 inLoop
:1, /* in a loop in parent function */
974 level
:JSFB_LEVEL_BITS
;
977 bool joinable() const;
980 * True if this function is inside the scope of a with-statement, an E4X
981 * filter-expression, or a function that uses direct eval.
983 bool inAnyDynamicScope() const;
986 * Unbrand an object being initialized or constructed if any method cannot
987 * be joined to one compiler-created null closure shared among N different
988 * closure environments.
990 * We despecialize from caching function objects, caching slots or shapes
991 * instead, because an unbranded object may still have joined methods (for
992 * which shape->isMethod), since PropertyCache::fill gives precedence to
993 * joined methods over branded methods.
995 bool shouldUnbrand(uintN methods
, uintN slowMethods
) const;
998 struct JSFunctionBoxQueue
{
999 JSFunctionBox
**vector
;
1003 size_t count() { return head
- tail
; }
1004 size_t length() { return lengthMask
+ 1; }
1006 JSFunctionBoxQueue()
1007 : vector(NULL
), head(0), tail(0), lengthMask(0) { }
1009 bool init(uint32 count
) {
1010 lengthMask
= JS_BITMASK(JS_CeilingLog2(count
));
1011 vector
= js_array_new
<JSFunctionBox
*>(length());
1015 ~JSFunctionBoxQueue() { js_array_delete(vector
); }
1017 void push(JSFunctionBox
*funbox
) {
1018 if (!funbox
->queued
) {
1019 JS_ASSERT(count() < length());
1020 vector
[head
++ & lengthMask
] = funbox
;
1021 funbox
->queued
= true;
1025 JSFunctionBox
*pull() {
1028 JS_ASSERT(tail
< head
);
1029 JSFunctionBox
*funbox
= vector
[tail
++ & lengthMask
];
1030 funbox
->queued
= false;
1035 #define NUM_TEMP_FREELISTS 6U /* 32 to 2048 byte size classes (32 bit) */
1037 typedef struct BindData BindData
;
1041 struct Parser
: private js::AutoGCRooter
1043 JSContext
* const context
; /* FIXME Bug 551291: use AutoGCRooter::context? */
1044 JSAtomListElement
*aleFreeList
;
1045 void *tempFreeList
[NUM_TEMP_FREELISTS
];
1046 TokenStream tokenStream
;
1047 void *tempPoolMark
; /* initial JSContext.tempPool mark */
1048 JSPrincipals
*principals
; /* principals associated with source */
1049 JSStackFrame
*const callerFrame
; /* scripted caller frame for eval and dbgapi */
1050 JSObject
*const callerVarObj
; /* callerFrame's varObj */
1051 JSParseNode
*nodeList
; /* list of recyclable parse-node structs */
1052 uint32 functionCount
; /* number of functions in current unit */
1053 JSObjectBox
*traceListHead
; /* list of parsed object for GC tracing */
1054 JSTreeContext
*tc
; /* innermost tree context (stack-allocated) */
1056 /* Root atoms and objects allocated for the parsed tree. */
1057 js::AutoKeepAtoms keepAtoms
;
1059 Parser(JSContext
*cx
, JSPrincipals
*prin
= NULL
, JSStackFrame
*cfp
= NULL
);
1062 friend void js::AutoGCRooter::trace(JSTracer
*trc
);
1063 friend struct ::JSTreeContext
;
1064 friend struct Compiler
;
1067 * Initialize a parser. Parameters are passed on to init tokenStream.
1068 * The compiler owns the arena pool "tops-of-stack" space above the current
1069 * JSContext.tempPool mark. This means you cannot allocate from tempPool
1070 * and save the pointer beyond the next Parser destructor invocation.
1072 bool init(const jschar
*base
, size_t length
, const char *filename
, uintN lineno
,
1075 void setPrincipals(JSPrincipals
*prin
);
1077 const char *getFilename() const { return tokenStream
.getFilename(); }
1078 JSVersion
versionWithFlags() const { return tokenStream
.versionWithFlags(); }
1079 JSVersion
versionNumber() const { return tokenStream
.versionNumber(); }
1080 bool hasXML() const { return tokenStream
.hasXML(); }
1081 bool hasAnonFunFix() const { return tokenStream
.hasAnonFunFix(); }
1084 * Parse a top-level JS script.
1086 JSParseNode
*parse(JSObject
*chain
);
1088 #if JS_HAS_XML_SUPPORT
1089 JSParseNode
*parseXMLText(JSObject
*chain
, bool allowList
);
1093 * Allocate a new parsed object or function container from cx->tempPool.
1095 JSObjectBox
*newObjectBox(JSObject
*obj
);
1097 JSFunctionBox
*newFunctionBox(JSObject
*obj
, JSParseNode
*fn
, JSTreeContext
*tc
);
1100 * Create a new function object given tree context (tc), optional name
1101 * (atom may be null) and lambda flag (JSFUN_LAMBDA or 0).
1103 JSFunction
*newFunction(JSTreeContext
*tc
, JSAtom
*atom
, uintN lambda
);
1106 * Analyze the tree of functions nested within a single compilation unit,
1107 * starting at funbox, recursively walking its kids, then following its
1108 * siblings, their kids, etc.
1110 bool analyzeFunctions(JSTreeContext
*tc
);
1111 void cleanFunctionList(JSFunctionBox
**funbox
);
1112 bool markFunArgs(JSFunctionBox
*funbox
);
1113 void setFunctionKinds(JSFunctionBox
*funbox
, uint32
*tcflags
);
1115 void trace(JSTracer
*trc
);
1118 * Report a parse (compile) error.
1120 inline bool reportErrorNumber(JSParseNode
*pn
, uintN flags
, uintN errorNumber
, ...);
1124 * JS parsers, from lowest to highest precedence.
1126 * Each parser must be called during the dynamic scope of a JSTreeContext
1127 * object, pointed to by this->tc.
1129 * Each returns a parse node tree or null on error.
1131 JSParseNode
*functionStmt();
1132 JSParseNode
*functionExpr();
1133 JSParseNode
*statements();
1134 JSParseNode
*statement();
1135 JSParseNode
*switchStatement();
1136 JSParseNode
*forStatement();
1137 JSParseNode
*tryStatement();
1138 JSParseNode
*withStatement();
1139 #if JS_HAS_BLOCK_SCOPE
1140 JSParseNode
*letStatement();
1142 JSParseNode
*expressionStatement();
1143 JSParseNode
*variables(bool inLetHead
);
1144 JSParseNode
*expr();
1145 JSParseNode
*assignExpr();
1146 JSParseNode
*condExpr();
1147 JSParseNode
*orExpr();
1148 JSParseNode
*andExpr();
1149 JSParseNode
*bitOrExpr();
1150 JSParseNode
*bitXorExpr();
1151 JSParseNode
*bitAndExpr();
1152 JSParseNode
*eqExpr();
1153 JSParseNode
*relExpr();
1154 JSParseNode
*shiftExpr();
1155 JSParseNode
*addExpr();
1156 JSParseNode
*mulExpr();
1157 JSParseNode
*unaryExpr();
1158 JSParseNode
*memberExpr(JSBool allowCallSyntax
);
1159 JSParseNode
*primaryExpr(js::TokenKind tt
, JSBool afterDot
);
1160 JSParseNode
*parenExpr(JSBool
*genexp
= NULL
);
1163 * Additional JS parsers.
1165 bool recognizeDirectivePrologue(JSParseNode
*pn
, bool *isDirectivePrologueMember
);
1167 enum FunctionType
{ GETTER
, SETTER
, GENERAL
};
1168 bool functionArguments(JSTreeContext
&funtc
, JSFunctionBox
*funbox
, JSParseNode
**list
);
1169 JSParseNode
*functionBody();
1170 JSParseNode
*functionDef(JSAtom
*name
, FunctionType type
, uintN lambda
);
1172 JSParseNode
*condition();
1173 JSParseNode
*comprehensionTail(JSParseNode
*kid
, uintN blockid
,
1174 js::TokenKind type
= js::TOK_SEMI
, JSOp op
= JSOP_NOP
);
1175 JSParseNode
*generatorExpr(JSParseNode
*kid
);
1176 JSBool
argumentList(JSParseNode
*listNode
);
1177 JSParseNode
*bracketedExpr();
1178 JSParseNode
*letBlock(JSBool statement
);
1179 JSParseNode
*returnOrYield(bool useAssignExpr
);
1180 JSParseNode
*destructuringExpr(BindData
*data
, js::TokenKind tt
);
1182 #if JS_HAS_XML_SUPPORT
1183 JSParseNode
*endBracketedExpr();
1185 JSParseNode
*propertySelector();
1186 JSParseNode
*qualifiedSuffix(JSParseNode
*pn
);
1187 JSParseNode
*qualifiedIdentifier();
1188 JSParseNode
*attributeIdentifier();
1189 JSParseNode
*xmlExpr(JSBool inTag
);
1190 JSParseNode
*xmlAtomNode();
1191 JSParseNode
*xmlNameExpr();
1192 JSParseNode
*xmlTagContent(js::TokenKind tagtype
, JSAtom
**namep
);
1193 JSBool
xmlElementContent(JSParseNode
*pn
);
1194 JSParseNode
*xmlElementOrList(JSBool allowList
);
1195 JSParseNode
*xmlElementOrListRoot(JSBool allowList
);
1196 #endif /* JS_HAS_XML_SUPPORT */
1200 Parser::reportErrorNumber(JSParseNode
*pn
, uintN flags
, uintN errorNumber
, ...)
1203 va_start(args
, errorNumber
);
1204 bool result
= tokenStream
.reportCompileErrorNumberVA(pn
, flags
, errorNumber
, args
);
1212 GlobalScope
*globalScope
;
1214 Compiler(JSContext
*cx
, JSPrincipals
*prin
= NULL
, JSStackFrame
*cfp
= NULL
);
1217 * Initialize a compiler. Parameters are passed on to init parser.
1220 init(const jschar
*base
, size_t length
, const char *filename
, uintN lineno
, JSVersion version
)
1222 return parser
.init(base
, length
, filename
, lineno
, version
);
1226 compileFunctionBody(JSContext
*cx
, JSFunction
*fun
, JSPrincipals
*principals
,
1227 js::Bindings
*bindings
, const jschar
*chars
, size_t length
,
1228 const char *filename
, uintN lineno
, JSVersion version
);
1231 compileScript(JSContext
*cx
, JSObject
*scopeChain
, JSStackFrame
*callerFrame
,
1232 JSPrincipals
*principals
, uint32 tcflags
,
1233 const jschar
*chars
, size_t length
,
1234 const char *filename
, uintN lineno
, JSVersion version
,
1235 JSString
*source
= NULL
, uintN staticLevel
= 0);
1238 static bool defineGlobals(JSContext
*cx
, GlobalScope
&globalScope
, JSScript
*script
);
1241 } /* namespace js */
1244 * Convenience macro to access Parser.tokenStream as a pointer.
1246 #define TS(p) (&(p)->tokenStream)
1249 js_FoldConstants(JSContext
*cx
, JSParseNode
*pn
, JSTreeContext
*tc
,
1250 bool inCond
= false);
1254 #endif /* jsparse_h___ */