Merge mozilla-central to tracemonkey. (CLOSED TREE)

This commit is contained in:
Chris Leary 2011-05-02 10:55:34 -07:00
commit d8a23919cc
125 changed files with 6882 additions and 5463 deletions

View File

@ -63,6 +63,7 @@
#include "prmem.h"
#include "jsapi.h" // for JSAutoRequest
#include "jsdbgapi.h" // for JS_ClearWatchPointsForObject
#include "jsfriendapi.h" // for JS_GetFrameScopeChainRaw
#include "nsReadableUtils.h"
#include "nsDOMClassInfo.h"
#include "nsJSEnvironment.h"
@ -5797,13 +5798,13 @@ nsGlobalWindow::CallerInnerWindow()
JSStackFrame *fp = nsnull;
JS_FrameIterator(cx, &fp);
if (fp) {
while (fp->isDummyFrame()) {
while (!JS_IsScriptFrame(cx, fp)) {
if (!JS_FrameIterator(cx, &fp))
break;
}
if (fp)
scope = &fp->scopeChain();
scope = JS_GetFrameScopeChainRaw(fp);
}
if (!scope)

View File

@ -116,6 +116,8 @@
#include "mozilla/FunctionTimer.h"
using namespace mozilla;
const size_t gStackSize = 8192;
#ifdef PR_LOGGING
@ -1884,8 +1886,8 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, void *aScope, void *aHandler
return NS_ERROR_FAILURE;
}
js::LazilyConstructed<nsAutoPoolRelease> poolRelease;
js::LazilyConstructed<js::AutoArrayRooter> tvr;
Maybe<nsAutoPoolRelease> poolRelease;
Maybe<js::AutoArrayRooter> tvr;
// Use |target| as the scope for wrapping the arguments, since aScope is
// the safe scope in many cases, which isn't very useful. Wrapping aTarget
@ -2373,8 +2375,8 @@ nsJSContext::SetProperty(void *aTarget, const char *aPropName, nsISupports *aArg
JSAutoRequest ar(mContext);
js::LazilyConstructed<nsAutoPoolRelease> poolRelease;
js::LazilyConstructed<js::AutoArrayRooter> tvr;
Maybe<nsAutoPoolRelease> poolRelease;
Maybe<js::AutoArrayRooter> tvr;
nsresult rv;
rv = ConvertSupportsTojsvals(aArgs, GetNativeGlobal(), &argc,
@ -2414,8 +2416,8 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs,
void *aScope,
PRUint32 *aArgc,
jsval **aArgv,
js::LazilyConstructed<nsAutoPoolRelease> &aPoolRelease,
js::LazilyConstructed<js::AutoArrayRooter> &aRooter)
Maybe<nsAutoPoolRelease> &aPoolRelease,
Maybe<js::AutoArrayRooter> &aRooter)
{
nsresult rv = NS_OK;

View File

@ -51,7 +51,9 @@ class nsIXPConnectJSObjectHolder;
class nsAutoPoolRelease;
namespace js {
class AutoArrayRooter;
template <class> class LazilyConstructed;
}
namespace mozilla {
template <class> class Maybe;
}
class nsJSContext : public nsIScriptContext,
@ -205,8 +207,8 @@ protected:
void *aScope,
PRUint32 *aArgc,
jsval **aArgv,
js::LazilyConstructed<nsAutoPoolRelease> &aPoolRelease,
js::LazilyConstructed<js::AutoArrayRooter> &aRooter);
mozilla::Maybe<nsAutoPoolRelease> &aPoolRelease,
mozilla::Maybe<js::AutoArrayRooter> &aRooter);
nsresult AddSupportsPrimitiveTojsvals(nsISupports *aArg, jsval *aArgv);

View File

@ -46,8 +46,6 @@
#include "base/basictypes.h"
#include "jsapi.h"
#include "jscntxt.h"
#include "jsdbgapi.h"
#include "jsprf.h"
#include "xpcpublic.h"
@ -406,13 +404,14 @@ GC(JSContext *cx,
jsval *vp)
{
JSRuntime *rt;
uint32 preBytes;
uint32 preBytes, postBytes;
rt = cx->runtime;
preBytes = rt->gcBytes;
rt = JS_GetRuntime(cx);
preBytes = JS_GetGCParameter(rt, JSGC_BYTES);
JS_GC(cx);
postBytes = JS_GetGCParameter(rt, JSGC_BYTES);
fprintf(stdout, "before %lu, after %lu, break %08lx\n",
(unsigned long)preBytes, (unsigned long)rt->gcBytes,
(unsigned long)preBytes, (unsigned long)postBytes,
#ifdef XP_UNIX
(unsigned long)sbrk(0)
#else

View File

@ -40,7 +40,6 @@
#include "jscntxt.h"
#include "jsapi.h"
#include "jstl.h"
#include "jshashtable.h"
#include "mozilla/jetpack/JetpackActorCommon.h"
@ -51,15 +50,7 @@
#include "nsJSUtils.h"
using mozilla::jetpack::JetpackActorCommon;
using mozilla::jetpack::PHandleParent;
using mozilla::jetpack::HandleParent;
using mozilla::jetpack::PHandleChild;
using mozilla::jetpack::HandleChild;
using mozilla::jetpack::KeyValue;
using mozilla::jetpack::PrimVariant;
using mozilla::jetpack::CompVariant;
using mozilla::jetpack::Variant;
using namespace mozilla::jetpack;
class JetpackActorCommon::OpaqueSeenType
{
@ -176,7 +167,7 @@ JetpackActorCommon::jsval_to_CompVariant(JSContext* cx, JSType type, jsval from,
if (type != JSTYPE_OBJECT)
return false;
js::LazilyConstructed<OpaqueSeenType> lost;
Maybe<OpaqueSeenType> lost;
if (!seen) {
lost.construct();
seen = lost.addr();
@ -337,7 +328,7 @@ JetpackActorCommon::jsval_from_CompVariant(JSContext* cx,
jsval* to,
OpaqueSeenType* seen)
{
js::LazilyConstructed<OpaqueSeenType> lost;
Maybe<OpaqueSeenType> lost;
if (!seen) {
lost.construct();
seen = lost.addr();

View File

@ -181,6 +181,7 @@ CPPSRCS = \
jsxml.cpp \
prmjtime.cpp \
sharkctl.cpp \
Stack.cpp \
$(NULL)
INSTALLED_HEADERS = \
@ -267,6 +268,20 @@ INSTALLED_HEADERS = \
prmjtime.h \
$(NULL)
###############################################
# BEGIN include sources for the vm subdirectory
#
VPATH += \
$(srcdir)/vm \
$(NULL)
EXPORTS_NAMESPACES = vm
EXPORTS_vm = \
Stack.h \
StringObject.h \
$(NULL)
###############################################
# BEGIN include sources for low-level code shared with Gecko
#
@ -274,9 +289,10 @@ VPATH += \
$(srcdir)/../../mfbt \
$(NULL)
EXPORTS_NAMESPACES = mozilla
EXPORTS_NAMESPACES += mozilla
EXPORTS_mozilla = \
Types.h \
Util.h \
$(NULL)
@ -636,7 +652,7 @@ check-malloc-function-usage: $(filter-out %jsalloc.h %jscntxt.h %jsutil.h, $(ALL
# We desire these numbers to go down, not up. See "User guide to memory
# management within SpiderMonkey" in jsutil.h.
$(srcdir)/config/check_source_count.py OffTheBooks:: 53 \
$(srcdir)/config/check_source_count.py OffTheBooks:: 52 \
"in Makefile.in" "{cx,rt}->{new_,new_array,malloc_,calloc_,realloc_}" $^
# This should go to zero, if possible.
$(srcdir)/config/check_source_count.py UnwantedForeground:: 34 \
@ -713,6 +729,11 @@ export::
DEFINES += -DEXPORT_JS_API
# mfbt is always packed with us, so if we're building a shared object,
# we need to declare "exported" mfbt symbols on its behalf when we use
# its headers.
DEFINES += -DIMPL_MFBT
# Some platforms that have stdint.h include it in system headers. So
# to reliably get limit macros defined, we'd always have to define the
# one below before including any header, but that's obscure and

View File

@ -0,0 +1,19 @@
var n1 = Number.prototype.toFixed;
var s1 = String.prototype.split;
delete Number;
delete String;
var n2 = (5).toFixed;
var s2 = ("foo").split;
// Check enumeration doesn't resurrect deleted standard classes
for (x in this) {}
// Ensure the prototypes are shared.
var n3 = (5).toFixed;
var s3 = ("foo").split;
assertEq(s1, s2);
assertEq(s1, s3);
assertEq(n1, n2);
assertEq(n1, n3);

View File

@ -0,0 +1,104 @@
function failWrapper(callback) {
try {
callback(); // this should fail
throw "test-error"; // and if it didn't we have a problem`
} catch (e) {
if (e == "test-error")
throw ("Testing error when running " + callback.toString());
}
}
print ("Deleting standard classes");
delete Function;
delete Object;
delete Array;
delete Boolean;
delete JSON;
delete Date;
delete Math;
delete Number;
delete String;
delete Regexp;
delete XML;
delete Reflect;
delete Proxy;
delete Error;
delete Iterator;
delete Generator;
delete StopIteration;
delete Float32Array;
delete Float64Array;
delete Int16Array;
delete Int32Array;
delete Int32Array;
delete Uint16Array;
delete Uint32Array;
delete Uint8Array;
delete Uint8ClampedArray;
delete Weakmap;
print ("Accessing standard classes shouldn't recreate them");
failWrapper(function () { Function; });
failWrapper(function () { Object; });
failWrapper(function () { Array; });
failWrapper(function () { Boolean; });
failWrapper(function () { JSON; });
failWrapper(function () { Date; });
failWrapper(function () { Math; });
failWrapper(function () { Number; });
failWrapper(function () { String; });
failWrapper(function () { Regexp; });
failWrapper(function () { XML; });
failWrapper(function () { Reflect; });
failWrapper(function () { Proxy; });
failWrapper(function () { Error; });
failWrapper(function () { Iterator; });
failWrapper(function () { Generator; });
failWrapper(function () { StopIteration; });
failWrapper(function () { Float32Array; });
failWrapper(function () { Float64Array; });
failWrapper(function () { Int16Array; });
failWrapper(function () { Int32Array; });
failWrapper(function () { Int32Array; });
failWrapper(function () { Uint16Array; });
failWrapper(function () { Uint32Array; });
failWrapper(function () { Uint8Array; });
failWrapper(function () { Uint8ClampedArray; });
failWrapper(function () { Weakmap; });
print ("Enumerate over the global object");
for (c in this) {}
print ("That shouldn't have recreated the standard classes either");
failWrapper(function () { Function; });
failWrapper(function () { Object; });
failWrapper(function () { Array; });
failWrapper(function () { Boolean; });
failWrapper(function () { JSON; });
failWrapper(function () { Date; });
failWrapper(function () { Math; });
failWrapper(function () { Number; });
failWrapper(function () { String; });
failWrapper(function () { Regexp; });
failWrapper(function () { XML; });
failWrapper(function () { Reflect; });
failWrapper(function () { Proxy; });
failWrapper(function () { Error; });
failWrapper(function () { Iterator; });
failWrapper(function () { Generator; });
failWrapper(function () { StopIteration; });
failWrapper(function () { Float32Array; });
failWrapper(function () { Float64Array; });
failWrapper(function () { Int16Array; });
failWrapper(function () { Int32Array; });
failWrapper(function () { Int32Array; });
failWrapper(function () { Uint16Array; });
failWrapper(function () { Uint32Array; });
failWrapper(function () { Uint8Array; });
failWrapper(function () { Uint8ClampedArray; });
failWrapper(function () { Weakmap; });
print ("success");

View File

@ -0,0 +1,5 @@
// Catch memory leaks when enumerating over the global object.
for (let z = 1; z <= 16000; ++z) {
for each (y in this);
}

View File

@ -112,7 +112,7 @@ MSG_DEF(JSMSG_BAD_SHARP_DEF, 29, 1, JSEXN_ERR, "invalid sharp variable
MSG_DEF(JSMSG_BAD_SHARP_USE, 30, 1, JSEXN_ERR, "invalid sharp variable use #{0}#")
MSG_DEF(JSMSG_BAD_INSTANCEOF_RHS, 31, 1, JSEXN_TYPEERR, "invalid 'instanceof' operand {0}")
MSG_DEF(JSMSG_BAD_BYTECODE, 32, 1, JSEXN_INTERNALERR, "unimplemented JavaScript bytecode {0}")
MSG_DEF(JSMSG_BAD_RADIX, 33, 1, JSEXN_ERR, "illegal radix {0}")
MSG_DEF(JSMSG_BAD_RADIX, 33, 0, JSEXN_RANGEERR, "radix must be an integer at least 2 and no greater than 36")
MSG_DEF(JSMSG_PAREN_BEFORE_LET, 34, 0, JSEXN_SYNTAXERR, "missing ( before let head")
MSG_DEF(JSMSG_CANT_CONVERT, 35, 1, JSEXN_ERR, "can't convert {0} to an integer")
MSG_DEF(JSMSG_CYCLIC_VALUE, 36, 1, JSEXN_TYPEERR, "cyclic {0} value")

View File

@ -90,16 +90,15 @@
#include "jstypedarray.h"
#include "jsatominlines.h"
#include "jscntxtinlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsscopeinlines.h"
#include "jscntxtinlines.h"
#include "jsregexpinlines.h"
#include "jsscriptinlines.h"
#include "jsstrinlines.h"
#include "assembler/wtf/Platform.h"
#include "vm/Stack-inl.h"
#if ENABLE_YARR_JIT
#include "assembler/jit/ExecutableAllocator.h"
#include "methodjit/Logging.h"
@ -845,7 +844,7 @@ JS_SetRuntimePrivate(JSRuntime *rt, void *data)
static void
StartRequest(JSContext *cx)
{
JSThread *t = cx->thread;
JSThread *t = cx->thread();
JS_ASSERT(CURRENT_THREAD_IS_ME(t));
if (t->data.requestDepth) {
@ -855,7 +854,7 @@ StartRequest(JSContext *cx)
AutoLockGC lock(rt);
/* Wait until the GC is finished. */
if (rt->gcThread != cx->thread) {
if (rt->gcThread != cx->thread()) {
while (rt->gcThread)
JS_AWAIT_GC_DONE(rt);
}
@ -879,7 +878,7 @@ StartRequest(JSContext *cx)
static void
StopRequest(JSContext *cx)
{
JSThread *t = cx->thread;
JSThread *t = cx->thread();
JS_ASSERT(CURRENT_THREAD_IS_ME(t));
JS_ASSERT(t->data.requestDepth != 0);
if (t->data.requestDepth != 1) {
@ -947,7 +946,7 @@ JS_PUBLIC_API(jsrefcount)
JS_SuspendRequest(JSContext *cx)
{
#ifdef JS_THREADSAFE
JSThread *t = cx->thread;
JSThread *t = cx->thread();
JS_ASSERT(CURRENT_THREAD_IS_ME(t));
jsrefcount saveDepth = t->data.requestDepth;
@ -967,7 +966,7 @@ JS_PUBLIC_API(void)
JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth)
{
#ifdef JS_THREADSAFE
JSThread *t = cx->thread;
JSThread *t = cx->thread();
JS_ASSERT(CURRENT_THREAD_IS_ME(t));
if (saveDepth == 0)
return;
@ -984,7 +983,7 @@ JS_PUBLIC_API(JSBool)
JS_IsInRequest(JSContext *cx)
{
#ifdef JS_THREADSAFE
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread));
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread()));
return JS_THREAD_DATA(cx)->requestDepth != 0;
#else
return false;
@ -1519,7 +1518,7 @@ JS_SetGlobalObject(JSContext *cx, JSObject *obj)
CHECK_REQUEST(cx);
cx->globalObject = obj;
if (!cx->hasfp())
if (!cx->running())
cx->resetCompartment();
}
@ -1775,8 +1774,7 @@ JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsid id, JSBool *resolved)
if (stdnm->clasp->flags & JSCLASS_IS_ANONYMOUS)
return JS_TRUE;
JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(stdnm->clasp);
if (obj->getReservedSlot(key).isObject())
if (IsStandardClassResolved(obj, stdnm->clasp))
return JS_TRUE;
if (!stdnm->init(cx, obj))
@ -1797,7 +1795,10 @@ JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj)
assertSameCompartment(cx, obj);
rt = cx->runtime;
/* Check whether we need to bind 'undefined' and define it if so. */
/*
* Check whether we need to bind 'undefined' and define it if so.
* Since ES5 15.1.1.3 undefined can't be deleted.
*/
atom = rt->atomState.typeAtoms[JSTYPE_VOID];
if (!obj->nativeContains(ATOM_TO_JSID(atom)) &&
!obj->defineProperty(cx, ATOM_TO_JSID(atom), UndefinedValue(),
@ -1806,12 +1807,12 @@ JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj)
return JS_FALSE;
}
/* Initialize any classes that have not been resolved yet. */
/* Initialize any classes that have not been initialized yet. */
for (i = 0; standard_class_atoms[i].init; i++) {
atom = OFFSET_TO_ATOM(rt, standard_class_atoms[i].atomOffset);
if (!obj->nativeContains(ATOM_TO_JSID(atom)) &&
!standard_class_atoms[i].init(cx, obj)) {
return JS_FALSE;
if (!js::IsStandardClassResolved(obj, standard_class_atoms[i].clasp) &&
!standard_class_atoms[i].init(cx, obj))
{
return JS_FALSE;
}
}
@ -2762,7 +2763,7 @@ JS_PUBLIC_API(void)
JS_SetNativeStackQuota(JSContext *cx, size_t stackSize)
{
#ifdef JS_THREADSAFE
JS_ASSERT(cx->thread);
JS_ASSERT(cx->thread());
#endif
#if JS_STACK_GROWTH_DIRECTION > 0
@ -4210,7 +4211,7 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent)
CHECK_REQUEST(cx);
assertSameCompartment(cx, parent); // XXX no funobj for now
if (!parent) {
if (cx->hasfp())
if (cx->running())
parent = GetScopeChain(cx, cx->fp());
if (!parent)
parent = cx->globalObject;
@ -5107,7 +5108,7 @@ JS_New(JSContext *cx, JSObject *ctor, uintN argc, jsval *argv)
// of object to create, create it, and clamp the return value to an object,
// among other details. js_InvokeConstructor does the hard work.
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, argc, &args))
if (!cx->stack.pushInvokeArgs(cx, argc, &args))
return NULL;
args.calleev().setObject(*ctor);
@ -5141,7 +5142,7 @@ JS_PUBLIC_API(JSOperationCallback)
JS_SetOperationCallback(JSContext *cx, JSOperationCallback callback)
{
#ifdef JS_THREADSAFE
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread));
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread()));
#endif
JSOperationCallback old = cx->operationCallback;
cx->operationCallback = callback;
@ -5183,9 +5184,9 @@ JS_IsRunning(JSContext *cx)
VOUCH_DOES_NOT_REQUIRE_STACK();
#ifdef JS_TRACER
JS_ASSERT_IF(JS_ON_TRACE(cx) && JS_TRACE_MONITOR_ON_TRACE(cx)->tracecx == cx, cx->hasfp());
JS_ASSERT_IF(JS_ON_TRACE(cx) && JS_TRACE_MONITOR_ON_TRACE(cx)->tracecx == cx, cx->running());
#endif
JSStackFrame *fp = cx->maybefp();
StackFrame *fp = cx->maybefp();
while (fp && fp->isDummyFrame())
fp = fp->prev();
return fp != NULL;
@ -5195,11 +5196,11 @@ JS_PUBLIC_API(JSStackFrame *)
JS_SaveFrameChain(JSContext *cx)
{
CHECK_REQUEST(cx);
JSStackFrame *fp = js_GetTopStackFrame(cx);
StackFrame *fp = js_GetTopStackFrame(cx);
if (!fp)
return NULL;
cx->saveActiveSegment();
return fp;
cx->stack.saveActiveSegment();
return Jsvalify(fp);
}
JS_PUBLIC_API(void)
@ -5207,10 +5208,10 @@ JS_RestoreFrameChain(JSContext *cx, JSStackFrame *fp)
{
CHECK_REQUEST(cx);
JS_ASSERT_NOT_ON_TRACE(cx);
JS_ASSERT(!cx->hasfp());
JS_ASSERT(!cx->running());
if (!fp)
return;
cx->restoreSegment();
cx->stack.restoreSegment();
}
/************************************************************************/
@ -5580,7 +5581,6 @@ JS_WriteStructuredClone(JSContext *cx, jsval v, uint64 **bufp, size_t *nbytesp,
JS_PUBLIC_API(JSBool)
JS_StructuredClone(JSContext *cx, jsval v, jsval *vp,
ReadStructuredCloneOp optionalReadOp,
const JSStructuredCloneCallbacks *optionalCallbacks,
void *closure)
{
@ -6031,9 +6031,9 @@ JS_SetContextThread(JSContext *cx)
{
#ifdef JS_THREADSAFE
JS_ASSERT(!cx->outstandingRequests);
if (cx->thread) {
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread));
return reinterpret_cast<jsword>(cx->thread->id);
if (cx->thread()) {
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread()));
return reinterpret_cast<jsword>(cx->thread()->id);
}
if (!js_InitContextThread(cx)) {
@ -6057,7 +6057,7 @@ JS_ClearContextThread(JSContext *cx)
* is a harmless no-op.
*/
JS_ASSERT(cx->outstandingRequests == 0);
JSThread *t = cx->thread;
JSThread *t = cx->thread();
if (!t)
return 0;
JS_ASSERT(CURRENT_THREAD_IS_ME(t));

View File

@ -111,6 +111,8 @@
#include "jsobjinlines.h"
#include "jsstrinlines.h"
#include "vm/Stack-inl.h"
using namespace js;
using namespace js::gc;
@ -366,7 +368,7 @@ GetElement(JSContext *cx, JSObject *obj, jsdouble index, JSBool *hole, Value *vp
index < obj->getArgsInitialLength() &&
!(*vp = obj->getArgsElement(uint32(index))).isMagic(JS_ARGS_HOLE)) {
*hole = JS_FALSE;
JSStackFrame *fp = (JSStackFrame *)obj->getPrivate();
StackFrame *fp = (StackFrame *)obj->getPrivate();
if (fp != JS_ARGUMENTS_OBJECT_ON_TRACE) {
if (fp)
*vp = fp->canonicalActualArg(index);
@ -434,7 +436,7 @@ GetElements(JSContext *cx, JSObject *aobj, jsuint length, Value *vp)
* fast path for deleted properties (MagicValue(JS_ARGS_HOLE) since
* this requires general-purpose property lookup.
*/
if (JSStackFrame *fp = (JSStackFrame *) aobj->getPrivate()) {
if (StackFrame *fp = (StackFrame *) aobj->getPrivate()) {
JS_ASSERT(fp->numActualArgs() <= JS_ARGS_LENGTH_MAX);
if (!fp->forEachCanonicalActualArg(CopyNonHoleArgsTo(aobj, vp)))
goto found_deleted_prop;
@ -1062,7 +1064,7 @@ JSObject::makeDenseArraySlow(JSContext *cx)
/* Create a native scope. */
JSObject *arrayProto = getProto();
js::gc::FinalizeKind kind = js::gc::FinalizeKind(arena()->header()->thingKind);
js::gc::FinalizeKind kind = js::gc::FinalizeKind(arenaHeader()->getThingKind());
if (!InitScopeForObject(cx, this, &js_SlowArrayClass, arrayProto, kind))
return false;
@ -1310,8 +1312,6 @@ static JSBool
array_toString_sub(JSContext *cx, JSObject *obj, JSBool locale,
JSString *sepstr, Value *rval)
{
JS_CHECK_RECURSION(cx, return false);
static const jschar comma = ',';
const jschar *sep;
size_t seplen;
@ -1393,6 +1393,8 @@ array_toString_sub(JSContext *cx, JSObject *obj, JSBool locale,
static JSBool
array_toString(JSContext *cx, uintN argc, Value *vp)
{
JS_CHECK_RECURSION(cx, return false);
JSObject *obj = ToObject(cx, &vp[1]);
if (!obj)
return false;
@ -1411,14 +1413,14 @@ array_toString(JSContext *cx, uintN argc, Value *vp)
LeaveTrace(cx);
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, 0, &args))
if (!cx->stack.pushInvokeArgs(cx, 0, &args))
return false;
args.calleev() = join;
args.thisv().setObject(*obj);
/* Do the call. */
if (!Invoke(cx, args, 0))
if (!Invoke(cx, args))
return false;
*vp = args.rval();
return true;
@ -1427,6 +1429,8 @@ array_toString(JSContext *cx, uintN argc, Value *vp)
static JSBool
array_toLocaleString(JSContext *cx, uintN argc, Value *vp)
{
JS_CHECK_RECURSION(cx, return false);
JSObject *obj = ToObject(cx, &vp[1]);
if (!obj)
return false;
@ -1524,6 +1528,8 @@ InitArrayObject(JSContext *cx, JSObject *obj, jsuint length, const Value *vector
static JSBool
array_join(JSContext *cx, uintN argc, Value *vp)
{
JS_CHECK_RECURSION(cx, return false);
JSString *str;
if (argc == 0 || vp[2].isUndefined()) {
str = NULL;
@ -2394,9 +2400,8 @@ array_splice(JSContext *cx, uintN argc, Value *vp)
/* Convert the first argument into a starting index. */
jsdouble d;
if (!ValueToNumber(cx, *argv, &d))
if (!ToInteger(cx, *argv, &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (d < 0) {
d += length;
if (d < 0)
@ -2414,9 +2419,8 @@ array_splice(JSContext *cx, uintN argc, Value *vp)
count = delta;
end = length;
} else {
if (!ValueToNumber(cx, *argv, &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (!ToInteger(cx, *argv, &d))
return false;
if (d < 0)
d = 0;
else if (d > delta)
@ -2638,9 +2642,8 @@ array_slice(JSContext *cx, uintN argc, Value *vp)
if (argc > 0) {
jsdouble d;
if (!ValueToNumber(cx, argv[0], &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (!ToInteger(cx, argv[0], &d))
return false;
if (d < 0) {
d += length;
if (d < 0)
@ -2651,9 +2654,8 @@ array_slice(JSContext *cx, uintN argc, Value *vp)
begin = (jsuint)d;
if (argc > 1 && !argv[1].isUndefined()) {
if (!ValueToNumber(cx, argv[1], &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (!ToInteger(cx, argv[1], &d))
return false;
if (d < 0) {
d += length;
if (d < 0)
@ -2721,9 +2723,8 @@ array_indexOfHelper(JSContext *cx, JSBool isLast, uintN argc, Value *vp)
jsdouble start;
tosearch = vp[2];
if (!ValueToNumber(cx, vp[3], &start))
return JS_FALSE;
start = js_DoubleToInteger(start);
if (!ToInteger(cx, vp[3], &start))
return false;
if (start < 0) {
start += length;
if (start < 0) {

View File

@ -125,6 +125,20 @@ IdToString(JSContext *cx, jsid id)
return js_ValueToString(cx, IdToValue(id));
}
template<>
struct DefaultHasher<jsid>
{
typedef jsid Lookup;
static HashNumber hash(const Lookup &l) {
JS_ASSERT(l == js_CheckForStringIndex(l));
return JSID_BITS(l);
}
static bool match(const jsid &id, const Lookup &l) {
JS_ASSERT(l == js_CheckForStringIndex(l));
return id == l;
}
};
}
#if JS_BYTES_PER_WORD == 4

View File

@ -47,6 +47,7 @@ namespace gc {
template <typename T> struct Arena;
struct ArenaBitmap;
struct ArenaHeader;
struct MarkingDelay;
struct Chunk;
struct FreeCell;
@ -64,7 +65,8 @@ struct Cell {
static const size_t CellSize = size_t(1) << CellShift;
static const size_t CellMask = CellSize - 1;
inline Arena<Cell> *arena() const;
inline uintptr_t address() const;
inline ArenaHeader *arenaHeader() const;
inline Chunk *chunk() const;
inline ArenaBitmap *bitmap() const;
JS_ALWAYS_INLINE size_t cellIndex() const;
@ -82,9 +84,12 @@ struct Cell {
JS_ALWAYS_INLINE const js::gc::FreeCell *asFreeCell() const {
return reinterpret_cast<const FreeCell *>(this);
}
#ifdef DEBUG
inline bool isAligned() const;
#endif
};
/* FreeCell has always size 8 */
struct FreeCell : Cell {
union {
FreeCell *link;
@ -92,7 +97,7 @@ struct FreeCell : Cell {
};
};
JS_STATIC_ASSERT(sizeof(FreeCell) == 8);
JS_STATIC_ASSERT(sizeof(FreeCell) == Cell::CellSize);
} /* namespace gc */
} /* namespace js */

View File

@ -74,6 +74,7 @@
#include "jsobj.h"
#include "jsopcode.h"
#include "jspubtd.h"
#include "jsscan.h"
#include "jsscope.h"
#include "jsscript.h"
#include "jsstaticcheck.h"
@ -86,449 +87,11 @@
#include "jscntxtinlines.h"
#include "jscompartment.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#ifdef XP_WIN
# include "jswin.h"
#elif defined(XP_OS2)
# define INCL_DOSMEMMGR
# include <os2.h>
#else
# include <unistd.h>
# include <sys/mman.h>
# if !defined(MAP_ANONYMOUS)
# if defined(MAP_ANON)
# define MAP_ANONYMOUS MAP_ANON
# else
# define MAP_ANONYMOUS 0
# endif
# endif
#endif
using namespace js;
using namespace js::gc;
JS_REQUIRES_STACK bool
StackSegment::contains(const JSStackFrame *fp) const
{
JS_ASSERT(inContext());
if (fp < initialFrame)
return false;
JSStackFrame *start;
if (isActive()) {
JS_ASSERT(cx->hasfp() && this == cx->activeSegment());
start = cx->fp();
} else {
JS_ASSERT(suspendedRegs && suspendedRegs->fp);
start = suspendedRegs->fp;
}
if (fp > start)
return false;
#ifdef DEBUG
bool found = false;
JSStackFrame *stop = initialFrame->prev();
for (JSStackFrame *f = start; !found && f != stop; f = f->prev()) {
if (f == fp) {
found = true;
break;
}
}
JS_ASSERT(found);
#endif
return true;
}
JSStackFrame *
StackSegment::computeNextFrame(JSStackFrame *fp) const
{
JS_ASSERT(contains(fp));
JS_ASSERT(fp != getCurrentFrame());
JSStackFrame *next = getCurrentFrame();
JSStackFrame *prev;
while ((prev = next->prev()) != fp)
next = prev;
return next;
}
StackSpace::StackSpace()
: base(NULL),
#ifdef XP_WIN
commitEnd(NULL),
#endif
end(NULL),
currentSegment(NULL),
#ifdef DEBUG
invokeSegment(NULL),
invokeFrame(NULL),
#endif
invokeArgEnd(NULL)
{
}
bool
StackSpace::init()
{
void *p;
#ifdef XP_WIN
p = VirtualAlloc(NULL, CAPACITY_BYTES, MEM_RESERVE, PAGE_READWRITE);
if (!p)
return false;
void *check = VirtualAlloc(p, COMMIT_BYTES, MEM_COMMIT, PAGE_READWRITE);
if (p != check)
return false;
base = reinterpret_cast<Value *>(p);
commitEnd = base + COMMIT_VALS;
end = base + CAPACITY_VALS;
#elif defined(XP_OS2)
if (DosAllocMem(&p, CAPACITY_BYTES, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_ANY) &&
DosAllocMem(&p, CAPACITY_BYTES, PAG_COMMIT | PAG_READ | PAG_WRITE))
return false;
base = reinterpret_cast<Value *>(p);
end = base + CAPACITY_VALS;
#else
JS_ASSERT(CAPACITY_BYTES % getpagesize() == 0);
p = mmap(NULL, CAPACITY_BYTES, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
return false;
base = reinterpret_cast<Value *>(p);
end = base + CAPACITY_VALS;
#endif
return true;
}
StackSpace::~StackSpace()
{
if (!base)
return;
#ifdef XP_WIN
VirtualFree(base, (commitEnd - base) * sizeof(Value), MEM_DECOMMIT);
VirtualFree(base, 0, MEM_RELEASE);
#elif defined(XP_OS2)
DosFreeMem(base);
#else
#ifdef SOLARIS
munmap((caddr_t)base, CAPACITY_BYTES);
#else
munmap(base, CAPACITY_BYTES);
#endif
#endif
}
#ifdef XP_WIN
JS_FRIEND_API(bool)
StackSpace::bumpCommit(Value *from, ptrdiff_t nvals) const
{
JS_ASSERT(end - from >= nvals);
Value *newCommit = commitEnd;
Value *request = from + nvals;
/* Use a dumb loop; will probably execute once. */
JS_ASSERT((end - newCommit) % COMMIT_VALS == 0);
do {
newCommit += COMMIT_VALS;
JS_ASSERT((end - newCommit) >= 0);
} while (newCommit < request);
/* The cast is safe because CAPACITY_BYTES is small. */
int32 size = static_cast<int32>(newCommit - commitEnd) * sizeof(Value);
if (!VirtualAlloc(commitEnd, size, MEM_COMMIT, PAGE_READWRITE))
return false;
commitEnd = newCommit;
return true;
}
#endif
void
StackSpace::mark(JSTracer *trc)
{
/*
* The correctness/completeness of marking depends on the continuity
* invariants described by the StackSegment and StackSpace definitions.
*
* NB:
* Stack slots might be torn or uninitialized in the presence of method
* JIT'd code. Arguments are an exception and are always fully synced
* (so they can be read by functions).
*/
Value *end = firstUnused();
for (StackSegment *seg = currentSegment; seg; seg = seg->getPreviousInMemory()) {
STATIC_ASSERT(ubound(end) >= 0);
if (seg->inContext()) {
/* This may be the only pointer to the initialVarObj. */
if (seg->hasInitialVarObj())
MarkObject(trc, seg->getInitialVarObj(), "varobj");
/* Mark slots/args trailing off of the last stack frame. */
JSStackFrame *fp = seg->getCurrentFrame();
MarkStackRangeConservatively(trc, fp->slots(), end);
/* Mark stack frames and slots/args between stack frames. */
JSStackFrame *initial = seg->getInitialFrame();
for (JSStackFrame *f = fp; f != initial; f = f->prev()) {
js_TraceStackFrame(trc, f);
MarkStackRangeConservatively(trc, f->prev()->slots(), (Value *)f);
}
/* Mark initial stack frame and leading args. */
js_TraceStackFrame(trc, initial);
MarkStackRangeConservatively(trc, seg->valueRangeBegin(), (Value *)initial);
} else {
/* Mark slots/args trailing off segment. */
MarkValueRange(trc, seg->valueRangeBegin(), end, "stack");
}
end = (Value *)seg;
}
}
bool
StackSpace::pushSegmentForInvoke(JSContext *cx, uintN argc, InvokeArgsGuard *ag)
{
Value *start = firstUnused();
ptrdiff_t nvals = VALUES_PER_STACK_SEGMENT + 2 + argc;
if (!ensureSpace(cx, start, nvals))
return false;
StackSegment *seg = new(start) StackSegment;
seg->setPreviousInMemory(currentSegment);
currentSegment = seg;
ag->cx = cx;
ag->seg = seg;
ImplicitCast<CallArgs>(*ag) = CallArgsFromVp(argc, seg->valueRangeBegin());
/* Use invokeArgEnd to root [vp, vpend) until the frame is pushed. */
#ifdef DEBUG
ag->prevInvokeSegment = invokeSegment;
invokeSegment = seg;
ag->prevInvokeFrame = invokeFrame;
invokeFrame = NULL;
#endif
ag->prevInvokeArgEnd = invokeArgEnd;
invokeArgEnd = ag->argv() + ag->argc();
return true;
}
void
StackSpace::popSegmentForInvoke(const InvokeArgsGuard &ag)
{
JS_ASSERT(!currentSegment->inContext());
JS_ASSERT(ag.seg == currentSegment);
JS_ASSERT(invokeSegment == currentSegment);
JS_ASSERT(invokeArgEnd == ag.argv() + ag.argc());
currentSegment = currentSegment->getPreviousInMemory();
#ifdef DEBUG
invokeSegment = ag.prevInvokeSegment;
invokeFrame = ag.prevInvokeFrame;
#endif
invokeArgEnd = ag.prevInvokeArgEnd;
}
bool
StackSpace::getSegmentAndFrame(JSContext *cx, uintN vplen, uintN nslots,
FrameGuard *fg) const
{
Value *start = firstUnused();
uintN nvals = VALUES_PER_STACK_SEGMENT + vplen + VALUES_PER_STACK_FRAME + nslots;
if (!ensureSpace(cx, start, nvals))
return false;
fg->seg_ = new(start) StackSegment;
fg->vp_ = start + VALUES_PER_STACK_SEGMENT;
fg->fp_ = reinterpret_cast<JSStackFrame *>(fg->vp() + vplen);
return true;
}
void
StackSpace::pushSegmentAndFrame(JSContext *cx, JSFrameRegs *regs, FrameGuard *fg)
{
/* Caller should have already initialized regs. */
JS_ASSERT(regs->fp == fg->fp());
StackSegment *seg = fg->segment();
/* Register new segment/frame with the context. */
cx->pushSegmentAndFrame(seg, *regs);
/* Officially push the segment/frame on the stack. */
seg->setPreviousInMemory(currentSegment);
currentSegment = seg;
/* Mark as 'pushed' in the guard. */
fg->cx_ = cx;
}
void
StackSpace::popSegmentAndFrame(JSContext *cx)
{
JS_ASSERT(isCurrentAndActive(cx));
JS_ASSERT(cx->hasActiveSegment());
PutActivationObjects(cx, cx->fp());
/* Officially pop the segment/frame from the stack. */
currentSegment = currentSegment->getPreviousInMemory();
/* Unregister pushed segment/frame from the context. */
cx->popSegmentAndFrame();
/*
* N.B. This StackSpace should be GC-able without any operations after
* cx->popSegmentAndFrame executes since it can trigger GC.
*/
}
FrameGuard::~FrameGuard()
{
if (!pushed())
return;
JS_ASSERT(cx_->activeSegment() == segment());
JS_ASSERT(cx_->maybefp() == fp());
cx_->stack().popSegmentAndFrame(cx_);
}
bool
StackSpace::getExecuteFrame(JSContext *cx, JSScript *script, ExecuteFrameGuard *fg) const
{
return getSegmentAndFrame(cx, 2, script->nslots, fg);
}
void
StackSpace::pushExecuteFrame(JSContext *cx, JSObject *initialVarObj, ExecuteFrameGuard *fg)
{
JSStackFrame *fp = fg->fp();
JSScript *script = fp->script();
fg->regs_.pc = script->code;
fg->regs_.fp = fp;
fg->regs_.sp = fp->base();
pushSegmentAndFrame(cx, &fg->regs_, fg);
fg->seg_->setInitialVarObj(initialVarObj);
}
bool
StackSpace::pushDummyFrame(JSContext *cx, JSObject &scopeChain, DummyFrameGuard *fg)
{
if (!getSegmentAndFrame(cx, 0 /*vplen*/, 0 /*nslots*/, fg))
return false;
fg->fp()->initDummyFrame(cx, scopeChain);
fg->regs_.fp = fg->fp();
fg->regs_.pc = NULL;
fg->regs_.sp = fg->fp()->slots();
pushSegmentAndFrame(cx, &fg->regs_, fg);
return true;
}
bool
StackSpace::getGeneratorFrame(JSContext *cx, uintN vplen, uintN nslots, GeneratorFrameGuard *fg)
{
return getSegmentAndFrame(cx, vplen, nslots, fg);
}
void
StackSpace::pushGeneratorFrame(JSContext *cx, JSFrameRegs *regs, GeneratorFrameGuard *fg)
{
JS_ASSERT(regs->fp == fg->fp());
JS_ASSERT(regs->fp->prev() == cx->maybefp());
pushSegmentAndFrame(cx, regs, fg);
}
bool
StackSpace::bumpCommitAndLimit(JSStackFrame *base, Value *sp, uintN nvals, Value **limit) const
{
JS_ASSERT(sp >= firstUnused());
JS_ASSERT(sp + nvals >= *limit);
#ifdef XP_WIN
if (commitEnd <= *limit) {
Value *quotaEnd = (Value *)base + STACK_QUOTA;
if (sp + nvals < quotaEnd) {
if (!ensureSpace(NULL, sp, nvals))
return false;
*limit = Min(quotaEnd, commitEnd);
return true;
}
}
#endif
return false;
}
void
FrameRegsIter::initSlow()
{
if (!curseg) {
curfp = NULL;
cursp = NULL;
curpc = NULL;
return;
}
JS_ASSERT(curseg->isSuspended());
curfp = curseg->getSuspendedFrame();
cursp = curseg->getSuspendedRegs()->sp;
curpc = curseg->getSuspendedRegs()->pc;
}
/*
* Using the invariant described in the js::StackSegment comment, we know that,
* when a pair of prev-linked stack frames are in the same segment, the
* first frame's address is the top of the prev-frame's stack, modulo missing
* arguments.
*/
void
FrameRegsIter::incSlow(JSStackFrame *fp, JSStackFrame *prev)
{
JS_ASSERT(prev);
JS_ASSERT(curpc == curfp->pc(cx, fp));
JS_ASSERT(fp == curseg->getInitialFrame());
/*
* If fp is in cs and the prev-frame is in csprev, it is not necessarily
* the case that |cs->getPreviousInContext == csprev| or that
* |csprev->getSuspendedFrame == prev| (because of indirect eval and
* JS_EvaluateInStackFrame). To compute prev's sp, we need to do a linear
* scan, keeping track of what is immediately after prev in memory.
*/
curseg = curseg->getPreviousInContext();
cursp = curseg->getSuspendedRegs()->sp;
JSStackFrame *f = curseg->getSuspendedFrame();
while (f != prev) {
if (f == curseg->getInitialFrame()) {
curseg = curseg->getPreviousInContext();
cursp = curseg->getSuspendedRegs()->sp;
f = curseg->getSuspendedFrame();
} else {
cursp = f->formalArgsEnd();
f = f->prev();
}
}
}
AllFramesIter::AllFramesIter(JSContext *cx)
: curcs(cx->stack().getCurrentSegment()),
curfp(curcs ? curcs->getCurrentFrame() : NULL)
{
}
AllFramesIter&
AllFramesIter::operator++()
{
JS_ASSERT(!done());
if (curfp == curcs->getInitialFrame()) {
curcs = curcs->getPreviousInMemory();
curfp = curcs ? curcs->getCurrentFrame() : NULL;
} else {
curfp = curfp->prev();
}
return *this;
}
namespace js {
ThreadData::ThreadData()
@ -649,16 +212,23 @@ js_InitContextThread(JSContext *cx)
return false;
JS_APPEND_LINK(&cx->threadLinks, &thread->contextList);
cx->thread = thread;
cx->setThread(thread);
return true;
}
void
JSContext::setThread(JSThread *thread)
{
thread_ = thread;
stack.threadReset();
}
void
js_ClearContextThread(JSContext *cx)
{
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread));
JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread()));
JS_REMOVE_AND_INIT_LINK(&cx->threadLinks);
cx->thread = NULL;
cx->setThread(NULL);
}
#endif /* JS_THREADSAFE */
@ -711,7 +281,7 @@ js_PurgeThreads(JSContext *cx)
JSThread *thread = e.front().value;
if (JS_CLIST_IS_EMPTY(&thread->contextList)) {
JS_ASSERT(cx->thread != thread);
JS_ASSERT(cx->thread() != thread);
Foreground::delete_(thread);
e.removeFront();
} else {
@ -892,7 +462,7 @@ DumpEvalCacheMeter(JSContext *cx)
fprintf(fp, "eval cache meter (%p):\n",
#ifdef JS_THREADSAFE
(void *) cx->thread
(void *) cx->thread()
#else
(void *) cx->runtime
#endif
@ -980,8 +550,8 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
* optimized builds. We assume that the embedding knows that an OOM error
* cannot happen in JS_SetContextThread.
*/
JS_ASSERT(cx->thread && CURRENT_THREAD_IS_ME(cx->thread));
if (!cx->thread)
JS_ASSERT(cx->thread() && CURRENT_THREAD_IS_ME(cx->thread()));
if (!cx->thread())
JS_SetContextThread(cx);
/*
@ -990,7 +560,7 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
* on this cx contributes to cx->thread->data.requestDepth and there is no
* JS_SuspendRequest calls that set aside the counter.
*/
JS_ASSERT(cx->outstandingRequests <= cx->thread->data.requestDepth);
JS_ASSERT(cx->outstandingRequests <= cx->thread()->data.requestDepth);
#endif
if (mode != JSDCM_NEW_FAILED) {
@ -1012,7 +582,7 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
* Typically we are called outside a request, so ensure that the GC is not
* running before removing the context from rt->contextList, see bug 477021.
*/
if (cx->thread->data.requestDepth == 0)
if (cx->thread()->data.requestDepth == 0)
js_WaitForGC(rt);
#endif
JS_REMOVE_LINK(&cx->link);
@ -1043,7 +613,7 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
* force or maybe run the GC, but by that point, rt->state will
* not be JSRTS_UP, and that GC attempt will return early.
*/
if (cx->thread->data.requestDepth == 0)
if (cx->thread()->data.requestDepth == 0)
JS_BeginRequest(cx);
#endif
@ -1089,7 +659,7 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
}
#ifdef JS_THREADSAFE
#ifdef DEBUG
JSThread *t = cx->thread;
JSThread *t = cx->thread();
#endif
js_ClearContextThread(cx);
JS_ASSERT_IF(JS_CLIST_IS_EMPTY(&t->contextList), !t->data.requestDepth);
@ -1109,7 +679,9 @@ js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp)
{
JSContext *cx = *iterp;
Conditionally<AutoLockGC> lockIf(!!unlocked, rt);
Maybe<AutoLockGC> lockIf;
if (unlocked)
lockIf.construct(rt);
cx = js_ContextFromLinkField(cx ? cx->link.next : rt->contextList.next);
if (&cx->link == &rt->contextList)
cx = NULL;
@ -1123,7 +695,7 @@ js_NextActiveContext(JSRuntime *rt, JSContext *cx)
JSContext *iter = cx;
#ifdef JS_THREADSAFE
while ((cx = js_ContextIterator(rt, JS_FALSE, &iter)) != NULL) {
if (cx->outstandingRequests && cx->thread->data.requestDepth)
if (cx->outstandingRequests && cx->thread()->data.requestDepth)
break;
}
return cx;
@ -1191,7 +763,7 @@ PopulateReportBlame(JSContext *cx, JSErrorReport *report)
* Walk stack until we find a frame that is associated with some script
* rather than a native frame.
*/
for (JSStackFrame *fp = js_GetTopStackFrame(cx); fp; fp = fp->prev()) {
for (StackFrame *fp = js_GetTopStackFrame(cx); fp; fp = fp->prev()) {
if (fp->pc(cx)) {
report->filename = fp->script()->filename;
report->lineno = js_FramePCToLineNumber(cx, fp);
@ -1253,22 +825,24 @@ js_ReportOutOfMemory(JSContext *cx)
}
void
js_ReportOutOfScriptQuota(JSContext *cx)
js_ReportOutOfScriptQuota(JSContext *maybecx)
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_SCRIPT_STACK_QUOTA);
if (maybecx)
JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL, JSMSG_SCRIPT_STACK_QUOTA);
}
JS_FRIEND_API(void)
js_ReportOverRecursed(JSContext *cx)
js_ReportOverRecursed(JSContext *maybecx)
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_OVER_RECURSED);
if (maybecx)
JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL, JSMSG_OVER_RECURSED);
}
void
js_ReportAllocationOverflow(JSContext *cx)
js_ReportAllocationOverflow(JSContext *maybecx)
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_ALLOC_OVERFLOW);
if (maybecx)
JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL, JSMSG_ALLOC_OVERFLOW);
}
/*
@ -1286,7 +860,7 @@ checkReportFlags(JSContext *cx, uintN *flags)
* We assume that if the top frame is a native, then it is strict if
* the nearest scripted frame is strict, see bug 536306.
*/
JSStackFrame *fp = js_GetScriptedCaller(cx, NULL);
StackFrame *fp = js_GetScriptedCaller(cx, NULL);
if (fp && fp->script()->strictModeCode)
*flags &= ~JSREPORT_WARNING;
else if (cx->hasStrictOption())
@ -1781,7 +1355,7 @@ TriggerOperationCallback(JSContext *cx)
*/
ThreadData *td;
#ifdef JS_THREADSAFE
JSThread *thread = cx->thread;
JSThread *thread = cx->thread();
if (!thread)
return;
td = &thread->data;
@ -1800,8 +1374,8 @@ TriggerAllOperationCallbacks(JSRuntime *rt)
} /* namespace js */
JSStackFrame *
js_GetScriptedCaller(JSContext *cx, JSStackFrame *fp)
StackFrame *
js_GetScriptedCaller(JSContext *cx, StackFrame *fp)
{
if (!fp)
fp = js_GetTopStackFrame(cx);
@ -1824,7 +1398,7 @@ js_GetCurrentBytecodePC(JSContext* cx)
#endif
{
JS_ASSERT_NOT_ON_TRACE(cx); /* for static analysis */
pc = cx->regs ? cx->regs->pc : NULL;
pc = cx->running() ? cx->regs().pc : NULL;
if (!pc)
return NULL;
imacpc = cx->fp()->maybeImacropc();
@ -1891,14 +1465,14 @@ JSContext::JSContext(JSRuntime *rt)
: hasVersionOverride(false),
runtime(rt),
compartment(NULL),
regs(NULL),
stack(thisDuringConstruction()),
busyArrays()
{}
JSContext::~JSContext()
{
#ifdef JS_THREADSAFE
JS_ASSERT(!thread);
JS_ASSERT(!thread_);
#endif
/* Free the stuff hanging off of cx. */
@ -1924,7 +1498,7 @@ void
JSContext::resetCompartment()
{
JSObject *scopeobj;
if (hasfp()) {
if (stack.running()) {
scopeobj = &fp()->scopeChain();
} else {
scopeobj = globalObject;
@ -1969,71 +1543,10 @@ JSContext::wrapPendingException()
setPendingException(v);
}
void
JSContext::pushSegmentAndFrame(js::StackSegment *newseg, JSFrameRegs &newregs)
{
JS_ASSERT(regs != &newregs);
if (hasActiveSegment())
currentSegment->suspend(regs);
newseg->setPreviousInContext(currentSegment);
currentSegment = newseg;
setCurrentRegs(&newregs);
newseg->joinContext(this, newregs.fp);
}
void
JSContext::popSegmentAndFrame()
{
JS_ASSERT_IF(regs->fp->hasCallObj(), !regs->fp->callObj().getPrivate());
JS_ASSERT_IF(regs->fp->hasArgsObj(), !regs->fp->argsObj().getPrivate());
JS_ASSERT(currentSegment->maybeContext() == this);
JS_ASSERT(currentSegment->getInitialFrame() == regs->fp);
/*
* NB: This function calls resetCompartment, which may GC, so the stack needs
* to be in a GC-able state by that point.
*/
currentSegment->leaveContext();
currentSegment = currentSegment->getPreviousInContext();
if (currentSegment) {
if (currentSegment->isSaved()) {
setCurrentRegs(NULL);
resetCompartment();
} else {
setCurrentRegs(currentSegment->getSuspendedRegs());
currentSegment->resume();
}
} else {
JS_ASSERT(regs->fp->prev() == NULL);
setCurrentRegs(NULL);
resetCompartment();
}
maybeMigrateVersionOverride();
}
void
JSContext::saveActiveSegment()
{
JS_ASSERT(hasActiveSegment());
currentSegment->save(regs);
setCurrentRegs(NULL);
resetCompartment();
}
void
JSContext::restoreSegment()
{
js::StackSegment *ccs = currentSegment;
setCurrentRegs(ccs->getSuspendedRegs());
ccs->restore();
resetCompartment();
}
JSGenerator *
JSContext::generatorFor(JSStackFrame *fp) const
JSContext::generatorFor(StackFrame *fp) const
{
JS_ASSERT(stack().contains(fp) && fp->isGeneratorFrame());
JS_ASSERT(stack.contains(fp) && fp->isGeneratorFrame());
JS_ASSERT(!fp->isFloatingGenerator());
JS_ASSERT(!genStack.empty());
@ -2049,17 +1562,6 @@ JSContext::generatorFor(JSStackFrame *fp) const
return NULL;
}
StackSegment *
StackSpace::containingSegment(const JSStackFrame *target)
{
for (StackSegment *seg = currentSegment; seg; seg = seg->getPreviousInMemory()) {
if (seg->contains(target))
return seg;
}
JS_NOT_REACHED("frame not in stack space");
return NULL;
}
JS_FRIEND_API(void)
JSRuntime::onTooMuchMalloc()
{

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,6 @@
#include "jscntxt.h"
#include "jscompartment.h"
#include "jsparse.h"
#include "jsstaticcheck.h"
#include "jsxml.h"
#include "jsregexp.h"
@ -64,7 +63,7 @@ GetGlobalForScopeChain(JSContext *cx)
*/
VOUCH_DOES_NOT_REQUIRE_STACK();
if (cx->hasfp())
if (cx->running())
return cx->fp()->scopeChain().getGlobal();
JSObject *scope = cx->globalObject;
@ -76,425 +75,6 @@ GetGlobalForScopeChain(JSContext *cx)
return scope->asGlobal();
}
}
#ifdef JS_METHODJIT
inline js::mjit::JaegerCompartment *JSContext::jaegerCompartment()
{
return compartment->jaegerCompartment;
}
#endif
inline bool
JSContext::ensureGeneratorStackSpace()
{
bool ok = genStack.reserve(genStack.length() + 1);
if (!ok)
js_ReportOutOfMemory(this);
return ok;
}
inline js::RegExpStatics *
JSContext::regExpStatics()
{
return js::RegExpStatics::extractFrom(js::GetGlobalForScopeChain(this));
}
namespace js {
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSFrameRegs *
StackSegment::getCurrentRegs() const
{
JS_ASSERT(inContext());
return isActive() ? cx->regs : getSuspendedRegs();
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSStackFrame *
StackSegment::getCurrentFrame() const
{
return getCurrentRegs()->fp;
}
JS_REQUIRES_STACK inline Value *
StackSpace::firstUnused() const
{
StackSegment *seg = currentSegment;
if (!seg) {
JS_ASSERT(invokeArgEnd == NULL);
return base;
}
if (seg->inContext()) {
Value *sp = seg->getCurrentRegs()->sp;
if (invokeArgEnd > sp) {
JS_ASSERT(invokeSegment == currentSegment);
JS_ASSERT_IF(seg->maybeContext()->hasfp(),
invokeFrame == seg->maybeContext()->fp());
return invokeArgEnd;
}
return sp;
}
JS_ASSERT(invokeArgEnd);
JS_ASSERT(invokeSegment == currentSegment);
return invokeArgEnd;
}
/* Inline so we don't need the friend API. */
JS_ALWAYS_INLINE bool
StackSpace::isCurrentAndActive(JSContext *cx) const
{
#ifdef DEBUG
JS_ASSERT_IF(cx->getCurrentSegment(),
cx->getCurrentSegment()->maybeContext() == cx);
cx->assertSegmentsInSync();
#endif
return currentSegment &&
currentSegment->isActive() &&
currentSegment == cx->getCurrentSegment();
}
STATIC_POSTCONDITION(!return || ubound(from) >= nvals)
JS_ALWAYS_INLINE bool
StackSpace::ensureSpace(JSContext *maybecx, Value *from, ptrdiff_t nvals) const
{
JS_ASSERT(from >= firstUnused());
#ifdef XP_WIN
JS_ASSERT(from <= commitEnd);
if (commitEnd - from >= nvals)
goto success;
if (end - from < nvals) {
if (maybecx)
js_ReportOutOfScriptQuota(maybecx);
return false;
}
if (!bumpCommit(from, nvals)) {
if (maybecx)
js_ReportOutOfScriptQuota(maybecx);
return false;
}
goto success;
#else
if (end - from < nvals) {
if (maybecx)
js_ReportOutOfScriptQuota(maybecx);
return false;
}
goto success;
#endif
success:
#ifdef DEBUG
memset(from, 0xde, nvals * sizeof(js::Value));
#endif
return true;
}
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;
}
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;
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE bool
StackSpace::pushInvokeArgs(JSContext *cx, uintN argc, InvokeArgsGuard *ag)
{
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;
/* Don't need to MakeRangeGCSafe: the VM stack is conservatively marked. */
/* Use invokeArgEnd to root [vp, vpend) until the frame is pushed. */
ag->prevInvokeArgEnd = invokeArgEnd;
invokeArgEnd = vpend;
#ifdef DEBUG
ag->prevInvokeSegment = invokeSegment;
invokeSegment = currentSegment;
ag->prevInvokeFrame = invokeFrame;
invokeFrame = cx->maybefp();
#endif
ag->cx = cx;
ImplicitCast<CallArgs>(*ag) = CallArgsFromVp(argc, vp);
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);
JS_ASSERT(invokeFrame == ag.cx->maybefp());
JS_ASSERT(invokeArgEnd == ag.argv() + ag.argc());
#ifdef DEBUG
invokeSegment = ag.prevInvokeSegment;
invokeFrame = ag.prevInvokeFrame;
#endif
invokeArgEnd = ag.prevInvokeArgEnd;
}
JS_ALWAYS_INLINE
InvokeArgsGuard::~InvokeArgsGuard()
{
if (JS_UNLIKELY(!pushed()))
return;
cx->stack().popInvokeArgs(*this);
}
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;
Value *dst = firstUnused;
Value *src = firstUnused - (2 + nactual);
PodCopy(dst, src, ncopy);
Debug_SetValueRangeToCrashOnTouch(src, ncopy);
return reinterpret_cast<JSStackFrame *>(firstUnused + ncopy);
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE bool
StackSpace::getInvokeFrame(JSContext *cx, const CallArgs &args,
JSFunction *fun, JSScript *script,
uint32 *flags, InvokeFrameGuard *fg) const
{
JS_ASSERT(firstUnused() == args.argv() + args.argc());
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;
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
StackSpace::pushInvokeFrame(JSContext *cx, const CallArgs &args,
InvokeFrameGuard *fg)
{
JS_ASSERT(firstUnused() == args.argv() + args.argc());
if (JS_UNLIKELY(!currentSegment->inContext())) {
cx->pushSegmentAndFrame(currentSegment, fg->regs_);
} else {
fg->prevRegs_ = cx->regs;
cx->setCurrentRegs(&fg->regs_);
}
fg->cx_ = cx;
JS_ASSERT(isCurrentAndActive(cx));
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
StackSpace::popInvokeFrame(const InvokeFrameGuard &fg)
{
JSContext *cx = fg.cx_;
JSStackFrame *fp = fg.regs_.fp;
PutActivationObjects(cx, fp);
JS_ASSERT(isCurrentAndActive(cx));
if (JS_UNLIKELY(currentSegment->getInitialFrame() == fp)) {
cx->popSegmentAndFrame();
} else {
JS_ASSERT(&fg.regs_ == cx->regs);
JS_ASSERT(fp->prev_ == fg.prevRegs_->fp);
JS_ASSERT(fp->prevpc() == fg.prevRegs_->pc);
cx->setCurrentRegs(fg.prevRegs_);
}
}
JS_ALWAYS_INLINE void
InvokeFrameGuard::pop()
{
JS_ASSERT(pushed());
cx_->stack().popInvokeFrame(*this);
cx_ = NULL;
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSStackFrame *
StackSpace::getInlineFrame(JSContext *cx, Value *sp, uintN nactual,
JSFunction *fun, JSScript *script, uint32 *flags) const
{
JS_ASSERT(isCurrentAndActive(cx));
JS_ASSERT(cx->hasActiveSegment());
JS_ASSERT(cx->regs->sp == sp);
return getCallFrame(cx, sp, nactual, fun, script, flags, EnsureSpaceCheck());
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE JSStackFrame *
StackSpace::getInlineFrameWithinLimit(JSContext *cx, Value *sp, uintN nactual,
JSFunction *fun, JSScript *script, uint32 *flags,
JSStackFrame *base, Value **limit) const
{
JS_ASSERT(isCurrentAndActive(cx));
JS_ASSERT(cx->hasActiveSegment());
JS_ASSERT(cx->regs->sp == sp);
return getCallFrame(cx, sp, nactual, fun, script, flags, LimitCheck(base, limit));
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
StackSpace::pushInlineFrame(JSContext *cx, JSScript *script, JSStackFrame *fp,
JSFrameRegs *regs)
{
JS_ASSERT(isCurrentAndActive(cx));
JS_ASSERT(cx->regs == regs && script == fp->script());
regs->fp = fp;
regs->pc = script->code;
regs->sp = fp->slots() + script->nfixed;
}
JS_REQUIRES_STACK JS_ALWAYS_INLINE void
StackSpace::popInlineFrame(JSContext *cx, JSStackFrame *prev, Value *newsp)
{
JSFrameRegs *regs = cx->regs;
JSStackFrame *fp = regs->fp;
JS_ASSERT(isCurrentAndActive(cx));
JS_ASSERT(cx->hasActiveSegment());
JS_ASSERT(fp->prev_ == prev);
JS_ASSERT(!fp->hasImacropc());
JS_ASSERT(prev->base() <= newsp && newsp <= fp->formalArgsEnd());
PutActivationObjects(cx, fp);
regs->pc = prev->pc(cx, fp);
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;
#endif
}
JS_REQUIRES_STACK inline
FrameRegsIter::FrameRegsIter(JSContext *cx)
: cx(cx)
{
curseg = cx->getCurrentSegment();
if (JS_UNLIKELY(!curseg || !curseg->isActive())) {
initSlow();
return;
}
JS_ASSERT(cx->regs->fp);
curfp = cx->regs->fp;
cursp = cx->regs->sp;
curpc = cx->regs->pc;
return;
}
inline FrameRegsIter &
FrameRegsIter::operator++()
{
JSStackFrame *fp = curfp;
JSStackFrame *prev = curfp = curfp->prev();
if (!prev)
return *this;
curpc = curfp->pc(cx, fp);
if (JS_UNLIKELY(fp == curseg->getInitialFrame())) {
incSlow(fp, prev);
return *this;
}
cursp = fp->formalArgsEnd();
return *this;
}
inline GSNCache *
GetGSNCache(JSContext *cx)
{
@ -528,7 +108,7 @@ class CompartmentChecker
public:
explicit CompartmentChecker(JSContext *cx) : context(cx), compartment(cx->compartment) {
check(cx->hasfp() ? JS_GetGlobalForScopeChain(cx) : cx->globalObject);
check(cx->running() ? JS_GetGlobalForScopeChain(cx) : cx->globalObject);
VOUCH_DOES_NOT_REQUIRE_STACK();
}
@ -613,7 +193,7 @@ class CompartmentChecker
}
}
void check(JSStackFrame *fp) {
void check(StackFrame *fp) {
check(&fp->scopeChain());
}
};
@ -811,6 +391,28 @@ CanLeaveTrace(JSContext *cx)
} /* namespace js */
#ifdef JS_METHODJIT
inline js::mjit::JaegerCompartment *JSContext::jaegerCompartment()
{
return compartment->jaegerCompartment;
}
#endif
inline bool
JSContext::ensureGeneratorStackSpace()
{
bool ok = genStack.reserve(genStack.length() + 1);
if (!ok)
js_ReportOutOfMemory(this);
return ok;
}
inline js::RegExpStatics *
JSContext::regExpStatics()
{
return js::RegExpStatics::extractFrom(js::GetGlobalForScopeChain(this));
}
inline void
JSContext::setPendingException(js::Value v) {
this->throwing = true;

View File

@ -222,7 +222,7 @@ JSCompartment::wrap(JSContext *cx, Value *vp)
* This loses us some transparency, and is generally very cheesy.
*/
JSObject *global;
if (cx->hasfp()) {
if (cx->running()) {
global = cx->fp()->scopeChain().getGlobal();
} else {
global = cx->globalObject;

View File

@ -136,6 +136,10 @@ struct TracerState
*/
struct TraceNativeStorage
{
/* Max number of stack slots/frame that may need to be restored in LeaveTree. */
static const size_t MAX_NATIVE_STACK_SLOTS = 4096;
static const size_t MAX_CALL_STACK_ENTRIES = 500;
double stack_global_buf[MAX_NATIVE_STACK_SLOTS + GLOBAL_SLOTS_BUFFER_SIZE];
FrameInfo *callstack_buf[MAX_CALL_STACK_ENTRIES];
@ -456,7 +460,7 @@ struct JS_FRIEND_API(JSCompartment) {
js::NativeIterCache nativeIterCache;
typedef js::LazilyConstructed<js::ToSourceCache> LazyToSourceCache;
typedef js::Maybe<js::ToSourceCache> LazyToSourceCache;
LazyToSourceCache toSourceCache;
JSCompartment(JSRuntime *rt);

View File

@ -73,6 +73,8 @@
#include "jsobjinlines.h"
#include "vm/Stack-inl.h"
using namespace js;
/*
@ -2106,13 +2108,13 @@ date_toJSON(JSContext *cx, uintN argc, Value *vp)
/* Step 6. */
LeaveTrace(cx);
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, 0, &args))
if (!cx->stack.pushInvokeArgs(cx, 0, &args))
return false;
args.calleev() = toISO;
args.thisv().setObject(*obj);
if (!Invoke(cx, args, 0))
if (!Invoke(cx, args))
return false;
*vp = args.rval();
return true;

View File

@ -69,11 +69,13 @@
#include "jsatominlines.h"
#include "jsdbgapiinlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsinterpinlines.h"
#include "jsscopeinlines.h"
#include "jsscriptinlines.h"
#include "vm/Stack-inl.h"
#include "jsautooplen.h"
#include "methodjit/MethodJIT.h"
@ -116,21 +118,21 @@ JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug)
namespace js {
void
ScriptDebugPrologue(JSContext *cx, JSStackFrame *fp)
ScriptDebugPrologue(JSContext *cx, StackFrame *fp)
{
if (fp->isFramePushedByExecute()) {
if (JSInterpreterHook hook = cx->debugHooks->executeHook)
fp->setHookData(hook(cx, fp, true, 0, cx->debugHooks->executeHookData));
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->debugHooks->executeHookData));
} else {
if (JSInterpreterHook hook = cx->debugHooks->callHook)
fp->setHookData(hook(cx, fp, true, 0, cx->debugHooks->callHookData));
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->debugHooks->callHookData));
}
Probes::enterJSFun(cx, fp->maybeFun(), fp->script());
}
bool
ScriptDebugEpilogue(JSContext *cx, JSStackFrame *fp, bool okArg)
ScriptDebugEpilogue(JSContext *cx, StackFrame *fp, bool okArg)
{
JSBool ok = okArg;
@ -139,10 +141,10 @@ ScriptDebugEpilogue(JSContext *cx, JSStackFrame *fp, bool okArg)
if (void *hookData = fp->maybeHookData()) {
if (fp->isFramePushedByExecute()) {
if (JSInterpreterHook hook = cx->debugHooks->executeHook)
hook(cx, fp, false, &ok, hookData);
hook(cx, Jsvalify(fp), false, &ok, hookData);
} else {
if (JSInterpreterHook hook = cx->debugHooks->callHook)
hook(cx, fp, false, &ok, hookData);
hook(cx, Jsvalify(fp), false, &ok, hookData);
}
}
@ -836,7 +838,9 @@ js_watch_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
}
{
Conditionally<AutoShapeRooter> tvr(needMethodSlotWrite, cx, needMethodSlotWrite);
Maybe<AutoShapeRooter> tvr;
if (needMethodSlotWrite)
tvr.construct(cx, needMethodSlotWrite);
/*
* Call the handler. This invalidates shape, so re-lookup the shape.
@ -1361,33 +1365,35 @@ JS_GetScriptPrincipals(JSContext *cx, JSScript *script)
JS_PUBLIC_API(JSStackFrame *)
JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp)
{
*iteratorp = (*iteratorp == NULL) ? js_GetTopStackFrame(cx) : (*iteratorp)->prev();
StackFrame *fp = Valueify(*iteratorp);
*iteratorp = Jsvalify((fp == NULL) ? js_GetTopStackFrame(cx) : fp->prev());
return *iteratorp;
}
JS_PUBLIC_API(JSScript *)
JS_GetFrameScript(JSContext *cx, JSStackFrame *fp)
{
return fp->maybeScript();
return Valueify(fp)->maybeScript();
}
JS_PUBLIC_API(jsbytecode *)
JS_GetFramePC(JSContext *cx, JSStackFrame *fp)
{
return fp->pc(cx);
return Valueify(fp)->pc(cx);
}
JS_PUBLIC_API(JSStackFrame *)
JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp)
{
return js_GetScriptedCaller(cx, fp);
return Jsvalify(js_GetScriptedCaller(cx, Valueify(fp)));
}
JS_PUBLIC_API(void *)
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp)
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fpArg)
{
StackFrame *fp = Valueify(fpArg);
if (fp->annotation() && fp->isScriptFrame()) {
JSPrincipals *principals = fp->principals(cx);
JSPrincipals *principals = fp->scopeChain().principals(cx);
if (principals && principals->globalPrivilegesEnabled(cx, principals)) {
/*
@ -1404,7 +1410,7 @@ JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp)
JS_PUBLIC_API(void)
JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation)
{
fp->setAnnotation(annotation);
Valueify(fp)->setAnnotation(annotation);
}
JS_PUBLIC_API(void *)
@ -1412,7 +1418,7 @@ JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp)
{
JSPrincipals *principals;
principals = fp->principals(cx);
principals = Valueify(fp)->scopeChain().principals(cx);
if (!principals)
return NULL;
return principals->getPrincipalArray(cx, principals);
@ -1421,34 +1427,36 @@ JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp)
JS_PUBLIC_API(JSBool)
JS_IsScriptFrame(JSContext *cx, JSStackFrame *fp)
{
return !fp->isDummyFrame();
return !Valueify(fp)->isDummyFrame();
}
/* this is deprecated, use JS_GetFrameScopeChain instead */
JS_PUBLIC_API(JSObject *)
JS_GetFrameObject(JSContext *cx, JSStackFrame *fp)
{
return &fp->scopeChain();
return &Valueify(fp)->scopeChain();
}
JS_PUBLIC_API(JSObject *)
JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp)
JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fpArg)
{
JS_ASSERT(cx->stack().contains(fp));
StackFrame *fp = Valueify(fpArg);
JS_ASSERT(cx->stack.contains(fp));
js::AutoCompartment ac(cx, &fp->scopeChain());
if (!ac.enter())
return NULL;
/* Force creation of argument and call objects if not yet created */
(void) JS_GetFrameCallObject(cx, fp);
(void) JS_GetFrameCallObject(cx, Jsvalify(fp));
return GetScopeChain(cx, fp);
}
JS_PUBLIC_API(JSObject *)
JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp)
JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fpArg)
{
JS_ASSERT(cx->stack().contains(fp));
StackFrame *fp = Valueify(fpArg);
JS_ASSERT(cx->stack.contains(fp));
if (!fp->isFunctionFrame())
return NULL;
@ -1467,8 +1475,9 @@ JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp)
}
JS_PUBLIC_API(JSBool)
JS_GetFrameThis(JSContext *cx, JSStackFrame *fp, jsval *thisv)
JS_GetFrameThis(JSContext *cx, JSStackFrame *fpArg, jsval *thisv)
{
StackFrame *fp = Valueify(fpArg);
if (fp->isDummyFrame())
return false;
@ -1485,12 +1494,13 @@ JS_GetFrameThis(JSContext *cx, JSStackFrame *fp, jsval *thisv)
JS_PUBLIC_API(JSFunction *)
JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp)
{
return fp->maybeFun();
return Valueify(fp)->maybeFun();
}
JS_PUBLIC_API(JSObject *)
JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp)
JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fpArg)
{
StackFrame *fp = Valueify(fpArg);
if (!fp->isFunctionFrame())
return NULL;
@ -1502,13 +1512,13 @@ JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp)
JS_PUBLIC_API(JSBool)
JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp)
{
return fp->isConstructing();
return Valueify(fp)->isConstructing();
}
JS_PUBLIC_API(JSObject *)
JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp)
{
return fp->maybeCallee();
return Valueify(fp)->maybeCallee();
}
JS_PUBLIC_API(JSBool)
@ -1516,7 +1526,7 @@ JS_GetValidFrameCalleeObject(JSContext *cx, JSStackFrame *fp, jsval *vp)
{
Value v;
if (!fp->getValidCalleeObject(cx, &v))
if (!Valueify(fp)->getValidCalleeObject(cx, &v))
return false;
*vp = Jsvalify(v);
return true;
@ -1525,18 +1535,19 @@ JS_GetValidFrameCalleeObject(JSContext *cx, JSStackFrame *fp, jsval *vp)
JS_PUBLIC_API(JSBool)
JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp)
{
return fp->isDebuggerFrame();
return Valueify(fp)->isDebuggerFrame();
}
JS_PUBLIC_API(jsval)
JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp)
{
return Jsvalify(fp->returnValue());
return Jsvalify(Valueify(fp)->returnValue());
}
JS_PUBLIC_API(void)
JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval)
JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fpArg, jsval rval)
{
StackFrame *fp = Valueify(fpArg);
#ifdef JS_METHODJIT
JS_ASSERT_IF(fp->isScriptFrame(), fp->script()->debugMode);
#endif
@ -1590,7 +1601,7 @@ JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
/***************************************************************************/
JS_PUBLIC_API(JSBool)
JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fpArg,
const jschar *chars, uintN length,
const char *filename, uintN lineno,
jsval *rval)
@ -1600,7 +1611,7 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
if (!CheckDebugMode(cx))
return false;
JSObject *scobj = JS_GetFrameScopeChain(cx, fp);
JSObject *scobj = JS_GetFrameScopeChain(cx, fpArg);
if (!scobj)
return false;
@ -1614,7 +1625,8 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
* we use a static level that will cause us not to attempt to optimize
* variable references made by this frame.
*/
JSScript *script = Compiler::compileScript(cx, scobj, fp, fp->principals(cx),
StackFrame *fp = Valueify(fpArg);
JSScript *script = Compiler::compileScript(cx, scobj, fp, fp->scopeChain().principals(cx),
TCF_COMPILE_N_GO, chars, length,
filename, lineno, cx->findVersion(),
NULL, UpvarCookie::UPVAR_LEVEL_LIMIT);
@ -1622,7 +1634,8 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
if (!script)
return false;
bool ok = Execute(cx, *scobj, script, fp, JSFRAME_DEBUGGER | JSFRAME_EVAL, Valueify(rval));
uintN evalFlags = StackFrame::DEBUGGER | StackFrame::EVAL;
bool ok = Execute(cx, *scobj, script, fp, evalFlags, Valueify(rval));
js_DestroyScript(cx, script);
return ok;
@ -2423,7 +2436,7 @@ jstv_Lineno(JSContext *cx, JSStackFrame *fp)
JS_FRIEND_API(void)
js::StoreTraceVisState(JSContext *cx, TraceVisState s, TraceVisExitReason r)
{
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
char *script_file = jstv_Filename(fp);
JSHashNumber hash = JS_HashString(script_file);

View File

@ -2211,7 +2211,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
}
if (cookie.isFree()) {
JSStackFrame *caller = cg->parser->callerFrame;
StackFrame *caller = cg->parser->callerFrame;
if (caller) {
JS_ASSERT(cg->compileAndGo());

View File

@ -64,10 +64,10 @@
#include "jsstaticcheck.h"
#include "jswrapper.h"
#include "jscntxtinlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "vm/Stack-inl.h"
using namespace js;
using namespace js::gc;
@ -267,7 +267,7 @@ InitExnPrivate(JSContext *cx, JSObject *exnObject, JSString *message,
JSErrorReporter older;
JSExceptionState *state;
jsid callerid;
JSStackFrame *fp, *fpstop;
StackFrame *fp, *fpstop;
size_t stackDepth, valueCount, size;
JSBool overflow;
JSExnPrivate *priv;
@ -693,7 +693,7 @@ static JSBool
Exception(JSContext *cx, uintN argc, Value *vp)
{
JSString *message, *filename;
JSStackFrame *fp;
StackFrame *fp;
/*
* ECMA ed. 3, 15.11.1 requires Error, etc., to construct even when

View File

@ -74,3 +74,9 @@ JS_UnwrapObject(JSObject *obj)
{
return obj->unwrap();
}
JS_FRIEND_API(JSObject *)
JS_GetFrameScopeChainRaw(JSStackFrame *fp)
{
return &Valueify(fp)->scopeChain();
}

View File

@ -54,6 +54,9 @@ JS_FindCompilationScope(JSContext *cx, JSObject *obj);
extern JS_FRIEND_API(JSObject *)
JS_UnwrapObject(JSObject *obj);
extern JS_FRIEND_API(JSObject *)
JS_GetFrameScopeChainRaw(JSStackFrame *fp);
JS_END_EXTERN_C
#endif /* jsfriendapi_h___ */

View File

@ -86,12 +86,12 @@
#endif
#include "jsatominlines.h"
#include "jscntxtinlines.h"
#include "jsfuninlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsscriptinlines.h"
#include "vm/Stack-inl.h"
using namespace js;
using namespace js::gc;
@ -102,7 +102,7 @@ JSObject::getThrowTypeError() const
}
JSBool
js_GetArgsValue(JSContext *cx, JSStackFrame *fp, Value *vp)
js_GetArgsValue(JSContext *cx, StackFrame *fp, Value *vp)
{
JSObject *argsobj;
@ -119,7 +119,7 @@ js_GetArgsValue(JSContext *cx, JSStackFrame *fp, Value *vp)
}
JSBool
js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, Value *vp)
js_GetArgsProperty(JSContext *cx, StackFrame *fp, jsid id, Value *vp)
{
JS_ASSERT(fp->isFunctionFrame());
@ -233,7 +233,7 @@ struct STATIC_SKIP_INFERENCE PutArg
};
JSObject *
js_GetArgsObject(JSContext *cx, JSStackFrame *fp)
js_GetArgsObject(JSContext *cx, StackFrame *fp)
{
/*
* We must be in a function activation; the function must be lightweight
@ -273,7 +273,7 @@ js_GetArgsObject(JSContext *cx, JSStackFrame *fp)
}
void
js_PutArgsObject(JSContext *cx, JSStackFrame *fp)
js_PutArgsObject(StackFrame *fp)
{
JSObject &argsobj = fp->argsObj();
if (argsobj.isNormalArguments()) {
@ -357,7 +357,7 @@ args_delProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp)
}
static JS_REQUIRES_STACK JSObject *
WrapEscapingClosure(JSContext *cx, JSStackFrame *fp, JSFunction *fun)
WrapEscapingClosure(JSContext *cx, StackFrame *fp, JSFunction *fun)
{
JS_ASSERT(fun->optimizedClosure());
JS_ASSERT(!fun->u.i.wrapper);
@ -526,7 +526,7 @@ ArgGetter(JSContext *cx, JSObject *obj, jsid id, Value *vp)
uintN arg = uintN(JSID_TO_INT(id));
if (arg < obj->getArgsInitialLength()) {
JS_ASSERT(!obj->getArgsElement(arg).isMagic(JS_ARGS_HOLE));
if (JSStackFrame *fp = (JSStackFrame *) obj->getPrivate())
if (StackFrame *fp = (StackFrame *) obj->getPrivate())
*vp = fp->canonicalActualArg(arg);
else
*vp = obj->getArgsElement(arg);
@ -575,7 +575,7 @@ ArgSetter(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
if (JSID_IS_INT(id)) {
uintN arg = uintN(JSID_TO_INT(id));
if (arg < obj->getArgsInitialLength()) {
JSStackFrame *fp = (JSStackFrame *) obj->getPrivate();
StackFrame *fp = (StackFrame *) obj->getPrivate();
if (fp) {
JSScript *script = fp->functionScript();
if (script->usesArguments)
@ -798,13 +798,13 @@ args_finalize(JSContext *cx, JSObject *obj)
* otherwise reachable. An executing generator is rooted by its invocation. To
* distinguish the two cases (which imply different access paths to the
* generator object), we use the JSFRAME_FLOATING_GENERATOR flag, which is only
* set on the JSStackFrame kept in the generator object's JSGenerator.
* set on the StackFrame kept in the generator object's JSGenerator.
*/
static inline void
MaybeMarkGenerator(JSTracer *trc, JSObject *obj)
{
#if JS_HAS_GENERATORS
JSStackFrame *fp = (JSStackFrame *) obj->getPrivate();
StackFrame *fp = (StackFrame *) obj->getPrivate();
if (fp && fp->isFloatingGenerator()) {
JSObject *genobj = js_FloatingFrameToGenerator(fp)->obj;
MarkObject(trc, *genobj, "generator object");
@ -838,7 +838,7 @@ args_trace(JSTracer *trc, JSObject *obj)
*
* The JSClass functions below collaborate to lazily reflect and synchronize
* actual argument values, argument count, and callee function object stored
* in a JSStackFrame with their corresponding property values in the frame's
* in a StackFrame with their corresponding property values in the frame's
* arguments object.
*/
Class js_ArgumentsClass = {
@ -895,7 +895,7 @@ Class StrictArgumentsClass = {
}
/*
* A Declarative Environment object stores its active JSStackFrame pointer in
* A Declarative Environment object stores its active StackFrame pointer in
* its private slot, just as Call and Arguments objects do.
*/
Class js_DeclEnvClass = {
@ -930,7 +930,7 @@ CheckForEscapingClosure(JSContext *cx, JSObject *obj, Value *vp)
if (fun->needsWrapper()) {
LeaveTrace(cx);
JSStackFrame *fp = (JSStackFrame *) obj->getPrivate();
StackFrame *fp = (StackFrame *) obj->getPrivate();
if (fp) {
JSObject *wrapper = WrapEscapingClosure(cx, fp, fun);
if (!wrapper)
@ -993,7 +993,7 @@ NewCallObject(JSContext *cx, JSScript *script, JSObject &scopeChain, JSObject *c
}
static inline JSObject *
NewDeclEnvObject(JSContext *cx, JSStackFrame *fp)
NewDeclEnvObject(JSContext *cx, StackFrame *fp)
{
JSObject *envobj = js_NewGCObject(cx, FINALIZE_OBJECT2);
if (!envobj)
@ -1011,7 +1011,7 @@ NewDeclEnvObject(JSContext *cx, JSStackFrame *fp)
namespace js {
JSObject *
CreateFunCallObject(JSContext *cx, JSStackFrame *fp)
CreateFunCallObject(JSContext *cx, StackFrame *fp)
{
JS_ASSERT(fp->isNonEvalFunctionFrame());
JS_ASSERT(!fp->hasCallObj());
@ -1048,7 +1048,7 @@ CreateFunCallObject(JSContext *cx, JSStackFrame *fp)
}
JSObject *
CreateEvalCallObject(JSContext *cx, JSStackFrame *fp)
CreateEvalCallObject(JSContext *cx, StackFrame *fp)
{
JSObject *callobj = NewCallObject(cx, fp->script(), fp->scopeChain(), NULL);
if (!callobj)
@ -1083,7 +1083,7 @@ CopyValuesToCallObject(JSObject &callobj, uintN nargs, Value *argv, uintN nvars,
}
void
js_PutCallObject(JSContext *cx, JSStackFrame *fp)
js_PutCallObject(StackFrame *fp)
{
JSObject &callobj = fp->callObj();
JS_ASSERT(callobj.getPrivate() == fp);
@ -1094,7 +1094,7 @@ js_PutCallObject(JSContext *cx, JSStackFrame *fp)
if (fp->hasArgsObj()) {
if (!fp->hasOverriddenArgs())
callobj.setCallObjArguments(ObjectValue(fp->argsObj()));
js_PutArgsObject(cx, fp);
js_PutArgsObject(fp);
}
JSScript *script = fp->script();
@ -1160,7 +1160,7 @@ js_PutCallObject(JSContext *cx, JSStackFrame *fp)
}
JSBool JS_FASTCALL
js_PutCallObjectOnTrace(JSContext *cx, JSObject *callobj, uint32 nargs, Value *argv,
js_PutCallObjectOnTrace(JSObject *callobj, uint32 nargs, Value *argv,
uint32 nvars, Value *slots)
{
JS_ASSERT(callobj->isCall());
@ -1173,7 +1173,7 @@ js_PutCallObjectOnTrace(JSContext *cx, JSObject *callobj, uint32 nargs, Value *a
return true;
}
JS_DEFINE_CALLINFO_6(extern, BOOL, js_PutCallObjectOnTrace, CONTEXT, OBJECT, UINT32, VALUEPTR,
JS_DEFINE_CALLINFO_5(extern, BOOL, js_PutCallObjectOnTrace, OBJECT, UINT32, VALUEPTR,
UINT32, VALUEPTR, 0, nanojit::ACCSET_STORE_ANY)
namespace js {
@ -1181,7 +1181,7 @@ namespace js {
static JSBool
GetCallArguments(JSContext *cx, JSObject *obj, jsid id, Value *vp)
{
JSStackFrame *fp = obj->maybeCallObjStackFrame();
StackFrame *fp = obj->maybeCallObjStackFrame();
if (fp && !fp->hasOverriddenArgs()) {
JSObject *argsobj = js_GetArgsObject(cx, fp);
if (!argsobj)
@ -1196,7 +1196,7 @@ GetCallArguments(JSContext *cx, JSObject *obj, jsid id, Value *vp)
static JSBool
SetCallArguments(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
{
if (JSStackFrame *fp = obj->maybeCallObjStackFrame())
if (StackFrame *fp = obj->maybeCallObjStackFrame())
fp->setOverriddenArgs();
obj->setCallObjArguments(*vp);
return true;
@ -1208,7 +1208,7 @@ GetCallArg(JSContext *cx, JSObject *obj, jsid id, Value *vp)
JS_ASSERT((int16) JSID_TO_INT(id) == JSID_TO_INT(id));
uintN i = (uint16) JSID_TO_INT(id);
if (JSStackFrame *fp = obj->maybeCallObjStackFrame())
if (StackFrame *fp = obj->maybeCallObjStackFrame())
*vp = fp->formalArg(i);
else
*vp = obj->callObjArg(i);
@ -1222,7 +1222,7 @@ SetCallArg(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
uintN i = (uint16) JSID_TO_INT(id);
Value *argp;
if (JSStackFrame *fp = obj->maybeCallObjStackFrame())
if (StackFrame *fp = obj->maybeCallObjStackFrame())
argp = &fp->formalArg(i);
else
argp = &obj->callObjArg(i);
@ -1261,7 +1261,7 @@ GetCallVar(JSContext *cx, JSObject *obj, jsid id, Value *vp)
JS_ASSERT((int16) JSID_TO_INT(id) == JSID_TO_INT(id));
uintN i = (uint16) JSID_TO_INT(id);
if (JSStackFrame *fp = obj->maybeCallObjStackFrame())
if (StackFrame *fp = obj->maybeCallObjStackFrame())
*vp = fp->varSlot(i);
else
*vp = obj->callObjVar(i);
@ -1302,7 +1302,7 @@ SetCallVar(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
#endif
Value *varp;
if (JSStackFrame *fp = obj->maybeCallObjStackFrame())
if (StackFrame *fp = obj->maybeCallObjStackFrame())
varp = &fp->varSlot(i);
else
varp = &obj->callObjVar(i);
@ -1379,7 +1379,7 @@ static void
call_trace(JSTracer *trc, JSObject *obj)
{
JS_ASSERT(obj->isCall());
if (JSStackFrame *fp = obj->maybeCallObjStackFrame()) {
if (StackFrame *fp = obj->maybeCallObjStackFrame()) {
/*
* FIXME: Hide copies of stack values rooted by fp from the Cycle
* Collector, which currently lacks a non-stub Unlink implementation
@ -1420,7 +1420,7 @@ JS_PUBLIC_DATA(Class) js_CallClass = {
};
bool
JSStackFrame::getValidCalleeObject(JSContext *cx, Value *vp)
StackFrame::getValidCalleeObject(JSContext *cx, Value *vp)
{
if (!isFunctionFrame()) {
vp->setUndefined();
@ -1584,7 +1584,7 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp)
JSFunction *fun = obj->getFunctionPrivate();
/* Find fun's top-most activation record. */
JSStackFrame *fp;
StackFrame *fp;
for (fp = js_GetTopStackFrame(cx);
fp && (fp->maybeFun() != fun || fp->isEvalOrDebuggerFrame());
fp = fp->prev()) {
@ -2058,7 +2058,7 @@ fun_toStringHelper(JSContext *cx, JSObject *obj, uintN indent)
return NULL;
if (!indent) {
LazilyConstructed<ToSourceCache> &lazy = cx->compartment->toSourceCache;
Maybe<ToSourceCache> &lazy = cx->compartment->toSourceCache;
if (lazy.empty()) {
lazy.construct();
@ -2137,7 +2137,7 @@ js_fun_call(JSContext *cx, uintN argc, Value *vp)
/* Allocate stack space for fval, obj, and the args. */
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, argc, &args))
if (!cx->stack.pushInvokeArgs(cx, argc, &args))
return JS_FALSE;
/* Push fval, thisv, and the args. */
@ -2145,7 +2145,7 @@ js_fun_call(JSContext *cx, uintN argc, Value *vp)
args.thisv() = thisv;
memcpy(args.argv(), argv, argc * sizeof *argv);
bool ok = Invoke(cx, args, 0);
bool ok = Invoke(cx, args);
*vp = args.rval();
return ok;
}
@ -2188,7 +2188,7 @@ js_fun_apply(JSContext *cx, uintN argc, Value *vp)
uintN n = uintN(JS_MIN(length, JS_ARGS_LENGTH_MAX));
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, n, &args))
if (!cx->stack.pushInvokeArgs(cx, n, &args))
return false;
/* Push fval, obj, and aobj's elements as args. */
@ -2200,7 +2200,7 @@ js_fun_apply(JSContext *cx, uintN argc, Value *vp)
return false;
/* Step 9. */
if (!Invoke(cx, args, 0))
if (!Invoke(cx, args))
return false;
*vp = args.rval();
return true;
@ -2301,7 +2301,7 @@ CallOrConstructBoundFunction(JSContext *cx, uintN argc, Value *vp)
const Value &boundThis = obj->getBoundFunctionThis();
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, argc + argslen, &args))
if (!cx->stack.pushInvokeArgs(cx, argc + argslen, &args))
return false;
/* 15.3.4.5.1, 15.3.4.5.2 step 4. */
@ -2314,7 +2314,7 @@ CallOrConstructBoundFunction(JSContext *cx, uintN argc, Value *vp)
if (!constructing)
args.thisv() = boundThis;
if (constructing ? !InvokeConstructor(cx, args) : !Invoke(cx, args, 0))
if (constructing ? !InvokeConstructor(cx, args) : !Invoke(cx, args))
return false;
*vp = args.rval();
@ -2961,9 +2961,7 @@ js_DefineFunction(JSContext *cx, JSObject *obj, jsid id, Native native,
return fun;
}
#if (JSV2F_CONSTRUCT & JSV2F_SEARCH_STACK)
# error "JSINVOKE_CONSTRUCT and JSV2F_SEARCH_STACK are not disjoint!"
#endif
JS_STATIC_ASSERT((JSV2F_CONSTRUCT & JSV2F_SEARCH_STACK) == 0);
JSFunction *
js_ValueToFunction(JSContext *cx, const Value *vp, uintN flags)

View File

@ -489,7 +489,7 @@ js_DefineFunction(JSContext *cx, JSObject *obj, jsid id, js::Native native,
* fact that JSINVOKE_CONSTRUCT (aka JSFRAME_CONSTRUCTING) is 1, and test that
* with #if/#error in jsfun.c.
*/
#define JSV2F_CONSTRUCT JSINVOKE_CONSTRUCT
#define JSV2F_CONSTRUCT ((uintN)js::INVOKE_CONSTRUCTOR)
#define JSV2F_SEARCH_STACK 0x10000
extern JSFunction *
@ -508,19 +508,19 @@ extern JSObject * JS_FASTCALL
js_CreateCallObjectOnTrace(JSContext *cx, JSFunction *fun, JSObject *callee, JSObject *scopeChain);
extern void
js_PutCallObject(JSContext *cx, JSStackFrame *fp);
js_PutCallObject(js::StackFrame *fp);
extern JSBool JS_FASTCALL
js_PutCallObjectOnTrace(JSContext *cx, JSObject *scopeChain, uint32 nargs,
js::Value *argv, uint32 nvars, js::Value *slots);
js_PutCallObjectOnTrace(JSObject *scopeChain, uint32 nargs, js::Value *argv,
uint32 nvars, js::Value *slots);
namespace js {
JSObject *
CreateFunCallObject(JSContext *cx, JSStackFrame *fp);
CreateFunCallObject(JSContext *cx, StackFrame *fp);
JSObject *
CreateEvalCallObject(JSContext *cx, JSStackFrame *fp);
CreateEvalCallObject(JSContext *cx, StackFrame *fp);
extern JSBool
GetCallArg(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
@ -550,10 +550,10 @@ SetCallUpvar(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp
} // namespace js
extern JSBool
js_GetArgsValue(JSContext *cx, JSStackFrame *fp, js::Value *vp);
js_GetArgsValue(JSContext *cx, js::StackFrame *fp, js::Value *vp);
extern JSBool
js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, js::Value *vp);
js_GetArgsProperty(JSContext *cx, js::StackFrame *fp, jsid id, js::Value *vp);
/*
* Get the arguments object for the given frame. If the frame is strict mode
@ -566,10 +566,10 @@ js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, js::Value *vp);
* function.
*/
extern JSObject *
js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
js_GetArgsObject(JSContext *cx, js::StackFrame *fp);
extern void
js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
js_PutArgsObject(js::StackFrame *fp);
inline bool
js_IsNamedLambda(JSFunction *fun) { return (fun->flags & JSFUN_LAMBDA) && fun->atom; }

File diff suppressed because it is too large Load Diff

View File

@ -92,6 +92,7 @@ enum FinalizeKind {
FINALIZE_OBJECT16_BACKGROUND,
FINALIZE_OBJECT_LAST = FINALIZE_OBJECT16_BACKGROUND,
FINALIZE_FUNCTION,
FINALIZE_FUNCTION_AND_OBJECT_LAST = FINALIZE_FUNCTION,
FINALIZE_SHAPE,
#if JS_HAS_XML_SUPPORT
FINALIZE_XML,
@ -102,18 +103,43 @@ enum FinalizeKind {
FINALIZE_LIMIT
};
const uintN JS_FINALIZE_OBJECT_LIMIT = 12;
const size_t ArenaShift = 12;
const size_t ArenaSize = size_t(1) << ArenaShift;
const size_t ArenaMask = ArenaSize - 1;
template <typename T> struct Arena;
/* Every arena has a header. */
struct ArenaHeader {
JSCompartment *compartment;
Arena<FreeCell> *next;
ArenaHeader *next;
FreeCell *freeList;
private:
unsigned thingKind;
public:
inline uintptr_t address() const;
inline Chunk *chunk() const;
inline ArenaBitmap *bitmap() const;
template <typename T>
Arena<T> *getArena() {
return reinterpret_cast<Arena<T> *>(address());
}
unsigned getThingKind() const {
return thingKind;
}
void setThingKind(unsigned kind) {
thingKind = kind;
}
inline MarkingDelay *getMarkingDelay() const;
#ifdef DEBUG
size_t thingSize;
bool isUsed;
bool hasFreeThings;
JS_FRIEND_API(size_t) getThingSize() const;
#endif
};
@ -143,10 +169,6 @@ struct Things<T, N, 0, 0> {
template <typename T>
struct Arena {
static const size_t ArenaSize = 4096;
ArenaHeader aheader;
/*
* Layout of an arena:
* An arena is 4K. We want it to have a header followed by a list of T
@ -171,35 +193,28 @@ struct Arena {
static const size_t SpaceAfterHeader = ArenaSize - HeaderSize;
static const size_t Filler2Size = SpaceAfterHeader % sizeof(T);
static const size_t ThingsPerArena = SpaceAfterHeader / sizeof(T);
static const size_t FirstThingOffset = HeaderSize;
static const size_t ThingsSpan = ThingsPerArena * sizeof(T);
ArenaHeader aheader;
Things<T, ThingsPerArena, Filler1Size, Filler2Size> t;
static void staticAsserts() {
/*
* Everything we store in the heap must be a multiple of the cell
* size.
*/
JS_STATIC_ASSERT(sizeof(T) % Cell::CellSize == 0);
JS_STATIC_ASSERT(offsetof(Arena<T>, t.things) % sizeof(T) == 0);
JS_STATIC_ASSERT(sizeof(Arena<T>) == ArenaSize);
}
inline Chunk *chunk() const;
inline size_t arenaIndex() const;
inline FreeCell *buildFreeList();
inline ArenaHeader *header() { return &aheader; };
inline MarkingDelay *getMarkingDelay() const;
inline ArenaBitmap *bitmap() const;
inline ConservativeGCTest mark(T *thing, JSTracer *trc);
void markDelayedChildren(JSTracer *trc);
inline bool inFreeList(void *thing) const;
inline T *getAlignedThing(const void *thing);
#ifdef DEBUG
inline bool assureThingIsAligned(void *thing);
#endif
void init(JSCompartment *compartment, unsigned thingKind);
bool finalize(JSContext *cx);
};
void FinalizeArena(Arena<FreeCell> *a);
void FinalizeArena(ArenaHeader *aheader);
/*
* Live objects are marked black. How many other additional colors are available
@ -209,7 +224,7 @@ static const uint32 BLACK = 0;
/* An arena bitmap contains enough mark bits for all the cells in an arena. */
struct ArenaBitmap {
static const size_t BitCount = Arena<FreeCell>::ArenaSize / Cell::CellSize;
static const size_t BitCount = ArenaSize / Cell::CellSize;
static const size_t BitWords = BitCount / JS_BITS_PER_WORD;
uintptr_t bitmap[BitWords];
@ -258,100 +273,76 @@ struct ArenaBitmap {
};
/* Ensure that bitmap covers the whole arena. */
JS_STATIC_ASSERT(Arena<FreeCell>::ArenaSize % Cell::CellSize == 0);
JS_STATIC_ASSERT(ArenaSize % Cell::CellSize == 0);
JS_STATIC_ASSERT(ArenaBitmap::BitCount % JS_BITS_PER_WORD == 0);
/* Marking delay is used to resume marking later when recursive marking uses too much stack. */
/*
* When recursive marking uses too much stack the marking is delayed and
* the corresponding arenas are put into a stack using a linked via the
* following per arena structure.
*/
struct MarkingDelay {
Arena<Cell> *link;
uintptr_t unmarkedChildren;
jsuword start;
ArenaHeader *link;
void init()
{
link = NULL;
unmarkedChildren = 0;
}
/*
* To separate arenas without things to mark later from the arena at the
* marked delay stack bottom we use for the latter a special sentinel
* value. We set it to the header for the second arena in the chunk
* starting the 0 address.
*/
static ArenaHeader *stackBottom() {
return reinterpret_cast<ArenaHeader *>(ArenaSize);
}
};
struct EmptyArenaLists {
/* Arenas with no internal freelist prepared. */
Arena<FreeCell> *cellFreeList;
ArenaHeader *cellFreeList;
/* Arenas with internal freelists prepared for a given finalize kind. */
Arena<FreeCell> *freeLists[FINALIZE_LIMIT];
ArenaHeader *freeLists[FINALIZE_LIMIT];
void init() {
PodZero(this);
}
Arena<FreeCell> *getOtherArena() {
Arena<FreeCell> *arena = cellFreeList;
if (arena) {
cellFreeList = arena->header()->next;
return arena;
ArenaHeader *getOtherArena() {
ArenaHeader *aheader = cellFreeList;
if (aheader) {
cellFreeList = aheader->next;
return aheader;
}
for (int i = 0; i < FINALIZE_LIMIT; i++) {
if ((arena = (Arena<FreeCell> *) freeLists[i])) {
freeLists[i] = freeLists[i]->header()->next;
return arena;
aheader = freeLists[i];
if (aheader) {
freeLists[i] = aheader->next;
return aheader;
}
}
JS_NOT_REACHED("No arena");
return NULL;
}
template <typename T>
inline Arena<T> *getTypedFreeList(unsigned thingKind);
ArenaHeader *getTypedFreeList(unsigned thingKind) {
JS_ASSERT(thingKind < FINALIZE_LIMIT);
ArenaHeader *aheader = freeLists[thingKind];
if (aheader)
freeLists[thingKind] = aheader->next;
return aheader;
}
template <typename T>
inline Arena<T> *getNext(JSCompartment *comp, unsigned thingKind);
template <typename T>
inline void insert(Arena<T> *arena);
void insert(ArenaHeader *aheader) {
unsigned thingKind = aheader->getThingKind();
aheader->next = freeLists[thingKind];
freeLists[thingKind] = aheader;
}
};
template <typename T>
inline Arena<T> *
EmptyArenaLists::getTypedFreeList(unsigned thingKind) {
JS_ASSERT(thingKind < FINALIZE_LIMIT);
Arena<T> *arena = (Arena<T>*) freeLists[thingKind];
if (arena) {
freeLists[thingKind] = freeLists[thingKind]->header()->next;
return arena;
}
return NULL;
}
template<typename T>
inline Arena<T> *
EmptyArenaLists::getNext(JSCompartment *comp, unsigned thingKind) {
Arena<T> *arena = getTypedFreeList<T>(thingKind);
if (arena) {
JS_ASSERT(arena->header()->isUsed == false);
JS_ASSERT(arena->header()->thingSize == sizeof(T));
#ifdef DEBUG
arena->header()->isUsed = true;
#endif
arena->header()->thingKind = thingKind;
arena->header()->compartment = comp;
return arena;
}
arena = (Arena<T> *)getOtherArena();
JS_ASSERT(arena->header()->isUsed == false);
arena->init(comp, thingKind);
return arena;
}
template <typename T>
inline void
EmptyArenaLists::insert(Arena<T> *arena) {
unsigned thingKind = arena->header()->thingKind;
JS_ASSERT(thingKind < FINALIZE_LIMIT);
arena->header()->next = freeLists[thingKind];
freeLists[thingKind] = (Arena<FreeCell> *) arena;
}
/* The chunk header (located at the end of the chunk to preserve arena alignment). */
struct ChunkInfo {
Chunk *link;
@ -366,7 +357,7 @@ struct ChunkInfo {
/* Chunks contain arenas and associated data structures (mark bitmap, delayed marking state). */
struct Chunk {
static const size_t BytesPerArena = sizeof(Arena<FreeCell>) +
static const size_t BytesPerArena = ArenaSize +
sizeof(ArenaBitmap) +
sizeof(MarkingDelay);
@ -378,6 +369,21 @@ struct Chunk {
ChunkInfo info;
static Chunk *fromAddress(uintptr_t addr) {
addr &= ~GC_CHUNK_MASK;
return reinterpret_cast<Chunk *>(addr);
}
static bool withinArenasRange(uintptr_t addr) {
uintptr_t offset = addr & GC_CHUNK_MASK;
return offset < ArenasPerChunk * ArenaSize;
}
static size_t arenaIndex(uintptr_t addr) {
JS_ASSERT(withinArenasRange(addr));
return (addr & GC_CHUNK_MASK) >> ArenaShift;
}
void clearMarkBitmap();
bool init(JSRuntime *rt);
@ -386,30 +392,37 @@ struct Chunk {
bool withinArenasRange(Cell *cell);
template <typename T>
Arena<T> *allocateArena(JSContext *cx, unsigned thingKind);
ArenaHeader *allocateArena(JSContext *cx, unsigned thingKind);
template <typename T>
void releaseArena(Arena<T> *a);
void releaseArena(ArenaHeader *aheader);
JSRuntime *getRuntime();
};
JS_STATIC_ASSERT(sizeof(Chunk) <= GC_CHUNK_SIZE);
JS_STATIC_ASSERT(sizeof(Chunk) + Chunk::BytesPerArena > GC_CHUNK_SIZE);
Arena<Cell> *
Cell::arena() const
inline uintptr_t
Cell::address() const
{
uintptr_t addr = uintptr_t(this);
JS_ASSERT(addr % sizeof(FreeCell) == 0);
addr &= ~(Arena<FreeCell>::ArenaSize - 1);
return reinterpret_cast<Arena<Cell> *>(addr);
JS_ASSERT(addr % Cell::CellSize == 0);
JS_ASSERT(Chunk::withinArenasRange(addr));
return addr;
}
inline ArenaHeader *
Cell::arenaHeader() const
{
uintptr_t addr = address();
addr &= ~ArenaMask;
return reinterpret_cast<ArenaHeader *>(addr);
}
Chunk *
Cell::chunk() const
{
uintptr_t addr = uintptr_t(this);
JS_ASSERT(addr % sizeof(FreeCell) == 0);
JS_ASSERT(addr % Cell::CellSize == 0);
addr &= ~(GC_CHUNK_SIZE - 1);
return reinterpret_cast<Chunk *>(addr);
}
@ -417,70 +430,60 @@ Cell::chunk() const
ArenaBitmap *
Cell::bitmap() const
{
return &chunk()->bitmaps[arena()->arenaIndex()];
return &chunk()->bitmaps[Chunk::arenaIndex(address())];
}
STATIC_POSTCONDITION_ASSUME(return < ArenaBitmap::BitCount)
size_t
Cell::cellIndex() const
{
return this->asFreeCell() - arena()->t.things[0].asFreeCell();
}
template <typename T>
Chunk *
Arena<T>::chunk() const
{
uintptr_t addr = uintptr_t(this);
JS_ASSERT(addr % sizeof(FreeCell) == 0);
addr &= ~(GC_CHUNK_SIZE - 1);
return reinterpret_cast<Chunk *>(addr);
}
template <typename T>
size_t
Arena<T>::arenaIndex() const
{
return reinterpret_cast<const Arena<FreeCell> *>(this) - chunk()->arenas;
}
template <typename T>
MarkingDelay *
Arena<T>::getMarkingDelay() const
{
return &chunk()->markingDelay[arenaIndex()];
}
template <typename T>
ArenaBitmap *
Arena<T>::bitmap() const
{
return &chunk()->bitmaps[arenaIndex()];
}
template <typename T>
inline T *
Arena<T>::getAlignedThing(const void *thing)
{
jsuword start = reinterpret_cast<jsuword>(&t.things[0]);
jsuword offset = reinterpret_cast<jsuword>(thing) - start;
offset -= offset % sizeof(T);
return reinterpret_cast<T *>(start + offset);
uintptr_t addr = address();
return (addr & ArenaMask) >> Cell::CellShift;
}
#ifdef DEBUG
template <typename T>
inline bool
Arena<T>::assureThingIsAligned(void *thing)
Cell::isAligned() const
{
return (getAlignedThing(thing) == thing);
uintptr_t offset = address() & ArenaMask;
return offset % arenaHeader()->getThingSize() == 0;
}
#endif
inline uintptr_t
ArenaHeader::address() const
{
uintptr_t addr = reinterpret_cast<uintptr_t>(this);
JS_ASSERT(!(addr & ArenaMask));
JS_ASSERT(Chunk::withinArenasRange(addr));
return addr;
}
inline Chunk *
ArenaHeader::chunk() const
{
return Chunk::fromAddress(address());
}
inline ArenaBitmap *
ArenaHeader::bitmap() const
{
return &chunk()->bitmaps[Chunk::arenaIndex(address())];
}
inline MarkingDelay *
ArenaHeader::getMarkingDelay() const
{
return &chunk()->markingDelay[Chunk::arenaIndex(address())];
}
static void
AssertValidColor(const void *thing, uint32 color)
{
JS_ASSERT_IF(color, color < reinterpret_cast<const js::gc::FreeCell *>(thing)->arena()->header()->thingSize / sizeof(FreeCell));
#ifdef DEBUG
ArenaHeader *aheader = reinterpret_cast<const js::gc::Cell *>(thing)->arenaHeader();
JS_ASSERT_IF(color, color < aheader->getThingSize() / Cell::CellSize);
#endif
}
inline bool
@ -508,15 +511,7 @@ Cell::unmark(uint32 color) const
JSCompartment *
Cell::compartment() const
{
return arena()->header()->compartment;
}
template <typename T>
static inline
Arena<T> *
GetArena(Cell *cell)
{
return reinterpret_cast<Arena<T> *>(cell->arena());
return arenaHeader()->compartment;
}
#define JSTRACE_XML 3
@ -580,15 +575,10 @@ GetGCThingRuntime(void *thing)
return reinterpret_cast<FreeCell *>(thing)->chunk()->info.runtime;
}
#ifdef DEBUG
extern bool
checkArenaListsForThing(JSCompartment *comp, jsuword thing);
#endif
/* The arenas in a list have uniform kind. */
struct ArenaList {
Arena<FreeCell> *head; /* list start */
Arena<FreeCell> *cursor; /* arena with free things */
ArenaHeader *head; /* list start */
ArenaHeader *cursor; /* arena with free things */
volatile bool hasToBeFinalized;
inline void init() {
@ -597,47 +587,35 @@ struct ArenaList {
hasToBeFinalized = false;
}
inline Arena<FreeCell> *getNextWithFreeList(JSContext *cx) {
inline ArenaHeader *getNextWithFreeList() {
JS_ASSERT(!hasToBeFinalized);
Arena<FreeCell> *a;
while (cursor != NULL) {
ArenaHeader *aheader = cursor->header();
a = cursor;
while (cursor) {
ArenaHeader *aheader = cursor;
cursor = aheader->next;
if (aheader->freeList)
return a;
return aheader;
}
return NULL;
}
#ifdef DEBUG
template <typename T>
bool arenasContainThing(void *thing) {
for (Arena<T> *a = (Arena<T> *) head; a; a = (Arena<T> *) a->header()->next) {
JS_ASSERT(a->header()->isUsed);
if (thing >= &a->t.things[0] && thing < &a->t.things[a->ThingsPerArena])
return true;
}
return false;
}
bool markedThingsInArenaList() {
for (Arena<FreeCell> *a = (Arena<FreeCell> *) head; a; a = (Arena<FreeCell> *) a->header()->next) {
if (!a->bitmap()->noBitsSet())
for (ArenaHeader *aheader = head; aheader; aheader = aheader->next) {
if (!aheader->bitmap()->noBitsSet())
return true;
}
return false;
}
#endif
inline void insert(Arena<FreeCell> *a) {
a->header()->next = head;
head = a;
inline void insert(ArenaHeader *aheader) {
aheader->next = head;
head = aheader;
}
void releaseAll() {
void releaseAll(unsigned thingKind) {
while (head) {
Arena<FreeCell> *next = head->header()->next;
ArenaHeader *next = head->next;
head->chunk()->releaseArena(head);
head = next;
}
@ -646,7 +624,7 @@ struct ArenaList {
}
inline bool isEmpty() const {
return (head == NULL);
return !head;
}
};
@ -664,17 +642,12 @@ struct FreeLists {
} else {
finalizables[kind] = NULL;
}
#ifdef DEBUG
if (top && !top->link)
top->arena()->header()->hasFreeThings = false;
#endif
}
return top;
}
template <typename T>
inline void populate(Arena<T> *a, uint32 thingKind) {
finalizables[thingKind] = &a->header()->freeList;
void populate(ArenaHeader *aheader, uint32 thingKind) {
finalizables[thingKind] = &aheader->freeList;
}
#ifdef DEBUG
@ -744,9 +717,7 @@ CheckGCFreeListLink(js::gc::FreeCell *cell)
* The GC things on the free lists come from one arena and the things on
* the free list are linked in ascending address order.
*/
JS_ASSERT_IF(cell->link,
cell->arena() ==
cell->link->arena());
JS_ASSERT_IF(cell->link, cell->arenaHeader() == cell->link->arenaHeader());
JS_ASSERT_IF(cell->link, cell < cell->link);
}
@ -821,7 +792,7 @@ extern JS_FRIEND_API(bool)
js_GCThingIsMarked(void *thing, uintN color);
extern void
js_TraceStackFrame(JSTracer *trc, JSStackFrame *fp);
js_TraceStackFrame(JSTracer *trc, js::StackFrame *fp);
namespace js {
@ -885,7 +856,7 @@ extern void
js_DestroyScriptsToGC(JSContext *cx, JSCompartment *comp);
extern void
FinalizeArenaList(JSContext *cx, js::gc::ArenaList *arenaList, js::gc::Arena<js::gc::FreeCell> *head);
FinalizeArenaList(JSContext *cx, js::gc::ArenaList *arenaList, js::gc::ArenaHeader *head);
namespace js {
@ -914,15 +885,18 @@ class GCHelperThread {
Vector<void **, 16, js::SystemAllocPolicy> freeVector;
void **freeCursor;
void **freeCursorEnd;
Vector<void **, 16, js::SystemAllocPolicy> finalizeVector;
void **finalizeCursor;
void **finalizeCursorEnd;
struct FinalizeListAndHead {
js::gc::ArenaList *list;
js::gc::ArenaHeader *head;
};
Vector<FinalizeListAndHead, 64, js::SystemAllocPolicy> finalizeVector;
JS_FRIEND_API(void)
replenishAndFreeLater(void *ptr);
void replenishAndFinalizeLater(js::gc::ArenaList *list);
static void freeElementsAndArray(void **array, void **end) {
JS_ASSERT(array <= end);
for (void **p = array; p != end; ++p)
@ -930,17 +904,6 @@ class GCHelperThread {
js::Foreground::free_(array);
}
void finalizeElementsAndArray(void **array, void **end) {
JS_ASSERT(array <= end);
for (void **p = array; p != end; p += 2) {
js::gc::ArenaList *list = (js::gc::ArenaList *)*p;
js::gc::Arena<js::gc::FreeCell> *head = (js::gc::Arena<js::gc::FreeCell> *)*(p+1);
FinalizeArenaList(cx, list, head);
}
js::Foreground::free_(array);
}
static void threadMain(void* arg);
void threadLoop(JSRuntime *rt);
@ -954,8 +917,6 @@ class GCHelperThread {
shutdown(false),
freeCursor(NULL),
freeCursorEnd(NULL),
finalizeCursor(NULL),
finalizeCursorEnd(NULL),
sweeping(false) { }
volatile bool sweeping;
@ -976,19 +937,16 @@ class GCHelperThread {
replenishAndFreeLater(ptr);
}
void finalizeLater(js::gc::ArenaList *list) {
bool finalizeLater(js::gc::ArenaList *list) {
JS_ASSERT(!sweeping);
JS_ASSERT(!list->hasToBeFinalized);
if (!list->head)
return;
return true;
FinalizeListAndHead f = {list, list->head};
if (!finalizeVector.append(f))
return false;
list->hasToBeFinalized = true;
JS_ASSERT(!sweeping);
if (finalizeCursor + 1 < finalizeCursorEnd) {
*finalizeCursor++ = list;
*finalizeCursor++ = list->head;
} else {
replenishAndFinalizeLater(list);
}
return true;
}
void setContext(JSContext *context) { cx = context; }
@ -1119,9 +1077,9 @@ struct GCMarker : public JSTracer {
public:
/* See comments before delayMarkingChildren is jsgc.cpp. */
js::gc::Arena<js::gc::Cell> *unmarkedArenaStackTop;
js::gc::ArenaHeader *unmarkedArenaStackTop;
#ifdef DEBUG
size_t markLaterCount;
size_t markLaterArenas;
#endif
#if defined(JS_DUMP_CONSERVATIVE_GC_ROOTS) || defined(JS_GCMETER)
@ -1129,8 +1087,7 @@ struct GCMarker : public JSTracer {
#endif
#ifdef JS_DUMP_CONSERVATIVE_GC_ROOTS
struct ConservativeRoot { void *thing; uint32 thingKind; };
Vector<ConservativeRoot, 0, SystemAllocPolicy> conservativeRoots;
Vector<void *, 0, SystemAllocPolicy> conservativeRoots;
const char *conservativeDumpFileName;
void dumpConservativeRoots();

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -114,7 +114,7 @@ GetGCThingTraceKind(const void *thing)
if (JSAtom::isStatic(thing))
return JSTRACE_STRING;
const Cell *cell = reinterpret_cast<const Cell *>(thing);
return GetFinalizableTraceKind(cell->arena()->header()->thingKind);
return GetFinalizableTraceKind(cell->arenaHeader()->getThingKind());
}
/* Capacity for slotsToThingKind */

View File

@ -77,14 +77,17 @@ Mark(JSTracer *trc, T *thing)
JS_ASSERT(JS_IS_VALID_TRACE_KIND(GetGCThingTraceKind(thing)));
JS_ASSERT(trc->debugPrinter || trc->debugPrintArg);
/* Per-Compartment GC only with GCMarker and no custom JSTracer */
JS_ASSERT_IF(trc->context->runtime->gcCurrentCompartment, IS_GC_MARKING_TRACER(trc));
JS_ASSERT(!JSAtom::isStatic(thing));
JS_ASSERT(thing->asFreeCell()->isAligned());
JSRuntime *rt = trc->context->runtime;
JS_ASSERT(thing->arena()->header()->compartment);
JS_ASSERT(thing->arena()->header()->compartment->rt == rt);
JS_ASSERT(thing->arenaHeader()->compartment);
JS_ASSERT(thing->arenaHeader()->compartment->rt == rt);
/* Don't mark things outside a compartment if we are in a per-compartment GC */
/*
* Don't mark things outside a compartment if we are in a per-compartment
* GC.
*/
if (!rt->gcCurrentCompartment || thing->compartment() == rt->gcCurrentCompartment) {
if (IS_GC_MARKING_TRACER(trc))
PushMarkStack(static_cast<GCMarker *>(trc), thing);
@ -104,7 +107,6 @@ MarkString(JSTracer *trc, JSString *str)
JS_ASSERT(str);
if (str->isStaticAtom())
return;
JS_ASSERT(GetArena<JSString>((Cell *)str)->assureThingIsAligned((JSString *)str));
Mark(trc, str);
}
@ -122,13 +124,6 @@ MarkObject(JSTracer *trc, JSObject &obj, const char *name)
JS_ASSERT(trc);
JS_ASSERT(&obj);
JS_SET_TRACING_NAME(trc, name);
JS_ASSERT(GetArena<JSObject>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots2>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots4>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots8>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots12>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots16>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSFunction>((Cell *)&obj)->assureThingIsAligned(&obj));
Mark(trc, &obj);
}
@ -139,13 +134,6 @@ MarkObjectWithPrinter(JSTracer *trc, JSObject &obj, JSTraceNamePrinter printer,
JS_ASSERT(trc);
JS_ASSERT(&obj);
JS_SET_TRACING_DETAILS(trc, printer, arg, index);
JS_ASSERT(GetArena<JSObject>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots2>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots4>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots8>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots12>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSObject_Slots16>((Cell *)&obj)->assureThingIsAligned(&obj) ||
GetArena<JSFunction>((Cell *)&obj)->assureThingIsAligned(&obj));
Mark(trc, &obj);
}
@ -155,19 +143,19 @@ MarkShape(JSTracer *trc, const Shape *shape, const char *name)
JS_ASSERT(trc);
JS_ASSERT(shape);
JS_SET_TRACING_NAME(trc, name);
JS_ASSERT(GetArena<Shape>((Cell *)shape)->assureThingIsAligned((void *)shape));
Mark(trc, shape);
}
#if JS_HAS_XML_SUPPORT
void
MarkXML(JSTracer *trc, JSXML *xml, const char *name)
{
JS_ASSERT(trc);
JS_ASSERT(xml);
JS_SET_TRACING_NAME(trc, name);
JS_ASSERT(GetArena<JSXML>(xml)->assureThingIsAligned(xml));
Mark(trc, xml);
}
#endif
void
PushMarkStack(GCMarker *gcmarker, JSXML *thing)

View File

@ -44,6 +44,8 @@
#include "jsbuiltins.h"
#include "jscompartment.h"
#include "jsgcinlines.h"
using namespace js;
using namespace js::gc;
@ -72,7 +74,7 @@ ConservativeGCStats::dump(FILE *fp)
fprintf(fp, " excluded, wrong tag: %lu\n", ULSTAT(counter[CGCT_WRONGTAG]));
fprintf(fp, " excluded, not live: %lu\n", ULSTAT(counter[CGCT_NOTLIVE]));
fprintf(fp, " valid GC things: %lu\n", ULSTAT(counter[CGCT_VALID]));
fprintf(fp, " valid but not aligned: %lu\n", ULSTAT(counter[CGCT_VALIDWITHOFFSET]));
fprintf(fp, " valid but not aligned: %lu\n", ULSTAT(unaligned));
#undef ULSTAT
}
#endif
@ -143,49 +145,6 @@ GetSizeAndThings(size_t &thingSize, size_t &thingsPerArena)
thingsPerArena = Arena<T>::ThingsPerArena;
}
#if defined JS_DUMP_CONSERVATIVE_GC_ROOTS
void *
GetAlignedThing(void *thing, int thingKind)
{
Cell *cell = (Cell *)thing;
switch (thingKind) {
case FINALIZE_OBJECT0:
case FINALIZE_OBJECT0_BACKGROUND:
return (void *)GetArena<JSObject>(cell)->getAlignedThing(thing);
case FINALIZE_OBJECT2:
case FINALIZE_OBJECT2_BACKGROUND:
return (void *)GetArena<JSObject_Slots2>(cell)->getAlignedThing(thing);
case FINALIZE_OBJECT4:
case FINALIZE_OBJECT4_BACKGROUND:
return (void *)GetArena<JSObject_Slots4>(cell)->getAlignedThing(thing);
case FINALIZE_OBJECT8:
case FINALIZE_OBJECT8_BACKGROUND:
return (void *)GetArena<JSObject_Slots8>(cell)->getAlignedThing(thing);
case FINALIZE_OBJECT12:
case FINALIZE_OBJECT12_BACKGROUND:
return (void *)GetArena<JSObject_Slots12>(cell)->getAlignedThing(thing);
case FINALIZE_OBJECT16:
case FINALIZE_OBJECT16_BACKGROUND:
return (void *)GetArena<JSObject_Slots16>(cell)->getAlignedThing(thing);
case FINALIZE_STRING:
return (void *)GetArena<JSString>(cell)->getAlignedThing(thing);
case FINALIZE_EXTERNAL_STRING:
return (void *)GetArena<JSExternalString>(cell)->getAlignedThing(thing);
case FINALIZE_SHORT_STRING:
return (void *)GetArena<JSShortString>(cell)->getAlignedThing(thing);
case FINALIZE_FUNCTION:
return (void *)GetArena<JSFunction>(cell)->getAlignedThing(thing);
#if JS_HAS_XML_SUPPORT
case FINALIZE_XML:
return (void *)GetArena<JSXML>(cell)->getAlignedThing(thing);
#endif
default:
JS_NOT_REACHED("wrong kind");
return NULL;
}
}
#endif
void GetSizeAndThingsPerArena(int thingKind, size_t &thingSize, size_t &thingsPerArena)
{
switch (thingKind) {
@ -366,16 +325,16 @@ GCMarker::dumpConservativeRoots()
conservativeStats.dump(fp);
for (ConservativeRoot *i = conservativeRoots.begin();
i != conservativeRoots.end();
++i) {
fprintf(fp, " %p: ", i->thing);
switch (GetFinalizableTraceKind(i->thingKind)) {
for (void **thingp = conservativeRoots.begin(); thingp != conservativeRoots.end(); ++thingp) {
void *thing = thingp;
fprintf(fp, " %p: ", thing);
switch (GetGCThingTraceKind(thing)) {
default:
JS_NOT_REACHED("Unknown trace kind");
case JSTRACE_OBJECT: {
JSObject *obj = (JSObject *) i->thing;
JSObject *obj = (JSObject *) thing;
fprintf(fp, "object %s", obj->getClass()->name);
break;
}
@ -384,7 +343,7 @@ GCMarker::dumpConservativeRoots()
break;
}
case JSTRACE_STRING: {
JSString *str = (JSString *) i->thing;
JSString *str = (JSString *) thing;
if (str->isLinear()) {
char buf[50];
PutEscapedString(buf, sizeof buf, &str->asLinear(), '"');
@ -396,7 +355,7 @@ GCMarker::dumpConservativeRoots()
}
# if JS_HAS_XML_SUPPORT
case JSTRACE_XML: {
JSXML *xml = (JSXML *) i->thing;
JSXML *xml = (JSXML *) thing;
fprintf(fp, "xml %u", (unsigned)xml->xml_class);
break;
}

View File

@ -63,7 +63,6 @@ namespace gc {
*/
enum ConservativeGCTest {
CGCT_VALID,
CGCT_VALIDWITHOFFSET, /* points within an object */
CGCT_LOWBITSET, /* excluded because one of the low bits was set */
CGCT_NOTARENA, /* not within arena range in a chunk */
CGCT_NOTCHUNK, /* not within a valid chunk */
@ -75,7 +74,9 @@ enum ConservativeGCTest {
struct ConservativeGCStats {
uint32 counter[gc::CGCT_END]; /* ConservativeGCTest classification
counters */
counters */
uint32 unaligned; /* number of valid but not aligned on
thing start pointers */
void add(const ConservativeGCStats &another) {
for (size_t i = 0; i != JS_ARRAY_LENGTH(counter); ++i)
@ -129,10 +130,6 @@ UpdateCompartmentStats(JSCompartment *comp, unsigned thingKind, uint32 nlivearen
uint32 nkilledArenas, uint32 nthings);
#endif /* JS_GCMETER */
#if defined JS_DUMP_CONSERVATIVE_GC_ROOTS
void *GetAlignedThing(void *thing, int thingKind);
#endif
} //gc
#ifdef MOZ_GCTIMER

View File

@ -796,6 +796,8 @@ struct PointerHasher
template <class T>
struct DefaultHasher<T *>: PointerHasher<T *, tl::FloorLog2<sizeof(void *)>::result> { };
/* Looking for a hasher for jsid? Try the DefaultHasher<jsid> in jsatom.h. */
/*
* JS-friendly, STL-like container providing a hash-based map from keys to
* values. In particular, HashMap calls constructors and destructors of all

File diff suppressed because it is too large Load Diff

View File

@ -45,807 +45,19 @@
*/
#include "jsprvtd.h"
#include "jspubtd.h"
#include "jsfun.h"
#include "jsopcode.h"
#include "jsscript.h"
#include "jsvalue.h"
struct JSFrameRegs
{
STATIC_SKIP_INFERENCE
js::Value *sp; /* stack pointer */
jsbytecode *pc; /* program counter */
JSStackFrame *fp; /* active frame */
};
/* Flags to toggle js::Interpret() execution. */
enum JSInterpMode
{
JSINTERP_NORMAL = 0, /* interpreter is running normally */
JSINTERP_RECORD = 1, /* interpreter has been started to record/run traces */
JSINTERP_SAFEPOINT = 2, /* interpreter should leave on a method JIT safe point */
JSINTERP_PROFILE = 3 /* interpreter should profile a loop */
};
/* Flags used in JSStackFrame::flags_ */
enum JSFrameFlags
{
/* Primary frame type */
JSFRAME_GLOBAL = 0x1, /* frame pushed for a global script */
JSFRAME_FUNCTION = 0x2, /* frame pushed for a scripted call */
JSFRAME_DUMMY = 0x4, /* frame pushed for bookkeeping */
/* Frame subtypes */
JSFRAME_EVAL = 0x8, /* frame pushed for eval() or debugger eval */
JSFRAME_DEBUGGER = 0x10, /* frame pushed for debugger eval */
JSFRAME_GENERATOR = 0x20, /* frame is associated with a generator */
JSFRAME_FLOATING_GENERATOR = 0x40, /* frame is is in generator obj, not on stack */
JSFRAME_CONSTRUCTING = 0x80, /* frame is for a constructor invocation */
/* Temporary frame states */
JSFRAME_YIELDING = 0x200, /* js::Interpret dispatched JSOP_YIELD */
JSFRAME_FINISHED_IN_INTERP = 0x400, /* set if frame finished in Interpret() */
/* Concerning function arguments */
JSFRAME_OVERRIDE_ARGS = 0x1000, /* overridden arguments local variable */
JSFRAME_OVERFLOW_ARGS = 0x2000, /* numActualArgs > numFormalArgs */
JSFRAME_UNDERFLOW_ARGS = 0x4000, /* numActualArgs < numFormalArgs */
/* Lazy frame initialization */
JSFRAME_HAS_IMACRO_PC = 0x8000, /* frame has imacpc value available */
JSFRAME_HAS_CALL_OBJ = 0x10000, /* frame has a callobj reachable from scopeChain_ */
JSFRAME_HAS_ARGS_OBJ = 0x20000, /* frame has an argsobj in JSStackFrame::args */
JSFRAME_HAS_HOOK_DATA = 0x40000, /* frame has hookData_ set */
JSFRAME_HAS_ANNOTATION = 0x80000, /* frame has annotation_ set */
JSFRAME_HAS_RVAL = 0x100000, /* frame has rval_ set */
JSFRAME_HAS_SCOPECHAIN = 0x200000, /* frame has scopeChain_ set */
JSFRAME_HAS_PREVPC = 0x400000 /* frame has prevpc_ set */
};
namespace js { namespace mjit { struct JITScript; } }
/*
* A stack frame is a part of a stack segment (see js::StackSegment) which is
* on the per-thread VM stack (see js::StackSpace).
*/
struct JSStackFrame
{
private:
mutable uint32 flags_; /* bits described by JSFrameFlags */
union { /* describes what code is executing in a */
JSScript *script; /* global frame */
JSFunction *fun; /* function frame, pre GetScopeChain */
} exec;
union { /* describes the arguments of a function */
uintN nactual; /* pre GetArgumentsObject */
JSObject *obj; /* post GetArgumentsObject */
JSScript *script; /* eval has no args, but needs a script */
} args;
mutable JSObject *scopeChain_; /* current scope chain */
JSStackFrame *prev_; /* previous cx->regs->fp */
void *ncode_; /* return address for method JIT */
/* Lazily initialized */
js::Value rval_; /* return value of the frame */
jsbytecode *prevpc_; /* pc of previous frame*/
jsbytecode *imacropc_; /* pc of macro caller */
void *hookData_; /* closure returned by call hook */
void *annotation_; /* perhaps remove with bug 546848 */
friend class js::StackSpace;
friend class js::FrameRegsIter;
friend struct JSContext;
inline void initPrev(JSContext *cx);
public:
/*
* Stack frame sort (see JSStackFrame comment above)
*
* A stack frame may have one of three types, which determines which
* members of the frame may be accessed and other invariants:
*
* global frame: execution of global code or an eval in global code
* function frame: execution of function code or an eval in a function
* dummy frame: bookkeeping frame (read: hack)
*
*/
bool isFunctionFrame() const {
return !!(flags_ & JSFRAME_FUNCTION);
}
bool isGlobalFrame() const {
return !!(flags_ & JSFRAME_GLOBAL);
}
bool isDummyFrame() const {
return !!(flags_ & JSFRAME_DUMMY);
}
bool isScriptFrame() const {
bool retval = !!(flags_ & (JSFRAME_FUNCTION | JSFRAME_GLOBAL));
JS_ASSERT(retval == !isDummyFrame());
return retval;
}
/*
* Eval frames
*
* As noted above, global and function frames may optionally be 'eval
* frames'. Eval code shares its parent's arguments which means that the
* arg-access members of JSStackFrame may not be used for eval frames.
* Search for 'hasArgs' below for more details.
*
* A further sub-classification of eval frames is whether the frame was
* pushed for an ES5 strict-mode eval().
*/
bool isEvalFrame() const {
JS_ASSERT_IF(flags_ & JSFRAME_EVAL, isScriptFrame());
return flags_ & JSFRAME_EVAL;
}
bool isNonEvalFunctionFrame() const {
return (flags_ & (JSFRAME_FUNCTION | JSFRAME_EVAL)) == JSFRAME_FUNCTION;
}
bool isStrictEvalFrame() const {
return isEvalFrame() && script()->strictModeCode;
}
bool isNonStrictEvalFrame() const {
return isEvalFrame() && !script()->strictModeCode;
}
/*
* Frame initialization
*
* After acquiring a pointer to an uninitialized stack frame on the VM
* stack from js::StackSpace, these members are used to initialize the
* stack frame before officially pushing the frame into the context.
* Collecting frame initialization into a set of inline helpers allows
* simpler reasoning and makes call-optimization easier.
*/
/* Used for Invoke, Interpret, trace-jit LeaveTree, and method-jit stubs. */
inline void initCallFrame(JSContext *cx, JSObject &callee, JSFunction *fun,
uint32 nactual, uint32 flags);
/* Used for SessionInvoke. */
inline void resetInvokeCallFrame();
/* Called by method-jit stubs and serve as a specification for jit-code. */
inline void initCallFrameCallerHalf(JSContext *cx, uint32 flags, void *ncode);
inline void initCallFrameEarlyPrologue(JSFunction *fun, uint32 nactual);
inline void initCallFrameLatePrologue();
/* Used for eval. */
inline void initEvalFrame(JSContext *cx, JSScript *script, JSStackFrame *prev,
uint32 flags);
inline void initGlobalFrame(JSScript *script, JSObject &chain, uint32 flags);
/* Used when activating generators. */
inline void stealFrameAndSlots(js::Value *vp, JSStackFrame *otherfp,
js::Value *othervp, js::Value *othersp);
/* Perhaps one fine day we will remove dummy frames. */
inline void initDummyFrame(JSContext *cx, JSObject &chain);
/*
* Previous frame
*
* A frame's 'prev' frame is either null or the previous frame pointed to
* by cx->regs->fp when this frame was pushed. Often, given two prev-linked
* frames, the next-frame is a function or eval that was called by the
* prev-frame, but not always: the prev-frame may have called a native that
* reentered the VM through JS_CallFunctionValue on the same context
* (without calling JS_SaveFrameChain) which pushed the next-frame. Thus,
* 'prev' has little semantic meaning and basically just tells the VM what
* to set cx->regs->fp to when this frame is popped.
*/
JSStackFrame *prev() const {
return prev_;
}
inline void resetGeneratorPrev(JSContext *cx);
/*
* Frame slots
*
* A frame's 'slots' are the fixed slots associated with the frame (like
* local variables) followed by an expression stack holding temporary
* values. A frame's 'base' is the base of the expression stack.
*/
js::Value *slots() const {
return (js::Value *)(this + 1);
}
js::Value *base() const {
return slots() + script()->nfixed;
}
js::Value &varSlot(uintN i) {
JS_ASSERT(i < script()->nfixed);
JS_ASSERT_IF(maybeFun(), i < script()->bindings.countVars());
return slots()[i];
}
/*
* Script
*
* All function and global frames have an associated JSScript which holds
* the bytecode being executed for the frame.
*/
/*
* Get the frame's current bytecode, assuming |this| is in |cx|.
* next is frame whose prev == this, NULL if not known or if this == cx->fp().
*/
jsbytecode *pc(JSContext *cx, JSStackFrame *next = NULL);
jsbytecode *prevpc() {
JS_ASSERT((prev_ != NULL) && (flags_ & JSFRAME_HAS_PREVPC));
return prevpc_;
}
JSScript *script() const {
JS_ASSERT(isScriptFrame());
return isFunctionFrame()
? isEvalFrame() ? args.script : fun()->script()
: exec.script;
}
JSScript *functionScript() const {
JS_ASSERT(isFunctionFrame());
return isEvalFrame() ? args.script : fun()->script();
}
JSScript *globalScript() const {
JS_ASSERT(isGlobalFrame());
return exec.script;
}
JSScript *maybeScript() const {
return isScriptFrame() ? script() : NULL;
}
size_t numFixed() const {
return script()->nfixed;
}
size_t numSlots() const {
return script()->nslots;
}
size_t numGlobalVars() const {
JS_ASSERT(isGlobalFrame());
return exec.script->nfixed;
}
/*
* Function
*
* All function frames have an associated interpreted JSFunction.
*/
JSFunction* fun() const {
JS_ASSERT(isFunctionFrame());
return exec.fun;
}
JSFunction* maybeFun() const {
return isFunctionFrame() ? fun() : NULL;
}
/*
* Arguments
*
* Only non-eval function frames have arguments. A frame follows its
* arguments contiguously in memory. The arguments pushed by the caller are
* the 'actual' arguments. The declared arguments of the callee are the
* 'formal' arguments. When the caller passes less or equal actual
* arguments, the actual and formal arguments are the same array (but with
* different extents). When the caller passes too many arguments, the
* formal subset of the actual arguments is copied onto the top of the
* stack. This allows the engine to maintain a jit-time constant offset of
* arguments from the frame pointer. Since the formal subset of the actual
* arguments is potentially on the stack twice, it is important for all
* reads/writes to refer to the same canonical memory location.
*
* An arguments object (the object returned by the 'arguments' keyword) is
* lazily created, so a given function frame may or may not have one.
*/
/* True if this frame has arguments. Contrast with hasArgsObj. */
bool hasArgs() const {
return isNonEvalFunctionFrame();
}
uintN numFormalArgs() const {
JS_ASSERT(hasArgs());
return fun()->nargs;
}
js::Value &formalArg(uintN i) const {
JS_ASSERT(i < numFormalArgs());
return formalArgs()[i];
}
js::Value *formalArgs() const {
JS_ASSERT(hasArgs());
return (js::Value *)this - numFormalArgs();
}
js::Value *formalArgsEnd() const {
JS_ASSERT(hasArgs());
return (js::Value *)this;
}
js::Value *maybeFormalArgs() const {
return (flags_ & (JSFRAME_FUNCTION | JSFRAME_EVAL)) == JSFRAME_FUNCTION
? formalArgs()
: NULL;
}
inline uintN numActualArgs() const;
inline js::Value *actualArgs() const;
inline js::Value *actualArgsEnd() const;
inline js::Value &canonicalActualArg(uintN i) const;
/*
* Apply 'op' to each arg of the specified type. Stop if 'op' returns
* false. Return 'true' iff all 'op' calls returned true.
*/
template <class Op> inline bool forEachCanonicalActualArg(Op op);
template <class Op> inline bool forEachFormalArg(Op op);
inline void clearMissingArgs();
bool hasArgsObj() const {
return !!(flags_ & JSFRAME_HAS_ARGS_OBJ);
}
JSObject &argsObj() const {
JS_ASSERT(hasArgsObj());
JS_ASSERT(!isEvalFrame());
return *args.obj;
}
JSObject *maybeArgsObj() const {
return hasArgsObj() ? &argsObj() : NULL;
}
inline void setArgsObj(JSObject &obj);
/*
* This value
*
* Every frame has a this value although, until 'this' is computed, the
* value may not be the semantically-correct 'this' value.
*
* The 'this' value is stored before the formal arguments for function
* frames and directly before the frame for global frames. The *Args
* members assert !isEvalFrame(), so we implement specialized inline
* methods for accessing 'this'. When the caller has static knowledge that
* a frame is a function or global frame, 'functionThis' and 'globalThis',
* respectively, allow more efficient access.
*/
js::Value &functionThis() const {
JS_ASSERT(isFunctionFrame());
if (isEvalFrame())
return ((js::Value *)this)[-1];
return formalArgs()[-1];
}
JSObject &constructorThis() const {
JS_ASSERT(hasArgs());
return formalArgs()[-1].toObject();
}
js::Value &globalThis() const {
JS_ASSERT(isGlobalFrame());
return ((js::Value *)this)[-1];
}
js::Value &thisValue() const {
if (flags_ & (JSFRAME_EVAL | JSFRAME_GLOBAL))
return ((js::Value *)this)[-1];
return formalArgs()[-1];
}
/*
* Callee
*
* Only function frames have a callee. An eval frame in a function has the
* same caller as its containing function frame.
*/
js::Value &calleev() const {
JS_ASSERT(isFunctionFrame());
if (isEvalFrame())
return ((js::Value *)this)[-2];
return formalArgs()[-2];
}
JSObject &callee() const {
JS_ASSERT(isFunctionFrame());
return calleev().toObject();
}
JSObject *maybeCallee() const {
return isFunctionFrame() ? &callee() : NULL;
}
js::CallReceiver callReceiver() const {
return js::CallReceiverFromArgv(formalArgs());
}
/*
* getValidCalleeObject is a fallible getter to compute the correct callee
* function object, which may require deferred cloning due to the JSObject
* methodReadBarrier. For a non-function frame, return true with *vp set
* from calleev, which may not be an object (it could be undefined).
*/
bool getValidCalleeObject(JSContext *cx, js::Value *vp);
/*
* Scope chain
*
* Every frame has a scopeChain which, when traversed via the 'parent' link
* to the root, indicates the current global object. A 'call object' is a
* node on a scope chain representing a function's activation record. A
* call object is used for dynamically-scoped name lookup and lexically-
* scoped upvar access. The call object holds the values of locals and
* arguments when a function returns (and its stack frame is popped). For
* performance reasons, call objects are created lazily for 'lightweight'
* functions, i.e., functions which are not statically known to require a
* call object. Thus, a given function frame may or may not have a call
* object. When a function does have a call object, it is found by walking
* up the scope chain until the first call object. Thus, it is important,
* when setting the scope chain, to indicate whether the new scope chain
* contains a new call object and thus changes the 'hasCallObj' state.
*
* NB: 'fp->hasCallObj()' implies that fp->callObj() needs to be 'put' when
* the frame is popped. Since the scope chain of a non-strict eval frame
* contains the call object of the parent (function) frame, it is possible
* to have:
* !fp->hasCall() && fp->scopeChain().isCall()
*/
JSObject &scopeChain() const {
JS_ASSERT_IF(!(flags_ & JSFRAME_HAS_SCOPECHAIN), isFunctionFrame());
if (!(flags_ & JSFRAME_HAS_SCOPECHAIN)) {
scopeChain_ = callee().getParent();
flags_ |= JSFRAME_HAS_SCOPECHAIN;
}
return *scopeChain_;
}
bool hasCallObj() const {
bool ret = !!(flags_ & JSFRAME_HAS_CALL_OBJ);
JS_ASSERT_IF(ret, !isNonStrictEvalFrame());
return ret;
}
inline JSObject &callObj() const;
inline void setScopeChainNoCallObj(JSObject &obj);
inline void setScopeChainWithOwnCallObj(JSObject &obj);
inline void markActivationObjectsAsPut();
/*
* Frame compartment
*
* A stack frame's compartment is the frame's containing context's
* compartment when the frame was pushed.
*/
JSCompartment *compartment() const {
JS_ASSERT_IF(isScriptFrame(), scopeChain().compartment() == script()->compartment);
return scopeChain().compartment();
}
inline JSPrincipals *principals(JSContext *cx) const;
/*
* Imacropc
*
* A frame's IMacro pc is the bytecode address when an imacro started
* executing (guaranteed non-null). An imacro does not push a frame, so
* when the imacro finishes, the frame's IMacro pc becomes the current pc.
*/
bool hasImacropc() const {
return flags_ & JSFRAME_HAS_IMACRO_PC;
}
jsbytecode *imacropc() const {
JS_ASSERT(hasImacropc());
return imacropc_;
}
jsbytecode *maybeImacropc() const {
return hasImacropc() ? imacropc() : NULL;
}
void clearImacropc() {
flags_ &= ~JSFRAME_HAS_IMACRO_PC;
}
void setImacropc(jsbytecode *pc) {
JS_ASSERT(pc);
JS_ASSERT(!(flags_ & JSFRAME_HAS_IMACRO_PC));
imacropc_ = pc;
flags_ |= JSFRAME_HAS_IMACRO_PC;
}
/* Annotation (will be removed after bug 546848) */
void* annotation() const {
return (flags_ & JSFRAME_HAS_ANNOTATION) ? annotation_ : NULL;
}
void setAnnotation(void *annot) {
flags_ |= JSFRAME_HAS_ANNOTATION;
annotation_ = annot;
}
/* Debugger hook data */
bool hasHookData() const {
return !!(flags_ & JSFRAME_HAS_HOOK_DATA);
}
void* hookData() const {
JS_ASSERT(hasHookData());
return hookData_;
}
void* maybeHookData() const {
return hasHookData() ? hookData_ : NULL;
}
void setHookData(void *v) {
hookData_ = v;
flags_ |= JSFRAME_HAS_HOOK_DATA;
}
/* Return value */
const js::Value &returnValue() {
if (!(flags_ & JSFRAME_HAS_RVAL))
rval_.setUndefined();
return rval_;
}
void markReturnValue() {
flags_ |= JSFRAME_HAS_RVAL;
}
void setReturnValue(const js::Value &v) {
rval_ = v;
markReturnValue();
}
void clearReturnValue() {
rval_.setUndefined();
markReturnValue();
}
/* Native-code return address */
void *nativeReturnAddress() const {
return ncode_;
}
void setNativeReturnAddress(void *addr) {
ncode_ = addr;
}
void **addressOfNativeReturnAddress() {
return &ncode_;
}
/*
* Generator-specific members
*
* A non-eval function frame may optionally be the activation of a
* generator. For the most part, generator frames act like ordinary frames.
* For exceptions, see js_FloatingFrameIfGenerator.
*/
bool isGeneratorFrame() const {
return !!(flags_ & JSFRAME_GENERATOR);
}
bool isFloatingGenerator() const {
JS_ASSERT_IF(flags_ & JSFRAME_FLOATING_GENERATOR, isGeneratorFrame());
return !!(flags_ & JSFRAME_FLOATING_GENERATOR);
}
void initFloatingGenerator() {
JS_ASSERT(!(flags_ & JSFRAME_GENERATOR));
flags_ |= (JSFRAME_GENERATOR | JSFRAME_FLOATING_GENERATOR);
}
void unsetFloatingGenerator() {
flags_ &= ~JSFRAME_FLOATING_GENERATOR;
}
void setFloatingGenerator() {
flags_ |= JSFRAME_FLOATING_GENERATOR;
}
/*
* js::Execute pushes both global and function frames (since eval() in a
* function pushes a frame with isFunctionFrame() && isEvalFrame()). Most
* code should not care where a frame was pushed, but if it is necessary to
* pick out frames pushed by js::Execute, this is the right query:
*/
bool isFramePushedByExecute() const {
return !!(flags_ & (JSFRAME_GLOBAL | JSFRAME_EVAL));
}
/*
* Other flags
*/
bool isConstructing() const {
return !!(flags_ & JSFRAME_CONSTRUCTING);
}
uint32 isConstructingFlag() const {
JS_ASSERT(isFunctionFrame());
JS_ASSERT((flags_ & ~(JSFRAME_CONSTRUCTING | JSFRAME_FUNCTION)) == 0);
return flags_;
}
bool isDebuggerFrame() const {
return !!(flags_ & JSFRAME_DEBUGGER);
}
bool isEvalOrDebuggerFrame() const {
return !!(flags_ & (JSFRAME_EVAL | JSFRAME_DEBUGGER));
}
bool hasOverriddenArgs() const {
return !!(flags_ & JSFRAME_OVERRIDE_ARGS);
}
bool hasOverflowArgs() const {
return !!(flags_ & JSFRAME_OVERFLOW_ARGS);
}
void setOverriddenArgs() {
flags_ |= JSFRAME_OVERRIDE_ARGS;
}
bool isYielding() {
return !!(flags_ & JSFRAME_YIELDING);
}
void setYielding() {
flags_ |= JSFRAME_YIELDING;
}
void clearYielding() {
flags_ &= ~JSFRAME_YIELDING;
}
void setFinishedInInterpreter() {
flags_ |= JSFRAME_FINISHED_IN_INTERP;
}
bool finishedInInterpreter() const {
return !!(flags_ & JSFRAME_FINISHED_IN_INTERP);
}
/*
* Variables object accessors
*
* A stack frame's 'varobj' refers to the 'variables object' (ES3 term)
* associated with the Execution Context's VariableEnvironment (ES5 10.3).
*
* To compute the frame's varobj, the caller must supply the segment
* containing the frame (see js::StackSegment comment). As an abbreviation,
* the caller may pass the context if the frame is contained in that
* context's active segment.
*/
inline JSObject &varobj(js::StackSegment *seg) const;
inline JSObject &varobj(JSContext *cx) const;
/* Access to privates from the jits. */
static size_t offsetOfFlags() {
return offsetof(JSStackFrame, flags_);
}
static size_t offsetOfExec() {
return offsetof(JSStackFrame, exec);
}
void *addressOfArgs() {
return &args;
}
static size_t offsetOfScopeChain() {
return offsetof(JSStackFrame, scopeChain_);
}
JSObject **addressOfScopeChain() {
JS_ASSERT(flags_ & JSFRAME_HAS_SCOPECHAIN);
return &scopeChain_;
}
static size_t offsetOfPrev() {
return offsetof(JSStackFrame, prev_);
}
static size_t offsetOfReturnValue() {
return offsetof(JSStackFrame, rval_);
}
static ptrdiff_t offsetOfncode() {
return offsetof(JSStackFrame, ncode_);
}
static ptrdiff_t offsetOfCallee(JSFunction *fun) {
JS_ASSERT(fun != NULL);
return -(fun->nargs + 2) * sizeof(js::Value);
}
static ptrdiff_t offsetOfThis(JSFunction *fun) {
return fun == NULL
? -1 * ptrdiff_t(sizeof(js::Value))
: -(fun->nargs + 1) * ptrdiff_t(sizeof(js::Value));
}
static ptrdiff_t offsetOfFormalArg(JSFunction *fun, uintN i) {
JS_ASSERT(i < fun->nargs);
return (-(int)fun->nargs + i) * sizeof(js::Value);
}
static size_t offsetOfFixed(uintN i) {
return sizeof(JSStackFrame) + i * sizeof(js::Value);
}
/* Workaround for static asserts on private members. */
void staticAsserts() {
JS_STATIC_ASSERT(offsetof(JSStackFrame, rval_) % sizeof(js::Value) == 0);
JS_STATIC_ASSERT(sizeof(JSStackFrame) % sizeof(js::Value) == 0);
}
#ifdef JS_METHODJIT
js::mjit::JITScript *jit() {
return script()->getJIT(isConstructing());
}
#endif
void methodjitStaticAsserts();
#ifdef DEBUG
/* Poison scopeChain value set before a frame is flushed. */
static JSObject *const sInvalidScopeChain;
#endif
};
#include "vm/Stack.h"
namespace js {
static const size_t VALUES_PER_STACK_FRAME = sizeof(JSStackFrame) / sizeof(Value);
extern JSObject *
GetBlockChain(JSContext *cx, StackFrame *fp);
extern JSObject *
GetBlockChain(JSContext *cx, JSStackFrame *fp);
extern JSObject *
GetBlockChainFast(JSContext *cx, JSStackFrame *fp, JSOp op, size_t oplen);
GetBlockChainFast(JSContext *cx, StackFrame *fp, JSOp op, size_t oplen);
extern JSObject *
GetScopeChain(JSContext *cx);
@ -858,10 +70,10 @@ GetScopeChain(JSContext *cx);
* must reflect at runtime.
*/
extern JSObject *
GetScopeChain(JSContext *cx, JSStackFrame *fp);
GetScopeChain(JSContext *cx, StackFrame *fp);
extern JSObject *
GetScopeChainFast(JSContext *cx, JSStackFrame *fp, JSOp op, size_t oplen);
GetScopeChainFast(JSContext *cx, StackFrame *fp, JSOp op, size_t oplen);
/*
* Report an error that the this value passed as |this| in the given arguments
@ -881,16 +93,6 @@ ReportIncompatibleMethod(JSContext *cx, Value *vp, Class *clasp);
template <typename T>
bool GetPrimitiveThis(JSContext *cx, Value *vp, T *v);
inline void
PutActivationObjects(JSContext *cx, JSStackFrame *fp)
{
/* The order is important since js_PutCallObject does js_PutArgsObject. */
if (fp->hasCallObj())
js_PutCallObject(cx, fp);
else if (fp->hasArgsObj())
js_PutArgsObject(cx, fp);
}
/*
* ScriptPrologue/ScriptEpilogue must be called in pairs. ScriptPrologue
* must be called before the script executes. ScriptEpilogue must be called
@ -898,10 +100,10 @@ PutActivationObjects(JSContext *cx, JSStackFrame *fp)
*/
inline bool
ScriptPrologue(JSContext *cx, JSStackFrame *fp, JSScript *script);
ScriptPrologue(JSContext *cx, StackFrame *fp, JSScript *script);
inline bool
ScriptEpilogue(JSContext *cx, JSStackFrame *fp, bool ok);
ScriptEpilogue(JSContext *cx, StackFrame *fp, bool ok);
/*
* It is not valid to call ScriptPrologue when a generator is resumed or to
@ -911,18 +113,18 @@ ScriptEpilogue(JSContext *cx, JSStackFrame *fp, bool ok);
*/
inline bool
ScriptPrologueOrGeneratorResume(JSContext *cx, JSStackFrame *fp);
ScriptPrologueOrGeneratorResume(JSContext *cx, StackFrame *fp);
inline bool
ScriptEpilogueOrGeneratorYield(JSContext *cx, JSStackFrame *fp, bool ok);
ScriptEpilogueOrGeneratorYield(JSContext *cx, StackFrame *fp, bool ok);
/* Implemented in jsdbgapi: */
extern void
ScriptDebugPrologue(JSContext *cx, JSStackFrame *fp);
ScriptDebugPrologue(JSContext *cx, StackFrame *fp);
extern bool
ScriptDebugEpilogue(JSContext *cx, JSStackFrame *fp, bool ok);
ScriptDebugEpilogue(JSContext *cx, StackFrame *fp, bool ok);
/*
* For a given |call|, convert null/undefined |this| into the global object for
@ -940,18 +142,40 @@ BoxNonStrictThis(JSContext *cx, const CallReceiver &call);
* an optimization to avoid global-this computation).
*/
inline bool
ComputeThis(JSContext *cx, JSStackFrame *fp);
ComputeThis(JSContext *cx, StackFrame *fp);
/*
* Choose enumerator values so that the enum can be passed used directly as the
* stack frame flags.
*/
enum ConstructOption {
INVOKE_NORMAL = 0,
INVOKE_CONSTRUCTOR = StackFrame::CONSTRUCTING
};
JS_STATIC_ASSERT(INVOKE_CONSTRUCTOR != INVOKE_NORMAL);
static inline uintN
ToReportFlags(ConstructOption option)
{
return (uintN)option;
}
static inline uint32
ToFrameFlags(ConstructOption option)
{
return (uintN)option;
}
/*
* The js::InvokeArgumentsGuard passed to js_Invoke must come from an
* immediately-enclosing successful call to js::StackSpace::pushInvokeArgs,
* i.e., there must have been no un-popped pushes to cx->stack(). Furthermore,
* i.e., there must have been no un-popped pushes to cx->stack. Furthermore,
* |args.getvp()[0]| should be the callee, |args.getvp()[1]| should be |this|,
* and the range [args.getvp() + 2, args.getvp() + 2 + args.getArgc()) should
* be initialized actual arguments.
*/
extern JS_REQUIRES_STACK bool
Invoke(JSContext *cx, const CallArgs &args, uint32 flags);
Invoke(JSContext *cx, const CallArgs &args, ConstructOption option = INVOKE_NORMAL);
/*
* Natives like sort/forEach/replace call Invoke repeatedly with the same
@ -979,29 +203,9 @@ Invoke(JSContext *cx, const CallArgs &args, uint32 flags);
*/
class InvokeSessionGuard;
/*
* Consolidated js_Invoke flags simply rename certain JSFRAME_* flags, so that
* we can share bits stored in JSStackFrame.flags and passed to:
*
* js_Invoke
* js_InternalInvoke
* js_ValueToFunction
* js_ValueToFunctionObject
* js_ValueToCallableObject
* js_ReportIsNotFunction
*
* See jsfun.h for the latter four and flag renaming macros.
*/
#define JSINVOKE_CONSTRUCT JSFRAME_CONSTRUCTING
/*
* Mask to isolate construct and iterator flags for use with jsfun.h functions.
*/
#define JSINVOKE_FUNFLAGS JSINVOKE_CONSTRUCT
/*
* "External" calls may come from C or C++ code using a JSContext on which no
* JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
* JS is running (!cx->fp), so they may need to push a dummy StackFrame.
*/
extern bool
@ -1037,17 +241,26 @@ ExternalInvokeConstructor(JSContext *cx, const Value &fval, uintN argc, Value *a
*/
extern JS_FORCES_STACK bool
Execute(JSContext *cx, JSObject &chain, JSScript *script,
JSStackFrame *prev, uintN flags, Value *result);
StackFrame *prev, uintN flags, Value *result);
/* Flags to toggle js::Interpret() execution. */
enum InterpMode
{
JSINTERP_NORMAL = 0, /* interpreter is running normally */
JSINTERP_RECORD = 1, /* interpreter has been started to record/run traces */
JSINTERP_SAFEPOINT = 2, /* interpreter should leave on a method JIT safe point */
JSINTERP_PROFILE = 3 /* interpreter should profile a loop */
};
/*
* Execute the caller-initialized frame for a user-defined script or function
* pointed to by cx->fp until completion or error.
*/
extern JS_REQUIRES_STACK JS_NEVER_INLINE bool
Interpret(JSContext *cx, JSStackFrame *stopFp, uintN inlineCallCount = 0, JSInterpMode mode = JSINTERP_NORMAL);
Interpret(JSContext *cx, StackFrame *stopFp, uintN inlineCallCount = 0, InterpMode mode = JSINTERP_NORMAL);
extern JS_REQUIRES_STACK bool
RunScript(JSContext *cx, JSScript *script, JSStackFrame *fp);
RunScript(JSContext *cx, JSScript *script, StackFrame *fp);
extern bool
CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs);
@ -1102,8 +315,6 @@ GetUpvar(JSContext *cx, uintN level, js::UpvarCookie cookie);
# endif
#endif
#define JS_MAX_INLINE_CALL_COUNT 3000
#if !JS_LONE_INTERPRET
# define JS_STATIC_INTERPRET static
#else

View File

@ -52,425 +52,7 @@
#include "jsfuninlines.h"
inline void
JSStackFrame::initPrev(JSContext *cx)
{
JS_ASSERT(flags_ & JSFRAME_HAS_PREVPC);
if (JSFrameRegs *regs = cx->regs) {
prev_ = regs->fp;
prevpc_ = regs->pc;
JS_ASSERT_IF(!prev_->isDummyFrame() && !prev_->hasImacropc(),
uint32(prevpc_ - prev_->script()->code) < prev_->script()->length);
} else {
prev_ = NULL;
#ifdef DEBUG
prevpc_ = (jsbytecode *)0xbadc;
#endif
}
}
inline void
JSStackFrame::resetGeneratorPrev(JSContext *cx)
{
flags_ |= JSFRAME_HAS_PREVPC;
initPrev(cx);
}
inline void
JSStackFrame::initCallFrame(JSContext *cx, JSObject &callee, JSFunction *fun,
uint32 nactual, uint32 flagsArg)
{
JS_ASSERT((flagsArg & ~(JSFRAME_CONSTRUCTING |
JSFRAME_OVERFLOW_ARGS |
JSFRAME_UNDERFLOW_ARGS)) == 0);
JS_ASSERT(fun == callee.getFunctionPrivate());
/* Initialize stack frame members. */
flags_ = JSFRAME_FUNCTION | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN | flagsArg;
exec.fun = fun;
args.nactual = nactual; /* only need to write if over/under-flow */
scopeChain_ = callee.getParent();
initPrev(cx);
JS_ASSERT(!hasImacropc());
JS_ASSERT(!hasHookData());
JS_ASSERT(annotation() == NULL);
JS_ASSERT(!hasCallObj());
}
inline void
JSStackFrame::resetInvokeCallFrame()
{
/* Undo changes to frame made during execution; see initCallFrame */
JS_ASSERT(!(flags_ & ~(JSFRAME_FUNCTION |
JSFRAME_OVERFLOW_ARGS |
JSFRAME_UNDERFLOW_ARGS |
JSFRAME_OVERRIDE_ARGS |
JSFRAME_HAS_PREVPC |
JSFRAME_HAS_RVAL |
JSFRAME_HAS_SCOPECHAIN |
JSFRAME_HAS_ANNOTATION |
JSFRAME_HAS_HOOK_DATA |
JSFRAME_HAS_CALL_OBJ |
JSFRAME_HAS_ARGS_OBJ |
JSFRAME_FINISHED_IN_INTERP)));
/*
* Since the stack frame is usually popped after PutActivationObjects,
* these bits aren't cleared. The activation objects must have actually
* been put, though.
*/
JS_ASSERT_IF(flags_ & JSFRAME_HAS_CALL_OBJ, callObj().getPrivate() == NULL);
JS_ASSERT_IF(flags_ & JSFRAME_HAS_ARGS_OBJ, argsObj().getPrivate() == NULL);
flags_ &= JSFRAME_FUNCTION |
JSFRAME_OVERFLOW_ARGS |
JSFRAME_HAS_PREVPC |
JSFRAME_UNDERFLOW_ARGS;
JS_ASSERT(exec.fun == callee().getFunctionPrivate());
scopeChain_ = callee().getParent();
}
inline void
JSStackFrame::initCallFrameCallerHalf(JSContext *cx, uint32 flagsArg,
void *ncode)
{
JS_ASSERT((flagsArg & ~(JSFRAME_CONSTRUCTING |
JSFRAME_FUNCTION |
JSFRAME_OVERFLOW_ARGS |
JSFRAME_UNDERFLOW_ARGS)) == 0);
flags_ = JSFRAME_FUNCTION | flagsArg;
prev_ = cx->regs->fp;
ncode_ = ncode;
}
/*
* The "early prologue" refers to the members that are stored for the benefit
* of slow paths before initializing the rest of the members.
*/
inline void
JSStackFrame::initCallFrameEarlyPrologue(JSFunction *fun, uint32 nactual)
{
exec.fun = fun;
if (flags_ & (JSFRAME_OVERFLOW_ARGS | JSFRAME_UNDERFLOW_ARGS))
args.nactual = nactual;
}
/*
* The "late prologue" refers to the members that are stored after having
* checked for stack overflow and formal/actual arg mismatch.
*/
inline void
JSStackFrame::initCallFrameLatePrologue()
{
SetValueRangeToUndefined(slots(), script()->nfixed);
}
inline void
JSStackFrame::initEvalFrame(JSContext *cx, JSScript *script, JSStackFrame *prev, uint32 flagsArg)
{
JS_ASSERT(flagsArg & JSFRAME_EVAL);
JS_ASSERT((flagsArg & ~(JSFRAME_EVAL | JSFRAME_DEBUGGER)) == 0);
JS_ASSERT(prev->isScriptFrame());
/* Copy (callee, thisv). */
js::Value *dstvp = (js::Value *)this - 2;
js::Value *srcvp = prev->hasArgs()
? prev->formalArgs() - 2
: (js::Value *)prev - 2;
dstvp[0] = srcvp[0];
dstvp[1] = srcvp[1];
JS_ASSERT_IF(prev->isFunctionFrame(),
dstvp[0].toObject().isFunction());
/* Initialize stack frame members. */
flags_ = flagsArg | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN |
(prev->flags_ & (JSFRAME_FUNCTION | JSFRAME_GLOBAL));
if (isFunctionFrame()) {
exec = prev->exec;
args.script = script;
} else {
exec.script = script;
}
scopeChain_ = &prev->scopeChain();
prev_ = prev;
prevpc_ = prev->pc(cx);
JS_ASSERT(!hasImacropc());
JS_ASSERT(!hasHookData());
setAnnotation(prev->annotation());
}
inline void
JSStackFrame::initGlobalFrame(JSScript *script, JSObject &chain, uint32 flagsArg)
{
JS_ASSERT((flagsArg & ~(JSFRAME_EVAL | JSFRAME_DEBUGGER)) == 0);
/* Initialize (callee, thisv). */
js::Value *vp = (js::Value *)this - 2;
vp[0].setUndefined();
vp[1].setUndefined(); /* Set after frame pushed using thisObject */
/* Initialize stack frame members. */
flags_ = flagsArg | JSFRAME_GLOBAL | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN;
exec.script = script;
args.script = (JSScript *)0xbad;
scopeChain_ = &chain;
prev_ = NULL;
JS_ASSERT(!hasImacropc());
JS_ASSERT(!hasHookData());
JS_ASSERT(annotation() == NULL);
}
inline void
JSStackFrame::initDummyFrame(JSContext *cx, JSObject &chain)
{
js::PodZero(this);
flags_ = JSFRAME_DUMMY | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN;
initPrev(cx);
chain.isGlobal();
setScopeChainNoCallObj(chain);
}
inline void
JSStackFrame::stealFrameAndSlots(js::Value *vp, JSStackFrame *otherfp,
js::Value *othervp, js::Value *othersp)
{
JS_ASSERT(vp == (js::Value *)this - (otherfp->formalArgsEnd() - othervp));
JS_ASSERT(othervp == otherfp->actualArgs() - 2);
JS_ASSERT(othersp >= otherfp->slots());
JS_ASSERT(othersp <= otherfp->base() + otherfp->numSlots());
PodCopy(vp, othervp, othersp - othervp);
JS_ASSERT(vp == this->actualArgs() - 2);
/* Catch bad-touching of non-canonical args (e.g., generator_trace). */
if (otherfp->hasOverflowArgs())
Debug_SetValueRangeToCrashOnTouch(othervp, othervp + 2 + otherfp->numFormalArgs());
/*
* Repoint Call, Arguments, Block and With objects to the new live frame.
* Call and Arguments are done directly because we have pointers to them.
* Block and With objects are done indirectly through 'liveFrame'. See
* js_LiveFrameToFloating comment in jsiter.h.
*/
if (hasCallObj()) {
JSObject &obj = callObj();
obj.setPrivate(this);
otherfp->flags_ &= ~JSFRAME_HAS_CALL_OBJ;
if (js_IsNamedLambda(fun())) {
JSObject *env = obj.getParent();
JS_ASSERT(env->getClass() == &js_DeclEnvClass);
env->setPrivate(this);
}
}
if (hasArgsObj()) {
JSObject &args = argsObj();
JS_ASSERT(args.isArguments());
if (args.isNormalArguments())
args.setPrivate(this);
else
JS_ASSERT(!args.getPrivate());
otherfp->flags_ &= ~JSFRAME_HAS_ARGS_OBJ;
}
}
inline js::Value &
JSStackFrame::canonicalActualArg(uintN i) const
{
if (i < numFormalArgs())
return formalArg(i);
JS_ASSERT(i < numActualArgs());
return actualArgs()[i];
}
template <class Op>
inline bool
JSStackFrame::forEachCanonicalActualArg(Op op)
{
uintN nformal = fun()->nargs;
js::Value *formals = formalArgsEnd() - nformal;
uintN nactual = numActualArgs();
if (nactual <= nformal) {
uintN i = 0;
js::Value *actualsEnd = formals + nactual;
for (js::Value *p = formals; p != actualsEnd; ++p, ++i) {
if (!op(i, p))
return false;
}
} else {
uintN i = 0;
js::Value *formalsEnd = formalArgsEnd();
for (js::Value *p = formals; p != formalsEnd; ++p, ++i) {
if (!op(i, p))
return false;
}
js::Value *actuals = formalsEnd - (nactual + 2);
js::Value *actualsEnd = formals - 2;
for (js::Value *p = actuals; p != actualsEnd; ++p, ++i) {
if (!op(i, p))
return false;
}
}
return true;
}
template <class Op>
inline bool
JSStackFrame::forEachFormalArg(Op op)
{
js::Value *formals = formalArgsEnd() - fun()->nargs;
js::Value *formalsEnd = formalArgsEnd();
uintN i = 0;
for (js::Value *p = formals; p != formalsEnd; ++p, ++i) {
if (!op(i, p))
return false;
}
return true;
}
namespace js {
struct CopyTo
{
Value *dst;
CopyTo(Value *dst) : dst(dst) {}
bool operator()(uintN, Value *src) {
*dst++ = *src;
return true;
}
};
}
JS_ALWAYS_INLINE void
JSStackFrame::clearMissingArgs()
{
if (flags_ & JSFRAME_UNDERFLOW_ARGS)
SetValueRangeToUndefined(formalArgs() + numActualArgs(), formalArgsEnd());
}
inline JSObject &
JSStackFrame::varobj(js::StackSegment *seg) const
{
JS_ASSERT(seg->contains(this));
return isFunctionFrame() ? callObj() : seg->getInitialVarObj();
}
inline JSObject &
JSStackFrame::varobj(JSContext *cx) const
{
JS_ASSERT(cx->activeSegment()->contains(this));
return isFunctionFrame() ? callObj() : cx->activeSegment()->getInitialVarObj();
}
inline uintN
JSStackFrame::numActualArgs() const
{
JS_ASSERT(hasArgs());
if (JS_UNLIKELY(flags_ & (JSFRAME_OVERFLOW_ARGS | JSFRAME_UNDERFLOW_ARGS)))
return hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual;
return numFormalArgs();
}
inline js::Value *
JSStackFrame::actualArgs() const
{
JS_ASSERT(hasArgs());
js::Value *argv = formalArgs();
if (JS_UNLIKELY(flags_ & JSFRAME_OVERFLOW_ARGS)) {
uintN nactual = hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual;
return argv - (2 + nactual);
}
return argv;
}
inline js::Value *
JSStackFrame::actualArgsEnd() const
{
JS_ASSERT(hasArgs());
if (JS_UNLIKELY(flags_ & JSFRAME_OVERFLOW_ARGS))
return formalArgs() - 2;
return formalArgs() + numActualArgs();
}
inline void
JSStackFrame::setArgsObj(JSObject &obj)
{
JS_ASSERT_IF(hasArgsObj(), &obj == args.obj);
JS_ASSERT_IF(!hasArgsObj(), numActualArgs() == obj.getArgsInitialLength());
args.obj = &obj;
flags_ |= JSFRAME_HAS_ARGS_OBJ;
}
inline void
JSStackFrame::setScopeChainNoCallObj(JSObject &obj)
{
#ifdef DEBUG
JS_ASSERT(&obj != NULL);
if (&obj != sInvalidScopeChain) {
if (hasCallObj()) {
JSObject *pobj = &obj;
while (pobj && pobj->getPrivate() != this)
pobj = pobj->getParent();
JS_ASSERT(pobj);
} else {
for (JSObject *pobj = &obj; pobj; pobj = pobj->getParent())
JS_ASSERT_IF(pobj->isCall(), pobj->getPrivate() != this);
}
}
#endif
scopeChain_ = &obj;
flags_ |= JSFRAME_HAS_SCOPECHAIN;
}
inline void
JSStackFrame::setScopeChainWithOwnCallObj(JSObject &obj)
{
JS_ASSERT(&obj != NULL);
JS_ASSERT(!hasCallObj() && obj.isCall() && obj.getPrivate() == this);
scopeChain_ = &obj;
flags_ |= JSFRAME_HAS_SCOPECHAIN | JSFRAME_HAS_CALL_OBJ;
}
inline JSObject &
JSStackFrame::callObj() const
{
JS_ASSERT_IF(isNonEvalFunctionFrame() || isStrictEvalFrame(), hasCallObj());
JSObject *pobj = &scopeChain();
while (JS_UNLIKELY(pobj->getClass() != &js_CallClass)) {
JS_ASSERT(js::IsCacheableNonGlobalScope(pobj) || pobj->isWith());
pobj = pobj->getParent();
}
return *pobj;
}
inline void
JSStackFrame::markActivationObjectsAsPut()
{
if (flags_ & (JSFRAME_HAS_ARGS_OBJ | JSFRAME_HAS_CALL_OBJ)) {
if (hasArgsObj() && !argsObj().getPrivate()) {
args.nactual = args.obj->getArgsInitialLength();
flags_ &= ~JSFRAME_HAS_ARGS_OBJ;
}
if (hasCallObj() && !callObj().getPrivate()) {
/*
* For function frames, the call object may or may not have have an
* enclosing DeclEnv object, so we use the callee's parent, since
* it was the initial scope chain. For global (strict) eval frames,
* there is no calle, but the call object's parent is the initial
* scope chain.
*/
scopeChain_ = isFunctionFrame()
? callee().getParent()
: scopeChain_->getParent();
flags_ &= ~JSFRAME_HAS_CALL_OBJ;
}
}
}
#include "vm/Stack-inl.h"
namespace js {
@ -548,12 +130,11 @@ InvokeSessionGuard::invoke(JSContext *cx) const
#else
if (!optimized())
#endif
return Invoke(cx, args_, 0);
return Invoke(cx, args_);
/* Clear any garbage left from the last Invoke. */
JSStackFrame *fp = frame_.fp();
StackFrame *fp = frame_.fp();
fp->clearMissingArgs();
PutActivationObjects(cx, frame_.fp());
fp->resetInvokeCallFrame();
SetValueRangeToUndefined(fp->slots(), script_->nfixed);
@ -563,9 +144,9 @@ InvokeSessionGuard::invoke(JSContext *cx) const
Probes::enterJSFun(cx, fp->fun(), script_);
#ifdef JS_METHODJIT
ok = mjit::EnterMethodJIT(cx, fp, code, stackLimit_);
cx->regs->pc = stop_;
cx->regs().pc = stop_;
#else
cx->regs->pc = script_->code;
cx->regs().pc = script_->code;
ok = Interpret(cx, cx->fp());
#endif
Probes::exitJSFun(cx, fp->fun(), script_);
@ -606,7 +187,7 @@ class PrimitiveBehavior<double> {
} // namespace detail
template <typename T>
bool
inline bool
GetPrimitiveThis(JSContext *cx, Value *vp, T *v)
{
typedef detail::PrimitiveBehavior<T> Behavior;
@ -704,7 +285,7 @@ ComputeImplicitThis(JSContext *cx, JSObject *obj, const Value &funval, Value *vp
}
inline bool
ComputeThis(JSContext *cx, JSStackFrame *fp)
ComputeThis(JSContext *cx, StackFrame *fp)
{
Value &thisv = fp->thisValue();
if (thisv.isObject())
@ -761,7 +342,7 @@ ValuePropertyBearer(JSContext *cx, const Value &v, int spindex)
}
inline bool
ScriptPrologue(JSContext *cx, JSStackFrame *fp)
ScriptPrologue(JSContext *cx, StackFrame *fp)
{
JS_ASSERT_IF(fp->isNonEvalFunctionFrame() && fp->fun()->isHeavyweight(), fp->hasCallObj());
@ -778,7 +359,7 @@ ScriptPrologue(JSContext *cx, JSStackFrame *fp)
}
inline bool
ScriptEpilogue(JSContext *cx, JSStackFrame *fp, bool ok)
ScriptEpilogue(JSContext *cx, StackFrame *fp, bool ok)
{
if (cx->compartment->debugMode)
ok = ScriptDebugEpilogue(cx, fp, ok);
@ -797,7 +378,7 @@ ScriptEpilogue(JSContext *cx, JSStackFrame *fp, bool ok)
}
inline bool
ScriptPrologueOrGeneratorResume(JSContext *cx, JSStackFrame *fp)
ScriptPrologueOrGeneratorResume(JSContext *cx, StackFrame *fp)
{
if (!fp->isGeneratorFrame())
return ScriptPrologue(cx, fp);
@ -807,7 +388,7 @@ ScriptPrologueOrGeneratorResume(JSContext *cx, JSStackFrame *fp)
}
inline bool
ScriptEpilogueOrGeneratorYield(JSContext *cx, JSStackFrame *fp, bool ok)
ScriptEpilogueOrGeneratorYield(JSContext *cx, StackFrame *fp, bool ok)
{
if (!fp->isYielding())
return ScriptEpilogue(cx, fp, ok);
@ -816,6 +397,6 @@ ScriptEpilogueOrGeneratorYield(JSContext *cx, JSStackFrame *fp, bool ok)
return ok;
}
}
} /* namespace js */
#endif /* jsinterpinlines_h__ */

View File

@ -65,6 +65,7 @@
#include "jsobj.h"
#include "jsopcode.h"
#include "jsproxy.h"
#include "jsscan.h"
#include "jsscope.h"
#include "jsscript.h"
#include "jsstaticcheck.h"
@ -74,11 +75,11 @@
#include "jsxml.h"
#endif
#include "jscntxtinlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsstrinlines.h"
#include "vm/Stack-inl.h"
using namespace js;
using namespace js::gc;
@ -1091,7 +1092,7 @@ generator_trace(JSTracer *trc, JSObject *obj)
if (gen->state == JSGEN_RUNNING || gen->state == JSGEN_CLOSING)
return;
JSStackFrame *fp = gen->floatingFrame();
StackFrame *fp = gen->floatingFrame();
JS_ASSERT(gen->liveFrame() == fp);
/*
@ -1134,17 +1135,10 @@ Class js_GeneratorClass = {
}
};
static inline void
RebaseRegsFromTo(JSFrameRegs *regs, JSStackFrame *from, JSStackFrame *to)
{
regs->fp = to;
regs->sp = to->slots() + (regs->sp - from->slots());
}
/*
* Called from the JSOP_GENERATOR case in the interpreter, with fp referring
* to the frame by which the generator function was activated. Create a new
* JSGenerator object, which contains its own JSStackFrame that we populate
* JSGenerator object, which contains its own StackFrame that we populate
* from *fp. We know that upon return, the JSOP_GENERATOR opcode will return
* from the activation in fp, so we can steal away fp->callobj and fp->argsobj
* if they are non-null.
@ -1156,8 +1150,8 @@ js_NewGenerator(JSContext *cx)
if (!obj)
return NULL;
JSStackFrame *stackfp = cx->fp();
JS_ASSERT(stackfp->base() == cx->regs->sp);
StackFrame *stackfp = cx->fp();
JS_ASSERT(stackfp->base() == cx->regs().sp);
JS_ASSERT(stackfp->actualArgs() <= stackfp->formalArgs());
/* Load and compute stack slot counts. */
@ -1177,7 +1171,7 @@ js_NewGenerator(JSContext *cx)
/* Cut up floatingStack space. */
Value *genvp = gen->floatingStack;
JSStackFrame *genfp = reinterpret_cast<JSStackFrame *>(genvp + vplen);
StackFrame *genfp = reinterpret_cast<StackFrame *>(genvp + vplen);
/* Initialize JSGenerator. */
gen->obj = obj;
@ -1186,11 +1180,11 @@ js_NewGenerator(JSContext *cx)
gen->floating = genfp;
/* Initialize regs stored in generator. */
gen->regs = *cx->regs;
RebaseRegsFromTo(&gen->regs, stackfp, genfp);
gen->regs = cx->regs();
gen->regs.rebaseFromTo(stackfp, genfp);
/* Copy frame off the stack. */
genfp->stealFrameAndSlots(genvp, stackfp, stackvp, cx->regs->sp);
genfp->stealFrameAndSlots(genvp, stackfp, stackvp, cx->regs().sp);
genfp->initFloatingGenerator();
obj->setPrivate(gen);
@ -1198,7 +1192,7 @@ js_NewGenerator(JSContext *cx)
}
JSGenerator *
js_FloatingFrameToGenerator(JSStackFrame *fp)
js_FloatingFrameToGenerator(StackFrame *fp)
{
JS_ASSERT(fp->isGeneratorFrame() && fp->isFloatingGenerator());
char *floatingStackp = (char *)(fp->actualArgs() - 2);
@ -1258,11 +1252,11 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, JSObject *obj,
break;
}
JSStackFrame *genfp = gen->floatingFrame();
StackFrame *genfp = gen->floatingFrame();
Value *genvp = gen->floatingStack;
uintN vplen = genfp->formalArgsEnd() - genvp;
JSStackFrame *stackfp;
StackFrame *stackfp;
Value *stackvp;
JSBool ok;
{
@ -1271,7 +1265,7 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, JSObject *obj,
* the code before pushExecuteFrame must not reenter the interpreter.
*/
GeneratorFrameGuard frame;
if (!cx->stack().getGeneratorFrame(cx, vplen, genfp->numSlots(), &frame)) {
if (!cx->stack.getGeneratorFrame(cx, vplen, genfp->numSlots(), &frame)) {
gen->state = JSGEN_CLOSED;
return JS_FALSE;
}
@ -1282,11 +1276,11 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, JSObject *obj,
stackfp->stealFrameAndSlots(stackvp, genfp, genvp, gen->regs.sp);
stackfp->resetGeneratorPrev(cx);
stackfp->unsetFloatingGenerator();
RebaseRegsFromTo(&gen->regs, genfp, stackfp);
gen->regs.rebaseFromTo(genfp, stackfp);
MUST_FLOW_THROUGH("restore");
/* Officially push frame. frame's destructor pops. */
cx->stack().pushGeneratorFrame(cx, &gen->regs, &frame);
cx->stack.pushGeneratorFrame(gen->regs, &frame);
cx->enterGenerator(gen); /* OOM check above. */
JSObject *enumerators = cx->enumerators;
@ -1306,7 +1300,7 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, JSObject *obj,
genfp->setFloatingGenerator();
}
MUST_FLOW_LABEL(restore)
RebaseRegsFromTo(&gen->regs, stackfp, genfp);
gen->regs.rebaseFromTo(stackfp, genfp);
if (gen->floatingFrame()->isYielding()) {
/* Yield cannot fail, throw or be called on closing. */

View File

@ -181,19 +181,19 @@ typedef enum JSGeneratorState {
struct JSGenerator {
JSObject *obj;
JSGeneratorState state;
JSFrameRegs regs;
js::FrameRegs regs;
JSObject *enumerators;
JSStackFrame *floating;
js::StackFrame *floating;
js::Value floatingStack[1];
JSStackFrame *floatingFrame() {
js::StackFrame *floatingFrame() {
return floating;
}
JSStackFrame *liveFrame() {
js::StackFrame *liveFrame() {
JS_ASSERT((state == JSGEN_RUNNING || state == JSGEN_CLOSING) ==
(regs.fp != floatingFrame()));
return regs.fp;
(regs.fp() != floatingFrame()));
return regs.fp();
}
};
@ -211,10 +211,10 @@ js_NewGenerator(JSContext *cx);
* Block and With objects must "normalize" to and from the floating/live frames
* in the case of generators using the following functions.
*/
inline JSStackFrame *
js_FloatingFrameIfGenerator(JSContext *cx, JSStackFrame *fp)
inline js::StackFrame *
js_FloatingFrameIfGenerator(JSContext *cx, js::StackFrame *fp)
{
JS_ASSERT(cx->stack().contains(fp));
JS_ASSERT(cx->stack.contains(fp));
if (JS_UNLIKELY(fp->isGeneratorFrame()))
return cx->generatorFor(fp)->floatingFrame();
return fp;
@ -222,10 +222,10 @@ js_FloatingFrameIfGenerator(JSContext *cx, JSStackFrame *fp)
/* Given a floating frame, given the JSGenerator containing it. */
extern JSGenerator *
js_FloatingFrameToGenerator(JSStackFrame *fp);
js_FloatingFrameToGenerator(js::StackFrame *fp);
inline JSStackFrame *
js_LiveFrameIfGenerator(JSStackFrame *fp)
inline js::StackFrame *
js_LiveFrameIfGenerator(js::StackFrame *fp)
{
return fp->isGeneratorFrame() ? js_FloatingFrameToGenerator(fp)->liveFrame() : fp;
}

View File

@ -81,7 +81,7 @@ typedef struct JSThinLock {
JSFatLock *fat;
} JSThinLock;
#define CX_THINLOCK_ID(cx) ((jsword)(cx)->thread)
#define CX_THINLOCK_ID(cx) ((jsword)(cx)->thread())
#define CURRENT_THREAD_IS_ME(me) (((JSThread *)me)->id == js_CurrentThreadId())
typedef PRLock JSLock;

View File

@ -881,5 +881,8 @@ js_InitMathClass(JSContext *cx, JSObject *obj)
return NULL;
if (!JS_DefineConstDoubles(cx, Math, math_constants))
return NULL;
MarkStandardClassInitializedNoProto(obj, &js_MathClass);
return Math;
}

View File

@ -700,19 +700,18 @@ num_toString(JSContext *cx, uintN argc, Value *vp)
if (!GetPrimitiveThis(cx, vp, &d))
return false;
int32_t base = 10;
int32 base = 10;
if (argc != 0 && !vp[2].isUndefined()) {
if (!ValueToECMAInt32(cx, vp[2], &base))
return JS_FALSE;
jsdouble d2;
if (!ToInteger(cx, vp[2], &d2))
return false;
if (base < 2 || base > 36) {
ToCStringBuf cbuf;
char *numStr = IntToCString(&cbuf, base); /* convert the base itself to a string */
JS_ASSERT(numStr);
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX,
numStr);
return JS_FALSE;
if (d2 < 2 || d2 > 36) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX);
return false;
}
base = int32(d2);
}
JSString *str = js_NumberToStringWithBase(cx, d, base);
if (!str) {
@ -874,9 +873,8 @@ num_to(JSContext *cx, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
precision = 0.0;
oneArgMode = zeroArgMode;
} else {
if (!ValueToNumber(cx, vp[2], &precision))
return JS_FALSE;
precision = js_DoubleToInteger(precision);
if (!ToInteger(cx, vp[2], &precision))
return false;
if (precision < precisionMin || precision > precisionMax) {
ToCStringBuf cbuf;
numStr = IntToCString(&cbuf, jsint(precision));

View File

@ -696,6 +696,26 @@ StringToNumberType(JSContext *cx, JSString *str, T *result)
*result = NumberTraits<T>::toSelfType(d);
return true;
}
/* ES5 9.4 ToInteger. */
static inline bool
ToInteger(JSContext *cx, const js::Value &v, jsdouble *dp)
{
if (v.isInt32()) {
*dp = v.toInt32();
return true;
}
if (v.isDouble()) {
*dp = v.toDouble();
} else {
extern bool ValueToNumberSlow(JSContext *cx, js::Value v, double *dp);
if (!ValueToNumberSlow(cx, v, dp))
return false;
}
*dp = js_DoubleToInteger(*dp);
return true;
}
} /* namespace js */
#endif /* jsnum_h___ */

View File

@ -86,6 +86,8 @@
#include "jsscriptinlines.h"
#include "jsobjinlines.h"
#include "vm/StringObject-inl.h"
#if JS_HAS_GENERATORS
#include "jsiter.h"
#endif
@ -959,7 +961,7 @@ EvalCacheHash(JSContext *cx, JSLinearString *str)
}
static JS_ALWAYS_INLINE JSScript *
EvalCacheLookup(JSContext *cx, JSLinearString *str, JSStackFrame *caller, uintN staticLevel,
EvalCacheLookup(JSContext *cx, JSLinearString *str, StackFrame *caller, uintN staticLevel,
JSPrincipals *principals, JSObject &scopeobj, JSScript **bucket)
{
/*
@ -1082,7 +1084,7 @@ class EvalScriptGuard
}
}
void lookupInEvalCache(JSStackFrame *caller, uintN staticLevel,
void lookupInEvalCache(StackFrame *caller, uintN staticLevel,
JSPrincipals *principals, JSObject &scopeobj) {
if (JSScript *found = EvalCacheLookup(cx_, str_, caller, staticLevel,
principals, scopeobj, bucket_)) {
@ -1120,7 +1122,7 @@ class EvalScriptGuard
enum EvalType { DIRECT_EVAL, INDIRECT_EVAL };
static bool
EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, JSStackFrame *caller,
EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *caller,
JSObject &scopeobj)
{
JS_ASSERT((evalType == INDIRECT_EVAL) == (caller == NULL));
@ -1235,7 +1237,7 @@ EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, JSStackFrame
esg.setNewScript(compiled);
}
return Execute(cx, scopeobj, esg.script(), caller, JSFRAME_EVAL, &call.rval());
return Execute(cx, scopeobj, esg.script(), caller, StackFrame::EVAL, &call.rval());
}
/*
@ -1247,7 +1249,7 @@ static inline bool
WarnOnTooManyArgs(JSContext *cx, const CallArgs &call)
{
if (call.argc() > 1) {
if (JSStackFrame *caller = js_GetScriptedCaller(cx, NULL)) {
if (StackFrame *caller = js_GetScriptedCaller(cx, NULL)) {
if (!caller->script()->warnedAboutTwoArgumentEval) {
static const char TWO_ARGUMENT_WARNING[] =
"Support for eval(code, scopeObject) has been removed. "
@ -1286,10 +1288,10 @@ bool
DirectEval(JSContext *cx, const CallArgs &call)
{
/* Direct eval can assume it was called from an interpreted frame. */
JSStackFrame *caller = cx->fp();
StackFrame *caller = cx->fp();
JS_ASSERT(caller->isScriptFrame());
JS_ASSERT(IsBuiltinEvalForScope(&caller->scopeChain(), call.calleev()));
JS_ASSERT(*cx->regs->pc == JSOP_EVAL);
JS_ASSERT(*cx->regs().pc == JSOP_EVAL);
AutoFunctionCallProbe callProbe(cx, call.callee().getFunctionPrivate(), caller->script());
@ -1339,8 +1341,8 @@ PrincipalsForCompiledCode(const CallArgs &call, JSContext *cx)
#ifdef DEBUG
if (calleePrincipals) {
if (JSStackFrame *caller = js_GetScriptedCaller(cx, NULL)) {
if (JSPrincipals *callerPrincipals = caller->principals(cx)) {
if (StackFrame *caller = js_GetScriptedCaller(cx, NULL)) {
if (JSPrincipals *callerPrincipals = caller->scopeChain().principals(cx)) {
JS_ASSERT(callerPrincipals->subsume(callerPrincipals, calleePrincipals));
}
}
@ -1360,8 +1362,8 @@ obj_watch_handler(JSContext *cx, JSObject *obj, jsid id, jsval old,
{
JSObject *callable = (JSObject *) closure;
if (JSPrincipals *watcher = callable->principals(cx)) {
if (JSStackFrame *caller = js_GetScriptedCaller(cx, NULL)) {
if (JSPrincipals *subject = caller->principals(cx)) {
if (StackFrame *caller = js_GetScriptedCaller(cx, NULL)) {
if (JSPrincipals *subject = caller->scopeChain().principals(cx)) {
if (!watcher->subsume(watcher, subject)) {
/* Silently don't call the watch handler. */
return JS_TRUE;
@ -2930,25 +2932,6 @@ js_CreateThisForFunction(JSContext *cx, JSObject *callee)
#ifdef JS_TRACER
static JS_ALWAYS_INLINE JSObject*
NewObjectWithClassProto(JSContext *cx, Class *clasp, JSObject *proto,
/*gc::FinalizeKind*/ unsigned _kind)
{
JS_ASSERT(clasp->isNative());
gc::FinalizeKind kind = gc::FinalizeKind(_kind);
if (CanBeFinalizedInBackground(kind, clasp))
kind = (gc::FinalizeKind)(kind + 1);
JSObject* obj = js_NewGCObject(cx, kind);
if (!obj)
return NULL;
if (!obj->initSharingEmptyShape(cx, clasp, proto, proto->getParent(), NULL, kind))
return NULL;
return obj;
}
JSObject* FASTCALL
js_Object_tn(JSContext* cx, JSObject* proto)
{
@ -2978,11 +2961,8 @@ JSObject* FASTCALL
js_String_tn(JSContext* cx, JSObject* proto, JSString* str)
{
JS_ASSERT(JS_ON_TRACE(cx));
JS_ASSERT(FINALIZE_OBJECT2 == gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(&js_StringClass)));
JSObject *obj = NewObjectWithClassProto(cx, &js_StringClass, proto, FINALIZE_OBJECT2);
if (!obj || !obj->initString(cx, str))
return NULL;
return obj;
JS_ASSERT(proto);
return StringObject::createWithProto(cx, str, *proto);
}
JS_DEFINE_CALLINFO_3(extern, OBJECT, js_String_tn, CONTEXT, CALLEE_PROTOTYPE, STRING, 0,
nanojit::ACCSET_STORE_ANY)
@ -3110,8 +3090,8 @@ js_InferFlags(JSContext *cx, uintN defaultFlags)
uint32 format;
uintN flags = 0;
JSStackFrame *const fp = js_GetTopStackFrame(cx);
if (!fp || !(pc = cx->regs->pc))
StackFrame *const fp = js_GetTopStackFrame(cx);
if (!fp || !(pc = cx->regs().pc))
return defaultFlags;
cs = &js_CodeSpec[js_GetOpcode(cx, fp->script(), pc)];
format = cs->format;
@ -3239,7 +3219,7 @@ js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth)
if (!obj)
return NULL;
JSStackFrame *priv = js_FloatingFrameIfGenerator(cx, cx->fp());
StackFrame *priv = js_FloatingFrameIfGenerator(cx, cx->fp());
EmptyShape *emptyWithShape = EmptyShape::getEmptyWithShape(cx);
if (!emptyWithShape)
@ -3281,7 +3261,7 @@ js_NewBlockObject(JSContext *cx)
}
JSObject *
js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp)
js_CloneBlockObject(JSContext *cx, JSObject *proto, StackFrame *fp)
{
JS_ASSERT(proto->isStaticBlock());
@ -3292,7 +3272,7 @@ js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp)
if (!clone)
return NULL;
JSStackFrame *priv = js_FloatingFrameIfGenerator(cx, fp);
StackFrame *priv = js_FloatingFrameIfGenerator(cx, fp);
/* The caller sets parent on its own. */
clone->initClonedBlock(cx, proto, priv);
@ -3309,7 +3289,7 @@ js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp)
JS_REQUIRES_STACK JSBool
js_PutBlockObject(JSContext *cx, JSBool normalUnwind)
{
JSStackFrame *const fp = cx->fp();
StackFrame *const fp = cx->fp();
JSObject *obj = &fp->scopeChain();
JS_ASSERT(obj->isClonedBlock());
JS_ASSERT(obj->getPrivate() == js_FloatingFrameIfGenerator(cx, cx->fp()));
@ -3320,8 +3300,8 @@ js_PutBlockObject(JSContext *cx, JSBool normalUnwind)
/* The block and its locals must be on the current stack for GC safety. */
uintN depth = OBJ_BLOCK_DEPTH(cx, obj);
JS_ASSERT(depth <= size_t(cx->regs->sp - fp->base()));
JS_ASSERT(count <= size_t(cx->regs->sp - fp->base() - depth));
JS_ASSERT(depth <= size_t(cx->regs().sp - fp->base()));
JS_ASSERT(count <= size_t(cx->regs().sp - fp->base() - depth));
/* See comments in CheckDestructuring from jsparse.cpp. */
JS_ASSERT(count >= 1);
@ -3350,7 +3330,7 @@ block_getProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp)
uintN index = (uintN) JSID_TO_INT(id);
JS_ASSERT(index < OBJ_BLOCK_COUNT(cx, obj));
JSStackFrame *fp = (JSStackFrame *) obj->getPrivate();
StackFrame *fp = (StackFrame *) obj->getPrivate();
if (fp) {
fp = js_LiveFrameIfGenerator(fp);
index += fp->numFixed() + OBJ_BLOCK_DEPTH(cx, obj);
@ -3371,7 +3351,7 @@ block_setProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *v
uintN index = (uintN) JSID_TO_INT(id);
JS_ASSERT(index < OBJ_BLOCK_COUNT(cx, obj));
JSStackFrame *fp = (JSStackFrame *) obj->getPrivate();
StackFrame *fp = (StackFrame *) obj->getPrivate();
if (fp) {
fp = js_LiveFrameIfGenerator(fp);
index += fp->numFixed() + OBJ_BLOCK_DEPTH(cx, obj);
@ -3976,6 +3956,37 @@ bad:
return NULL;
}
/*
* Lazy standard classes need a way to indicate if they have been initialized.
* Otherwise, when we delete them, we might accidentally recreate them via a
* lazy initialization. We use the presence of a ctor or proto in the
* globalObject's slot to indicate that they've been constructed, but this only
* works for classes which have a proto and ctor. Classes which don't have one
* can call MarkStandardClassInitializedNoProto(), and we can always check
* whether a class is initialized by calling IsStandardClassResolved().
*/
bool
IsStandardClassResolved(JSObject *obj, js::Class *clasp)
{
JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(clasp);
/* If the constructor is undefined, then it hasn't been initialized. */
return (obj->getReservedSlot(key) != UndefinedValue());
}
void
MarkStandardClassInitializedNoProto(JSObject* obj, js::Class *clasp)
{
JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(clasp);
/*
* We use True so that it's obvious what we're doing (instead of, say,
* Null, which might be miscontrued as an error in setting Undefined).
*/
if (obj->getReservedSlot(key) == UndefinedValue())
obj->setSlot(key, BooleanValue(true));
}
}
JSObject *
@ -4227,7 +4238,7 @@ JSBool
js_FindClassObject(JSContext *cx, JSObject *start, JSProtoKey protoKey,
Value *vp, Class *clasp)
{
JSStackFrame *fp;
StackFrame *fp;
JSObject *obj, *cobj, *pobj;
jsid id;
JSProperty *prop;
@ -4945,7 +4956,7 @@ js_LookupPropertyWithFlagsInline(JSContext *cx, JSObject *obj, jsid id, uintN fl
* Non-native objects must have either non-native lookup results,
* or else native results from the non-native's prototype chain.
*
* See JSStackFrame::getValidCalleeObject, where we depend on this
* See StackFrame::getValidCalleeObject, where we depend on this
* fact to force a prototype-delegated joined method accessed via
* arguments.callee through the delegating |this| object's method
* read barrier.
@ -5459,7 +5470,7 @@ js_GetMethod(JSContext *cx, JSObject *obj, jsid id, uintN getHow, Value *vp)
JS_FRIEND_API(bool)
js_CheckUndeclaredVarAssignment(JSContext *cx, JSString *propname)
{
JSStackFrame *const fp = js_GetTopStackFrame(cx);
StackFrame *const fp = js_GetTopStackFrame(cx);
if (!fp)
return true;
@ -5873,7 +5884,7 @@ js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool str
JSFunction *fun = GET_FUNCTION_PRIVATE(cx, funobj);
if (fun != funobj) {
for (JSStackFrame *fp = cx->maybefp(); fp; fp = fp->prev()) {
for (StackFrame *fp = cx->maybefp(); fp; fp = fp->prev()) {
if (fp->isFunctionFrame() &&
fp->callee() == fun->compiledFunObj() &&
fp->thisValue().isObject())
@ -6157,7 +6168,7 @@ js_GetClassPrototype(JSContext *cx, JSObject *scopeobj, JSProtoKey protoKey,
if (protoKey != JSProto_Null) {
if (!scopeobj) {
if (cx->hasfp())
if (cx->running())
scopeobj = &cx->fp()->scopeChain();
if (!scopeobj) {
scopeobj = cx->globalObject;
@ -6205,12 +6216,8 @@ js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto, uintN attrs
JSObject *
PrimitiveToObject(JSContext *cx, const Value &v)
{
if (v.isString()) {
JSObject *obj = NewBuiltinClassInstance(cx, &js_StringClass);
if (!obj || !obj->initString(cx, v.toString()))
return NULL;
return obj;
}
if (v.isString())
return StringObject::create(cx, v.toString());
JS_ASSERT(v.isNumber() || v.isBoolean());
Class *clasp = v.isNumber() ? &js_NumberClass : &js_BooleanClass;
@ -6858,7 +6865,7 @@ MaybeDumpValue(const char *name, const Value &v)
}
JS_FRIEND_API(void)
js_DumpStackFrame(JSContext *cx, JSStackFrame *start)
js_DumpStackFrame(JSContext *cx, StackFrame *start)
{
/* This should only called during live debugging. */
VOUCH_DOES_NOT_REQUIRE_STACK();
@ -6875,9 +6882,9 @@ js_DumpStackFrame(JSContext *cx, JSStackFrame *start)
}
for (; !i.done(); ++i) {
JSStackFrame *const fp = i.fp();
StackFrame *const fp = i.fp();
fprintf(stderr, "JSStackFrame at %p\n", (void *) fp);
fprintf(stderr, "StackFrame at %p\n", (void *) fp);
if (fp->isFunctionFrame()) {
fprintf(stderr, "callee fun: ");
dumpValue(ObjectValue(fp->callee()));

View File

@ -262,6 +262,7 @@ namespace js {
struct NativeIterator;
class RegExp;
class GlobalObject;
class StringObject;
}
@ -330,6 +331,9 @@ struct JSObject : js::gc::Cell {
inline void setLastProperty(const js::Shape *shape);
inline void removeLastProperty();
/* For setLastProperty() only. */
friend class js::StringObject;
#ifdef DEBUG
void checkShapeConsistency();
#endif
@ -477,7 +481,7 @@ struct JSObject : js::gc::Cell {
/* Functions for setting up scope chain object maps and shapes. */
void initCall(JSContext *cx, const js::Bindings &bindings, JSObject *parent);
void initClonedBlock(JSContext *cx, JSObject *proto, JSStackFrame *priv);
void initClonedBlock(JSContext *cx, JSObject *proto, js::StackFrame *priv);
void setBlockOwnShape(JSContext *cx);
void deletingShapeChange(JSContext *cx, const js::Shape &shape);
@ -755,23 +759,8 @@ struct JSObject : js::gc::Cell {
inline const js::Value &getPrimitiveThis() const;
inline void setPrimitiveThis(const js::Value &pthis);
private:
/* 0 is JSSLOT_PRIMITIVE_THIS */
static const uint32 JSSLOT_STRING_LENGTH = 1;
/*
* Compute the initial shape to associate with fresh String objects,
* encoding the initial length property. Return the shape after changing
* this String object's last property to it.
*/
const js::Shape *assignInitialStringShape(JSContext *cx);
public:
static const uint32 STRING_RESERVED_SLOTS = 2;
inline size_t getStringLength() const;
inline bool initString(JSContext *cx, JSString *str);
inline js::StringObject *asString();
/*
* Array-specific getters and setters (for both dense and slow arrays).
@ -916,7 +905,7 @@ struct JSObject : js::gc::Cell {
inline bool callIsForEval() const;
/* The stack frame for this Call object, if the frame is still active. */
inline JSStackFrame *maybeCallObjStackFrame() const;
inline js::StackFrame *maybeCallObjStackFrame() const;
/*
* The callee function if this Call object was created for a function
@ -1416,7 +1405,7 @@ inline bool JSObject::isBlock() const { return getClass() == &js_BlockClass; }
/*
* Block scope object macros. The slots reserved by js_BlockClass are:
*
* private JSStackFrame * active frame pointer or null
* private StackFrame * active frame pointer or null
* JSSLOT_BLOCK_DEPTH int depth of block slots in frame
*
* After JSSLOT_BLOCK_DEPTH come one or more slots for the block locals.
@ -1424,7 +1413,7 @@ inline bool JSObject::isBlock() const { return getClass() == &js_BlockClass; }
* A With object is like a Block object, in that both have one reserved slot
* telling the stack depth of the relevant slots (the slot whose value is the
* object named in the with statement, the slots containing the block's local
* variables); and both have a private slot referring to the JSStackFrame in
* variables); and both have a private slot referring to the StackFrame in
* whose activation they were created (or null if the with or block object
* outlives the frame).
*/
@ -1480,7 +1469,7 @@ extern JSObject *
js_NewBlockObject(JSContext *cx);
extern JSObject *
js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp);
js_CloneBlockObject(JSContext *cx, JSObject *proto, js::StackFrame *fp);
extern JS_REQUIRES_STACK JSBool
js_PutBlockObject(JSContext *cx, JSBool normalUnwind);
@ -1548,6 +1537,13 @@ DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAt
Native constructor, uintN nargs,
JSPropertySpec *ps, JSFunctionSpec *fs,
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
bool
IsStandardClassResolved(JSObject *obj, js::Class *clasp);
void
MarkStandardClassInitializedNoProto(JSObject *obj, js::Class *clasp);
}
extern JSObject *
@ -1912,7 +1908,7 @@ JS_FRIEND_API(void) js_DumpAtom(JSAtom *atom);
JS_FRIEND_API(void) js_DumpObject(JSObject *obj);
JS_FRIEND_API(void) js_DumpValue(const js::Value &val);
JS_FRIEND_API(void) js_DumpId(jsid id);
JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, JSStackFrame *start = NULL);
JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, js::StackFrame *start = NULL);
#endif
extern uintN
@ -1922,7 +1918,6 @@ js_InferFlags(JSContext *cx, uintN defaultFlags);
JSBool
js_Object(JSContext *cx, uintN argc, js::Value *vp);
namespace js {
extern bool

View File

@ -169,7 +169,7 @@ JSObject::initCall(JSContext *cx, const js::Bindings &bindings, JSObject *parent
* shape.
*/
inline void
JSObject::initClonedBlock(JSContext *cx, JSObject *proto, JSStackFrame *frame)
JSObject::initClonedBlock(JSContext *cx, JSObject *proto, js::StackFrame *frame)
{
init(cx, &js_BlockClass, proto, NULL, frame, false);
@ -327,7 +327,7 @@ JSObject::setPrimitiveThis(const js::Value &pthis)
inline /* gc::FinalizeKind */ unsigned
JSObject::finalizeKind() const
{
return js::gc::FinalizeKind(arena()->header()->thingKind);
return js::gc::FinalizeKind(arenaHeader()->getThingKind());
}
inline size_t
@ -509,11 +509,11 @@ JSObject::callIsForEval() const
return getSlot(JSSLOT_CALL_CALLEE).isNull();
}
inline JSStackFrame *
inline js::StackFrame *
JSObject::maybeCallObjStackFrame() const
{
JS_ASSERT(isCall());
return reinterpret_cast<JSStackFrame *>(getPrivate());
return reinterpret_cast<js::StackFrame *>(getPrivate());
}
inline void
@ -881,12 +881,6 @@ JSObject::principals(JSContext *cx)
return compPrincipals;
}
inline JSPrincipals *
JSStackFrame::principals(JSContext *cx) const
{
return scopeChain().principals(cx);
}
inline uint32
JSObject::slotSpan() const
{
@ -1222,7 +1216,7 @@ NewBuiltinClassInstance(JSContext *cx, Class *clasp, gc::FinalizeKind kind)
/* NB: inline-expanded and specialized version of js_GetClassPrototype. */
JSObject *global;
if (!cx->hasfp()) {
if (!cx->running()) {
global = cx->globalObject;
OBJ_TO_INNER_OBJECT(cx, global);
if (!global)
@ -1429,6 +1423,25 @@ NewObjectGCKind(JSContext *cx, js::Class *clasp)
return gc::FINALIZE_OBJECT4;
}
static JS_ALWAYS_INLINE JSObject*
NewObjectWithClassProto(JSContext *cx, Class *clasp, JSObject *proto,
/*gc::FinalizeKind*/ unsigned _kind)
{
JS_ASSERT(clasp->isNative());
gc::FinalizeKind kind = gc::FinalizeKind(_kind);
if (CanBeFinalizedInBackground(kind, clasp))
kind = (gc::FinalizeKind)(kind + 1);
JSObject* obj = js_NewGCObject(cx, kind);
if (!obj)
return NULL;
if (!obj->initSharingEmptyShape(cx, clasp, proto, proto->getParent(), NULL, kind))
return NULL;
return obj;
}
/* Make an object with pregenerated shape from a NEWOBJECT bytecode. */
static inline JSObject *
CopyInitializerObject(JSContext *cx, JSObject *baseobj)

View File

@ -67,6 +67,8 @@
#include "jsobjinlines.h"
#include "jsstrinlines.h"
#include "vm/Stack-inl.h"
using namespace js;
using namespace js::gc;
@ -129,21 +131,19 @@ js_json_parse(JSContext *cx, uintN argc, Value *vp)
return ParseJSONWithReviver(cx, linearStr->chars(), linearStr->length(), reviver, vp);
}
/* ES5 15.12.3. */
JSBool
js_json_stringify(JSContext *cx, uintN argc, Value *vp)
{
Value *argv = vp + 2;
AutoValueRooter space(cx);
AutoObjectRooter replacer(cx);
// Must throw an Error if there isn't a first arg
if (!JS_ConvertArguments(cx, argc, Jsvalify(argv), "v / o v", vp, replacer.addr(), space.addr()))
return JS_FALSE;
*vp = (argc >= 1) ? vp[2] : UndefinedValue();
JSObject *replacer = (argc >= 2 && vp[3].isObject())
? &vp[3].toObject()
: NULL;
Value space = (argc >= 3) ? vp[4] : UndefinedValue();
StringBuffer sb(cx);
if (!js_Stringify(cx, vp, replacer.object(), space.value(), sb))
return JS_FALSE;
if (!js_Stringify(cx, vp, replacer, space, sb))
return false;
// XXX This can never happen to nsJSON.cpp, but the JSON object
// needs to support returning undefined. So this is a little awkward
@ -151,13 +151,13 @@ js_json_stringify(JSContext *cx, uintN argc, Value *vp)
if (!sb.empty()) {
JSString *str = sb.finishString();
if (!str)
return JS_FALSE;
return false;
vp->setString(str);
} else {
vp->setUndefined();
}
return JS_TRUE;
return true;
}
JSBool
@ -179,84 +179,91 @@ js_TryJSON(JSContext *cx, Value *vp)
}
static const char quote = '\"';
static const char backslash = '\\';
static const char unicodeEscape[] = "\\u00";
static JSBool
write_string(JSContext *cx, StringBuffer &sb, const jschar *buf, uint32 len)
static inline bool IsQuoteSpecialCharacter(jschar c)
{
if (!sb.append(quote))
return JS_FALSE;
JS_STATIC_ASSERT('\b' < ' ');
JS_STATIC_ASSERT('\f' < ' ');
JS_STATIC_ASSERT('\n' < ' ');
JS_STATIC_ASSERT('\r' < ' ');
JS_STATIC_ASSERT('\t' < ' ');
return c == '"' || c == '\\' || c < ' ';
}
uint32 mark = 0;
uint32 i;
for (i = 0; i < len; ++i) {
if (buf[i] == quote || buf[i] == backslash) {
if (!sb.append(&buf[mark], i - mark) || !sb.append(backslash) ||
!sb.append(buf[i])) {
return JS_FALSE;
}
mark = i + 1;
} else if (buf[i] <= 31 || buf[i] == 127) {
if (!sb.append(&buf[mark], i - mark) ||
!sb.append(unicodeEscape)) {
return JS_FALSE;
}
char ubuf[3];
size_t len = JS_snprintf(ubuf, sizeof(ubuf), "%.2x", buf[i]);
JS_ASSERT(len == 2);
jschar wbuf[3];
size_t wbufSize = JS_ARRAY_LENGTH(wbuf);
if (!js_InflateStringToBuffer(cx, ubuf, len, wbuf, &wbufSize) ||
!sb.append(wbuf, wbufSize)) {
return JS_FALSE;
}
mark = i + 1;
/* ES5 15.12.3 Quote. */
static bool
Quote(JSContext *cx, StringBuffer &sb, JSString *str)
{
JS::Anchor<JSString *> anchor(str);
size_t len = str->length();
const jschar *buf = str->getChars(cx);
if (!buf)
return false;
/* Step 1. */
if (!sb.append('"'))
return false;
/* Step 2. */
for (size_t i = 0; i < len; ++i) {
/* Batch-append maximal character sequences containing no escapes. */
size_t mark = i;
do {
if (IsQuoteSpecialCharacter(buf[i]))
break;
} while (++i < len);
if (i > mark) {
if (!sb.append(&buf[mark], i - mark))
return false;
if (i == len)
break;
}
jschar c = buf[i];
if (c == '"' || c == '\\') {
if (!sb.append('\\') || !sb.append(c))
return false;
} else if (c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t') {
jschar abbrev = (c == '\b')
? 'b'
: (c == '\f')
? 'f'
: (c == '\n')
? 'n'
: (c == '\r')
? 'r'
: 't';
if (!sb.append('\\') || !sb.append(abbrev))
return false;
mark = i + 1;
} else {
JS_ASSERT(c < ' ');
if (!sb.append("\\u00"))
return false;
JS_ASSERT((c >> 4) < 10);
uint8 x = c >> 4, y = c % 16;
if (!sb.append('0' + x) || !sb.append(y < 10 ? '0' + y : 'a' + (y - 10)))
return false;
}
}
if (mark < len && !sb.append(&buf[mark], len - mark))
return JS_FALSE;
return sb.append(quote);
/* Steps 3-4. */
return sb.append('"');
}
class StringifyContext
{
public:
StringifyContext(JSContext *cx, StringBuffer &sb, JSObject *replacer)
: sb(sb), gap(cx), replacer(replacer), depth(0), objectStack(cx)
public:
StringifyContext(JSContext *cx, StringBuffer &sb, const StringBuffer &gap,
JSObject *replacer, const AutoIdVector &propertyList)
: sb(sb),
gap(gap),
replacer(replacer),
propertyList(propertyList),
depth(0),
objectStack(cx)
{}
bool initializeGap(JSContext *cx, const Value &space) {
AutoValueRooter gapValue(cx, space);
if (space.isObject()) {
JSObject &obj = space.toObject();
Class *clasp = obj.getClass();
if (clasp == &js_NumberClass || clasp == &js_StringClass)
*gapValue.addr() = obj.getPrimitiveThis();
}
if (gapValue.value().isString()) {
if (!gap.append(gapValue.value().toString()))
return false;
if (gap.length() > 10)
gap.resize(10);
} else if (gapValue.value().isNumber()) {
jsdouble d = gapValue.value().isInt32()
? gapValue.value().toInt32()
: js_DoubleToInteger(gapValue.value().toDouble());
d = JS_MIN(10, d);
if (d >= 1 && !gap.appendN(' ', uint32(d)))
return false;
}
return true;
}
bool initializeStack() {
bool init() {
return objectStack.init(16);
}
@ -265,8 +272,9 @@ public:
#endif
StringBuffer &sb;
StringBuffer gap;
JSObject *replacer;
const StringBuffer &gap;
JSObject * const replacer;
const AutoIdVector &propertyList;
uint32 depth;
HashSet<JSObject *> objectStack;
};
@ -336,14 +344,14 @@ PreprocessValue(JSContext *cx, JSObject *holder, jsid key, Value *vp, StringifyC
LeaveTrace(cx);
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, 1, &args))
if (!cx->stack.pushInvokeArgs(cx, 1, &args))
return false;
args.calleev() = toJSON;
args.thisv() = *vp;
args[0] = StringValue(keyStr);
if (!Invoke(cx, args, 0))
if (!Invoke(cx, args))
return false;
*vp = args.rval();
}
@ -359,7 +367,7 @@ PreprocessValue(JSContext *cx, JSObject *holder, jsid key, Value *vp, StringifyC
LeaveTrace(cx);
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, 2, &args))
if (!cx->stack.pushInvokeArgs(cx, 2, &args))
return false;
args.calleev() = ObjectValue(*scx->replacer);
@ -367,7 +375,7 @@ PreprocessValue(JSContext *cx, JSObject *holder, jsid key, Value *vp, StringifyC
args[0] = StringValue(keyStr);
args[1] = *vp;
if (!Invoke(cx, args, 0))
if (!Invoke(cx, args))
return false;
*vp = args.rval();
}
@ -430,44 +438,25 @@ JO(JSContext *cx, JSObject *obj, StringifyContext *scx)
if (!scx->sb.append('{'))
return JS_FALSE;
AutoIdRooter idr(cx);
jsid& id = *idr.addr();
/* Steps 5-7. */
/* XXX Bug 648471: Do this in js_Stringify, rename keySource. */
Value keySource = ObjectValue(*obj);
bool usingWhitelist = false;
// if the replacer is an array, we use the keys from it
if (scx->replacer && JS_IsArrayObject(cx, scx->replacer)) {
usingWhitelist = true;
keySource.setObject(*scx->replacer);
AutoIdVector ids(cx);
const AutoIdVector *props;
if (scx->replacer && !scx->replacer->isCallable()) {
JS_ASSERT(JS_IsArrayObject(cx, scx->replacer));
props = &scx->propertyList;
} else {
JS_ASSERT_IF(scx->replacer, scx->propertyList.length() == 0);
if (!GetPropertyNames(cx, obj, JSITER_OWNONLY, &ids))
return false;
props = &ids;
}
bool wroteMember = false;
AutoIdVector props(cx);
if (!GetPropertyNames(cx, &keySource.toObject(), JSITER_OWNONLY, &props))
return JS_FALSE;
/* My kingdom for not-quite-initialized-from-the-start references. */
const AutoIdVector &propertyList = *props;
/* Steps 8-10, 13. */
for (size_t i = 0, len = props.length(); i < len; i++) {
if (!usingWhitelist) {
if (!js_ValueToStringId(cx, IdToValue(props[i]), &id))
return JS_FALSE;
} else {
// skip non-index properties
jsuint index = 0;
if (!js_IdIsIndex(props[i], &index))
continue;
Value whitelistElement;
if (!scx->replacer->getProperty(cx, props[i], &whitelistElement))
return JS_FALSE;
if (!js_ValueToStringId(cx, whitelistElement, &id))
return JS_FALSE;
}
bool wroteMember = false;
for (size_t i = 0, len = propertyList.length(); i < len; i++) {
/*
* Steps 8a-8b. Note that the call to Str is broken up into 1) getting
* the property; 2) processing for toJSON, calling the replacer, and
@ -475,43 +464,38 @@ JO(JSContext *cx, JSObject *obj, StringifyContext *scx)
* values which process to |undefined|, and 4) stringifying all values
* which pass the filter.
*/
const jsid &id = propertyList[i];
Value outputValue;
if (!obj->getProperty(cx, id, &outputValue))
return JS_FALSE;
return false;
if (!PreprocessValue(cx, obj, id, &outputValue, scx))
return JS_FALSE;
return false;
if (IsFilteredValue(outputValue))
continue;
/* Output a comma unless this is the first member to write. */
if (wroteMember && !scx->sb.append(','))
return JS_FALSE;
return false;
wroteMember = true;
if (!WriteIndent(cx, scx, scx->depth))
return JS_FALSE;
return false;
// Be careful below: this string is weakly rooted!
JSString *s = js_ValueToString(cx, IdToValue(id));
JSString *s = IdToString(cx, id);
if (!s)
return JS_FALSE;
return false;
JS::Anchor<JSString *> anchor(s);
size_t length = s->length();
const jschar *chars = s->getChars(cx);
if (!chars)
return JS_FALSE;
if (!write_string(cx, scx->sb, chars, length) ||
if (!Quote(cx, scx->sb, s) ||
!scx->sb.append(':') ||
!(scx->gap.empty() || scx->sb.append(' ')) ||
!Str(cx, outputValue, scx)) {
return JS_FALSE;
!Str(cx, outputValue, scx))
{
return false;
}
}
if (wroteMember && !WriteIndent(cx, scx, scx->depth - 1))
return JS_FALSE;
return false;
return scx->sb.append('}');
}
@ -611,14 +595,8 @@ Str(JSContext *cx, const Value &v, StringifyContext *scx)
*/
/* Step 8. */
if (v.isString()) {
JSString *str = v.toString();
size_t length = str->length();
const jschar *chars = str->getChars(cx);
if (!chars)
return false;
return write_string(cx, scx->sb, chars, length);
}
if (v.isString())
return Quote(cx, scx->sb, v.toString());
/* Step 5. */
if (v.isNull())
@ -653,27 +631,155 @@ Str(JSContext *cx, const Value &v, StringifyContext *scx)
return ok;
}
/* ES5 15.12.3. */
JSBool
js_Stringify(JSContext *cx, Value *vp, JSObject *replacer, const Value &space,
StringBuffer &sb)
js_Stringify(JSContext *cx, Value *vp, JSObject *replacer, Value space, StringBuffer &sb)
{
StringifyContext scx(cx, sb, replacer);
if (!scx.initializeGap(cx, space) || !scx.initializeStack())
return JS_FALSE;
/*
* Step 4.
*
* The spec algorithm is unhelpfully vague in 15.12.3 step 4b about the
* exact steps taken when the replacer is an array, regarding the exact
* sequence of [[Get]] calls for the array's elements, when its overall
* length is calculated, whether own or own plus inherited properties are
* considered, and so on. A rewrite of the step was proposed in
* <https://mail.mozilla.org/pipermail/es5-discuss/2011-April/003976.html>,
* whose steps are copied below, and which are implemented here.
*
* i. Let PropertyList be an empty internal List.
* ii. Let len be the result of calling the [[Get]] internal method of
* replacer with the argument "length".
* iii. Let i be 0.
* iv. While i < len:
* 1. Let item be undefined.
* 2. Let v be the result of calling the [[Get]] internal method of
* replacer with the argument ToString(i).
* 3. If Type(v) is String then let item be v.
* 4. Else if Type(v) is Number then let item be ToString(v).
* 5. Else if Type(v) is Object then
* a. If the [[Class]] internal property of v is "String" or
* "Number" then let item be ToString(v).
* 6. If item is not undefined and item is not currently an element of
* PropertyList then,
* a. Append item to the end of PropertyList.
* 7. Let i be i + 1.
*/
AutoIdVector propertyList(cx);
if (replacer && JS_IsArrayObject(cx, replacer)) {
/* Step 4b(ii). */
jsuint len;
JS_ALWAYS_TRUE(js_GetLengthProperty(cx, replacer, &len));
if (replacer->isDenseArray())
len = JS_MIN(len, replacer->getDenseArrayCapacity());
JSObject *obj = NewBuiltinClassInstance(cx, &js_ObjectClass);
if (!obj)
return JS_FALSE;
HashSet<jsid> idSet(cx);
if (!idSet.init(len))
return false;
AutoObjectRooter tvr(cx, obj);
/* Step 4b(iii). */
jsuint i = 0;
/* Step 4b(iv). */
for (; i < len; i++) {
/* Step 4b(iv)(2). */
Value v;
if (!replacer->getProperty(cx, INT_TO_JSID(i), &v))
return false;
jsid id;
if (v.isNumber()) {
/* Step 4b(iv)(4). */
int32_t n;
if (v.isNumber() && ValueFitsInInt32(v, &n) && INT_FITS_IN_JSID(n)) {
id = INT_TO_JSID(n);
} else {
if (!js_ValueToStringId(cx, v, &id))
return false;
id = js_CheckForStringIndex(id);
}
} else if (v.isString() ||
(v.isObject() && (v.toObject().isString() || v.toObject().isNumber())))
{
/* Step 4b(iv)(3), 4b(iv)(5). */
if (!js_ValueToStringId(cx, v, &id))
return false;
id = js_CheckForStringIndex(id);
} else {
continue;
}
/* Step 4b(iv)(6). */
HashSet<jsid>::AddPtr p = idSet.lookupForAdd(id);
if (!p) {
/* Step 4b(iv)(6)(a). */
if (!idSet.add(p, id) || !propertyList.append(id))
return false;
}
}
}
/* Step 5. */
if (space.isObject()) {
JSObject &spaceObj = space.toObject();
if (spaceObj.isNumber()) {
jsdouble d;
if (!ValueToNumber(cx, space, &d))
return false;
space = NumberValue(d);
} else if (spaceObj.isString()) {
JSString *str = js_ValueToString(cx, space);
if (!str)
return false;
space = StringValue(str);
}
}
StringBuffer gap(cx);
if (space.isNumber()) {
/* Step 6. */
jsdouble d;
JS_ALWAYS_TRUE(ToInteger(cx, space, &d));
d = JS_MIN(10, d);
if (d >= 1 && !gap.appendN(' ', uint32(d)))
return false;
} else if (space.isString()) {
/* Step 7. */
JSLinearString *str = space.toString()->ensureLinear(cx);
if (!str)
return false;
JS::Anchor<JSString *> anchor(str);
size_t len = JS_MIN(10, space.toString()->length());
if (!gap.append(str->chars(), len))
return false;
} else {
/* Step 8. */
JS_ASSERT(gap.empty());
}
/* Step 9. */
JSObject *wrapper = NewBuiltinClassInstance(cx, &js_ObjectClass);
if (!wrapper)
return false;
/* Step 10. */
jsid emptyId = ATOM_TO_JSID(cx->runtime->atomState.emptyAtom);
if (!obj->defineProperty(cx, emptyId, *vp, NULL, NULL, JSPROP_ENUMERATE))
return JS_FALSE;
if (!js_DefineNativeProperty(cx, wrapper, emptyId, *vp, PropertyStub, StrictPropertyStub,
JSPROP_ENUMERATE, 0, 0, NULL))
{
return false;
}
if (!PreprocessValue(cx, obj, emptyId, vp, &scx))
return JS_FALSE;
/* Step 11. */
StringifyContext scx(cx, sb, gap, replacer, propertyList);
if (!scx.init())
return false;
if (!PreprocessValue(cx, wrapper, emptyId, vp, &scx))
return false;
if (IsFilteredValue(*vp))
return JS_TRUE;
return true;
return Str(cx, *vp, &scx);
}
@ -1397,5 +1503,7 @@ js_InitJSONClass(JSContext *cx, JSObject *obj)
if (!JS_DefineFunctions(cx, JSON, json_static_methods))
return NULL;
MarkStandardClassInitializedNoProto(obj, &js_JSONClass);
return JSON;
}

View File

@ -52,8 +52,8 @@ extern JSObject *
js_InitJSONClass(JSContext *cx, JSObject *obj);
extern JSBool
js_Stringify(JSContext *cx, js::Value *vp, JSObject *replacer,
const js::Value &space, js::StringBuffer &sb);
js_Stringify(JSContext *cx, js::Value *vp, JSObject *replacer, js::Value space,
js::StringBuffer &sb);
extern JSBool js_TryJSON(JSContext *cx, js::Value *vp);

View File

@ -72,7 +72,6 @@
#include "jsstaticcheck.h"
#include "jsvector.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsscriptinlines.h"
#include "jscntxtinlines.h"
@ -311,7 +310,7 @@ js_DumpPC(JSContext *cx)
void *mark = JS_ARENA_MARK(&cx->tempPool);
Sprinter sprinter;
INIT_SPRINTER(cx, &sprinter, &cx->tempPool, 0);
JSBool ok = js_DisassembleAtPC(cx, cx->fp()->script(), true, cx->regs->pc, &sprinter);
JSBool ok = js_DisassembleAtPC(cx, cx->fp()->script(), true, cx->regs().pc, &sprinter);
fprintf(stdout, "%s", sprinter.base);
JS_ARENA_RELEASE(&cx->tempPool, mark);
return ok;
@ -2053,7 +2052,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
token = CodeToken[op];
if (pc + oplen == jp->dvgfence) {
JSStackFrame *fp;
StackFrame *fp;
uint32 format, mode, type;
/*
@ -2915,7 +2914,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
* object that's not a constructor, causing us to be
* called with an intervening frame on the stack.
*/
JSStackFrame *fp = js_GetTopStackFrame(cx);
StackFrame *fp = js_GetTopStackFrame(cx);
if (fp) {
while (!fp->isEvalFrame())
fp = fp->prev();
@ -5088,7 +5087,7 @@ char *
js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v_in,
JSString *fallback)
{
JSStackFrame *fp;
StackFrame *fp;
JSScript *script;
jsbytecode *pc;
@ -5100,12 +5099,12 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v_in,
LeaveTrace(cx);
if (!cx->regs || !cx->regs->fp || !cx->regs->fp->isScriptFrame())
if (!cx->running() || !cx->fp()->isScriptFrame())
goto do_fallback;
fp = cx->regs->fp;
fp = cx->fp();
script = fp->script();
pc = fp->hasImacropc() ? fp->imacropc() : cx->regs->pc;
pc = fp->hasImacropc() ? fp->imacropc() : cx->regs().pc;
JS_ASSERT(script->code <= pc && pc < script->code + script->length);
if (pc < script->main)
@ -5139,7 +5138,7 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v_in,
* it that caused exception, see bug 328664.
*/
Value *stackBase = fp->base();
Value *sp = cx->regs->sp;
Value *sp = cx->regs().sp;
do {
if (sp == stackBase) {
pcdepth = -1;
@ -5167,11 +5166,10 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v_in,
}
{
jsbytecode* basepc = cx->regs->pc;
jsbytecode* basepc = cx->regs().pc;
jsbytecode* savedImacropc = fp->maybeImacropc();
if (savedImacropc) {
JS_ASSERT(cx->hasfp());
cx->regs->pc = savedImacropc;
cx->regs().pc = savedImacropc;
fp->clearImacropc();
}
@ -5186,8 +5184,7 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v_in,
name = DecompileExpression(cx, script, fp->maybeFun(), pc);
if (savedImacropc) {
JS_ASSERT(cx->hasfp());
cx->regs->pc = basepc;
cx->regs().pc = basepc;
fp->setImacropc(savedImacropc);
}
@ -5467,7 +5464,7 @@ ReconstructImacroPCStack(JSContext *cx, JSScript *script,
* Begin with a recursive call back to ReconstructPCStack to pick up
* the state-of-the-world at the *start* of the imacro.
*/
JSStackFrame *fp = js_GetScriptedCaller(cx, NULL);
StackFrame *fp = js_GetScriptedCaller(cx, NULL);
JS_ASSERT(fp->hasImacropc());
intN pcdepth = ReconstructPCStack(cx, script, fp->imacropc(), pcstack);
if (pcdepth < 0)

View File

@ -91,7 +91,6 @@
#endif
#include "jsatominlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsregexpinlines.h"
#include "jsscriptinlines.h"
@ -185,14 +184,14 @@ JSParseNode::clear()
pn_parens = false;
}
Parser::Parser(JSContext *cx, JSPrincipals *prin, JSStackFrame *cfp)
Parser::Parser(JSContext *cx, JSPrincipals *prin, StackFrame *cfp)
: js::AutoGCRooter(cx, PARSER),
context(cx),
aleFreeList(NULL),
tokenStream(cx),
principals(NULL),
callerFrame(cfp),
callerVarObj(cfp ? &cfp->varobj(cx->stack().containingSegment(cfp)) : NULL),
callerVarObj(cfp ? &cx->stack.space().varObjForFrame(cfp) : NULL),
nodeList(NULL),
functionCount(0),
traceListHead(NULL),
@ -891,13 +890,13 @@ SetStaticLevel(JSTreeContext *tc, uintN staticLevel)
/*
* Compile a top-level script.
*/
Compiler::Compiler(JSContext *cx, JSPrincipals *prin, JSStackFrame *cfp)
Compiler::Compiler(JSContext *cx, JSPrincipals *prin, StackFrame *cfp)
: parser(cx, prin, cfp)
{
}
JSScript *
Compiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *callerFrame,
Compiler::compileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerFrame,
JSPrincipals *principals, uint32 tcflags,
const jschar *chars, size_t length,
const char *filename, uintN lineno, JSVersion version,
@ -8762,7 +8761,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot)
return NULL;
JSObject *obj;
if (context->hasfp()) {
if (context->running()) {
obj = RegExp::createObject(context, context->regExpStatics(),
tokenStream.getTokenbuf().begin(),
tokenStream.getTokenbuf().length(),

View File

@ -1048,14 +1048,14 @@ namespace js {
struct Parser : private js::AutoGCRooter
{
JSContext * const context; /* FIXME Bug 551291: use AutoGCRooter::context? */
JSContext *const context; /* FIXME Bug 551291: use AutoGCRooter::context? */
JSAtomListElement *aleFreeList;
void *tempFreeList[NUM_TEMP_FREELISTS];
TokenStream tokenStream;
void *tempPoolMark; /* initial JSContext.tempPool mark */
JSPrincipals *principals; /* principals associated with source */
JSStackFrame *const callerFrame; /* scripted caller frame for eval and dbgapi */
JSObject *const callerVarObj; /* callerFrame's varObj */
StackFrame *const callerFrame; /* scripted caller frame for eval and dbgapi */
JSObject *const callerVarObj; /* callerFrame's varObj */
JSParseNode *nodeList; /* list of recyclable parse-node structs */
uint32 functionCount; /* number of functions in current unit */
JSObjectBox *traceListHead; /* list of parsed object for GC tracing */
@ -1065,7 +1065,7 @@ struct Parser : private js::AutoGCRooter
/* Root atoms and objects allocated for the parsed tree. */
js::AutoKeepAtoms keepAtoms;
Parser(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL);
Parser(JSContext *cx, JSPrincipals *prin = NULL, StackFrame *cfp = NULL);
~Parser();
friend void js::AutoGCRooter::trace(JSTracer *trc);
@ -1238,7 +1238,7 @@ struct Compiler
Parser parser;
GlobalScope *globalScope;
Compiler(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL);
Compiler(JSContext *cx, JSPrincipals *prin = NULL, StackFrame *cfp = NULL);
/*
* Initialize a compiler. Parameters are passed on to init parser.
@ -1255,7 +1255,7 @@ struct Compiler
const char *filename, uintN lineno, JSVersion version);
static JSScript *
compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *callerFrame,
compileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerFrame,
JSPrincipals *principals, uint32 tcflags,
const jschar *chars, size_t length,
const char *filename, uintN lineno, JSVersion version,

View File

@ -135,7 +135,7 @@ PropertyCache::fill(JSContext *cx, JSObject *obj, uintN scopeIndex, uintN protoI
* Optimize the cached vword based on our parameters and the current pc's
* opcode format flags.
*/
pc = cx->regs->pc;
pc = cx->regs().pc;
op = js_GetOpcode(cx, cx->fp()->script(), pc);
cs = &js_CodeSpec[op];
kshape = 0;
@ -324,7 +324,7 @@ PropertyCache::fullTest(JSContext *cx, jsbytecode *pc, JSObject **objp, JSObject
JSObject *obj, *pobj, *tmp;
uint32 vcap;
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
JS_ASSERT(uintN((fp->hasImacropc() ? fp->imacropc() : pc) - fp->script()->code)

View File

@ -1406,7 +1406,7 @@ FixProxy(JSContext *cx, JSObject *proxy, JSBool *bp)
* Make a blank object from the recipe fix provided to us. This must have
* number of fixed slots as the proxy so that we can swap their contents.
*/
gc::FinalizeKind kind = gc::FinalizeKind(proxy->arena()->header()->thingKind);
gc::FinalizeKind kind = gc::FinalizeKind(proxy->arenaHeader()->getThingKind());
JSObject *newborn = NewNonFunction<WithProto::Given>(cx, clasp, proto, parent, kind);
if (!newborn)
return false;
@ -1459,5 +1459,8 @@ js_InitProxyClass(JSContext *cx, JSObject *obj)
}
if (!JS_DefineFunctions(cx, module, static_methods))
return NULL;
MarkStandardClassInitializedNoProto(obj, &js_ProxyClass);
return module;
}

View File

@ -138,12 +138,18 @@ class ExecuteArgsGuard;
class InvokeFrameGuard;
class InvokeArgsGuard;
class InvokeSessionGuard;
class StringBuffer;
class TraceRecorder;
struct TraceMonitor;
class StackSpace;
class FrameRegs;
class StackFrame;
class StackSegment;
class StackSpace;
class ContextStack;
class FrameRegsIter;
class StringBuffer;
class CallReceiver;
class CallArgs;
struct Compiler;
struct Parser;

View File

@ -3314,5 +3314,7 @@ js_InitReflectClass(JSContext *cx, JSObject *obj)
if (!JS_DefineFunctions(cx, Reflect, static_methods))
return NULL;
MarkStandardClassInitializedNoProto(obj, &js_ReflectClass);
return Reflect;
}

View File

@ -678,15 +678,8 @@ ExecuteRegExp(JSContext *cx, ExecType execType, uintN argc, Value *vp)
/* Step 5. */
jsdouble i;
if (lastIndex.isInt32()) {
i = lastIndex.toInt32();
} else {
if (lastIndex.isDouble())
i = lastIndex.toDouble();
else if (!ValueToNumber(cx, lastIndex, &i))
return false;
i = js_DoubleToInteger(i);
}
if (!ToInteger(cx, lastIndex, &i))
return false;
/* Steps 6-7 (with sticky extension). */
if (!re->global() && !re->sticky())

View File

@ -49,8 +49,10 @@
#include "jsscope.h"
#include "jsgc.h"
#include "jsgcinlines.h"
#include "vm/StringObject.h"
#include "jscntxtinlines.h"
#include "jsgcinlines.h"
#include "jsobjinlines.h"
inline void
@ -71,7 +73,7 @@ JSObject::getEmptyShape(JSContext *cx, js::Class *aclasp,
if (!emptyShapes) {
emptyShapes = (js::EmptyShape**)
cx->calloc_(sizeof(js::EmptyShape*) * js::gc::JS_FINALIZE_OBJECT_LIMIT);
cx->calloc_(sizeof(js::EmptyShape*) * js::gc::FINALIZE_FUNCTION_AND_OBJECT_LAST);
if (!emptyShapes)
return NULL;
@ -134,34 +136,29 @@ JSObject::extend(JSContext *cx, const js::Shape *shape, bool isDefinitelyAtom)
updateShape(cx);
}
namespace js {
inline bool
JSObject::initString(JSContext *cx, JSString *str)
StringObject::init(JSContext *cx, JSString *str)
{
JS_ASSERT(isString());
JS_ASSERT(nativeEmpty());
const js::Shape **shapep = &cx->compartment->initialStringShape;
const Shape **shapep = &cx->compartment->initialStringShape;
if (*shapep) {
setLastProperty(*shapep);
} else {
*shapep = assignInitialStringShape(cx);
*shapep = assignInitialShape(cx);
if (!*shapep)
return false;
}
JS_ASSERT(*shapep == lastProperty());
JS_ASSERT(!nativeEmpty());
JS_ASSERT(nativeLookup(ATOM_TO_JSID(cx->runtime->atomState.lengthAtom))->slot == LENGTH_SLOT);
JS_ASSERT(nativeLookup(ATOM_TO_JSID(cx->runtime->atomState.lengthAtom))->slot ==
JSObject::JSSLOT_STRING_LENGTH);
setPrimitiveThis(js::StringValue(str));
JS_ASSERT(str->length() <= JSString::MAX_LENGTH);
setSlot(JSSLOT_STRING_LENGTH, js::Int32Value(int32(str->length())));
setStringThis(str);
return true;
}
namespace js {
inline
Shape::Shape(jsid id, js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot, uintN attrs,
uintN flags, intN shortid, uint32 shape, uint32 slotSpan)

View File

@ -68,7 +68,6 @@
#endif
#include "methodjit/MethodJIT.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsscriptinlines.h"
@ -1225,7 +1224,7 @@ JSScript::NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natom
script->compartment = cx->compartment;
#ifdef CHECK_SCRIPT_OWNER
script->owner = cx->thread;
script->owner = cx->thread();
#endif
JS_APPEND_LINK(&script->links, &cx->compartment->scripts);
@ -1470,7 +1469,7 @@ DestroyScript(JSContext *cx, JSScript *script)
JS_PROPERTY_CACHE(cx).purgeForScript(cx, script);
#ifdef CHECK_SCRIPT_OWNER
JS_ASSERT(script->owner == cx->thread);
JS_ASSERT(script->owner == cx->thread());
#endif
}
@ -1646,7 +1645,7 @@ js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc)
}
uintN
js_FramePCToLineNumber(JSContext *cx, JSStackFrame *fp)
js_FramePCToLineNumber(JSContext *cx, StackFrame *fp)
{
return js_PCToLineNumber(cx, fp->script(),
fp->hasImacropc() ? fp->imacropc() : fp->pc(cx));
@ -1662,7 +1661,7 @@ js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc)
jssrcnote *sn;
JSSrcNoteType type;
/* Cope with JSStackFrame.pc value prior to entering js_Interpret. */
/* Cope with StackFrame.pc value prior to entering js_Interpret. */
if (!pc)
return 0;
@ -1767,12 +1766,12 @@ js_GetScriptLineExtent(JSScript *script)
const char *
js::CurrentScriptFileAndLineSlow(JSContext *cx, uintN *linenop)
{
if (!cx->hasfp()) {
if (!cx->running()) {
*linenop = 0;
return NULL;
}
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
while (fp->isDummyFrame())
fp = fp->prev();

View File

@ -738,7 +738,7 @@ js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc);
* fp->imacpc may be non-null, indicating an active imacro.
*/
extern uintN
js_FramePCToLineNumber(JSContext *cx, JSStackFrame *fp);
js_FramePCToLineNumber(JSContext *cx, js::StackFrame *fp);
extern uintN
js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);

View File

@ -102,9 +102,9 @@ inline const char *
CurrentScriptFileAndLine(JSContext *cx, uintN *linenop, LineOption opt)
{
if (opt == CALLED_FROM_JSOP_EVAL) {
JS_ASSERT(*cx->regs->pc == JSOP_EVAL);
JS_ASSERT(*(cx->regs->pc + JSOP_EVAL_LENGTH) == JSOP_LINENO);
*linenop = GET_UINT16(cx->regs->pc + JSOP_EVAL_LENGTH);
JS_ASSERT(*cx->regs().pc == JSOP_EVAL);
JS_ASSERT(*(cx->regs().pc + JSOP_EVAL_LENGTH) == JSOP_LINENO);
*linenop = GET_UINT16(cx->regs().pc + JSOP_EVAL_LENGTH);
return cx->fp()->script()->filename;
}

View File

@ -76,13 +76,14 @@
#include "jsvector.h"
#include "jsversion.h"
#include "jscntxtinlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsregexpinlines.h"
#include "jsstrinlines.h"
#include "jsautooplen.h" // generated headers last
#include "vm/StringObject-inl.h"
using namespace js;
using namespace js::gc;
@ -90,7 +91,7 @@ using namespace js::gc;
bool
JSString::isShort() const
{
bool is_short = arena()->header()->thingKind == FINALIZE_SHORT_STRING;
bool is_short = arenaHeader()->getThingKind() == FINALIZE_SHORT_STRING;
JS_ASSERT_IF(is_short, isFlat());
return is_short;
}
@ -105,7 +106,7 @@ JSString::isFixed() const
bool
JSString::isExternal() const
{
bool is_external = arena()->header()->thingKind == FINALIZE_EXTERNAL_STRING;
bool is_external = arenaHeader()->getThingKind() == FINALIZE_EXTERNAL_STRING;
JS_ASSERT_IF(is_external, isFixed());
return is_external;
}
@ -750,7 +751,7 @@ str_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
Class js_StringClass = {
js_String_str,
JSCLASS_HAS_RESERVED_SLOTS(JSObject::STRING_RESERVED_SLOTS) |
JSCLASS_HAS_RESERVED_SLOTS(StringObject::RESERVED_SLOTS) |
JSCLASS_NEW_RESOLVE | JSCLASS_HAS_CACHED_PROTO(JSProto_String),
PropertyStub, /* addProperty */
PropertyStub, /* delProperty */
@ -882,11 +883,8 @@ ValueToIntegerRange(JSContext *cx, const Value &v, int32 *out)
*out = v.toInt32();
} else {
double d;
if (!ValueToNumber(cx, v, &d))
if (!ToInteger(cx, v, &d))
return false;
d = js_DoubleToInteger(d);
if (d > INT32_MAX)
*out = INT32_MAX;
else if (d < INT32_MIN)
@ -1086,14 +1084,9 @@ js_str_charAt(JSContext *cx, uintN argc, Value *vp)
if (!str)
return false;
double d;
if (argc == 0) {
d = 0.0;
} else {
if (!ValueToNumber(cx, vp[2], &d))
return false;
d = js_DoubleToInteger(d);
}
double d = 0.0;
if (argc > 0 && !ToInteger(cx, vp[2], &d))
return false;
if (d < 0 || str->length() <= d)
goto out_of_range;
@ -1126,14 +1119,9 @@ js_str_charCodeAt(JSContext *cx, uintN argc, Value *vp)
if (!str)
return false;
double d;
if (argc == 0) {
d = 0.0;
} else {
if (!ValueToNumber(cx, vp[2], &d))
return false;
d = js_DoubleToInteger(d);
}
double d = 0.0;
if (argc > 0 && !ToInteger(cx, vp[2], &d))
return false;
if (d < 0 || str->length() <= d)
goto out_of_range;
@ -1468,9 +1456,8 @@ str_indexOf(JSContext *cx, uintN argc, Value *vp)
}
} else {
jsdouble d;
if (!ValueToNumber(cx, vp[3], &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (!ToInteger(cx, vp[3], &d))
return false;
if (d <= 0) {
start = 0;
} else if (d > textlen) {
@ -2452,7 +2439,7 @@ str_replace_flat_lambda(JSContext *cx, uintN argc, Value *vp, ReplaceData &rdata
/* lambda(matchStr, matchStart, textstr) */
static const uint32 lambdaArgc = 3;
if (!cx->stack().pushInvokeArgs(cx, lambdaArgc, &rdata.singleShot))
if (!cx->stack.pushInvokeArgs(cx, lambdaArgc, &rdata.singleShot))
return false;
CallArgs &args = rdata.singleShot;
@ -2464,7 +2451,7 @@ str_replace_flat_lambda(JSContext *cx, uintN argc, Value *vp, ReplaceData &rdata
sp[1].setInt32(fm.match());
sp[2].setString(rdata.str);
if (!Invoke(cx, rdata.singleShot, 0))
if (!Invoke(cx, rdata.singleShot))
return false;
JSString *repstr = js_ValueToString(cx, args.rval());
@ -2995,9 +2982,8 @@ str_slice(JSContext *cx, uintN argc, Value *vp)
if (argc != 0) {
double begin, end, length;
if (!ValueToNumber(cx, vp[2], &begin))
return JS_FALSE;
begin = js_DoubleToInteger(begin);
if (!ToInteger(cx, vp[2], &begin))
return false;
length = str->length();
if (begin < 0) {
begin += length;
@ -3010,9 +2996,8 @@ str_slice(JSContext *cx, uintN argc, Value *vp)
if (argc == 1 || vp[3].isUndefined()) {
end = length;
} else {
if (!ValueToNumber(cx, vp[3], &end))
return JS_FALSE;
end = js_DoubleToInteger(end);
if (!ToInteger(cx, vp[3], &end))
return false;
if (end < 0) {
end += length;
if (end < 0)
@ -3471,10 +3456,10 @@ js_String(JSContext *cx, uintN argc, Value *vp)
}
if (IsConstructing(vp)) {
JSObject *obj = NewBuiltinClassInstance(cx, &js_StringClass);
if (!obj || !obj->initString(cx, str))
StringObject *strobj = StringObject::create(cx, str);
if (!strobj)
return false;
vp->setObject(*obj);
vp->setObject(*strobj);
} else {
vp->setString(str);
}
@ -3538,14 +3523,13 @@ static JSFunctionSpec string_static_methods[] = {
};
const Shape *
JSObject::assignInitialStringShape(JSContext *cx)
StringObject::assignInitialShape(JSContext *cx)
{
JS_ASSERT(!cx->compartment->initialStringShape);
JS_ASSERT(isString());
JS_ASSERT(nativeEmpty());
return addDataProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.lengthAtom),
JSSLOT_STRING_LENGTH, JSPROP_PERMANENT | JSPROP_READONLY);
LENGTH_SLOT, JSPROP_PERMANENT | JSPROP_READONLY);
}
JSObject *
@ -3567,7 +3551,7 @@ js_InitStringClass(JSContext *cx, JSObject *global)
return NULL;
JSObject *proto = NewObject<WithProto::Class>(cx, &js_StringClass, objectProto, global);
if (!proto || !proto->initString(cx, cx->runtime->emptyString))
if (!proto || !proto->asString()->init(cx, cx->runtime->emptyString))
return NULL;
/* Now create the String function. */
@ -3906,6 +3890,8 @@ js::ValueToStringBufferSlow(JSContext *cx, const Value &arg, StringBuffer &sb)
JS_FRIEND_API(JSString *)
js_ValueToSource(JSContext *cx, const Value &v)
{
JS_CHECK_RECURSION(cx, return NULL);
if (v.isUndefined())
return cx->runtime->atomState.void0Atom;
if (v.isString())

View File

@ -551,10 +551,10 @@ inline void
JSAtom::finalize(JSRuntime *rt)
{
JS_ASSERT(isAtom());
if (arena()->header()->thingKind == js::gc::FINALIZE_STRING)
if (arenaHeader()->getThingKind() == js::gc::FINALIZE_STRING)
asFlat().finalize(rt);
else
JS_ASSERT(arena()->header()->thingKind == js::gc::FINALIZE_SHORT_STRING);
JS_ASSERT(arenaHeader()->getThingKind() == js::gc::FINALIZE_SHORT_STRING);
}
inline void

View File

@ -234,142 +234,6 @@ PointerRangeSize(T *begin, T *end)
return (size_t(end) - size_t(begin)) / sizeof(T);
}
/*
* This utility pales in comparison to Boost's aligned_storage. The utility
* simply assumes that JSUint64 is enough alignment for anyone. This may need
* to be extended one day...
*
* As an important side effect, pulling the storage into this template is
* enough obfuscation to confuse gcc's strict-aliasing analysis into not giving
* false negatives when we cast from the char buffer to whatever type we've
* constructed using the bytes.
*/
template <size_t nbytes>
struct AlignedStorage
{
union U {
char bytes[nbytes];
uint64 _;
} u;
const void *addr() const { return u.bytes; }
void *addr() { return u.bytes; }
};
template <class T>
struct AlignedStorage2
{
union U {
char bytes[sizeof(T)];
uint64 _;
} u;
const T *addr() const { return (const T *)u.bytes; }
T *addr() { return (T *)u.bytes; }
};
/*
* Small utility for lazily constructing objects without using dynamic storage.
* When a LazilyConstructed<T> is constructed, it is |empty()|, i.e., no value
* of T has been constructed and no T destructor will be called when the
* LazilyConstructed<T> is destroyed. Upon calling |construct|, a T object will
* be constructed with the given arguments and that object will be destroyed
* when the owning LazilyConstructed<T> is destroyed.
*
* N.B. GCC seems to miss some optimizations with LazilyConstructed and may
* generate extra branches/loads/stores. Use with caution on hot paths.
*/
template <class T>
class LazilyConstructed
{
AlignedStorage2<T> storage;
bool constructed;
T &asT() { return *storage.addr(); }
explicit LazilyConstructed(const LazilyConstructed &other);
const LazilyConstructed &operator=(const LazilyConstructed &other);
public:
LazilyConstructed() { constructed = false; }
~LazilyConstructed() { if (constructed) asT().~T(); }
bool empty() const { return !constructed; }
void construct() {
JS_ASSERT(!constructed);
new(storage.addr()) T();
constructed = true;
}
template <class T1>
void construct(const T1 &t1) {
JS_ASSERT(!constructed);
new(storage.addr()) T(t1);
constructed = true;
}
template <class T1, class T2>
void construct(const T1 &t1, const T2 &t2) {
JS_ASSERT(!constructed);
new(storage.addr()) T(t1, t2);
constructed = true;
}
template <class T1, class T2, class T3>
void construct(const T1 &t1, const T2 &t2, const T3 &t3) {
JS_ASSERT(!constructed);
new(storage.addr()) T(t1, t2, t3);
constructed = true;
}
template <class T1, class T2, class T3, class T4>
void construct(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) {
JS_ASSERT(!constructed);
new(storage.addr()) T(t1, t2, t3, t4);
constructed = true;
}
T *addr() {
JS_ASSERT(constructed);
return &asT();
}
T &ref() {
JS_ASSERT(constructed);
return asT();
}
void destroy() {
ref().~T();
constructed = false;
}
void destroyIfConstructed() {
if (!empty())
destroy();
}
};
/*
* N.B. GCC seems to miss some optimizations with Conditionally and may
* generate extra branches/loads/stores. Use with caution on hot paths.
*/
template <class T>
class Conditionally {
LazilyConstructed<T> t;
public:
Conditionally(bool b) { if (b) t.construct(); }
template <class T1>
Conditionally(bool b, const T1 &t1) { if (b) t.construct(t1); }
template <class T1, class T2>
Conditionally(bool b, const T1 &t1, const T2 &t2) { if (b) t.construct(t1, t2); }
};
template <class T>
class AlignedPtrAndFlag
{

File diff suppressed because it is too large Load Diff

View File

@ -653,7 +653,7 @@ public:
JSScript *entryScript;
/* The stack frame where we started profiling. Only valid while profiling! */
JSStackFrame *entryfp;
StackFrame *entryfp;
/* The bytecode locations of the loop header and the back edge. */
jsbytecode *top, *bottom;
@ -716,12 +716,12 @@ public:
* and how many iterations we execute it.
*/
struct InnerLoop {
JSStackFrame *entryfp;
StackFrame *entryfp;
jsbytecode *top, *bottom;
uintN iters;
InnerLoop() {}
InnerLoop(JSStackFrame *entryfp, jsbytecode *top, jsbytecode *bottom)
InnerLoop(StackFrame *entryfp, jsbytecode *top, jsbytecode *bottom)
: entryfp(entryfp), top(top), bottom(bottom), iters(0) {}
};
@ -772,7 +772,7 @@ public:
return StackValue(false);
}
LoopProfile(TraceMonitor *tm, JSStackFrame *entryfp, jsbytecode *top, jsbytecode *bottom);
LoopProfile(TraceMonitor *tm, StackFrame *entryfp, jsbytecode *top, jsbytecode *bottom);
void reset();
@ -1188,9 +1188,9 @@ class TraceRecorder
JS_REQUIRES_STACK ptrdiff_t nativespOffsetImpl(const void* p) const;
JS_REQUIRES_STACK ptrdiff_t nativespOffset(const Value* p) const;
JS_REQUIRES_STACK void importImpl(tjit::Address addr, const void* p, JSValueType t,
const char *prefix, uintN index, JSStackFrame *fp);
const char *prefix, uintN index, StackFrame *fp);
JS_REQUIRES_STACK void import(tjit::Address addr, const Value* p, JSValueType t,
const char *prefix, uintN index, JSStackFrame *fp);
const char *prefix, uintN index, StackFrame *fp);
JS_REQUIRES_STACK void import(TreeFragment* tree, nanojit::LIns* sp, unsigned stackSlots,
unsigned callDepth, unsigned ngslots, JSValueType* typeMap);
void trackNativeStackUse(unsigned slots);
@ -1265,7 +1265,7 @@ class TraceRecorder
JS_REQUIRES_STACK nanojit::LIns* scopeChain();
JS_REQUIRES_STACK nanojit::LIns* entryScopeChain() const;
JS_REQUIRES_STACK nanojit::LIns* entryFrameIns() const;
JS_REQUIRES_STACK JSStackFrame* frameIfInRange(JSObject* obj, unsigned* depthp = NULL) const;
JS_REQUIRES_STACK StackFrame* frameIfInRange(JSObject* obj, unsigned* depthp = NULL) const;
JS_REQUIRES_STACK RecordingStatus traverseScopeChain(JSObject *obj, nanojit::LIns *obj_ins, JSObject *obj2, nanojit::LIns *&obj2_ins);
JS_REQUIRES_STACK AbortableRecordingStatus scopeChainProp(JSObject* obj, Value*& vp, nanojit::LIns*& ins, NameResult& nr, JSObject **scopeObjp = NULL);
JS_REQUIRES_STACK RecordingStatus callProp(JSObject* obj, JSProperty* shape, jsid id, Value*& vp, nanojit::LIns*& ins, NameResult& nr);
@ -1482,8 +1482,8 @@ class TraceRecorder
JS_REQUIRES_STACK RecordingStatus createThis(JSObject& ctor, nanojit::LIns* ctor_ins,
nanojit::LIns** thisobj_insp);
JS_REQUIRES_STACK RecordingStatus guardCallee(Value& callee);
JS_REQUIRES_STACK JSStackFrame *guardArguments(JSObject *obj, nanojit::LIns* obj_ins,
unsigned *depthp);
JS_REQUIRES_STACK StackFrame *guardArguments(JSObject *obj, nanojit::LIns* obj_ins,
unsigned *depthp);
JS_REQUIRES_STACK nanojit::LIns* guardArgsLengthNotAssigned(nanojit::LIns* argsobj_ins);
JS_REQUIRES_STACK void guardNotHole(nanojit::LIns* argsobj_ins, nanojit::LIns* ids_ins);
JS_REQUIRES_STACK RecordingStatus getClassPrototype(JSObject* ctor,
@ -1683,7 +1683,7 @@ class TraceRecorder
#define TRACE_2(x,a,b) TRACE_ARGS(x, (a, b))
extern JS_REQUIRES_STACK MonitorResult
MonitorLoopEdge(JSContext* cx, uintN& inlineCallCount, JSInterpMode interpMode);
MonitorLoopEdge(JSContext* cx, uintN& inlineCallCount, InterpMode interpMode);
extern JS_REQUIRES_STACK TracePointAction
RecordTracePoint(JSContext*, uintN& inlineCallCount, bool* blacklist);

View File

@ -1236,87 +1236,5 @@ Debug_SetValueRangeToCrashOnTouch(Value *vec, size_t len)
#endif
}
/*
* Abstracts the layout of the (callee,this) receiver pair that is passed to
* natives and scripted functions.
*/
class CallReceiver
{
#ifdef DEBUG
mutable bool usedRval_;
#endif
protected:
Value *argv_;
CallReceiver() {}
CallReceiver(Value *argv) : argv_(argv) {
#ifdef DEBUG
usedRval_ = false;
#endif
}
public:
friend CallReceiver CallReceiverFromVp(Value *);
friend CallReceiver CallReceiverFromArgv(Value *);
Value *base() const { return argv_ - 2; }
JSObject &callee() const { JS_ASSERT(!usedRval_); return argv_[-2].toObject(); }
Value &calleev() const { JS_ASSERT(!usedRval_); return argv_[-2]; }
Value &thisv() const { return argv_[-1]; }
Value &rval() const {
#ifdef DEBUG
usedRval_ = true;
#endif
return argv_[-2];
}
void calleeHasBeenReset() const {
#ifdef DEBUG
usedRval_ = false;
#endif
}
};
JS_ALWAYS_INLINE CallReceiver
CallReceiverFromVp(Value *vp)
{
return CallReceiver(vp + 2);
}
JS_ALWAYS_INLINE CallReceiver
CallReceiverFromArgv(Value *argv)
{
return CallReceiver(argv);
}
/*
* Abstracts the layout of the stack passed to natives from the engine and from
* natives to js::Invoke.
*/
class CallArgs : public CallReceiver
{
uintN argc_;
protected:
CallArgs() {}
CallArgs(uintN argc, Value *argv) : CallReceiver(argv), argc_(argc) {}
public:
friend CallArgs CallArgsFromVp(uintN, Value *);
friend CallArgs CallArgsFromArgv(uintN, Value *);
Value &operator[](unsigned i) const { JS_ASSERT(i < argc_); return argv_[i]; }
Value *argv() const { return argv_; }
uintN argc() const { return argc_; }
};
JS_ALWAYS_INLINE CallArgs
CallArgsFromVp(uintN argc, Value *vp)
{
return CallArgs(argc, vp + 2);
}
JS_ALWAYS_INLINE CallArgs
CallArgsFromArgv(uintN argc, Value *argv)
{
return CallArgs(argc, argv);
}
} /* namespace js */
#endif /* jsvalue_h__ */

View File

@ -385,7 +385,7 @@ AutoCompartment::enter()
JS_ASSERT(scopeChain->isNative());
frame.construct();
if (!context->stack().pushDummyFrame(context, *scopeChain, &frame.ref())) {
if (!context->stack.pushDummyFrame(context, *scopeChain, &frame.ref())) {
context->compartment = origin;
return false;
}

View File

@ -164,8 +164,8 @@ class AutoCompartment
JSObject * const target;
JSCompartment * const destination;
private:
LazilyConstructed<DummyFrameGuard> frame;
JSFrameRegs regs;
Maybe<DummyFrameGuard> frame;
FrameRegs regs;
AutoStringRooter input;
bool entered;

View File

@ -57,7 +57,6 @@
#include "jsfun.h"
#include "jsgc.h"
#include "jsgcmark.h"
#include "jsinterp.h"
#include "jslock.h"
#include "jsnum.h"
#include "jsobj.h"
@ -72,11 +71,11 @@
#include "jsvector.h"
#include "jsatominlines.h"
#include "jscntxtinlines.h"
#include "jsinterpinlines.h"
#include "jsobjinlines.h"
#include "jsstrinlines.h"
#include "vm/Stack-inl.h"
#ifdef DEBUG
#include <string.h> /* for #ifdef DEBUG memset calls */
#endif
@ -1745,7 +1744,7 @@ ParseXMLSource(JSContext *cx, JSString *src)
filename = NULL;
lineno = 1;
if (!i.done()) {
JSStackFrame *fp = i.fp();
StackFrame *fp = i.fp();
op = (JSOp) *i.pc();
if (op == JSOP_TOXML || op == JSOP_TOXMLLIST) {
filename = fp->script()->filename;
@ -7307,8 +7306,7 @@ js_SetDefaultXMLNamespace(JSContext *cx, const Value &v)
if (!ns)
return JS_FALSE;
JSStackFrame *fp = js_GetTopStackFrame(cx);
JSObject &varobj = fp->varobj(cx);
JSObject &varobj = cx->stack.currentVarObj();
if (!varobj.defineProperty(cx, JS_DEFAULT_XML_NAMESPACE_ID, ObjectValue(*ns),
PropertyStub, StrictPropertyStub, JSPROP_PERMANENT)) {
return JS_FALSE;
@ -7386,7 +7384,7 @@ js_ValueToXMLString(JSContext *cx, const Value &v)
JSBool
js_GetAnyName(JSContext *cx, jsid *idp)
{
JSObject *global = cx->hasfp() ? cx->fp()->scopeChain().getGlobal() : cx->globalObject;
JSObject *global = cx->running() ? cx->fp()->scopeChain().getGlobal() : cx->globalObject;
Value v = global->getReservedSlot(JSProto_AnyName);
if (v.isUndefined()) {
JSObject *obj = NewNonFunction<WithProto::Given>(cx, &js_AnyNameClass, NULL, global);
@ -7627,7 +7625,7 @@ js_StepXMLListFilter(JSContext *cx, JSBool initialized)
JSXMLFilter *filter;
LeaveTrace(cx);
sp = Jsvalify(cx->regs->sp);
sp = Jsvalify(cx->regs().sp);
if (!initialized) {
/*
* We haven't iterated yet, so initialize the filter based on the

View File

@ -589,7 +589,7 @@ static const JSC::MacroAssembler::RegisterID JSParamReg_Argc = JSC::SparcRegist
if (frameDepth >= 0) {
// sp = fp->slots() + frameDepth
// regs->sp = sp
addPtr(Imm32(sizeof(JSStackFrame) + frameDepth * sizeof(jsval)),
addPtr(Imm32(sizeof(StackFrame) + frameDepth * sizeof(jsval)),
JSFrameReg,
ClobberInCall);
storePtr(ClobberInCall, FrameAddress(offsetof(VMFrame, regs.sp)));
@ -605,11 +605,11 @@ static const JSC::MacroAssembler::RegisterID JSParamReg_Argc = JSC::SparcRegist
setupInfallibleVMFrame(frameDepth);
/* regs->fp = fp */
storePtr(JSFrameReg, FrameAddress(offsetof(VMFrame, regs.fp)));
storePtr(JSFrameReg, FrameAddress(VMFrame::offsetOfFp));
/* PC -> regs->pc :( */
storePtr(ImmPtr(pc),
FrameAddress(offsetof(VMFrame, regs) + offsetof(JSFrameRegs, pc)));
FrameAddress(offsetof(VMFrame, regs) + offsetof(FrameRegs, pc)));
}
// An infallible VM call is a stub call (taking a VMFrame & and one
@ -753,7 +753,7 @@ static const JSC::MacroAssembler::RegisterID JSParamReg_Argc = Assembler::JSPar
struct FrameFlagsAddress : JSC::MacroAssembler::Address
{
FrameFlagsAddress()
: Address(JSFrameReg, JSStackFrame::offsetOfFlags())
: Address(JSFrameReg, StackFrame::offsetOfFlags())
{}
};

View File

@ -83,7 +83,7 @@ static const char *OpcodeNames[] = {
};
#endif
mjit::Compiler::Compiler(JSContext *cx, JSStackFrame *fp)
mjit::Compiler::Compiler(JSContext *cx, StackFrame *fp)
: BaseCompiler(cx),
fp(fp),
script(fp->script()),
@ -239,7 +239,7 @@ mjit::Compiler::~Compiler()
}
CompileStatus JS_NEVER_INLINE
mjit::TryCompile(JSContext *cx, JSStackFrame *fp)
mjit::TryCompile(JSContext *cx, StackFrame *fp)
{
JS_ASSERT(cx->fp() == fp);
@ -294,7 +294,7 @@ mjit::Compiler::generatePrologue()
Label fastPath = masm.label();
/* Store this early on so slow paths can access it. */
masm.storePtr(ImmPtr(fun), Address(JSFrameReg, JSStackFrame::offsetOfExec()));
masm.storePtr(ImmPtr(fun), Address(JSFrameReg, StackFrame::offsetOfExec()));
{
/*
@ -312,8 +312,8 @@ mjit::Compiler::generatePrologue()
stubcc.masm.move(JSParamReg_Argc, Registers::ArgReg1);
/* Slow path - call the arity check function. Returns new fp. */
stubcc.masm.storePtr(ImmPtr(fun), Address(JSFrameReg, JSStackFrame::offsetOfExec()));
stubcc.masm.storePtr(JSFrameReg, FrameAddress(offsetof(VMFrame, regs.fp)));
stubcc.masm.storePtr(ImmPtr(fun), Address(JSFrameReg, StackFrame::offsetOfExec()));
stubcc.masm.storePtr(JSFrameReg, FrameAddress(VMFrame::offsetOfFp));
OOL_STUBCALL(stubs::FixupArity);
stubcc.masm.move(Registers::ReturnReg, JSFrameReg);
stubcc.crossJump(stubcc.masm.jump(), fastPath);
@ -343,7 +343,7 @@ mjit::Compiler::generatePrologue()
*/
for (uint32 i = 0; i < script->nfixed; i++) {
if (analysis->localHasUseBeforeDef(i) || addTraceHints) {
Address local(JSFrameReg, sizeof(JSStackFrame) + i * sizeof(Value));
Address local(JSFrameReg, sizeof(StackFrame) + i * sizeof(Value));
masm.storeValue(UndefinedValue(), local);
}
}
@ -364,10 +364,11 @@ mjit::Compiler::generatePrologue()
*/
RegisterID t0 = Registers::ReturnReg;
Jump hasScope = masm.branchTest32(Assembler::NonZero,
FrameFlagsAddress(), Imm32(JSFRAME_HAS_SCOPECHAIN));
masm.loadPayload(Address(JSFrameReg, JSStackFrame::offsetOfCallee(fun)), t0);
FrameFlagsAddress(),
Imm32(StackFrame::HAS_SCOPECHAIN));
masm.loadPayload(Address(JSFrameReg, StackFrame::offsetOfCallee(fun)), t0);
masm.loadPtr(Address(t0, offsetof(JSObject, parent)), t0);
masm.storePtr(t0, Address(JSFrameReg, JSStackFrame::offsetOfScopeChain()));
masm.storePtr(t0, Address(JSFrameReg, StackFrame::offsetOfScopeChain()));
hasScope.linkTo(masm.label(), &masm);
}
}
@ -968,12 +969,12 @@ mjit::Compiler::generateMethod()
{
RegisterID reg = frame.allocReg();
masm.load32(FrameFlagsAddress(), reg);
masm.or32(Imm32(JSFRAME_HAS_RVAL), reg);
masm.or32(Imm32(StackFrame::HAS_RVAL), reg);
masm.store32(reg, FrameFlagsAddress());
frame.freeReg(reg);
FrameEntry *fe = frame.peek(-1);
frame.storeTo(fe, Address(JSFrameReg, JSStackFrame::offsetOfReturnValue()), true);
frame.storeTo(fe, Address(JSFrameReg, StackFrame::offsetOfReturnValue()), true);
frame.pop();
}
END_CASE(JSOP_POPV)
@ -2119,7 +2120,7 @@ mjit::Compiler::jsop_getglobal(uint32 index)
void
mjit::Compiler::emitFinalReturn(Assembler &masm)
{
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfncode()), Registers::ReturnReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfNcode()), Registers::ReturnReg);
masm.jump(Registers::ReturnReg);
}
@ -2166,8 +2167,8 @@ mjit::Compiler::loadReturnValue(Assembler *masm, FrameEntry *fe)
if (analysis->usesReturnValue()) {
Jump rvalClear = masm->branchTest32(Assembler::Zero,
FrameFlagsAddress(),
Imm32(JSFRAME_HAS_RVAL));
Address rvalAddress(JSFrameReg, JSStackFrame::offsetOfReturnValue());
Imm32(StackFrame::HAS_RVAL));
Address rvalAddress(JSFrameReg, StackFrame::offsetOfReturnValue());
masm->loadValueAsComponents(rvalAddress, typeReg, dataReg);
rvalClear.linkTo(masm->label(), masm);
}
@ -2184,7 +2185,7 @@ mjit::Compiler::fixPrimitiveReturn(Assembler *masm, FrameEntry *fe)
JS_ASSERT(isConstructing);
bool ool = (masm != &this->masm);
Address thisv(JSFrameReg, JSStackFrame::offsetOfThis(fun));
Address thisv(JSFrameReg, StackFrame::offsetOfThis(fun));
// We can just load |thisv| if either of the following is true:
// (1) There is no explicit return value, AND fp->rval is not used.
@ -2256,8 +2257,8 @@ mjit::Compiler::emitReturn(FrameEntry *fe)
} else {
/* if (hasCallObj() || hasArgsObj()) */
Jump putObjs = masm.branchTest32(Assembler::NonZero,
Address(JSFrameReg, JSStackFrame::offsetOfFlags()),
Imm32(JSFRAME_HAS_CALL_OBJ | JSFRAME_HAS_ARGS_OBJ));
Address(JSFrameReg, StackFrame::offsetOfFlags()),
Imm32(StackFrame::HAS_CALL_OBJ | StackFrame::HAS_ARGS_OBJ));
stubcc.linkExit(putObjs, Uses(frame.frameSlots()));
stubcc.leave();
@ -2338,7 +2339,7 @@ mjit::Compiler::interruptCheckHelper()
* interrupt is on another thread.
*/
stubcc.masm.loadPtr(FrameAddress(offsetof(VMFrame, cx)), reg);
stubcc.masm.loadPtr(Address(reg, offsetof(JSContext, thread)), reg);
stubcc.masm.loadPtr(Address(reg, JSContext::threadOffset()), reg);
Address flag(reg, offsetof(JSThread, data.interruptFlags));
Jump noInterrupt = stubcc.masm.branchTest32(Assembler::Zero, flag);
#endif
@ -2377,16 +2378,16 @@ mjit::Compiler::emitUncachedCall(uint32 argc, bool callingNew)
Jump notCompiled = masm.branchTestPtr(Assembler::Zero, r0, r0);
masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.fp)), JSFrameReg);
masm.loadPtr(FrameAddress(VMFrame::offsetOfFp), JSFrameReg);
callPatch.hasFastNcode = true;
callPatch.fastNcodePatch =
masm.storePtrWithPatch(ImmPtr(NULL),
Address(JSFrameReg, JSStackFrame::offsetOfncode()));
Address(JSFrameReg, StackFrame::offsetOfNcode()));
masm.jump(r0);
callPatch.joinPoint = masm.label();
addReturnSite(callPatch.joinPoint, __LINE__);
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfPrev()), JSFrameReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfPrev()), JSFrameReg);
frame.popn(argc + 2);
frame.takeReg(JSReturnReg_Type);
@ -2460,8 +2461,8 @@ mjit::Compiler::checkCallApplySpeculation(uint32 callImmArgc, uint32 speculatedA
RegisterID r0 = Registers::ReturnReg;
Jump notCompiled = stubcc.masm.branchTestPtr(Assembler::Zero, r0, r0);
stubcc.masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.fp)), JSFrameReg);
Address ncodeAddr(JSFrameReg, JSStackFrame::offsetOfncode());
stubcc.masm.loadPtr(FrameAddress(VMFrame::offsetOfFp), JSFrameReg);
Address ncodeAddr(JSFrameReg, StackFrame::offsetOfNcode());
uncachedCallPatch->hasSlowNcode = true;
uncachedCallPatch->slowNcodePatch = stubcc.masm.storePtrWithPatch(ImmPtr(NULL), ncodeAddr);
@ -2731,11 +2732,11 @@ mjit::Compiler::inlineCallHelper(uint32 callImmArgc, bool callingNew)
stubcc.masm.move(Imm32(callIC.frameSize.staticArgc()), JSParamReg_Argc);
else
stubcc.masm.load32(FrameAddress(offsetof(VMFrame, u.call.dynamicArgc)), JSParamReg_Argc);
stubcc.masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.fp)), JSFrameReg);
stubcc.masm.loadPtr(FrameAddress(VMFrame::offsetOfFp), JSFrameReg);
callPatch.hasSlowNcode = true;
callPatch.slowNcodePatch =
stubcc.masm.storePtrWithPatch(ImmPtr(NULL),
Address(JSFrameReg, JSStackFrame::offsetOfncode()));
Address(JSFrameReg, StackFrame::offsetOfNcode()));
stubcc.masm.jump(Registers::ReturnReg);
/*
@ -2764,7 +2765,7 @@ mjit::Compiler::inlineCallHelper(uint32 callImmArgc, bool callingNew)
uint32 flags = 0;
if (callingNew)
flags |= JSFRAME_CONSTRUCTING;
flags |= StackFrame::CONSTRUCTING;
InlineFrameAssembler inlFrame(masm, callIC, flags);
callPatch.hasFastNcode = true;
@ -2775,7 +2776,7 @@ mjit::Compiler::inlineCallHelper(uint32 callImmArgc, bool callingNew)
addReturnSite(callPatch.joinPoint, __LINE__);
if (lowerFunCallOrApply)
uncachedCallPatch.joinPoint = callIC.joinPoint;
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfPrev()), JSFrameReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfPrev()), JSFrameReg);
/*
* We've placed hotJump, joinPoint and hotPathLabel, and no other labels are located by offset
@ -2818,7 +2819,7 @@ mjit::Compiler::inlineCallHelper(uint32 callImmArgc, bool callingNew)
/*
* This function must be called immediately after any instruction which could
* cause a new JSStackFrame to be pushed and could lead to a new debug trap
* cause a new StackFrame to be pushed and could lead to a new debug trap
* being set. This includes any API callbacks and any scripted or native call.
*/
void
@ -2830,7 +2831,7 @@ mjit::Compiler::addCallSite(const InternalCallSite &site)
void
mjit::Compiler::restoreFrameRegs(Assembler &masm)
{
masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.fp)), JSFrameReg);
masm.loadPtr(FrameAddress(VMFrame::offsetOfFp), JSFrameReg);
}
bool
@ -3163,7 +3164,7 @@ mjit::Compiler::jsop_callprop_generic(JSAtom *atom)
* since a sync will be needed for the upcoming call.
*/
uint32 thisvSlot = frame.localSlots();
Address thisv = Address(JSFrameReg, sizeof(JSStackFrame) + thisvSlot * sizeof(Value));
Address thisv = Address(JSFrameReg, sizeof(StackFrame) + thisvSlot * sizeof(Value));
#if defined JS_NUNBOX32
masm.storeValueFromComponents(pic.typeReg, pic.objReg, thisv);
@ -3622,7 +3623,7 @@ mjit::Compiler::jsop_bindname(JSAtom *atom, bool usePropCache)
pic.fastPathStart = masm.label();
Address parent(pic.objReg, offsetof(JSObject, parent));
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfScopeChain()), pic.objReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfScopeChain()), pic.objReg);
pic.shapeGuard = masm.label();
Jump inlineJump = masm.branchPtr(Assembler::NotEqual, parent, ImmPtr(0));
@ -3689,7 +3690,7 @@ void
mjit::Compiler::jsop_bindname(JSAtom *atom, bool usePropCache)
{
RegisterID reg = frame.allocReg();
Address scopeChain(JSFrameReg, JSStackFrame::offsetOfScopeChain());
Address scopeChain(JSFrameReg, StackFrame::offsetOfScopeChain());
masm.loadPtr(scopeChain, reg);
Address address(reg, offsetof(JSObject, parent));

View File

@ -326,7 +326,7 @@ class Compiler : public BaseCompiler
size_t offsetIndex;
};
JSStackFrame *fp;
StackFrame *fp;
JSScript *script;
JSObject *scopeChain;
JSObject *globalObj;
@ -372,7 +372,7 @@ class Compiler : public BaseCompiler
// follows interpreter usage in JSOP_LENGTH.
enum { LengthAtomIndex = uint32(-2) };
Compiler(JSContext *cx, JSStackFrame *fp);
Compiler(JSContext *cx, StackFrame *fp);
~Compiler();
CompileStatus compile();

View File

@ -733,13 +733,13 @@ FrameState::addressOf(const FrameEntry *fe) const
{
int32 frameOffset = 0;
if (fe >= locals)
frameOffset = JSStackFrame::offsetOfFixed(uint32(fe - locals));
frameOffset = StackFrame::offsetOfFixed(uint32(fe - locals));
else if (fe >= args)
frameOffset = JSStackFrame::offsetOfFormalArg(fun, uint32(fe - args));
frameOffset = StackFrame::offsetOfFormalArg(fun, uint32(fe - args));
else if (fe == this_)
frameOffset = JSStackFrame::offsetOfThis(fun);
frameOffset = StackFrame::offsetOfThis(fun);
else if (fe == callee_)
frameOffset = JSStackFrame::offsetOfCallee(fun);
frameOffset = StackFrame::offsetOfCallee(fun);
JS_ASSERT(frameOffset);
return Address(JSFrameReg, frameOffset);
}

View File

@ -741,13 +741,13 @@ class FrameState
void assertValidRegisterState() const;
#endif
// Return an address, relative to the JSStackFrame, that represents where
// Return an address, relative to the StackFrame, that represents where
// this FrameEntry is stored in memory. Note that this is its canonical
// address, not its backing store. There is no guarantee that the memory
// is coherent.
Address addressOf(const FrameEntry *fe) const;
// Returns an address, relative to the JSStackFrame, that represents where
// Returns an address, relative to the StackFrame, that represents where
// this FrameEntry is backed in memory. This is not necessarily its
// canonical address, but the address for which the payload has been synced
// to memory. The caller guarantees that the payload has been synced.

View File

@ -62,7 +62,7 @@ struct AdjustedFrame {
/*
* This is used for emitting code to inline callee-side frame creation and
* should jit code equivalent to JSStackFrame::initCallFrameCallerHalf.
* should jit code equivalent to StackFrame::initCallFrameCallerHalf.
*
* Once finished, JSFrameReg is advanced to be the new fp.
*/
@ -105,23 +105,23 @@ class InlineFrameAssembler {
DataLabelPtr assemble(void *ncode)
{
JS_ASSERT((flags & ~JSFRAME_CONSTRUCTING) == 0);
JS_ASSERT((flags & ~StackFrame::CONSTRUCTING) == 0);
/* Generate JSStackFrame::initCallFrameCallerHalf. */
/* Generate StackFrame::initCallFrameCallerHalf. */
DataLabelPtr ncodePatch;
if (frameSize.isStatic()) {
uint32 frameDepth = frameSize.staticLocalSlots();
AdjustedFrame newfp(sizeof(JSStackFrame) + frameDepth * sizeof(Value));
AdjustedFrame newfp(sizeof(StackFrame) + frameDepth * sizeof(Value));
Address flagsAddr = newfp.addrOf(JSStackFrame::offsetOfFlags());
masm.store32(Imm32(JSFRAME_FUNCTION | flags), flagsAddr);
Address prevAddr = newfp.addrOf(JSStackFrame::offsetOfPrev());
Address flagsAddr = newfp.addrOf(StackFrame::offsetOfFlags());
masm.store32(Imm32(StackFrame::FUNCTION | flags), flagsAddr);
Address prevAddr = newfp.addrOf(StackFrame::offsetOfPrev());
masm.storePtr(JSFrameReg, prevAddr);
Address ncodeAddr = newfp.addrOf(JSStackFrame::offsetOfncode());
Address ncodeAddr = newfp.addrOf(StackFrame::offsetOfNcode());
ncodePatch = masm.storePtrWithPatch(ImmPtr(ncode), ncodeAddr);
masm.addPtr(Imm32(sizeof(JSStackFrame) + frameDepth * sizeof(Value)), JSFrameReg);
masm.addPtr(Imm32(sizeof(StackFrame) + frameDepth * sizeof(Value)), JSFrameReg);
} else {
/*
* If the frame size is dynamic, then the fast path generated by
@ -134,11 +134,11 @@ class InlineFrameAssembler {
RegisterID newfp = tempRegs.takeAnyReg();
masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.sp)), newfp);
Address flagsAddr(newfp, JSStackFrame::offsetOfFlags());
masm.store32(Imm32(JSFRAME_FUNCTION | flags), flagsAddr);
Address prevAddr(newfp, JSStackFrame::offsetOfPrev());
Address flagsAddr(newfp, StackFrame::offsetOfFlags());
masm.store32(Imm32(StackFrame::FUNCTION | flags), flagsAddr);
Address prevAddr(newfp, StackFrame::offsetOfPrev());
masm.storePtr(JSFrameReg, prevAddr);
Address ncodeAddr(newfp, JSStackFrame::offsetOfncode());
Address ncodeAddr(newfp, StackFrame::offsetOfNcode());
ncodePatch = masm.storePtrWithPatch(ImmPtr(ncode), ncodeAddr);
masm.move(newfp, JSFrameReg);

View File

@ -81,13 +81,13 @@ using ic::Repatcher;
static jsbytecode *
FindExceptionHandler(JSContext *cx)
{
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
JSScript *script = fp->script();
top:
if (cx->isExceptionPending() && JSScript::isValidOffset(script->trynotesOffset)) {
// The PC is updated before every stub call, so we can use it here.
unsigned offset = cx->regs->pc - script->main;
unsigned offset = cx->regs().pc - script->main;
JSTryNoteArray *tnarray = script->trynotes();
for (unsigned i = 0; i < tnarray->length; ++i) {
@ -110,12 +110,12 @@ top:
// bytecode compiler cannot throw, so this is not possible.
if (offset - tn->start > tn->length)
continue;
if (tn->stackDepth > cx->regs->sp - fp->base())
if (tn->stackDepth > cx->regs().sp - fp->base())
continue;
jsbytecode *pc = script->main + tn->start + tn->length;
JSBool ok = js_UnwindScope(cx, tn->stackDepth, JS_TRUE);
JS_ASSERT(cx->regs->sp == fp->base() + tn->stackDepth);
JS_ASSERT(cx->regs().sp == fp->base() + tn->stackDepth);
switch (tn->kind) {
case JSTRY_CATCH:
@ -139,9 +139,9 @@ top:
* Push (true, exception) pair for finally to indicate that
* [retsub] should rethrow the exception.
*/
cx->regs->sp[0].setBoolean(true);
cx->regs->sp[1] = cx->getPendingException();
cx->regs->sp += 2;
cx->regs().sp[0].setBoolean(true);
cx->regs().sp[1] = cx->getPendingException();
cx->regs().sp += 2;
cx->clearPendingException();
return pc;
@ -157,8 +157,8 @@ top:
Value v = cx->getPendingException();
JS_ASSERT(js_GetOpcode(cx, fp->script(), pc) == JSOP_ENDITER);
cx->clearPendingException();
ok = !!js_CloseIterator(cx, &cx->regs->sp[-1].toObject());
cx->regs->sp -= 1;
ok = !!js_CloseIterator(cx, &cx->regs().sp[-1].toObject());
cx->regs().sp -= 1;
if (!ok)
goto top;
cx->setPendingException(v);
@ -176,16 +176,9 @@ top:
static void
InlineReturn(VMFrame &f)
{
JSContext *cx = f.cx;
JSStackFrame *fp = f.regs.fp;
JS_ASSERT(f.fp() != f.entryfp);
JS_ASSERT(!js_IsActiveWithOrBlock(cx, &fp->scopeChain(), 0));
Value *newsp = fp->actualArgs() - 1;
newsp[-1] = fp->returnValue();
cx->stack().popInlineFrame(cx, fp->prev(), newsp);
JS_ASSERT(!js_IsActiveWithOrBlock(f.cx, &f.fp()->scopeChain(), 0));
f.cx->stack.popInlineFrame();
}
void JS_FASTCALL
@ -193,7 +186,7 @@ stubs::SlowCall(VMFrame &f, uint32 argc)
{
Value *vp = f.regs.sp - (argc + 2);
if (!Invoke(f.cx, InvokeArgsAlreadyOnTheStack(vp, argc), 0))
if (!Invoke(f.cx, InvokeArgsAlreadyOnTheStack(argc, vp)))
THROW();
}
@ -203,7 +196,7 @@ stubs::SlowNew(VMFrame &f, uint32 argc)
JSContext *cx = f.cx;
Value *vp = f.regs.sp - (argc + 2);
if (!InvokeConstructor(cx, InvokeArgsAlreadyOnTheStack(vp, argc)))
if (!InvokeConstructor(cx, InvokeArgsAlreadyOnTheStack(argc, vp)))
THROW();
}
@ -212,11 +205,9 @@ stubs::SlowNew(VMFrame &f, uint32 argc)
* on fp->exec.fun.
*/
static inline void
RemovePartialFrame(JSContext *cx, JSStackFrame *fp)
RemovePartialFrame(JSContext *cx, StackFrame *fp)
{
JSStackFrame *prev = fp->prev();
Value *newsp = (Value *)fp;
cx->stack().popInlineFrame(cx, prev, newsp);
cx->stack.popInlineFrame();
}
/*
@ -229,7 +220,8 @@ stubs::HitStackQuota(VMFrame &f)
/* Include space to push another frame. */
uintN nvals = f.fp()->script()->nslots + VALUES_PER_STACK_FRAME;
JS_ASSERT(f.regs.sp == f.fp()->base());
if (f.cx->stack().bumpCommitAndLimit(f.entryfp, f.regs.sp, nvals, &f.stackLimit))
StackSpace &space = f.cx->stack.space();
if (space.bumpLimitWithinQuota(NULL, f.entryfp, f.regs.sp, nvals, &f.stackLimit))
return;
/* Remove the current partially-constructed frame before throwing. */
@ -246,7 +238,7 @@ void * JS_FASTCALL
stubs::FixupArity(VMFrame &f, uint32 nactual)
{
JSContext *cx = f.cx;
JSStackFrame *oldfp = f.fp();
StackFrame *oldfp = f.fp();
JS_ASSERT(nactual != oldfp->numFormalArgs());
@ -261,13 +253,12 @@ stubs::FixupArity(VMFrame &f, uint32 nactual)
void *ncode = oldfp->nativeReturnAddress();
/* Pop the inline frame. */
f.fp() = oldfp->prev();
f.regs.sp = (Value*) oldfp;
f.regs.popPartialFrame((Value *)oldfp);
/* Reserve enough space for a callee frame. */
JSStackFrame *newfp = cx->stack().getInlineFrameWithinLimit(cx, (Value*) oldfp, nactual,
fun, fun->script(), &flags,
f.entryfp, &f.stackLimit);
StackFrame *newfp = cx->stack.getInlineFrameWithinLimit(cx, (Value*) oldfp, nactual,
fun, fun->script(), &flags,
f.entryfp, &f.stackLimit);
if (!newfp) {
/*
* The PC is not coherent with the current frame, so fix it up for
@ -295,7 +286,7 @@ stubs::CompileFunction(VMFrame &f, uint32 nactual)
* compile though because we could throw, so get a full, adjusted frame.
*/
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
StackFrame *fp = f.fp();
/*
* Since we can only use members set by initCallFrameCallerHalf,
@ -312,7 +303,7 @@ stubs::CompileFunction(VMFrame &f, uint32 nactual)
fp->initCallFrameEarlyPrologue(fun, nactual);
if (nactual != fp->numFormalArgs()) {
fp = (JSStackFrame *)FixupArity(f, nactual);
fp = (StackFrame *)FixupArity(f, nactual);
if (!fp)
return NULL;
}
@ -321,9 +312,7 @@ stubs::CompileFunction(VMFrame &f, uint32 nactual)
fp->initCallFrameLatePrologue();
/* These would have been initialized by the prologue. */
f.regs.fp = fp;
f.regs.sp = fp->base();
f.regs.pc = script->code;
f.regs.prepareToRun(fp, script);
if (fun->isHeavyweight() && !js::CreateFunCallObject(cx, fp))
THROWV(NULL);
@ -352,10 +341,9 @@ UncachedInlineCall(VMFrame &f, uint32 flags, void **pret, bool *unjittable, uint
JSScript *newscript = newfun->script();
/* Get pointer to new frame/slots, prepare arguments. */
StackSpace &stack = cx->stack();
JSStackFrame *newfp = stack.getInlineFrameWithinLimit(cx, f.regs.sp, argc,
newfun, newscript, &flags,
f.entryfp, &f.stackLimit);
StackFrame *newfp = cx->stack.getInlineFrameWithinLimit(cx, f.regs.sp, argc,
newfun, newscript, &flags,
f.entryfp, &f.stackLimit);
if (JS_UNLIKELY(!newfp))
return false;
@ -364,8 +352,8 @@ UncachedInlineCall(VMFrame &f, uint32 flags, void **pret, bool *unjittable, uint
SetValueRangeToUndefined(newfp->slots(), newscript->nfixed);
/* Officially push the frame. */
stack.pushInlineFrame(cx, newscript, newfp, &f.regs);
JS_ASSERT(newfp == f.regs.fp);
cx->stack.pushInlineFrame(newscript, newfp, f.regs);
JS_ASSERT(newfp == f.fp());
/* Scope with a call object parented by callee's parent. */
if (newfun->isHeavyweight() && !js::CreateFunCallObject(cx, newfp))
@ -414,10 +402,10 @@ stubs::UncachedNewHelper(VMFrame &f, uint32 argc, UncachedCallResult *ucr)
/* Try to do a fast inline call before the general Invoke path. */
if (IsFunctionObject(*vp, &ucr->fun) && ucr->fun->isInterpretedConstructor()) {
ucr->callee = &vp->toObject();
if (!UncachedInlineCall(f, JSFRAME_CONSTRUCTING, &ucr->codeAddr, &ucr->unjittable, argc))
if (!UncachedInlineCall(f, StackFrame::CONSTRUCTING, &ucr->codeAddr, &ucr->unjittable, argc))
THROW();
} else {
if (!InvokeConstructor(cx, InvokeArgsAlreadyOnTheStack(vp, argc)))
if (!InvokeConstructor(cx, InvokeArgsAlreadyOnTheStack(argc, vp)))
THROW();
}
}
@ -435,13 +423,13 @@ stubs::Eval(VMFrame &f, uint32 argc)
{
Value *vp = f.regs.sp - (argc + 2);
if (!IsBuiltinEvalForScope(&f.regs.fp->scopeChain(), *vp)) {
if (!Invoke(f.cx, InvokeArgsAlreadyOnTheStack(vp, argc), 0))
if (!IsBuiltinEvalForScope(&f.fp()->scopeChain(), *vp)) {
if (!Invoke(f.cx, InvokeArgsAlreadyOnTheStack(argc, vp)))
THROW();
return;
}
JS_ASSERT(f.regs.fp == f.cx->fp());
JS_ASSERT(f.fp() == f.cx->fp());
if (!DirectEval(f.cx, CallArgsFromVp(argc, vp)))
THROW();
@ -473,7 +461,7 @@ stubs::UncachedCallHelper(VMFrame &f, uint32 argc, UncachedCallResult *ucr)
}
}
if (!Invoke(f.cx, InvokeArgsAlreadyOnTheStack(vp, argc), 0))
if (!Invoke(f.cx, InvokeArgsAlreadyOnTheStack(argc, vp)))
THROW();
return;
@ -483,7 +471,7 @@ void JS_FASTCALL
stubs::PutActivationObjects(VMFrame &f)
{
JS_ASSERT(f.fp()->hasCallObj() || f.fp()->hasArgsObj());
js::PutActivationObjects(f.cx, f.fp());
f.fp()->putActivationObjects();
}
extern "C" void *
@ -508,13 +496,13 @@ js_InternalThrow(VMFrame &f)
}
// Make sure sp is up to date.
JS_ASSERT(cx->regs == &f.regs);
JS_ASSERT(&cx->regs() == &f.regs);
// Call the throw hook if necessary
JSThrowHook handler = f.cx->debugHooks->throwHook;
if (handler) {
Value rval;
switch (handler(cx, cx->fp()->script(), cx->regs->pc, Jsvalify(&rval),
switch (handler(cx, cx->fp()->script(), cx->regs().pc, Jsvalify(&rval),
cx->debugHooks->throwHookData)) {
case JSTRAP_ERROR:
cx->clearPendingException();
@ -555,16 +543,16 @@ js_InternalThrow(VMFrame &f)
if (f.entryfp == f.fp())
break;
JS_ASSERT(f.regs.sp == cx->regs->sp);
JS_ASSERT(f.regs.sp == cx->regs().sp);
InlineReturn(f);
}
JS_ASSERT(f.regs.sp == cx->regs->sp);
JS_ASSERT(f.regs.sp == cx->regs().sp);
if (!pc)
return NULL;
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
JSScript *script = fp->script();
return script->nativeCodeForPC(fp->isConstructing(), pc);
}
@ -581,7 +569,7 @@ void JS_FASTCALL
stubs::CreateThis(VMFrame &f, JSObject *proto)
{
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
StackFrame *fp = f.fp();
JSObject *callee = &fp->callee();
JSObject *obj = js_CreateThisForFunctionWithProto(cx, callee, proto);
if (!obj)
@ -610,7 +598,7 @@ stubs::ScriptDebugEpilogue(VMFrame &f)
* handler in the process.
*/
static inline bool
HandleErrorInExcessFrame(VMFrame &f, JSStackFrame *stopFp, bool searchedTopmostFrame = true)
HandleErrorInExcessFrame(VMFrame &f, StackFrame *stopFp, bool searchedTopmostFrame = true)
{
JSContext *cx = f.cx;
@ -621,7 +609,7 @@ HandleErrorInExcessFrame(VMFrame &f, JSStackFrame *stopFp, bool searchedTopmostF
*
* Note that this also guarantees ScriptEpilogue() has been called.
*/
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
if (searchedTopmostFrame) {
/*
* This is a special case meaning that fp->finishedInInterpreter() is
@ -647,7 +635,7 @@ HandleErrorInExcessFrame(VMFrame &f, JSStackFrame *stopFp, bool searchedTopmostF
/* Clear imacros. */
if (fp->hasImacropc()) {
cx->regs->pc = fp->imacropc();
cx->regs().pc = fp->imacropc();
fp->clearImacropc();
}
JS_ASSERT(!fp->hasImacropc());
@ -656,7 +644,7 @@ HandleErrorInExcessFrame(VMFrame &f, JSStackFrame *stopFp, bool searchedTopmostF
if (cx->isExceptionPending()) {
jsbytecode *pc = FindExceptionHandler(cx);
if (pc) {
cx->regs->pc = pc;
cx->regs().pc = pc;
returnOK = true;
break;
}
@ -672,7 +660,7 @@ HandleErrorInExcessFrame(VMFrame &f, JSStackFrame *stopFp, bool searchedTopmostF
InlineReturn(f);
}
JS_ASSERT(&f.regs == cx->regs);
JS_ASSERT(&f.regs == &cx->regs());
JS_ASSERT_IF(!returnOK, cx->fp() == stopFp);
return returnOK;
@ -682,12 +670,12 @@ HandleErrorInExcessFrame(VMFrame &f, JSStackFrame *stopFp, bool searchedTopmostF
static inline void *
AtSafePoint(JSContext *cx)
{
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
if (fp->hasImacropc())
return NULL;
JSScript *script = fp->script();
return script->maybeNativeCodeForPC(fp->isConstructing(), cx->regs->pc);
return script->maybeNativeCodeForPC(fp->isConstructing(), cx->regs().pc);
}
/*
@ -698,13 +686,13 @@ static inline JSBool
PartialInterpret(VMFrame &f)
{
JSContext *cx = f.cx;
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
#ifdef DEBUG
JSScript *script = fp->script();
JS_ASSERT(!fp->finishedInInterpreter());
JS_ASSERT(fp->hasImacropc() ||
!script->maybeNativeCodeForPC(fp->isConstructing(), cx->regs->pc));
!script->maybeNativeCodeForPC(fp->isConstructing(), cx->regs().pc));
#endif
JSBool ok = JS_TRUE;
@ -726,7 +714,7 @@ JS_STATIC_ASSERT(JSOP_NOP == 0);
static inline bool
FrameIsFinished(JSContext *cx)
{
JSOp op = JSOp(*cx->regs->pc);
JSOp op = JSOp(*cx->regs().pc);
return (op == JSOP_RETURN ||
op == JSOP_RETRVAL ||
op == JSOP_STOP)
@ -739,12 +727,12 @@ FrameIsFinished(JSContext *cx)
static inline void
AdvanceReturnPC(JSContext *cx)
{
JS_ASSERT(*cx->regs->pc == JSOP_CALL ||
*cx->regs->pc == JSOP_NEW ||
*cx->regs->pc == JSOP_EVAL ||
*cx->regs->pc == JSOP_FUNCALL ||
*cx->regs->pc == JSOP_FUNAPPLY);
cx->regs->pc += JSOP_CALL_LENGTH;
JS_ASSERT(*cx->regs().pc == JSOP_CALL ||
*cx->regs().pc == JSOP_NEW ||
*cx->regs().pc == JSOP_EVAL ||
*cx->regs().pc == JSOP_FUNCALL ||
*cx->regs().pc == JSOP_FUNAPPLY);
cx->regs().pc += JSOP_CALL_LENGTH;
}
@ -756,7 +744,7 @@ AdvanceReturnPC(JSContext *cx)
* (and faster) to finish frames in C++ even if at a safe point here.
*/
static bool
HandleFinishedFrame(VMFrame &f, JSStackFrame *entryFrame)
HandleFinishedFrame(VMFrame &f, StackFrame *entryFrame)
{
JSContext *cx = f.cx;
@ -791,7 +779,7 @@ HandleFinishedFrame(VMFrame &f, JSStackFrame *entryFrame)
*/
bool returnOK = true;
if (!cx->fp()->finishedInInterpreter()) {
if (JSOp(*cx->regs->pc) == JSOP_RETURN)
if (JSOp(*cx->regs().pc) == JSOP_RETURN)
cx->fp()->setReturnValue(f.regs.sp[-1]);
returnOK = ScriptEpilogue(cx, cx->fp(), true);
@ -821,10 +809,10 @@ HandleFinishedFrame(VMFrame &f, JSStackFrame *entryFrame)
* pushed by a call, that has method JIT'd code.
*/
static bool
EvaluateExcessFrame(VMFrame &f, JSStackFrame *entryFrame)
EvaluateExcessFrame(VMFrame &f, StackFrame *entryFrame)
{
JSContext *cx = f.cx;
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
/*
* A "finished" frame is when the interpreter rested on a STOP,
@ -851,7 +839,7 @@ EvaluateExcessFrame(VMFrame &f, JSStackFrame *entryFrame)
* always leave f.regs.fp == entryFrame.
*/
static bool
FinishExcessFrames(VMFrame &f, JSStackFrame *entryFrame)
FinishExcessFrames(VMFrame &f, StackFrame *entryFrame)
{
JSContext *cx = f.cx;
@ -940,7 +928,7 @@ RunTracer(VMFrame &f)
#endif
{
JSContext *cx = f.cx;
JSStackFrame *entryFrame = f.fp();
StackFrame *entryFrame = f.fp();
TracePointAction tpa;
/* :TODO: nuke PIC? */
@ -989,7 +977,6 @@ RunTracer(VMFrame &f)
// error failures correctly.
JS_ASSERT_IF(cx->isExceptionPending(), tpa == TPA_Error);
f.fp() = cx->fp();
JS_ASSERT(f.fp() == cx->fp());
switch (tpa) {
case TPA_Nothing:

View File

@ -63,7 +63,7 @@ struct Registers {
static const RegisterID ScratchReg = JSC::X86Registers::r11;
#endif
// Register that homes the current JSStackFrame.
// Register that homes the current StackFrame.
#if defined(JS_CPU_X86) || defined(JS_CPU_X64)
static const RegisterID JSFrameReg = JSC::X86Registers::ebx;
#elif defined(JS_CPU_ARM)

View File

@ -57,7 +57,7 @@ static const size_t CALLS_BEFORE_COMPILE = 16;
static const size_t BACKEDGES_BEFORE_COMPILE = 16;
static inline CompileStatus
CanMethodJIT(JSContext *cx, JSScript *script, JSStackFrame *fp, CompileRequest request)
CanMethodJIT(JSContext *cx, JSScript *script, StackFrame *fp, CompileRequest request)
{
if (!cx->methodJitEnabled)
return Compile_Abort;
@ -81,7 +81,7 @@ CanMethodJIT(JSContext *cx, JSScript *script, JSStackFrame *fp, CompileRequest r
* methodjit. If so, we compile the given function.
*/
static inline CompileStatus
CanMethodJITAtBranch(JSContext *cx, JSScript *script, JSStackFrame *fp, jsbytecode *pc)
CanMethodJITAtBranch(JSContext *cx, JSScript *script, StackFrame *fp, jsbytecode *pc)
{
if (!cx->methodJitEnabled)
return Compile_Abort;

View File

@ -62,20 +62,20 @@ js::mjit::CompilerAllocPolicy::CompilerAllocPolicy(JSContext *cx, Compiler &comp
{
}
void
JSStackFrame::methodjitStaticAsserts()
StackFrame::methodjitStaticAsserts()
{
/* Static assert for x86 trampolines in MethodJIT.cpp. */
#if defined(JS_CPU_X86)
JS_STATIC_ASSERT(offsetof(JSStackFrame, rval_) == 0x18);
JS_STATIC_ASSERT(offsetof(JSStackFrame, rval_) + 4 == 0x1C);
JS_STATIC_ASSERT(offsetof(JSStackFrame, ncode_) == 0x14);
JS_STATIC_ASSERT(offsetof(StackFrame, rval_) == 0x18);
JS_STATIC_ASSERT(offsetof(StackFrame, rval_) + 4 == 0x1C);
JS_STATIC_ASSERT(offsetof(StackFrame, ncode_) == 0x14);
/* ARM uses decimal literals. */
JS_STATIC_ASSERT(offsetof(JSStackFrame, rval_) == 24);
JS_STATIC_ASSERT(offsetof(JSStackFrame, rval_) + 4 == 28);
JS_STATIC_ASSERT(offsetof(JSStackFrame, ncode_) == 20);
JS_STATIC_ASSERT(offsetof(StackFrame, rval_) == 24);
JS_STATIC_ASSERT(offsetof(StackFrame, rval_) + 4 == 28);
JS_STATIC_ASSERT(offsetof(StackFrame, ncode_) == 20);
#elif defined(JS_CPU_X64)
JS_STATIC_ASSERT(offsetof(JSStackFrame, rval_) == 0x30);
JS_STATIC_ASSERT(offsetof(JSStackFrame, ncode_) == 0x28);
JS_STATIC_ASSERT(offsetof(StackFrame, rval_) == 0x30);
JS_STATIC_ASSERT(offsetof(StackFrame, ncode_) == 0x28);
#endif
}
@ -119,7 +119,7 @@ extern "C" void JS_FASTCALL
PushActiveVMFrame(VMFrame &f)
{
f.entryfp->script()->compartment->jaegerCompartment->pushActiveFrame(&f);
f.regs.fp->setNativeReturnAddress(JS_FUNC_TO_DATA_PTR(void*, JaegerTrampolineReturn));
f.regs.fp()->setNativeReturnAddress(JS_FUNC_TO_DATA_PTR(void*, JaegerTrampolineReturn));
}
extern "C" void JS_FASTCALL
@ -131,7 +131,8 @@ PopActiveVMFrame(VMFrame &f)
extern "C" void JS_FASTCALL
SetVMFrameRegs(VMFrame &f)
{
f.cx->setCurrentRegs(&f.regs);
/* Restored on exit from EnterMethodJIT. */
f.cx->stack.repointRegs(&f.regs);
}
#if defined(__APPLE__) || (defined(XP_WIN) && !defined(JS_CPU_X64)) || defined(XP_OS2)
@ -140,7 +141,7 @@ SetVMFrameRegs(VMFrame &f)
# define SYMBOL_STRING(name) #name
#endif
JS_STATIC_ASSERT(offsetof(JSFrameRegs, sp) == 0);
JS_STATIC_ASSERT(offsetof(FrameRegs, sp) == 0);
#if defined(__linux__) && defined(JS_CPU_X64)
# define SYMBOL_STRING_RELOC(name) #name "@plt"
@ -179,7 +180,7 @@ JS_STATIC_ASSERT(sizeof(VMFrame) % 16 == 0);
* *** DANGER ***
*/
JS_STATIC_ASSERT(offsetof(VMFrame, savedRBX) == 0x58);
JS_STATIC_ASSERT(offsetof(VMFrame, regs.fp) == 0x38);
JS_STATIC_ASSERT(VMFrame::offsetOfFp == 0x38);
JS_STATIC_ASSERT(JSVAL_TAG_MASK == 0xFFFF800000000000LL);
JS_STATIC_ASSERT(JSVAL_PAYLOAD_MASK == 0x00007FFFFFFFFFFFLL);
@ -284,7 +285,7 @@ SYMBOL_STRING(JaegerThrowpoline) ":" "\n"
* *** DANGER ***
*/
JS_STATIC_ASSERT(offsetof(VMFrame, savedEBX) == 0x2c);
JS_STATIC_ASSERT(offsetof(VMFrame, regs.fp) == 0x1C);
JS_STATIC_ASSERT((VMFrame::offsetOfFp) == 0x1C);
asm (
".text\n"
@ -370,7 +371,7 @@ JS_STATIC_ASSERT(offsetof(VMFrame, savedLR) == (4*19));
JS_STATIC_ASSERT(offsetof(VMFrame, entryfp) == (4*10));
JS_STATIC_ASSERT(offsetof(VMFrame, stackLimit) == (4*9));
JS_STATIC_ASSERT(offsetof(VMFrame, cx) == (4*8));
JS_STATIC_ASSERT(offsetof(VMFrame, regs.fp) == (4*7));
JS_STATIC_ASSERT(VMFrame::offsetOfFp == (4*7));
JS_STATIC_ASSERT(offsetof(VMFrame, unused) == (4*4));
JS_STATIC_ASSERT(offsetof(VMFrame, previous) == (4*3));
@ -520,11 +521,11 @@ SYMBOL_STRING(JaegerStubVeneer) ":" "\n"
* *** DANGER ***
*/
JS_STATIC_ASSERT(offsetof(VMFrame, savedEBX) == 0x2c);
JS_STATIC_ASSERT(offsetof(VMFrame, regs.fp) == 0x1C);
JS_STATIC_ASSERT(VMFrame::offsetOfFp == 0x1C);
extern "C" {
__declspec(naked) JSBool JaegerTrampoline(JSContext *cx, JSStackFrame *fp, void *code,
__declspec(naked) JSBool JaegerTrampoline(JSContext *cx, StackFrame *fp, void *code,
Value *stackLimit)
{
__asm {
@ -615,7 +616,7 @@ extern "C" {
* *** DANGER ***
*/
JS_STATIC_ASSERT(offsetof(VMFrame, savedRBX) == 0x58);
JS_STATIC_ASSERT(offsetof(VMFrame, regs.fp) == 0x38);
JS_STATIC_ASSERT(VMFrame::offsetOfFp == 0x38);
JS_STATIC_ASSERT(JSVAL_TAG_MASK == 0xFFFF800000000000LL);
JS_STATIC_ASSERT(JSVAL_PAYLOAD_MASK == 0x00007FFFFFFFFFFFLL);
@ -660,10 +661,10 @@ JaegerCompartment::Finish()
}
extern "C" JSBool
JaegerTrampoline(JSContext *cx, JSStackFrame *fp, void *code, Value *stackLimit);
JaegerTrampoline(JSContext *cx, StackFrame *fp, void *code, Value *stackLimit);
JSBool
mjit::EnterMethodJIT(JSContext *cx, JSStackFrame *fp, void *code, Value *stackLimit)
mjit::EnterMethodJIT(JSContext *cx, StackFrame *fp, void *code, Value *stackLimit)
{
#ifdef JS_METHODJIT_SPEW
Profiler prof;
@ -674,8 +675,8 @@ mjit::EnterMethodJIT(JSContext *cx, JSStackFrame *fp, void *code, Value *stackLi
prof.start();
#endif
JS_ASSERT(cx->regs->fp == fp);
JSFrameRegs *oldRegs = cx->regs;
JS_ASSERT(cx->fp() == fp);
FrameRegs &oldRegs = cx->regs();
JSBool ok;
{
@ -684,7 +685,8 @@ mjit::EnterMethodJIT(JSContext *cx, JSStackFrame *fp, void *code, Value *stackLi
ok = JaegerTrampoline(cx, fp, code, stackLimit);
}
cx->setCurrentRegs(oldRegs);
/* Undo repointRegs in SetVMFrameRegs. */
cx->stack.repointRegs(&oldRegs);
JS_ASSERT(fp == cx->fp());
/* The trampoline wrote the return value but did not set the HAS_RVAL flag. */
@ -702,11 +704,11 @@ mjit::EnterMethodJIT(JSContext *cx, JSStackFrame *fp, void *code, Value *stackLi
}
static inline JSBool
CheckStackAndEnterMethodJIT(JSContext *cx, JSStackFrame *fp, void *code)
CheckStackAndEnterMethodJIT(JSContext *cx, StackFrame *fp, void *code)
{
JS_CHECK_RECURSION(cx, return false);
Value *stackLimit = cx->stack().getStackLimit(cx);
Value *stackLimit = cx->stack.space().getStackLimit(cx);
if (!stackLimit)
return false;
@ -716,7 +718,7 @@ CheckStackAndEnterMethodJIT(JSContext *cx, JSStackFrame *fp, void *code)
JSBool
mjit::JaegerShot(JSContext *cx)
{
JSStackFrame *fp = cx->fp();
StackFrame *fp = cx->fp();
JSScript *script = fp->script();
JITScript *jit = script->getJIT(fp->isConstructing());
@ -725,7 +727,7 @@ mjit::JaegerShot(JSContext *cx)
AbortRecording(cx, "attempt to enter method JIT while recording");
#endif
JS_ASSERT(cx->regs->pc == script->code);
JS_ASSERT(cx->regs().pc == script->code);
return CheckStackAndEnterMethodJIT(cx, cx->fp(), jit->invokeEntry);
}

View File

@ -107,10 +107,10 @@ struct VMFrame
VMFrame *previous;
void *unused;
JSFrameRegs regs;
FrameRegs regs;
JSContext *cx;
Value *stackLimit;
JSStackFrame *entryfp;
StackFrame *entryfp;
#if defined(JS_CPU_X86)
void *savedEBX;
@ -178,8 +178,13 @@ struct VMFrame
JSRuntime *runtime() { return cx->runtime; }
JSStackFrame *&fp() { return regs.fp; }
StackFrame *fp() { return regs.fp(); }
mjit::JITScript *jit() { return fp()->jit(); }
static const size_t offsetOfFp = 5 * sizeof(void *) + FrameRegs::offsetOfFp;
static void staticAssert() {
JS_STATIC_ASSERT(offsetOfFp == offsetof(VMFrame, regs) + FrameRegs::offsetOfFp);
}
};
#ifdef JS_CPU_ARM
@ -425,7 +430,7 @@ struct JITScript {
* Execute the given mjit code. This is a low-level call and callers must
* provide the same guarantees as JaegerShot/CheckStackAndEnterMethodJIT.
*/
JSBool EnterMethodJIT(JSContext *cx, JSStackFrame *fp, void *code, Value *stackLimit);
JSBool EnterMethodJIT(JSContext *cx, StackFrame *fp, void *code, Value *stackLimit);
/* Execute a method that has been JIT compiled. */
JSBool JaegerShot(JSContext *cx);
@ -445,7 +450,7 @@ void JS_FASTCALL
ProfileStubCall(VMFrame &f);
CompileStatus JS_NEVER_INLINE
TryCompile(JSContext *cx, JSStackFrame *fp);
TryCompile(JSContext *cx, StackFrame *fp);
void
ReleaseScriptCode(JSContext *cx, JSScript *script);

View File

@ -652,7 +652,7 @@ class CallCompiler : public BaseCompiler
Jump hasCode = masm.branchPtr(Assembler::Above, t0, ImmPtr(JS_UNJITTABLE_SCRIPT));
/* Try and compile. On success we get back the nmap pointer. */
masm.storePtr(JSFrameReg, FrameAddress(offsetof(VMFrame, regs.fp)));
masm.storePtr(JSFrameReg, FrameAddress(VMFrame::offsetOfFp));
void *compilePtr = JS_FUNC_TO_DATA_PTR(void *, stubs::CompileFunction);
if (ic.frameSize.isStatic()) {
masm.move(Imm32(ic.frameSize.staticArgc()), Registers::ArgReg1);
@ -661,7 +661,7 @@ class CallCompiler : public BaseCompiler
masm.load32(FrameAddress(offsetof(VMFrame, u.call.dynamicArgc)), Registers::ArgReg1);
masm.fallibleVMCall(compilePtr, script->code, -1);
}
masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.fp)), JSFrameReg);
masm.loadPtr(FrameAddress(VMFrame::offsetOfFp), JSFrameReg);
Jump notCompiled = masm.branchTestPtr(Assembler::Zero, Registers::ReturnReg,
Registers::ReturnReg);
@ -777,7 +777,7 @@ class CallCompiler : public BaseCompiler
JITScript *jit = f.jit();
/* Snapshot the frameDepth before SplatApplyArgs modifies it. */
uintN initialFrameDepth = f.regs.sp - f.regs.fp->slots();
uintN initialFrameDepth = f.regs.sp - f.regs.fp()->slots();
/*
* SplatApplyArgs has not been called, so we call it here before
@ -785,7 +785,7 @@ class CallCompiler : public BaseCompiler
*/
Value *vp;
if (ic.frameSize.isStatic()) {
JS_ASSERT(f.regs.sp - f.regs.fp->slots() == (int)ic.frameSize.staticLocalSlots());
JS_ASSERT(f.regs.sp - f.regs.fp()->slots() == (int)ic.frameSize.staticLocalSlots());
vp = f.regs.sp - (2 + ic.frameSize.staticArgc());
} else {
JS_ASSERT(*f.regs.pc == JSOP_FUNAPPLY && GET_ARGC(f.regs.pc) == 2);
@ -839,18 +839,18 @@ class CallCompiler : public BaseCompiler
RegisterID t0 = tempRegs.takeAnyReg();
/* Store pc. */
masm.storePtr(ImmPtr(cx->regs->pc),
masm.storePtr(ImmPtr(cx->regs().pc),
FrameAddress(offsetof(VMFrame, regs.pc)));
/* Store sp (if not already set by ic::SplatApplyArgs). */
if (ic.frameSize.isStatic()) {
uint32 spOffset = sizeof(JSStackFrame) + initialFrameDepth * sizeof(Value);
uint32 spOffset = sizeof(StackFrame) + initialFrameDepth * sizeof(Value);
masm.addPtr(Imm32(spOffset), JSFrameReg, t0);
masm.storePtr(t0, FrameAddress(offsetof(VMFrame, regs.sp)));
}
/* Store fp. */
masm.storePtr(JSFrameReg, FrameAddress(offsetof(VMFrame, regs.fp)));
masm.storePtr(JSFrameReg, FrameAddress(VMFrame::offsetOfFp));
/* Grab cx. */
#ifdef JS_CPU_X86
@ -868,7 +868,7 @@ class CallCompiler : public BaseCompiler
#endif
MaybeRegisterID argcReg;
if (ic.frameSize.isStatic()) {
uint32 vpOffset = sizeof(JSStackFrame) + (vp - f.regs.fp->slots()) * sizeof(Value);
uint32 vpOffset = sizeof(StackFrame) + (vp - f.regs.fp()->slots()) * sizeof(Value);
masm.addPtr(Imm32(vpOffset), JSFrameReg, vpReg);
} else {
argcReg = tempRegs.takeAnyReg();
@ -972,7 +972,7 @@ class CallCompiler : public BaseCompiler
JSObject *callee = ucr.callee;
JS_ASSERT(callee);
uint32 flags = callingNew ? JSFRAME_CONSTRUCTING : 0;
uint32 flags = callingNew ? StackFrame::CONSTRUCTING : 0;
if (!ic.hit) {
ic.hit = true;
@ -1036,7 +1036,6 @@ ic::NativeNew(VMFrame &f, CallICInfo *ic)
}
static const unsigned MANY_ARGS = 1024;
static const unsigned MIN_SPACE = 500;
static bool
BumpStackFull(VMFrame &f, uintN inc)
@ -1045,12 +1044,8 @@ BumpStackFull(VMFrame &f, uintN inc)
if (inc < MANY_ARGS) {
if (f.regs.sp + inc < f.stackLimit)
return true;
StackSpace &stack = f.cx->stack();
if (!stack.bumpCommitAndLimit(f.entryfp, f.regs.sp, inc, &f.stackLimit)) {
js_ReportOverRecursed(f.cx);
return false;
}
return true;
StackSpace &space = f.cx->stack.space();
return space.bumpLimitWithinQuota(f.cx, f.entryfp, f.regs.sp, inc, &f.stackLimit);
}
/*
@ -1065,20 +1060,8 @@ BumpStackFull(VMFrame &f, uintN inc)
* However, since each apply call must consume at least MANY_ARGS slots,
* this sequence will quickly reach the end of the stack and OOM.
*/
uintN incWithSpace = inc + MIN_SPACE;
Value *bumpedWithSpace = f.regs.sp + incWithSpace;
if (bumpedWithSpace < f.stackLimit)
return true;
StackSpace &stack = f.cx->stack();
if (stack.bumpCommitAndLimit(f.entryfp, f.regs.sp, incWithSpace, &f.stackLimit))
return true;
if (!stack.ensureSpace(f.cx, f.regs.sp, incWithSpace))
return false;
f.stackLimit = bumpedWithSpace;
return true;
StackSpace &space = f.cx->stack.space();
return space.bumpLimit(f.cx, f.entryfp, f.regs.sp, inc, &f.stackLimit);
}
static JS_ALWAYS_INLINE bool
@ -1117,7 +1100,7 @@ ic::SplatApplyArgs(VMFrame &f)
Value *vp = f.regs.sp - 3;
JS_ASSERT(JS_CALLEE(cx, vp).toObject().getFunctionPrivate()->u.n.native == js_fun_apply);
JSStackFrame *fp = f.regs.fp;
StackFrame *fp = f.regs.fp();
if (!fp->hasOverriddenArgs()) {
uintN n;
if (!fp->hasArgsObj()) {

View File

@ -404,8 +404,8 @@ class SetPropCompiler : public PICStubCompiler
{
Address addr(pic.shapeReg, shape->setterOp() == SetCallArg
? JSStackFrame::offsetOfFormalArg(fun, slot)
: JSStackFrame::offsetOfFixed(slot));
? StackFrame::offsetOfFormalArg(fun, slot)
: StackFrame::offsetOfFixed(slot));
masm.storeValue(pic.u.vr, addr);
skipOver = masm.jump();
}
@ -907,7 +907,7 @@ class GetPropCompiler : public PICStubCompiler
* up in the fast path, or put this offset in PICInfo?
*/
uint32 thisvOffset = uint32(f.regs.sp - f.fp()->slots()) - 1;
Address thisv(JSFrameReg, sizeof(JSStackFrame) + thisvOffset * sizeof(Value));
Address thisv(JSFrameReg, sizeof(StackFrame) + thisvOffset * sizeof(Value));
masm.storeValueFromComponents(ImmType(JSVAL_TYPE_STRING),
pic.objReg, thisv);
@ -1247,7 +1247,7 @@ class ScopeNameCompiler : public PICStubCompiler
/* For GETXPROP, the object is already in objReg. */
if (pic.kind == ic::PICInfo::NAME)
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfScopeChain()), pic.objReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfScopeChain()), pic.objReg);
JS_ASSERT(obj == getprop.holder);
JS_ASSERT(getprop.holder == scopeChain->getGlobal());
@ -1315,7 +1315,7 @@ class ScopeNameCompiler : public PICStubCompiler
/* For GETXPROP, the object is already in objReg. */
if (pic.kind == ic::PICInfo::NAME)
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfScopeChain()), pic.objReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfScopeChain()), pic.objReg);
JS_ASSERT(obj == getprop.holder);
JS_ASSERT(getprop.holder != scopeChain->getGlobal());
@ -1352,8 +1352,8 @@ class ScopeNameCompiler : public PICStubCompiler
/* Not-escaped case. */
{
Address addr(pic.shapeReg, kind == ARG ? JSStackFrame::offsetOfFormalArg(fun, slot)
: JSStackFrame::offsetOfFixed(slot));
Address addr(pic.shapeReg, kind == ARG ? StackFrame::offsetOfFormalArg(fun, slot)
: StackFrame::offsetOfFixed(slot));
masm.loadPayload(addr, pic.objReg);
masm.loadTypeTag(addr, pic.shapeReg);
skipOver = masm.jump();
@ -1459,7 +1459,7 @@ class ScopeNameCompiler : public PICStubCompiler
/* Kludge to allow (typeof foo == "undefined") tests. */
disable("property not found");
if (pic.kind == ic::PICInfo::NAME) {
JSOp op2 = js_GetOpcode(cx, script, cx->regs->pc + JSOP_NAME_LENGTH);
JSOp op2 = js_GetOpcode(cx, script, cx->regs().pc + JSOP_NAME_LENGTH);
if (op2 == JSOP_TYPEOF) {
vp->setUndefined();
return true;
@ -1531,7 +1531,7 @@ class BindNameCompiler : public PICStubCompiler
BindNameLabels &labels = pic.bindNameLabels();
/* Guard on the shape of the scope chain. */
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfScopeChain()), pic.objReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfScopeChain()), pic.objReg);
masm.loadShape(pic.objReg, pic.shapeReg);
Jump firstShape = masm.branch32(Assembler::NotEqual, pic.shapeReg,
Imm32(scopeChain->shape()));
@ -1751,7 +1751,7 @@ void JS_FASTCALL
ic::CallProp(VMFrame &f, ic::PICInfo *pic)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
JSScript *script = f.fp()->script();
@ -1850,7 +1850,7 @@ ic::CallProp(VMFrame &f, ic::PICInfo *pic)
}
#if JS_HAS_NO_SUCH_METHOD
if (JS_UNLIKELY(rval.isUndefined()) && regs.sp[-1].isObject()) {
if (JS_UNLIKELY(rval.isPrimitive()) && regs.sp[-1].isObject()) {
regs.sp[-2].setString(pic->atom);
if (!js_OnUnknownMethod(cx, regs.sp - 2))
THROW();
@ -2102,8 +2102,8 @@ GetElementIC::attachGetProp(JSContext *cx, JSObject *obj, const Value &v, jsid i
if (op == JSOP_CALLELEM) {
// Emit a write of |obj| to the top of the stack, before we lose it.
Value *thisVp = &cx->regs->sp[-1];
Address thisSlot(JSFrameReg, JSStackFrame::offsetOfFixed(thisVp - cx->fp()->slots()));
Value *thisVp = &cx->regs().sp[-1];
Address thisSlot(JSFrameReg, StackFrame::offsetOfFixed(thisVp - cx->fp()->slots()));
masm.storeValueFromComponents(ImmType(JSVAL_TYPE_OBJECT), objReg, thisSlot);
}
@ -2369,7 +2369,7 @@ ic::CallElement(VMFrame &f, ic::GetElementIC *ic)
THROW();
#if JS_HAS_NO_SUCH_METHOD
if (JS_UNLIKELY(f.regs.sp[-2].isUndefined()) && thisv.isObject()) {
if (JS_UNLIKELY(f.regs.sp[-2].isPrimitive()) && thisv.isObject()) {
f.regs.sp[-2] = f.regs.sp[-1];
f.regs.sp[-1].setObject(*thisObj);
if (!js_OnUnknownMethod(cx, f.regs.sp - 2))

View File

@ -88,7 +88,7 @@ struct StateRemat {
// representation in a struct or union. This prevents bloating the IC
// structs by an extra 8 bytes in some cases. 16 bits are needed to encode
// the largest local:
// ((UINT16_LIMIT - 1) * sizeof(Value) + sizeof(JSStackFrame),
// ((UINT16_LIMIT - 1) * sizeof(Value) + sizeof(StackFrame),
// And an extra bit for the sign on arguments.
#define MIN_STATE_REMAT_BITS 21
@ -96,7 +96,7 @@ struct StateRemat {
bool inRegister() const { return offset_ >= 0 &&
offset_ <= int32(JSC::MacroAssembler::TotalRegisters); }
bool inMemory() const {
return offset_ >= int32(sizeof(JSStackFrame)) ||
return offset_ >= int32(sizeof(StackFrame)) ||
offset_ < 0;
}

View File

@ -123,8 +123,8 @@ Recompiler::recompile()
Vector<PatchableAddress> normalPatches(cx);
Vector<PatchableAddress> ctorPatches(cx);
JSStackFrame *firstCtorFrame = NULL;
JSStackFrame *firstNormalFrame = NULL;
StackFrame *firstCtorFrame = NULL;
StackFrame *firstNormalFrame = NULL;
// Find all JIT'd stack frames to account for return addresses that will
// need to be patched after recompilation.
@ -133,8 +133,8 @@ Recompiler::recompile()
f = f->previous) {
// Scan all frames owned by this VMFrame.
JSStackFrame *end = f->entryfp->prev();
for (JSStackFrame *fp = f->fp(); fp != end; fp = fp->prev()) {
StackFrame *end = f->entryfp->prev();
for (StackFrame *fp = f->fp(); fp != end; fp = fp->prev()) {
// Remember the latest frame for each type of JIT'd code, so the
// compiler will have a frame to re-JIT from.
if (!firstCtorFrame && fp->script() == script && fp->isConstructing())
@ -198,7 +198,7 @@ Recompiler::saveTraps(JITScript *jit, Vector<CallSite> *sites)
}
bool
Recompiler::recompile(JSStackFrame *fp, Vector<PatchableAddress> &patches,
Recompiler::recompile(StackFrame *fp, Vector<PatchableAddress> &patches,
Vector<CallSite> &sites)
{
/* If we get this far, the script is live, and we better be safe to re-jit. */

View File

@ -98,7 +98,7 @@ private:
PatchableAddress findPatch(JITScript *jit, void **location);
void applyPatch(Compiler& c, PatchableAddress& toPatch);
bool recompile(JSStackFrame *fp, Vector<PatchableAddress> &patches,
bool recompile(StackFrame *fp, Vector<PatchableAddress> &patches,
Vector<CallSite> &sites);
bool saveTraps(JITScript *jit, Vector<CallSite> *sites);
};

View File

@ -411,7 +411,7 @@ void JS_FASTCALL
stubs::GetElem(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value &lref = regs.sp[-2];
Value &rref = regs.sp[-1];
@ -451,7 +451,7 @@ stubs::GetElem(VMFrame &f)
if (arg < obj->getArgsInitialLength()) {
copyFrom = obj->addressOfArgsElement(arg);
if (!copyFrom->isMagic()) {
if (JSStackFrame *afp = (JSStackFrame *) obj->getPrivate())
if (StackFrame *afp = (StackFrame *) obj->getPrivate())
copyFrom = &afp->canonicalActualArg(arg);
goto end_getelem;
}
@ -496,7 +496,7 @@ void JS_FASTCALL
stubs::CallElem(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
/* Find the object on which to look for |this|'s properties. */
Value thisv = regs.sp[-2];
@ -514,7 +514,7 @@ stubs::CallElem(VMFrame &f)
THROW();
#if JS_HAS_NO_SUCH_METHOD
if (JS_UNLIKELY(regs.sp[-2].isUndefined()) && thisv.isObject()) {
if (JS_UNLIKELY(regs.sp[-2].isPrimitive()) && thisv.isObject()) {
regs.sp[-2] = regs.sp[-1];
regs.sp[-1].setObject(*thisObj);
if (!js_OnUnknownMethod(cx, regs.sp - 2))
@ -531,7 +531,7 @@ void JS_FASTCALL
stubs::SetElem(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value &objval = regs.sp[-3];
Value &idval = regs.sp[-2];
@ -691,7 +691,7 @@ stubs::DefFun(VMFrame &f, JSFunction *fun)
JSObject *obj2;
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
StackFrame *fp = f.fp();
/*
* A top-level function defined in Global or Eval code (see ECMA-262
@ -744,7 +744,7 @@ stubs::DefFun(VMFrame &f, JSFunction *fun)
* current scope chain even for the case of function expression statements
* and functions defined by eval inside let or with blocks.
*/
JSObject *parent = &fp->varobj(cx);
JSObject *parent = &cx->stack.currentVarObj();
/* ES5 10.5 (NB: with subsequent errata). */
jsid id = ATOM_TO_JSID(fun->atom);
@ -811,7 +811,7 @@ template void JS_FASTCALL stubs::DefFun<false>(VMFrame &f, JSFunction *fun);
#define RELATIONAL(OP) \
JS_BEGIN_MACRO \
JSContext *cx = f.cx; \
JSFrameRegs &regs = f.regs; \
FrameRegs &regs = f.regs; \
Value rval = regs.sp[-1]; \
Value lval = regs.sp[-2]; \
bool cond; \
@ -879,7 +879,7 @@ static inline bool
StubEqualityOp(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value rval = regs.sp[-1];
Value lval = regs.sp[-2];
@ -1006,7 +1006,7 @@ void JS_FASTCALL
stubs::Add(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value rval = regs.sp[-1];
Value lval = regs.sp[-2];
@ -1078,7 +1078,7 @@ void JS_FASTCALL
stubs::Sub(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
double d1, d2;
if (!ValueToNumber(cx, regs.sp[-2], &d1) ||
!ValueToNumber(cx, regs.sp[-1], &d2)) {
@ -1092,7 +1092,7 @@ void JS_FASTCALL
stubs::Mul(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
double d1, d2;
if (!ValueToNumber(cx, regs.sp[-2], &d1) ||
!ValueToNumber(cx, regs.sp[-1], &d2)) {
@ -1107,7 +1107,7 @@ stubs::Div(VMFrame &f)
{
JSContext *cx = f.cx;
JSRuntime *rt = cx->runtime;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
double d1, d2;
if (!ValueToNumber(cx, regs.sp[-2], &d1) ||
@ -1139,7 +1139,7 @@ void JS_FASTCALL
stubs::Mod(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value &lref = regs.sp[-2];
Value &rref = regs.sp[-1];
@ -1202,7 +1202,7 @@ void JS_FASTCALL
stubs::Trap(VMFrame &f, uint32 trapTypes)
{
Value rval;
jsbytecode *pc = f.cx->regs->pc;
jsbytecode *pc = f.cx->regs().pc;
/*
* Trap may be called for a single-step interrupt trap and/or a
@ -1296,7 +1296,7 @@ void JS_FASTCALL
stubs::InitElem(VMFrame &f, uint32 last)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
/* Pop the element's value into rval. */
JS_ASSERT(regs.sp - f.fp()->base() >= 3);
@ -1836,7 +1836,7 @@ static bool JS_FASTCALL
InlineGetProp(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value *vp = &f.regs.sp[-1];
JSObject *obj = ValueToObject(f.cx, vp);
@ -1913,7 +1913,7 @@ void JS_FASTCALL
stubs::CallProp(VMFrame &f, JSAtom *origAtom)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value lval;
lval = regs.sp[-1];
@ -1994,7 +1994,7 @@ stubs::CallProp(VMFrame &f, JSAtom *origAtom)
}
}
#if JS_HAS_NO_SUCH_METHOD
if (JS_UNLIKELY(rval.isUndefined()) && regs.sp[-1].isObject()) {
if (JS_UNLIKELY(rval.isPrimitive()) && regs.sp[-1].isObject()) {
regs.sp[-2].setString(origAtom);
if (!js_OnUnknownMethod(cx, regs.sp - 2))
THROW();
@ -2005,7 +2005,7 @@ stubs::CallProp(VMFrame &f, JSAtom *origAtom)
void JS_FASTCALL
stubs::Length(VMFrame &f)
{
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
Value *vp = &regs.sp[-1];
if (vp->isString()) {
@ -2042,7 +2042,7 @@ InitPropOrMethod(VMFrame &f, JSAtom *atom, JSOp op)
{
JSContext *cx = f.cx;
JSRuntime *rt = cx->runtime;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
/* Load the property's initial value into rval. */
JS_ASSERT(regs.sp - f.fp()->base() >= 2);
@ -2224,7 +2224,7 @@ JSBool JS_FASTCALL
stubs::InstanceOf(VMFrame &f)
{
JSContext *cx = f.cx;
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
const Value &rref = regs.sp[-1];
if (rref.isPrimitive()) {
@ -2263,7 +2263,7 @@ stubs::ArgCnt(VMFrame &f)
{
JSContext *cx = f.cx;
JSRuntime *rt = cx->runtime;
JSStackFrame *fp = f.fp();
StackFrame *fp = f.fp();
jsid id = ATOM_TO_JSID(rt->atomState.lengthAtom);
f.regs.sp++;
@ -2274,9 +2274,9 @@ stubs::ArgCnt(VMFrame &f)
void JS_FASTCALL
stubs::EnterBlock(VMFrame &f, JSObject *obj)
{
JSFrameRegs &regs = f.regs;
FrameRegs &regs = f.regs;
#ifdef DEBUG
JSStackFrame *fp = f.fp();
StackFrame *fp = f.fp();
#endif
JS_ASSERT(obj->isStaticBlock());
@ -2316,7 +2316,7 @@ void JS_FASTCALL
stubs::LeaveBlock(VMFrame &f, JSObject *blockChain)
{
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
StackFrame *fp = f.fp();
#ifdef DEBUG
JS_ASSERT(blockChain->isStaticBlock());
@ -2552,9 +2552,9 @@ void JS_FASTCALL
stubs::DefVarOrConst(VMFrame &f, JSAtom *atom)
{
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
StackFrame *fp = f.fp();
JSObject *obj = &fp->varobj(cx);
JSObject *obj = &cx->stack.currentVarObj();
JS_ASSERT(!obj->getOps()->defineProperty);
uintN attrs = JSPROP_ENUMERATE;
if (!fp->isEvalFrame())
@ -2598,9 +2598,8 @@ void JS_FASTCALL
stubs::SetConst(VMFrame &f, JSAtom *atom)
{
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
JSObject *obj = &fp->varobj(cx);
JSObject *obj = &cx->stack.currentVarObj();
const Value &ref = f.regs.sp[-1];
if (!obj->defineProperty(cx, ATOM_TO_JSID(atom), ref,
PropertyStub, StrictPropertyStub,

View File

@ -118,20 +118,20 @@ TrampolineCompiler::generateForceReturn(Assembler &masm)
{
/* if (hasArgsObj() || hasCallObj()) stubs::PutActivationObjects() */
Jump noActObjs = masm.branchTest32(Assembler::Zero, FrameFlagsAddress(),
Imm32(JSFRAME_HAS_CALL_OBJ | JSFRAME_HAS_ARGS_OBJ));
Imm32(StackFrame::HAS_CALL_OBJ | StackFrame::HAS_ARGS_OBJ));
masm.fallibleVMCall(JS_FUNC_TO_DATA_PTR(void *, stubs::PutActivationObjects), NULL, 0);
noActObjs.linkTo(masm.label(), &masm);
/* Store any known return value */
masm.loadValueAsComponents(UndefinedValue(), JSReturnReg_Type, JSReturnReg_Data);
Jump rvalClear = masm.branchTest32(Assembler::Zero,
FrameFlagsAddress(), Imm32(JSFRAME_HAS_RVAL));
Address rvalAddress(JSFrameReg, JSStackFrame::offsetOfReturnValue());
FrameFlagsAddress(), Imm32(StackFrame::HAS_RVAL));
Address rvalAddress(JSFrameReg, StackFrame::offsetOfReturnValue());
masm.loadValueAsComponents(rvalAddress, JSReturnReg_Type, JSReturnReg_Data);
rvalClear.linkTo(masm.label(), &masm);
/* Return to the caller */
masm.loadPtr(Address(JSFrameReg, JSStackFrame::offsetOfncode()), Registers::ReturnReg);
masm.loadPtr(Address(JSFrameReg, StackFrame::offsetOfNcode()), Registers::ReturnReg);
masm.jump(Registers::ReturnReg);
return true;
}

View File

@ -43,7 +43,7 @@ extern PopActiveVMFrame:PROC
.CODE
; JSBool JaegerTrampoline(JSContext *cx, JSStackFrame *fp, void *code,
; JSBool JaegerTrampoline(JSContext *cx, StackFrame *fp, void *code,
; Value *stackLimit, void *safePoint);
JaegerTrampoline PROC FRAME
push rbp

View File

@ -44,7 +44,7 @@
.text
.intel_syntax noprefix
# JSBool JaegerTrampoline(JSContext *cx, JSStackFrame *fp, void *code,
# JSBool JaegerTrampoline(JSContext *cx, StackFrame *fp, void *code,
# Value *stackLimit, void *safePoint)#
.globl JaegerTrampoline
.def JaegerTrampoline

View File

@ -37,8 +37,8 @@
.text
/ JSBool JaegerTrampoline(JSContext *cx, JSStackFrame *fp, void *code,
/ JSFrameRegs *regs, uintptr_t inlineCallCount)
/ JSBool JaegerTrampoline(JSContext *cx, StackFrame *fp, void *code,
/ FrameRegs *regs, uintptr_t inlineCallCount)
.global JaegerTrampoline
.type JaegerTrampoline, @function
JaegerTrampoline:

View File

@ -37,8 +37,8 @@
.text
/ JSBool JaegerTrampoline(JSContext *cx, JSStackFrame *fp, void *code,
/ JSFrameRegs *regs, uintptr_t inlineCallCount)
/ JSBool JaegerTrampoline(JSContext *cx, StackFrame *fp, void *code,
/ FrameRegs *regs, uintptr_t inlineCallCount)
.global JaegerTrampoline
.type JaegerTrampoline, @function
JaegerTrampoline:

View File

@ -1800,7 +1800,7 @@ GetTrapArgs(JSContext *cx, uintN argc, jsval *argv, JSScript **scriptp,
uintN intarg;
JSScript *script;
*scriptp = JS_GetScriptedCaller(cx, NULL)->script();
*scriptp = JS_GetFrameScript(cx, JS_GetScriptedCaller(cx, NULL));
*ip = 0;
if (argc != 0) {
v = argv[0];
@ -1823,11 +1823,12 @@ GetTrapArgs(JSContext *cx, uintN argc, jsval *argv, JSScript **scriptp,
}
static JSTrapStatus
TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
TrapHandler(JSContext *cx, JSScript *, jsbytecode *pc, jsval *rval,
jsval closure)
{
JSString *str = JSVAL_TO_STRING(closure);
JSStackFrame *caller = JS_GetScriptedCaller(cx, NULL);
JSScript *script = JS_GetFrameScript(cx, caller);
size_t length;
const jschar *chars = JS_GetStringCharsAndLength(cx, str, &length);
@ -1835,8 +1836,8 @@ TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
return JSTRAP_ERROR;
if (!JS_EvaluateUCInStackFrame(cx, caller, chars, length,
caller->script()->filename,
caller->script()->lineno,
script->filename,
script->lineno,
rval)) {
return JSTRAP_ERROR;
}
@ -1938,7 +1939,7 @@ LineToPC(JSContext *cx, uintN argc, jsval *vp)
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_LINE2PC_USAGE);
return JS_FALSE;
}
script = JS_GetScriptedCaller(cx, NULL)->script();
script = JS_GetFrameScript(cx, JS_GetScriptedCaller(cx, NULL));
if (!GetTrapArgs(cx, argc, JS_ARGV(cx, vp), &script, &i))
return JS_FALSE;
lineno = (i == 0) ? script->lineno : (uintN)i;
@ -3218,7 +3219,8 @@ ResolveClass(JSContext *cx, JSObject *obj, jsid id, JSBool *resolved)
if (!*resolved) {
if (JSID_IS_ATOM(id, CLASS_ATOM(cx, Reflect))) {
if (!js_InitReflectClass(cx, obj))
if (!IsStandardClassResolved(obj, &js_ReflectClass) &&
!js_InitReflectClass(cx, obj))
return JS_FALSE;
*resolved = JS_TRUE;
}
@ -3573,6 +3575,8 @@ EvalInContext(JSContext *cx, uintN argc, jsval *vp)
return true;
JSStackFrame *fp = JS_GetScriptedCaller(cx, NULL);
JSScript *script = JS_GetFrameScript(cx, fp);
jsbytecode *pc = JS_GetFramePC(cx, fp);
{
JSAutoEnterCompartment ac;
uintN flags;
@ -3591,8 +3595,8 @@ EvalInContext(JSContext *cx, uintN argc, jsval *vp)
return false;
}
if (!JS_EvaluateUCScript(cx, sobj, src, srclen,
fp->script()->filename,
JS_PCToLineNumber(cx, fp->script(), fp->pc(cx)),
script->filename,
JS_PCToLineNumber(cx, script, pc),
vp)) {
return false;
}
@ -3618,7 +3622,7 @@ EvalInFrame(JSContext *cx, uintN argc, jsval *vp)
? !!(JSVAL_TO_BOOLEAN(argv[2]))
: false;
JS_ASSERT(cx->hasfp());
JS_ASSERT(cx->running());
FrameRegsIter fi(cx);
for (uint32 i = 0; i < upCount; ++i, ++fi) {
@ -3626,8 +3630,8 @@ EvalInFrame(JSContext *cx, uintN argc, jsval *vp)
break;
}
JSStackFrame *const fp = fi.fp();
if (!JS_IsScriptFrame(cx, fp)) {
StackFrame *const fp = fi.fp();
if (!fp->isScriptFrame()) {
JS_ReportError(cx, "cannot eval in non-script frame");
return JS_FALSE;
}
@ -3641,7 +3645,7 @@ EvalInFrame(JSContext *cx, uintN argc, jsval *vp)
if (!chars)
return JS_FALSE;
JSBool ok = JS_EvaluateUCInStackFrame(cx, fp, chars, length,
JSBool ok = JS_EvaluateUCInStackFrame(cx, Jsvalify(fp), chars, length,
fp->script()->filename,
JS_PCToLineNumber(cx, fp->script(),
fi.pc()),
@ -4463,7 +4467,6 @@ Snarf(JSContext *cx, uintN argc, jsval *vp)
{
JSString *str;
const char *pathname;
JSStackFrame *fp;
if (!argc)
return JS_FALSE;
@ -4476,10 +4479,11 @@ Snarf(JSContext *cx, uintN argc, jsval *vp)
return JS_FALSE;
/* Get the currently executing script's name. */
fp = JS_GetScriptedCaller(cx, NULL);
JS_ASSERT(fp && fp->script()->filename);
JSStackFrame *fp = JS_GetScriptedCaller(cx, NULL);
JSScript *script = JS_GetFrameScript(cx, fp);
JS_ASSERT(fp && script->filename);
#ifdef XP_UNIX
pathname = MakeAbsolutePathname(cx, fp->script()->filename, filename.ptr());
pathname = MakeAbsolutePathname(cx, script->filename, filename.ptr());
if (!pathname)
return JS_FALSE;
#else

View File

@ -14,9 +14,15 @@ script stringify-call-toJSON-once.js
script stringify-dropping-elements.js
script stringify-gap.js
script stringify-ignore-noncallable-toJSON.js
script stringify-missing-arguments.js
script stringify-primitives.js
script stringify-replacer.js
script stringify-replacer-array-duplicated-element.js
script stringify-replacer-array-edgecase-jsid-elements.js
script stringify-replacer-array-hijinks.js
script stringify-replacer-array-skipped-element.js
script stringify-replacer-with-array-indexes.js
script stringify-special-escapes.js
script stringify-toJSON-arguments.js
script trailing-comma.js

View File

@ -43,6 +43,15 @@ var expected =
assertEq(JSON.stringify(obj, null, 3), expected);
assertEq(JSON.stringify(obj, null, " "), expected);
obj = [1, 2, 3];
String.prototype.toString = function() { return "--"; };
assertEq(JSON.stringify(obj, null, new String(" ")), "[\n--1,\n--2,\n--3\n]");
Number.prototype.valueOf = function() { return 0; };
assertEq(JSON.stringify(obj, null, new Number(3)), "[1,2,3]");
/******************************************************************************/

View File

@ -0,0 +1,22 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var gTestfile = 'stringify-missing-arguments.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 648471;
var summary = "JSON.stringify with no arguments";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
assertEq(JSON.stringify(), undefined);
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("All tests passed!");

View File

@ -0,0 +1,69 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var gTestfile = 'stringify-replacer-array-hijinks.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 648471;
var summary =
"Better/more correct handling for replacer arrays with getter array index " +
"properties";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
var bigOdd = Math.pow(2, 50) + 1;
function two()
{
return Math.random() < 0.5 ? 2 : "2";
}
assertEq(JSON.stringify({ 1: 1 }, [1, 1]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [1, "1"]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [1, bigOdd % two()]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, ["1", 1]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, ["1", "1"]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, ["1", bigOdd % two()]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), 1]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), "1"]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), bigOdd % two()]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [1, new String(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [1, new Number(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, ["1", new Number(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, ["1", new String(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), new Number(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), new String(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [new String(1), new String(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [new String(1), new Number(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [new Number(1), new String(1)]), '{"1":1}');
assertEq(JSON.stringify({ 1: 1 }, [new Number(1), new Number(1)]), '{"1":1}');
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

View File

@ -0,0 +1,77 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var gTestfile = 'stringify-replacer-array-edgecase-jsid-elements.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 648471;
var summary =
"Better/more correct handling for replacer arrays with getter array index " +
"properties";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
/* JSID_INT_MIN/MAX copied from jsapi.h. */
var obj =
{
/* [JSID_INT_MIN - 1, JSID_INT_MIN + 1] */
"-1073741825": -1073741825,
"-1073741824": -1073741824,
"-1073741823": -1073741823,
"-2.5": -2.5,
"-1": -1,
0: 0,
1: 1,
2.5: 2.5,
/* [JSID_INT_MAX - 1, JSID_INT_MAX + 1] */
1073741822: 1073741822,
1073741823: 1073741823,
1073741824: 1073741824,
};
for (var s in obj)
{
var n = obj[s];
assertEq(+s, n);
assertEq(JSON.stringify(obj, [n]),
'{"' + s + '":' + n + '}',
"Failed to stringify numeric property " + n + "correctly");
assertEq(JSON.stringify(obj, [s]),
'{"' + s + '":' + n + '}',
"Failed to stringify string property " + n + "correctly");
assertEq(JSON.stringify(obj, [s, ]),
'{"' + s + '":' + n + '}',
"Failed to stringify string then number properties ('" + s + "', " + n + ") correctly");
assertEq(JSON.stringify(obj, [n, s]),
'{"' + s + '":' + n + '}',
"Failed to stringify number then string properties (" + n + ", '" + s + "') correctly");
}
// -0 is tricky, because ToString(-0) === "0", so test it specially.
assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0]),
'{"0":42}',
"Failed to stringify numeric property -0 correctly");
assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0"]),
'{"-0":17}',
"Failed to stringify string property -0 correctly");
assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0", -0]),
'{"-0":17,"0":42}',
"Failed to stringify string then number properties ('-0', -0) correctly");
assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0, "-0"]),
'{"0":42,"-0":17}',
"Failed to stringify number then string properties (-0, '-0) correctly");
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

View File

@ -0,0 +1,59 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var gTestfile = 'stringify-replacer-array-hijinks.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 648471;
var summary =
"Better/more correct handling for replacer arrays with getter array index " +
"properties";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
var replacer = [0, 1, 2, 3];
Object.prototype[3] = 3;
Object.defineProperty(replacer, 1, {
get: function()
{
Object.defineProperty(replacer, 4, { value: 4 });
delete replacer[2];
delete replacer[3];
replacer[5] = 5;
return 1;
}
});
var s =
JSON.stringify({0: { 1: { 3: { 4: { 5: { 2: "omitted" } } } } } }, replacer);
// The replacer array's length is as seen on first query, so property names are
// accumulated for indexes i ∈ {0, 1, 2, 3}, but index 1 deletes 2 and 3, so 2
// isn't seen but 3 is seen as Object.prototype[3].
assertEq('{"0":{"1":{"3":{"3":3}},"3":3},"3":3}', s);
var replacer = [0, 1, 2, 3];
Object.defineProperty(replacer, 0, {
get: function()
{
replacer.length = 0;
return {};
}
});
// The replacer.length truncation means only properties on the prototype chain
// shine through, but it doesn't affect the original bounds of the iteration
// used to determine property names which will be included in the final string.
assertEq(JSON.stringify({ 0: 0, 1: 1, 2: 2, 3: 3 }, replacer),
'{"3":3}');
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

View File

@ -0,0 +1,62 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var gTestfile = 'stringify-replacer-array-skipped-element.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 648471;
var summary =
"Better/more correct handling for replacer arrays with getter array index " +
"properties";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
assertEq(JSON.stringify({ 3: 3, 4: 4 },
["3", { toString: function() { return "4" } }]),
'{"3":3}');
assertEq(JSON.stringify({ 3: 3, true: 4 }, ["3", true]),
'{"3":3}');
assertEq(JSON.stringify({ 3: 3, true: 4 }, ["3", "true", true]),
'{"3":3,"true":4}');
assertEq(JSON.stringify({ 3: 3, true: 4 }, ["3", true, "true"]),
'{"3":3,"true":4}');
assertEq(JSON.stringify({ 3: 3, false: 4 }, ["3", false]),
'{"3":3}');
assertEq(JSON.stringify({ 3: 3, false: 4 }, ["3", "false", false]),
'{"3":3,"false":4}');
assertEq(JSON.stringify({ 3: 3, false: 4 }, ["3", false, "false"]),
'{"3":3,"false":4}');
assertEq(JSON.stringify({ 3: 3, undefined: 4 }, ["3", undefined]),
'{"3":3}');
assertEq(JSON.stringify({ 3: 3, undefined: 4 }, ["3", "undefined", undefined]),
'{"3":3,"undefined":4}');
assertEq(JSON.stringify({ 3: 3, undefined: 4 }, ["3", undefined, "undefined"]),
'{"3":3,"undefined":4}');
assertEq(JSON.stringify({ 3: 3, null: 4 }, ["3", null]),
'{"3":3}');
assertEq(JSON.stringify({ 3: 3, null: 4 }, ["3", "null", null]),
'{"3":3,"null":4}');
assertEq(JSON.stringify({ 3: 3, null: 4 }, ["3", null, "null"]),
'{"3":3,"null":4}');
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

View File

@ -0,0 +1,227 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var gTestfile = 'stringify-special-escapes.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 512266;
var summary =
"JSON.stringify of \\b\\f\\n\\r\\t should use one-character escapes, not hex";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
assertEq(JSON.stringify("\u0000"), '"\\u0000"');
assertEq(JSON.stringify("\u0001"), '"\\u0001"');
assertEq(JSON.stringify("\u0002"), '"\\u0002"');
assertEq(JSON.stringify("\u0003"), '"\\u0003"');
assertEq(JSON.stringify("\u0004"), '"\\u0004"');
assertEq(JSON.stringify("\u0005"), '"\\u0005"');
assertEq(JSON.stringify("\u0006"), '"\\u0006"');
assertEq(JSON.stringify("\u0007"), '"\\u0007"');
assertEq(JSON.stringify("\u0008"), '"\\b"');
assertEq(JSON.stringify("\u0009"), '"\\t"');
assertEq(JSON.stringify("\u000A"), '"\\n"');
assertEq(JSON.stringify("\u000B"), '"\\u000b"');
assertEq(JSON.stringify("\u000C"), '"\\f"');
assertEq(JSON.stringify("\u000D"), '"\\r"');
assertEq(JSON.stringify("\u000E"), '"\\u000e"');
assertEq(JSON.stringify("\u000F"), '"\\u000f"');
assertEq(JSON.stringify("\u0010"), '"\\u0010"');
assertEq(JSON.stringify("\u0011"), '"\\u0011"');
assertEq(JSON.stringify("\u0012"), '"\\u0012"');
assertEq(JSON.stringify("\u0013"), '"\\u0013"');
assertEq(JSON.stringify("\u0014"), '"\\u0014"');
assertEq(JSON.stringify("\u0015"), '"\\u0015"');
assertEq(JSON.stringify("\u0016"), '"\\u0016"');
assertEq(JSON.stringify("\u0017"), '"\\u0017"');
assertEq(JSON.stringify("\u0018"), '"\\u0018"');
assertEq(JSON.stringify("\u0019"), '"\\u0019"');
assertEq(JSON.stringify("\u001A"), '"\\u001a"');
assertEq(JSON.stringify("\u001B"), '"\\u001b"');
assertEq(JSON.stringify("\u001C"), '"\\u001c"');
assertEq(JSON.stringify("\u001D"), '"\\u001d"');
assertEq(JSON.stringify("\u001E"), '"\\u001e"');
assertEq(JSON.stringify("\u001F"), '"\\u001f"');
assertEq(JSON.stringify("\u0020"), '" "');
assertEq(JSON.stringify("\\u0000"), '"\\\\u0000"');
assertEq(JSON.stringify("\\u0001"), '"\\\\u0001"');
assertEq(JSON.stringify("\\u0002"), '"\\\\u0002"');
assertEq(JSON.stringify("\\u0003"), '"\\\\u0003"');
assertEq(JSON.stringify("\\u0004"), '"\\\\u0004"');
assertEq(JSON.stringify("\\u0005"), '"\\\\u0005"');
assertEq(JSON.stringify("\\u0006"), '"\\\\u0006"');
assertEq(JSON.stringify("\\u0007"), '"\\\\u0007"');
assertEq(JSON.stringify("\\u0008"), '"\\\\u0008"');
assertEq(JSON.stringify("\\u0009"), '"\\\\u0009"');
assertEq(JSON.stringify("\\u000A"), '"\\\\u000A"');
assertEq(JSON.stringify("\\u000B"), '"\\\\u000B"');
assertEq(JSON.stringify("\\u000C"), '"\\\\u000C"');
assertEq(JSON.stringify("\\u000D"), '"\\\\u000D"');
assertEq(JSON.stringify("\\u000E"), '"\\\\u000E"');
assertEq(JSON.stringify("\\u000F"), '"\\\\u000F"');
assertEq(JSON.stringify("\\u0010"), '"\\\\u0010"');
assertEq(JSON.stringify("\\u0011"), '"\\\\u0011"');
assertEq(JSON.stringify("\\u0012"), '"\\\\u0012"');
assertEq(JSON.stringify("\\u0013"), '"\\\\u0013"');
assertEq(JSON.stringify("\\u0014"), '"\\\\u0014"');
assertEq(JSON.stringify("\\u0015"), '"\\\\u0015"');
assertEq(JSON.stringify("\\u0016"), '"\\\\u0016"');
assertEq(JSON.stringify("\\u0017"), '"\\\\u0017"');
assertEq(JSON.stringify("\\u0018"), '"\\\\u0018"');
assertEq(JSON.stringify("\\u0019"), '"\\\\u0019"');
assertEq(JSON.stringify("\\u001A"), '"\\\\u001A"');
assertEq(JSON.stringify("\\u001B"), '"\\\\u001B"');
assertEq(JSON.stringify("\\u001C"), '"\\\\u001C"');
assertEq(JSON.stringify("\\u001D"), '"\\\\u001D"');
assertEq(JSON.stringify("\\u001E"), '"\\\\u001E"');
assertEq(JSON.stringify("\\u001F"), '"\\\\u001F"');
assertEq(JSON.stringify("\\u0020"), '"\\\\u0020"');
assertEq(JSON.stringify("a\u0000"), '"a\\u0000"');
assertEq(JSON.stringify("a\u0001"), '"a\\u0001"');
assertEq(JSON.stringify("a\u0002"), '"a\\u0002"');
assertEq(JSON.stringify("a\u0003"), '"a\\u0003"');
assertEq(JSON.stringify("a\u0004"), '"a\\u0004"');
assertEq(JSON.stringify("a\u0005"), '"a\\u0005"');
assertEq(JSON.stringify("a\u0006"), '"a\\u0006"');
assertEq(JSON.stringify("a\u0007"), '"a\\u0007"');
assertEq(JSON.stringify("a\u0008"), '"a\\b"');
assertEq(JSON.stringify("a\u0009"), '"a\\t"');
assertEq(JSON.stringify("a\u000A"), '"a\\n"');
assertEq(JSON.stringify("a\u000B"), '"a\\u000b"');
assertEq(JSON.stringify("a\u000C"), '"a\\f"');
assertEq(JSON.stringify("a\u000D"), '"a\\r"');
assertEq(JSON.stringify("a\u000E"), '"a\\u000e"');
assertEq(JSON.stringify("a\u000F"), '"a\\u000f"');
assertEq(JSON.stringify("a\u0010"), '"a\\u0010"');
assertEq(JSON.stringify("a\u0011"), '"a\\u0011"');
assertEq(JSON.stringify("a\u0012"), '"a\\u0012"');
assertEq(JSON.stringify("a\u0013"), '"a\\u0013"');
assertEq(JSON.stringify("a\u0014"), '"a\\u0014"');
assertEq(JSON.stringify("a\u0015"), '"a\\u0015"');
assertEq(JSON.stringify("a\u0016"), '"a\\u0016"');
assertEq(JSON.stringify("a\u0017"), '"a\\u0017"');
assertEq(JSON.stringify("a\u0018"), '"a\\u0018"');
assertEq(JSON.stringify("a\u0019"), '"a\\u0019"');
assertEq(JSON.stringify("a\u001A"), '"a\\u001a"');
assertEq(JSON.stringify("a\u001B"), '"a\\u001b"');
assertEq(JSON.stringify("a\u001C"), '"a\\u001c"');
assertEq(JSON.stringify("a\u001D"), '"a\\u001d"');
assertEq(JSON.stringify("a\u001E"), '"a\\u001e"');
assertEq(JSON.stringify("a\u001F"), '"a\\u001f"');
assertEq(JSON.stringify("a\u0020"), '"a "');
assertEq(JSON.stringify("a\\u0000"), '"a\\\\u0000"');
assertEq(JSON.stringify("a\\u0001"), '"a\\\\u0001"');
assertEq(JSON.stringify("a\\u0002"), '"a\\\\u0002"');
assertEq(JSON.stringify("a\\u0003"), '"a\\\\u0003"');
assertEq(JSON.stringify("a\\u0004"), '"a\\\\u0004"');
assertEq(JSON.stringify("a\\u0005"), '"a\\\\u0005"');
assertEq(JSON.stringify("a\\u0006"), '"a\\\\u0006"');
assertEq(JSON.stringify("a\\u0007"), '"a\\\\u0007"');
assertEq(JSON.stringify("a\\u0008"), '"a\\\\u0008"');
assertEq(JSON.stringify("a\\u0009"), '"a\\\\u0009"');
assertEq(JSON.stringify("a\\u000A"), '"a\\\\u000A"');
assertEq(JSON.stringify("a\\u000B"), '"a\\\\u000B"');
assertEq(JSON.stringify("a\\u000C"), '"a\\\\u000C"');
assertEq(JSON.stringify("a\\u000D"), '"a\\\\u000D"');
assertEq(JSON.stringify("a\\u000E"), '"a\\\\u000E"');
assertEq(JSON.stringify("a\\u000F"), '"a\\\\u000F"');
assertEq(JSON.stringify("a\\u0010"), '"a\\\\u0010"');
assertEq(JSON.stringify("a\\u0011"), '"a\\\\u0011"');
assertEq(JSON.stringify("a\\u0012"), '"a\\\\u0012"');
assertEq(JSON.stringify("a\\u0013"), '"a\\\\u0013"');
assertEq(JSON.stringify("a\\u0014"), '"a\\\\u0014"');
assertEq(JSON.stringify("a\\u0015"), '"a\\\\u0015"');
assertEq(JSON.stringify("a\\u0016"), '"a\\\\u0016"');
assertEq(JSON.stringify("a\\u0017"), '"a\\\\u0017"');
assertEq(JSON.stringify("a\\u0018"), '"a\\\\u0018"');
assertEq(JSON.stringify("a\\u0019"), '"a\\\\u0019"');
assertEq(JSON.stringify("a\\u001A"), '"a\\\\u001A"');
assertEq(JSON.stringify("a\\u001B"), '"a\\\\u001B"');
assertEq(JSON.stringify("a\\u001C"), '"a\\\\u001C"');
assertEq(JSON.stringify("a\\u001D"), '"a\\\\u001D"');
assertEq(JSON.stringify("a\\u001E"), '"a\\\\u001E"');
assertEq(JSON.stringify("a\\u001F"), '"a\\\\u001F"');
assertEq(JSON.stringify("a\\u0020"), '"a\\\\u0020"');
assertEq(JSON.stringify("\u0000Q"), '"\\u0000Q"');
assertEq(JSON.stringify("\u0001Q"), '"\\u0001Q"');
assertEq(JSON.stringify("\u0002Q"), '"\\u0002Q"');
assertEq(JSON.stringify("\u0003Q"), '"\\u0003Q"');
assertEq(JSON.stringify("\u0004Q"), '"\\u0004Q"');
assertEq(JSON.stringify("\u0005Q"), '"\\u0005Q"');
assertEq(JSON.stringify("\u0006Q"), '"\\u0006Q"');
assertEq(JSON.stringify("\u0007Q"), '"\\u0007Q"');
assertEq(JSON.stringify("\u0008Q"), '"\\bQ"');
assertEq(JSON.stringify("\u0009Q"), '"\\tQ"');
assertEq(JSON.stringify("\u000AQ"), '"\\nQ"');
assertEq(JSON.stringify("\u000BQ"), '"\\u000bQ"');
assertEq(JSON.stringify("\u000CQ"), '"\\fQ"');
assertEq(JSON.stringify("\u000DQ"), '"\\rQ"');
assertEq(JSON.stringify("\u000EQ"), '"\\u000eQ"');
assertEq(JSON.stringify("\u000FQ"), '"\\u000fQ"');
assertEq(JSON.stringify("\u0010Q"), '"\\u0010Q"');
assertEq(JSON.stringify("\u0011Q"), '"\\u0011Q"');
assertEq(JSON.stringify("\u0012Q"), '"\\u0012Q"');
assertEq(JSON.stringify("\u0013Q"), '"\\u0013Q"');
assertEq(JSON.stringify("\u0014Q"), '"\\u0014Q"');
assertEq(JSON.stringify("\u0015Q"), '"\\u0015Q"');
assertEq(JSON.stringify("\u0016Q"), '"\\u0016Q"');
assertEq(JSON.stringify("\u0017Q"), '"\\u0017Q"');
assertEq(JSON.stringify("\u0018Q"), '"\\u0018Q"');
assertEq(JSON.stringify("\u0019Q"), '"\\u0019Q"');
assertEq(JSON.stringify("\u001AQ"), '"\\u001aQ"');
assertEq(JSON.stringify("\u001BQ"), '"\\u001bQ"');
assertEq(JSON.stringify("\u001CQ"), '"\\u001cQ"');
assertEq(JSON.stringify("\u001DQ"), '"\\u001dQ"');
assertEq(JSON.stringify("\u001EQ"), '"\\u001eQ"');
assertEq(JSON.stringify("\u001FQ"), '"\\u001fQ"');
assertEq(JSON.stringify("\u0020Q"), '" Q"');
assertEq(JSON.stringify("\\u0000Q"), '"\\\\u0000Q"');
assertEq(JSON.stringify("\\u0001Q"), '"\\\\u0001Q"');
assertEq(JSON.stringify("\\u0002Q"), '"\\\\u0002Q"');
assertEq(JSON.stringify("\\u0003Q"), '"\\\\u0003Q"');
assertEq(JSON.stringify("\\u0004Q"), '"\\\\u0004Q"');
assertEq(JSON.stringify("\\u0005Q"), '"\\\\u0005Q"');
assertEq(JSON.stringify("\\u0006Q"), '"\\\\u0006Q"');
assertEq(JSON.stringify("\\u0007Q"), '"\\\\u0007Q"');
assertEq(JSON.stringify("\\u0008Q"), '"\\\\u0008Q"');
assertEq(JSON.stringify("\\u0009Q"), '"\\\\u0009Q"');
assertEq(JSON.stringify("\\u000AQ"), '"\\\\u000AQ"');
assertEq(JSON.stringify("\\u000BQ"), '"\\\\u000BQ"');
assertEq(JSON.stringify("\\u000CQ"), '"\\\\u000CQ"');
assertEq(JSON.stringify("\\u000DQ"), '"\\\\u000DQ"');
assertEq(JSON.stringify("\\u000EQ"), '"\\\\u000EQ"');
assertEq(JSON.stringify("\\u000FQ"), '"\\\\u000FQ"');
assertEq(JSON.stringify("\\u0010Q"), '"\\\\u0010Q"');
assertEq(JSON.stringify("\\u0011Q"), '"\\\\u0011Q"');
assertEq(JSON.stringify("\\u0012Q"), '"\\\\u0012Q"');
assertEq(JSON.stringify("\\u0013Q"), '"\\\\u0013Q"');
assertEq(JSON.stringify("\\u0014Q"), '"\\\\u0014Q"');
assertEq(JSON.stringify("\\u0015Q"), '"\\\\u0015Q"');
assertEq(JSON.stringify("\\u0016Q"), '"\\\\u0016Q"');
assertEq(JSON.stringify("\\u0017Q"), '"\\\\u0017Q"');
assertEq(JSON.stringify("\\u0018Q"), '"\\\\u0018Q"');
assertEq(JSON.stringify("\\u0019Q"), '"\\\\u0019Q"');
assertEq(JSON.stringify("\\u001AQ"), '"\\\\u001AQ"');
assertEq(JSON.stringify("\\u001BQ"), '"\\\\u001BQ"');
assertEq(JSON.stringify("\\u001CQ"), '"\\\\u001CQ"');
assertEq(JSON.stringify("\\u001DQ"), '"\\\\u001DQ"');
assertEq(JSON.stringify("\\u001EQ"), '"\\\\u001EQ"');
assertEq(JSON.stringify("\\u001FQ"), '"\\\\u001FQ"');
assertEq(JSON.stringify("\\u0020Q"), '"\\\\u0020Q"');
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

Some files were not shown because too many files have changed in this diff Show More