1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=79:
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 ***** */
42 * JavaScript bytecode interpreter.
49 #include "jsarena.h" /* Added by JSIFY */
50 #include "jsutil.h" /* Added by JSIFY */
57 #include "jsversion.h"
71 #include "jsstaticcheck.h"
74 #ifdef INCLUDE_MOZILLA_DTRACE
75 #include "jsdtracef.h"
78 #if JS_HAS_XML_SUPPORT
82 #include "jsautooplen.h"
84 /* jsinvoke_cpp___ indicates inclusion from jsinvoke.cpp. */
85 #if !JS_LONE_INTERPRET ^ defined jsinvoke_cpp___
88 js_GenerateShape(JSContext
*cx
, JSBool gcLocked
, JSScopeProperty
*sprop
)
92 JSTempValueRooter tvr
;
95 shape
= JS_ATOMIC_INCREMENT(&rt
->shapeGen
);
96 JS_ASSERT(shape
!= 0);
97 if (shape
& SHAPE_OVERFLOW_BIT
) {
100 JS_PUSH_TEMP_ROOT_SPROP(cx
, sprop
, &tvr
);
101 js_GC(cx
, gcLocked
? GC_LOCK_HELD
: GC_NORMAL
);
103 JS_POP_TEMP_ROOT(cx
, &tvr
);
104 shape
= JS_ATOMIC_INCREMENT(&rt
->shapeGen
);
105 JS_ASSERT(shape
!= 0);
106 JS_ASSERT_IF(shape
& SHAPE_OVERFLOW_BIT
,
107 JS_PROPERTY_CACHE(cx
).disabled
);
112 JS_REQUIRES_STACK
void
113 js_FillPropertyCache(JSContext
*cx
, JSObject
*obj
, jsuword kshape
,
114 uintN scopeIndex
, uintN protoIndex
,
115 JSObject
*pobj
, JSScopeProperty
*sprop
,
116 JSPropCacheEntry
**entryp
)
118 JSPropertyCache
*cache
;
122 const JSCodeSpec
*cs
;
127 JSPropCacheEntry
*entry
;
129 JS_ASSERT(!cx
->runtime
->gcRunning
);
130 cache
= &JS_PROPERTY_CACHE(cx
);
131 pc
= cx
->fp
->regs
->pc
;
132 if (cache
->disabled
|| (cx
->fp
->flags
& JSFRAME_EVAL
)) {
133 PCMETER(cache
->disfills
++);
139 * Check for fill from js_SetPropertyHelper where the setter removed sprop
140 * from pobj's scope (via unwatch or delete, e.g.).
142 scope
= OBJ_SCOPE(pobj
);
143 JS_ASSERT(scope
->object
== pobj
);
144 if (!SCOPE_HAS_PROPERTY(scope
, sprop
)) {
145 PCMETER(cache
->oddfills
++);
151 * Check for overdeep scope and prototype chain. Because resolve, getter,
152 * and setter hooks can change the prototype chain using JS_SetPrototype
153 * after js_LookupPropertyWithFlags has returned the nominal protoIndex,
154 * we have to validate protoIndex if it is non-zero. If it is zero, then
155 * we know thanks to the SCOPE_HAS_PROPERTY test above, and from the fact
156 * that obj == pobj, that protoIndex is invariant.
158 * The scopeIndex can't be wrong. We require JS_SetParent calls to happen
159 * before any running script might consult a parent-linked scope chain. If
160 * this requirement is not satisfied, the fill in progress will never hit,
161 * but vcap vs. scope shape tests ensure nothing malfunctions.
163 JS_ASSERT_IF(scopeIndex
== 0 && protoIndex
== 0, obj
== pobj
);
164 if (protoIndex
!= 0) {
167 JS_ASSERT(pobj
!= obj
);
171 tmp
= OBJ_GET_PROTO(cx
, tmp
);
173 PCMETER(cache
->noprotos
++);
182 if (scopeIndex
> PCVCAP_SCOPEMASK
|| protoIndex
> PCVCAP_PROTOMASK
) {
183 PCMETER(cache
->longchains
++);
189 * Optimize the cached vword based on our parameters and the current pc's
190 * opcode format flags.
193 cs
= &js_CodeSpec
[op
];
197 * Check for a prototype "plain old method" callee computation. What
198 * is a plain old method? It's a function-valued property with stub
199 * getter and setter, so get of a function is idempotent and set is
202 if (cs
->format
& JOF_CALLOP
) {
203 if (SPROP_HAS_STUB_GETTER(sprop
) &&
204 SPROP_HAS_VALID_SLOT(sprop
, scope
)) {
207 v
= LOCKED_OBJ_GET_SLOT(pobj
, sprop
->slot
);
208 if (VALUE_IS_FUNCTION(cx
, v
)) {
210 * Great, we have a function-valued prototype property
211 * where the getter is JS_PropertyStub. The type id in
212 * pobj's scope does not evolve with changes to property
215 * So here, on first cache fill for this method, we brand
216 * the scope with a new shape and set the SCOPE_BRANDED
217 * flag. Once this scope flag is set, any write that adds
218 * or deletes a function-valued plain old property in
219 * scope->object will result in shape being regenerated.
221 if (!SCOPE_IS_BRANDED(scope
)) {
222 PCMETER(cache
->brandfills
++);
225 "branding %p (%s) for funobj %p (%s), kshape %lu\n",
226 pobj
, LOCKED_OBJ_GET_CLASS(pobj
)->name
,
228 JS_GetFunctionName(GET_FUNCTION_PRIVATE(cx
,
229 JSVAL_TO_OBJECT(v
))),
232 SCOPE_MAKE_UNIQUE_SHAPE(cx
, scope
);
233 SCOPE_SET_BRANDED(scope
);
234 if (OBJ_SCOPE(obj
) == scope
)
235 kshape
= scope
->shape
;
237 vword
= JSVAL_OBJECT_TO_PCVAL(v
);
243 /* If getting a value via a stub getter, we can cache the slot. */
244 if (!(cs
->format
& JOF_SET
) &&
245 SPROP_HAS_STUB_GETTER(sprop
) &&
246 SPROP_HAS_VALID_SLOT(sprop
, scope
)) {
247 /* Great, let's cache sprop's slot and use it on cache hit. */
248 vword
= SLOT_TO_PCVAL(sprop
->slot
);
250 /* Best we can do is to cache sprop (still a nice speedup). */
251 vword
= SPROP_TO_PCVAL(sprop
);
256 * Our caller preserved the scope shape prior to the js_GetPropertyHelper
257 * or similar call out of the interpreter. We want to cache under that
258 * shape if op is overtly mutating, to bias for the case where the mutator
259 * udpates shape predictably.
261 * Note that an apparently non-mutating op such as JSOP_NAME may still
262 * mutate the base object via, e.g., lazy standard class initialization,
263 * but that is a one-time event and we'll have to miss the old shape and
264 * re-fill under the new one.
266 if (!(cs
->format
& (JOF_SET
| JOF_INCDEC
)) && obj
== pobj
)
267 kshape
= scope
->shape
;
269 khash
= PROPERTY_CACHE_HASH_PC(pc
, kshape
);
271 JS_ASSERT(kshape
!= 0 || scope
->shape
!= 0);
272 JS_ASSERT(scopeIndex
== 0 && protoIndex
== 0);
273 JS_ASSERT(OBJ_SCOPE(obj
)->object
== obj
);
275 if (op
== JSOP_LENGTH
) {
276 atom
= cx
->runtime
->atomState
.lengthAtom
;
278 pcoff
= (JOF_TYPE(cs
->format
) == JOF_SLOTATOM
) ? 2 : 0;
279 GET_ATOM_FROM_BYTECODE(cx
->fp
->script
, pc
, pcoff
, atom
);
281 JS_ASSERT_IF(scopeIndex
== 0,
282 protoIndex
!= 1 || OBJ_GET_PROTO(cx
, obj
) == pobj
);
283 if (scopeIndex
!= 0 || protoIndex
!= 1) {
284 khash
= PROPERTY_CACHE_HASH_ATOM(atom
, obj
, pobj
);
285 PCMETER(if (PCVCAP_TAG(cache
->table
[khash
].vcap
) <= 1)
286 cache
->pcrecycles
++);
287 pc
= (jsbytecode
*) atom
;
288 kshape
= (jsuword
) obj
;
292 entry
= &cache
->table
[khash
];
293 PCMETER(if (entry
!= *entryp
) cache
->modfills
++);
294 PCMETER(if (!PCVAL_IS_NULL(entry
->vword
)) cache
->recycles
++);
296 entry
->kshape
= kshape
;
297 entry
->vcap
= PCVCAP_MAKE(scope
->shape
, scopeIndex
, protoIndex
);
298 entry
->vword
= vword
;
301 cache
->empty
= JS_FALSE
;
302 PCMETER(cache
->fills
++);
305 JS_REQUIRES_STACK JSAtom
*
306 js_FullTestPropertyCache(JSContext
*cx
, jsbytecode
*pc
,
307 JSObject
**objp
, JSObject
**pobjp
,
308 JSPropCacheEntry
**entryp
)
311 const JSCodeSpec
*cs
;
314 JSObject
*obj
, *pobj
, *tmp
;
315 JSPropCacheEntry
*entry
;
318 JS_ASSERT(uintN((cx
->fp
->imacpc
? cx
->fp
->imacpc
: pc
) - cx
->fp
->script
->code
)
319 < cx
->fp
->script
->length
);
322 cs
= &js_CodeSpec
[op
];
323 if (op
== JSOP_LENGTH
) {
324 atom
= cx
->runtime
->atomState
.lengthAtom
;
326 pcoff
= (JOF_TYPE(cs
->format
) == JOF_SLOTATOM
) ? 2 : 0;
327 GET_ATOM_FROM_BYTECODE(cx
->fp
->script
, pc
, pcoff
, atom
);
331 JS_ASSERT(OBJ_IS_NATIVE(obj
));
332 entry
= &JS_PROPERTY_CACHE(cx
).table
[PROPERTY_CACHE_HASH_ATOM(atom
, obj
, NULL
)];
336 if (entry
->kpc
!= (jsbytecode
*) atom
) {
337 PCMETER(JS_PROPERTY_CACHE(cx
).idmisses
++);
340 entry
= &JS_PROPERTY_CACHE(cx
).table
[PROPERTY_CACHE_HASH_PC(pc
, OBJ_SHAPE(obj
))];
342 "id miss for %s from %s:%u"
343 " (pc %u, kpc %u, kshape %u, shape %u)\n",
344 js_AtomToPrintableString(cx
, atom
),
345 cx
->fp
->script
->filename
,
346 js_PCToLineNumber(cx
, cx
->fp
->script
, pc
),
347 pc
- cx
->fp
->script
->code
,
348 entry
->kpc
- cx
->fp
->script
->code
,
351 js_Disassemble1(cx
, cx
->fp
->script
, pc
,
352 PTRDIFF(pc
, cx
->fp
->script
->code
, jsbytecode
),
359 if (entry
->kshape
!= (jsuword
) obj
) {
360 PCMETER(JS_PROPERTY_CACHE(cx
).komisses
++);
365 JS_LOCK_OBJ(cx
, pobj
);
367 if (JOF_MODE(cs
->format
) == JOF_NAME
) {
368 while (vcap
& (PCVCAP_SCOPEMASK
<< PCVCAP_PROTOBITS
)) {
369 tmp
= LOCKED_OBJ_GET_PARENT(pobj
);
370 if (!tmp
|| !OBJ_IS_NATIVE(tmp
))
372 JS_UNLOCK_OBJ(cx
, pobj
);
374 JS_LOCK_OBJ(cx
, pobj
);
375 vcap
-= PCVCAP_PROTOSIZE
;
381 while (vcap
& PCVCAP_PROTOMASK
) {
382 tmp
= LOCKED_OBJ_GET_PROTO(pobj
);
383 if (!tmp
|| !OBJ_IS_NATIVE(tmp
))
385 JS_UNLOCK_OBJ(cx
, pobj
);
387 JS_LOCK_OBJ(cx
, pobj
);
391 if (PCVCAP_SHAPE(vcap
) == OBJ_SHAPE(pobj
)) {
393 jsid id
= ATOM_TO_JSID(atom
);
395 CHECK_FOR_STRING_INDEX(id
);
396 JS_ASSERT(SCOPE_GET_PROPERTY(OBJ_SCOPE(pobj
), id
));
397 JS_ASSERT(OBJ_SCOPE(pobj
)->object
== pobj
);
403 PCMETER(JS_PROPERTY_CACHE(cx
).vcmisses
++);
404 JS_UNLOCK_OBJ(cx
, pobj
);
409 #define ASSERT_CACHE_IS_EMPTY(cache) \
411 JSPropertyCache *cache_ = (cache); \
413 JS_ASSERT(cache_->empty); \
414 for (i_ = 0; i_ < PROPERTY_CACHE_SIZE; i_++) { \
415 JS_ASSERT(!cache_->table[i_].kpc); \
416 JS_ASSERT(!cache_->table[i_].kshape); \
417 JS_ASSERT(!cache_->table[i_].vcap); \
418 JS_ASSERT(!cache_->table[i_].vword); \
422 #define ASSERT_CACHE_IS_EMPTY(cache) ((void)0)
425 JS_STATIC_ASSERT(PCVAL_NULL
== 0);
428 js_FlushPropertyCache(JSContext
*cx
)
430 JSPropertyCache
*cache
;
432 cache
= &JS_PROPERTY_CACHE(cx
);
434 ASSERT_CACHE_IS_EMPTY(cache
);
438 memset(cache
->table
, 0, sizeof cache
->table
);
439 cache
->empty
= JS_TRUE
;
441 #ifdef JS_PROPERTY_CACHE_METERING
444 fp
= fopen("/tmp/propcache.stats", "w");
446 fputs("Property cache stats for ", fp
);
448 fprintf(fp
, "thread %lu, ", (unsigned long) cx
->thread
->id
);
450 fprintf(fp
, "GC %u\n", cx
->runtime
->gcNumber
);
452 # define P(mem) fprintf(fp, "%11s %10lu\n", #mem, (unsigned long)cache->mem)
484 fprintf(fp
, "hit rates: pc %g%% (proto %g%%), set %g%%, ini %g%%, full %g%%\n",
485 (100. * cache
->pchits
) / cache
->tests
,
486 (100. * cache
->protopchits
) / cache
->tests
,
487 (100. * (cache
->addpchits
+ cache
->setpchits
))
489 (100. * cache
->inipchits
) / cache
->initests
,
490 (100. * (cache
->tests
- cache
->misses
)) / cache
->tests
);
496 PCMETER(cache
->flushes
++);
500 js_FlushPropertyCacheForScript(JSContext
*cx
, JSScript
*script
)
502 JSPropertyCache
*cache
;
503 JSPropCacheEntry
*entry
;
505 cache
= &JS_PROPERTY_CACHE(cx
);
506 for (entry
= cache
->table
; entry
< cache
->table
+ PROPERTY_CACHE_SIZE
;
508 if (JS_UPTRDIFF(entry
->kpc
, script
->code
) < script
->length
) {
512 entry
->vcap
= entry
->vword
= 0;
519 js_DisablePropertyCache(JSContext
*cx
)
521 JS_ASSERT(JS_PROPERTY_CACHE(cx
).disabled
>= 0);
522 ++JS_PROPERTY_CACHE(cx
).disabled
;
526 js_EnablePropertyCache(JSContext
*cx
)
528 --JS_PROPERTY_CACHE(cx
).disabled
;
529 JS_ASSERT(JS_PROPERTY_CACHE(cx
).disabled
>= 0);
533 * Check if the current arena has enough space to fit nslots after sp and, if
534 * so, reserve the necessary space.
537 AllocateAfterSP(JSContext
*cx
, jsval
*sp
, uintN nslots
)
542 JS_ASSERT((jsval
*) cx
->stackPool
.current
->base
<= sp
);
543 JS_ASSERT(sp
<= (jsval
*) cx
->stackPool
.current
->avail
);
544 surplus
= (jsval
*) cx
->stackPool
.current
->avail
- sp
;
545 if (nslots
<= surplus
)
549 * No room before current->avail, check if the arena has enough space to
550 * fit the missing slots before the limit.
552 if (nslots
> (size_t) ((jsval
*) cx
->stackPool
.current
->limit
- sp
))
555 JS_ARENA_ALLOCATE_CAST(sp2
, jsval
*, &cx
->stackPool
,
556 (nslots
- surplus
) * sizeof(jsval
));
557 JS_ASSERT(sp2
== sp
+ surplus
);
561 JS_STATIC_INTERPRET jsval
*
562 js_AllocRawStack(JSContext
*cx
, uintN nslots
, void **markp
)
566 if (!cx
->stackPool
.first
.next
) {
569 JS_ARENA_ALLOCATE_CAST(timestamp
, int64
*,
570 &cx
->stackPool
, sizeof *timestamp
);
572 js_ReportOutOfScriptQuota(cx
);
575 *timestamp
= JS_Now();
579 *markp
= JS_ARENA_MARK(&cx
->stackPool
);
580 JS_ARENA_ALLOCATE_CAST(sp
, jsval
*, &cx
->stackPool
, nslots
* sizeof(jsval
));
582 js_ReportOutOfScriptQuota(cx
);
586 JS_STATIC_INTERPRET
void
587 js_FreeRawStack(JSContext
*cx
, void *mark
)
589 JS_ARENA_RELEASE(&cx
->stackPool
, mark
);
592 JS_FRIEND_API(jsval
*)
593 js_AllocStack(JSContext
*cx
, uintN nslots
, void **markp
)
599 /* Callers don't check for zero nslots: we do to avoid empty segments. */
602 return (jsval
*) JS_ARENA_MARK(&cx
->stackPool
);
605 /* Allocate 2 extra slots for the stack segment header we'll likely need. */
606 sp
= js_AllocRawStack(cx
, 2 + nslots
, markp
);
610 /* Try to avoid another header if we can piggyback on the last segment. */
611 a
= cx
->stackPool
.current
;
612 sh
= cx
->stackHeaders
;
613 if (sh
&& JS_STACK_SEGMENT(sh
) + sh
->nslots
== sp
) {
614 /* Extend the last stack segment, give back the 2 header slots. */
615 sh
->nslots
+= nslots
;
616 a
->avail
-= 2 * sizeof(jsval
);
619 * Need a new stack segment, so allocate and push a stack segment
620 * header from the 2 extra slots.
622 sh
= (JSStackHeader
*)sp
;
624 sh
->down
= cx
->stackHeaders
;
625 cx
->stackHeaders
= sh
;
630 * Store JSVAL_NULL using memset, to let compilers optimize as they see
631 * fit, in case a caller allocates and pushes GC-things one by one, which
632 * could nest a last-ditch GC that will scan this segment.
634 memset(sp
, 0, nslots
* sizeof(jsval
));
639 js_FreeStack(JSContext
*cx
, void *mark
)
644 /* Check for zero nslots allocation special case. */
648 /* We can assert because js_FreeStack always balances js_AllocStack. */
649 sh
= cx
->stackHeaders
;
652 /* If mark is in the current segment, reduce sh->nslots, else pop sh. */
653 slotdiff
= JS_UPTRDIFF(mark
, JS_STACK_SEGMENT(sh
)) / sizeof(jsval
);
654 if (slotdiff
< (jsuword
)sh
->nslots
)
655 sh
->nslots
= slotdiff
;
657 cx
->stackHeaders
= sh
->down
;
659 /* Release the stackPool space allocated since mark was set. */
660 JS_ARENA_RELEASE(&cx
->stackPool
, mark
);
664 js_GetScopeChain(JSContext
*cx
, JSStackFrame
*fp
)
666 JSObject
*obj
, *cursor
, *clonedChild
, *parent
;
667 JSTempValueRooter tvr
;
669 obj
= fp
->blockChain
;
672 * Don't force a call object for a lightweight function call, but do
673 * insist that there is a call object for a heavyweight function call.
675 JS_ASSERT(!fp
->fun
||
676 !(fp
->fun
->flags
& JSFUN_HEAVYWEIGHT
) ||
678 JS_ASSERT(fp
->scopeChain
);
679 return fp
->scopeChain
;
683 * We have one or more lexical scopes to reflect into fp->scopeChain, so
684 * make sure there's a call object at the current head of the scope chain,
685 * if this frame is a call frame.
687 if (fp
->fun
&& !fp
->callobj
) {
688 JS_ASSERT(OBJ_GET_CLASS(cx
, fp
->scopeChain
) != &js_BlockClass
||
689 OBJ_GET_PRIVATE(cx
, fp
->scopeChain
) != fp
);
690 if (!js_GetCallObject(cx
, fp
, fp
->scopeChain
))
695 * Clone the block chain. To avoid recursive cloning we set the parent of
696 * the cloned child after we clone the parent. In the following loop when
697 * clonedChild is null it indicates the first iteration when no special GC
698 * rooting is necessary. On the second and the following iterations we
699 * have to protect cloned so far chain against the GC during cloning of
705 parent
= OBJ_GET_PARENT(cx
, cursor
);
708 * We pass fp->scopeChain and not null even if we override the parent
709 * slot later as null triggers useless calculations of slot's value in
710 * js_NewObject that js_CloneBlockObject calls.
712 cursor
= js_CloneBlockObject(cx
, cursor
, fp
->scopeChain
, fp
);
715 JS_POP_TEMP_ROOT(cx
, &tvr
);
720 * The first iteration. Check if other follow and root obj if so
721 * to protect the whole cloned chain against GC.
726 JS_PUSH_TEMP_ROOT_OBJECT(cx
, obj
, &tvr
);
729 * Avoid OBJ_SET_PARENT overhead as clonedChild cannot escape to
732 STOBJ_SET_PARENT(clonedChild
, cursor
);
734 JS_ASSERT(tvr
.u
.value
== OBJECT_TO_JSVAL(obj
));
735 JS_POP_TEMP_ROOT(cx
, &tvr
);
739 clonedChild
= cursor
;
742 fp
->flags
|= JSFRAME_POP_BLOCKS
;
743 fp
->scopeChain
= obj
;
744 fp
->blockChain
= NULL
;
749 js_GetPrimitiveThis(JSContext
*cx
, jsval
*vp
, JSClass
*clasp
, jsval
*thisvp
)
755 if (JSVAL_IS_OBJECT(v
)) {
756 obj
= JS_THIS_OBJECT(cx
, vp
);
757 if (!JS_InstanceOf(cx
, obj
, clasp
, vp
+ 2))
759 v
= OBJ_GET_SLOT(cx
, obj
, JSSLOT_PRIVATE
);
766 * ECMA requires "the global object", but in embeddings such as the browser,
767 * which have multiple top-level objects (windows, frames, etc. in the DOM),
768 * we prefer fun's parent. An example that causes this code to run:
771 * function f() { return this }
772 * function g() { return f }
778 * The alert should display "true".
780 JS_STATIC_INTERPRET JSObject
*
781 js_ComputeGlobalThis(JSContext
*cx
, JSBool lazy
, jsval
*argv
)
785 if (JSVAL_IS_PRIMITIVE(argv
[-2]) ||
786 !OBJ_GET_PARENT(cx
, JSVAL_TO_OBJECT(argv
[-2]))) {
787 thisp
= cx
->globalObject
;
797 * Walk up the parent chain, first checking that the running script
798 * has access to the callee's parent object. Note that if lazy, the
799 * running script whose principals we want to check is the script
800 * associated with fp->down, not with fp.
802 * FIXME: 417851 -- this access check should not be required, as it
803 * imposes a performance penalty on all js_ComputeGlobalThis calls,
804 * and it represents a maintenance hazard.
806 fp
= js_GetTopStackFrame(cx
); /* quell GCC overwarning */
808 JS_ASSERT(fp
->argv
== argv
);
809 fp
->dormantNext
= cx
->dormantFrameChain
;
810 cx
->dormantFrameChain
= fp
;
814 thisp
= JSVAL_TO_OBJECT(argv
[-2]);
815 id
= ATOM_TO_JSID(cx
->runtime
->atomState
.parentAtom
);
817 ok
= OBJ_CHECK_ACCESS(cx
, thisp
, id
, JSACC_PARENT
, &v
, &attrs
);
819 cx
->dormantFrameChain
= fp
->dormantNext
;
820 fp
->dormantNext
= NULL
;
827 thisp
= JSVAL_IS_VOID(v
)
828 ? OBJ_GET_PARENT(cx
, thisp
)
829 : JSVAL_TO_OBJECT(v
);
830 while ((parent
= OBJ_GET_PARENT(cx
, thisp
)) != NULL
)
834 OBJ_TO_OUTER_OBJECT(cx
, thisp
);
837 argv
[-1] = OBJECT_TO_JSVAL(thisp
);
842 ComputeThis(JSContext
*cx
, JSBool lazy
, jsval
*argv
)
846 JS_ASSERT(!JSVAL_IS_NULL(argv
[-1]));
847 if (!JSVAL_IS_OBJECT(argv
[-1])) {
848 if (!js_PrimitiveToObject(cx
, &argv
[-1]))
850 thisp
= JSVAL_TO_OBJECT(argv
[-1]);
852 thisp
= JSVAL_TO_OBJECT(argv
[-1]);
853 if (OBJ_GET_CLASS(cx
, thisp
) == &js_CallClass
||
854 OBJ_GET_CLASS(cx
, thisp
) == &js_BlockClass
) {
855 return js_ComputeGlobalThis(cx
, lazy
, argv
);
858 if (thisp
->map
->ops
->thisObject
) {
859 /* Some objects (e.g., With) delegate 'this' to another object. */
860 thisp
= thisp
->map
->ops
->thisObject(cx
, thisp
);
864 OBJ_TO_OUTER_OBJECT(cx
, thisp
);
867 argv
[-1] = OBJECT_TO_JSVAL(thisp
);
873 js_ComputeThis(JSContext
*cx
, JSBool lazy
, jsval
*argv
)
875 if (JSVAL_IS_NULL(argv
[-1]))
876 return js_ComputeGlobalThis(cx
, lazy
, argv
);
877 return ComputeThis(cx
, lazy
, argv
);
880 #if JS_HAS_NO_SUCH_METHOD
882 #define JSSLOT_FOUND_FUNCTION JSSLOT_PRIVATE
883 #define JSSLOT_SAVED_ID (JSSLOT_PRIVATE + 1)
885 JSClass js_NoSuchMethodClass
= {
887 JSCLASS_HAS_RESERVED_SLOTS(2) | JSCLASS_IS_ANONYMOUS
|
888 JSCLASS_HAS_CACHED_PROTO(JSProto_NoSuchMethod
),
889 JS_PropertyStub
, JS_PropertyStub
, JS_PropertyStub
, JS_PropertyStub
,
890 JS_EnumerateStub
, JS_ResolveStub
, JS_ConvertStub
, JS_FinalizeStub
,
891 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
897 js_InitNoSuchMethodClass(JSContext
*cx
, JSObject
* obj
);
902 js_InitNoSuchMethodClass(JSContext
*cx
, JSObject
* obj
)
906 proto
= JS_InitClass(cx
, obj
, NULL
, &js_NoSuchMethodClass
, NULL
, 0, NULL
,
911 OBJ_CLEAR_PROTO(cx
, proto
);
916 * When JSOP_CALLPROP or JSOP_CALLELEM does not find the method property of
917 * the base object, we search for the __noSuchMethod__ method in the base.
918 * If it exists, we store the method and the property's id into an object of
919 * NoSuchMethod class and store this object into the callee's stack slot.
920 * Later, js_Invoke will recognise such an object and transfer control to
921 * NoSuchMethod that invokes the method like:
923 * this.__noSuchMethod__(id, args)
925 * where id is the name of the method that this invocation attempted to
926 * call by name, and args is an Array containing this invocation's actual
929 JS_STATIC_INTERPRET JSBool
930 js_OnUnknownMethod(JSContext
*cx
, jsval
*vp
)
934 JSTempValueRooter tvr
;
937 JS_ASSERT(!JSVAL_IS_PRIMITIVE(vp
[1]));
938 obj
= JSVAL_TO_OBJECT(vp
[1]);
939 JS_PUSH_SINGLE_TEMP_ROOT(cx
, JSVAL_NULL
, &tvr
);
941 MUST_FLOW_THROUGH("out");
942 id
= ATOM_TO_JSID(cx
->runtime
->atomState
.noSuchMethodAtom
);
943 #if JS_HAS_XML_SUPPORT
944 if (OBJECT_IS_XML(cx
, obj
)) {
947 ops
= (JSXMLObjectOps
*) obj
->map
->ops
;
948 obj
= ops
->getMethod(cx
, obj
, id
, &tvr
.u
.value
);
953 vp
[1] = OBJECT_TO_JSVAL(obj
);
957 ok
= OBJ_GET_PROPERTY(cx
, obj
, id
, &tvr
.u
.value
);
961 if (JSVAL_IS_PRIMITIVE(tvr
.u
.value
)) {
964 #if JS_HAS_XML_SUPPORT
965 /* Extract the function name from function::name qname. */
966 if (!JSVAL_IS_PRIMITIVE(vp
[0])) {
967 obj
= JSVAL_TO_OBJECT(vp
[0]);
968 ok
= js_IsFunctionQName(cx
, obj
, &id
);
972 vp
[0] = ID_TO_VALUE(id
);
975 obj
= js_NewObject(cx
, &js_NoSuchMethodClass
, NULL
, NULL
, 0);
980 obj
->fslots
[JSSLOT_FOUND_FUNCTION
] = tvr
.u
.value
;
981 obj
->fslots
[JSSLOT_SAVED_ID
] = vp
[0];
982 vp
[0] = OBJECT_TO_JSVAL(obj
);
987 JS_POP_TEMP_ROOT(cx
, &tvr
);
992 NoSuchMethod(JSContext
*cx
, uintN argc
, jsval
*vp
, uint32 flags
)
997 JSObject
*obj
, *argsobj
;
999 invokevp
= js_AllocStack(cx
, 2 + 2, &mark
);
1003 JS_ASSERT(!JSVAL_IS_PRIMITIVE(vp
[0]));
1004 JS_ASSERT(!JSVAL_IS_PRIMITIVE(vp
[1]));
1005 obj
= JSVAL_TO_OBJECT(vp
[0]);
1006 JS_ASSERT(STOBJ_GET_CLASS(obj
) == &js_NoSuchMethodClass
);
1008 invokevp
[0] = obj
->fslots
[JSSLOT_FOUND_FUNCTION
];
1009 invokevp
[1] = vp
[1];
1010 invokevp
[2] = obj
->fslots
[JSSLOT_SAVED_ID
];
1011 argsobj
= js_NewArrayObject(cx
, argc
, vp
+ 2);
1015 invokevp
[3] = OBJECT_TO_JSVAL(argsobj
);
1016 ok
= (flags
& JSINVOKE_CONSTRUCT
)
1017 ? js_InvokeConstructor(cx
, 2, JS_TRUE
, invokevp
)
1018 : js_Invoke(cx
, 2, invokevp
, flags
);
1019 vp
[0] = invokevp
[0];
1021 js_FreeStack(cx
, mark
);
1025 #endif /* JS_HAS_NO_SUCH_METHOD */
1028 * We check if the function accepts a primitive value as |this|. For that we
1029 * use a table that maps value's tag into the corresponding function flag.
1031 JS_STATIC_ASSERT(JSVAL_INT
== 1);
1032 JS_STATIC_ASSERT(JSVAL_DOUBLE
== 2);
1033 JS_STATIC_ASSERT(JSVAL_STRING
== 4);
1034 JS_STATIC_ASSERT(JSVAL_BOOLEAN
== 6);
1036 const uint16 js_PrimitiveTestFlags
[] = {
1037 JSFUN_THISP_NUMBER
, /* INT */
1038 JSFUN_THISP_NUMBER
, /* DOUBLE */
1039 JSFUN_THISP_NUMBER
, /* INT */
1040 JSFUN_THISP_STRING
, /* STRING */
1041 JSFUN_THISP_NUMBER
, /* INT */
1042 JSFUN_THISP_BOOLEAN
, /* BOOLEAN */
1043 JSFUN_THISP_NUMBER
/* INT */
1047 * Find a function reference and its 'this' object implicit first parameter
1048 * under argc arguments on cx's stack, and call the function. Push missing
1049 * required arguments, allocate declared local variables, and pop everything
1050 * when done. Then push the return value.
1052 JS_FRIEND_API(JSBool
)
1053 js_Invoke(JSContext
*cx
, uintN argc
, jsval
*vp
, uintN flags
)
1057 jsval
*sp
, *argv
, *newvp
;
1059 JSObject
*funobj
, *parent
;
1067 uint32 rootedArgsFlag
;
1068 JSInterpreterHook hook
;
1071 /* [vp .. vp + 2 + argc) must belong to the last JS stack arena. */
1072 JS_ASSERT((jsval
*) cx
->stackPool
.current
->base
<= vp
);
1073 JS_ASSERT(vp
+ 2 + argc
<= (jsval
*) cx
->stackPool
.current
->avail
);
1076 * Mark the top of stack and load frequently-used registers. After this
1077 * point the control should flow through label out2: to return.
1079 mark
= JS_ARENA_MARK(&cx
->stackPool
);
1082 if (JSVAL_IS_PRIMITIVE(v
))
1085 funobj
= JSVAL_TO_OBJECT(v
);
1086 parent
= OBJ_GET_PARENT(cx
, funobj
);
1087 clasp
= OBJ_GET_CLASS(cx
, funobj
);
1088 if (clasp
!= &js_FunctionClass
) {
1089 #if JS_HAS_NO_SUCH_METHOD
1090 if (clasp
== &js_NoSuchMethodClass
) {
1091 ok
= NoSuchMethod(cx
, argc
, vp
, flags
);
1096 /* Function is inlined, all other classes use object ops. */
1097 ops
= funobj
->map
->ops
;
1100 * XXX this makes no sense -- why convert to function if clasp->call?
1101 * XXX better to call that hook without converting
1102 * XXX the only thing that needs fixing is liveconnect
1104 * Try converting to function, for closure and API compatibility.
1105 * We attempt the conversion under all circumstances for 1.2, but
1106 * only if there is a call op defined otherwise.
1108 if ((ops
== &js_ObjectOps
) ? clasp
->call
: ops
->call
) {
1109 ok
= clasp
->convert(cx
, funobj
, JSTYPE_FUNCTION
, &v
);
1113 if (VALUE_IS_FUNCTION(cx
, v
)) {
1114 /* Make vp refer to funobj to keep it available as argv[-2]. */
1116 funobj
= JSVAL_TO_OBJECT(v
);
1117 parent
= OBJ_GET_PARENT(cx
, funobj
);
1125 /* Try a call or construct native object op. */
1126 if (flags
& JSINVOKE_CONSTRUCT
) {
1127 if (!JSVAL_IS_OBJECT(vp
[1])) {
1128 ok
= js_PrimitiveToObject(cx
, &vp
[1]);
1132 native
= ops
->construct
;
1140 /* Get private data and set derived locals from it. */
1141 fun
= GET_FUNCTION_PRIVATE(cx
, funobj
);
1142 nslots
= FUN_MINARGS(fun
);
1143 nslots
= (nslots
> argc
) ? nslots
- argc
: 0;
1144 if (FUN_INTERPRETED(fun
)) {
1146 script
= fun
->u
.i
.script
;
1148 native
= fun
->u
.n
.native
;
1150 nslots
+= fun
->u
.n
.extra
;
1153 if (JSFUN_BOUND_METHOD_TEST(fun
->flags
)) {
1154 /* Handle bound method special case. */
1155 vp
[1] = OBJECT_TO_JSVAL(parent
);
1156 } else if (!JSVAL_IS_OBJECT(vp
[1])) {
1157 JS_ASSERT(!(flags
& JSINVOKE_CONSTRUCT
));
1158 if (PRIMITIVE_THIS_TEST(fun
, vp
[1]))
1163 if (flags
& JSINVOKE_CONSTRUCT
) {
1164 JS_ASSERT(!JSVAL_IS_PRIMITIVE(vp
[1]));
1167 * We must call js_ComputeThis in case we are not called from the
1168 * interpreter, where a prior bytecode has computed an appropriate
1171 * But we need to compute |this| eagerly only for so-called "slow"
1172 * (i.e., not fast) native functions. Fast natives must use either
1173 * JS_THIS or JS_THIS_OBJECT, and scripted functions will go through
1174 * the appropriate this-computing bytecode, e.g., JSOP_THIS.
1176 if (native
&& (!fun
|| !(fun
->flags
& JSFUN_FAST_NATIVE
))) {
1177 if (!js_ComputeThis(cx
, JS_FALSE
, vp
+ 2)) {
1181 flags
|= JSFRAME_COMPUTED_THIS
;
1186 if (native
&& fun
&& (fun
->flags
& JSFUN_FAST_NATIVE
)) {
1187 #ifdef DEBUG_NOT_THROWING
1188 JSBool alreadyThrowing
= cx
->throwing
;
1190 JS_ASSERT(nslots
== 0);
1191 #if JS_HAS_LVALUE_RETURN
1192 /* Set by JS_SetCallReturnValue2, used to return reference types. */
1193 cx
->rval2set
= JS_FALSE
;
1195 ok
= ((JSFastNative
) native
)(cx
, argc
, vp
);
1196 JS_RUNTIME_METER(cx
->runtime
, nativeCalls
);
1197 #ifdef DEBUG_NOT_THROWING
1198 if (ok
&& !alreadyThrowing
)
1199 ASSERT_NOT_THROWING(cx
);
1207 rootedArgsFlag
= JSFRAME_ROOTED_ARGV
;
1210 * The extra slots required by the function continue with argument
1211 * slots. Thus, when the last stack pool arena does not have room to
1212 * fit nslots right after sp and AllocateAfterSP fails, we have to copy
1213 * [vp..vp+2+argc) slots and clear rootedArgsFlag to root the copy.
1215 if (!AllocateAfterSP(cx
, sp
, nslots
)) {
1217 newvp
= js_AllocRawStack(cx
, 2 + argc
+ nslots
, NULL
);
1222 memcpy(newvp
, vp
, (2 + argc
) * sizeof(jsval
));
1227 /* Push void to initialize missing args. */
1234 /* Allocate space for local variables and stack of interpreted function. */
1235 if (script
&& script
->nslots
!= 0) {
1236 if (!AllocateAfterSP(cx
, sp
, script
->nslots
)) {
1237 /* NB: Discontinuity between argv and slots, stack slots. */
1238 sp
= js_AllocRawStack(cx
, script
->nslots
, NULL
);
1245 /* Push void to initialize local variables. */
1246 for (jsval
*end
= sp
+ fun
->u
.i
.nvars
; sp
!= end
; ++sp
)
1251 * Initialize the frame.
1253 * To set thisp we use an explicit cast and not JSVAL_TO_OBJECT, as vp[1]
1254 * can be a primitive value here for those native functions specified with
1255 * JSFUN_THISP_(NUMBER|STRING|BOOLEAN) flags.
1257 frame
.thisp
= (JSObject
*)vp
[1];
1258 frame
.varobj
= NULL
;
1259 frame
.callobj
= frame
.argsobj
= NULL
;
1260 frame
.script
= script
;
1261 frame
.callee
= funobj
;
1266 /* Default return value for a constructor is the new object. */
1267 frame
.rval
= (flags
& JSINVOKE_CONSTRUCT
) ? vp
[1] : JSVAL_VOID
;
1268 frame
.down
= js_GetTopStackFrame(cx
);
1269 frame
.annotation
= NULL
;
1270 frame
.scopeChain
= NULL
; /* set below for real, after cx->fp is set */
1272 frame
.imacpc
= NULL
;
1274 frame
.sharpDepth
= 0;
1275 frame
.sharpArray
= NULL
;
1276 frame
.flags
= flags
| rootedArgsFlag
;
1277 frame
.dormantNext
= NULL
;
1278 frame
.xmlNamespace
= NULL
;
1279 frame
.blockChain
= NULL
;
1281 MUST_FLOW_THROUGH("out");
1284 /* Init these now in case we goto out before first hook call. */
1285 hook
= cx
->debugHooks
->callHook
;
1288 /* call the hook if present */
1289 if (hook
&& (native
|| script
))
1290 hookData
= hook(cx
, &frame
, JS_TRUE
, 0, cx
->debugHooks
->callHookData
);
1292 /* Call the function, either a native method or an interpreted script. */
1294 #ifdef DEBUG_NOT_THROWING
1295 JSBool alreadyThrowing
= cx
->throwing
;
1298 #if JS_HAS_LVALUE_RETURN
1299 /* Set by JS_SetCallReturnValue2, used to return reference types. */
1300 cx
->rval2set
= JS_FALSE
;
1303 /* If native, use caller varobj and scopeChain for eval. */
1304 JS_ASSERT(!frame
.varobj
);
1305 JS_ASSERT(!frame
.scopeChain
);
1307 frame
.varobj
= frame
.down
->varobj
;
1308 frame
.scopeChain
= frame
.down
->scopeChain
;
1311 /* But ensure that we have a scope chain. */
1312 if (!frame
.scopeChain
)
1313 frame
.scopeChain
= parent
;
1315 frame
.displaySave
= NULL
;
1316 ok
= native(cx
, frame
.thisp
, argc
, frame
.argv
, &frame
.rval
);
1317 JS_RUNTIME_METER(cx
->runtime
, nativeCalls
);
1318 #ifdef DEBUG_NOT_THROWING
1319 if (ok
&& !alreadyThrowing
)
1320 ASSERT_NOT_THROWING(cx
);
1322 } else if (script
) {
1323 /* Use parent scope so js_GetCallObject can find the right "Call". */
1324 frame
.scopeChain
= parent
;
1325 if (JSFUN_HEAVYWEIGHT_TEST(fun
->flags
)) {
1326 /* Scope with a call object parented by the callee's parent. */
1327 if (!js_GetCallObject(cx
, &frame
, parent
)) {
1332 frame
.slots
= sp
- fun
->u
.i
.nvars
;
1334 ok
= js_Interpret(cx
);
1336 /* fun might be onerror trying to report a syntax error in itself. */
1337 frame
.scopeChain
= NULL
;
1338 frame
.displaySave
= NULL
;
1344 hook
= cx
->debugHooks
->callHook
;
1346 hook(cx
, &frame
, JS_FALSE
, &ok
, hookData
);
1349 /* If frame has a call object, sync values and clear back-pointer. */
1351 ok
&= js_PutCallObject(cx
, &frame
);
1353 /* If frame has an arguments object, sync values and clear back-pointer. */
1355 ok
&= js_PutArgsObject(cx
, &frame
);
1359 /* Restore cx->fp now that we're done releasing frame objects. */
1360 cx
->fp
= frame
.down
;
1363 /* Pop everything we may have allocated off the stack. */
1364 JS_ARENA_RELEASE(&cx
->stackPool
, mark
);
1370 js_ReportIsNotFunction(cx
, vp
, flags
& JSINVOKE_FUNFLAGS
);
1376 js_InternalInvoke(JSContext
*cx
, JSObject
*obj
, jsval fval
, uintN flags
,
1377 uintN argc
, jsval
*argv
, jsval
*rval
)
1383 invokevp
= js_AllocStack(cx
, 2 + argc
, &mark
);
1388 invokevp
[1] = OBJECT_TO_JSVAL(obj
);
1389 memcpy(invokevp
+ 2, argv
, argc
* sizeof *argv
);
1391 ok
= js_Invoke(cx
, argc
, invokevp
, flags
);
1394 * Store *rval in the a scoped local root if a scope is open, else in
1395 * the lastInternalResult pigeon-hole GC root, solely so users of
1396 * js_InternalInvoke and its direct and indirect (js_ValueToString for
1397 * example) callers do not need to manage roots for local, temporary
1398 * references to such results.
1401 if (JSVAL_IS_GCTHING(*rval
) && *rval
!= JSVAL_NULL
) {
1402 if (cx
->localRootStack
) {
1403 if (js_PushLocalRoot(cx
, cx
->localRootStack
, *rval
) < 0)
1406 cx
->weakRoots
.lastInternalResult
= *rval
;
1411 js_FreeStack(cx
, mark
);
1416 js_InternalGetOrSet(JSContext
*cx
, JSObject
*obj
, jsid id
, jsval fval
,
1417 JSAccessMode mode
, uintN argc
, jsval
*argv
, jsval
*rval
)
1419 JSSecurityCallbacks
*callbacks
;
1422 * js_InternalInvoke could result in another try to get or set the same id
1423 * again, see bug 355497.
1425 JS_CHECK_RECURSION(cx
, return JS_FALSE
);
1428 * Check general (not object-ops/class-specific) access from the running
1429 * script to obj.id only if id has a scripted getter or setter that we're
1430 * about to invoke. If we don't check this case, nothing else will -- no
1431 * other native code has the chance to check.
1433 * Contrast this non-native (scripted) case with native getter and setter
1434 * accesses, where the native itself must do an access check, if security
1435 * policies requires it. We make a checkAccess or checkObjectAccess call
1436 * back to the embedding program only in those cases where we're not going
1437 * to call an embedding-defined native function, getter, setter, or class
1438 * hook anyway. Where we do call such a native, there's no need for the
1439 * engine to impose a separate access check callback on all embeddings --
1440 * many embeddings have no security policy at all.
1442 JS_ASSERT(mode
== JSACC_READ
|| mode
== JSACC_WRITE
);
1443 callbacks
= JS_GetSecurityCallbacks(cx
);
1445 callbacks
->checkObjectAccess
&&
1446 VALUE_IS_FUNCTION(cx
, fval
) &&
1447 FUN_INTERPRETED(GET_FUNCTION_PRIVATE(cx
, JSVAL_TO_OBJECT(fval
))) &&
1448 !callbacks
->checkObjectAccess(cx
, obj
, ID_TO_VALUE(id
), mode
, &fval
)) {
1452 return js_InternalCall(cx
, obj
, fval
, argc
, argv
, rval
);
1456 js_Execute(JSContext
*cx
, JSObject
*chain
, JSScript
*script
,
1457 JSStackFrame
*down
, uintN flags
, jsval
*result
)
1459 JSInterpreterHook hook
;
1460 void *hookData
, *mark
;
1461 JSStackFrame
*oldfp
, frame
;
1462 JSObject
*obj
, *tmp
;
1465 #ifdef INCLUDE_MOZILLA_DTRACE
1466 if (JAVASCRIPT_EXECUTE_START_ENABLED())
1467 jsdtrace_execute_start(script
);
1470 hook
= cx
->debugHooks
->executeHook
;
1471 hookData
= mark
= NULL
;
1472 oldfp
= js_GetTopStackFrame(cx
);
1473 frame
.script
= script
;
1475 /* Propagate arg state for eval and the debugger API. */
1476 frame
.callobj
= down
->callobj
;
1477 frame
.argsobj
= down
->argsobj
;
1478 frame
.varobj
= down
->varobj
;
1479 frame
.callee
= down
->callee
;
1480 frame
.fun
= down
->fun
;
1481 frame
.thisp
= down
->thisp
;
1482 if (down
->flags
& JSFRAME_COMPUTED_THIS
)
1483 flags
|= JSFRAME_COMPUTED_THIS
;
1484 frame
.argc
= down
->argc
;
1485 frame
.argv
= down
->argv
;
1486 frame
.annotation
= down
->annotation
;
1487 frame
.sharpArray
= down
->sharpArray
;
1488 JS_ASSERT(script
->nfixed
== 0);
1490 frame
.callobj
= frame
.argsobj
= NULL
;
1492 if (cx
->options
& JSOPTION_VAROBJFIX
) {
1493 while ((tmp
= OBJ_GET_PARENT(cx
, obj
)) != NULL
)
1497 frame
.callee
= NULL
;
1499 frame
.thisp
= chain
;
1502 frame
.annotation
= NULL
;
1503 frame
.sharpArray
= NULL
;
1506 frame
.imacpc
= NULL
;
1507 if (script
->nslots
!= 0) {
1508 frame
.slots
= js_AllocRawStack(cx
, script
->nslots
, &mark
);
1513 memset(frame
.slots
, 0, script
->nfixed
* sizeof(jsval
));
1518 frame
.rval
= JSVAL_VOID
;
1520 frame
.scopeChain
= chain
;
1522 frame
.sharpDepth
= 0;
1523 frame
.flags
= flags
;
1524 frame
.dormantNext
= NULL
;
1525 frame
.xmlNamespace
= NULL
;
1526 frame
.blockChain
= NULL
;
1529 * Here we wrap the call to js_Interpret with code to (conditionally)
1530 * save and restore the old stack frame chain into a chain of 'dormant'
1531 * frame chains. Since we are replacing cx->fp, we were running into
1532 * the problem that if GC was called under this frame, some of the GC
1533 * things associated with the old frame chain (available here only in
1534 * the C variable 'oldfp') were not rooted and were being collected.
1536 * So, now we preserve the links to these 'dormant' frame chains in cx
1537 * before calling js_Interpret and cleanup afterwards. The GC walks
1538 * these dormant chains and marks objects in the same way that it marks
1539 * objects in the primary cx->fp chain.
1541 if (oldfp
&& oldfp
!= down
) {
1542 JS_ASSERT(!oldfp
->dormantNext
);
1543 oldfp
->dormantNext
= cx
->dormantFrameChain
;
1544 cx
->dormantFrameChain
= oldfp
;
1549 OBJ_TO_OUTER_OBJECT(cx
, frame
.thisp
);
1554 frame
.flags
|= JSFRAME_COMPUTED_THIS
;
1558 hookData
= hook(cx
, &frame
, JS_TRUE
, 0,
1559 cx
->debugHooks
->executeHookData
);
1562 ok
= js_Interpret(cx
);
1564 *result
= frame
.rval
;
1567 hook
= cx
->debugHooks
->executeHook
;
1569 hook(cx
, &frame
, JS_FALSE
, &ok
, hookData
);
1574 js_FreeRawStack(cx
, mark
);
1577 if (oldfp
&& oldfp
!= down
) {
1578 JS_ASSERT(cx
->dormantFrameChain
== oldfp
);
1579 cx
->dormantFrameChain
= oldfp
->dormantNext
;
1580 oldfp
->dormantNext
= NULL
;
1584 #ifdef INCLUDE_MOZILLA_DTRACE
1585 if (JAVASCRIPT_EXECUTE_DONE_ENABLED())
1586 jsdtrace_execute_done(script
);
1592 js_CheckRedeclaration(JSContext
*cx
, JSObject
*obj
, jsid id
, uintN attrs
,
1593 JSObject
**objp
, JSProperty
**propp
)
1597 uintN oldAttrs
, report
;
1600 const char *type
, *name
;
1602 if (!OBJ_LOOKUP_PROPERTY(cx
, obj
, id
, &obj2
, &prop
))
1612 * Use prop as a speedup hint to OBJ_GET_ATTRIBUTES, but drop it on error.
1613 * An assertion at label bad: will insist that it is null.
1615 if (!OBJ_GET_ATTRIBUTES(cx
, obj2
, id
, prop
, &oldAttrs
)) {
1616 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
1624 * From here, return true, or else goto bad on failure to null out params.
1625 * If our caller doesn't want prop, drop it (we don't need it any longer).
1628 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
1632 if (attrs
== JSPROP_INITIALIZER
) {
1633 /* Allow the new object to override properties. */
1636 report
= JSREPORT_WARNING
| JSREPORT_STRICT
;
1638 /* We allow redeclaring some non-readonly properties. */
1639 if (((oldAttrs
| attrs
) & JSPROP_READONLY
) == 0) {
1641 * Allow redeclaration of variables and functions, but insist that
1642 * the new value is not a getter if the old value was, ditto for
1643 * setters -- unless prop is impermanent (in which case anyone
1644 * could delete it and redefine it, willy-nilly).
1646 if (!(attrs
& (JSPROP_GETTER
| JSPROP_SETTER
)))
1648 if ((~(oldAttrs
^ attrs
) & (JSPROP_GETTER
| JSPROP_SETTER
)) == 0)
1650 if (!(oldAttrs
& JSPROP_PERMANENT
))
1654 report
= JSREPORT_ERROR
;
1655 isFunction
= (oldAttrs
& (JSPROP_GETTER
| JSPROP_SETTER
)) != 0;
1657 if (!OBJ_GET_PROPERTY(cx
, obj
, id
, &value
))
1659 isFunction
= VALUE_IS_FUNCTION(cx
, value
);
1663 type
= (attrs
== JSPROP_INITIALIZER
)
1665 : (oldAttrs
& attrs
& JSPROP_GETTER
)
1667 : (oldAttrs
& attrs
& JSPROP_SETTER
)
1669 : (oldAttrs
& JSPROP_READONLY
)
1674 name
= js_ValueToPrintableString(cx
, ID_TO_VALUE(id
));
1677 return JS_ReportErrorFlagsAndNumber(cx
, report
,
1678 js_GetErrorMessage
, NULL
,
1679 JSMSG_REDECLARED_VAR
,
1692 js_StrictlyEqual(JSContext
*cx
, jsval lval
, jsval rval
)
1694 jsval ltag
= JSVAL_TAG(lval
), rtag
= JSVAL_TAG(rval
);
1698 if (ltag
== JSVAL_STRING
) {
1699 JSString
*lstr
= JSVAL_TO_STRING(lval
),
1700 *rstr
= JSVAL_TO_STRING(rval
);
1701 return js_EqualStrings(lstr
, rstr
);
1703 if (ltag
== JSVAL_DOUBLE
) {
1704 ld
= *JSVAL_TO_DOUBLE(lval
);
1705 rd
= *JSVAL_TO_DOUBLE(rval
);
1706 return JSDOUBLE_COMPARE(ld
, ==, rd
, JS_FALSE
);
1708 if (ltag
== JSVAL_OBJECT
&&
1710 !JSVAL_IS_NULL(lval
) &&
1711 !JSVAL_IS_NULL(rval
)) {
1712 JSObject
*lobj
, *robj
;
1714 lobj
= js_GetWrappedObject(cx
, JSVAL_TO_OBJECT(lval
));
1715 robj
= js_GetWrappedObject(cx
, JSVAL_TO_OBJECT(rval
));
1716 lval
= OBJECT_TO_JSVAL(lobj
);
1717 rval
= OBJECT_TO_JSVAL(robj
);
1719 return lval
== rval
;
1721 if (ltag
== JSVAL_DOUBLE
&& JSVAL_IS_INT(rval
)) {
1722 ld
= *JSVAL_TO_DOUBLE(lval
);
1723 rd
= JSVAL_TO_INT(rval
);
1724 return JSDOUBLE_COMPARE(ld
, ==, rd
, JS_FALSE
);
1726 if (JSVAL_IS_INT(lval
) && rtag
== JSVAL_DOUBLE
) {
1727 ld
= JSVAL_TO_INT(lval
);
1728 rd
= *JSVAL_TO_DOUBLE(rval
);
1729 return JSDOUBLE_COMPARE(ld
, ==, rd
, JS_FALSE
);
1731 return lval
== rval
;
1735 js_InvokeConstructor(JSContext
*cx
, uintN argc
, JSBool clampReturn
, jsval
*vp
)
1737 JSFunction
*fun
, *fun2
;
1738 JSObject
*obj
, *obj2
, *proto
, *parent
;
1745 if (!JSVAL_IS_OBJECT(lval
) ||
1746 (obj2
= JSVAL_TO_OBJECT(lval
)) == NULL
||
1747 /* XXX clean up to avoid special cases above ObjectOps layer */
1748 OBJ_GET_CLASS(cx
, obj2
) == &js_FunctionClass
||
1749 !obj2
->map
->ops
->construct
)
1751 fun
= js_ValueToFunction(cx
, vp
, JSV2F_CONSTRUCT
);
1756 clasp
= &js_ObjectClass
;
1758 proto
= parent
= NULL
;
1762 * Get the constructor prototype object for this function.
1763 * Use the nominal 'this' parameter slot, vp[1], as a local
1764 * root to protect this prototype, in case it has no other
1767 if (!OBJ_GET_PROPERTY(cx
, obj2
,
1768 ATOM_TO_JSID(cx
->runtime
->atomState
1769 .classPrototypeAtom
),
1774 proto
= JSVAL_IS_OBJECT(rval
) ? JSVAL_TO_OBJECT(rval
) : NULL
;
1775 parent
= OBJ_GET_PARENT(cx
, obj2
);
1777 if (OBJ_GET_CLASS(cx
, obj2
) == &js_FunctionClass
) {
1778 fun2
= GET_FUNCTION_PRIVATE(cx
, obj2
);
1779 if (!FUN_INTERPRETED(fun2
) &&
1780 !(fun2
->flags
& JSFUN_TRACEABLE
) &&
1781 fun2
->u
.n
.u
.clasp
) {
1782 clasp
= fun2
->u
.n
.u
.clasp
;
1786 obj
= js_NewObject(cx
, clasp
, proto
, parent
, 0);
1790 /* Now we have an object with a constructor method; call it. */
1791 vp
[1] = OBJECT_TO_JSVAL(obj
);
1792 if (!js_Invoke(cx
, argc
, vp
, JSINVOKE_CONSTRUCT
)) {
1793 cx
->weakRoots
.newborn
[GCX_OBJECT
] = NULL
;
1797 /* Check the return value and if it's primitive, force it to be obj. */
1799 if (clampReturn
&& JSVAL_IS_PRIMITIVE(rval
)) {
1801 /* native [[Construct]] returning primitive is error */
1802 JS_ReportErrorNumber(cx
, js_GetErrorMessage
, NULL
,
1803 JSMSG_BAD_NEW_RESULT
,
1804 js_ValueToPrintableString(cx
, rval
));
1807 *vp
= OBJECT_TO_JSVAL(obj
);
1810 JS_RUNTIME_METER(cx
->runtime
, constructs
);
1815 js_InternNonIntElementId(JSContext
*cx
, JSObject
*obj
, jsval idval
, jsid
*idp
)
1817 JS_ASSERT(!JSVAL_IS_INT(idval
));
1819 #if JS_HAS_XML_SUPPORT
1820 if (!JSVAL_IS_PRIMITIVE(idval
)) {
1821 if (OBJECT_IS_XML(cx
, obj
)) {
1822 *idp
= OBJECT_JSVAL_TO_JSID(idval
);
1825 if (!js_IsFunctionQName(cx
, JSVAL_TO_OBJECT(idval
), idp
))
1832 return js_ValueToStringId(cx
, idval
, idp
);
1836 * Enter the new with scope using an object at sp[-1] and associate the depth
1837 * of the with block with sp + stackIndex.
1839 JS_STATIC_INTERPRET JS_REQUIRES_STACK JSBool
1840 js_EnterWith(JSContext
*cx
, jsint stackIndex
)
1844 JSObject
*obj
, *parent
, *withobj
;
1848 JS_ASSERT(stackIndex
< 0);
1849 JS_ASSERT(StackBase(fp
) <= sp
+ stackIndex
);
1851 if (!JSVAL_IS_PRIMITIVE(sp
[-1])) {
1852 obj
= JSVAL_TO_OBJECT(sp
[-1]);
1854 obj
= js_ValueToNonNullObject(cx
, sp
[-1]);
1857 sp
[-1] = OBJECT_TO_JSVAL(obj
);
1860 parent
= js_GetScopeChain(cx
, fp
);
1864 OBJ_TO_INNER_OBJECT(cx
, obj
);
1868 withobj
= js_NewWithObject(cx
, obj
, parent
,
1869 sp
+ stackIndex
- StackBase(fp
));
1873 fp
->scopeChain
= withobj
;
1874 js_DisablePropertyCache(cx
);
1878 JS_STATIC_INTERPRET JS_REQUIRES_STACK
void
1879 js_LeaveWith(JSContext
*cx
)
1883 withobj
= cx
->fp
->scopeChain
;
1884 JS_ASSERT(OBJ_GET_CLASS(cx
, withobj
) == &js_WithClass
);
1885 JS_ASSERT(OBJ_GET_PRIVATE(cx
, withobj
) == cx
->fp
);
1886 JS_ASSERT(OBJ_BLOCK_DEPTH(cx
, withobj
) >= 0);
1887 cx
->fp
->scopeChain
= OBJ_GET_PARENT(cx
, withobj
);
1888 JS_SetPrivate(cx
, withobj
, NULL
);
1889 js_EnablePropertyCache(cx
);
1892 JS_REQUIRES_STACK JSClass
*
1893 js_IsActiveWithOrBlock(JSContext
*cx
, JSObject
*obj
, int stackDepth
)
1897 clasp
= OBJ_GET_CLASS(cx
, obj
);
1898 if ((clasp
== &js_WithClass
|| clasp
== &js_BlockClass
) &&
1899 OBJ_GET_PRIVATE(cx
, obj
) == cx
->fp
&&
1900 OBJ_BLOCK_DEPTH(cx
, obj
) >= stackDepth
) {
1906 JS_STATIC_INTERPRET JS_REQUIRES_STACK jsint
1907 js_CountWithBlocks(JSContext
*cx
, JSStackFrame
*fp
)
1914 for (obj
= fp
->scopeChain
;
1915 (clasp
= js_IsActiveWithOrBlock(cx
, obj
, 0)) != NULL
;
1916 obj
= OBJ_GET_PARENT(cx
, obj
)) {
1917 if (clasp
== &js_WithClass
)
1924 * Unwind block and scope chains to match the given depth. The function sets
1925 * fp->sp on return to stackDepth.
1927 JS_REQUIRES_STACK JSBool
1928 js_UnwindScope(JSContext
*cx
, JSStackFrame
*fp
, jsint stackDepth
,
1929 JSBool normalUnwind
)
1934 JS_ASSERT(stackDepth
>= 0);
1935 JS_ASSERT(StackBase(fp
) + stackDepth
<= fp
->regs
->sp
);
1937 for (obj
= fp
->blockChain
; obj
; obj
= OBJ_GET_PARENT(cx
, obj
)) {
1938 JS_ASSERT(OBJ_GET_CLASS(cx
, obj
) == &js_BlockClass
);
1939 if (OBJ_BLOCK_DEPTH(cx
, obj
) < stackDepth
)
1942 fp
->blockChain
= obj
;
1945 obj
= fp
->scopeChain
;
1946 clasp
= js_IsActiveWithOrBlock(cx
, obj
, stackDepth
);
1949 if (clasp
== &js_BlockClass
) {
1950 /* Don't fail until after we've updated all stacks. */
1951 normalUnwind
&= js_PutBlockObject(cx
, normalUnwind
);
1957 fp
->regs
->sp
= StackBase(fp
) + stackDepth
;
1958 return normalUnwind
;
1961 JS_STATIC_INTERPRET JSBool
1962 js_DoIncDec(JSContext
*cx
, const JSCodeSpec
*cs
, jsval
*vp
, jsval
*vp2
)
1968 if (JSVAL_IS_DOUBLE(v
)) {
1969 d
= *JSVAL_TO_DOUBLE(v
);
1970 } else if (JSVAL_IS_INT(v
)) {
1971 d
= JSVAL_TO_INT(v
);
1973 d
= js_ValueToNumber(cx
, vp
);
1974 if (JSVAL_IS_NULL(*vp
))
1976 JS_ASSERT(JSVAL_IS_NUMBER(*vp
) || *vp
== JSVAL_TRUE
);
1978 /* Store the result of v conversion back in vp for post increments. */
1979 if ((cs
->format
& JOF_POST
) &&
1981 && !js_NewNumberInRootedValue(cx
, d
, vp
)) {
1986 (cs
->format
& JOF_INC
) ? d
++ : d
--;
1987 if (!js_NewNumberInRootedValue(cx
, d
, vp2
))
1990 if (!(cs
->format
& JOF_POST
))
1997 JS_STATIC_INTERPRET JS_REQUIRES_STACK
void
1998 js_TraceOpcode(JSContext
*cx
, jsint len
)
2004 intN ndefs
, n
, nuses
;
2009 tracefp
= (FILE *) cx
->tracefp
;
2014 prevop
= (JSOp
) regs
->pc
[-len
];
2015 ndefs
= js_CodeSpec
[prevop
].ndefs
;
2017 for (n
= -ndefs
; n
< 0; n
++) {
2018 char *bytes
= js_DecompileValueGenerator(cx
, n
, regs
->sp
[n
],
2021 fprintf(tracefp
, "%s %s",
2022 (n
== -ndefs
) ? " output:" : ",",
2027 fprintf(tracefp
, " @ %u\n", (uintN
) (regs
->sp
- StackBase(fp
)));
2029 fprintf(tracefp
, " stack: ");
2030 for (siter
= StackBase(fp
); siter
< regs
->sp
; siter
++) {
2031 str
= js_ValueToString(cx
, *siter
);
2033 fputs("<null>", tracefp
);
2035 js_FileEscapedString(tracefp
, str
, 0);
2036 fputc(' ', tracefp
);
2038 fputc('\n', tracefp
);
2041 fprintf(tracefp
, "%4u: ",
2042 js_PCToLineNumber(cx
, fp
->script
, fp
->imacpc
? fp
->imacpc
: regs
->pc
));
2043 js_Disassemble1(cx
, fp
->script
, regs
->pc
,
2044 PTRDIFF(regs
->pc
, fp
->script
->code
, jsbytecode
),
2046 op
= (JSOp
) *regs
->pc
;
2047 nuses
= js_CodeSpec
[op
].nuses
;
2049 for (n
= -nuses
; n
< 0; n
++) {
2050 char *bytes
= js_DecompileValueGenerator(cx
, n
, regs
->sp
[n
],
2053 fprintf(tracefp
, "%s %s",
2054 (n
== -nuses
) ? " inputs:" : ",",
2059 fprintf(tracefp
, " @ %u\n", (uintN
) (regs
->sp
- StackBase(fp
)));
2067 # include <stdlib.h>
2069 # define HIST_NSLOTS 8
2072 * The second dimension is hardcoded at 256 because we know that many bits fit
2073 * in a byte, and mainly to optimize away multiplying by JSOP_LIMIT to address
2074 * any particular row.
2076 static uint32 succeeds
[JSOP_LIMIT
][256];
2077 static uint32 slot_ops
[JSOP_LIMIT
][HIST_NSLOTS
];
2079 JS_STATIC_INTERPRET
void
2080 js_MeterOpcodePair(JSOp op1
, JSOp op2
)
2082 if (op1
!= JSOP_STOP
)
2083 ++succeeds
[op1
][op2
];
2086 JS_STATIC_INTERPRET
void
2087 js_MeterSlotOpcode(JSOp op
, uint32 slot
)
2089 if (slot
< HIST_NSLOTS
)
2090 ++slot_ops
[op
][slot
];
2093 typedef struct Edge
{
2100 compare_edges(const void *a
, const void *b
)
2102 const Edge
*ea
= (const Edge
*) a
;
2103 const Edge
*eb
= (const Edge
*) b
;
2105 return (int32
)eb
->count
- (int32
)ea
->count
;
2111 const char *name
, *from
, *style
;
2113 uint32 total
, count
;
2114 uint32 i
, j
, nedges
;
2117 name
= getenv("JS_OPMETER_FILE");
2119 name
= "/tmp/ops.dot";
2120 fp
= fopen(name
, "w");
2127 for (i
= 0; i
< JSOP_LIMIT
; i
++) {
2128 for (j
= 0; j
< JSOP_LIMIT
; j
++) {
2129 count
= succeeds
[i
][j
];
2137 # define SIGNIFICANT(count,total) (200. * (count) >= (total))
2139 graph
= (Edge
*) calloc(nedges
, sizeof graph
[0]);
2140 for (i
= nedges
= 0; i
< JSOP_LIMIT
; i
++) {
2141 from
= js_CodeName
[i
];
2142 for (j
= 0; j
< JSOP_LIMIT
; j
++) {
2143 count
= succeeds
[i
][j
];
2144 if (count
!= 0 && SIGNIFICANT(count
, total
)) {
2145 graph
[nedges
].from
= from
;
2146 graph
[nedges
].to
= js_CodeName
[j
];
2147 graph
[nedges
].count
= count
;
2152 qsort(graph
, nedges
, sizeof(Edge
), compare_edges
);
2156 fputs("digraph {\n", fp
);
2157 for (i
= 0, style
= NULL
; i
< nedges
; i
++) {
2158 JS_ASSERT(i
== 0 || graph
[i
-1].count
>= graph
[i
].count
);
2159 if (!style
|| graph
[i
-1].count
!= graph
[i
].count
) {
2160 style
= (i
> nedges
* .75) ? "dotted" :
2161 (i
> nedges
* .50) ? "dashed" :
2162 (i
> nedges
* .25) ? "solid" : "bold";
2164 fprintf(fp
, " %s -> %s [label=\"%lu\" style=%s]\n",
2165 graph
[i
].from
, graph
[i
].to
,
2166 (unsigned long)graph
[i
].count
, style
);
2172 name
= getenv("JS_OPMETER_HIST");
2174 name
= "/tmp/ops.hist";
2175 fp
= fopen(name
, "w");
2180 fputs("bytecode", fp
);
2181 for (j
= 0; j
< HIST_NSLOTS
; j
++)
2182 fprintf(fp
, " slot %1u", (unsigned)j
);
2184 fputs("========", fp
);
2185 for (j
= 0; j
< HIST_NSLOTS
; j
++)
2186 fputs(" =======", fp
);
2188 for (i
= 0; i
< JSOP_LIMIT
; i
++) {
2189 for (j
= 0; j
< HIST_NSLOTS
; j
++) {
2190 if (slot_ops
[i
][j
] != 0) {
2191 /* Reuse j in the next loop, since we break after. */
2192 fprintf(fp
, "%-8.8s", js_CodeName
[i
]);
2193 for (j
= 0; j
< HIST_NSLOTS
; j
++)
2194 fprintf(fp
, " %7lu", (unsigned long)slot_ops
[i
][j
]);
2203 #endif /* JS_OPSMETER */
2205 #endif /* !JS_LONE_INTERPRET ^ defined jsinvoke_cpp___ */
2207 #ifndef jsinvoke_cpp___
2209 #define PUSH(v) (*regs.sp++ = (v))
2210 #define PUSH_OPND(v) PUSH(v)
2211 #define STORE_OPND(n,v) (regs.sp[n] = (v))
2212 #define POP() (*--regs.sp)
2213 #define POP_OPND() POP()
2214 #define FETCH_OPND(n) (regs.sp[n])
2217 * Push the jsdouble d using sp from the lexical environment. Try to convert d
2218 * to a jsint that fits in a jsval, otherwise GC-alloc space for it and push a
2221 #define STORE_NUMBER(cx, n, d) \
2225 if (JSDOUBLE_IS_INT(d, i_) && INT_FITS_IN_JSVAL(i_)) \
2226 regs.sp[n] = INT_TO_JSVAL(i_); \
2227 else if (!js_NewDoubleInRootedValue(cx, d, ®s.sp[n])) \
2231 #define STORE_INT(cx, n, i) \
2233 if (INT_FITS_IN_JSVAL(i)) \
2234 regs.sp[n] = INT_TO_JSVAL(i); \
2235 else if (!js_NewDoubleInRootedValue(cx, (jsdouble) (i), ®s.sp[n])) \
2239 #define STORE_UINT(cx, n, u) \
2241 if ((u) <= JSVAL_INT_MAX) \
2242 regs.sp[n] = INT_TO_JSVAL(u); \
2243 else if (!js_NewDoubleInRootedValue(cx, (jsdouble) (u), ®s.sp[n])) \
2247 #define FETCH_NUMBER(cx, n, d) \
2251 v_ = FETCH_OPND(n); \
2252 VALUE_TO_NUMBER(cx, n, v_, d); \
2255 #define FETCH_INT(cx, n, i) \
2259 v_= FETCH_OPND(n); \
2260 if (JSVAL_IS_INT(v_)) { \
2261 i = JSVAL_TO_INT(v_); \
2263 i = js_ValueToECMAInt32(cx, ®s.sp[n]); \
2264 if (JSVAL_IS_NULL(regs.sp[n])) \
2269 #define FETCH_UINT(cx, n, ui) \
2273 v_= FETCH_OPND(n); \
2274 if (JSVAL_IS_INT(v_)) { \
2275 ui = (uint32) JSVAL_TO_INT(v_); \
2277 ui = js_ValueToECMAUint32(cx, ®s.sp[n]); \
2278 if (JSVAL_IS_NULL(regs.sp[n])) \
2284 * Optimized conversion macros that test for the desired type in v before
2285 * homing sp and calling a conversion function.
2287 #define VALUE_TO_NUMBER(cx, n, v, d) \
2289 JS_ASSERT(v == regs.sp[n]); \
2290 if (JSVAL_IS_INT(v)) { \
2291 d = (jsdouble)JSVAL_TO_INT(v); \
2292 } else if (JSVAL_IS_DOUBLE(v)) { \
2293 d = *JSVAL_TO_DOUBLE(v); \
2295 d = js_ValueToNumber(cx, ®s.sp[n]); \
2296 if (JSVAL_IS_NULL(regs.sp[n])) \
2298 JS_ASSERT(JSVAL_IS_NUMBER(regs.sp[n]) || \
2299 regs.sp[n] == JSVAL_TRUE); \
2303 #define POP_BOOLEAN(cx, v, b) \
2305 v = FETCH_OPND(-1); \
2306 if (v == JSVAL_NULL) { \
2308 } else if (JSVAL_IS_BOOLEAN(v)) { \
2309 b = JSVAL_TO_BOOLEAN(v); \
2311 b = js_ValueToBoolean(v); \
2316 #define VALUE_TO_OBJECT(cx, n, v, obj) \
2318 if (!JSVAL_IS_PRIMITIVE(v)) { \
2319 obj = JSVAL_TO_OBJECT(v); \
2321 obj = js_ValueToNonNullObject(cx, v); \
2324 STORE_OPND(n, OBJECT_TO_JSVAL(obj)); \
2328 #define FETCH_OBJECT(cx, n, v, obj) \
2330 v = FETCH_OPND(n); \
2331 VALUE_TO_OBJECT(cx, n, v, obj); \
2334 #define DEFAULT_VALUE(cx, n, hint, v) \
2336 JS_ASSERT(!JSVAL_IS_PRIMITIVE(v)); \
2337 JS_ASSERT(v == regs.sp[n]); \
2338 if (!OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), hint, ®s.sp[n])) \
2344 * Quickly test if v is an int from the [-2**29, 2**29) range, that is, when
2345 * the lowest bit of v is 1 and the bits 30 and 31 are both either 0 or 1. For
2346 * such v we can do increment or decrement via adding or subtracting two
2347 * without checking that the result overflows JSVAL_INT_MIN or JSVAL_INT_MAX.
2349 #define CAN_DO_FAST_INC_DEC(v) (((((v) << 1) ^ v) & 0x80000001) == 1)
2351 JS_STATIC_ASSERT(JSVAL_INT
== 1);
2352 JS_STATIC_ASSERT(!CAN_DO_FAST_INC_DEC(INT_TO_JSVAL(JSVAL_INT_MIN
)));
2353 JS_STATIC_ASSERT(!CAN_DO_FAST_INC_DEC(INT_TO_JSVAL(JSVAL_INT_MAX
)));
2356 * Conditional assert to detect failure to clear a pending exception that is
2357 * suppressed (or unintentional suppression of a wanted exception).
2359 #if defined DEBUG_brendan || defined DEBUG_mrbkap || defined DEBUG_shaver
2360 # define DEBUG_NOT_THROWING 1
2363 #ifdef DEBUG_NOT_THROWING
2364 # define ASSERT_NOT_THROWING(cx) JS_ASSERT(!(cx)->throwing)
2366 # define ASSERT_NOT_THROWING(cx) /* nothing */
2370 * Define JS_OPMETER to instrument bytecode succession, generating a .dot file
2371 * on shutdown that shows the graph of significant predecessor/successor pairs
2372 * executed, where the edge labels give the succession counts. The .dot file
2373 * is named by the JS_OPMETER_FILE envariable, and defaults to /tmp/ops.dot.
2375 * Bonus feature: JS_OPMETER also enables counters for stack-addressing ops
2376 * such as JSOP_GETLOCAL, JSOP_INCARG, via METER_SLOT_OP. The resulting counts
2377 * are written to JS_OPMETER_HIST, defaulting to /tmp/ops.hist.
2380 # define METER_OP_INIT(op) /* nothing */
2381 # define METER_OP_PAIR(op1,op2) /* nothing */
2382 # define METER_SLOT_OP(op,slot) /* nothing */
2386 * The second dimension is hardcoded at 256 because we know that many bits fit
2387 * in a byte, and mainly to optimize away multiplying by JSOP_LIMIT to address
2388 * any particular row.
2390 # define METER_OP_INIT(op) ((op) = JSOP_STOP)
2391 # define METER_OP_PAIR(op1,op2) (js_MeterOpcodePair(op1, op2))
2392 # define METER_SLOT_OP(op,slot) (js_MeterSlotOpcode(op, slot))
2396 #define MAX_INLINE_CALL_COUNT 3000
2399 * Threaded interpretation via computed goto appears to be well-supported by
2400 * GCC 3 and higher. IBM's C compiler when run with the right options (e.g.,
2401 * -qlanglvl=extended) also supports threading. Ditto the SunPro C compiler.
2402 * Currently it's broken for JS_VERSION < 160, though this isn't worth fixing.
2403 * Add your compiler support macros here.
2405 #ifndef JS_THREADED_INTERP
2406 # if JS_VERSION >= 160 && ( \
2408 (__IBMC__ >= 700 && defined __IBM_COMPUTED_GOTO) || \
2409 __SUNPRO_C >= 0x570)
2410 # define JS_THREADED_INTERP 1
2412 # define JS_THREADED_INTERP 0
2417 * Interpreter assumes the following to implement condition-free interrupt
2418 * implementation when !JS_THREADED_INTERP.
2420 JS_STATIC_ASSERT(JSOP_INTERRUPT
== 0);
2423 * Ensure that the intrepreter switch can close call-bytecode cases in the
2424 * same way as non-call bytecodes.
2426 JS_STATIC_ASSERT(JSOP_NAME_LENGTH
== JSOP_CALLNAME_LENGTH
);
2427 JS_STATIC_ASSERT(JSOP_GETGVAR_LENGTH
== JSOP_CALLGVAR_LENGTH
);
2428 JS_STATIC_ASSERT(JSOP_GETUPVAR_LENGTH
== JSOP_CALLUPVAR_LENGTH
);
2429 JS_STATIC_ASSERT(JSOP_GETARG_LENGTH
== JSOP_CALLARG_LENGTH
);
2430 JS_STATIC_ASSERT(JSOP_GETLOCAL_LENGTH
== JSOP_CALLLOCAL_LENGTH
);
2431 JS_STATIC_ASSERT(JSOP_XMLNAME_LENGTH
== JSOP_CALLXMLNAME_LENGTH
);
2434 * Same for JSOP_SETNAME and JSOP_SETPROP, which differ only slightly but
2435 * remain distinct for the decompiler. Ditto for JSOP_NULL{,THIS}.
2437 JS_STATIC_ASSERT(JSOP_SETNAME_LENGTH
== JSOP_SETPROP_LENGTH
);
2438 JS_STATIC_ASSERT(JSOP_NULL_LENGTH
== JSOP_NULLTHIS_LENGTH
);
2440 /* See TRY_BRANCH_AFTER_COND. */
2441 JS_STATIC_ASSERT(JSOP_IFNE_LENGTH
== JSOP_IFEQ_LENGTH
);
2442 JS_STATIC_ASSERT(JSOP_IFNE
== JSOP_IFEQ
+ 1);
2444 /* For the fastest case inder JSOP_INCNAME, etc. */
2445 JS_STATIC_ASSERT(JSOP_INCNAME_LENGTH
== JSOP_DECNAME_LENGTH
);
2446 JS_STATIC_ASSERT(JSOP_INCNAME_LENGTH
== JSOP_NAMEINC_LENGTH
);
2447 JS_STATIC_ASSERT(JSOP_INCNAME_LENGTH
== JSOP_NAMEDEC_LENGTH
);
2449 JS_REQUIRES_STACK JSBool
2450 js_Interpret(JSContext
*cx
)
2455 uintN inlineCallCount
;
2457 JSVersion currentVersion
, originalVersion
;
2459 JSObject
*obj
, *obj2
, *parent
;
2462 jsbytecode
*endpc
, *pc2
;
2466 uintN argc
, attrs
, flags
;
2468 jsval
*vp
, lval
, rval
, ltmp
, rtmp
;
2471 JSScopeProperty
*sprop
;
2472 JSString
*str
, *str2
;
2478 #if JS_THREADED_INTERP
2479 register void * const *jumpTable
;
2481 register uint32 switchMask
;
2484 jsint low
, high
, off
, npairs
;
2486 #if JS_HAS_GETTER_SETTER
2487 JSPropertyOp getter
, setter
;
2489 JSAutoResolveFlags
rf(cx
, JSRESOLVE_INFER
);
2492 # define JS_EXTENSION __extension__
2493 # define JS_EXTENSION_(s) __extension__ ({ s; })
2495 # define JS_EXTENSION
2496 # define JS_EXTENSION_(s) s
2499 #if JS_THREADED_INTERP
2500 static void *const normalJumpTable
[] = {
2501 # define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
2502 JS_EXTENSION &&L_##op,
2503 # include "jsopcode.tbl"
2508 static void *const recordingJumpTable
[] = {
2509 # define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
2510 JS_EXTENSION &&R_##op,
2511 # include "jsopcode.tbl"
2514 #endif /* JS_TRACER */
2516 static void *const interruptJumpTable
[] = {
2517 # define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
2518 JS_EXTENSION &&L_JSOP_INTERRUPT,
2519 # include "jsopcode.tbl"
2523 METER_OP_INIT(op
); /* to nullify first METER_OP_PAIR */
2526 # define CHECK_RECORDER() JS_BEGIN_MACRO \
2527 JS_ASSERT(!TRACE_RECORDER(cx) ^ \
2528 (jumpTable == recordingJumpTable)); \
2531 # define CHECK_RECORDER() ((void)0)
2534 # define DO_OP() JS_BEGIN_MACRO \
2536 JS_EXTENSION_(goto *jumpTable[op]); \
2538 # define DO_NEXT_OP(n) JS_BEGIN_MACRO \
2539 METER_OP_PAIR(op, regs.pc[n]); \
2540 op = (JSOp) *(regs.pc += (n)); \
2544 # define BEGIN_CASE(OP) L_##OP: \
2546 # define END_CASE(OP) DO_NEXT_OP(OP##_LENGTH);
2547 # define END_VARLEN_CASE DO_NEXT_OP(len);
2548 # define ADD_EMPTY_CASE(OP) BEGIN_CASE(OP) \
2549 JS_ASSERT(js_CodeSpec[OP].length == 1); \
2550 op = (JSOp) *++regs.pc; \
2553 # define END_EMPTY_CASES
2555 #else /* !JS_THREADED_INTERP */
2557 # define DO_OP() goto do_op
2558 # define DO_NEXT_OP(n) JS_BEGIN_MACRO \
2559 JS_ASSERT((n) == len); \
2563 # define BEGIN_CASE(OP) case OP:
2564 # define END_CASE(OP) END_CASE_LEN(OP##_LENGTH)
2565 # define END_CASE_LEN(n) END_CASE_LENX(n)
2566 # define END_CASE_LENX(n) END_CASE_LEN##n
2569 * To share the code for all len == 1 cases we use the specialized label with
2570 * code that falls through to advance_pc: .
2572 # define END_CASE_LEN1 goto advance_pc_by_one;
2573 # define END_CASE_LEN2 len = 2; goto advance_pc;
2574 # define END_CASE_LEN3 len = 3; goto advance_pc;
2575 # define END_CASE_LEN4 len = 4; goto advance_pc;
2576 # define END_CASE_LEN5 len = 5; goto advance_pc;
2577 # define END_VARLEN_CASE goto advance_pc;
2578 # define ADD_EMPTY_CASE(OP) BEGIN_CASE(OP)
2579 # define END_EMPTY_CASES goto advance_pc_by_one;
2581 #endif /* !JS_THREADED_INTERP */
2584 /* We had better not be entering the interpreter from JIT-compiled code. */
2585 TraceRecorder
*tr
= NULL
;
2586 if (JS_ON_TRACE(cx
)) {
2587 tr
= TRACE_RECORDER(cx
);
2588 SET_TRACE_RECORDER(cx
, NULL
);
2589 JS_TRACE_MONITOR(cx
).onTrace
= JS_FALSE
;
2591 * ON_TRACE means either recording or coming from traced code.
2592 * If there's no recorder (the latter case), don't care.
2595 if (tr
->wasDeepAborted())
2596 tr
->removeFragmentoReferences();
2598 tr
->pushAbortStack();
2603 /* Check for too deep of a native thread stack. */
2604 JS_CHECK_RECURSION(cx
, return JS_FALSE
);
2608 /* Set registerized frame pointer and derived script pointer. */
2610 script
= fp
->script
;
2611 JS_ASSERT(script
->length
!= 0);
2613 /* Count of JS function calls that nest in this C js_Interpret frame. */
2614 inlineCallCount
= 0;
2617 * Initialize the index segment register used by LOAD_ATOM and
2618 * GET_FULL_INDEX macros below. As a register we use a pointer based on
2619 * the atom map to turn frequently executed LOAD_ATOM into simple array
2620 * access. For less frequent object and regexp loads we have to recover
2621 * the segment from atoms pointer first.
2623 atoms
= script
->atomMap
.vector
;
2625 #define LOAD_ATOM(PCOFF) \
2627 JS_ASSERT(fp->imacpc \
2628 ? atoms == COMMON_ATOMS_START(&rt->atomState) && \
2629 GET_INDEX(regs.pc + PCOFF) < js_common_atom_count \
2630 : (size_t)(atoms - script->atomMap.vector) < \
2631 (size_t)(script->atomMap.length - \
2632 GET_INDEX(regs.pc + PCOFF))); \
2633 atom = atoms[GET_INDEX(regs.pc + PCOFF)]; \
2636 #define GET_FULL_INDEX(PCOFF) \
2637 (atoms - script->atomMap.vector + GET_INDEX(regs.pc + PCOFF))
2639 #define LOAD_OBJECT(PCOFF) \
2640 JS_GET_SCRIPT_OBJECT(script, GET_FULL_INDEX(PCOFF), obj)
2642 #define LOAD_FUNCTION(PCOFF) \
2643 JS_GET_SCRIPT_FUNCTION(script, GET_FULL_INDEX(PCOFF), fun)
2647 #define MONITOR_BRANCH() \
2649 if (TRACING_ENABLED(cx)) { \
2650 ENABLE_TRACER(js_MonitorLoopEdge(cx, inlineCallCount)); \
2652 script = fp->script; \
2653 atoms = script->atomMap.vector; \
2654 currentVersion = (JSVersion) script->version; \
2655 JS_ASSERT(fp->regs == ®s); \
2661 #else /* !JS_TRACER */
2663 #define MONITOR_BRANCH() ((void) 0)
2665 #endif /* !JS_TRACER */
2668 * Prepare to call a user-supplied branch handler, and abort the script
2669 * if it returns false.
2671 #define CHECK_BRANCH() \
2673 if ((cx->operationCount -= JSOW_SCRIPT_JUMP) <= 0) { \
2674 if (!js_ResetOperationCount(cx)) \
2686 op = (JSOp) *regs.pc; \
2690 MUST_FLOW_THROUGH("exit");
2694 * Optimized Get and SetVersion for proper script language versioning.
2696 * If any native method or JSClass/JSObjectOps hook calls js_SetVersion
2697 * and changes cx->version, the effect will "stick" and we will stop
2698 * maintaining currentVersion. This is relied upon by testsuites, for
2699 * the most part -- web browsers select version before compiling and not
2702 currentVersion
= (JSVersion
) script
->version
;
2703 originalVersion
= (JSVersion
) cx
->version
;
2704 if (currentVersion
!= originalVersion
)
2705 js_SetVersion(cx
, currentVersion
);
2707 /* Update the static-link display. */
2708 if (script
->staticDepth
< JS_DISPLAY_SIZE
) {
2709 JSStackFrame
**disp
= &cx
->display
[script
->staticDepth
];
2710 fp
->displaySave
= *disp
;
2714 fp
->pcDisabledSave
= JS_PROPERTY_CACHE(cx
).disabled
;
2718 * Load the debugger's interrupt hook here and after calling out to native
2719 * functions (but not to getters, setters, or other native hooks), so we do
2720 * not have to reload it each time through the interpreter loop -- we hope
2721 * the compiler can keep it in a register when it is non-null.
2723 #if JS_THREADED_INTERP
2725 # define LOAD_INTERRUPT_HANDLER(cx) \
2726 ((void) (jumpTable = (cx)->debugHooks->interruptHandler \
2727 ? interruptJumpTable \
2728 : TRACE_RECORDER(cx) \
2729 ? recordingJumpTable \
2731 # define ENABLE_TRACER(flag) \
2733 bool flag_ = (flag); \
2734 JS_ASSERT(flag_ == !!TRACE_RECORDER(cx)); \
2735 jumpTable = flag_ ? recordingJumpTable : normalJumpTable; \
2737 #else /* !JS_TRACER */
2738 # define LOAD_INTERRUPT_HANDLER(cx) \
2739 ((void) (jumpTable = (cx)->debugHooks->interruptHandler \
2740 ? interruptJumpTable \
2742 # define ENABLE_TRACER(flag) ((void)0)
2743 #endif /* !JS_TRACER */
2744 #else /* !JS_THREADED_INTERP */
2746 # define LOAD_INTERRUPT_HANDLER(cx) \
2747 ((void) (switchMask = ((cx)->debugHooks->interruptHandler || \
2748 TRACE_RECORDER(cx)) ? 0 : 255))
2749 # define ENABLE_TRACER(flag) \
2751 bool flag_ = (flag); \
2752 JS_ASSERT(flag_ == !!TRACE_RECORDER(cx)); \
2753 switchMask = flag_ ? 0 : 255; \
2755 #else /* !JS_TRACER */
2756 # define LOAD_INTERRUPT_HANDLER(cx) \
2757 ((void) (switchMask = ((cx)->debugHooks->interruptHandler \
2759 # define ENABLE_TRACER(flag) ((void)0)
2760 #endif /* !JS_TRACER */
2761 #endif /* !JS_THREADED_INTERP */
2763 LOAD_INTERRUPT_HANDLER(cx
);
2765 #if !JS_HAS_GENERATORS
2766 JS_ASSERT(!fp
->regs
);
2768 /* Initialize the pc and sp registers unless we're resuming a generator. */
2769 if (JS_LIKELY(!fp
->regs
)) {
2771 ASSERT_NOT_THROWING(cx
);
2772 regs
.pc
= script
->code
;
2773 regs
.sp
= StackBase(fp
);
2775 #if JS_HAS_GENERATORS
2779 JS_ASSERT(fp
->flags
& JSFRAME_GENERATOR
);
2780 gen
= FRAME_TO_GENERATOR(fp
);
2781 JS_ASSERT(fp
->regs
== &gen
->savedRegs
);
2782 regs
= gen
->savedRegs
;
2784 JS_ASSERT((size_t) (regs
.pc
- script
->code
) <= script
->length
);
2785 JS_ASSERT((size_t) (regs
.sp
- StackBase(fp
)) <= StackDepth(script
));
2786 JS_ASSERT(JS_PROPERTY_CACHE(cx
).disabled
>= 0);
2787 JS_PROPERTY_CACHE(cx
).disabled
+= js_CountWithBlocks(cx
, fp
);
2790 * To support generator_throw and to catch ignored exceptions,
2791 * fail if cx->throwing is set.
2794 #ifdef DEBUG_NOT_THROWING
2795 if (cx
->exception
!= JSVAL_ARETURN
) {
2796 printf("JS INTERPRETER CALLED WITH PENDING EXCEPTION %lx\n",
2797 (unsigned long) cx
->exception
);
2803 #endif /* JS_HAS_GENERATORS */
2806 * It is important that "op" be initialized before calling DO_OP because
2807 * it is possible for "op" to be specially assigned during the normal
2808 * processing of an opcode while looping. We rely on DO_NEXT_OP to manage
2809 * "op" correctly in all other cases.
2814 #if JS_THREADED_INTERP
2816 * This is a loop, but it does not look like a loop. The loop-closing
2817 * jump is distributed throughout goto *jumpTable[op] inside of DO_OP.
2818 * When interrupts are enabled, jumpTable is set to interruptJumpTable
2819 * where all jumps point to the JSOP_INTERRUPT case. The latter, after
2820 * calling the interrupt handler, dispatches through normalJumpTable to
2821 * continue the normal bytecode processing.
2826 JS_ASSERT(js_CodeSpec
[op
].length
== 1);
2830 op
= (JSOp
) *regs
.pc
;
2833 js_TraceOpcode(cx
, len
);
2837 switchOp
= op
& switchMask
;
2840 #endif /* !JS_THREADED_INTERP */
2842 BEGIN_CASE(JSOP_INTERRUPT
)
2844 JSTrapHandler handler
;
2846 handler
= cx
->debugHooks
->interruptHandler
;
2848 switch (handler(cx
, script
, regs
.pc
, &rval
,
2849 cx
->debugHooks
->interruptHandlerData
)) {
2852 case JSTRAP_CONTINUE
:
2859 cx
->throwing
= JS_TRUE
;
2860 cx
->exception
= rval
;
2864 #if !JS_THREADED_INTERP
2866 /* this was not a real interrupt, the tracer is trying to
2868 switchOp
= op
+ 256;
2872 LOAD_INTERRUPT_HANDLER(cx
);
2874 #if JS_THREADED_INTERP
2875 JS_EXTENSION_(goto *normalJumpTable
[op
]);
2882 /* No-ops for ease of decompilation. */
2883 ADD_EMPTY_CASE(JSOP_NOP
)
2884 ADD_EMPTY_CASE(JSOP_CONDSWITCH
)
2885 ADD_EMPTY_CASE(JSOP_TRY
)
2886 ADD_EMPTY_CASE(JSOP_FINALLY
)
2887 #if JS_HAS_XML_SUPPORT
2888 ADD_EMPTY_CASE(JSOP_STARTXML
)
2889 ADD_EMPTY_CASE(JSOP_STARTXMLEXPR
)
2893 /* ADD_EMPTY_CASE is not used here as JSOP_LINENO_LENGTH == 3. */
2894 BEGIN_CASE(JSOP_LINENO
)
2895 END_CASE(JSOP_LINENO
)
2897 BEGIN_CASE(JSOP_PUSH
)
2898 PUSH_OPND(JSVAL_VOID
);
2901 BEGIN_CASE(JSOP_POP
)
2905 BEGIN_CASE(JSOP_POPN
)
2906 regs
.sp
-= GET_UINT16(regs
.pc
);
2908 JS_ASSERT(StackBase(fp
) <= regs
.sp
);
2909 obj
= fp
->blockChain
;
2911 OBJ_BLOCK_DEPTH(cx
, obj
) + OBJ_BLOCK_COUNT(cx
, obj
)
2912 <= (size_t) (regs
.sp
- StackBase(fp
)));
2913 for (obj
= fp
->scopeChain
; obj
; obj
= OBJ_GET_PARENT(cx
, obj
)) {
2914 clasp
= OBJ_GET_CLASS(cx
, obj
);
2915 if (clasp
!= &js_BlockClass
&& clasp
!= &js_WithClass
)
2917 if (OBJ_GET_PRIVATE(cx
, obj
) != fp
)
2919 JS_ASSERT(StackBase(fp
) + OBJ_BLOCK_DEPTH(cx
, obj
)
2920 + ((clasp
== &js_BlockClass
)
2921 ? OBJ_BLOCK_COUNT(cx
, obj
)
2928 BEGIN_CASE(JSOP_SETRVAL
)
2929 BEGIN_CASE(JSOP_POPV
)
2930 ASSERT_NOT_THROWING(cx
);
2931 fp
->rval
= POP_OPND();
2934 BEGIN_CASE(JSOP_ENTERWITH
)
2935 if (!js_EnterWith(cx
, -1))
2939 * We must ensure that different "with" blocks have different
2940 * stack depth associated with them. This allows the try handler
2941 * search to properly recover the scope chain. Thus we must keep
2942 * the stack at least at the current level.
2944 * We set sp[-1] to the current "with" object to help asserting
2945 * the enter/leave balance in [leavewith].
2947 regs
.sp
[-1] = OBJECT_TO_JSVAL(fp
->scopeChain
);
2948 END_CASE(JSOP_ENTERWITH
)
2950 BEGIN_CASE(JSOP_LEAVEWITH
)
2951 JS_ASSERT(regs
.sp
[-1] == OBJECT_TO_JSVAL(fp
->scopeChain
));
2954 END_CASE(JSOP_LEAVEWITH
)
2956 BEGIN_CASE(JSOP_RETURN
)
2958 fp
->rval
= POP_OPND();
2961 BEGIN_CASE(JSOP_RETRVAL
) /* fp->rval already set */
2962 BEGIN_CASE(JSOP_STOP
)
2964 * When the inlined frame exits with an exception or an error, ok
2965 * will be false after the inline_return label.
2967 ASSERT_NOT_THROWING(cx
);
2971 * If we are at the end of an imacro, return to its caller in
2972 * the current frame.
2974 JS_ASSERT(op
== JSOP_STOP
);
2977 JS_ASSERT((uintN
)(regs
.sp
- fp
->slots
) <= script
->nslots
);
2978 regs
.pc
= fp
->imacpc
+ js_CodeSpec
[*fp
->imacpc
].length
;
2980 atoms
= script
->atomMap
.vector
;
2981 op
= JSOp(*regs
.pc
);
2985 JS_ASSERT(regs
.sp
== StackBase(fp
));
2986 if ((fp
->flags
& JSFRAME_CONSTRUCTING
) &&
2987 JSVAL_IS_PRIMITIVE(fp
->rval
)) {
2989 JS_ReportErrorNumber(cx
, js_GetErrorMessage
, NULL
,
2990 JSMSG_BAD_NEW_RESULT
,
2991 js_ValueToPrintableString(cx
, rval
));
2994 fp
->rval
= OBJECT_TO_JSVAL(fp
->thisp
);
2997 if (inlineCallCount
)
3000 JSInlineFrame
*ifp
= (JSInlineFrame
*) fp
;
3001 void *hookData
= ifp
->hookData
;
3003 JS_ASSERT(JS_PROPERTY_CACHE(cx
).disabled
== fp
->pcDisabledSave
);
3004 JS_ASSERT(!fp
->blockChain
);
3005 JS_ASSERT(!js_IsActiveWithOrBlock(cx
, fp
->scopeChain
, 0));
3007 if (script
->staticDepth
< JS_DISPLAY_SIZE
)
3008 cx
->display
[script
->staticDepth
] = fp
->displaySave
;
3011 JSInterpreterHook hook
;
3014 hook
= cx
->debugHooks
->callHook
;
3017 * Do not pass &ok directly as exposing the address
3018 * inhibits optimizations and uninitialised warnings.
3021 hook(cx
, fp
, JS_FALSE
, &status
, hookData
);
3023 LOAD_INTERRUPT_HANDLER(cx
);
3028 * If fp has a call object, sync values and clear the back-
3029 * pointer. This can happen for a lightweight function if it
3030 * calls eval unexpectedly (in a way that is hidden from the
3031 * compiler). See bug 325540.
3034 ok
&= js_PutCallObject(cx
, fp
);
3037 ok
&= js_PutArgsObject(cx
, fp
);
3039 #ifdef INCLUDE_MOZILLA_DTRACE
3040 /* DTrace function return, inlines */
3041 if (JAVASCRIPT_FUNCTION_RVAL_ENABLED())
3042 jsdtrace_function_rval(cx
, fp
, fp
->fun
);
3043 if (JAVASCRIPT_FUNCTION_RETURN_ENABLED())
3044 jsdtrace_function_return(cx
, fp
, fp
->fun
);
3047 /* Restore context version only if callee hasn't set version. */
3048 if (JS_LIKELY(cx
->version
== currentVersion
)) {
3049 currentVersion
= ifp
->callerVersion
;
3050 if (currentVersion
!= cx
->version
)
3051 js_SetVersion(cx
, currentVersion
);
3055 * If inline-constructing, replace primitive rval with the new
3056 * object passed in via |this|, and instrument this constructor
3059 if (fp
->flags
& JSFRAME_CONSTRUCTING
) {
3060 if (JSVAL_IS_PRIMITIVE(fp
->rval
))
3061 fp
->rval
= OBJECT_TO_JSVAL(fp
->thisp
);
3062 JS_RUNTIME_METER(cx
->runtime
, constructs
);
3065 /* Restore caller's registers. */
3066 regs
= ifp
->callerRegs
;
3068 /* Store the return value in the caller's operand frame. */
3069 regs
.sp
-= 1 + (size_t) ifp
->frame
.argc
;
3070 regs
.sp
[-1] = fp
->rval
;
3072 /* Restore cx->fp and release the inline frame's space. */
3073 cx
->fp
= fp
= fp
->down
;
3074 JS_ASSERT(fp
->regs
== &ifp
->callerRegs
);
3076 JS_ARENA_RELEASE(&cx
->stackPool
, ifp
->mark
);
3078 /* Restore the calling script's interpreter registers. */
3079 script
= fp
->script
;
3080 atoms
= script
->atomMap
.vector
;
3082 /* Resume execution in the calling frame. */
3084 if (JS_LIKELY(ok
)) {
3085 TRACE_0(LeaveFrame
);
3086 JS_ASSERT(js_CodeSpec
[*regs
.pc
].length
== JSOP_CALL_LENGTH
);
3087 len
= JSOP_CALL_LENGTH
;
3094 BEGIN_CASE(JSOP_DEFAULT
)
3097 BEGIN_CASE(JSOP_GOTO
)
3098 len
= GET_JUMP_OFFSET(regs
.pc
);
3102 BEGIN_CASE(JSOP_IFEQ
)
3103 POP_BOOLEAN(cx
, rval
, cond
);
3104 if (cond
== JS_FALSE
) {
3105 len
= GET_JUMP_OFFSET(regs
.pc
);
3110 BEGIN_CASE(JSOP_IFNE
)
3111 POP_BOOLEAN(cx
, rval
, cond
);
3112 if (cond
!= JS_FALSE
) {
3113 len
= GET_JUMP_OFFSET(regs
.pc
);
3119 POP_BOOLEAN(cx
, rval
, cond
);
3120 if (cond
== JS_TRUE
) {
3121 len
= GET_JUMP_OFFSET(regs
.pc
);
3127 BEGIN_CASE(JSOP_AND
)
3128 POP_BOOLEAN(cx
, rval
, cond
);
3129 if (cond
== JS_FALSE
) {
3130 len
= GET_JUMP_OFFSET(regs
.pc
);
3136 BEGIN_CASE(JSOP_DEFAULTX
)
3139 BEGIN_CASE(JSOP_GOTOX
)
3140 len
= GET_JUMPX_OFFSET(regs
.pc
);
3142 END_CASE(JSOP_GOTOX
);
3144 BEGIN_CASE(JSOP_IFEQX
)
3145 POP_BOOLEAN(cx
, rval
, cond
);
3146 if (cond
== JS_FALSE
) {
3147 len
= GET_JUMPX_OFFSET(regs
.pc
);
3150 END_CASE(JSOP_IFEQX
)
3152 BEGIN_CASE(JSOP_IFNEX
)
3153 POP_BOOLEAN(cx
, rval
, cond
);
3154 if (cond
!= JS_FALSE
) {
3155 len
= GET_JUMPX_OFFSET(regs
.pc
);
3158 END_CASE(JSOP_IFNEX
)
3160 BEGIN_CASE(JSOP_ORX
)
3161 POP_BOOLEAN(cx
, rval
, cond
);
3162 if (cond
== JS_TRUE
) {
3163 len
= GET_JUMPX_OFFSET(regs
.pc
);
3169 BEGIN_CASE(JSOP_ANDX
)
3170 POP_BOOLEAN(cx
, rval
, cond
);
3171 if (cond
== JS_FALSE
) {
3172 len
= GET_JUMPX_OFFSET(regs
.pc
);
3179 * If the index value at sp[n] is not an int that fits in a jsval, it could
3180 * be an object (an XML QName, AttributeName, or AnyName), but only if we are
3181 * compiling with JS_HAS_XML_SUPPORT. Otherwise convert the index value to a
3184 #define FETCH_ELEMENT_ID(obj, n, id) \
3186 jsval idval_ = FETCH_OPND(n); \
3187 if (JSVAL_IS_INT(idval_)) { \
3188 id = INT_JSVAL_TO_JSID(idval_); \
3190 if (!js_InternNonIntElementId(cx, obj, idval_, &id)) \
3192 regs.sp[n] = ID_TO_VALUE(id); \
3196 #define TRY_BRANCH_AFTER_COND(cond,spdec) \
3199 JS_ASSERT(js_CodeSpec[op].length == 1); \
3200 diff_ = (uintN) regs.pc[1] - (uintN) JSOP_IFEQ; \
3203 if (cond == (diff_ != 0)) { \
3205 len = GET_JUMP_OFFSET(regs.pc); \
3208 len = 1 + JSOP_IFEQ_LENGTH; \
3214 rval
= FETCH_OPND(-1);
3215 if (JSVAL_IS_PRIMITIVE(rval
)) {
3216 js_ReportValueError(cx
, JSMSG_IN_NOT_OBJECT
, -1, rval
, NULL
);
3219 obj
= JSVAL_TO_OBJECT(rval
);
3220 FETCH_ELEMENT_ID(obj
, -2, id
);
3221 if (!OBJ_LOOKUP_PROPERTY(cx
, obj
, id
, &obj2
, &prop
))
3223 cond
= prop
!= NULL
;
3225 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
3226 TRY_BRANCH_AFTER_COND(cond
, 2);
3228 STORE_OPND(-1, BOOLEAN_TO_JSVAL(cond
));
3231 BEGIN_CASE(JSOP_ITER
)
3232 JS_ASSERT(regs
.sp
> StackBase(fp
));
3234 if (!js_ValueToIterator(cx
, flags
, ®s
.sp
[-1]))
3236 LOAD_INTERRUPT_HANDLER(cx
);
3237 JS_ASSERT(!JSVAL_IS_PRIMITIVE(regs
.sp
[-1]));
3241 BEGIN_CASE(JSOP_NEXTITER
)
3242 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3243 JS_ASSERT(!JSVAL_IS_PRIMITIVE(regs
.sp
[-2]));
3244 if (!js_CallIteratorNext(cx
, JSVAL_TO_OBJECT(regs
.sp
[-2]), ®s
.sp
[-1]))
3246 LOAD_INTERRUPT_HANDLER(cx
);
3247 rval
= BOOLEAN_TO_JSVAL(regs
.sp
[-1] != JSVAL_HOLE
);
3249 TRACE_0(IteratorNextComplete
);
3250 END_CASE(JSOP_NEXTITER
)
3252 BEGIN_CASE(JSOP_ENDITER
)
3254 * Decrease the stack pointer even when !ok -- see comments in the
3255 * exception capturing code for details.
3257 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3258 ok
= js_CloseIterator(cx
, regs
.sp
[-2]);
3262 END_CASE(JSOP_ENDITER
)
3264 BEGIN_CASE(JSOP_FORARG
)
3265 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3266 slot
= GET_ARGNO(regs
.pc
);
3267 JS_ASSERT(slot
< fp
->fun
->nargs
);
3268 fp
->argv
[slot
] = regs
.sp
[-1];
3269 END_CASE(JSOP_FORARG
)
3271 BEGIN_CASE(JSOP_FORLOCAL
)
3272 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3273 slot
= GET_SLOTNO(regs
.pc
);
3274 JS_ASSERT(slot
< fp
->script
->nslots
);
3275 vp
= &fp
->slots
[slot
];
3278 END_CASE(JSOP_FORLOCAL
)
3280 BEGIN_CASE(JSOP_FORNAME
)
3281 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3283 id
= ATOM_TO_JSID(atom
);
3284 if (!js_FindProperty(cx
, id
, &obj
, &obj2
, &prop
))
3287 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
3288 ok
= OBJ_SET_PROPERTY(cx
, obj
, id
, ®s
.sp
[-1]);
3291 END_CASE(JSOP_FORNAME
)
3293 BEGIN_CASE(JSOP_FORPROP
)
3294 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3296 id
= ATOM_TO_JSID(atom
);
3297 FETCH_OBJECT(cx
, -1, lval
, obj
);
3298 ok
= OBJ_SET_PROPERTY(cx
, obj
, id
, ®s
.sp
[-2]);
3302 END_CASE(JSOP_FORPROP
)
3304 BEGIN_CASE(JSOP_FORELEM
)
3306 * JSOP_FORELEM simply dups the property identifier at top of stack
3307 * and lets the subsequent JSOP_ENUMELEM opcode sequence handle the
3308 * left-hand side expression evaluation and assignment. This opcode
3309 * exists solely to help the decompiler.
3311 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3312 rval
= FETCH_OPND(-1);
3314 END_CASE(JSOP_FORELEM
)
3316 BEGIN_CASE(JSOP_DUP
)
3317 JS_ASSERT(regs
.sp
> StackBase(fp
));
3318 rval
= FETCH_OPND(-1);
3322 BEGIN_CASE(JSOP_DUP2
)
3323 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3324 lval
= FETCH_OPND(-2);
3325 rval
= FETCH_OPND(-1);
3330 BEGIN_CASE(JSOP_SWAP
)
3331 JS_ASSERT(regs
.sp
- 2 >= StackBase(fp
));
3332 lval
= FETCH_OPND(-2);
3333 rval
= FETCH_OPND(-1);
3334 STORE_OPND(-1, lval
);
3335 STORE_OPND(-2, rval
);
3338 #define PROPERTY_OP(n, call) \
3340 /* Fetch the left part and resolve it to a non-null object. */ \
3341 FETCH_OBJECT(cx, n, lval, obj); \
3343 /* Get or set the property. */ \
3348 #define ELEMENT_OP(n, call) \
3350 /* Fetch the left part and resolve it to a non-null object. */ \
3351 FETCH_OBJECT(cx, n - 1, lval, obj); \
3353 /* Fetch index and convert it to id suitable for use with obj. */ \
3354 FETCH_ELEMENT_ID(obj, n, id); \
3356 /* Get or set the element. */ \
3361 #define NATIVE_GET(cx,obj,pobj,sprop,vp) \
3363 if (SPROP_HAS_STUB_GETTER(sprop)) { \
3364 /* Fast path for Object instance properties. */ \
3365 JS_ASSERT((sprop)->slot != SPROP_INVALID_SLOT || \
3366 !SPROP_HAS_STUB_SETTER(sprop)); \
3367 *vp = ((sprop)->slot != SPROP_INVALID_SLOT) \
3368 ? LOCKED_OBJ_GET_SLOT(pobj, (sprop)->slot) \
3371 if (!js_NativeGet(cx, obj, pobj, sprop, vp)) \
3376 #define NATIVE_SET(cx,obj,sprop,vp) \
3378 if (SPROP_HAS_STUB_SETTER(sprop) && \
3379 (sprop)->slot != SPROP_INVALID_SLOT) { \
3380 /* Fast path for, e.g., Object instance properties. */ \
3381 LOCKED_OBJ_WRITE_BARRIER(cx, obj, (sprop)->slot, *vp); \
3383 if (!js_NativeSet(cx, obj, sprop, vp)) \
3389 * Deadlocks or else bad races are likely if JS_THREADSAFE, so we must rely on
3390 * single-thread DEBUG js shell testing to verify property cache hits.
3392 #if defined DEBUG && !defined JS_THREADSAFE
3393 # define ASSERT_VALID_PROPERTY_CACHE_HIT(pcoff,obj,pobj,entry) \
3396 JSObject *obj_, *pobj_; \
3397 JSProperty *prop_; \
3398 JSScopeProperty *sprop_; \
3399 uint32 sample_ = rt->gcNumber; \
3401 GET_ATOM_FROM_BYTECODE(script, regs.pc, pcoff, atom_); \
3403 atom_ = rt->atomState.lengthAtom; \
3404 if (JOF_OPMODE(*regs.pc) == JOF_NAME) { \
3405 ok = js_FindProperty(cx, ATOM_TO_JSID(atom_), &obj_, &pobj_, \
3409 ok = js_LookupProperty(cx, obj, ATOM_TO_JSID(atom_), &pobj_, \
3414 if (rt->gcNumber != sample_) \
3417 JS_ASSERT(pobj_ == pobj); \
3418 sprop_ = (JSScopeProperty *) prop_; \
3419 if (PCVAL_IS_SLOT(entry->vword)) { \
3420 JS_ASSERT(PCVAL_TO_SLOT(entry->vword) == sprop_->slot); \
3421 } else if (PCVAL_IS_SPROP(entry->vword)) { \
3422 JS_ASSERT(PCVAL_TO_SPROP(entry->vword) == sprop_); \
3425 JS_ASSERT(PCVAL_IS_OBJECT(entry->vword)); \
3426 JS_ASSERT(entry->vword != PCVAL_NULL); \
3427 JS_ASSERT(SCOPE_IS_BRANDED(OBJ_SCOPE(pobj))); \
3428 JS_ASSERT(SPROP_HAS_STUB_GETTER(sprop_)); \
3429 JS_ASSERT(SPROP_HAS_VALID_SLOT(sprop_, OBJ_SCOPE(pobj_))); \
3430 v_ = LOCKED_OBJ_GET_SLOT(pobj_, sprop_->slot); \
3431 JS_ASSERT(VALUE_IS_FUNCTION(cx, v_)); \
3432 JS_ASSERT(PCVAL_TO_OBJECT(entry->vword) == JSVAL_TO_OBJECT(v_)); \
3434 OBJ_DROP_PROPERTY(cx, pobj_, prop_); \
3437 # define ASSERT_VALID_PROPERTY_CACHE_HIT(pcoff,obj,pobj,entry) ((void) 0)
3441 * Skip the JSOP_POP typically found after a JSOP_SET* opcode, where oplen is
3442 * the constant length of the SET opcode sequence, and spdec is the constant
3443 * by which to decrease the stack pointer to pop all of the SET op's operands.
3445 * NB: unlike macros that could conceivably be replaced by functions (ignoring
3446 * goto error), where a call should not have to be braced in order to expand
3447 * correctly (e.g., in if (cond) FOO(); else BAR()), these three macros lack
3448 * JS_{BEGIN,END}_MACRO brackets. They are also indented so as to align with
3449 * nearby opcode code.
3451 #define SKIP_POP_AFTER_SET(oplen,spdec) \
3452 if (regs.pc[oplen] == JSOP_POP) { \
3454 regs.pc += oplen + JSOP_POP_LENGTH; \
3455 op = (JSOp) *regs.pc; \
3459 #define END_SET_CASE(OP) \
3460 SKIP_POP_AFTER_SET(OP##_LENGTH, 1); \
3463 #define END_SET_CASE_STORE_RVAL(OP,spdec) \
3464 SKIP_POP_AFTER_SET(OP##_LENGTH, spdec); \
3465 rval = FETCH_OPND(-1); \
3466 regs.sp -= (spdec) - 1; \
3467 STORE_OPND(-1, rval); \
3470 BEGIN_CASE(JSOP_SETCONST
)
3473 rval
= FETCH_OPND(-1);
3474 if (!OBJ_DEFINE_PROPERTY(cx
, obj
, ATOM_TO_JSID(atom
), rval
,
3475 JS_PropertyStub
, JS_PropertyStub
,
3476 JSPROP_ENUMERATE
| JSPROP_PERMANENT
|
3481 END_SET_CASE(JSOP_SETCONST
);
3483 #if JS_HAS_DESTRUCTURING
3484 BEGIN_CASE(JSOP_ENUMCONSTELEM
)
3485 rval
= FETCH_OPND(-3);
3486 FETCH_OBJECT(cx
, -2, lval
, obj
);
3487 FETCH_ELEMENT_ID(obj
, -1, id
);
3488 if (!OBJ_DEFINE_PROPERTY(cx
, obj
, id
, rval
,
3489 JS_PropertyStub
, JS_PropertyStub
,
3490 JSPROP_ENUMERATE
| JSPROP_PERMANENT
|
3496 END_CASE(JSOP_ENUMCONSTELEM
)
3499 BEGIN_CASE(JSOP_BINDNAME
)
3501 JSPropCacheEntry
*entry
;
3503 obj
= fp
->scopeChain
;
3504 if (JS_LIKELY(OBJ_IS_NATIVE(obj
))) {
3505 PROPERTY_CACHE_TEST(cx
, regs
.pc
, obj
, obj2
, entry
, atom
);
3507 ASSERT_VALID_PROPERTY_CACHE_HIT(0, obj
, obj2
, entry
);
3508 JS_UNLOCK_OBJ(cx
, obj2
);
3515 id
= ATOM_TO_JSID(atom
);
3516 obj
= js_FindIdentifierBase(cx
, id
, entry
);
3520 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
3521 END_CASE(JSOP_BINDNAME
)
3523 BEGIN_CASE(JSOP_IMACOP
)
3524 JS_ASSERT(JS_UPTRDIFF(fp
->imacpc
, script
->code
) < script
->length
);
3525 op
= JSOp(*fp
->imacpc
);
3528 #define BITWISE_OP(OP) \
3530 FETCH_INT(cx, -2, i); \
3531 FETCH_INT(cx, -1, j); \
3534 STORE_INT(cx, -1, i); \
3537 BEGIN_CASE(JSOP_BITOR
)
3539 END_CASE(JSOP_BITOR
)
3541 BEGIN_CASE(JSOP_BITXOR
)
3543 END_CASE(JSOP_BITXOR
)
3545 BEGIN_CASE(JSOP_BITAND
)
3547 END_CASE(JSOP_BITAND
)
3549 #define RELATIONAL_OP(OP) \
3551 rval = FETCH_OPND(-1); \
3552 lval = FETCH_OPND(-2); \
3553 /* Optimize for two int-tagged operands (typical loop control). */ \
3554 if ((lval & rval) & JSVAL_INT) { \
3555 cond = JSVAL_TO_INT(lval) OP JSVAL_TO_INT(rval); \
3557 if (!JSVAL_IS_PRIMITIVE(lval)) \
3558 DEFAULT_VALUE(cx, -2, JSTYPE_NUMBER, lval); \
3559 if (!JSVAL_IS_PRIMITIVE(rval)) \
3560 DEFAULT_VALUE(cx, -1, JSTYPE_NUMBER, rval); \
3561 if (JSVAL_IS_STRING(lval) && JSVAL_IS_STRING(rval)) { \
3562 str = JSVAL_TO_STRING(lval); \
3563 str2 = JSVAL_TO_STRING(rval); \
3564 cond = js_CompareStrings(str, str2) OP 0; \
3566 VALUE_TO_NUMBER(cx, -2, lval, d); \
3567 VALUE_TO_NUMBER(cx, -1, rval, d2); \
3568 cond = JSDOUBLE_COMPARE(d, OP, d2, JS_FALSE); \
3571 TRY_BRANCH_AFTER_COND(cond, 2); \
3573 STORE_OPND(-1, BOOLEAN_TO_JSVAL(cond)); \
3577 * NB: These macros can't use JS_BEGIN_MACRO/JS_END_MACRO around their bodies
3578 * because they begin if/else chains, so callers must not put semicolons after
3579 * the call expressions!
3581 #if JS_HAS_XML_SUPPORT
3582 #define XML_EQUALITY_OP(OP) \
3583 if ((ltmp == JSVAL_OBJECT && \
3584 (obj2 = JSVAL_TO_OBJECT(lval)) && \
3585 OBJECT_IS_XML(cx, obj2)) || \
3586 (rtmp == JSVAL_OBJECT && \
3587 (obj2 = JSVAL_TO_OBJECT(rval)) && \
3588 OBJECT_IS_XML(cx, obj2))) { \
3589 JSXMLObjectOps *ops; \
3591 ops = (JSXMLObjectOps *) obj2->map->ops; \
3592 if (obj2 == JSVAL_TO_OBJECT(rval)) \
3594 if (!ops->equality(cx, obj2, rval, &cond)) \
3596 cond = cond OP JS_TRUE; \
3599 #define EXTENDED_EQUALITY_OP(OP) \
3600 if (ltmp == JSVAL_OBJECT && \
3601 (obj2 = JSVAL_TO_OBJECT(lval)) && \
3602 ((clasp = OBJ_GET_CLASS(cx, obj2))->flags & JSCLASS_IS_EXTENDED)) { \
3603 JSExtendedClass *xclasp; \
3605 xclasp = (JSExtendedClass *) clasp; \
3606 if (!xclasp->equality(cx, obj2, rval, &cond)) \
3608 cond = cond OP JS_TRUE; \
3611 #define XML_EQUALITY_OP(OP) /* nothing */
3612 #define EXTENDED_EQUALITY_OP(OP) /* nothing */
3615 #define EQUALITY_OP(OP, IFNAN) \
3617 rval = FETCH_OPND(-1); \
3618 lval = FETCH_OPND(-2); \
3619 ltmp = JSVAL_TAG(lval); \
3620 rtmp = JSVAL_TAG(rval); \
3621 XML_EQUALITY_OP(OP) \
3622 if (ltmp == rtmp) { \
3623 if (ltmp == JSVAL_STRING) { \
3624 str = JSVAL_TO_STRING(lval); \
3625 str2 = JSVAL_TO_STRING(rval); \
3626 cond = js_EqualStrings(str, str2) OP JS_TRUE; \
3627 } else if (ltmp == JSVAL_DOUBLE) { \
3628 d = *JSVAL_TO_DOUBLE(lval); \
3629 d2 = *JSVAL_TO_DOUBLE(rval); \
3630 cond = JSDOUBLE_COMPARE(d, OP, d2, IFNAN); \
3632 EXTENDED_EQUALITY_OP(OP) \
3633 /* Handle all undefined (=>NaN) and int combinations. */ \
3634 cond = lval OP rval; \
3637 if (JSVAL_IS_NULL(lval) || JSVAL_IS_VOID(lval)) { \
3638 cond = (JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval)) OP 1; \
3639 } else if (JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval)) { \
3642 if (ltmp == JSVAL_OBJECT) { \
3643 DEFAULT_VALUE(cx, -2, JSTYPE_VOID, lval); \
3644 ltmp = JSVAL_TAG(lval); \
3645 } else if (rtmp == JSVAL_OBJECT) { \
3646 DEFAULT_VALUE(cx, -1, JSTYPE_VOID, rval); \
3647 rtmp = JSVAL_TAG(rval); \
3649 if (ltmp == JSVAL_STRING && rtmp == JSVAL_STRING) { \
3650 str = JSVAL_TO_STRING(lval); \
3651 str2 = JSVAL_TO_STRING(rval); \
3652 cond = js_EqualStrings(str, str2) OP JS_TRUE; \
3654 VALUE_TO_NUMBER(cx, -2, lval, d); \
3655 VALUE_TO_NUMBER(cx, -1, rval, d2); \
3656 cond = JSDOUBLE_COMPARE(d, OP, d2, IFNAN); \
3660 TRY_BRANCH_AFTER_COND(cond, 2); \
3662 STORE_OPND(-1, BOOLEAN_TO_JSVAL(cond)); \
3666 EQUALITY_OP(==, JS_FALSE
);
3670 EQUALITY_OP(!=, JS_TRUE
);
3673 #define STRICT_EQUALITY_OP(OP) \
3675 rval = FETCH_OPND(-1); \
3676 lval = FETCH_OPND(-2); \
3677 cond = js_StrictlyEqual(cx, lval, rval) OP JS_TRUE; \
3679 STORE_OPND(-1, BOOLEAN_TO_JSVAL(cond)); \
3682 BEGIN_CASE(JSOP_STRICTEQ
)
3683 STRICT_EQUALITY_OP(==);
3684 END_CASE(JSOP_STRICTEQ
)
3686 BEGIN_CASE(JSOP_STRICTNE
)
3687 STRICT_EQUALITY_OP(!=);
3688 END_CASE(JSOP_STRICTNE
)
3690 BEGIN_CASE(JSOP_CASE
)
3691 STRICT_EQUALITY_OP(==);
3694 len
= GET_JUMP_OFFSET(regs
.pc
);
3700 BEGIN_CASE(JSOP_CASEX
)
3701 STRICT_EQUALITY_OP(==);
3704 len
= GET_JUMPX_OFFSET(regs
.pc
);
3708 END_CASE(JSOP_CASEX
)
3727 #undef RELATIONAL_OP
3729 #define SIGNED_SHIFT_OP(OP) \
3731 FETCH_INT(cx, -2, i); \
3732 FETCH_INT(cx, -1, j); \
3733 i = i OP (j & 31); \
3735 STORE_INT(cx, -1, i); \
3738 BEGIN_CASE(JSOP_LSH
)
3739 SIGNED_SHIFT_OP(<<);
3742 BEGIN_CASE(JSOP_RSH
)
3743 SIGNED_SHIFT_OP(>>);
3746 BEGIN_CASE(JSOP_URSH
)
3750 FETCH_UINT(cx
, -2, u
);
3751 FETCH_INT(cx
, -1, j
);
3754 STORE_UINT(cx
, -1, u
);
3759 #undef SIGNED_SHIFT_OP
3761 BEGIN_CASE(JSOP_ADD
)
3762 rval
= FETCH_OPND(-1);
3763 lval
= FETCH_OPND(-2);
3764 #if JS_HAS_XML_SUPPORT
3765 if (!JSVAL_IS_PRIMITIVE(lval
) &&
3766 (obj2
= JSVAL_TO_OBJECT(lval
), OBJECT_IS_XML(cx
, obj2
)) &&
3767 VALUE_IS_XML(cx
, rval
)) {
3768 JSXMLObjectOps
*ops
;
3770 ops
= (JSXMLObjectOps
*) obj2
->map
->ops
;
3771 if (!ops
->concatenate(cx
, obj2
, rval
, &rval
))
3774 STORE_OPND(-1, rval
);
3778 if (!JSVAL_IS_PRIMITIVE(lval
))
3779 DEFAULT_VALUE(cx
, -2, JSTYPE_VOID
, lval
);
3780 if (!JSVAL_IS_PRIMITIVE(rval
))
3781 DEFAULT_VALUE(cx
, -1, JSTYPE_VOID
, rval
);
3782 if ((cond
= JSVAL_IS_STRING(lval
)) || JSVAL_IS_STRING(rval
)) {
3784 str
= JSVAL_TO_STRING(lval
);
3785 str2
= js_ValueToString(cx
, rval
);
3788 regs
.sp
[-1] = STRING_TO_JSVAL(str2
);
3790 str2
= JSVAL_TO_STRING(rval
);
3791 str
= js_ValueToString(cx
, lval
);
3794 regs
.sp
[-2] = STRING_TO_JSVAL(str
);
3796 str
= js_ConcatStrings(cx
, str
, str2
);
3800 STORE_OPND(-1, STRING_TO_JSVAL(str
));
3802 VALUE_TO_NUMBER(cx
, -2, lval
, d
);
3803 VALUE_TO_NUMBER(cx
, -1, rval
, d2
);
3806 STORE_NUMBER(cx
, -1, d
);
3811 #define BINARY_OP(OP) \
3813 FETCH_NUMBER(cx, -2, d); \
3814 FETCH_NUMBER(cx, -1, d2); \
3817 STORE_NUMBER(cx, -1, d); \
3820 BEGIN_CASE(JSOP_SUB
)
3824 BEGIN_CASE(JSOP_MUL
)
3828 BEGIN_CASE(JSOP_DIV
)
3829 FETCH_NUMBER(cx
, -1, d2
);
3830 FETCH_NUMBER(cx
, -2, d
);
3834 /* XXX MSVC miscompiles such that (NaN == 0) */
3835 if (JSDOUBLE_IS_NaN(d2
))
3836 rval
= DOUBLE_TO_JSVAL(rt
->jsNaN
);
3839 if (d
== 0 || JSDOUBLE_IS_NaN(d
))
3840 rval
= DOUBLE_TO_JSVAL(rt
->jsNaN
);
3841 else if ((JSDOUBLE_HI32(d
) ^ JSDOUBLE_HI32(d2
)) >> 31)
3842 rval
= DOUBLE_TO_JSVAL(rt
->jsNegativeInfinity
);
3844 rval
= DOUBLE_TO_JSVAL(rt
->jsPositiveInfinity
);
3845 STORE_OPND(-1, rval
);
3848 STORE_NUMBER(cx
, -1, d
);
3852 BEGIN_CASE(JSOP_MOD
)
3853 FETCH_NUMBER(cx
, -1, d2
);
3854 FETCH_NUMBER(cx
, -2, d
);
3857 STORE_OPND(-1, DOUBLE_TO_JSVAL(rt
->jsNaN
));
3860 /* Workaround MS fmod bug where 42 % (1/0) => NaN, not 42. */
3861 if (!(JSDOUBLE_IS_FINITE(d
) && JSDOUBLE_IS_INFINITE(d2
)))
3864 STORE_NUMBER(cx
, -1, d
);
3868 BEGIN_CASE(JSOP_NOT
)
3869 POP_BOOLEAN(cx
, rval
, cond
);
3870 PUSH_OPND(BOOLEAN_TO_JSVAL(!cond
));
3873 BEGIN_CASE(JSOP_BITNOT
)
3874 FETCH_INT(cx
, -1, i
);
3876 STORE_INT(cx
, -1, i
);
3877 END_CASE(JSOP_BITNOT
)
3879 BEGIN_CASE(JSOP_NEG
)
3881 * When the operand is int jsval, INT_FITS_IN_JSVAL(i) implies
3882 * INT_FITS_IN_JSVAL(-i) unless i is 0 or JSVAL_INT_MIN when the
3883 * results, -0.0 or JSVAL_INT_MAX + 1, are jsdouble values.
3885 rval
= FETCH_OPND(-1);
3886 if (JSVAL_IS_INT(rval
) &&
3887 rval
!= INT_TO_JSVAL(JSVAL_INT_MIN
) &&
3888 (i
= JSVAL_TO_INT(rval
)) != 0) {
3889 JS_STATIC_ASSERT(!INT_FITS_IN_JSVAL(-JSVAL_INT_MIN
));
3891 JS_ASSERT(INT_FITS_IN_JSVAL(i
));
3892 regs
.sp
[-1] = INT_TO_JSVAL(i
);
3894 if (JSVAL_IS_DOUBLE(rval
)) {
3895 d
= *JSVAL_TO_DOUBLE(rval
);
3897 d
= js_ValueToNumber(cx
, ®s
.sp
[-1]);
3898 if (JSVAL_IS_NULL(regs
.sp
[-1]))
3900 JS_ASSERT(JSVAL_IS_NUMBER(regs
.sp
[-1]) ||
3901 regs
.sp
[-1] == JSVAL_TRUE
);
3905 * Negation of a zero doesn't produce a negative
3906 * zero on HPUX. Perform the operation by bit
3909 JSDOUBLE_HI32(d
) ^= JSDOUBLE_HI32_SIGNBIT
;
3913 if (!js_NewNumberInRootedValue(cx
, d
, ®s
.sp
[-1]))
3918 BEGIN_CASE(JSOP_POS
)
3919 rval
= FETCH_OPND(-1);
3920 if (!JSVAL_IS_NUMBER(rval
)) {
3921 d
= js_ValueToNumber(cx
, ®s
.sp
[-1]);
3923 if (JSVAL_IS_NULL(rval
))
3925 if (rval
== JSVAL_TRUE
) {
3926 if (!js_NewNumberInRootedValue(cx
, d
, ®s
.sp
[-1]))
3929 JS_ASSERT(JSVAL_IS_NUMBER(rval
));
3934 BEGIN_CASE(JSOP_DELNAME
)
3936 id
= ATOM_TO_JSID(atom
);
3937 if (!js_FindProperty(cx
, id
, &obj
, &obj2
, &prop
))
3940 /* ECMA says to return true if name is undefined or inherited. */
3941 PUSH_OPND(JSVAL_TRUE
);
3943 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
3944 if (!OBJ_DELETE_PROPERTY(cx
, obj
, id
, ®s
.sp
[-1]))
3947 END_CASE(JSOP_DELNAME
)
3949 BEGIN_CASE(JSOP_DELPROP
)
3951 id
= ATOM_TO_JSID(atom
);
3952 PROPERTY_OP(-1, OBJ_DELETE_PROPERTY(cx
, obj
, id
, &rval
));
3953 STORE_OPND(-1, rval
);
3954 END_CASE(JSOP_DELPROP
)
3956 BEGIN_CASE(JSOP_DELELEM
)
3957 ELEMENT_OP(-1, OBJ_DELETE_PROPERTY(cx
, obj
, id
, &rval
));
3959 STORE_OPND(-1, rval
);
3960 END_CASE(JSOP_DELELEM
)
3962 BEGIN_CASE(JSOP_TYPEOFEXPR
)
3963 BEGIN_CASE(JSOP_TYPEOF
)
3964 rval
= FETCH_OPND(-1);
3965 type
= JS_TypeOfValue(cx
, rval
);
3966 atom
= rt
->atomState
.typeAtoms
[type
];
3967 STORE_OPND(-1, ATOM_KEY(atom
));
3968 END_CASE(JSOP_TYPEOF
)
3970 BEGIN_CASE(JSOP_VOID
)
3971 STORE_OPND(-1, JSVAL_VOID
);
3974 BEGIN_CASE(JSOP_INCELEM
)
3975 BEGIN_CASE(JSOP_DECELEM
)
3976 BEGIN_CASE(JSOP_ELEMINC
)
3977 BEGIN_CASE(JSOP_ELEMDEC
)
3979 * Delay fetching of id until we have the object to ensure
3980 * the proper evaluation order. See bug 372331.
3984 goto fetch_incop_obj
;
3986 BEGIN_CASE(JSOP_INCPROP
)
3987 BEGIN_CASE(JSOP_DECPROP
)
3988 BEGIN_CASE(JSOP_PROPINC
)
3989 BEGIN_CASE(JSOP_PROPDEC
)
3991 id
= ATOM_TO_JSID(atom
);
3995 FETCH_OBJECT(cx
, i
, lval
, obj
);
3997 FETCH_ELEMENT_ID(obj
, -1, id
);
4000 BEGIN_CASE(JSOP_INCNAME
)
4001 BEGIN_CASE(JSOP_DECNAME
)
4002 BEGIN_CASE(JSOP_NAMEINC
)
4003 BEGIN_CASE(JSOP_NAMEDEC
)
4005 JSPropCacheEntry
*entry
;
4007 obj
= fp
->scopeChain
;
4008 if (JS_LIKELY(OBJ_IS_NATIVE(obj
))) {
4009 PROPERTY_CACHE_TEST(cx
, regs
.pc
, obj
, obj2
, entry
, atom
);
4011 ASSERT_VALID_PROPERTY_CACHE_HIT(0, obj
, obj2
, entry
);
4012 if (obj
== obj2
&& PCVAL_IS_SLOT(entry
->vword
)) {
4013 slot
= PCVAL_TO_SLOT(entry
->vword
);
4014 JS_ASSERT(slot
< obj
->map
->freeslot
);
4015 rval
= LOCKED_OBJ_GET_SLOT(obj
, slot
);
4016 if (JS_LIKELY(CAN_DO_FAST_INC_DEC(rval
))) {
4018 rval
+= (js_CodeSpec
[op
].format
& JOF_INC
) ? 2 : -2;
4019 if (!(js_CodeSpec
[op
].format
& JOF_POST
))
4021 LOCKED_OBJ_SET_SLOT(obj
, slot
, rval
);
4022 JS_UNLOCK_OBJ(cx
, obj
);
4024 len
= JSOP_INCNAME_LENGTH
;
4028 JS_UNLOCK_OBJ(cx
, obj2
);
4035 id
= ATOM_TO_JSID(atom
);
4036 if (js_FindPropertyHelper(cx
, id
, &obj
, &obj2
, &prop
, &entry
) < 0)
4039 goto atom_not_defined
;
4040 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
4045 const JSCodeSpec
*cs
;
4049 * We need a root to store the value to leave on the stack until
4050 * we have done with OBJ_SET_PROPERTY.
4052 PUSH_OPND(JSVAL_NULL
);
4053 if (!OBJ_GET_PROPERTY(cx
, obj
, id
, ®s
.sp
[-1]))
4056 cs
= &js_CodeSpec
[op
];
4057 JS_ASSERT(cs
->ndefs
== 1);
4058 JS_ASSERT((cs
->format
& JOF_TMPSLOT_MASK
) == JOF_TMPSLOT2
);
4060 if (JS_LIKELY(CAN_DO_FAST_INC_DEC(v
))) {
4063 incr
= (cs
->format
& JOF_INC
) ? 2 : -2;
4064 if (cs
->format
& JOF_POST
) {
4065 regs
.sp
[-1] = v
+ incr
;
4070 fp
->flags
|= JSFRAME_ASSIGNING
;
4071 ok
= OBJ_SET_PROPERTY(cx
, obj
, id
, ®s
.sp
[-1]);
4072 fp
->flags
&= ~JSFRAME_ASSIGNING
;
4077 * We must set regs.sp[-1] to v for both post and pre increments
4078 * as the setter overwrites regs.sp[-1].
4082 /* We need an extra root for the result. */
4083 PUSH_OPND(JSVAL_NULL
);
4084 if (!js_DoIncDec(cx
, cs
, ®s
.sp
[-2], ®s
.sp
[-1]))
4086 fp
->flags
|= JSFRAME_ASSIGNING
;
4087 ok
= OBJ_SET_PROPERTY(cx
, obj
, id
, ®s
.sp
[-1]);
4088 fp
->flags
&= ~JSFRAME_ASSIGNING
;
4094 if (cs
->nuses
== 0) {
4095 /* regs.sp[-1] already contains the result of name increment. */
4098 regs
.sp
-= cs
->nuses
;
4108 /* Position cases so the most frequent i++ does not need a jump. */
4109 BEGIN_CASE(JSOP_DECARG
)
4110 incr
= -2; incr2
= -2; goto do_arg_incop
;
4111 BEGIN_CASE(JSOP_ARGDEC
)
4112 incr
= -2; incr2
= 0; goto do_arg_incop
;
4113 BEGIN_CASE(JSOP_INCARG
)
4114 incr
= 2; incr2
= 2; goto do_arg_incop
;
4115 BEGIN_CASE(JSOP_ARGINC
)
4116 incr
= 2; incr2
= 0;
4119 slot
= GET_ARGNO(regs
.pc
);
4120 JS_ASSERT(slot
< fp
->fun
->nargs
);
4121 METER_SLOT_OP(op
, slot
);
4122 vp
= fp
->argv
+ slot
;
4123 goto do_int_fast_incop
;
4125 BEGIN_CASE(JSOP_DECLOCAL
)
4126 incr
= -2; incr2
= -2; goto do_local_incop
;
4127 BEGIN_CASE(JSOP_LOCALDEC
)
4128 incr
= -2; incr2
= 0; goto do_local_incop
;
4129 BEGIN_CASE(JSOP_INCLOCAL
)
4130 incr
= 2; incr2
= 2; goto do_local_incop
;
4131 BEGIN_CASE(JSOP_LOCALINC
)
4132 incr
= 2; incr2
= 0;
4135 * do_local_incop comes right before do_int_fast_incop as we want to
4136 * avoid an extra jump for variable cases as local++ is more frequent
4140 slot
= GET_SLOTNO(regs
.pc
);
4141 JS_ASSERT(slot
< fp
->script
->nslots
);
4142 vp
= fp
->slots
+ slot
;
4143 METER_SLOT_OP(op
, slot
);
4144 vp
= fp
->slots
+ slot
;
4148 if (JS_LIKELY(CAN_DO_FAST_INC_DEC(rval
))) {
4150 JS_ASSERT(JSOP_INCARG_LENGTH
== js_CodeSpec
[op
].length
);
4151 SKIP_POP_AFTER_SET(JSOP_INCARG_LENGTH
, 0);
4152 PUSH_OPND(rval
+ incr2
);
4155 if (!js_DoIncDec(cx
, &js_CodeSpec
[op
], ®s
.sp
[-1], vp
))
4158 len
= JSOP_INCARG_LENGTH
;
4159 JS_ASSERT(len
== js_CodeSpec
[op
].length
);
4163 /* NB: This macro doesn't use JS_BEGIN_MACRO/JS_END_MACRO around its body. */
4164 #define FAST_GLOBAL_INCREMENT_OP(SLOWOP,INCR,INCR2) \
4168 goto do_global_incop
4173 BEGIN_CASE(JSOP_DECGVAR
)
4174 FAST_GLOBAL_INCREMENT_OP(JSOP_DECNAME
, -2, -2);
4175 BEGIN_CASE(JSOP_GVARDEC
)
4176 FAST_GLOBAL_INCREMENT_OP(JSOP_NAMEDEC
, -2, 0);
4177 BEGIN_CASE(JSOP_INCGVAR
)
4178 FAST_GLOBAL_INCREMENT_OP(JSOP_INCNAME
, 2, 2);
4179 BEGIN_CASE(JSOP_GVARINC
)
4180 FAST_GLOBAL_INCREMENT_OP(JSOP_NAMEINC
, 2, 0);
4182 #undef FAST_GLOBAL_INCREMENT_OP
4185 JS_ASSERT((js_CodeSpec
[op
].format
& JOF_TMPSLOT_MASK
) ==
4187 slot
= GET_SLOTNO(regs
.pc
);
4188 JS_ASSERT(slot
< GlobalVarCount(fp
));
4189 METER_SLOT_OP(op
, slot
);
4190 lval
= fp
->slots
[slot
];
4191 if (JSVAL_IS_NULL(lval
)) {
4195 slot
= JSVAL_TO_INT(lval
);
4196 rval
= OBJ_GET_SLOT(cx
, fp
->varobj
, slot
);
4197 if (JS_LIKELY(CAN_DO_FAST_INC_DEC(rval
))) {
4198 PUSH_OPND(rval
+ incr2
);
4202 PUSH_OPND(JSVAL_NULL
); /* Extra root */
4203 if (!js_DoIncDec(cx
, &js_CodeSpec
[op
], ®s
.sp
[-2], ®s
.sp
[-1]))
4208 OBJ_SET_SLOT(cx
, fp
->varobj
, slot
, rval
);
4209 len
= JSOP_INCGVAR_LENGTH
; /* all gvar incops are same length */
4210 JS_ASSERT(len
== js_CodeSpec
[op
].length
);
4214 #define COMPUTE_THIS(cx, fp, obj) \
4216 if (fp->flags & JSFRAME_COMPUTED_THIS) { \
4219 obj = js_ComputeThis(cx, JS_TRUE, fp->argv); \
4223 fp->flags |= JSFRAME_COMPUTED_THIS; \
4227 BEGIN_CASE(JSOP_THIS
)
4228 COMPUTE_THIS(cx
, fp
, obj
);
4229 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
4232 BEGIN_CASE(JSOP_GETTHISPROP
)
4234 COMPUTE_THIS(cx
, fp
, obj
);
4236 goto do_getprop_with_obj
;
4240 BEGIN_CASE(JSOP_GETARGPROP
)
4242 slot
= GET_ARGNO(regs
.pc
);
4243 JS_ASSERT(slot
< fp
->fun
->nargs
);
4244 PUSH_OPND(fp
->argv
[slot
]);
4245 goto do_getprop_body
;
4247 BEGIN_CASE(JSOP_GETLOCALPROP
)
4249 slot
= GET_SLOTNO(regs
.pc
);
4250 JS_ASSERT(slot
< script
->nslots
);
4251 PUSH_OPND(fp
->slots
[slot
]);
4252 goto do_getprop_body
;
4254 BEGIN_CASE(JSOP_GETPROP
)
4255 BEGIN_CASE(JSOP_GETXPROP
)
4259 lval
= FETCH_OPND(-1);
4261 do_getprop_with_lval
:
4262 VALUE_TO_OBJECT(cx
, -1, lval
, obj
);
4264 do_getprop_with_obj
:
4267 JSPropCacheEntry
*entry
;
4269 aobj
= OBJ_IS_DENSE_ARRAY(cx
, obj
) ? OBJ_GET_PROTO(cx
, obj
) : obj
;
4270 if (JS_LIKELY(aobj
->map
->ops
->getProperty
== js_GetProperty
)) {
4271 PROPERTY_CACHE_TEST(cx
, regs
.pc
, aobj
, obj2
, entry
, atom
);
4273 ASSERT_VALID_PROPERTY_CACHE_HIT(i
, aobj
, obj2
, entry
);
4274 if (PCVAL_IS_OBJECT(entry
->vword
)) {
4275 rval
= PCVAL_OBJECT_TO_JSVAL(entry
->vword
);
4276 } else if (PCVAL_IS_SLOT(entry
->vword
)) {
4277 slot
= PCVAL_TO_SLOT(entry
->vword
);
4278 JS_ASSERT(slot
< obj2
->map
->freeslot
);
4279 rval
= LOCKED_OBJ_GET_SLOT(obj2
, slot
);
4281 JS_ASSERT(PCVAL_IS_SPROP(entry
->vword
));
4282 sprop
= PCVAL_TO_SPROP(entry
->vword
);
4283 NATIVE_GET(cx
, obj
, obj2
, sprop
, &rval
);
4285 JS_UNLOCK_OBJ(cx
, obj2
);
4291 atom
= rt
->atomState
.lengthAtom
;
4295 id
= ATOM_TO_JSID(atom
);
4297 ? !js_GetPropertyHelper(cx
, aobj
, id
, &rval
, &entry
)
4298 : !OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
)) {
4303 STORE_OPND(-1, rval
);
4304 JS_ASSERT(JSOP_GETPROP_LENGTH
+ i
== js_CodeSpec
[op
].length
);
4305 len
= JSOP_GETPROP_LENGTH
+ i
;
4308 BEGIN_CASE(JSOP_LENGTH
)
4309 lval
= FETCH_OPND(-1);
4310 if (JSVAL_IS_STRING(lval
)) {
4311 str
= JSVAL_TO_STRING(lval
);
4312 regs
.sp
[-1] = INT_TO_JSVAL(JSSTRING_LENGTH(str
));
4313 } else if (!JSVAL_IS_PRIMITIVE(lval
) &&
4314 (obj
= JSVAL_TO_OBJECT(lval
), OBJ_IS_ARRAY(cx
, obj
))) {
4318 * We know that the array is created with only its 'length'
4319 * private data in a fixed slot at JSSLOT_ARRAY_LENGTH. See
4320 * also JSOP_ARRAYPUSH, far below.
4322 length
= obj
->fslots
[JSSLOT_ARRAY_LENGTH
];
4323 if (length
<= JSVAL_INT_MAX
) {
4324 regs
.sp
[-1] = INT_TO_JSVAL(length
);
4325 } else if (!js_NewDoubleInRootedValue(cx
, (jsdouble
) length
,
4331 goto do_getprop_with_lval
;
4333 END_CASE(JSOP_LENGTH
)
4335 BEGIN_CASE(JSOP_CALLPROP
)
4338 JSPropCacheEntry
*entry
;
4340 lval
= FETCH_OPND(-1);
4341 if (!JSVAL_IS_PRIMITIVE(lval
)) {
4342 obj
= JSVAL_TO_OBJECT(lval
);
4344 if (JSVAL_IS_STRING(lval
)) {
4346 } else if (JSVAL_IS_NUMBER(lval
)) {
4348 } else if (JSVAL_IS_BOOLEAN(lval
)) {
4349 i
= JSProto_Boolean
;
4351 JS_ASSERT(JSVAL_IS_NULL(lval
) || JSVAL_IS_VOID(lval
));
4352 js_ReportIsNullOrUndefined(cx
, -1, lval
, NULL
);
4356 if (!js_GetClassPrototype(cx
, NULL
, INT_TO_JSID(i
), &obj
))
4360 aobj
= OBJ_IS_DENSE_ARRAY(cx
, obj
) ? OBJ_GET_PROTO(cx
, obj
) : obj
;
4361 if (JS_LIKELY(aobj
->map
->ops
->getProperty
== js_GetProperty
)) {
4362 PROPERTY_CACHE_TEST(cx
, regs
.pc
, aobj
, obj2
, entry
, atom
);
4364 ASSERT_VALID_PROPERTY_CACHE_HIT(0, aobj
, obj2
, entry
);
4365 if (PCVAL_IS_OBJECT(entry
->vword
)) {
4366 rval
= PCVAL_OBJECT_TO_JSVAL(entry
->vword
);
4367 } else if (PCVAL_IS_SLOT(entry
->vword
)) {
4368 slot
= PCVAL_TO_SLOT(entry
->vword
);
4369 JS_ASSERT(slot
< obj2
->map
->freeslot
);
4370 rval
= LOCKED_OBJ_GET_SLOT(obj2
, slot
);
4372 JS_ASSERT(PCVAL_IS_SPROP(entry
->vword
));
4373 sprop
= PCVAL_TO_SPROP(entry
->vword
);
4374 NATIVE_GET(cx
, obj
, obj2
, sprop
, &rval
);
4376 JS_UNLOCK_OBJ(cx
, obj2
);
4377 STORE_OPND(-1, rval
);
4387 * Cache miss: use the immediate atom that was loaded for us under
4388 * PROPERTY_CACHE_TEST.
4390 id
= ATOM_TO_JSID(atom
);
4392 if (!JSVAL_IS_PRIMITIVE(lval
)) {
4393 #if JS_HAS_XML_SUPPORT
4394 /* Special-case XML object method lookup, per ECMA-357. */
4395 if (OBJECT_IS_XML(cx
, obj
)) {
4396 JSXMLObjectOps
*ops
;
4398 ops
= (JSXMLObjectOps
*) obj
->map
->ops
;
4399 obj
= ops
->getMethod(cx
, obj
, id
, &rval
);
4405 ? !js_GetPropertyHelper(cx
, aobj
, id
, &rval
, &entry
)
4406 : !OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
)) {
4409 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
4410 STORE_OPND(-2, rval
);
4412 JS_ASSERT(obj
->map
->ops
->getProperty
== js_GetProperty
);
4413 if (!js_GetPropertyHelper(cx
, obj
, id
, &rval
, &entry
))
4415 STORE_OPND(-1, lval
);
4416 STORE_OPND(-2, rval
);
4420 /* Wrap primitive lval in object clothing if necessary. */
4421 if (JSVAL_IS_PRIMITIVE(lval
)) {
4422 /* FIXME: https://bugzilla.mozilla.org/show_bug.cgi?id=412571 */
4423 if (!VALUE_IS_FUNCTION(cx
, rval
) ||
4424 (obj
= JSVAL_TO_OBJECT(rval
),
4425 fun
= GET_FUNCTION_PRIVATE(cx
, obj
),
4426 !PRIMITIVE_THIS_TEST(fun
, lval
))) {
4427 if (!js_PrimitiveToObject(cx
, ®s
.sp
[-1]))
4431 #if JS_HAS_NO_SUCH_METHOD
4432 if (JS_UNLIKELY(JSVAL_IS_VOID(rval
))) {
4434 regs
.sp
[-2] = ATOM_KEY(atom
);
4435 if (!js_OnUnknownMethod(cx
, regs
.sp
- 2))
4440 END_CASE(JSOP_CALLPROP
)
4442 BEGIN_CASE(JSOP_SETNAME
)
4443 BEGIN_CASE(JSOP_SETPROP
)
4444 rval
= FETCH_OPND(-1);
4445 lval
= FETCH_OPND(-2);
4446 JS_ASSERT(!JSVAL_IS_PRIMITIVE(lval
) || op
== JSOP_SETPROP
);
4447 VALUE_TO_OBJECT(cx
, -2, lval
, obj
);
4450 JSPropCacheEntry
*entry
;
4454 if (JS_LIKELY(obj
->map
->ops
->setProperty
== js_SetProperty
)) {
4455 JSPropertyCache
*cache
= &JS_PROPERTY_CACHE(cx
);
4456 uint32 kshape
= OBJ_SHAPE(obj
);
4459 * Open-code JS_PROPERTY_CACHE_TEST, specializing for two
4460 * important set-property cases. First:
4462 * function f(a, b, c) {
4463 * var o = {p:a, q:b, r:c};
4467 * or similar real-world cases, which evolve a newborn
4468 * native object predicatably through some bounded number
4469 * of property additions. And second:
4473 * in a frequently executed method or loop body, where p
4474 * will (possibly after the first iteration) always exist
4475 * in native object o.
4477 entry
= &cache
->table
[PROPERTY_CACHE_HASH_PC(regs
.pc
, kshape
)];
4478 PCMETER(cache
->tests
++);
4479 PCMETER(cache
->settests
++);
4480 if (entry
->kpc
== regs
.pc
&& entry
->kshape
== kshape
) {
4483 JS_LOCK_OBJ(cx
, obj
);
4484 scope
= OBJ_SCOPE(obj
);
4485 if (scope
->shape
== kshape
) {
4486 JS_ASSERT(PCVAL_IS_SPROP(entry
->vword
));
4487 sprop
= PCVAL_TO_SPROP(entry
->vword
);
4488 JS_ASSERT(!(sprop
->attrs
& JSPROP_READONLY
));
4489 JS_ASSERT(!SCOPE_IS_SEALED(OBJ_SCOPE(obj
)));
4491 if (scope
->object
== obj
) {
4493 * Fastest path: the cached sprop is already
4494 * in scope. Just NATIVE_SET and break to get
4495 * out of the do-while(0).
4497 if (sprop
== scope
->lastProp
||
4498 SCOPE_HAS_PROPERTY(scope
, sprop
)) {
4499 PCMETER(cache
->pchits
++);
4500 PCMETER(cache
->setpchits
++);
4501 NATIVE_SET(cx
, obj
, sprop
, &rval
);
4502 JS_UNLOCK_SCOPE(cx
, scope
);
4503 TRACE_2(SetPropHit
, entry
, sprop
);
4507 scope
= js_GetMutableScope(cx
, obj
);
4509 JS_UNLOCK_OBJ(cx
, obj
);
4514 if (sprop
->parent
== scope
->lastProp
&&
4515 !SCOPE_HAD_MIDDLE_DELETE(scope
) &&
4516 SPROP_HAS_STUB_SETTER(sprop
) &&
4517 (slot
= sprop
->slot
) == scope
->map
.freeslot
) {
4519 * Fast path: adding a plain old property that
4520 * was once at the frontier of the property
4521 * tree, whose slot is next to claim among the
4522 * allocated slots in obj, where scope->table
4523 * has not been created yet.
4525 * We may want to remove hazard conditions
4526 * above and inline compensation code here,
4527 * depending on real-world workloads.
4529 JS_ASSERT(!(LOCKED_OBJ_GET_CLASS(obj
)->flags
&
4530 JSCLASS_SHARE_ALL_PROPERTIES
));
4532 PCMETER(cache
->pchits
++);
4533 PCMETER(cache
->addpchits
++);
4536 * Beware classes such as Function that use
4537 * the reserveSlots hook to allocate a number
4538 * of reserved slots that may vary with obj.
4540 if (slot
< STOBJ_NSLOTS(obj
) &&
4541 !OBJ_GET_CLASS(cx
, obj
)->reserveSlots
) {
4542 ++scope
->map
.freeslot
;
4544 if (!js_AllocSlot(cx
, obj
, &slot
)) {
4545 JS_UNLOCK_SCOPE(cx
, scope
);
4551 * If this obj's number of reserved slots
4552 * differed, or if something created a hash
4553 * table for scope, we must pay the price of
4554 * js_AddScopeProperty.
4556 * If slot does not match the cached sprop's
4557 * slot, update the cache entry in the hope
4558 * that obj and other instances with the same
4559 * number of reserved slots are now "hot".
4561 if (slot
!= sprop
->slot
|| scope
->table
) {
4562 JSScopeProperty
*sprop2
=
4563 js_AddScopeProperty(cx
, scope
,
4572 js_FreeSlot(cx
, obj
, slot
);
4573 JS_UNLOCK_SCOPE(cx
, scope
);
4576 if (sprop2
!= sprop
) {
4577 PCMETER(cache
->slotchanges
++);
4578 JS_ASSERT(slot
!= sprop
->slot
&&
4579 slot
== sprop2
->slot
&&
4580 sprop2
->id
== sprop
->id
);
4581 entry
->vword
= SPROP_TO_PCVAL(sprop2
);
4585 SCOPE_EXTEND_SHAPE(cx
, scope
, sprop
);
4586 ++scope
->entryCount
;
4587 scope
->lastProp
= sprop
;
4590 GC_WRITE_BARRIER(cx
, scope
,
4591 LOCKED_OBJ_GET_SLOT(obj
, slot
),
4593 LOCKED_OBJ_SET_SLOT(obj
, slot
, rval
);
4594 JS_UNLOCK_SCOPE(cx
, scope
);
4595 TRACE_2(SetPropHit
, entry
, sprop
);
4599 PCMETER(cache
->setpcmisses
++);
4603 JS_UNLOCK_OBJ(cx
, obj
);
4606 atom
= js_FullTestPropertyCache(cx
, regs
.pc
, &obj
, &obj2
,
4609 PCMETER(cache
->misses
++);
4610 PCMETER(cache
->setmisses
++);
4612 ASSERT_VALID_PROPERTY_CACHE_HIT(0, obj
, obj2
, entry
);
4615 JS_ASSERT(PCVAL_IS_SPROP(entry
->vword
));
4616 sprop
= PCVAL_TO_SPROP(entry
->vword
);
4617 JS_ASSERT(!(sprop
->attrs
& JSPROP_READONLY
));
4618 JS_ASSERT(!SCOPE_IS_SEALED(OBJ_SCOPE(obj2
)));
4619 NATIVE_SET(cx
, obj
, sprop
, &rval
);
4621 JS_UNLOCK_OBJ(cx
, obj2
);
4623 TRACE_2(SetPropHit
, entry
, sprop
);
4631 id
= ATOM_TO_JSID(atom
);
4633 if (!js_SetPropertyHelper(cx
, obj
, id
, &rval
, &entry
))
4637 TRACE_1(SetPropMiss
, entry
);
4640 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
4644 if (!entry
&& TRACE_RECORDER(cx
)) {
4645 js_AbortRecording(cx
, "SetPropUncached");
4650 END_SET_CASE_STORE_RVAL(JSOP_SETPROP
, 2);
4652 BEGIN_CASE(JSOP_GETELEM
)
4653 /* Open-coded ELEMENT_OP optimized for strings and dense arrays. */
4654 lval
= FETCH_OPND(-2);
4655 rval
= FETCH_OPND(-1);
4656 if (JSVAL_IS_STRING(lval
) && JSVAL_IS_INT(rval
)) {
4657 str
= JSVAL_TO_STRING(lval
);
4658 i
= JSVAL_TO_INT(rval
);
4659 if ((size_t)i
< JSSTRING_LENGTH(str
)) {
4660 str
= js_GetUnitString(cx
, str
, (size_t)i
);
4663 rval
= STRING_TO_JSVAL(str
);
4668 VALUE_TO_OBJECT(cx
, -2, lval
, obj
);
4669 if (JSVAL_IS_INT(rval
)) {
4670 if (OBJ_IS_DENSE_ARRAY(cx
, obj
)) {
4673 length
= ARRAY_DENSE_LENGTH(obj
);
4674 i
= JSVAL_TO_INT(rval
);
4675 if ((jsuint
)i
< length
&&
4676 i
< obj
->fslots
[JSSLOT_ARRAY_LENGTH
]) {
4677 rval
= obj
->dslots
[i
];
4678 if (rval
!= JSVAL_HOLE
)
4681 /* Reload rval from the stack in the rare hole case. */
4682 rval
= FETCH_OPND(-1);
4685 id
= INT_JSVAL_TO_JSID(rval
);
4687 if (!js_InternNonIntElementId(cx
, obj
, rval
, &id
))
4691 if (!OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
))
4695 STORE_OPND(-1, rval
);
4696 END_CASE(JSOP_GETELEM
)
4698 BEGIN_CASE(JSOP_CALLELEM
)
4700 * FIXME: JSOP_CALLELEM should call getMethod on XML objects as
4701 * CALLPROP does. See bug 362910.
4703 ELEMENT_OP(-1, OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
));
4704 #if JS_HAS_NO_SUCH_METHOD
4705 if (JS_UNLIKELY(JSVAL_IS_VOID(rval
))) {
4706 regs
.sp
[-2] = regs
.sp
[-1];
4707 regs
.sp
[-1] = OBJECT_TO_JSVAL(obj
);
4708 if (!js_OnUnknownMethod(cx
, regs
.sp
- 2))
4713 STORE_OPND(-2, rval
);
4714 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
4716 END_CASE(JSOP_CALLELEM
)
4718 BEGIN_CASE(JSOP_SETELEM
)
4719 rval
= FETCH_OPND(-1);
4720 FETCH_OBJECT(cx
, -3, lval
, obj
);
4721 FETCH_ELEMENT_ID(obj
, -2, id
);
4723 if (OBJ_IS_DENSE_ARRAY(cx
, obj
) && JSID_IS_INT(id
)) {
4726 length
= ARRAY_DENSE_LENGTH(obj
);
4727 i
= JSID_TO_INT(id
);
4728 if ((jsuint
)i
< length
) {
4729 if (obj
->dslots
[i
] == JSVAL_HOLE
) {
4730 if (rt
->anyArrayProtoHasElement
)
4732 if (i
>= obj
->fslots
[JSSLOT_ARRAY_LENGTH
])
4733 obj
->fslots
[JSSLOT_ARRAY_LENGTH
] = i
+ 1;
4734 obj
->fslots
[JSSLOT_ARRAY_COUNT
]++;
4736 obj
->dslots
[i
] = rval
;
4741 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
4744 END_SET_CASE_STORE_RVAL(JSOP_SETELEM
, 3)
4746 BEGIN_CASE(JSOP_ENUMELEM
)
4747 /* Funky: the value to set is under the [obj, id] pair. */
4748 rval
= FETCH_OPND(-3);
4749 FETCH_OBJECT(cx
, -2, lval
, obj
);
4750 FETCH_ELEMENT_ID(obj
, -1, id
);
4751 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
4754 END_CASE(JSOP_ENUMELEM
)
4756 BEGIN_CASE(JSOP_NEW
)
4757 /* Get immediate argc and find the constructor function. */
4758 argc
= GET_ARGC(regs
.pc
);
4759 vp
= regs
.sp
- (2 + argc
);
4760 JS_ASSERT(vp
>= StackBase(fp
));
4763 * Assign lval, obj, and fun exactly as the code at inline_call:
4764 * expects to find them, to avoid nesting a js_Interpret call via
4765 * js_InvokeConstructor.
4768 if (VALUE_IS_FUNCTION(cx
, lval
)) {
4769 obj
= JSVAL_TO_OBJECT(lval
);
4770 fun
= GET_FUNCTION_PRIVATE(cx
, obj
);
4771 if (FUN_INTERPRETED(fun
)) {
4772 /* Root as we go using vp[1]. */
4773 if (!OBJ_GET_PROPERTY(cx
, obj
,
4774 ATOM_TO_JSID(cx
->runtime
->atomState
4775 .classPrototypeAtom
),
4780 obj2
= js_NewObject(cx
, &js_ObjectClass
,
4781 JSVAL_IS_OBJECT(rval
)
4782 ? JSVAL_TO_OBJECT(rval
)
4784 OBJ_GET_PARENT(cx
, obj
),
4788 vp
[1] = OBJECT_TO_JSVAL(obj2
);
4789 flags
= JSFRAME_CONSTRUCTING
;
4794 if (!js_InvokeConstructor(cx
, argc
, JS_FALSE
, vp
))
4797 LOAD_INTERRUPT_HANDLER(cx
);
4800 BEGIN_CASE(JSOP_APPLY
)
4802 argc
= GET_ARGC(regs
.pc
);
4803 vp
= regs
.sp
- (argc
+ 2);
4805 if (!VALUE_IS_FUNCTION(cx
, lval
))
4807 obj
= JSVAL_TO_OBJECT(lval
);
4808 fun
= GET_FUNCTION_PRIVATE(cx
, obj
);
4809 if (FUN_INTERPRETED(fun
))
4812 bool apply
= (JSFastNative
)fun
->u
.n
.native
== js_fun_apply
;
4813 if (!apply
&& (JSFastNative
)fun
->u
.n
.native
!= js_fun_call
)
4817 * If the second arg to apply is null or void, treat it as an empty
4820 jsuint applylen
= 0;
4821 if (apply
&& argc
>= 2 &&
4822 !JSVAL_IS_VOID(vp
[3]) && !JSVAL_IS_NULL(vp
[3])) {
4824 * Fall back on js_Invoke when the array argument has a wrong
4825 * type or when it has too many elements to fit into the
4826 * current stack chunk.
4828 if (!JSVAL_IS_OBJECT(vp
[3]))
4832 JSObject
* aobj
= JSVAL_TO_OBJECT(vp
[3]);
4833 if (!js_IsArrayLike(cx
, aobj
, &arraylike
, &applylen
))
4835 if (!arraylike
|| applylen
> ARGC_LIMIT
)
4838 JSArena
*a
= cx
->stackPool
.current
;
4839 JS_ASSERT(jsuword(vp
+ 2) <= a
->limit
);
4842 * We need space for applylen elements plus an extra slot to
4843 * temporary root the array object when we unpack its elements
4844 * using OBJ_GET_PROPERTY below.
4846 if (a
->limit
- jsuword(vp
+ 2) < (applylen
+ 1) * sizeof(jsval
))
4850 if (!VALUE_IS_FUNCTION(cx
, vp
[1]))
4856 * Call fun with its global object as the 'this' param if
4861 /* Convert the first arg to 'this'. */
4862 if (!JSVAL_IS_PRIMITIVE(vp
[2]))
4863 obj
= JSVAL_TO_OBJECT(vp
[2]);
4864 else if (!js_ValueToObject(cx
, vp
[2], &obj
))
4867 vp
[1] = OBJECT_TO_JSVAL(obj
);
4872 memmove(vp
+ 2, vp
+ 3, argc
* sizeof *vp
);
4874 } else if (applylen
== 0) {
4878 * Make room for missing arguments to the right including the
4879 * temporary root nulling any extra stack slots for GC safety.
4881 jsval
* newsp
= vp
+ 2 + applylen
+ 1;
4882 if (newsp
> regs
.sp
) {
4883 JSArena
*a
= cx
->stackPool
.current
;
4884 JS_ASSERT(jsuword(newsp
) <= a
->limit
); /* see above */
4885 if ((jsuword
) newsp
> a
->avail
)
4886 a
->avail
= (jsuword
) newsp
;
4887 memset(vp
+ 2 + argc
, 0, (applylen
- argc
) * sizeof(jsval
));
4890 JSObject
*aobj
= JSVAL_TO_OBJECT(vp
[3]);
4894 /* Expand array content onto the stack. */
4895 for (i
= 0; i
< jsint(applylen
); i
++) {
4896 id
= INT_TO_JSID(i
);
4897 if (!OBJ_GET_PROPERTY(cx
, aobj
, id
, &vp
[2 + i
])) {
4899 * There is no good way to restore the original stack
4900 * state here, but it is in a reasonable state with
4901 * either original elements or nulls for all arguments
4902 * we didn't unpack yet, so we leave it at that.
4909 regs
.sp
= vp
+ 2 + argc
;
4910 TRACE_1(ApplyComplete
, argc
);
4911 goto do_call_with_specified_vp_and_argc
;
4914 BEGIN_CASE(JSOP_CALL
)
4915 BEGIN_CASE(JSOP_EVAL
)
4917 argc
= GET_ARGC(regs
.pc
);
4918 vp
= regs
.sp
- (argc
+ 2);
4920 do_call_with_specified_vp_and_argc
:
4922 if (VALUE_IS_FUNCTION(cx
, lval
)) {
4923 obj
= JSVAL_TO_OBJECT(lval
);
4924 fun
= GET_FUNCTION_PRIVATE(cx
, obj
);
4926 /* Clear frame flags since this is not a constructor call. */
4928 if (FUN_INTERPRETED(fun
))
4931 uintN nframeslots
, nvars
, missing
;
4936 JSInlineFrame
*newifp
;
4937 JSInterpreterHook hook
;
4939 /* Restrict recursion of lightweight functions. */
4940 if (inlineCallCount
== MAX_INLINE_CALL_COUNT
) {
4941 js_ReportOverRecursed(cx
);
4945 /* Compute the total number of stack slots needed by fun. */
4946 nframeslots
= JS_HOWMANY(sizeof(JSInlineFrame
),
4948 script
= fun
->u
.i
.script
;
4949 atoms
= script
->atomMap
.vector
;
4950 nbytes
= (nframeslots
+ script
->nslots
) * sizeof(jsval
);
4952 /* Allocate missing expected args adjacent to actuals. */
4953 a
= cx
->stackPool
.current
;
4954 newmark
= (void *) a
->avail
;
4955 if (fun
->nargs
<= argc
) {
4958 newsp
= vp
+ 2 + fun
->nargs
;
4959 JS_ASSERT(newsp
> regs
.sp
);
4960 if ((jsuword
) newsp
<= a
->limit
) {
4961 if ((jsuword
) newsp
> a
->avail
)
4962 a
->avail
= (jsuword
) newsp
;
4963 jsval
*argsp
= newsp
;
4965 *--argsp
= JSVAL_VOID
;
4966 } while (argsp
!= regs
.sp
);
4969 missing
= fun
->nargs
- argc
;
4970 nbytes
+= (2 + fun
->nargs
) * sizeof(jsval
);
4974 /* Allocate the inline frame with its slots and operands. */
4975 if (a
->avail
+ nbytes
<= a
->limit
) {
4976 newsp
= (jsval
*) a
->avail
;
4978 JS_ASSERT(missing
== 0);
4980 JS_ARENA_ALLOCATE_CAST(newsp
, jsval
*, &cx
->stackPool
,
4983 js_ReportOutOfScriptQuota(cx
);
4984 goto bad_inline_call
;
4988 * Move args if the missing ones overflow arena a, then
4989 * push undefined for the missing args.
4992 memcpy(newsp
, vp
, (2 + argc
) * sizeof(jsval
));
4994 newsp
= vp
+ 2 + argc
;
4996 *newsp
++ = JSVAL_VOID
;
4997 } while (--missing
!= 0);
5001 /* Claim space for the stack frame and initialize it. */
5002 newifp
= (JSInlineFrame
*) newsp
;
5003 newsp
+= nframeslots
;
5004 newifp
->frame
.callobj
= NULL
;
5005 newifp
->frame
.argsobj
= NULL
;
5006 newifp
->frame
.varobj
= NULL
;
5007 newifp
->frame
.script
= script
;
5008 newifp
->frame
.callee
= obj
;
5009 newifp
->frame
.fun
= fun
;
5010 newifp
->frame
.argc
= argc
;
5011 newifp
->frame
.argv
= vp
+ 2;
5012 newifp
->frame
.rval
= JSVAL_VOID
;
5013 newifp
->frame
.down
= fp
;
5014 newifp
->frame
.annotation
= NULL
;
5015 newifp
->frame
.scopeChain
= parent
= OBJ_GET_PARENT(cx
, obj
);
5016 newifp
->frame
.sharpDepth
= 0;
5017 newifp
->frame
.sharpArray
= NULL
;
5018 newifp
->frame
.flags
= flags
;
5019 newifp
->frame
.dormantNext
= NULL
;
5020 newifp
->frame
.xmlNamespace
= NULL
;
5021 newifp
->frame
.blockChain
= NULL
;
5022 if (script
->staticDepth
< JS_DISPLAY_SIZE
) {
5023 JSStackFrame
**disp
= &cx
->display
[script
->staticDepth
];
5024 newifp
->frame
.displaySave
= *disp
;
5025 *disp
= &newifp
->frame
;
5028 newifp
->frame
.pcDisabledSave
=
5029 JS_PROPERTY_CACHE(cx
).disabled
;
5031 newifp
->mark
= newmark
;
5033 /* Compute the 'this' parameter now that argv is set. */
5034 JS_ASSERT(!JSFUN_BOUND_METHOD_TEST(fun
->flags
));
5035 JS_ASSERT(JSVAL_IS_OBJECT(vp
[1]));
5036 newifp
->frame
.thisp
= (JSObject
*)vp
[1];
5038 newifp
->frame
.regs
= NULL
;
5039 newifp
->frame
.imacpc
= NULL
;
5040 newifp
->frame
.slots
= newsp
;
5042 /* Push void to initialize local variables. */
5043 nvars
= fun
->u
.i
.nvars
;
5045 *newsp
++ = JSVAL_VOID
;
5047 /* Call the debugger hook if present. */
5048 hook
= cx
->debugHooks
->callHook
;
5050 newifp
->hookData
= hook(cx
, &newifp
->frame
, JS_TRUE
, 0,
5051 cx
->debugHooks
->callHookData
);
5052 LOAD_INTERRUPT_HANDLER(cx
);
5054 newifp
->hookData
= NULL
;
5057 /* Scope with a call object parented by callee's parent. */
5058 if (JSFUN_HEAVYWEIGHT_TEST(fun
->flags
) &&
5059 !js_GetCallObject(cx
, &newifp
->frame
, parent
)) {
5060 goto bad_inline_call
;
5063 /* Switch version if currentVersion wasn't overridden. */
5064 newifp
->callerVersion
= (JSVersion
) cx
->version
;
5065 if (JS_LIKELY(cx
->version
== currentVersion
)) {
5066 currentVersion
= (JSVersion
) script
->version
;
5067 if (currentVersion
!= cx
->version
)
5068 js_SetVersion(cx
, currentVersion
);
5071 /* Push the frame and set interpreter registers. */
5072 newifp
->callerRegs
= regs
;
5073 fp
->regs
= &newifp
->callerRegs
;
5075 regs
.pc
= script
->code
;
5076 newifp
->frame
.regs
= ®s
;
5077 cx
->fp
= fp
= &newifp
->frame
;
5079 TRACE_0(EnterFrame
);
5082 JS_RUNTIME_METER(rt
, inlineCalls
);
5084 #ifdef INCLUDE_MOZILLA_DTRACE
5085 /* DTrace function entry, inlines */
5086 if (JAVASCRIPT_FUNCTION_ENTRY_ENABLED())
5087 jsdtrace_function_entry(cx
, fp
, fun
);
5088 if (JAVASCRIPT_FUNCTION_INFO_ENABLED())
5089 jsdtrace_function_info(cx
, fp
, fp
->down
, fun
);
5090 if (JAVASCRIPT_FUNCTION_ARGS_ENABLED())
5091 jsdtrace_function_args(cx
, fp
, fun
);
5094 /* Load first op and dispatch it (safe since JSOP_STOP). */
5095 op
= (JSOp
) *regs
.pc
;
5099 JS_ASSERT(fp
->regs
== ®s
);
5100 script
= fp
->script
;
5101 atoms
= script
->atomMap
.vector
;
5102 js_FreeRawStack(cx
, newmark
);
5106 #ifdef INCLUDE_MOZILLA_DTRACE
5107 /* DTrace function entry, non-inlines */
5108 if (VALUE_IS_FUNCTION(cx
, lval
)) {
5109 if (JAVASCRIPT_FUNCTION_ENTRY_ENABLED())
5110 jsdtrace_function_entry(cx
, fp
, fun
);
5111 if (JAVASCRIPT_FUNCTION_INFO_ENABLED())
5112 jsdtrace_function_info(cx
, fp
, fp
, fun
);
5113 if (JAVASCRIPT_FUNCTION_ARGS_ENABLED())
5114 jsdtrace_function_args(cx
, fp
, fun
);
5118 if (fun
->flags
& JSFUN_FAST_NATIVE
) {
5119 JS_ASSERT(fun
->u
.n
.extra
== 0);
5120 JS_ASSERT(JSVAL_IS_OBJECT(vp
[1]) ||
5121 PRIMITIVE_THIS_TEST(fun
, vp
[1]));
5122 ok
= ((JSFastNative
) fun
->u
.n
.native
)(cx
, argc
, vp
);
5123 #ifdef INCLUDE_MOZILLA_DTRACE
5124 if (VALUE_IS_FUNCTION(cx
, lval
)) {
5125 if (JAVASCRIPT_FUNCTION_RVAL_ENABLED())
5126 jsdtrace_function_rval(cx
, fp
, fun
);
5127 if (JAVASCRIPT_FUNCTION_RETURN_ENABLED())
5128 jsdtrace_function_return(cx
, fp
, fun
);
5134 TRACE_0(FastNativeCallComplete
);
5139 ok
= js_Invoke(cx
, argc
, vp
, 0);
5140 #ifdef INCLUDE_MOZILLA_DTRACE
5141 /* DTrace function return, non-inlines */
5142 if (VALUE_IS_FUNCTION(cx
, lval
)) {
5143 if (JAVASCRIPT_FUNCTION_RVAL_ENABLED())
5144 jsdtrace_function_rval(cx
, fp
, fun
);
5145 if (JAVASCRIPT_FUNCTION_RETURN_ENABLED())
5146 jsdtrace_function_return(cx
, fp
, fun
);
5150 LOAD_INTERRUPT_HANDLER(cx
);
5153 JS_RUNTIME_METER(rt
, nonInlineCalls
);
5156 #if JS_HAS_LVALUE_RETURN
5159 * Use the stack depth we didn't claim in our budget, but that
5160 * we know is there on account of [fun, this] already having
5161 * been pushed, at a minimum (if no args). Those two slots
5162 * have been popped and [rval] has been pushed, which leaves
5163 * one more slot for rval2 before we might overflow.
5165 * NB: rval2 must be the property identifier, and rval the
5166 * object from which to get the property. The pair form an
5167 * ECMA "reference type", which can be used on the right- or
5168 * left-hand side of assignment ops. Note well: only native
5169 * methods can return reference types. See JSOP_SETCALL just
5170 * below for the left-hand-side case.
5172 PUSH_OPND(cx
->rval2
);
5173 ELEMENT_OP(-1, OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
));
5176 STORE_OPND(-1, rval
);
5177 cx
->rval2set
= JS_FALSE
;
5179 #endif /* JS_HAS_LVALUE_RETURN */
5182 #if JS_HAS_LVALUE_RETURN
5183 BEGIN_CASE(JSOP_SETCALL
)
5184 argc
= GET_ARGC(regs
.pc
);
5185 vp
= regs
.sp
- argc
- 2;
5186 ok
= js_Invoke(cx
, argc
, vp
, 0);
5188 LOAD_INTERRUPT_HANDLER(cx
);
5191 if (!cx
->rval2set
) {
5192 op2
= (JSOp
) regs
.pc
[JSOP_SETCALL_LENGTH
];
5193 if (op2
!= JSOP_DELELEM
) {
5194 JS_ASSERT(!(js_CodeSpec
[op2
].format
& JOF_DEL
));
5195 JS_ReportErrorNumber(cx
, js_GetErrorMessage
, NULL
,
5196 JSMSG_BAD_LEFTSIDE_OF_ASS
);
5201 * Store true as the result of the emulated delete of a
5202 * non-existent property. NB: We don't METER_OP_PAIR here;
5203 * it doesn't seem worth the code for this obscure case.
5206 regs
.pc
+= JSOP_SETCALL_LENGTH
+ JSOP_DELELEM_LENGTH
;
5207 op
= (JSOp
) *regs
.pc
;
5210 PUSH_OPND(cx
->rval2
);
5211 cx
->rval2set
= JS_FALSE
;
5212 END_CASE(JSOP_SETCALL
)
5215 BEGIN_CASE(JSOP_NAME
)
5216 BEGIN_CASE(JSOP_CALLNAME
)
5218 JSPropCacheEntry
*entry
;
5220 obj
= fp
->scopeChain
;
5221 if (JS_LIKELY(OBJ_IS_NATIVE(obj
))) {
5222 PROPERTY_CACHE_TEST(cx
, regs
.pc
, obj
, obj2
, entry
, atom
);
5224 ASSERT_VALID_PROPERTY_CACHE_HIT(0, obj
, obj2
, entry
);
5225 if (PCVAL_IS_OBJECT(entry
->vword
)) {
5226 rval
= PCVAL_OBJECT_TO_JSVAL(entry
->vword
);
5227 JS_UNLOCK_OBJ(cx
, obj2
);
5231 if (PCVAL_IS_SLOT(entry
->vword
)) {
5232 slot
= PCVAL_TO_SLOT(entry
->vword
);
5233 JS_ASSERT(slot
< obj2
->map
->freeslot
);
5234 rval
= LOCKED_OBJ_GET_SLOT(obj2
, slot
);
5235 JS_UNLOCK_OBJ(cx
, obj2
);
5239 JS_ASSERT(PCVAL_IS_SPROP(entry
->vword
));
5240 sprop
= PCVAL_TO_SPROP(entry
->vword
);
5248 id
= ATOM_TO_JSID(atom
);
5249 if (js_FindPropertyHelper(cx
, id
, &obj
, &obj2
, &prop
, &entry
) < 0)
5252 /* Kludge to allow (typeof foo == "undefined") tests. */
5253 endpc
= script
->code
+ script
->length
;
5254 op2
= (JSOp
) regs
.pc
[JSOP_NAME_LENGTH
];
5255 if (op2
== JSOP_TYPEOF
) {
5256 PUSH_OPND(JSVAL_VOID
);
5257 len
= JSOP_NAME_LENGTH
;
5260 goto atom_not_defined
;
5263 /* Take the slow path if prop was not found in a native object. */
5264 if (!OBJ_IS_NATIVE(obj
) || !OBJ_IS_NATIVE(obj2
)) {
5265 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
5266 if (!OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
))
5270 sprop
= (JSScopeProperty
*)prop
;
5272 NATIVE_GET(cx
, obj
, obj2
, sprop
, &rval
);
5273 OBJ_DROP_PROPERTY(cx
, obj2
, (JSProperty
*) sprop
);
5278 if (op
== JSOP_CALLNAME
)
5279 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
5283 BEGIN_CASE(JSOP_UINT16
)
5284 i
= (jsint
) GET_UINT16(regs
.pc
);
5285 rval
= INT_TO_JSVAL(i
);
5287 END_CASE(JSOP_UINT16
)
5289 BEGIN_CASE(JSOP_UINT24
)
5290 i
= (jsint
) GET_UINT24(regs
.pc
);
5291 rval
= INT_TO_JSVAL(i
);
5293 END_CASE(JSOP_UINT24
)
5295 BEGIN_CASE(JSOP_INT8
)
5296 i
= GET_INT8(regs
.pc
);
5297 rval
= INT_TO_JSVAL(i
);
5301 BEGIN_CASE(JSOP_INT32
)
5302 i
= GET_INT32(regs
.pc
);
5303 rval
= INT_TO_JSVAL(i
);
5305 END_CASE(JSOP_INT32
)
5307 BEGIN_CASE(JSOP_INDEXBASE
)
5309 * Here atoms can exceed script->atomMap.length as we use atoms
5310 * as a segment register for object literals as well.
5312 atoms
+= GET_INDEXBASE(regs
.pc
);
5313 END_CASE(JSOP_INDEXBASE
)
5315 BEGIN_CASE(JSOP_INDEXBASE1
)
5316 BEGIN_CASE(JSOP_INDEXBASE2
)
5317 BEGIN_CASE(JSOP_INDEXBASE3
)
5318 atoms
+= (op
- JSOP_INDEXBASE1
+ 1) << 16;
5319 END_CASE(JSOP_INDEXBASE3
)
5321 BEGIN_CASE(JSOP_RESETBASE0
)
5322 BEGIN_CASE(JSOP_RESETBASE
)
5323 atoms
= script
->atomMap
.vector
;
5324 END_CASE(JSOP_RESETBASE
)
5326 BEGIN_CASE(JSOP_DOUBLE
)
5327 BEGIN_CASE(JSOP_STRING
)
5329 PUSH_OPND(ATOM_KEY(atom
));
5330 END_CASE(JSOP_DOUBLE
)
5332 BEGIN_CASE(JSOP_OBJECT
)
5334 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
5335 END_CASE(JSOP_OBJECT
)
5337 BEGIN_CASE(JSOP_REGEXP
)
5342 * Push a regexp object for the atom mapped by the bytecode at pc,
5343 * cloning the literal's regexp object if necessary, to simulate in
5344 * the pre-compile/execute-later case what ECMA specifies for the
5345 * compile-and-go case: that scanning each regexp literal creates
5346 * a single corresponding RegExp object.
5348 * To support pre-compilation transparently, we must handle the
5349 * case where a regexp object literal is used in a different global
5350 * at execution time from the global with which it was scanned at
5351 * compile time. We do this by re-wrapping the JSRegExp private
5352 * data struct with a cloned object having the right prototype and
5353 * parent, and having its own lastIndex property value storage.
5355 * Unlike JSOP_DEFFUN and other prolog bytecodes that may clone
5356 * literal objects, we don't want to pay a script prolog execution
5357 * price for all regexp literals in a script (many may not be used
5358 * by a particular execution of that script, depending on control
5359 * flow), so we initialize lazily here.
5361 * XXX This code is specific to regular expression objects. If we
5362 * need a similar op for other kinds of object literals, we should
5363 * push cloning down under JSObjectOps and reuse code here.
5365 index
= GET_FULL_INDEX(0);
5366 JS_ASSERT(index
< JS_SCRIPT_REGEXPS(script
)->length
);
5371 * We're in function code, not global or eval code (in eval
5372 * code, JSOP_REGEXP is never emitted). The cloned funobj
5373 * contains JS_SCRIPT_REGEXPS(script)->length reserved slots
5374 * for the cloned regexps; see fun_reserveSlots, jsfun.c.
5376 funobj
= fp
->callee
;
5377 slot
+= JSCLASS_RESERVED_SLOTS(&js_FunctionClass
);
5378 if (script
->upvarsOffset
!= 0)
5379 slot
+= JS_SCRIPT_UPVARS(script
)->length
;
5380 if (!JS_GetReservedSlot(cx
, funobj
, slot
, &rval
))
5382 if (JSVAL_IS_VOID(rval
))
5386 * We're in global code. The code generator reserved a slot
5387 * for the regexp among script->nfixed slots. All such slots
5388 * are initialized to null, not void, for faster testing in
5389 * JSOP_*GVAR cases. To simplify index calculations we count
5390 * regexps in the reverse order down from script->nslots - 1.
5392 JS_ASSERT(slot
< script
->nfixed
);
5393 slot
= script
->nfixed
- slot
- 1;
5394 rval
= fp
->slots
[slot
];
5396 funobj
= NULL
; /* suppress bogus gcc warnings */
5400 if (JSVAL_IS_NULL(rval
)) {
5401 /* Compute the current global object in obj2. */
5402 obj2
= fp
->scopeChain
;
5403 while ((parent
= OBJ_GET_PARENT(cx
, obj2
)) != NULL
)
5407 * If obj's parent is not obj2, we must clone obj so that it
5408 * has the right parent, and therefore, the right prototype.
5410 * Yes, this means we assume that the correct RegExp.prototype
5411 * to which regexp instances (including literals) delegate can
5412 * be distinguished solely by the instance's parent, which was
5413 * set to the parent of the RegExp constructor function object
5414 * when the instance was created. In other words,
5416 * (/x/.__parent__ == RegExp.__parent__) implies
5417 * (/x/.__proto__ == RegExp.prototype)
5419 * (unless you assign a different object to RegExp.prototype
5420 * at runtime, in which case, ECMA doesn't specify operation,
5421 * and you get what you deserve).
5423 * This same coupling between instance parent and constructor
5424 * parent turns up everywhere (see jsobj.c's FindClassObject,
5425 * js_ConstructObject, and js_NewObject). It's fundamental to
5426 * the design of the language when you consider multiple global
5427 * objects and separate compilation and execution, even though
5428 * it is not specified fully in ECMA.
5430 JS_GET_SCRIPT_REGEXP(script
, index
, obj
);
5431 if (OBJ_GET_PARENT(cx
, obj
) != obj2
) {
5432 obj
= js_CloneRegExpObject(cx
, obj
, obj2
);
5436 rval
= OBJECT_TO_JSVAL(obj
);
5438 /* Store the regexp object value in its cloneIndex slot. */
5440 if (!JS_SetReservedSlot(cx
, funobj
, slot
, rval
))
5443 fp
->slots
[slot
] = rval
;
5449 END_CASE(JSOP_REGEXP
)
5451 BEGIN_CASE(JSOP_ZERO
)
5452 PUSH_OPND(JSVAL_ZERO
);
5455 BEGIN_CASE(JSOP_ONE
)
5456 PUSH_OPND(JSVAL_ONE
);
5459 BEGIN_CASE(JSOP_NULL
)
5460 BEGIN_CASE(JSOP_NULLTHIS
)
5461 PUSH_OPND(JSVAL_NULL
);
5464 BEGIN_CASE(JSOP_FALSE
)
5465 PUSH_OPND(JSVAL_FALSE
);
5466 END_CASE(JSOP_FALSE
)
5468 BEGIN_CASE(JSOP_TRUE
)
5469 PUSH_OPND(JSVAL_TRUE
);
5472 BEGIN_CASE(JSOP_TABLESWITCH
)
5474 len
= GET_JUMP_OFFSET(pc2
);
5477 * ECMAv2+ forbids conversion of discriminant, so we will skip to
5478 * the default case if the discriminant isn't already an int jsval.
5479 * (This opcode is emitted only for dense jsint-domain switches.)
5482 if (JSVAL_IS_INT(rval
)) {
5483 i
= JSVAL_TO_INT(rval
);
5484 } else if (JSVAL_IS_DOUBLE(rval
) && *JSVAL_TO_DOUBLE(rval
) == 0) {
5485 /* Treat -0 (double) as 0. */
5491 pc2
+= JUMP_OFFSET_LEN
;
5492 low
= GET_JUMP_OFFSET(pc2
);
5493 pc2
+= JUMP_OFFSET_LEN
;
5494 high
= GET_JUMP_OFFSET(pc2
);
5497 if ((jsuint
)i
< (jsuint
)(high
- low
+ 1)) {
5498 pc2
+= JUMP_OFFSET_LEN
+ JUMP_OFFSET_LEN
* i
;
5499 off
= (jsint
) GET_JUMP_OFFSET(pc2
);
5505 BEGIN_CASE(JSOP_TABLESWITCHX
)
5507 len
= GET_JUMPX_OFFSET(pc2
);
5510 * ECMAv2+ forbids conversion of discriminant, so we will skip to
5511 * the default case if the discriminant isn't already an int jsval.
5512 * (This opcode is emitted only for dense jsint-domain switches.)
5515 if (JSVAL_IS_INT(rval
)) {
5516 i
= JSVAL_TO_INT(rval
);
5517 } else if (JSVAL_IS_DOUBLE(rval
) && *JSVAL_TO_DOUBLE(rval
) == 0) {
5518 /* Treat -0 (double) as 0. */
5524 pc2
+= JUMPX_OFFSET_LEN
;
5525 low
= GET_JUMP_OFFSET(pc2
);
5526 pc2
+= JUMP_OFFSET_LEN
;
5527 high
= GET_JUMP_OFFSET(pc2
);
5530 if ((jsuint
)i
< (jsuint
)(high
- low
+ 1)) {
5531 pc2
+= JUMP_OFFSET_LEN
+ JUMPX_OFFSET_LEN
* i
;
5532 off
= (jsint
) GET_JUMPX_OFFSET(pc2
);
5538 BEGIN_CASE(JSOP_LOOKUPSWITCHX
)
5539 off
= JUMPX_OFFSET_LEN
;
5540 goto do_lookup_switch
;
5542 BEGIN_CASE(JSOP_LOOKUPSWITCH
)
5543 off
= JUMP_OFFSET_LEN
;
5547 * JSOP_LOOKUPSWITCH and JSOP_LOOKUPSWITCHX are never used if
5548 * any atom index in it would exceed 64K limit.
5550 JS_ASSERT(atoms
== script
->atomMap
.vector
);
5554 if (!JSVAL_IS_NUMBER(lval
) &&
5555 !JSVAL_IS_STRING(lval
) &&
5556 !JSVAL_IS_BOOLEAN(lval
)) {
5557 goto end_lookup_switch
;
5561 npairs
= (jsint
) GET_UINT16(pc2
);
5563 JS_ASSERT(npairs
); /* empty switch uses JSOP_TABLESWITCH */
5565 #define SEARCH_PAIRS(MATCH_CODE) \
5567 JS_ASSERT(GET_INDEX(pc2) < script->atomMap.length); \
5568 atom = atoms[GET_INDEX(pc2)]; \
5569 rval = ATOM_KEY(atom); \
5575 if (--npairs == 0) { \
5580 if (JSVAL_IS_STRING(lval
)) {
5581 str
= JSVAL_TO_STRING(lval
);
5583 match
= (JSVAL_IS_STRING(rval
) &&
5584 ((str2
= JSVAL_TO_STRING(rval
)) == str
||
5585 js_EqualStrings(str2
, str
)));
5587 } else if (JSVAL_IS_DOUBLE(lval
)) {
5588 d
= *JSVAL_TO_DOUBLE(lval
);
5590 match
= (JSVAL_IS_DOUBLE(rval
) &&
5591 *JSVAL_TO_DOUBLE(rval
) == d
);
5595 match
= (lval
== rval
);
5601 len
= (op
== JSOP_LOOKUPSWITCH
)
5602 ? GET_JUMP_OFFSET(pc2
)
5603 : GET_JUMPX_OFFSET(pc2
);
5606 BEGIN_CASE(JSOP_TRAP
)
5608 JSTrapStatus status
;
5610 status
= JS_HandleTrap(cx
, script
, regs
.pc
, &rval
);
5619 cx
->throwing
= JS_TRUE
;
5620 cx
->exception
= rval
;
5625 JS_ASSERT(status
== JSTRAP_CONTINUE
);
5626 LOAD_INTERRUPT_HANDLER(cx
);
5627 JS_ASSERT(JSVAL_IS_INT(rval
));
5628 op
= (JSOp
) JSVAL_TO_INT(rval
);
5629 JS_ASSERT((uintN
)op
< (uintN
)JSOP_LIMIT
);
5633 BEGIN_CASE(JSOP_ARGUMENTS
)
5634 if (!js_GetArgsValue(cx
, fp
, &rval
))
5637 END_CASE(JSOP_ARGUMENTS
)
5639 BEGIN_CASE(JSOP_ARGSUB
)
5640 id
= INT_TO_JSID(GET_ARGNO(regs
.pc
));
5641 if (!js_GetArgsProperty(cx
, fp
, id
, &rval
))
5644 END_CASE(JSOP_ARGSUB
)
5646 BEGIN_CASE(JSOP_ARGCNT
)
5647 id
= ATOM_TO_JSID(rt
->atomState
.lengthAtom
);
5648 if (!js_GetArgsProperty(cx
, fp
, id
, &rval
))
5651 END_CASE(JSOP_ARGCNT
)
5653 BEGIN_CASE(JSOP_GETARG
)
5654 BEGIN_CASE(JSOP_CALLARG
)
5655 slot
= GET_ARGNO(regs
.pc
);
5656 JS_ASSERT(slot
< fp
->fun
->nargs
);
5657 METER_SLOT_OP(op
, slot
);
5658 PUSH_OPND(fp
->argv
[slot
]);
5659 if (op
== JSOP_CALLARG
)
5660 PUSH_OPND(JSVAL_NULL
);
5661 END_CASE(JSOP_GETARG
)
5663 BEGIN_CASE(JSOP_SETARG
)
5664 slot
= GET_ARGNO(regs
.pc
);
5665 JS_ASSERT(slot
< fp
->fun
->nargs
);
5666 METER_SLOT_OP(op
, slot
);
5667 vp
= &fp
->argv
[slot
];
5669 *vp
= FETCH_OPND(-1);
5670 END_SET_CASE(JSOP_SETARG
)
5672 BEGIN_CASE(JSOP_GETLOCAL
)
5673 slot
= GET_SLOTNO(regs
.pc
);
5674 JS_ASSERT(slot
< script
->nslots
);
5675 PUSH_OPND(fp
->slots
[slot
]);
5676 END_CASE(JSOP_GETLOCAL
)
5678 BEGIN_CASE(JSOP_CALLLOCAL
)
5679 slot
= GET_SLOTNO(regs
.pc
);
5680 JS_ASSERT(slot
< script
->nslots
);
5681 PUSH_OPND(fp
->slots
[slot
]);
5682 PUSH_OPND(JSVAL_NULL
);
5683 END_CASE(JSOP_CALLLOCAL
)
5685 BEGIN_CASE(JSOP_SETLOCAL
)
5686 slot
= GET_SLOTNO(regs
.pc
);
5687 JS_ASSERT(slot
< script
->nslots
);
5688 vp
= &fp
->slots
[slot
];
5690 *vp
= FETCH_OPND(-1);
5691 END_SET_CASE(JSOP_SETLOCAL
)
5693 BEGIN_CASE(JSOP_GETUPVAR
)
5694 BEGIN_CASE(JSOP_CALLUPVAR
)
5700 index
= GET_UINT16(regs
.pc
);
5701 uva
= JS_SCRIPT_UPVARS(script
);
5702 JS_ASSERT(index
< uva
->length
);
5703 skip
= UPVAR_FRAME_SKIP(uva
->vector
[index
]);
5704 fp2
= cx
->display
[script
->staticDepth
- skip
];
5705 JS_ASSERT(fp2
->fun
&& fp2
->script
);
5707 slot
= UPVAR_FRAME_SLOT(uva
->vector
[index
]);
5708 if (slot
< fp2
->fun
->nargs
) {
5711 slot
-= fp2
->fun
->nargs
;
5712 JS_ASSERT(slot
< fp2
->script
->nslots
);
5716 PUSH_OPND(vp
[slot
]);
5717 if (op
== JSOP_CALLUPVAR
)
5718 PUSH_OPND(JSVAL_NULL
);
5720 END_CASE(JSOP_GETUPVAR
)
5722 BEGIN_CASE(JSOP_GETGVAR
)
5723 BEGIN_CASE(JSOP_CALLGVAR
)
5724 slot
= GET_SLOTNO(regs
.pc
);
5725 JS_ASSERT(slot
< GlobalVarCount(fp
));
5726 METER_SLOT_OP(op
, slot
);
5727 lval
= fp
->slots
[slot
];
5728 if (JSVAL_IS_NULL(lval
)) {
5729 op
= (op
== JSOP_GETGVAR
) ? JSOP_NAME
: JSOP_CALLNAME
;
5733 slot
= JSVAL_TO_INT(lval
);
5734 rval
= OBJ_GET_SLOT(cx
, obj
, slot
);
5736 if (op
== JSOP_CALLGVAR
)
5737 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
5738 END_CASE(JSOP_GETGVAR
)
5740 BEGIN_CASE(JSOP_SETGVAR
)
5741 slot
= GET_SLOTNO(regs
.pc
);
5742 JS_ASSERT(slot
< GlobalVarCount(fp
));
5743 METER_SLOT_OP(op
, slot
);
5744 rval
= FETCH_OPND(-1);
5746 lval
= fp
->slots
[slot
];
5747 if (JSVAL_IS_NULL(lval
)) {
5749 * Inline-clone and deoptimize JSOP_SETNAME code here because
5750 * JSOP_SETGVAR has arity 1: [rval], not arity 2: [obj, rval]
5751 * as JSOP_SETNAME does, where [obj] is due to JSOP_BINDNAME.
5754 id
= ATOM_TO_JSID(atom
);
5755 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
5758 slot
= JSVAL_TO_INT(lval
);
5759 JS_LOCK_OBJ(cx
, obj
);
5760 LOCKED_OBJ_WRITE_BARRIER(cx
, obj
, slot
, rval
);
5761 JS_UNLOCK_OBJ(cx
, obj
);
5763 END_SET_CASE(JSOP_SETGVAR
)
5765 BEGIN_CASE(JSOP_DEFCONST
)
5766 BEGIN_CASE(JSOP_DEFVAR
)
5767 index
= GET_INDEX(regs
.pc
);
5768 atom
= atoms
[index
];
5771 * index is relative to atoms at this point but for global var
5772 * code below we need the absolute value.
5774 index
+= atoms
- script
->atomMap
.vector
;
5776 attrs
= JSPROP_ENUMERATE
;
5777 if (!(fp
->flags
& JSFRAME_EVAL
))
5778 attrs
|= JSPROP_PERMANENT
;
5779 if (op
== JSOP_DEFCONST
)
5780 attrs
|= JSPROP_READONLY
;
5782 /* Lookup id in order to check for redeclaration problems. */
5783 id
= ATOM_TO_JSID(atom
);
5784 if (!js_CheckRedeclaration(cx
, obj
, id
, attrs
, &obj2
, &prop
))
5787 /* Bind a variable only if it's not yet defined. */
5789 if (!OBJ_DEFINE_PROPERTY(cx
, obj
, id
, JSVAL_VOID
,
5790 JS_PropertyStub
, JS_PropertyStub
,
5799 * Try to optimize a property we either just created, or found
5800 * directly in the global object, that is permanent, has a slot,
5801 * and has stub getter and setter, into a "fast global" accessed
5802 * by the JSOP_*GVAR opcodes.
5805 index
< GlobalVarCount(fp
) &&
5806 (attrs
& JSPROP_PERMANENT
) &&
5808 OBJ_IS_NATIVE(obj
)) {
5809 sprop
= (JSScopeProperty
*) prop
;
5810 if (SPROP_HAS_VALID_SLOT(sprop
, OBJ_SCOPE(obj
)) &&
5811 SPROP_HAS_STUB_GETTER(sprop
) &&
5812 SPROP_HAS_STUB_SETTER(sprop
)) {
5814 * Fast globals use frame variables to map the global
5815 * name's atom index to the permanent fp->varobj slot
5816 * number, tagged as a jsval. The atom index for the
5817 * global's name literal is identical to its variable
5820 fp
->slots
[index
] = INT_TO_JSVAL(sprop
->slot
);
5824 OBJ_DROP_PROPERTY(cx
, obj2
, prop
);
5825 END_CASE(JSOP_DEFVAR
)
5827 BEGIN_CASE(JSOP_DEFFUN
)
5829 * A top-level function defined in Global or Eval code (see
5830 * ECMA-262 Ed. 3), or else a SpiderMonkey extension: a named
5831 * function statement in a compound statement (not at the top
5832 * statement level of global code, or at the top level of a
5837 if (!fp
->blockChain
) {
5838 obj2
= fp
->scopeChain
;
5840 obj2
= js_GetScopeChain(cx
, fp
);
5846 * If static link is not current scope, clone fun's object to link
5847 * to the current scope via parent. This clause exists to enable
5848 * sharing of compiled functions among multiple equivalent scopes,
5849 * splitting the cost of compilation evenly among the scopes and
5850 * amortizing it over a number of executions. Examples include XUL
5851 * scripts and event handlers shared among Mozilla chrome windows,
5852 * and server-side JS user-defined functions shared among requests.
5854 obj
= FUN_OBJECT(fun
);
5855 if (OBJ_GET_PARENT(cx
, obj
) != obj2
) {
5856 obj
= js_CloneFunctionObject(cx
, fun
, obj2
);
5862 * Protect obj from any GC hiding below OBJ_DEFINE_PROPERTY. All
5863 * paths from here must flow through the "Restore fp->scopeChain"
5864 * code below the OBJ_DEFINE_PROPERTY call.
5866 MUST_FLOW_THROUGH("restore");
5867 fp
->scopeChain
= obj
;
5868 rval
= OBJECT_TO_JSVAL(obj
);
5871 * ECMA requires functions defined when entering Eval code to be
5874 attrs
= (fp
->flags
& JSFRAME_EVAL
)
5876 : JSPROP_ENUMERATE
| JSPROP_PERMANENT
;
5879 * Load function flags that are also property attributes. Getters
5880 * and setters do not need a slot, their value is stored elsewhere
5881 * in the property itself, not in obj slots.
5883 flags
= JSFUN_GSFLAG2ATTR(fun
->flags
);
5885 attrs
|= flags
| JSPROP_SHARED
;
5890 * We define the function as a property of the variable object and
5891 * not the current scope chain even for the case of function
5892 * expression statements and functions defined by eval inside let
5895 parent
= fp
->varobj
;
5899 * Check for a const property of the same name -- or any kind
5900 * of property if executing with the strict option. We check
5901 * here at runtime as well as at compile-time, to handle eval
5902 * as well as multiple HTML script tags.
5904 id
= ATOM_TO_JSID(fun
->atom
);
5905 ok
= js_CheckRedeclaration(cx
, parent
, id
, attrs
, NULL
, NULL
);
5907 if (attrs
== JSPROP_ENUMERATE
) {
5908 JS_ASSERT(fp
->flags
& JSFRAME_EVAL
);
5909 ok
= OBJ_SET_PROPERTY(cx
, parent
, id
, &rval
);
5911 JS_ASSERT(attrs
& JSPROP_PERMANENT
);
5913 ok
= OBJ_DEFINE_PROPERTY(cx
, parent
, id
, rval
,
5914 (flags
& JSPROP_GETTER
)
5915 ? JS_EXTENSION (JSPropertyOp
) obj
5917 (flags
& JSPROP_SETTER
)
5918 ? JS_EXTENSION (JSPropertyOp
) obj
5925 /* Restore fp->scopeChain now that obj is defined in fp->varobj. */
5926 MUST_FLOW_LABEL(restore
)
5927 fp
->scopeChain
= obj2
;
5929 cx
->weakRoots
.newborn
[GCX_OBJECT
] = NULL
;
5932 END_CASE(JSOP_DEFFUN
)
5934 BEGIN_CASE(JSOP_DEFLOCALFUN
)
5935 LOAD_FUNCTION(SLOTNO_LEN
);
5938 * Define a local function (i.e., one nested at the top level of
5939 * another function), parented by the current scope chain, and
5940 * stored in a local variable slot that the compiler allocated.
5941 * This is an optimization over JSOP_DEFFUN that avoids requiring
5942 * a call object for the outer function's activation.
5944 slot
= GET_SLOTNO(regs
.pc
);
5946 parent
= js_GetScopeChain(cx
, fp
);
5950 obj
= FUN_OBJECT(fun
);
5951 if (OBJ_GET_PARENT(cx
, obj
) != parent
) {
5952 obj
= js_CloneFunctionObject(cx
, fun
, parent
);
5957 TRACE_2(DefLocalFunSetSlot
, slot
, obj
);
5959 fp
->slots
[slot
] = OBJECT_TO_JSVAL(obj
);
5960 END_CASE(JSOP_DEFLOCALFUN
)
5962 BEGIN_CASE(JSOP_ANONFUNOBJ
)
5963 /* Load the specified function object literal. */
5966 /* If re-parenting, push a clone of the function object. */
5967 parent
= js_GetScopeChain(cx
, fp
);
5970 obj
= FUN_OBJECT(fun
);
5971 if (OBJ_GET_PARENT(cx
, obj
) != parent
) {
5972 obj
= js_CloneFunctionObject(cx
, fun
, parent
);
5976 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
5977 END_CASE(JSOP_ANONFUNOBJ
)
5979 BEGIN_CASE(JSOP_NAMEDFUNOBJ
)
5983 * ECMA ed. 3 FunctionExpression: function Identifier [etc.].
5985 * 1. Create a new object as if by the expression new Object().
5986 * 2. Add Result(1) to the front of the scope chain.
5988 * Step 2 is achieved by making the new object's parent be the
5989 * current scope chain, and then making the new object the parent
5990 * of the Function object clone.
5992 obj2
= js_GetScopeChain(cx
, fp
);
5995 parent
= js_NewObject(cx
, &js_ObjectClass
, NULL
, obj2
, 0);
6000 * 3. Create a new Function object as specified in section 13.2
6001 * with [parameters and body specified by the function expression
6002 * that was parsed by the compiler into a Function object, and
6003 * saved in the script's atom map].
6005 * Protect parent from the GC.
6007 fp
->scopeChain
= parent
;
6008 obj
= js_CloneFunctionObject(cx
, fun
, parent
);
6013 * Protect obj from any GC hiding below OBJ_DEFINE_PROPERTY. All
6014 * paths from here must flow through the "Restore fp->scopeChain"
6015 * code below the OBJ_DEFINE_PROPERTY call.
6017 MUST_FLOW_THROUGH("restore2");
6018 fp
->scopeChain
= obj
;
6019 rval
= OBJECT_TO_JSVAL(obj
);
6022 * 4. Create a property in the object Result(1). The property's
6023 * name is [fun->atom, the identifier parsed by the compiler],
6024 * value is Result(3), and attributes are { DontDelete, ReadOnly }.
6026 attrs
= JSFUN_GSFLAG2ATTR(fun
->flags
);
6028 attrs
|= JSPROP_SHARED
;
6031 ok
= OBJ_DEFINE_PROPERTY(cx
, parent
, ATOM_TO_JSID(fun
->atom
), rval
,
6032 (attrs
& JSPROP_GETTER
)
6033 ? JS_EXTENSION (JSPropertyOp
) obj
6035 (attrs
& JSPROP_SETTER
)
6036 ? JS_EXTENSION (JSPropertyOp
) obj
6039 JSPROP_ENUMERATE
| JSPROP_PERMANENT
|
6043 /* Restore fp->scopeChain now that obj is defined in parent. */
6044 MUST_FLOW_LABEL(restore2
)
6045 fp
->scopeChain
= obj2
;
6047 cx
->weakRoots
.newborn
[GCX_OBJECT
] = NULL
;
6052 * 5. Remove Result(1) from the front of the scope chain [no-op].
6053 * 6. Return Result(3).
6055 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
6056 END_CASE(JSOP_NAMEDFUNOBJ
)
6058 #if JS_HAS_GETTER_SETTER
6059 BEGIN_CASE(JSOP_GETTER
)
6060 BEGIN_CASE(JSOP_SETTER
)
6062 op2
= (JSOp
) *++regs
.pc
;
6064 case JSOP_INDEXBASE
:
6065 atoms
+= GET_INDEXBASE(regs
.pc
);
6066 regs
.pc
+= JSOP_INDEXBASE_LENGTH
- 1;
6067 goto do_getter_setter
;
6068 case JSOP_INDEXBASE1
:
6069 case JSOP_INDEXBASE2
:
6070 case JSOP_INDEXBASE3
:
6071 atoms
+= (op2
- JSOP_INDEXBASE1
+ 1) << 16;
6072 goto do_getter_setter
;
6077 id
= ATOM_TO_JSID(atom
);
6078 rval
= FETCH_OPND(-1);
6083 rval
= FETCH_OPND(-1);
6087 FETCH_OBJECT(cx
, i
- 1, lval
, obj
);
6091 JS_ASSERT(regs
.sp
- StackBase(fp
) >= 2);
6092 rval
= FETCH_OPND(-1);
6095 id
= ATOM_TO_JSID(atom
);
6099 JS_ASSERT(op2
== JSOP_INITELEM
);
6101 JS_ASSERT(regs
.sp
- StackBase(fp
) >= 3);
6102 rval
= FETCH_OPND(-1);
6106 lval
= FETCH_OPND(i
-1);
6107 JS_ASSERT(JSVAL_IS_OBJECT(lval
));
6108 obj
= JSVAL_TO_OBJECT(lval
);
6112 /* Ensure that id has a type suitable for use with obj. */
6114 FETCH_ELEMENT_ID(obj
, i
, id
);
6116 if (JS_TypeOfValue(cx
, rval
) != JSTYPE_FUNCTION
) {
6117 JS_ReportErrorNumber(cx
, js_GetErrorMessage
, NULL
,
6118 JSMSG_BAD_GETTER_OR_SETTER
,
6126 * Getters and setters are just like watchpoints from an access
6127 * control point of view.
6129 if (!OBJ_CHECK_ACCESS(cx
, obj
, id
, JSACC_WATCH
, &rtmp
, &attrs
))
6132 if (op
== JSOP_GETTER
) {
6133 getter
= JS_EXTENSION (JSPropertyOp
) JSVAL_TO_OBJECT(rval
);
6134 setter
= JS_PropertyStub
;
6135 attrs
= JSPROP_GETTER
;
6137 getter
= JS_PropertyStub
;
6138 setter
= JS_EXTENSION (JSPropertyOp
) JSVAL_TO_OBJECT(rval
);
6139 attrs
= JSPROP_SETTER
;
6141 attrs
|= JSPROP_ENUMERATE
| JSPROP_SHARED
;
6143 /* Check for a readonly or permanent property of the same name. */
6144 if (!js_CheckRedeclaration(cx
, obj
, id
, attrs
, NULL
, NULL
))
6147 if (!OBJ_DEFINE_PROPERTY(cx
, obj
, id
, JSVAL_VOID
, getter
, setter
,
6153 if (js_CodeSpec
[op2
].ndefs
)
6154 STORE_OPND(-1, rval
);
6155 len
= js_CodeSpec
[op2
].length
;
6157 #endif /* JS_HAS_GETTER_SETTER */
6159 BEGIN_CASE(JSOP_HOLE
)
6160 PUSH_OPND(JSVAL_HOLE
);
6163 BEGIN_CASE(JSOP_NEWARRAY
)
6164 len
= GET_UINT24(regs
.pc
);
6165 JS_ASSERT(len
<= regs
.sp
- StackBase(fp
));
6166 obj
= js_NewArrayObject(cx
, len
, regs
.sp
- len
, JS_TRUE
);
6170 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
6171 END_CASE(JSOP_NEWARRAY
)
6173 BEGIN_CASE(JSOP_NEWINIT
)
6174 i
= GET_INT8(regs
.pc
);
6175 JS_ASSERT(i
== JSProto_Array
|| i
== JSProto_Object
);
6176 obj
= (i
== JSProto_Array
)
6177 ? js_NewArrayObject(cx
, 0, NULL
)
6178 : js_NewObject(cx
, &js_ObjectClass
, NULL
, NULL
, 0);
6181 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
6183 LOAD_INTERRUPT_HANDLER(cx
);
6184 END_CASE(JSOP_NEWINIT
)
6186 BEGIN_CASE(JSOP_ENDINIT
)
6187 if (--fp
->sharpDepth
== 0)
6188 fp
->sharpArray
= NULL
;
6190 /* Re-set the newborn root to the top of this object tree. */
6191 JS_ASSERT(regs
.sp
- StackBase(fp
) >= 1);
6192 lval
= FETCH_OPND(-1);
6193 JS_ASSERT(JSVAL_IS_OBJECT(lval
));
6194 cx
->weakRoots
.newborn
[GCX_OBJECT
] = JSVAL_TO_GCTHING(lval
);
6195 END_CASE(JSOP_ENDINIT
)
6197 BEGIN_CASE(JSOP_INITPROP
)
6198 /* Load the property's initial value into rval. */
6199 JS_ASSERT(regs
.sp
- StackBase(fp
) >= 2);
6200 rval
= FETCH_OPND(-1);
6202 /* Load the object being initialized into lval/obj. */
6203 lval
= FETCH_OPND(-2);
6204 obj
= JSVAL_TO_OBJECT(lval
);
6205 JS_ASSERT(OBJ_IS_NATIVE(obj
));
6206 JS_ASSERT(!OBJ_GET_CLASS(cx
, obj
)->reserveSlots
);
6207 JS_ASSERT(!(LOCKED_OBJ_GET_CLASS(obj
)->flags
&
6208 JSCLASS_SHARE_ALL_PROPERTIES
));
6213 JSPropertyCache
*cache
;
6214 JSPropCacheEntry
*entry
;
6216 JS_LOCK_OBJ(cx
, obj
);
6217 scope
= OBJ_SCOPE(obj
);
6218 JS_ASSERT(!SCOPE_IS_SEALED(scope
));
6219 kshape
= scope
->shape
;
6220 cache
= &JS_PROPERTY_CACHE(cx
);
6221 entry
= &cache
->table
[PROPERTY_CACHE_HASH_PC(regs
.pc
, kshape
)];
6222 PCMETER(cache
->tests
++);
6223 PCMETER(cache
->initests
++);
6225 if (entry
->kpc
== regs
.pc
&& entry
->kshape
== kshape
) {
6226 PCMETER(cache
->pchits
++);
6227 PCMETER(cache
->inipchits
++);
6229 JS_ASSERT(PCVAL_IS_SPROP(entry
->vword
));
6230 sprop
= PCVAL_TO_SPROP(entry
->vword
);
6231 JS_ASSERT(!(sprop
->attrs
& JSPROP_READONLY
));
6234 * If this property has a non-stub setter, it must be
6235 * __proto__, __parent__, or another "shared prototype"
6236 * built-in. Force a miss to save code size here and let
6237 * the standard code path take care of business.
6239 if (!SPROP_HAS_STUB_SETTER(sprop
))
6240 goto do_initprop_miss
;
6242 if (scope
->object
!= obj
) {
6243 scope
= js_GetMutableScope(cx
, obj
);
6245 JS_UNLOCK_OBJ(cx
, obj
);
6251 * Detect a repeated property name and force a miss to
6252 * share the strict warning code and cope with complexity
6253 * managed by js_AddScopeProperty.
6255 if (sprop
->parent
!= scope
->lastProp
)
6256 goto do_initprop_miss
;
6258 TRACE_2(SetPropHit
, entry
, sprop
);
6261 * Otherwise this entry must be for a direct property of
6262 * obj, not a proto-property, and there cannot have been
6263 * any deletions of prior properties.
6265 JS_ASSERT(PCVCAP_MAKE(sprop
->shape
, 0, 0) == entry
->vcap
);
6266 JS_ASSERT(!SCOPE_HAD_MIDDLE_DELETE(scope
));
6267 JS_ASSERT(!scope
->table
||
6268 !SCOPE_HAS_PROPERTY(scope
, sprop
));
6271 JS_ASSERT(slot
== scope
->map
.freeslot
);
6272 if (slot
< STOBJ_NSLOTS(obj
)) {
6273 ++scope
->map
.freeslot
;
6275 if (!js_AllocSlot(cx
, obj
, &slot
)) {
6276 JS_UNLOCK_SCOPE(cx
, scope
);
6279 JS_ASSERT(slot
== sprop
->slot
);
6282 JS_ASSERT(!scope
->lastProp
||
6283 scope
->shape
== scope
->lastProp
->shape
);
6285 JSScopeProperty
*sprop2
=
6286 js_AddScopeProperty(cx
, scope
, sprop
->id
,
6287 sprop
->getter
, sprop
->setter
,
6289 sprop
->flags
, sprop
->shortid
);
6291 js_FreeSlot(cx
, obj
, slot
);
6292 JS_UNLOCK_SCOPE(cx
, scope
);
6295 JS_ASSERT(sprop2
== sprop
);
6297 scope
->shape
= sprop
->shape
;
6298 ++scope
->entryCount
;
6299 scope
->lastProp
= sprop
;
6302 GC_WRITE_BARRIER(cx
, scope
,
6303 LOCKED_OBJ_GET_SLOT(obj
, slot
),
6305 LOCKED_OBJ_SET_SLOT(obj
, slot
, rval
);
6306 JS_UNLOCK_SCOPE(cx
, scope
);
6311 PCMETER(cache
->inipcmisses
++);
6312 JS_UNLOCK_SCOPE(cx
, scope
);
6314 /* Get the immediate property name into id. */
6316 id
= ATOM_TO_JSID(atom
);
6318 /* Set the property named by obj[id] to rval. */
6319 if (!js_CheckRedeclaration(cx
, obj
, id
, JSPROP_INITIALIZER
,
6323 if (!js_SetPropertyHelper(cx
, obj
, id
, &rval
, &entry
))
6327 TRACE_1(SetPropMiss
, entry
);
6331 /* Common tail for property cache hit and miss cases. */
6333 END_CASE(JSOP_INITPROP
);
6335 BEGIN_CASE(JSOP_INITELEM
)
6336 /* Pop the element's value into rval. */
6337 JS_ASSERT(regs
.sp
- StackBase(fp
) >= 3);
6338 rval
= FETCH_OPND(-1);
6340 /* Find the object being initialized at top of stack. */
6341 lval
= FETCH_OPND(-3);
6342 JS_ASSERT(!JSVAL_IS_PRIMITIVE(lval
));
6343 obj
= JSVAL_TO_OBJECT(lval
);
6345 /* Fetch id now that we have obj. */
6346 FETCH_ELEMENT_ID(obj
, -2, id
);
6349 * Check for property redeclaration strict warning (we may be in
6350 * an object initialiser, not an array initialiser).
6352 if (!js_CheckRedeclaration(cx
, obj
, id
, JSPROP_INITIALIZER
, NULL
,
6358 * If rval is a hole, do not call OBJ_SET_PROPERTY. In this case,
6359 * obj must be an array, so if the current op is the last element
6360 * initialiser, set the array length to one greater than id.
6362 if (rval
== JSVAL_HOLE
) {
6363 JS_ASSERT(OBJ_IS_ARRAY(cx
, obj
));
6364 JS_ASSERT(JSID_IS_INT(id
));
6365 JS_ASSERT((jsuint
) JSID_TO_INT(id
) < ARRAY_INIT_LIMIT
);
6366 if ((JSOp
) regs
.pc
[JSOP_INITELEM_LENGTH
] == JSOP_ENDINIT
&&
6367 !js_SetLengthProperty(cx
, obj
,
6368 (jsuint
) (JSID_TO_INT(id
) + 1))) {
6372 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
6376 END_CASE(JSOP_INITELEM
)
6378 #if JS_HAS_SHARP_VARS
6379 BEGIN_CASE(JSOP_DEFSHARP
)
6380 obj
= fp
->sharpArray
;
6382 obj
= js_NewArrayObject(cx
, 0, NULL
);
6385 fp
->sharpArray
= obj
;
6387 i
= (jsint
) GET_UINT16(regs
.pc
);
6388 id
= INT_TO_JSID(i
);
6389 rval
= FETCH_OPND(-1);
6390 if (JSVAL_IS_PRIMITIVE(rval
)) {
6392 JS_snprintf(numBuf
, sizeof numBuf
, "%u", (unsigned) i
);
6393 JS_ReportErrorNumber(cx
, js_GetErrorMessage
, NULL
,
6394 JSMSG_BAD_SHARP_DEF
, numBuf
);
6397 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
6399 END_CASE(JSOP_DEFSHARP
)
6401 BEGIN_CASE(JSOP_USESHARP
)
6402 i
= (jsint
) GET_UINT16(regs
.pc
);
6403 id
= INT_TO_JSID(i
);
6404 obj
= fp
->sharpArray
;
6408 if (!OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
))
6411 if (!JSVAL_IS_OBJECT(rval
)) {
6414 JS_snprintf(numBuf
, sizeof numBuf
, "%u", (unsigned) i
);
6415 JS_ReportErrorNumber(cx
, js_GetErrorMessage
, NULL
,
6416 JSMSG_BAD_SHARP_USE
, numBuf
);
6420 END_CASE(JSOP_USESHARP
)
6421 #endif /* JS_HAS_SHARP_VARS */
6423 BEGIN_CASE(JSOP_GOSUB
)
6425 i
= PTRDIFF(regs
.pc
, script
->main
, jsbytecode
) + JSOP_GOSUB_LENGTH
;
6426 PUSH(INT_TO_JSVAL(i
));
6427 len
= GET_JUMP_OFFSET(regs
.pc
);
6430 BEGIN_CASE(JSOP_GOSUBX
)
6432 i
= PTRDIFF(regs
.pc
, script
->main
, jsbytecode
) + JSOP_GOSUBX_LENGTH
;
6433 len
= GET_JUMPX_OFFSET(regs
.pc
);
6434 PUSH(INT_TO_JSVAL(i
));
6437 BEGIN_CASE(JSOP_RETSUB
)
6438 /* Pop [exception or hole, retsub pc-index]. */
6441 JS_ASSERT(JSVAL_IS_BOOLEAN(lval
));
6442 if (JSVAL_TO_BOOLEAN(lval
)) {
6444 * Exception was pending during finally, throw it *before* we
6445 * adjust pc, because pc indexes into script->trynotes. This
6446 * turns out not to be necessary, but it seems clearer. And
6447 * it points out a FIXME: 350509, due to Igor Bukanov.
6449 cx
->throwing
= JS_TRUE
;
6450 cx
->exception
= rval
;
6453 JS_ASSERT(JSVAL_IS_INT(rval
));
6454 len
= JSVAL_TO_INT(rval
);
6455 regs
.pc
= script
->main
;
6458 BEGIN_CASE(JSOP_EXCEPTION
)
6459 JS_ASSERT(cx
->throwing
);
6460 PUSH(cx
->exception
);
6461 cx
->throwing
= JS_FALSE
;
6462 END_CASE(JSOP_EXCEPTION
)
6464 BEGIN_CASE(JSOP_THROWING
)
6465 JS_ASSERT(!cx
->throwing
);
6466 cx
->throwing
= JS_TRUE
;
6467 cx
->exception
= POP_OPND();
6468 END_CASE(JSOP_THROWING
)
6470 BEGIN_CASE(JSOP_THROW
)
6471 JS_ASSERT(!cx
->throwing
);
6472 cx
->throwing
= JS_TRUE
;
6473 cx
->exception
= POP_OPND();
6474 /* let the code at error try to catch the exception. */
6477 BEGIN_CASE(JSOP_SETLOCALPOP
)
6479 * The stack must have a block with at least one local slot below
6480 * the exception object.
6482 JS_ASSERT((size_t) (regs
.sp
- StackBase(fp
)) >= 2);
6483 slot
= GET_UINT16(regs
.pc
);
6484 JS_ASSERT(slot
+ 1 < script
->nslots
);
6485 fp
->slots
[slot
] = POP_OPND();
6486 END_CASE(JSOP_SETLOCALPOP
)
6488 BEGIN_CASE(JSOP_INSTANCEOF
)
6489 rval
= FETCH_OPND(-1);
6490 if (JSVAL_IS_PRIMITIVE(rval
) ||
6491 !(obj
= JSVAL_TO_OBJECT(rval
))->map
->ops
->hasInstance
) {
6492 js_ReportValueError(cx
, JSMSG_BAD_INSTANCEOF_RHS
,
6496 lval
= FETCH_OPND(-2);
6498 if (!obj
->map
->ops
->hasInstance(cx
, obj
, lval
, &cond
))
6501 STORE_OPND(-1, BOOLEAN_TO_JSVAL(cond
));
6502 END_CASE(JSOP_INSTANCEOF
)
6504 #if JS_HAS_DEBUGGER_KEYWORD
6505 BEGIN_CASE(JSOP_DEBUGGER
)
6507 JSTrapHandler handler
= cx
->debugHooks
->debuggerHandler
;
6509 switch (handler(cx
, script
, regs
.pc
, &rval
,
6510 cx
->debugHooks
->debuggerHandlerData
)) {
6513 case JSTRAP_CONTINUE
:
6520 cx
->throwing
= JS_TRUE
;
6521 cx
->exception
= rval
;
6525 LOAD_INTERRUPT_HANDLER(cx
);
6528 END_CASE(JSOP_DEBUGGER
)
6529 #endif /* JS_HAS_DEBUGGER_KEYWORD */
6531 #if JS_HAS_XML_SUPPORT
6532 BEGIN_CASE(JSOP_DEFXMLNS
)
6534 if (!js_SetDefaultXMLNamespace(cx
, rval
))
6536 END_CASE(JSOP_DEFXMLNS
)
6538 BEGIN_CASE(JSOP_ANYNAME
)
6539 if (!js_GetAnyName(cx
, &rval
))
6542 END_CASE(JSOP_ANYNAME
)
6544 BEGIN_CASE(JSOP_QNAMEPART
)
6546 PUSH_OPND(ATOM_KEY(atom
));
6547 END_CASE(JSOP_QNAMEPART
)
6549 BEGIN_CASE(JSOP_QNAMECONST
)
6551 rval
= ATOM_KEY(atom
);
6552 lval
= FETCH_OPND(-1);
6553 obj
= js_ConstructXMLQNameObject(cx
, lval
, rval
);
6556 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
6557 END_CASE(JSOP_QNAMECONST
)
6559 BEGIN_CASE(JSOP_QNAME
)
6560 rval
= FETCH_OPND(-1);
6561 lval
= FETCH_OPND(-2);
6562 obj
= js_ConstructXMLQNameObject(cx
, lval
, rval
);
6566 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
6567 END_CASE(JSOP_QNAME
)
6569 BEGIN_CASE(JSOP_TOATTRNAME
)
6570 rval
= FETCH_OPND(-1);
6571 if (!js_ToAttributeName(cx
, &rval
))
6573 STORE_OPND(-1, rval
);
6574 END_CASE(JSOP_TOATTRNAME
)
6576 BEGIN_CASE(JSOP_TOATTRVAL
)
6577 rval
= FETCH_OPND(-1);
6578 JS_ASSERT(JSVAL_IS_STRING(rval
));
6579 str
= js_EscapeAttributeValue(cx
, JSVAL_TO_STRING(rval
), JS_FALSE
);
6582 STORE_OPND(-1, STRING_TO_JSVAL(str
));
6583 END_CASE(JSOP_TOATTRVAL
)
6585 BEGIN_CASE(JSOP_ADDATTRNAME
)
6586 BEGIN_CASE(JSOP_ADDATTRVAL
)
6587 rval
= FETCH_OPND(-1);
6588 lval
= FETCH_OPND(-2);
6589 str
= JSVAL_TO_STRING(lval
);
6590 str2
= JSVAL_TO_STRING(rval
);
6591 str
= js_AddAttributePart(cx
, op
== JSOP_ADDATTRNAME
, str
, str2
);
6595 STORE_OPND(-1, STRING_TO_JSVAL(str
));
6596 END_CASE(JSOP_ADDATTRNAME
)
6598 BEGIN_CASE(JSOP_BINDXMLNAME
)
6599 lval
= FETCH_OPND(-1);
6600 if (!js_FindXMLProperty(cx
, lval
, &obj
, &id
))
6602 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
6603 PUSH_OPND(ID_TO_VALUE(id
));
6604 END_CASE(JSOP_BINDXMLNAME
)
6606 BEGIN_CASE(JSOP_SETXMLNAME
)
6607 obj
= JSVAL_TO_OBJECT(FETCH_OPND(-3));
6608 rval
= FETCH_OPND(-1);
6609 FETCH_ELEMENT_ID(obj
, -2, id
);
6610 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
6612 rval
= FETCH_OPND(-1);
6614 STORE_OPND(-1, rval
);
6615 END_CASE(JSOP_SETXMLNAME
)
6617 BEGIN_CASE(JSOP_CALLXMLNAME
)
6618 BEGIN_CASE(JSOP_XMLNAME
)
6619 lval
= FETCH_OPND(-1);
6620 if (!js_FindXMLProperty(cx
, lval
, &obj
, &id
))
6622 if (!OBJ_GET_PROPERTY(cx
, obj
, id
, &rval
))
6624 STORE_OPND(-1, rval
);
6625 if (op
== JSOP_CALLXMLNAME
)
6626 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
6627 END_CASE(JSOP_XMLNAME
)
6629 BEGIN_CASE(JSOP_DESCENDANTS
)
6630 BEGIN_CASE(JSOP_DELDESC
)
6631 FETCH_OBJECT(cx
, -2, lval
, obj
);
6632 rval
= FETCH_OPND(-1);
6633 if (!js_GetXMLDescendants(cx
, obj
, rval
, &rval
))
6636 if (op
== JSOP_DELDESC
) {
6637 regs
.sp
[-1] = rval
; /* set local root */
6638 if (!js_DeleteXMLListElements(cx
, JSVAL_TO_OBJECT(rval
)))
6640 rval
= JSVAL_TRUE
; /* always succeed */
6644 STORE_OPND(-1, rval
);
6645 END_CASE(JSOP_DESCENDANTS
)
6647 BEGIN_CASE(JSOP_FILTER
)
6649 * We push the hole value before jumping to [enditer] so we can
6650 * detect the first iteration and direct js_StepXMLListFilter to
6651 * initialize filter's state.
6653 PUSH_OPND(JSVAL_HOLE
);
6654 len
= GET_JUMP_OFFSET(regs
.pc
);
6658 BEGIN_CASE(JSOP_ENDFILTER
)
6659 cond
= (regs
.sp
[-1] != JSVAL_HOLE
);
6661 /* Exit the "with" block left from the previous iteration. */
6664 if (!js_StepXMLListFilter(cx
, cond
))
6666 if (regs
.sp
[-1] != JSVAL_NULL
) {
6668 * Decrease sp after EnterWith returns as we use sp[-1] there
6669 * to root temporaries.
6671 JS_ASSERT(VALUE_IS_XML(cx
, regs
.sp
[-1]));
6672 if (!js_EnterWith(cx
, -2))
6675 len
= GET_JUMP_OFFSET(regs
.pc
);
6680 END_CASE(JSOP_ENDFILTER
);
6682 BEGIN_CASE(JSOP_TOXML
)
6683 rval
= FETCH_OPND(-1);
6684 obj
= js_ValueToXMLObject(cx
, rval
);
6687 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
6688 END_CASE(JSOP_TOXML
)
6690 BEGIN_CASE(JSOP_TOXMLLIST
)
6691 rval
= FETCH_OPND(-1);
6692 obj
= js_ValueToXMLListObject(cx
, rval
);
6695 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
6696 END_CASE(JSOP_TOXMLLIST
)
6698 BEGIN_CASE(JSOP_XMLTAGEXPR
)
6699 rval
= FETCH_OPND(-1);
6700 str
= js_ValueToString(cx
, rval
);
6703 STORE_OPND(-1, STRING_TO_JSVAL(str
));
6704 END_CASE(JSOP_XMLTAGEXPR
)
6706 BEGIN_CASE(JSOP_XMLELTEXPR
)
6707 rval
= FETCH_OPND(-1);
6708 if (VALUE_IS_XML(cx
, rval
)) {
6709 str
= js_ValueToXMLString(cx
, rval
);
6711 str
= js_ValueToString(cx
, rval
);
6713 str
= js_EscapeElementValue(cx
, str
);
6717 STORE_OPND(-1, STRING_TO_JSVAL(str
));
6718 END_CASE(JSOP_XMLELTEXPR
)
6720 BEGIN_CASE(JSOP_XMLOBJECT
)
6722 obj
= js_CloneXMLObject(cx
, obj
);
6725 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
6726 END_CASE(JSOP_XMLOBJECT
)
6728 BEGIN_CASE(JSOP_XMLCDATA
)
6730 str
= ATOM_TO_STRING(atom
);
6731 obj
= js_NewXMLSpecialObject(cx
, JSXML_CLASS_TEXT
, NULL
, str
);
6734 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
6735 END_CASE(JSOP_XMLCDATA
)
6737 BEGIN_CASE(JSOP_XMLCOMMENT
)
6739 str
= ATOM_TO_STRING(atom
);
6740 obj
= js_NewXMLSpecialObject(cx
, JSXML_CLASS_COMMENT
, NULL
, str
);
6743 PUSH_OPND(OBJECT_TO_JSVAL(obj
));
6744 END_CASE(JSOP_XMLCOMMENT
)
6746 BEGIN_CASE(JSOP_XMLPI
)
6748 str
= ATOM_TO_STRING(atom
);
6749 rval
= FETCH_OPND(-1);
6750 str2
= JSVAL_TO_STRING(rval
);
6751 obj
= js_NewXMLSpecialObject(cx
,
6752 JSXML_CLASS_PROCESSING_INSTRUCTION
,
6756 STORE_OPND(-1, OBJECT_TO_JSVAL(obj
));
6757 END_CASE(JSOP_XMLPI
)
6759 BEGIN_CASE(JSOP_GETFUNNS
)
6760 if (!js_GetFunctionNamespace(cx
, &rval
))
6763 END_CASE(JSOP_GETFUNNS
)
6764 #endif /* JS_HAS_XML_SUPPORT */
6766 BEGIN_CASE(JSOP_ENTERBLOCK
)
6768 JS_ASSERT(!OBJ_IS_CLONED_BLOCK(obj
));
6769 JS_ASSERT(StackBase(fp
) + OBJ_BLOCK_DEPTH(cx
, obj
) == regs
.sp
);
6770 vp
= regs
.sp
+ OBJ_BLOCK_COUNT(cx
, obj
);
6771 JS_ASSERT(regs
.sp
< vp
);
6772 JS_ASSERT(vp
<= fp
->slots
+ script
->nslots
);
6773 while (regs
.sp
< vp
) {
6774 STORE_OPND(0, JSVAL_VOID
);
6779 * If this frame had to reflect the compile-time block chain into
6780 * the runtime scope chain, we can't optimize block scopes out of
6781 * runtime any longer, because an outer block that parents obj has
6782 * been cloned onto the scope chain. To avoid re-cloning such a
6783 * parent and accumulating redundant clones via js_GetScopeChain,
6784 * we must clone each block eagerly on entry, and push it on the
6785 * scope chain, until this frame pops.
6787 if (fp
->flags
& JSFRAME_POP_BLOCKS
) {
6788 JS_ASSERT(!fp
->blockChain
);
6789 obj
= js_CloneBlockObject(cx
, obj
, fp
->scopeChain
, fp
);
6792 fp
->scopeChain
= obj
;
6794 JS_ASSERT(!fp
->blockChain
||
6795 OBJ_GET_PARENT(cx
, obj
) == fp
->blockChain
);
6796 fp
->blockChain
= obj
;
6798 END_CASE(JSOP_ENTERBLOCK
)
6800 BEGIN_CASE(JSOP_LEAVEBLOCKEXPR
)
6801 BEGIN_CASE(JSOP_LEAVEBLOCK
)
6804 uintN blockDepth
= OBJ_BLOCK_DEPTH(cx
,
6809 JS_ASSERT(blockDepth
<= StackDepth(script
));
6811 if (fp
->blockChain
) {
6812 JS_ASSERT(OBJ_GET_CLASS(cx
, fp
->blockChain
) == &js_BlockClass
);
6813 fp
->blockChain
= OBJ_GET_PARENT(cx
, fp
->blockChain
);
6816 * This block was cloned into fp->scopeChain, so clear its
6817 * private data and sync its locals to their property slots.
6819 if (!js_PutBlockObject(cx
, JS_TRUE
))
6824 * We will move the result of the expression to the new topmost
6827 if (op
== JSOP_LEAVEBLOCKEXPR
)
6828 rval
= FETCH_OPND(-1);
6829 regs
.sp
-= GET_UINT16(regs
.pc
);
6830 if (op
== JSOP_LEAVEBLOCKEXPR
) {
6831 JS_ASSERT(StackBase(fp
) + blockDepth
== regs
.sp
- 1);
6832 STORE_OPND(-1, rval
);
6834 JS_ASSERT(StackBase(fp
) + blockDepth
== regs
.sp
);
6837 END_CASE(JSOP_LEAVEBLOCK
)
6839 #if JS_HAS_GENERATORS
6840 BEGIN_CASE(JSOP_GENERATOR
)
6841 ASSERT_NOT_THROWING(cx
);
6842 regs
.pc
+= JSOP_GENERATOR_LENGTH
;
6843 obj
= js_NewGenerator(cx
, fp
);
6846 JS_ASSERT(!fp
->callobj
&& !fp
->argsobj
);
6847 fp
->rval
= OBJECT_TO_JSVAL(obj
);
6849 if (inlineCallCount
!= 0)
6853 BEGIN_CASE(JSOP_YIELD
)
6854 ASSERT_NOT_THROWING(cx
);
6855 if (FRAME_TO_GENERATOR(fp
)->state
== JSGEN_CLOSING
) {
6856 js_ReportValueError(cx
, JSMSG_BAD_GENERATOR_YIELD
,
6857 JSDVG_SEARCH_STACK
, fp
->argv
[-2], NULL
);
6860 fp
->rval
= FETCH_OPND(-1);
6861 fp
->flags
|= JSFRAME_YIELDING
;
6862 regs
.pc
+= JSOP_YIELD_LENGTH
;
6866 BEGIN_CASE(JSOP_ARRAYPUSH
)
6867 slot
= GET_UINT16(regs
.pc
);
6868 JS_ASSERT(script
->nfixed
<= slot
);
6869 JS_ASSERT(slot
< script
->nslots
);
6870 lval
= fp
->slots
[slot
];
6871 obj
= JSVAL_TO_OBJECT(lval
);
6872 JS_ASSERT(OBJ_GET_CLASS(cx
, obj
) == &js_ArrayClass
);
6873 rval
= FETCH_OPND(-1);
6876 * We know that the array is created with only a 'length' private
6877 * data slot at JSSLOT_ARRAY_LENGTH, and that previous iterations
6878 * of the comprehension have added the only properties directly in
6881 i
= obj
->fslots
[JSSLOT_ARRAY_LENGTH
];
6882 if (i
== ARRAY_INIT_LIMIT
) {
6883 JS_ReportErrorNumberUC(cx
, js_GetErrorMessage
, NULL
,
6884 JSMSG_ARRAY_INIT_TOO_BIG
);
6887 id
= INT_TO_JSID(i
);
6888 if (!OBJ_SET_PROPERTY(cx
, obj
, id
, &rval
))
6891 END_CASE(JSOP_ARRAYPUSH
)
6892 #endif /* JS_HAS_GENERATORS */
6894 #if JS_THREADED_INTERP
6896 L_JSOP_BACKPATCH_POP
:
6898 # if !JS_HAS_GENERATORS
6904 # if !JS_HAS_DESTRUCTURING
6905 L_JSOP_ENUMCONSTELEM
:
6908 # if !JS_HAS_XML_SUPPORT
6910 L_JSOP_STARTXMLEXPR
:
6952 #else /* !JS_THREADED_INTERP */
6957 JS_snprintf(numBuf
, sizeof numBuf
, "%d", op
);
6958 JS_ReportErrorNumber(cx
, js_GetErrorMessage
, NULL
,
6959 JSMSG_BAD_BYTECODE
, numBuf
);
6965 #if JS_THREADED_INTERP
6966 # define OPDEF(x,val,name,token,length,nuses,ndefs,prec,format) \
6967 R_##x: RECORD(x); goto L_##x;
6969 # define OPDEF(x,val,name,token,length,nuses,ndefs,prec,format) \
6970 case 256 + x: RECORD(x); op = x; switchOp = x; goto do_switch;
6972 #include "jsopcode.tbl"
6975 #endif /* JS_TRACER */
6977 #if !JS_THREADED_INTERP
6981 #endif /* !JS_THREADED_INTERP */
6984 if (fp
->imacpc
&& cx
->throwing
) {
6985 // To keep things simple, we hard-code imacro exception handlers here.
6986 if (*fp
->imacpc
== JSOP_NEXTITER
) {
6987 JS_ASSERT(*regs
.pc
== JSOP_CALL
);
6988 if (js_ValueIsStopIteration(cx
->exception
)) {
6989 cx
->throwing
= JS_FALSE
;
6990 cx
->exception
= JSVAL_VOID
;
6991 regs
.sp
[-1] = JSVAL_HOLE
;
6997 // Handle other exceptions as if they came from the imacro-calling pc.
6998 regs
.pc
= fp
->imacpc
;
7000 atoms
= script
->atomMap
.vector
;
7003 JS_ASSERT((size_t)(regs
.pc
- script
->code
) < script
->length
);
7004 if (!cx
->throwing
) {
7005 /* This is an error, not a catchable exception, quit the frame ASAP. */
7008 JSTrapHandler handler
;
7009 JSTryNote
*tn
, *tnlimit
;
7012 /* Call debugger throw hook if set. */
7013 handler
= cx
->debugHooks
->throwHook
;
7015 switch (handler(cx
, script
, regs
.pc
, &rval
,
7016 cx
->debugHooks
->throwHookData
)) {
7018 cx
->throwing
= JS_FALSE
;
7021 cx
->throwing
= JS_FALSE
;
7026 cx
->exception
= rval
;
7027 case JSTRAP_CONTINUE
:
7030 LOAD_INTERRUPT_HANDLER(cx
);
7034 * Look for a try block in script that can catch this exception.
7036 if (script
->trynotesOffset
== 0)
7039 offset
= (uint32
)(regs
.pc
- script
->main
);
7040 tn
= JS_SCRIPT_TRYNOTES(script
)->vector
;
7041 tnlimit
= tn
+ JS_SCRIPT_TRYNOTES(script
)->length
;
7043 if (offset
- tn
->start
>= tn
->length
)
7047 * We have a note that covers the exception pc but we must check
7048 * whether the interpreter has already executed the corresponding
7049 * handler. This is possible when the executed bytecode
7050 * implements break or return from inside a for-in loop.
7052 * In this case the emitter generates additional [enditer] and
7053 * [gosub] opcodes to close all outstanding iterators and execute
7054 * the finally blocks. If such an [enditer] throws an exception,
7055 * its pc can still be inside several nested for-in loops and
7056 * try-finally statements even if we have already closed the
7057 * corresponding iterators and invoked the finally blocks.
7059 * To address this, we make [enditer] always decrease the stack
7060 * even when its implementation throws an exception. Thus already
7061 * executed [enditer] and [gosub] opcodes will have try notes
7062 * with the stack depth exceeding the current one and this
7063 * condition is what we use to filter them out.
7065 if (tn
->stackDepth
> regs
.sp
- StackBase(fp
))
7069 * Set pc to the first bytecode after the the try note to point
7070 * to the beginning of catch or finally or to [enditer] closing
7073 regs
.pc
= (script
)->main
+ tn
->start
+ tn
->length
;
7075 ok
= js_UnwindScope(cx
, fp
, tn
->stackDepth
, JS_TRUE
);
7076 JS_ASSERT(fp
->regs
->sp
== StackBase(fp
) + tn
->stackDepth
);
7079 * Restart the handler search with updated pc and stack depth
7080 * to properly notify the debugger.
7087 JS_ASSERT(*regs
.pc
== JSOP_ENTERBLOCK
);
7089 #if JS_HAS_GENERATORS
7090 /* Catch cannot intercept the closing of a generator. */
7091 if (JS_UNLIKELY(cx
->exception
== JSVAL_ARETURN
))
7096 * Don't clear cx->throwing to save cx->exception from GC
7097 * until it is pushed to the stack via [exception] in the
7105 * Push (true, exception) pair for finally to indicate that
7106 * [retsub] should rethrow the exception.
7109 PUSH(cx
->exception
);
7110 cx
->throwing
= JS_FALSE
;
7116 * This is similar to JSOP_ENDITER in the interpreter loop,
7117 * except the code now uses the stack slot normally used by
7118 * JSOP_NEXTITER, namely regs.sp[-1] before the regs.sp -= 2
7119 * adjustment and regs.sp[1] after, to save and restore the
7120 * pending exception.
7122 JS_ASSERT(*regs
.pc
== JSOP_ENDITER
);
7123 regs
.sp
[-1] = cx
->exception
;
7124 cx
->throwing
= JS_FALSE
;
7125 ok
= js_CloseIterator(cx
, regs
.sp
[-2]);
7129 cx
->throwing
= JS_TRUE
;
7130 cx
->exception
= regs
.sp
[1];
7132 } while (++tn
!= tnlimit
);
7136 * Propagate the exception or error to the caller unless the exception
7137 * is an asynchronous return from a generator.
7140 #if JS_HAS_GENERATORS
7141 if (JS_UNLIKELY(cx
->throwing
&& cx
->exception
== JSVAL_ARETURN
)) {
7142 cx
->throwing
= JS_FALSE
;
7144 fp
->rval
= JSVAL_VOID
;
7151 * Unwind the scope making sure that ok stays false even when UnwindScope
7154 * When a trap handler returns JSTRAP_RETURN, we jump here with ok set to
7155 * true bypassing any finally blocks.
7157 ok
&= js_UnwindScope(cx
, fp
, 0, ok
|| cx
->throwing
);
7158 JS_ASSERT(regs
.sp
== StackBase(fp
));
7160 if (inlineCallCount
)
7165 * At this point we are inevitably leaving an interpreted function or a
7166 * top-level script, and returning to one of:
7167 * (a) an "out of line" call made through js_Invoke;
7168 * (b) a js_Execute activation;
7169 * (c) a generator (SendToGenerator, jsiter.c).
7171 * We must not be in an inline frame. The check above ensures that for the
7172 * error case and for a normal return, the code jumps directly to parent's
7175 JS_ASSERT(inlineCallCount
== 0);
7176 JS_ASSERT(fp
->regs
== ®s
);
7178 if (TRACE_RECORDER(cx
))
7179 js_AbortRecording(cx
, "recording out of js_Interpret");
7181 #if JS_HAS_GENERATORS
7182 if (JS_UNLIKELY(fp
->flags
& JSFRAME_YIELDING
)) {
7185 gen
= FRAME_TO_GENERATOR(fp
);
7186 gen
->savedRegs
= regs
;
7187 gen
->frame
.regs
= &gen
->savedRegs
;
7188 JS_PROPERTY_CACHE(cx
).disabled
-= js_CountWithBlocks(cx
, fp
);
7189 JS_ASSERT(JS_PROPERTY_CACHE(cx
).disabled
>= 0);
7191 #endif /* JS_HAS_GENERATORS */
7193 JS_ASSERT(!fp
->blockChain
);
7194 JS_ASSERT(!js_IsActiveWithOrBlock(cx
, fp
->scopeChain
, 0));
7198 /* Undo the remaining effects committed on entry to js_Interpret. */
7199 if (script
->staticDepth
< JS_DISPLAY_SIZE
)
7200 cx
->display
[script
->staticDepth
] = fp
->displaySave
;
7201 JS_ASSERT(JS_PROPERTY_CACHE(cx
).disabled
== fp
->pcDisabledSave
);
7202 if (cx
->version
== currentVersion
&& currentVersion
!= originalVersion
)
7203 js_SetVersion(cx
, originalVersion
);
7208 JS_TRACE_MONITOR(cx
).onTrace
= JS_TRUE
;
7209 SET_TRACE_RECORDER(cx
, tr
);
7210 if (!tr
->wasDeepAborted()) {
7211 tr
->popAbortStack();
7220 const char *printable
;
7222 printable
= js_AtomToPrintableString(cx
, atom
);
7224 js_ReportIsNotDefined(cx
, printable
);
7229 #endif /* !defined jsinvoke_cpp___ */