2011-10-25 23:07:42 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2009-09-09 23:52:55 +00:00
|
|
|
* vim: set ts=8 sw=4 et tw=79 ft=cpp:
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-09 23:52:55 +00:00
|
|
|
|
|
|
|
#ifndef jsscriptinlines_h___
|
|
|
|
#define jsscriptinlines_h___
|
|
|
|
|
2011-04-08 17:52:51 +00:00
|
|
|
#include "jsautooplen.h"
|
2010-11-16 23:34:24 +00:00
|
|
|
#include "jscntxt.h"
|
2009-09-10 14:22:20 +00:00
|
|
|
#include "jsfun.h"
|
2009-10-19 00:41:24 +00:00
|
|
|
#include "jsopcode.h"
|
2009-09-10 17:23:52 +00:00
|
|
|
#include "jsscript.h"
|
2010-11-16 23:34:24 +00:00
|
|
|
#include "jsscope.h"
|
2011-10-05 06:48:32 +00:00
|
|
|
|
2012-01-02 23:02:05 +00:00
|
|
|
#include "vm/ScopeObject.h"
|
2011-06-06 15:32:41 +00:00
|
|
|
#include "vm/GlobalObject.h"
|
2011-10-05 06:48:32 +00:00
|
|
|
#include "vm/RegExpObject.h"
|
2010-11-16 23:34:24 +00:00
|
|
|
|
2011-07-08 18:16:25 +00:00
|
|
|
#include "jsscopeinlines.h"
|
|
|
|
|
2010-11-16 23:34:24 +00:00
|
|
|
namespace js {
|
|
|
|
|
2011-11-14 21:03:50 +00:00
|
|
|
inline
|
|
|
|
Bindings::Bindings(JSContext *cx)
|
2012-02-28 07:49:02 +00:00
|
|
|
: lastBinding(NULL), nargs(0), nvars(0), hasDup_(false)
|
2011-11-14 21:03:50 +00:00
|
|
|
{}
|
|
|
|
|
2010-11-16 23:34:24 +00:00
|
|
|
inline void
|
|
|
|
Bindings::transfer(JSContext *cx, Bindings *bindings)
|
|
|
|
{
|
2011-03-12 00:29:38 +00:00
|
|
|
JS_ASSERT(!lastBinding);
|
2011-09-28 22:04:55 +00:00
|
|
|
JS_ASSERT(!bindings->lastBinding || !bindings->lastBinding->inDictionary());
|
2010-11-16 23:34:24 +00:00
|
|
|
|
|
|
|
*this = *bindings;
|
|
|
|
#ifdef DEBUG
|
|
|
|
bindings->lastBinding = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
Bindings::clone(JSContext *cx, Bindings *bindings)
|
|
|
|
{
|
2011-03-12 00:29:38 +00:00
|
|
|
JS_ASSERT(!lastBinding);
|
2011-09-28 22:04:55 +00:00
|
|
|
JS_ASSERT(!bindings->lastBinding || !bindings->lastBinding->inDictionary());
|
2010-11-16 23:34:24 +00:00
|
|
|
|
|
|
|
*this = *bindings;
|
|
|
|
}
|
|
|
|
|
2011-03-15 19:18:36 +00:00
|
|
|
Shape *
|
2010-11-16 23:34:24 +00:00
|
|
|
Bindings::lastShape() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(lastBinding);
|
2011-09-28 22:04:55 +00:00
|
|
|
JS_ASSERT(!lastBinding->inDictionary());
|
2010-11-16 23:34:24 +00:00
|
|
|
return lastBinding;
|
|
|
|
}
|
|
|
|
|
2012-01-27 22:33:27 +00:00
|
|
|
Shape *
|
|
|
|
Bindings::initialShape(JSContext *cx) const
|
|
|
|
{
|
|
|
|
/* Get an allocation kind to match an empty call object. */
|
|
|
|
gc::AllocKind kind = gc::FINALIZE_OBJECT4;
|
|
|
|
JS_ASSERT(gc::GetGCKindSlots(kind) == CallObject::RESERVED_SLOTS + 1);
|
|
|
|
|
|
|
|
return EmptyShape::getInitialShape(cx, &CallClass, NULL, NULL, kind,
|
|
|
|
BaseShape::VAROBJ);
|
|
|
|
}
|
|
|
|
|
2011-03-12 00:29:38 +00:00
|
|
|
bool
|
|
|
|
Bindings::ensureShape(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!lastBinding) {
|
2012-01-27 22:33:27 +00:00
|
|
|
lastBinding = initialShape(cx);
|
2011-06-07 16:14:52 +00:00
|
|
|
if (!lastBinding)
|
2011-03-12 00:29:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-28 22:04:55 +00:00
|
|
|
bool
|
|
|
|
Bindings::extensibleParents()
|
|
|
|
{
|
|
|
|
return lastBinding && lastBinding->extensibleParents();
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:42:53 +00:00
|
|
|
extern void
|
2012-02-28 23:11:11 +00:00
|
|
|
CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *linenop, JSPrincipals **origin);
|
2011-04-08 17:52:51 +00:00
|
|
|
|
2011-06-28 00:42:53 +00:00
|
|
|
inline void
|
2012-02-28 23:11:11 +00:00
|
|
|
CurrentScriptFileLineOrigin(JSContext *cx, const char **file, unsigned *linenop, JSPrincipals **origin,
|
2011-06-28 00:42:53 +00:00
|
|
|
LineOption opt = NOT_CALLED_FROM_JSOP_EVAL)
|
2011-04-08 17:52:51 +00:00
|
|
|
{
|
|
|
|
if (opt == CALLED_FROM_JSOP_EVAL) {
|
2011-12-07 21:15:48 +00:00
|
|
|
JS_ASSERT(JSOp(*cx->regs().pc) == JSOP_EVAL);
|
2011-04-13 16:27:37 +00:00
|
|
|
JS_ASSERT(*(cx->regs().pc + JSOP_EVAL_LENGTH) == JSOP_LINENO);
|
2011-06-28 00:42:53 +00:00
|
|
|
JSScript *script = cx->fp()->script();
|
|
|
|
*file = script->filename;
|
2011-04-13 16:27:37 +00:00
|
|
|
*linenop = GET_UINT16(cx->regs().pc + JSOP_EVAL_LENGTH);
|
2011-06-28 00:42:53 +00:00
|
|
|
*origin = script->originPrincipals;
|
|
|
|
return;
|
2011-04-08 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:42:53 +00:00
|
|
|
CurrentScriptFileLineOriginSlow(cx, file, linenop, origin);
|
2011-04-08 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 21:11:08 +00:00
|
|
|
inline void
|
2012-03-25 07:48:45 +00:00
|
|
|
ScriptCounts::destroy(FreeOp *fop)
|
2011-12-16 21:11:08 +00:00
|
|
|
{
|
2012-03-25 07:48:45 +00:00
|
|
|
fop->free_(pcCountsVector);
|
2011-12-16 21:11:08 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 07:12:47 +00:00
|
|
|
inline void
|
|
|
|
MarkScriptFilename(JSRuntime *rt, const char *filename)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* As an invariant, a ScriptFilenameEntry should not be 'marked' outside of
|
|
|
|
* a GC. Since SweepScriptFilenames is only called during a full gc,
|
|
|
|
* to preserve this invariant, only mark during a full gc.
|
|
|
|
*/
|
|
|
|
if (rt->gcIsFull)
|
|
|
|
ScriptFilenameEntry::fromFilename(filename)->marked = true;
|
|
|
|
}
|
|
|
|
|
2010-11-16 23:34:24 +00:00
|
|
|
} // namespace js
|
2009-09-10 14:22:20 +00:00
|
|
|
|
2011-12-15 23:27:58 +00:00
|
|
|
inline void
|
|
|
|
JSScript::setFunction(JSFunction *fun)
|
|
|
|
{
|
|
|
|
function_ = fun;
|
|
|
|
}
|
|
|
|
|
2009-09-10 14:22:20 +00:00
|
|
|
inline JSFunction *
|
|
|
|
JSScript::getFunction(size_t index)
|
|
|
|
{
|
|
|
|
JSObject *funobj = getObject(index);
|
2011-10-11 22:28:54 +00:00
|
|
|
JS_ASSERT(funobj->isFunction() && funobj->toFunction()->isInterpreted());
|
|
|
|
return funobj->toFunction();
|
2009-09-10 14:22:20 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 22:52:39 +00:00
|
|
|
inline JSFunction *
|
|
|
|
JSScript::getCallerFunction()
|
|
|
|
{
|
|
|
|
JS_ASSERT(savedCallerFun);
|
|
|
|
return getFunction(0);
|
|
|
|
}
|
|
|
|
|
2009-09-10 14:22:20 +00:00
|
|
|
inline JSObject *
|
|
|
|
JSScript::getRegExp(size_t index)
|
|
|
|
{
|
2012-04-11 06:51:12 +00:00
|
|
|
js::ObjectArray *arr = regexps();
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ASSERT(uint32_t(index) < arr->length);
|
2009-09-09 23:52:55 +00:00
|
|
|
JSObject *obj = arr->vector[index];
|
2011-09-03 00:23:26 +00:00
|
|
|
JS_ASSERT(obj->isRegExp());
|
2009-09-09 23:52:55 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2009-10-19 00:41:24 +00:00
|
|
|
inline bool
|
|
|
|
JSScript::isEmpty() const
|
|
|
|
{
|
2010-11-16 23:30:56 +00:00
|
|
|
if (length > 3)
|
|
|
|
return false;
|
2010-10-15 18:36:56 +00:00
|
|
|
|
2010-11-16 23:30:56 +00:00
|
|
|
jsbytecode *pc = code;
|
|
|
|
if (noScriptRval && JSOp(*pc) == JSOP_FALSE)
|
|
|
|
++pc;
|
|
|
|
return JSOp(*pc) == JSOP_STOP;
|
2009-10-19 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 15:32:41 +00:00
|
|
|
inline bool
|
|
|
|
JSScript::hasGlobal() const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Make sure that we don't try to query information about global objects
|
|
|
|
* which have had their scopes cleared. compileAndGo code should not run
|
|
|
|
* anymore against such globals.
|
|
|
|
*/
|
2011-09-01 19:20:30 +00:00
|
|
|
JS_ASSERT(types && types->hasScope());
|
|
|
|
js::GlobalObject *obj = types->global;
|
2011-07-28 16:16:53 +00:00
|
|
|
return obj && !obj->isCleared();
|
2011-06-06 15:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline js::GlobalObject *
|
|
|
|
JSScript::global() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(hasGlobal());
|
2011-09-01 19:20:30 +00:00
|
|
|
return types->global;
|
2011-06-06 15:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSScript::hasClearedGlobal() const
|
|
|
|
{
|
2011-09-01 19:20:30 +00:00
|
|
|
JS_ASSERT(types && types->hasScope());
|
|
|
|
js::GlobalObject *obj = types->global;
|
2011-07-28 16:16:53 +00:00
|
|
|
return obj && obj->isCleared();
|
2011-06-06 15:32:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:20:30 +00:00
|
|
|
inline js::types::TypeScriptNesting *
|
|
|
|
JSScript::nesting() const
|
|
|
|
{
|
2011-10-21 21:31:01 +00:00
|
|
|
JS_ASSERT(function() && types && types->hasScope());
|
2011-09-01 19:20:30 +00:00
|
|
|
return types->nesting;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSScript::clearNesting()
|
|
|
|
{
|
|
|
|
js::types::TypeScriptNesting *nesting = this->nesting();
|
|
|
|
if (nesting) {
|
|
|
|
js::Foreground::delete_(nesting);
|
|
|
|
types->nesting = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 23:07:42 +00:00
|
|
|
inline void
|
|
|
|
JSScript::writeBarrierPre(JSScript *script)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
|
|
|
if (!script)
|
|
|
|
return;
|
|
|
|
|
|
|
|
JSCompartment *comp = script->compartment();
|
|
|
|
if (comp->needsBarrier()) {
|
|
|
|
JS_ASSERT(!comp->rt->gcRunning);
|
2012-02-17 19:46:11 +00:00
|
|
|
JSScript *tmp = script;
|
|
|
|
MarkScriptUnbarriered(comp->barrierTracer(), &tmp, "write barrier");
|
|
|
|
JS_ASSERT(tmp == script);
|
2011-10-25 23:07:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSScript::writeBarrierPost(JSScript *script, void *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:52:55 +00:00
|
|
|
#endif /* jsscriptinlines_h___ */
|