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"
|
2011-10-05 06:48:32 +00:00
|
|
|
|
2011-06-06 15:32:41 +00:00
|
|
|
#include "vm/GlobalObject.h"
|
2011-10-05 06:48:32 +00:00
|
|
|
#include "vm/RegExpObject.h"
|
2013-01-26 15:03:19 +00:00
|
|
|
#include "vm/Shape.h"
|
2010-11-16 23:34:24 +00:00
|
|
|
|
2013-01-26 15:03:19 +00:00
|
|
|
#include "vm/Shape-inl.h"
|
2011-07-08 18:16:25 +00:00
|
|
|
|
2010-11-16 23:34:24 +00:00
|
|
|
namespace js {
|
|
|
|
|
2011-11-14 21:03:50 +00:00
|
|
|
inline
|
2012-06-21 02:14:35 +00:00
|
|
|
Bindings::Bindings()
|
2012-08-16 22:38:22 +00:00
|
|
|
: callObjShape_(NULL), bindingArrayAndFlag_(TEMPORARY_STORAGE_BIT), numArgs_(0), numVars_(0)
|
2011-11-14 21:03:50 +00:00
|
|
|
{}
|
|
|
|
|
2012-08-06 14:56:45 +00:00
|
|
|
inline
|
2012-11-29 18:22:12 +00:00
|
|
|
AliasedFormalIter::AliasedFormalIter(js::UnrootedScript script)
|
2012-08-16 22:38:22 +00:00
|
|
|
: begin_(script->bindings.bindingArray()),
|
2012-08-06 14:56:45 +00:00
|
|
|
p_(begin_),
|
|
|
|
end_(begin_ + (script->funHasAnyAliasedFormal ? script->bindings.numArgs() : 0)),
|
|
|
|
slot_(CallObject::RESERVED_SLOTS)
|
2012-06-29 18:42:42 +00:00
|
|
|
{
|
2012-08-06 14:56:45 +00:00
|
|
|
settle();
|
2012-06-29 18:42:42 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-09-26 18:13:20 +00:00
|
|
|
AutoAssertNoGC nogc;
|
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);
|
2012-12-04 19:10:53 +00:00
|
|
|
UnrootedScript script = cx->fp()->script();
|
2011-06-28 00:42:53 +00:00
|
|
|
*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);
|
2012-11-16 17:14:06 +00:00
|
|
|
fop->delete_(ionCounts);
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-01 23:02:08 +00:00
|
|
|
inline void
|
|
|
|
MarkScriptBytecode(JSRuntime *rt, const jsbytecode *bytecode)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* As an invariant, a ScriptBytecodeEntry should not be 'marked' outside of
|
|
|
|
* a GC. Since SweepScriptBytecodes is only called during a full gc,
|
|
|
|
* to preserve this invariant, only mark during a full gc.
|
|
|
|
*/
|
|
|
|
if (rt->gcIsFull)
|
|
|
|
SharedScriptData::fromBytecode(bytecode)->marked = true;
|
|
|
|
}
|
|
|
|
|
2013-02-20 11:54:13 +00:00
|
|
|
void
|
|
|
|
SetFrameArgumentsObject(JSContext *cx, AbstractFramePtr frame,
|
|
|
|
HandleScript script, JSObject *argsobj);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-03 20:59:41 +00:00
|
|
|
inline js::RegExpObject *
|
2009-09-10 14:22:20 +00:00
|
|
|
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());
|
2012-02-03 20:59:41 +00:00
|
|
|
return (js::RegExpObject *) obj;
|
2009-09-09 23:52:55 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-07-03 17:24:35 +00:00
|
|
|
inline js::GlobalObject &
|
2011-06-06 15:32:41 +00:00
|
|
|
JSScript::global() const
|
|
|
|
{
|
2012-07-03 17:24:35 +00:00
|
|
|
/*
|
|
|
|
* A JSScript always marks its compartment's global (via bindings) so we
|
|
|
|
* can assert that maybeGlobal is non-null here.
|
|
|
|
*/
|
|
|
|
return *compartment()->maybeGlobal();
|
2011-06-06 15:32:41 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 15:20:33 +00:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
inline bool
|
2012-07-27 23:20:48 +00:00
|
|
|
JSScript::ensureHasMJITInfo(JSContext *cx)
|
2012-05-25 15:20:33 +00:00
|
|
|
{
|
2012-07-27 23:20:48 +00:00
|
|
|
if (mJITInfo)
|
2012-05-25 15:20:33 +00:00
|
|
|
return true;
|
2012-07-27 23:20:48 +00:00
|
|
|
mJITInfo = cx->new_<JITScriptSet>();
|
|
|
|
return mJITInfo != NULL;
|
2012-05-25 15:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2012-07-27 23:20:48 +00:00
|
|
|
JSScript::destroyMJITInfo(js::FreeOp *fop)
|
2012-05-25 15:20:33 +00:00
|
|
|
{
|
2012-07-27 23:20:48 +00:00
|
|
|
fop->delete_(mJITInfo);
|
|
|
|
mJITInfo = NULL;
|
2012-05-25 15:20:33 +00:00
|
|
|
}
|
|
|
|
#endif /* JS_METHODJIT */
|
|
|
|
|
2011-10-25 23:07:42 +00:00
|
|
|
inline void
|
2012-11-29 18:22:12 +00:00
|
|
|
JSScript::writeBarrierPre(js::UnrootedScript script)
|
2011-10-25 23:07:42 +00:00
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
|
|
|
if (!script)
|
|
|
|
return;
|
|
|
|
|
2013-01-27 21:51:41 +00:00
|
|
|
JS::Zone *zone = script->zone();
|
|
|
|
if (zone->needsBarrier()) {
|
|
|
|
JS_ASSERT(!zone->rt->isHeapBusy());
|
2012-11-29 18:22:12 +00:00
|
|
|
js::UnrootedScript tmp = script;
|
2013-01-27 21:51:41 +00:00
|
|
|
MarkScriptUnbarriered(zone->barrierTracer(), &tmp, "write barrier");
|
2012-02-17 19:46:11 +00:00
|
|
|
JS_ASSERT(tmp == script);
|
2011-10-25 23:07:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2012-11-29 18:22:12 +00:00
|
|
|
JSScript::writeBarrierPost(js::UnrootedScript script, void *addr)
|
2011-10-25 23:07:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-31 02:10:46 +00:00
|
|
|
inline JSPrincipals *
|
|
|
|
JSScript::principals()
|
|
|
|
{
|
|
|
|
return compartment()->principals;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:52:55 +00:00
|
|
|
#endif /* jsscriptinlines_h___ */
|