2011-02-15 04:57:54 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2010-08-13 14:22:18 -07:00
|
|
|
* vim: set ts=4 sw=4 et tw=78:
|
2010-03-28 13:34:16 -07:00
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is SpiderMonkey code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Jeff Walden <jwalden+code@mit.edu> (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef jscntxtinlines_h___
|
|
|
|
#define jscntxtinlines_h___
|
|
|
|
|
|
|
|
#include "jscntxt.h"
|
2010-12-22 12:02:25 -08:00
|
|
|
#include "jscompartment.h"
|
2010-03-03 17:52:26 -08:00
|
|
|
#include "jsparse.h"
|
2010-06-16 14:13:28 -07:00
|
|
|
#include "jsstaticcheck.h"
|
2010-03-28 13:34:16 -07:00
|
|
|
#include "jsxml.h"
|
2010-09-13 15:53:50 -07:00
|
|
|
#include "jsregexp.h"
|
2010-09-27 13:49:09 -07:00
|
|
|
#include "jsgc.h"
|
2010-09-13 15:53:50 -07:00
|
|
|
|
2010-10-27 16:18:16 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
static inline JSObject *
|
|
|
|
GetGlobalForScopeChain(JSContext *cx)
|
2010-09-13 15:53:50 -07:00
|
|
|
{
|
2010-10-27 16:18:16 -07:00
|
|
|
/*
|
|
|
|
* This is essentially GetScopeChain(cx)->getGlobal(), but without
|
|
|
|
* falling off trace.
|
|
|
|
*
|
|
|
|
* This use of cx->fp, possibly on trace, is deliberate:
|
|
|
|
* cx->fp->scopeChain->getGlobal() returns the same object whether we're on
|
|
|
|
* trace or not, since we do not trace calls across global objects.
|
|
|
|
*/
|
|
|
|
VOUCH_DOES_NOT_REQUIRE_STACK();
|
|
|
|
|
|
|
|
if (cx->hasfp())
|
|
|
|
return cx->fp()->scopeChain().getGlobal();
|
|
|
|
|
|
|
|
JSObject *scope = cx->globalObject;
|
|
|
|
if (!scope) {
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INACTIVE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
OBJ_TO_INNER_OBJECT(cx, scope);
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
2010-09-13 15:53:50 -07:00
|
|
|
}
|
2010-03-28 13:34:16 -07:00
|
|
|
|
2010-10-29 15:37:13 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
inline js::mjit::JaegerCompartment *JSContext::jaegerCompartment()
|
|
|
|
{
|
|
|
|
return compartment->jaegerCompartment;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-03 18:10:13 -08:00
|
|
|
inline bool
|
|
|
|
JSContext::ensureGeneratorStackSpace()
|
|
|
|
{
|
|
|
|
bool ok = genStack.reserve(genStack.length() + 1);
|
|
|
|
if (!ok)
|
|
|
|
js_ReportOutOfMemory(this);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2010-09-29 06:27:34 -07:00
|
|
|
JSStackFrame *
|
|
|
|
JSContext::computeNextFrame(JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
JSStackFrame *next = NULL;
|
|
|
|
for (js::StackSegment *ss = currentSegment; ; ss = ss->getPreviousInContext()) {
|
|
|
|
JSStackFrame *end = ss->getInitialFrame()->prev();
|
|
|
|
for (JSStackFrame *f = ss->getCurrentFrame(); f != end; next = f, f = f->prev()) {
|
|
|
|
if (f == fp)
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
if (end != ss->getPreviousInContext()->getCurrentFrame())
|
|
|
|
next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-27 16:18:16 -07:00
|
|
|
inline js::RegExpStatics *
|
|
|
|
JSContext::regExpStatics()
|
|
|
|
{
|
|
|
|
return js::RegExpStatics::extractFrom(js::GetGlobalForScopeChain(this));
|
|
|
|
}
|
|
|
|
|
2010-03-28 13:34:16 -07:00
|
|
|
namespace js {
|
|
|
|
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSFrameRegs *
|
|
|
|
StackSegment::getCurrentRegs() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(inContext());
|
|
|
|
return isActive() ? cx->regs : getSuspendedRegs();
|
2010-03-03 17:52:26 -08:00
|
|
|
}
|
|
|
|
|
2010-08-22 16:00:20 -07:00
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSStackFrame *
|
|
|
|
StackSegment::getCurrentFrame() const
|
|
|
|
{
|
|
|
|
return getCurrentRegs()->fp;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_REQUIRES_STACK inline Value *
|
2010-03-03 17:52:26 -08:00
|
|
|
StackSpace::firstUnused() const
|
|
|
|
{
|
2010-07-29 14:43:11 -07:00
|
|
|
StackSegment *seg = currentSegment;
|
2010-07-30 10:40:58 -07:00
|
|
|
if (!seg) {
|
|
|
|
JS_ASSERT(invokeArgEnd == NULL);
|
2010-03-03 17:52:26 -08:00
|
|
|
return base;
|
2010-07-30 10:40:58 -07:00
|
|
|
}
|
2010-08-10 13:29:17 -07:00
|
|
|
if (seg->inContext()) {
|
2010-07-30 10:40:58 -07:00
|
|
|
Value *sp = seg->getCurrentRegs()->sp;
|
|
|
|
if (invokeArgEnd > sp) {
|
|
|
|
JS_ASSERT(invokeSegment == currentSegment);
|
2010-08-22 16:00:20 -07:00
|
|
|
JS_ASSERT_IF(seg->maybeContext()->hasfp(),
|
|
|
|
invokeFrame == seg->maybeContext()->fp());
|
2010-07-30 10:40:58 -07:00
|
|
|
return invokeArgEnd;
|
|
|
|
}
|
|
|
|
return sp;
|
2010-03-03 18:10:13 -08:00
|
|
|
}
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_ASSERT(invokeArgEnd);
|
|
|
|
JS_ASSERT(invokeSegment == currentSegment);
|
|
|
|
return invokeArgEnd;
|
2010-03-03 17:52:26 -08:00
|
|
|
}
|
|
|
|
|
2010-07-30 10:40:58 -07:00
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
/* Inline so we don't need the friend API. */
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
StackSpace::isCurrentAndActive(JSContext *cx) const
|
2010-03-03 17:52:26 -08:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_ASSERT_IF(cx->getCurrentSegment(),
|
|
|
|
cx->getCurrentSegment()->maybeContext() == cx);
|
2010-07-22 13:46:43 -07:00
|
|
|
cx->assertSegmentsInSync();
|
2010-03-03 17:52:26 -08:00
|
|
|
#endif
|
2010-07-30 10:40:58 -07:00
|
|
|
return currentSegment &&
|
|
|
|
currentSegment->isActive() &&
|
|
|
|
currentSegment == cx->getCurrentSegment();
|
2010-03-03 17:52:26 -08:00
|
|
|
}
|
|
|
|
|
2010-10-01 21:00:55 -07:00
|
|
|
STATIC_POSTCONDITION(!return || ubound(from) >= nvals)
|
2010-03-03 17:52:26 -08:00
|
|
|
JS_ALWAYS_INLINE bool
|
2010-07-14 23:19:36 -07:00
|
|
|
StackSpace::ensureSpace(JSContext *maybecx, Value *from, ptrdiff_t nvals) const
|
2010-03-03 17:52:26 -08:00
|
|
|
{
|
2010-10-21 11:33:22 -07:00
|
|
|
JS_ASSERT(from >= firstUnused());
|
2010-03-03 17:52:26 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
JS_ASSERT(from <= commitEnd);
|
2010-10-21 11:33:22 -07:00
|
|
|
if (commitEnd - from >= nvals)
|
2010-08-09 22:43:33 -07:00
|
|
|
goto success;
|
2010-03-03 17:52:26 -08:00
|
|
|
if (end - from < nvals) {
|
|
|
|
if (maybecx)
|
|
|
|
js_ReportOutOfScriptQuota(maybecx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!bumpCommit(from, nvals)) {
|
|
|
|
if (maybecx)
|
|
|
|
js_ReportOutOfScriptQuota(maybecx);
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-09 22:43:33 -07:00
|
|
|
goto success;
|
2010-03-03 17:52:26 -08:00
|
|
|
#else
|
2010-10-21 11:33:22 -07:00
|
|
|
if (end - from < nvals) {
|
2010-03-03 17:52:26 -08:00
|
|
|
if (maybecx)
|
|
|
|
js_ReportOutOfScriptQuota(maybecx);
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-09 22:43:33 -07:00
|
|
|
goto success;
|
|
|
|
#endif
|
|
|
|
success:
|
|
|
|
#ifdef DEBUG
|
|
|
|
memset(from, 0xde, nvals * sizeof(js::Value));
|
2010-03-03 17:52:26 -08:00
|
|
|
#endif
|
2010-08-09 22:43:33 -07:00
|
|
|
return true;
|
2010-03-03 17:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
StackSpace::ensureEnoughSpaceToEnterTrace()
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
return ensureSpace(NULL, firstUnused(), MAX_TRACE_SPACE_VALS);
|
|
|
|
#endif
|
|
|
|
return end - firstUnused() > MAX_TRACE_SPACE_VALS;
|
|
|
|
}
|
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
StackSpace::EnsureSpaceCheck::operator()(const StackSpace &stack, JSContext *cx,
|
|
|
|
Value *from, uintN nvals)
|
|
|
|
{
|
|
|
|
return stack.ensureSpace(cx, from, nvals);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
StackSpace::LimitCheck::operator()(const StackSpace &stack, JSContext *cx,
|
|
|
|
Value *from, uintN nvals)
|
|
|
|
{
|
|
|
|
JS_ASSERT(from == stack.firstUnused());
|
|
|
|
JS_ASSERT(from < *limit);
|
|
|
|
if (*limit - from >= ptrdiff_t(nvals))
|
|
|
|
return true;
|
|
|
|
if (stack.bumpCommitAndLimit(base, from, nvals, limit))
|
|
|
|
return true;
|
|
|
|
js_ReportOverRecursed(cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE bool
|
2010-08-09 22:43:33 -07:00
|
|
|
StackSpace::pushInvokeArgs(JSContext *cx, uintN argc, InvokeArgsGuard *ag)
|
2010-07-30 10:40:58 -07:00
|
|
|
{
|
|
|
|
if (JS_UNLIKELY(!isCurrentAndActive(cx)))
|
|
|
|
return pushSegmentForInvoke(cx, argc, ag);
|
|
|
|
|
|
|
|
Value *sp = cx->regs->sp;
|
|
|
|
Value *start = invokeArgEnd > sp ? invokeArgEnd : sp;
|
|
|
|
JS_ASSERT(start == firstUnused());
|
|
|
|
uintN nvals = 2 + argc;
|
|
|
|
if (!ensureSpace(cx, start, nvals))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Value *vp = start;
|
|
|
|
Value *vpend = vp + nvals;
|
2011-02-07 12:06:32 -08:00
|
|
|
/* Don't need to MakeRangeGCSafe: the VM stack is conservatively marked. */
|
2010-07-30 10:40:58 -07:00
|
|
|
|
|
|
|
/* Use invokeArgEnd to root [vp, vpend) until the frame is pushed. */
|
2010-08-09 22:43:33 -07:00
|
|
|
ag->prevInvokeArgEnd = invokeArgEnd;
|
2010-07-30 10:40:58 -07:00
|
|
|
invokeArgEnd = vpend;
|
|
|
|
#ifdef DEBUG
|
2010-08-09 22:43:33 -07:00
|
|
|
ag->prevInvokeSegment = invokeSegment;
|
2010-07-30 10:40:58 -07:00
|
|
|
invokeSegment = currentSegment;
|
2010-08-09 22:43:33 -07:00
|
|
|
ag->prevInvokeFrame = invokeFrame;
|
2010-08-22 16:00:20 -07:00
|
|
|
invokeFrame = cx->maybefp();
|
2010-07-30 10:40:58 -07:00
|
|
|
#endif
|
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
ag->cx = cx;
|
|
|
|
ag->argv_ = vp + 2;
|
|
|
|
ag->argc_ = argc;
|
2010-07-30 10:40:58 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
|
|
|
|
StackSpace::popInvokeArgs(const InvokeArgsGuard &ag)
|
|
|
|
{
|
|
|
|
if (JS_UNLIKELY(ag.seg != NULL)) {
|
|
|
|
popSegmentForInvoke(ag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ASSERT(isCurrentAndActive(ag.cx));
|
|
|
|
JS_ASSERT(invokeSegment == currentSegment);
|
2010-08-22 16:00:20 -07:00
|
|
|
JS_ASSERT(invokeFrame == ag.cx->maybefp());
|
2010-07-30 10:41:03 -07:00
|
|
|
JS_ASSERT(invokeArgEnd == ag.argv() + ag.argc());
|
2010-07-30 10:40:58 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
invokeSegment = ag.prevInvokeSegment;
|
|
|
|
invokeFrame = ag.prevInvokeFrame;
|
|
|
|
#endif
|
|
|
|
invokeArgEnd = ag.prevInvokeArgEnd;
|
2010-07-26 19:49:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
InvokeArgsGuard::~InvokeArgsGuard()
|
|
|
|
{
|
2010-07-30 10:40:58 -07:00
|
|
|
if (JS_UNLIKELY(!pushed()))
|
|
|
|
return;
|
|
|
|
cx->stack().popInvokeArgs(*this);
|
|
|
|
}
|
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
template <class Check>
|
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSStackFrame *
|
|
|
|
StackSpace::getCallFrame(JSContext *cx, Value *firstUnused, uintN nactual,
|
|
|
|
JSFunction *fun, JSScript *script, uint32 *flags,
|
|
|
|
Check check) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(fun->script() == script);
|
|
|
|
|
|
|
|
/* Include an extra sizeof(JSStackFrame) for the method-jit. */
|
|
|
|
uintN nvals = VALUES_PER_STACK_FRAME + script->nslots;
|
|
|
|
uintN nformal = fun->nargs;
|
|
|
|
|
|
|
|
/* Maintain layout invariant: &formalArgs[0] == ((Value *)fp) - nformal. */
|
|
|
|
|
|
|
|
if (nactual == nformal) {
|
|
|
|
if (JS_UNLIKELY(!check(*this, cx, firstUnused, nvals)))
|
|
|
|
return NULL;
|
|
|
|
return reinterpret_cast<JSStackFrame *>(firstUnused);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nactual < nformal) {
|
|
|
|
*flags |= JSFRAME_UNDERFLOW_ARGS;
|
|
|
|
uintN nmissing = nformal - nactual;
|
|
|
|
if (JS_UNLIKELY(!check(*this, cx, firstUnused, nmissing + nvals)))
|
|
|
|
return NULL;
|
|
|
|
SetValueRangeToUndefined(firstUnused, nmissing);
|
|
|
|
return reinterpret_cast<JSStackFrame *>(firstUnused + nmissing);
|
|
|
|
}
|
|
|
|
|
|
|
|
*flags |= JSFRAME_OVERFLOW_ARGS;
|
|
|
|
uintN ncopy = 2 + nformal;
|
|
|
|
if (JS_UNLIKELY(!check(*this, cx, firstUnused, ncopy + nvals)))
|
|
|
|
return NULL;
|
2011-02-07 15:55:20 -08:00
|
|
|
|
|
|
|
Value *dst = firstUnused;
|
|
|
|
Value *src = firstUnused - (2 + nactual);
|
|
|
|
PodCopy(dst, src, ncopy);
|
|
|
|
Debug_SetValueRangeToCrashOnTouch(src, ncopy);
|
2010-08-09 22:43:33 -07:00
|
|
|
return reinterpret_cast<JSStackFrame *>(firstUnused + ncopy);
|
|
|
|
}
|
|
|
|
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE bool
|
2010-07-30 10:41:03 -07:00
|
|
|
StackSpace::getInvokeFrame(JSContext *cx, const CallArgs &args,
|
2010-08-09 22:43:33 -07:00
|
|
|
JSFunction *fun, JSScript *script,
|
|
|
|
uint32 *flags, InvokeFrameGuard *fg) const
|
2010-07-30 10:40:58 -07:00
|
|
|
{
|
2010-07-30 10:41:03 -07:00
|
|
|
JS_ASSERT(firstUnused() == args.argv() + args.argc());
|
2010-07-30 10:40:58 -07:00
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
Value *firstUnused = args.argv() + args.argc();
|
|
|
|
fg->regs_.fp = getCallFrame(cx, firstUnused, args.argc(), fun, script, flags,
|
|
|
|
EnsureSpaceCheck());
|
|
|
|
fg->regs_.sp = fg->regs_.fp->slots() + script->nfixed;
|
|
|
|
fg->regs_.pc = script->code;
|
|
|
|
|
|
|
|
return fg->regs_.fp != NULL;
|
2010-07-30 10:40:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
|
2010-07-30 10:41:03 -07:00
|
|
|
StackSpace::pushInvokeFrame(JSContext *cx, const CallArgs &args,
|
2010-08-09 22:43:33 -07:00
|
|
|
InvokeFrameGuard *fg)
|
2010-07-30 10:40:58 -07:00
|
|
|
{
|
2010-07-30 10:41:03 -07:00
|
|
|
JS_ASSERT(firstUnused() == args.argv() + args.argc());
|
2010-07-30 10:40:58 -07:00
|
|
|
|
|
|
|
if (JS_UNLIKELY(!currentSegment->inContext())) {
|
2010-08-09 22:43:33 -07:00
|
|
|
cx->pushSegmentAndFrame(currentSegment, fg->regs_);
|
2010-07-30 10:40:58 -07:00
|
|
|
} else {
|
2010-08-09 22:43:33 -07:00
|
|
|
fg->prevRegs_ = cx->regs;
|
|
|
|
cx->setCurrentRegs(&fg->regs_);
|
2010-07-30 10:40:58 -07:00
|
|
|
}
|
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
fg->cx_ = cx;
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_ASSERT(isCurrentAndActive(cx));
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
|
|
|
|
StackSpace::popInvokeFrame(const InvokeFrameGuard &fg)
|
|
|
|
{
|
2010-08-09 22:43:33 -07:00
|
|
|
JSContext *cx = fg.cx_;
|
|
|
|
JSStackFrame *fp = fg.regs_.fp;
|
2010-07-30 10:40:58 -07:00
|
|
|
|
|
|
|
JS_ASSERT(isCurrentAndActive(cx));
|
|
|
|
if (JS_UNLIKELY(currentSegment->getInitialFrame() == fp)) {
|
|
|
|
cx->popSegmentAndFrame();
|
|
|
|
} else {
|
2010-08-09 22:43:33 -07:00
|
|
|
JS_ASSERT(&fg.regs_ == cx->regs);
|
|
|
|
JS_ASSERT(fp->prev_ == fg.prevRegs_->fp);
|
2010-09-29 06:27:34 -07:00
|
|
|
JS_ASSERT(fp->prevpc() == fg.prevRegs_->pc);
|
2010-08-09 22:43:33 -07:00
|
|
|
cx->setCurrentRegs(fg.prevRegs_);
|
2010-07-30 10:40:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-28 15:23:43 -07:00
|
|
|
JS_ALWAYS_INLINE void
|
|
|
|
InvokeFrameGuard::pop()
|
2010-07-30 10:40:58 -07:00
|
|
|
{
|
2010-09-28 15:23:43 -07:00
|
|
|
JS_ASSERT(pushed());
|
2010-08-09 22:43:33 -07:00
|
|
|
cx_->stack().popInvokeFrame(*this);
|
2010-09-28 15:23:43 -07:00
|
|
|
cx_ = NULL;
|
2010-07-26 19:49:27 -07:00
|
|
|
}
|
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSStackFrame *
|
2010-08-09 22:43:33 -07:00
|
|
|
StackSpace::getInlineFrame(JSContext *cx, Value *sp, uintN nactual,
|
|
|
|
JSFunction *fun, JSScript *script, uint32 *flags) const
|
2010-03-03 17:52:26 -08:00
|
|
|
{
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_ASSERT(isCurrentAndActive(cx));
|
2010-07-22 13:46:43 -07:00
|
|
|
JS_ASSERT(cx->hasActiveSegment());
|
2010-03-03 18:10:13 -08:00
|
|
|
JS_ASSERT(cx->regs->sp == sp);
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
return getCallFrame(cx, sp, nactual, fun, script, flags, EnsureSpaceCheck());
|
2010-08-13 14:22:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSStackFrame *
|
2010-08-09 22:43:33 -07:00
|
|
|
StackSpace::getInlineFrameWithinLimit(JSContext *cx, Value *sp, uintN nactual,
|
|
|
|
JSFunction *fun, JSScript *script, uint32 *flags,
|
|
|
|
JSStackFrame *base, Value **limit) const
|
2010-08-13 14:22:18 -07:00
|
|
|
{
|
2010-08-09 22:43:33 -07:00
|
|
|
JS_ASSERT(isCurrentAndActive(cx));
|
|
|
|
JS_ASSERT(cx->hasActiveSegment());
|
|
|
|
JS_ASSERT(cx->regs->sp == sp);
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
return getCallFrame(cx, sp, nactual, fun, script, flags, LimitCheck(base, limit));
|
2010-03-03 17:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
|
2010-08-09 22:43:33 -07:00
|
|
|
StackSpace::pushInlineFrame(JSContext *cx, JSScript *script, JSStackFrame *fp,
|
|
|
|
JSFrameRegs *regs)
|
2010-03-03 17:52:26 -08:00
|
|
|
{
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_ASSERT(isCurrentAndActive(cx));
|
2010-08-09 22:43:33 -07:00
|
|
|
JS_ASSERT(cx->regs == regs && script == fp->script());
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
regs->fp = fp;
|
|
|
|
regs->pc = script->code;
|
|
|
|
regs->sp = fp->slots() + script->nfixed;
|
2010-03-03 17:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
|
2010-08-09 22:43:33 -07:00
|
|
|
StackSpace::popInlineFrame(JSContext *cx, JSStackFrame *prev, Value *newsp)
|
2010-03-03 17:52:26 -08:00
|
|
|
{
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_ASSERT(isCurrentAndActive(cx));
|
2010-07-22 13:46:43 -07:00
|
|
|
JS_ASSERT(cx->hasActiveSegment());
|
2010-08-09 22:43:33 -07:00
|
|
|
JS_ASSERT(cx->regs->fp->prev_ == prev);
|
|
|
|
JS_ASSERT(!cx->regs->fp->hasImacropc());
|
|
|
|
JS_ASSERT(prev->base() <= newsp && newsp <= cx->regs->fp->formalArgsEnd());
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2010-03-03 18:10:13 -08:00
|
|
|
JSFrameRegs *regs = cx->regs;
|
2010-09-29 06:27:34 -07:00
|
|
|
regs->pc = prev->pc(cx, regs->fp);
|
2010-08-09 22:43:33 -07:00
|
|
|
regs->fp = prev;
|
|
|
|
regs->sp = newsp;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE Value *
|
|
|
|
StackSpace::getStackLimit(JSContext *cx)
|
|
|
|
{
|
|
|
|
Value *sp = cx->regs->sp;
|
|
|
|
JS_ASSERT(sp == firstUnused());
|
|
|
|
Value *limit = sp + STACK_QUOTA;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to reserve the whole STACK_QUOTA. If that fails, though, just
|
|
|
|
* reserve the minimum required space: enough for the nslots + an
|
|
|
|
* additional stack frame.
|
|
|
|
*/
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (JS_LIKELY(limit <= commitEnd))
|
|
|
|
return limit;
|
|
|
|
if (ensureSpace(NULL /* don't report error */, sp, STACK_QUOTA))
|
|
|
|
return limit;
|
|
|
|
uintN minimum = cx->fp()->numSlots() + VALUES_PER_STACK_FRAME;
|
|
|
|
return ensureSpace(cx, sp, minimum) ? sp + minimum : NULL;
|
|
|
|
#else
|
|
|
|
if (JS_LIKELY(limit <= end))
|
|
|
|
return limit;
|
|
|
|
uintN minimum = cx->fp()->numSlots() + VALUES_PER_STACK_FRAME;
|
|
|
|
return ensureSpace(cx, sp, minimum) ? sp + minimum : NULL;
|
2010-03-03 18:10:13 -08:00
|
|
|
#endif
|
2010-03-03 17:52:26 -08:00
|
|
|
}
|
|
|
|
|
2010-07-30 10:40:58 -07:00
|
|
|
JS_REQUIRES_STACK inline
|
|
|
|
FrameRegsIter::FrameRegsIter(JSContext *cx)
|
2010-09-29 06:27:34 -07:00
|
|
|
: cx(cx)
|
2010-07-30 10:40:58 -07:00
|
|
|
{
|
|
|
|
curseg = cx->getCurrentSegment();
|
2010-08-20 16:54:58 -07:00
|
|
|
if (JS_UNLIKELY(!curseg || !curseg->isActive())) {
|
2010-07-30 10:40:58 -07:00
|
|
|
initSlow();
|
2010-08-20 16:54:58 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-08-22 16:00:20 -07:00
|
|
|
JS_ASSERT(cx->regs->fp);
|
|
|
|
curfp = cx->regs->fp;
|
2010-07-30 10:40:58 -07:00
|
|
|
cursp = cx->regs->sp;
|
|
|
|
curpc = cx->regs->pc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline FrameRegsIter &
|
|
|
|
FrameRegsIter::operator++()
|
|
|
|
{
|
2010-08-09 22:43:33 -07:00
|
|
|
JSStackFrame *fp = curfp;
|
|
|
|
JSStackFrame *prev = curfp = curfp->prev();
|
|
|
|
if (!prev)
|
2010-07-30 10:40:58 -07:00
|
|
|
return *this;
|
|
|
|
|
2010-09-29 06:27:34 -07:00
|
|
|
curpc = curfp->pc(cx, fp);
|
2010-07-30 10:40:58 -07:00
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
if (JS_UNLIKELY(fp == curseg->getInitialFrame())) {
|
|
|
|
incSlow(fp, prev);
|
2010-07-30 10:40:58 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
cursp = fp->formalArgsEnd();
|
2010-07-30 10:40:58 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-19 11:58:00 -07:00
|
|
|
class AutoNamespaceArray : protected AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoNamespaceArray(JSContext *cx) : AutoGCRooter(cx, NAMESPACES) {
|
|
|
|
array.init();
|
2010-03-28 13:34:16 -07:00
|
|
|
}
|
|
|
|
|
2010-06-19 11:58:00 -07:00
|
|
|
~AutoNamespaceArray() {
|
|
|
|
array.finish(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 length() const { return array.length; }
|
2010-03-28 13:34:16 -07:00
|
|
|
|
|
|
|
public:
|
2010-06-19 11:58:00 -07:00
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
2010-03-28 13:34:16 -07:00
|
|
|
JSXMLArray array;
|
|
|
|
};
|
|
|
|
|
2011-02-15 04:57:54 -08:00
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
AutoResolving::AutoResolving(JSContext *cx, JSObject *obj, jsid id, Kind kind
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM_NO_INIT)
|
|
|
|
: object(obj),
|
|
|
|
id(id),
|
|
|
|
kind(kind),
|
|
|
|
lastp(&JS_THREAD_DATA(cx)->resolvingList),
|
|
|
|
prev(*lastp)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
*lastp = this;
|
|
|
|
}
|
|
|
|
|
2010-11-08 18:05:54 -08:00
|
|
|
#ifdef DEBUG
|
2010-06-16 14:13:28 -07:00
|
|
|
class CompartmentChecker
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
JSContext *context;
|
|
|
|
JSCompartment *compartment;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit CompartmentChecker(JSContext *cx) : context(cx), compartment(cx->compartment) {
|
2010-08-22 16:00:20 -07:00
|
|
|
check(cx->hasfp() ? JS_GetGlobalForScopeChain(cx) : cx->globalObject);
|
2010-06-16 14:13:28 -07:00
|
|
|
VOUCH_DOES_NOT_REQUIRE_STACK();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a breakpoint here (break js::CompartmentChecker::fail) to debug
|
|
|
|
* compartment mismatches.
|
|
|
|
*/
|
|
|
|
static void fail(JSCompartment *c1, JSCompartment *c2) {
|
|
|
|
printf("*** Compartment mismatch %p vs. %p\n", (void *) c1, (void *) c2);
|
2010-11-08 18:05:54 -08:00
|
|
|
JS_NOT_REACHED("compartment mismatched");
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
2011-01-05 18:44:30 -08:00
|
|
|
/* Note: should only be used when neither c1 nor c2 may be the default compartment. */
|
|
|
|
static void check(JSCompartment *c1, JSCompartment *c2) {
|
2011-01-13 14:42:36 -08:00
|
|
|
JS_ASSERT(c1 != c1->rt->atomsCompartment);
|
|
|
|
JS_ASSERT(c2 != c2->rt->atomsCompartment);
|
2011-01-05 18:44:30 -08:00
|
|
|
if (c1 != c2)
|
|
|
|
fail(c1, c2);
|
|
|
|
}
|
|
|
|
|
2010-06-16 14:13:28 -07:00
|
|
|
void check(JSCompartment *c) {
|
2011-01-13 14:42:36 -08:00
|
|
|
if (c && c != context->runtime->atomsCompartment) {
|
2010-06-16 14:13:28 -07:00
|
|
|
if (!compartment)
|
|
|
|
compartment = c;
|
|
|
|
else if (c != compartment)
|
|
|
|
fail(compartment, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void check(JSPrincipals *) { /* nothing for now */ }
|
|
|
|
|
|
|
|
void check(JSObject *obj) {
|
|
|
|
if (obj)
|
2011-01-24 16:30:08 -08:00
|
|
|
check(obj->compartment());
|
|
|
|
}
|
|
|
|
|
|
|
|
void check(JSString *str) {
|
|
|
|
if (!JSString::isStatic(str) && !str->isAtomized())
|
|
|
|
check(str->asCell()->compartment());
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
void check(const js::Value &v) {
|
|
|
|
if (v.isObject())
|
|
|
|
check(&v.toObject());
|
2011-01-24 16:30:08 -08:00
|
|
|
else if (v.isString())
|
|
|
|
check(v.toString());
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2010-06-16 14:13:28 -07:00
|
|
|
void check(jsval v) {
|
2010-07-14 23:19:36 -07:00
|
|
|
check(Valueify(v));
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void check(const ValueArray &arr) {
|
|
|
|
for (size_t i = 0; i < arr.length; i++)
|
|
|
|
check(arr.array[i]);
|
|
|
|
}
|
2010-07-14 23:19:36 -07:00
|
|
|
|
|
|
|
void check(const JSValueArray &arr) {
|
|
|
|
for (size_t i = 0; i < arr.length; i++)
|
|
|
|
check(arr.array[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check(jsid id) {
|
|
|
|
if (JSID_IS_OBJECT(id))
|
|
|
|
check(JSID_TO_OBJECT(id));
|
|
|
|
}
|
2010-06-16 14:13:28 -07:00
|
|
|
|
|
|
|
void check(JSIdArray *ida) {
|
|
|
|
if (ida) {
|
2010-07-14 23:19:36 -07:00
|
|
|
for (jsint i = 0; i < ida->length; i++) {
|
|
|
|
if (JSID_IS_OBJECT(ida->vector[i]))
|
|
|
|
check(ida->vector[i]);
|
|
|
|
}
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void check(JSScript *script) {
|
2010-11-16 15:30:56 -08:00
|
|
|
if (script) {
|
2010-09-29 23:17:29 -07:00
|
|
|
check(script->compartment);
|
|
|
|
if (script->u.object)
|
|
|
|
check(script->u.object);
|
|
|
|
}
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
2010-10-26 19:48:51 -07:00
|
|
|
void check(JSStackFrame *fp) {
|
|
|
|
check(&fp->scopeChain());
|
|
|
|
}
|
2010-06-16 14:13:28 -07:00
|
|
|
};
|
|
|
|
|
2010-11-08 18:05:54 -08:00
|
|
|
#endif
|
|
|
|
|
2010-06-16 14:13:28 -07:00
|
|
|
/*
|
|
|
|
* Don't perform these checks when called from a finalizer. The checking
|
|
|
|
* depends on other objects not having been swept yet.
|
|
|
|
*/
|
|
|
|
#define START_ASSERT_SAME_COMPARTMENT() \
|
|
|
|
if (cx->runtime->gcRunning) \
|
|
|
|
return; \
|
|
|
|
CompartmentChecker c(cx)
|
|
|
|
|
|
|
|
template <class T1> inline void
|
|
|
|
assertSameCompartment(JSContext *cx, T1 t1)
|
|
|
|
{
|
2010-11-08 18:05:54 -08:00
|
|
|
#ifdef DEBUG
|
2010-06-16 14:13:28 -07:00
|
|
|
START_ASSERT_SAME_COMPARTMENT();
|
|
|
|
c.check(t1);
|
2010-11-08 18:05:54 -08:00
|
|
|
#endif
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1, class T2> inline void
|
|
|
|
assertSameCompartment(JSContext *cx, T1 t1, T2 t2)
|
|
|
|
{
|
2010-11-08 18:05:54 -08:00
|
|
|
#ifdef DEBUG
|
2010-06-16 14:13:28 -07:00
|
|
|
START_ASSERT_SAME_COMPARTMENT();
|
|
|
|
c.check(t1);
|
|
|
|
c.check(t2);
|
2010-11-08 18:05:54 -08:00
|
|
|
#endif
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1, class T2, class T3> inline void
|
|
|
|
assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3)
|
|
|
|
{
|
2010-11-08 18:05:54 -08:00
|
|
|
#ifdef DEBUG
|
2010-06-16 14:13:28 -07:00
|
|
|
START_ASSERT_SAME_COMPARTMENT();
|
|
|
|
c.check(t1);
|
|
|
|
c.check(t2);
|
|
|
|
c.check(t3);
|
2010-11-08 18:05:54 -08:00
|
|
|
#endif
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1, class T2, class T3, class T4> inline void
|
|
|
|
assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3, T4 t4)
|
|
|
|
{
|
2010-11-08 18:05:54 -08:00
|
|
|
#ifdef DEBUG
|
2010-06-16 14:13:28 -07:00
|
|
|
START_ASSERT_SAME_COMPARTMENT();
|
|
|
|
c.check(t1);
|
|
|
|
c.check(t2);
|
|
|
|
c.check(t3);
|
|
|
|
c.check(t4);
|
2010-11-08 18:05:54 -08:00
|
|
|
#endif
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1, class T2, class T3, class T4, class T5> inline void
|
|
|
|
assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
|
|
|
|
{
|
2010-11-08 18:05:54 -08:00
|
|
|
#ifdef DEBUG
|
2010-06-16 14:13:28 -07:00
|
|
|
START_ASSERT_SAME_COMPARTMENT();
|
|
|
|
c.check(t1);
|
|
|
|
c.check(t2);
|
|
|
|
c.check(t3);
|
|
|
|
c.check(t4);
|
|
|
|
c.check(t5);
|
2010-11-08 18:05:54 -08:00
|
|
|
#endif
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef START_ASSERT_SAME_COMPARTMENT
|
|
|
|
|
2010-10-01 21:00:55 -07:00
|
|
|
STATIC_PRECONDITION_ASSUME(ubound(vp) >= argc + 2)
|
2010-08-16 12:35:04 -07:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
CallJSNative(JSContext *cx, js::Native native, uintN argc, js::Value *vp)
|
2010-06-16 14:13:28 -07:00
|
|
|
{
|
2010-08-16 12:35:04 -07:00
|
|
|
#ifdef DEBUG
|
2011-01-07 02:03:14 -08:00
|
|
|
JSBool alreadyThrowing = cx->isExceptionPending();
|
2010-08-16 12:35:04 -07:00
|
|
|
#endif
|
2010-06-16 14:13:28 -07:00
|
|
|
assertSameCompartment(cx, ValueArray(vp, argc + 2));
|
|
|
|
JSBool ok = native(cx, argc, vp);
|
2010-08-16 12:35:04 -07:00
|
|
|
if (ok) {
|
2010-06-16 14:13:28 -07:00
|
|
|
assertSameCompartment(cx, vp[0]);
|
2011-01-07 02:03:14 -08:00
|
|
|
JS_ASSERT_IF(!alreadyThrowing, !cx->isExceptionPending());
|
2010-08-16 12:35:04 -07:00
|
|
|
}
|
2010-06-16 14:13:28 -07:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2011-02-09 18:17:34 -08:00
|
|
|
extern JSBool CallOrConstructBoundFunction(JSContext *, uintN, js::Value *);
|
|
|
|
|
2010-10-01 21:00:55 -07:00
|
|
|
STATIC_PRECONDITION(ubound(vp) >= argc + 2)
|
2010-08-16 12:35:04 -07:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
CallJSNativeConstructor(JSContext *cx, js::Native native, uintN argc, js::Value *vp)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSObject *callee = &vp[0].toObject();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
JS_ASSERT(vp[1].isMagic());
|
|
|
|
if (!CallJSNative(cx, native, argc, vp))
|
|
|
|
return false;
|
|
|
|
|
2010-09-08 22:20:45 -07:00
|
|
|
/*
|
|
|
|
* Native constructors must return non-primitive values on success.
|
|
|
|
* Although it is legal, if a constructor returns the callee, there is a
|
|
|
|
* 99.9999% chance it is a bug. If any valid code actually wants the
|
2010-09-24 12:54:13 -07:00
|
|
|
* constructor to return the callee, the assertion can be removed or
|
|
|
|
* (another) conjunct can be added to the antecedent.
|
2010-09-08 22:20:45 -07:00
|
|
|
*
|
|
|
|
* Proxies are exceptions to both rules: they can return primitives and
|
|
|
|
* they allow content to return the callee.
|
2010-09-24 12:54:13 -07:00
|
|
|
*
|
2011-02-09 18:17:34 -08:00
|
|
|
* CallOrConstructBoundFunction is an exception as well because we
|
|
|
|
* might have used bind on a proxy function.
|
|
|
|
*
|
2010-09-24 12:54:13 -07:00
|
|
|
* (new Object(Object)) returns the callee.
|
2010-08-16 12:35:04 -07:00
|
|
|
*/
|
2010-09-08 22:20:45 -07:00
|
|
|
extern JSBool proxy_Construct(JSContext *, uintN, Value *);
|
2011-02-09 18:17:34 -08:00
|
|
|
JS_ASSERT_IF(native != proxy_Construct && native != js::CallOrConstructBoundFunction &&
|
2010-09-27 13:09:48 -07:00
|
|
|
(!callee->isFunction() || callee->getFunctionPrivate()->u.n.clasp != &js_ObjectClass),
|
2010-09-08 22:20:45 -07:00
|
|
|
!vp->isPrimitive() && callee != &vp[0].toObject());
|
|
|
|
|
2010-08-16 12:35:04 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE bool
|
2010-08-29 11:57:08 -07:00
|
|
|
CallJSPropertyOp(JSContext *cx, js::PropertyOp op, JSObject *obj, jsid id, js::Value *vp)
|
2010-06-16 14:13:28 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
assertSameCompartment(cx, obj, id, *vp);
|
|
|
|
JSBool ok = op(cx, obj, id, vp);
|
2010-06-16 14:13:28 -07:00
|
|
|
if (ok)
|
|
|
|
assertSameCompartment(cx, obj, *vp);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2010-08-16 12:35:04 -07:00
|
|
|
JS_ALWAYS_INLINE bool
|
2011-02-09 11:31:40 -08:00
|
|
|
CallJSPropertyOpSetter(JSContext *cx, js::StrictPropertyOp op, JSObject *obj, jsid id,
|
|
|
|
JSBool strict, js::Value *vp)
|
2010-06-16 14:13:28 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
assertSameCompartment(cx, obj, id, *vp);
|
2011-02-09 11:31:40 -08:00
|
|
|
return op(cx, obj, id, strict, vp);
|
2010-06-16 14:13:28 -07:00
|
|
|
}
|
|
|
|
|
2010-10-29 10:42:35 -07:00
|
|
|
inline bool
|
2011-02-09 11:31:40 -08:00
|
|
|
CallSetter(JSContext *cx, JSObject *obj, jsid id, js::StrictPropertyOp op, uintN attrs,
|
|
|
|
uintN shortid, JSBool strict, js::Value *vp)
|
2010-10-29 10:42:35 -07:00
|
|
|
{
|
|
|
|
if (attrs & JSPROP_SETTER)
|
|
|
|
return ExternalGetOrSet(cx, obj, id, CastAsObjectJsval(op), JSACC_WRITE, 1, vp, vp);
|
|
|
|
|
|
|
|
if (attrs & JSPROP_GETTER)
|
|
|
|
return js_ReportGetterOnlyAssignment(cx);
|
|
|
|
|
|
|
|
if (attrs & JSPROP_SHORTID)
|
|
|
|
id = INT_TO_JSID(shortid);
|
2011-02-09 11:31:40 -08:00
|
|
|
return CallJSPropertyOpSetter(cx, op, obj, id, strict, vp);
|
2010-10-29 10:42:35 -07:00
|
|
|
}
|
|
|
|
|
2010-12-22 12:02:25 -08:00
|
|
|
#ifdef JS_TRACER
|
|
|
|
/*
|
|
|
|
* Reconstruct the JS stack and clear cx->tracecx. We must be currently in a
|
|
|
|
* _FAIL builtin from trace on cx or another context on the same thread. The
|
|
|
|
* machine code for the trace remains on the C stack when js_DeepBail returns.
|
|
|
|
*
|
|
|
|
* Implemented in jstracer.cpp.
|
|
|
|
*/
|
|
|
|
JS_FORCES_STACK JS_FRIEND_API(void)
|
|
|
|
DeepBail(JSContext *cx);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static JS_INLINE void
|
|
|
|
LeaveTraceIfGlobalObject(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
if (!obj->parent)
|
|
|
|
LeaveTrace(cx);
|
|
|
|
}
|
|
|
|
|
2011-01-05 15:47:46 -08:00
|
|
|
static JS_INLINE void
|
|
|
|
LeaveTraceIfArgumentsObject(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
if (obj->isArguments())
|
|
|
|
LeaveTrace(cx);
|
|
|
|
}
|
|
|
|
|
2010-12-22 12:02:25 -08:00
|
|
|
static JS_INLINE JSBool
|
|
|
|
CanLeaveTrace(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
|
|
|
#ifdef JS_TRACER
|
2011-02-01 10:18:06 -08:00
|
|
|
return JS_TRACE_MONITOR_ON_TRACE(cx)->bailExit != NULL;
|
2010-12-22 12:02:25 -08:00
|
|
|
#else
|
|
|
|
return JS_FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
2010-03-28 13:34:16 -07:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
inline void
|
|
|
|
JSContext::setPendingException(js::Value v) {
|
|
|
|
this->throwing = true;
|
|
|
|
this->exception = v;
|
|
|
|
assertSameCompartment(this, v);
|
|
|
|
}
|
|
|
|
|
2010-03-28 13:34:16 -07:00
|
|
|
#endif /* jscntxtinlines_h___ */
|