mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-31 19:10:36 +00:00
Bug 558437 - rename JSCompiler to js::Parser (r=brendan).
This commit is contained in:
parent
eba63d253d
commit
cfc5514d85
@ -4511,8 +4511,8 @@ JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT;
|
||||
script = JSCompiler::compileScript(cx, obj, NULL, principals, tcflags,
|
||||
chars, length, NULL, filename, lineno);
|
||||
script = Compiler::compileScript(cx, obj, NULL, principals, tcflags,
|
||||
chars, length, NULL, filename, lineno);
|
||||
LAST_FRAME_CHECKS(cx, script);
|
||||
return script;
|
||||
}
|
||||
@ -4538,11 +4538,11 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
|
||||
result = JS_TRUE;
|
||||
exnState = JS_SaveExceptionState(cx);
|
||||
{
|
||||
JSCompiler jsc(cx);
|
||||
if (jsc.init(chars, length, NULL, NULL, 1)) {
|
||||
Parser parser(cx);
|
||||
if (parser.init(chars, length, NULL, NULL, 1)) {
|
||||
older = JS_SetErrorReporter(cx, NULL);
|
||||
if (!jsc.parse(obj) &&
|
||||
jsc.tokenStream.isUnexpectedEOF()) {
|
||||
if (!parser.parse(obj) &&
|
||||
parser.tokenStream.isUnexpectedEOF()) {
|
||||
/*
|
||||
* We ran into an error. If it was because we ran out of
|
||||
* source, we return false so our caller knows to try to
|
||||
@ -4578,8 +4578,8 @@ JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename)
|
||||
}
|
||||
|
||||
tcflags = JS_OPTIONS_TO_TCFLAGS(cx);
|
||||
script = JSCompiler::compileScript(cx, obj, NULL, NULL, tcflags,
|
||||
NULL, 0, fp, filename, 1);
|
||||
script = Compiler::compileScript(cx, obj, NULL, NULL, tcflags,
|
||||
NULL, 0, fp, filename, 1);
|
||||
if (fp != stdin)
|
||||
fclose(fp);
|
||||
LAST_FRAME_CHECKS(cx, script);
|
||||
@ -4603,8 +4603,8 @@ JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj,
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
tcflags = JS_OPTIONS_TO_TCFLAGS(cx);
|
||||
script = JSCompiler::compileScript(cx, obj, NULL, principals, tcflags,
|
||||
NULL, 0, file, filename, 1);
|
||||
script = Compiler::compileScript(cx, obj, NULL, principals, tcflags,
|
||||
NULL, 0, file, filename, 1);
|
||||
LAST_FRAME_CHECKS(cx, script);
|
||||
return script;
|
||||
}
|
||||
@ -4743,8 +4743,8 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
||||
}
|
||||
}
|
||||
|
||||
if (!JSCompiler::compileFunctionBody(cx, fun, principals,
|
||||
chars, length, filename, lineno)) {
|
||||
if (!Compiler::compileFunctionBody(cx, fun, principals,
|
||||
chars, length, filename, lineno)) {
|
||||
fun = NULL;
|
||||
goto out;
|
||||
}
|
||||
@ -4892,11 +4892,11 @@ JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSBool ok;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
script = JSCompiler::compileScript(cx, obj, NULL, principals,
|
||||
!rval
|
||||
? TCF_COMPILE_N_GO | TCF_NO_SCRIPT_RVAL
|
||||
: TCF_COMPILE_N_GO,
|
||||
chars, length, NULL, filename, lineno);
|
||||
script = Compiler::compileScript(cx, obj, NULL, principals,
|
||||
!rval
|
||||
? TCF_COMPILE_N_GO | TCF_NO_SCRIPT_RVAL
|
||||
: TCF_COMPILE_N_GO,
|
||||
chars, length, NULL, filename, lineno);
|
||||
if (!script) {
|
||||
LAST_FRAME_CHECKS(cx, script);
|
||||
return JS_FALSE;
|
||||
|
@ -60,6 +60,8 @@
|
||||
#include "jsversion.h"
|
||||
#include "jsstrinlines.h"
|
||||
|
||||
using namespace js;
|
||||
|
||||
/*
|
||||
* ATOM_HASH assumes that JSHashNumber is 32-bit even on 64-bit systems.
|
||||
*/
|
||||
@ -956,23 +958,23 @@ JS_STATIC_ASSERT(TEMP_SIZE_START >= sizeof(JSHashTable));
|
||||
static void *
|
||||
js_alloc_temp_space(void *priv, size_t size)
|
||||
{
|
||||
JSCompiler *jsc = (JSCompiler *) priv;
|
||||
Parser *parser = (Parser *) priv;
|
||||
|
||||
void *space;
|
||||
if (size < TEMP_SIZE_LIMIT) {
|
||||
int bin = JS_CeilingLog2(size) - TEMP_SIZE_START_LOG2;
|
||||
JS_ASSERT(unsigned(bin) < NUM_TEMP_FREELISTS);
|
||||
|
||||
space = jsc->tempFreeList[bin];
|
||||
space = parser->tempFreeList[bin];
|
||||
if (space) {
|
||||
jsc->tempFreeList[bin] = *(void **)space;
|
||||
parser->tempFreeList[bin] = *(void **)space;
|
||||
return space;
|
||||
}
|
||||
}
|
||||
|
||||
JS_ARENA_ALLOCATE(space, &jsc->context->tempPool, size);
|
||||
JS_ARENA_ALLOCATE(space, &parser->context->tempPool, size);
|
||||
if (!space)
|
||||
js_ReportOutOfScriptQuota(jsc->context);
|
||||
js_ReportOutOfScriptQuota(parser->context);
|
||||
return space;
|
||||
}
|
||||
|
||||
@ -982,29 +984,29 @@ js_free_temp_space(void *priv, void *item, size_t size)
|
||||
if (size >= TEMP_SIZE_LIMIT)
|
||||
return;
|
||||
|
||||
JSCompiler *jsc = (JSCompiler *) priv;
|
||||
Parser *parser = (Parser *) priv;
|
||||
int bin = JS_CeilingLog2(size) - TEMP_SIZE_START_LOG2;
|
||||
JS_ASSERT(unsigned(bin) < NUM_TEMP_FREELISTS);
|
||||
|
||||
*(void **)item = jsc->tempFreeList[bin];
|
||||
jsc->tempFreeList[bin] = item;
|
||||
*(void **)item = parser->tempFreeList[bin];
|
||||
parser->tempFreeList[bin] = item;
|
||||
}
|
||||
|
||||
static JSHashEntry *
|
||||
js_alloc_temp_entry(void *priv, const void *key)
|
||||
{
|
||||
JSCompiler *jsc = (JSCompiler *) priv;
|
||||
Parser *parser = (Parser *) priv;
|
||||
JSAtomListElement *ale;
|
||||
|
||||
ale = jsc->aleFreeList;
|
||||
ale = parser->aleFreeList;
|
||||
if (ale) {
|
||||
jsc->aleFreeList = ALE_NEXT(ale);
|
||||
parser->aleFreeList = ALE_NEXT(ale);
|
||||
return &ale->entry;
|
||||
}
|
||||
|
||||
JS_ARENA_ALLOCATE_TYPE(ale, JSAtomListElement, &jsc->context->tempPool);
|
||||
JS_ARENA_ALLOCATE_TYPE(ale, JSAtomListElement, &parser->context->tempPool);
|
||||
if (!ale) {
|
||||
js_ReportOutOfScriptQuota(jsc->context);
|
||||
js_ReportOutOfScriptQuota(parser->context);
|
||||
return NULL;
|
||||
}
|
||||
return &ale->entry;
|
||||
@ -1013,11 +1015,11 @@ js_alloc_temp_entry(void *priv, const void *key)
|
||||
static void
|
||||
js_free_temp_entry(void *priv, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
JSCompiler *jsc = (JSCompiler *) priv;
|
||||
Parser *parser = (Parser *) priv;
|
||||
JSAtomListElement *ale = (JSAtomListElement *) he;
|
||||
|
||||
ALE_SET_NEXT(ale, jsc->aleFreeList);
|
||||
jsc->aleFreeList = ale;
|
||||
ALE_SET_NEXT(ale, parser->aleFreeList);
|
||||
parser->aleFreeList = ale;
|
||||
}
|
||||
|
||||
static JSHashAllocOps temp_alloc_ops = {
|
||||
@ -1053,7 +1055,7 @@ JSAtomList::rawLookup(JSAtom *atom, JSHashEntry **&hep)
|
||||
#define ATOM_LIST_HASH_THRESHOLD 12
|
||||
|
||||
JSAtomListElement *
|
||||
JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how)
|
||||
JSAtomList::add(Parser *parser, JSAtom *atom, AddHow how)
|
||||
{
|
||||
JS_ASSERT(!set);
|
||||
|
||||
@ -1064,7 +1066,7 @@ JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how)
|
||||
if (!ale || how != UNIQUE) {
|
||||
if (count < ATOM_LIST_HASH_THRESHOLD && !table) {
|
||||
/* Few enough for linear search and no hash table yet needed. */
|
||||
ale = (JSAtomListElement *)js_alloc_temp_entry(jsc, atom);
|
||||
ale = (JSAtomListElement *)js_alloc_temp_entry(parser, atom);
|
||||
if (!ale)
|
||||
return NULL;
|
||||
ALE_SET_ATOM(ale, atom);
|
||||
@ -1090,7 +1092,7 @@ JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how)
|
||||
JS_ASSERT(!hep);
|
||||
table = JS_NewHashTable(count + 1, js_hash_atom_ptr,
|
||||
JS_CompareValues, JS_CompareValues,
|
||||
&temp_alloc_ops, jsc);
|
||||
&temp_alloc_ops, parser);
|
||||
if (!table)
|
||||
return NULL;
|
||||
|
||||
@ -1150,7 +1152,7 @@ JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how)
|
||||
}
|
||||
|
||||
void
|
||||
JSAtomList::rawRemove(JSCompiler *jsc, JSAtomListElement *ale, JSHashEntry **hep)
|
||||
JSAtomList::rawRemove(Parser *parser, JSAtomListElement *ale, JSHashEntry **hep)
|
||||
{
|
||||
JS_ASSERT(!set);
|
||||
JS_ASSERT(count != 0);
|
||||
@ -1166,7 +1168,7 @@ JSAtomList::rawRemove(JSCompiler *jsc, JSAtomListElement *ale, JSHashEntry **hep
|
||||
hep = &(*hep)->next;
|
||||
}
|
||||
*hep = ale->entry.next;
|
||||
js_free_temp_entry(jsc, &ale->entry, HT_FREE_ENTRY);
|
||||
js_free_temp_entry(parser, &ale->entry, HT_FREE_ENTRY);
|
||||
}
|
||||
|
||||
--count;
|
||||
@ -1180,7 +1182,7 @@ JSAutoAtomList::~JSAutoAtomList()
|
||||
JSHashEntry *hep = list;
|
||||
while (hep) {
|
||||
JSHashEntry *next = hep->next;
|
||||
js_free_temp_entry(compiler, hep, HT_FREE_ENTRY);
|
||||
js_free_temp_entry(parser, hep, HT_FREE_ENTRY);
|
||||
hep = next;
|
||||
}
|
||||
}
|
||||
|
@ -152,16 +152,16 @@ struct JSAtomList : public JSAtomSet
|
||||
|
||||
enum AddHow { UNIQUE, SHADOW, HOIST };
|
||||
|
||||
JSAtomListElement *add(JSCompiler *jsc, JSAtom *atom, AddHow how = UNIQUE);
|
||||
JSAtomListElement *add(js::Parser *parser, JSAtom *atom, AddHow how = UNIQUE);
|
||||
|
||||
void remove(JSCompiler *jsc, JSAtom *atom) {
|
||||
void remove(js::Parser *parser, JSAtom *atom) {
|
||||
JSHashEntry **hep;
|
||||
JSAtomListElement *ale = rawLookup(atom, hep);
|
||||
if (ale)
|
||||
rawRemove(jsc, ale, hep);
|
||||
rawRemove(parser, ale, hep);
|
||||
}
|
||||
|
||||
void rawRemove(JSCompiler *jsc, JSAtomListElement *ale, JSHashEntry **hep);
|
||||
void rawRemove(js::Parser *parser, JSAtomListElement *ale, JSHashEntry **hep);
|
||||
};
|
||||
|
||||
/*
|
||||
@ -170,10 +170,10 @@ struct JSAtomList : public JSAtomSet
|
||||
*/
|
||||
struct JSAutoAtomList: public JSAtomList
|
||||
{
|
||||
JSAutoAtomList(JSCompiler *c): compiler(c) {}
|
||||
JSAutoAtomList(js::Parser *p): parser(p) {}
|
||||
~JSAutoAtomList();
|
||||
private:
|
||||
JSCompiler *compiler; /* For freeing list entries. */
|
||||
js::Parser *parser; /* For freeing list entries. */
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -1649,7 +1649,7 @@ class AutoGCRooter {
|
||||
JSVAL = -1, /* js::AutoValueRooter */
|
||||
SPROP = -2, /* js::AutoScopePropertyRooter */
|
||||
WEAKROOTS = -3, /* js::AutoSaveWeakRoots */
|
||||
COMPILER = -4, /* JSCompiler */
|
||||
PARSER = -4, /* js::Parser */
|
||||
SCRIPT = -5, /* js::AutoScriptRooter */
|
||||
ENUMERATOR = -6, /* js::AutoEnumStateRooter */
|
||||
IDARRAY = -7, /* js::AutoIdArray */
|
||||
|
@ -81,8 +81,8 @@ AutoGCRooter::trace(JSTracer *trc)
|
||||
static_cast<AutoSaveWeakRoots *>(this)->savedRoots.mark(trc);
|
||||
return;
|
||||
|
||||
case COMPILER:
|
||||
static_cast<JSCompiler *>(this)->trace(trc);
|
||||
case PARSER:
|
||||
static_cast<Parser *>(this)->trace(trc);
|
||||
return;
|
||||
|
||||
case SCRIPT:
|
||||
|
@ -1344,9 +1344,9 @@ 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.
|
||||
*/
|
||||
script = JSCompiler::compileScript(cx, scobj, fp, JS_StackFramePrincipals(cx, fp),
|
||||
TCF_COMPILE_N_GO, chars, length, NULL,
|
||||
filename, lineno, NULL, JS_DISPLAY_SIZE);
|
||||
script = Compiler::compileScript(cx, scobj, fp, JS_StackFramePrincipals(cx, fp),
|
||||
TCF_COMPILE_N_GO, chars, length, NULL,
|
||||
filename, lineno, NULL, JS_DISPLAY_SIZE);
|
||||
|
||||
if (!script)
|
||||
return JS_FALSE;
|
||||
|
@ -85,10 +85,10 @@ static JSBool
|
||||
NewTryNote(JSContext *cx, JSCodeGenerator *cg, JSTryNoteKind kind,
|
||||
uintN stackDepth, size_t start, size_t end);
|
||||
|
||||
JSCodeGenerator::JSCodeGenerator(JSCompiler *jsc,
|
||||
JSCodeGenerator::JSCodeGenerator(Parser *parser,
|
||||
JSArenaPool *cpool, JSArenaPool *npool,
|
||||
uintN lineno)
|
||||
: JSTreeContext(jsc),
|
||||
: JSTreeContext(parser),
|
||||
codePool(cpool), notePool(npool),
|
||||
codeMark(JS_ARENA_MARK(cpool)), noteMark(JS_ARENA_MARK(npool)),
|
||||
stackDepth(0), maxStackDepth(0),
|
||||
@ -114,10 +114,10 @@ JSCodeGenerator::~JSCodeGenerator()
|
||||
|
||||
/* NB: non-null only after OOM. */
|
||||
if (spanDeps)
|
||||
compiler->context->free(spanDeps);
|
||||
parser->context->free(spanDeps);
|
||||
|
||||
if (upvarMap.vector)
|
||||
compiler->context->free(upvarMap.vector);
|
||||
parser->context->free(upvarMap.vector);
|
||||
}
|
||||
|
||||
static ptrdiff_t
|
||||
@ -189,7 +189,7 @@ UpdateDepth(JSContext *cx, JSCodeGenerator *cg, ptrdiff_t target)
|
||||
TokenStream *ts;
|
||||
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%d", target);
|
||||
ts = &cg->compiler->tokenStream;
|
||||
ts = &cg->parser->tokenStream;
|
||||
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING,
|
||||
js_GetErrorMessage, NULL,
|
||||
JSMSG_STACK_UNDERFLOW,
|
||||
@ -895,7 +895,7 @@ OptimizeSpanDeps(JSContext *cx, JSCodeGenerator *cg)
|
||||
|
||||
if (growth) {
|
||||
#ifdef DEBUG_brendan
|
||||
TokenStream *ts = &cg->compiler->tokenStream;
|
||||
TokenStream *ts = &cg->parser->tokenStream;
|
||||
|
||||
printf("%s:%u: %u/%u jumps extended in %d passes (%d=%d+%d)\n",
|
||||
ts->filename ? ts->filename : "stdin", cg->firstLine,
|
||||
@ -1258,7 +1258,7 @@ JSTreeContext::ensureSharpSlots()
|
||||
|
||||
JS_ASSERT(!(flags & TCF_HAS_SHARPS));
|
||||
if (flags & TCF_IN_FUNCTION) {
|
||||
JSContext *cx = compiler->context;
|
||||
JSContext *cx = parser->context;
|
||||
JSAtom *sharpArrayAtom = js_Atomize(cx, "#array", 6, 0);
|
||||
JSAtom *sharpDepthAtom = js_Atomize(cx, "#depth", 6, 0);
|
||||
if (!sharpArrayAtom || !sharpDepthAtom)
|
||||
@ -1271,7 +1271,7 @@ JSTreeContext::ensureSharpSlots()
|
||||
return false;
|
||||
} else {
|
||||
/*
|
||||
* JSCompiler::compileScript will rebase immediate operands indexing
|
||||
* Compiler::compileScript will rebase immediate operands indexing
|
||||
* the sharp slots to come at the end of the global script's |nfixed|
|
||||
* slots storage, after gvars and regexps.
|
||||
*/
|
||||
@ -1562,7 +1562,7 @@ js_DefineCompileTimeConstant(JSContext *cx, JSCodeGenerator *cg, JSAtom *atom,
|
||||
return JS_FALSE;
|
||||
v = ATOM_KEY(valueAtom);
|
||||
}
|
||||
ale = cg->constList.add(cg->compiler, atom);
|
||||
ale = cg->constList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
ALE_SET_VALUE(ale, v);
|
||||
@ -1773,7 +1773,7 @@ EmitAtomOp(JSContext *cx, JSParseNode *pn, JSOp op, JSCodeGenerator *cg)
|
||||
pn->pn_atom == cx->runtime->atomState.lengthAtom) {
|
||||
return js_Emit1(cx, cg, JSOP_LENGTH) >= 0;
|
||||
}
|
||||
ale = cg->atomList.add(cg->compiler, pn->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn->pn_atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
return EmitIndexOp(cx, op, ALE_INDEX(ale), cg);
|
||||
@ -1826,7 +1826,7 @@ EmitSlotIndexOp(JSContext *cx, JSOp op, uintN slot, uintN index,
|
||||
* Adjust the slot for a block local to account for the number of variables
|
||||
* that share the same index space with locals. Due to the incremental code
|
||||
* generation for top-level script, we do the adjustment via code patching in
|
||||
* JSCompiler::compileScript; see comments there.
|
||||
* Compiler::compileScript; see comments there.
|
||||
*
|
||||
* The function returns -1 on failures.
|
||||
*/
|
||||
@ -1894,15 +1894,15 @@ EmitEnterBlock(JSContext *cx, JSParseNode *pn, JSCodeGenerator *cg)
|
||||
* lazily, growing upvarMap.vector by powers of two.
|
||||
*
|
||||
* This function knows that it is called with pn pointing to a PN_NAME-arity
|
||||
* node, and cg->compiler->callerFrame having a non-null fun member, and the
|
||||
* node, and cg->parser->callerFrame having a non-null fun member, and the
|
||||
* static level of cg at least one greater than the eval-calling function's
|
||||
* static level.
|
||||
*/
|
||||
static bool
|
||||
MakeUpvarForEval(JSParseNode *pn, JSCodeGenerator *cg)
|
||||
{
|
||||
JSContext *cx = cg->compiler->context;
|
||||
JSFunction *fun = cg->compiler->callerFrame->fun;
|
||||
JSContext *cx = cg->parser->context;
|
||||
JSFunction *fun = cg->parser->callerFrame->fun;
|
||||
uintN upvarLevel = fun->u.i.script->staticLevel;
|
||||
|
||||
JSFunctionBox *funbox = cg->funbox;
|
||||
@ -1947,7 +1947,7 @@ MakeUpvarForEval(JSParseNode *pn, JSCodeGenerator *cg)
|
||||
return false;
|
||||
}
|
||||
|
||||
ale = cg->upvarList.add(cg->compiler, atom);
|
||||
ale = cg->upvarList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return false;
|
||||
JS_ASSERT(ALE_INDEX(ale) == cg->upvarList.count - 1);
|
||||
@ -2050,7 +2050,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
* Turn JSOP_DELNAME into JSOP_FALSE if dn is known, as all declared
|
||||
* bindings visible to the compiler are permanent in JS unless the
|
||||
* declaration originates in eval code. We detect eval code by testing
|
||||
* cg->compiler->callerFrame, which is set only by eval or a debugger
|
||||
* cg->parser->callerFrame, which is set only by eval or a debugger
|
||||
* equivalent.
|
||||
*
|
||||
* Note that this callerFrame non-null test must be qualified by testing
|
||||
@ -2063,7 +2063,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
break;
|
||||
case JSOP_DELNAME:
|
||||
if (dn_kind != JSDefinition::UNKNOWN) {
|
||||
if (cg->compiler->callerFrame && !cg->funbox)
|
||||
if (cg->parser->callerFrame && !cg->funbox)
|
||||
JS_ASSERT(cg->flags & TCF_COMPILE_N_GO);
|
||||
else
|
||||
pn->pn_op = JSOP_FALSE;
|
||||
@ -2077,7 +2077,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
}
|
||||
|
||||
if (cookie == FREE_UPVAR_COOKIE) {
|
||||
JSStackFrame *caller = cg->compiler->callerFrame;
|
||||
JSStackFrame *caller = cg->parser->callerFrame;
|
||||
if (caller) {
|
||||
JS_ASSERT(cg->flags & TCF_COMPILE_N_GO);
|
||||
|
||||
@ -2096,12 +2096,12 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
* Make sure the variable object used by the compiler to initialize
|
||||
* parent links matches the caller's varobj. Compile-n-go compiler-
|
||||
* created function objects have the top-level cg's scopeChain set
|
||||
* as their parent by JSCompiler::newFunction.
|
||||
* as their parent by Parser::newFunction.
|
||||
*/
|
||||
JSObject *scopeobj = (cg->flags & TCF_IN_FUNCTION)
|
||||
? FUN_OBJECT(cg->fun)->getParent()
|
||||
: cg->scopeChain;
|
||||
if (scopeobj != cg->compiler->callerVarObj)
|
||||
if (scopeobj != cg->parser->callerVarObj)
|
||||
return JS_TRUE;
|
||||
|
||||
/*
|
||||
@ -2118,7 +2118,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
* defeats the display optimization to static link searching used
|
||||
* by JSOP_{GET,CALL}UPVAR.
|
||||
*/
|
||||
JSFunction *fun = cg->compiler->callerFrame->fun;
|
||||
JSFunction *fun = cg->parser->callerFrame->fun;
|
||||
JS_ASSERT(cg->staticLevel >= fun->u.i.script->staticLevel);
|
||||
unsigned skip = cg->staticLevel - fun->u.i.script->staticLevel;
|
||||
if (cg->skipSpansGenerator(skip))
|
||||
@ -2184,7 +2184,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
return JS_TRUE;
|
||||
|
||||
#ifdef DEBUG
|
||||
JSStackFrame *caller = cg->compiler->callerFrame;
|
||||
JSStackFrame *caller = cg->parser->callerFrame;
|
||||
#endif
|
||||
JS_ASSERT(caller);
|
||||
JS_ASSERT(caller->script);
|
||||
@ -2196,7 +2196,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
|
||||
JSCodeGenerator *evalcg = (JSCodeGenerator *) tc;
|
||||
JS_ASSERT(evalcg->flags & TCF_COMPILE_N_GO);
|
||||
JS_ASSERT(caller->fun && cg->compiler->callerVarObj == evalcg->scopeChain);
|
||||
JS_ASSERT(caller->fun && cg->parser->callerVarObj == evalcg->scopeChain);
|
||||
|
||||
/*
|
||||
* Don't generate upvars on the left side of a for loop. See
|
||||
@ -2241,7 +2241,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
/*
|
||||
* The function we're compiling may not be heavyweight, but if it
|
||||
* escapes as a funarg, we can't use JSOP_GETUPVAR/JSOP_CALLUPVAR.
|
||||
* JSCompiler::analyzeFunctions has arranged for this function's
|
||||
* Parser::analyzeFunctions has arranged for this function's
|
||||
* enclosing functions to be heavyweight, so we can safely stick
|
||||
* with JSOP_NAME/JSOP_CALLNAME.
|
||||
*/
|
||||
@ -2266,7 +2266,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
if (!js_AddLocal(cx, cg->fun, atom, JSLOCAL_UPVAR))
|
||||
return JS_FALSE;
|
||||
|
||||
ale = cg->upvarList.add(cg->compiler, atom);
|
||||
ale = cg->upvarList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
index = ALE_INDEX(ale);
|
||||
@ -2691,7 +2691,7 @@ EmitSpecialPropOp(JSContext *cx, JSParseNode *pn, JSOp op, JSCodeGenerator *cg)
|
||||
* array instances by going up to Array.prototype before looking up the
|
||||
* property name.
|
||||
*/
|
||||
JSAtomListElement *ale = cg->atomList.add(cg->compiler, pn->pn_atom);
|
||||
JSAtomListElement *ale = cg->atomList.add(cg->parser, pn->pn_atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
if (!EmitIndexOp(cx, JSOP_QNAMEPART, ALE_INDEX(ale), cg))
|
||||
@ -2755,7 +2755,7 @@ EmitPropOp(JSContext *cx, JSParseNode *pn, JSOp op, JSCodeGenerator *cg,
|
||||
JSAtomListElement *ale;
|
||||
jsatomid atomIndex;
|
||||
|
||||
ale = cg->atomList.add(cg->compiler, pn->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn->pn_atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
atomIndex = ALE_INDEX(ale);
|
||||
@ -2994,7 +2994,7 @@ EmitNumberOp(JSContext *cx, jsdouble dval, JSCodeGenerator *cg)
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
|
||||
ale = cg->atomList.add(cg->compiler, atom);
|
||||
ale = cg->atomList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
return EmitIndexOp(cx, JSOP_DOUBLE, ALE_INDEX(ale), cg);
|
||||
@ -3433,7 +3433,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn,
|
||||
pn4->pn_type == TOK_NAME) {
|
||||
/* Note a propagated constant with the const's name. */
|
||||
JS_ASSERT(!pn4->maybeExpr());
|
||||
ale = cg->atomList.add(cg->compiler, pn4->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn4->pn_atom);
|
||||
if (!ale)
|
||||
goto bad;
|
||||
CG_NEXT(cg) = pc;
|
||||
@ -3450,7 +3450,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn,
|
||||
if (pn4 && pn4->pn_type == TOK_NAME) {
|
||||
/* Note a propagated constant with the const's name. */
|
||||
JS_ASSERT(!pn4->maybeExpr());
|
||||
ale = cg->atomList.add(cg->compiler, pn4->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn4->pn_atom);
|
||||
if (!ale)
|
||||
goto bad;
|
||||
CG_NEXT(cg) = pc;
|
||||
@ -3531,7 +3531,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn,
|
||||
continue;
|
||||
if (!js_AtomizePrimitiveValue(cx, pn3->pn_val, &atom))
|
||||
goto bad;
|
||||
ale = cg->atomList.add(cg->compiler, atom);
|
||||
ale = cg->atomList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
goto bad;
|
||||
SET_INDEX(pc, ALE_INDEX(ale));
|
||||
@ -3640,7 +3640,7 @@ MaybeEmitVarDecl(JSContext *cx, JSCodeGenerator *cg, JSOp prologOp,
|
||||
if (pn->pn_cookie != FREE_UPVAR_COOKIE) {
|
||||
atomIndex = (jsatomid) UPVAR_FRAME_SLOT(pn->pn_cookie);
|
||||
} else {
|
||||
ale = cg->atomList.add(cg->compiler, pn->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn->pn_atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
atomIndex = ALE_INDEX(ale);
|
||||
@ -4393,7 +4393,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSCodeGenerator *cg2 =
|
||||
new (cg2space) JSCodeGenerator(cg->compiler,
|
||||
new (cg2space) JSCodeGenerator(cg->parser,
|
||||
cg->codePool, cg->notePool,
|
||||
pn->pn_pos.begin.lineno);
|
||||
cg2->flags = pn->pn_funbox->tcflags | TCF_IN_FUNCTION;
|
||||
@ -5053,7 +5053,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
stmt = cg->topStmt;
|
||||
atom = pn->pn_atom;
|
||||
if (atom) {
|
||||
ale = cg->atomList.add(cg->compiler, atom);
|
||||
ale = cg->atomList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
while (stmt->type != STMT_LABEL || stmt->label != atom)
|
||||
@ -5076,7 +5076,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
if (atom) {
|
||||
/* Find the loop statement enclosed by the matching label. */
|
||||
JSStmtInfo *loop = NULL;
|
||||
ale = cg->atomList.add(cg->compiler, atom);
|
||||
ale = cg->atomList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
while (stmt->type != STMT_LABEL || stmt->label != atom) {
|
||||
@ -5667,7 +5667,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
case TOK_COLON:
|
||||
/* Emit an annotated nop so we know to decompile a label. */
|
||||
atom = pn->pn_atom;
|
||||
ale = cg->atomList.add(cg->compiler, atom);
|
||||
ale = cg->atomList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
pn2 = pn->expr();
|
||||
@ -5741,7 +5741,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
if (pn2->pn_cookie != FREE_UPVAR_COOKIE) {
|
||||
atomIndex = (jsatomid) pn2->pn_cookie;
|
||||
} else {
|
||||
ale = cg->atomList.add(cg->compiler, pn2->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn2->pn_atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
atomIndex = ALE_INDEX(ale);
|
||||
@ -5752,7 +5752,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
case TOK_DOT:
|
||||
if (!js_EmitTree(cx, cg, pn2->expr()))
|
||||
return JS_FALSE;
|
||||
ale = cg->atomList.add(cg->compiler, pn2->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn2->pn_atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
atomIndex = ALE_INDEX(ale);
|
||||
@ -6653,7 +6653,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
} else {
|
||||
JS_ASSERT(pn3->pn_type == TOK_NAME ||
|
||||
pn3->pn_type == TOK_STRING);
|
||||
ale = cg->atomList.add(cg->compiler, pn3->pn_atom);
|
||||
ale = cg->atomList.add(cg->parser, pn3->pn_atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -6815,7 +6815,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
if (pn->pn_count == 0) {
|
||||
JS_ASSERT(pn->pn_type == TOK_XMLLIST);
|
||||
atom = cx->runtime->atomState.emptyAtom;
|
||||
ale = cg->atomList.add(cg->compiler, atom);
|
||||
ale = cg->atomList.add(cg->parser, atom);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
EMIT_INDEX_OP(JSOP_STRING, ALE_INDEX(ale));
|
||||
@ -6844,7 +6844,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
if (js_Emit1(cx, cg, JSOP_STARTXML) < 0)
|
||||
return JS_FALSE;
|
||||
|
||||
ale = cg->atomList.add(cg->compiler,
|
||||
ale = cg->atomList.add(cg->parser,
|
||||
(pn->pn_type == TOK_XMLETAGO)
|
||||
? cx->runtime->atomState.etagoAtom
|
||||
: cx->runtime->atomState.stagoAtom);
|
||||
@ -6878,7 +6878,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
}
|
||||
}
|
||||
|
||||
ale = cg->atomList.add(cg->compiler,
|
||||
ale = cg->atomList.add(cg->parser,
|
||||
(pn->pn_type == TOK_XMLPTAGC)
|
||||
? cx->runtime->atomState.ptagcAtom
|
||||
: cx->runtime->atomState.tagcAtom);
|
||||
@ -6915,7 +6915,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
break;
|
||||
|
||||
case TOK_XMLPI:
|
||||
ale = cg->atomList.add(cg->compiler, pn->pn_atom2);
|
||||
ale = cg->atomList.add(cg->parser, pn->pn_atom2);
|
||||
if (!ale)
|
||||
return JS_FALSE;
|
||||
if (!EmitIndexOp(cx, JSOP_QNAMEPART, ALE_INDEX(ale), cg))
|
||||
|
@ -176,7 +176,7 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
JSParseNode *blockNode; /* parse node for a block with let declarations
|
||||
(block with its own lexical scope) */
|
||||
JSAtomList decls; /* function, const, and var declarations */
|
||||
JSCompiler *compiler; /* ptr to common parsing and lexing data */
|
||||
js::Parser *parser; /* ptr to common parsing and lexing data */
|
||||
|
||||
union {
|
||||
JSFunction *fun; /* function to store argument and variable
|
||||
@ -190,7 +190,7 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
|
||||
JSFunctionBox *funbox; /* null or box for function we're compiling
|
||||
if (flags & TCF_IN_FUNCTION) and not in
|
||||
JSCompiler::compileFunctionBody */
|
||||
Compiler::compileFunctionBody */
|
||||
JSFunctionBox *functionList;
|
||||
|
||||
#ifdef JS_SCOPE_DEPTH_METER
|
||||
@ -198,13 +198,13 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
uint16 maxScopeDepth; /* maximum lexical scope chain depth */
|
||||
#endif
|
||||
|
||||
JSTreeContext(JSCompiler *jsc)
|
||||
JSTreeContext(js::Parser *prs)
|
||||
: flags(0), ngvars(0), bodyid(0), blockidGen(0),
|
||||
topStmt(NULL), topScopeStmt(NULL), blockChain(NULL), blockNode(NULL),
|
||||
compiler(jsc), scopeChain(NULL), parent(jsc->tc), staticLevel(0),
|
||||
parser(prs), scopeChain(NULL), parent(prs->tc), staticLevel(0),
|
||||
funbox(NULL), functionList(NULL), sharpSlotBase(-1)
|
||||
{
|
||||
jsc->tc = this;
|
||||
prs->tc = this;
|
||||
JS_SCOPE_DEPTH_METERING(scopeDepth = maxScopeDepth = 0);
|
||||
}
|
||||
|
||||
@ -214,9 +214,9 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
* cases, we store uint16(-1) in maxScopeDepth.
|
||||
*/
|
||||
~JSTreeContext() {
|
||||
compiler->tc = this->parent;
|
||||
parser->tc = this->parent;
|
||||
JS_SCOPE_DEPTH_METERING_IF((maxScopeDepth != uint16(-1)),
|
||||
JS_BASIC_STATS_ACCUM(&compiler
|
||||
JS_BASIC_STATS_ACCUM(&parser
|
||||
->context
|
||||
->runtime
|
||||
->lexicalScopeDepthStats,
|
||||
@ -260,7 +260,7 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
own name */
|
||||
#define TCF_HAS_FUNCTION_STMT 0x800 /* block contains a function statement */
|
||||
#define TCF_GENEXP_LAMBDA 0x1000 /* flag lambda from generator expression */
|
||||
#define TCF_COMPILE_N_GO 0x2000 /* compiler-and-go mode of script, can
|
||||
#define TCF_COMPILE_N_GO 0x2000 /* compile-and-go mode of script, can
|
||||
optimize name references based on scope
|
||||
chain */
|
||||
#define TCF_NO_SCRIPT_RVAL 0x4000 /* API caller does not want result value
|
||||
@ -281,7 +281,7 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
#define TCF_DECL_DESTRUCTURING 0x10000
|
||||
|
||||
/*
|
||||
* A request flag passed to JSCompiler::compileScript and then down via
|
||||
* A request flag passed to Compiler::compileScript and then down via
|
||||
* JSCodeGenerator to js_NewScriptFromCG, from script_compile_sub and any
|
||||
* kindred functions that need to make mutable scripts (even empty ones;
|
||||
* i.e., they can't share the const JSScript::emptyScript() singleton).
|
||||
@ -335,7 +335,7 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
* JSOPTION_STRICT warnings or strict mode errors.
|
||||
*/
|
||||
inline bool JSTreeContext::needStrictChecks() {
|
||||
return JS_HAS_STRICT_OPTION(compiler->context) ||
|
||||
return JS_HAS_STRICT_OPTION(parser->context) ||
|
||||
(flags & TCF_STRICT_MODE_CODE);
|
||||
}
|
||||
|
||||
@ -467,14 +467,14 @@ struct JSCodeGenerator : public JSTreeContext
|
||||
/*
|
||||
* Initialize cg to allocate bytecode space from codePool, source note
|
||||
* space from notePool, and all other arena-allocated temporaries from
|
||||
* jsc->context->tempPool.
|
||||
* parser->context->tempPool.
|
||||
*/
|
||||
JSCodeGenerator(JSCompiler *jsc,
|
||||
JSCodeGenerator(js::Parser *parser,
|
||||
JSArenaPool *codePool, JSArenaPool *notePool,
|
||||
uintN lineno);
|
||||
|
||||
/*
|
||||
* Release cg->codePool, cg->notePool, and compiler->context->tempPool to
|
||||
* Release cg->codePool, cg->notePool, and parser->context->tempPool to
|
||||
* marks set by JSCodeGenerator's ctor. Note that cgs are magic: they own
|
||||
* the arena pool "tops-of-stack" space above their codeMark, noteMark, and
|
||||
* tempMark points. This means you cannot alloc from tempPool and save the
|
||||
@ -493,7 +493,7 @@ struct JSCodeGenerator : public JSTreeContext
|
||||
}
|
||||
};
|
||||
|
||||
#define CG_TS(cg) TS((cg)->compiler)
|
||||
#define CG_TS(cg) TS((cg)->parser)
|
||||
|
||||
#define CG_BASE(cg) ((cg)->current->base)
|
||||
#define CG_LIMIT(cg) ((cg)->current->limit)
|
||||
|
@ -2426,9 +2426,9 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
str = cx->runtime->emptyString;
|
||||
}
|
||||
|
||||
return JSCompiler::compileFunctionBody(cx, fun, principals,
|
||||
str->chars(), str->length(),
|
||||
filename, lineno);
|
||||
return Compiler::compileFunctionBody(cx, fun, principals,
|
||||
str->chars(), str->length(),
|
||||
filename, lineno);
|
||||
}
|
||||
|
||||
JSObject *
|
||||
|
@ -1353,14 +1353,14 @@ obj_eval(JSContext *cx, uintN argc, jsval *vp)
|
||||
script->principals->subsume(script->principals, principals)))) {
|
||||
/*
|
||||
* Get the prior (cache-filling) eval's saved caller function.
|
||||
* See JSCompiler::compileScript in jsparse.cpp.
|
||||
* See Compiler::compileScript in jsparse.cpp.
|
||||
*/
|
||||
JSFunction *fun = script->getFunction(0);
|
||||
|
||||
if (fun == caller->fun) {
|
||||
/*
|
||||
* Get the source string passed for safekeeping in the
|
||||
* atom map by the prior eval to JSCompiler::compileScript.
|
||||
* atom map by the prior eval to Compiler::compileScript.
|
||||
*/
|
||||
JSString *src = ATOM_TO_STRING(script->atomMap.vector[0]);
|
||||
|
||||
@ -1412,11 +1412,11 @@ obj_eval(JSContext *cx, uintN argc, jsval *vp)
|
||||
*/
|
||||
JSStackFrame *callerFrame = (staticLevel != 0) ? caller : NULL;
|
||||
if (!script) {
|
||||
script = JSCompiler::compileScript(cx, scopeobj, callerFrame,
|
||||
principals,
|
||||
TCF_COMPILE_N_GO | TCF_NEED_MUTABLE_SCRIPT,
|
||||
str->chars(), str->length(),
|
||||
NULL, file, line, str, staticLevel);
|
||||
script = Compiler::compileScript(cx, scopeobj, callerFrame,
|
||||
principals,
|
||||
TCF_COMPILE_N_GO | TCF_NEED_MUTABLE_SCRIPT,
|
||||
str->chars(), str->length(),
|
||||
NULL, file, line, str, staticLevel);
|
||||
if (!script)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ typedef enum JSOp {
|
||||
|
||||
#define JOF_SHARPSLOT (1U<<24) /* first immediate is uint16 stack slot no.
|
||||
that needs fixup when in global code (see
|
||||
JSCompiler::compileScript) */
|
||||
Compiler::compileScript) */
|
||||
|
||||
/* Shorthands for type from format and type from opcode. */
|
||||
#define JOF_TYPE(fmt) ((fmt) & JOF_TYPEMASK)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -749,7 +749,7 @@ struct JSDefinition : public JSParseNode
|
||||
* We store definition pointers in PN_NAMESET JSAtomLists in the AST, but
|
||||
* due to redefinition these nodes may become uses of other definitions.
|
||||
* This is unusual, so we simply chase the pn_lexdef link to find the final
|
||||
* definition node. See methods called from JSCompiler::analyzeFunctions.
|
||||
* definition node. See methods called from Parser::analyzeFunctions.
|
||||
*
|
||||
* FIXME: MakeAssignment mutates for want of a parent link...
|
||||
*/
|
||||
@ -910,7 +910,10 @@ struct JSFunctionBoxQueue {
|
||||
|
||||
typedef struct BindData BindData;
|
||||
|
||||
struct JSCompiler : private js::AutoGCRooter {
|
||||
namespace js {
|
||||
|
||||
struct Parser : private js::AutoGCRooter
|
||||
{
|
||||
JSContext * const context; /* FIXME Bug 551291: use AutoGCRooter::context? */
|
||||
JSAtomListElement *aleFreeList;
|
||||
void *tempFreeList[NUM_TEMP_FREELISTS];
|
||||
@ -927,8 +930,8 @@ struct JSCompiler : private js::AutoGCRooter {
|
||||
/* Root atoms and objects allocated for the parsed tree. */
|
||||
js::AutoKeepAtoms keepAtoms;
|
||||
|
||||
JSCompiler(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL)
|
||||
: js::AutoGCRooter(cx, COMPILER), context(cx),
|
||||
Parser(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL)
|
||||
: js::AutoGCRooter(cx, PARSER), context(cx),
|
||||
aleFreeList(NULL), tokenStream(cx), principals(NULL), callerFrame(cfp),
|
||||
callerVarObj(cfp ? cfp->varobj(cx->containingCallStack(cfp)) : NULL),
|
||||
nodeList(NULL), functionCount(0), traceListHead(NULL), tc(NULL),
|
||||
@ -939,16 +942,17 @@ struct JSCompiler : private js::AutoGCRooter {
|
||||
JS_ASSERT_IF(cfp, cfp->script);
|
||||
}
|
||||
|
||||
~JSCompiler();
|
||||
~Parser();
|
||||
|
||||
friend void js::AutoGCRooter::trace(JSTracer *trc);
|
||||
friend struct JSTreeContext;
|
||||
friend struct Compiler;
|
||||
|
||||
/*
|
||||
* Initialize a compiler. Parameters are passed on to init tokenStream.
|
||||
* Initialize a parser. Parameters are passed on to init tokenStream.
|
||||
* The compiler owns the arena pool "tops-of-stack" space above the current
|
||||
* JSContext.tempPool mark. This means you cannot allocate from tempPool
|
||||
* and save the pointer beyond the next JSCompiler destructor invocation.
|
||||
* and save the pointer beyond the next Parser destructor invocation.
|
||||
*/
|
||||
bool init(const jschar *base, size_t length,
|
||||
FILE *fp, const char *filename, uintN lineno);
|
||||
@ -1051,8 +1055,27 @@ private:
|
||||
JSParseNode *xmlElementOrList(JSBool allowList);
|
||||
JSParseNode *xmlElementOrListRoot(JSBool allowList);
|
||||
#endif /* JS_HAS_XML_SUPPORT */
|
||||
};
|
||||
|
||||
struct Compiler
|
||||
{
|
||||
Parser parser;
|
||||
|
||||
Compiler(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL)
|
||||
: parser(cx, prin, cfp)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize a compiler. Parameters are passed on to init parser.
|
||||
*/
|
||||
inline bool
|
||||
init(const jschar *base, size_t length,
|
||||
FILE *fp, const char *filename, uintN lineno)
|
||||
{
|
||||
return parser.init(base, length, fp, filename, lineno);
|
||||
}
|
||||
|
||||
public:
|
||||
static bool
|
||||
compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
@ -1067,10 +1090,12 @@ public:
|
||||
unsigned staticLevel = 0);
|
||||
};
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
/*
|
||||
* Convenience macro to access JSCompiler.tokenStream as a pointer.
|
||||
* Convenience macro to access Parser.tokenStream as a pointer.
|
||||
*/
|
||||
#define TS(jsc) (&(jsc)->tokenStream)
|
||||
#define TS(p) (&(p)->tokenStream)
|
||||
|
||||
extern JSBool
|
||||
js_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc,
|
||||
|
@ -88,13 +88,18 @@ typedef uint8 jsbytecode;
|
||||
typedef uint8 jssrcnote;
|
||||
typedef uint32 jsatomid;
|
||||
|
||||
/* Class and struct forward declarations in namespace js. */
|
||||
namespace js {
|
||||
struct Parser;
|
||||
struct Compiler;
|
||||
}
|
||||
|
||||
/* Struct typedefs. */
|
||||
typedef struct JSArgumentFormatMap JSArgumentFormatMap;
|
||||
typedef struct JSCodeGenerator JSCodeGenerator;
|
||||
typedef struct JSGCThing JSGCThing;
|
||||
typedef struct JSGenerator JSGenerator;
|
||||
typedef struct JSNativeEnumerator JSNativeEnumerator;
|
||||
typedef struct JSCompiler JSCompiler;
|
||||
typedef struct JSFunctionBox JSFunctionBox;
|
||||
typedef struct JSObjectBox JSObjectBox;
|
||||
typedef struct JSParseNode JSParseNode;
|
||||
|
@ -1396,7 +1396,7 @@ TokenStream::getTokenInternal()
|
||||
*
|
||||
* https://bugzilla.mozilla.org/show_bug.cgi?id=336551
|
||||
*
|
||||
* The check for this is in jsparse.cpp, JSCompiler::compileScript.
|
||||
* The check for this is in jsparse.cpp, Compiler::compileScript.
|
||||
*/
|
||||
if ((flags & TSF_OPERAND) &&
|
||||
(JS_HAS_XML_OPTION(cx) || peekChar() != '!')) {
|
||||
|
@ -1004,7 +1004,7 @@ js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg)
|
||||
script->nfixed = (uint16) nfixed;
|
||||
js_InitAtomMap(cx, &script->atomMap, &cg->atomList);
|
||||
|
||||
filename = cg->compiler->tokenStream.getFilename();
|
||||
filename = cg->parser->tokenStream.getFilename();
|
||||
if (filename) {
|
||||
script->filename = js_SaveScriptFilename(cx, filename);
|
||||
if (!script->filename)
|
||||
@ -1017,7 +1017,7 @@ js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg)
|
||||
}
|
||||
script->nslots = script->nfixed + cg->maxStackDepth;
|
||||
script->staticLevel = uint16(cg->staticLevel);
|
||||
script->principals = cg->compiler->principals;
|
||||
script->principals = cg->parser->principals;
|
||||
if (script->principals)
|
||||
JSPRINCIPALS_HOLD(cx, script->principals);
|
||||
|
||||
|
@ -1216,10 +1216,10 @@ static const char xml_namespace_str[] = "http://www.w3.org/XML/1998/namespace";
|
||||
static const char xmlns_namespace_str[] = "http://www.w3.org/2000/xmlns/";
|
||||
|
||||
static JSObject *
|
||||
ParseNodeToQName(JSCompiler *jsc, JSParseNode *pn,
|
||||
ParseNodeToQName(Parser *parser, JSParseNode *pn,
|
||||
JSXMLArray *inScopeNSes, JSBool isAttributeName)
|
||||
{
|
||||
JSContext *cx = jsc->context;
|
||||
JSContext *cx = parser->context;
|
||||
JSString *str, *uri, *prefix, *localName;
|
||||
size_t length, offset;
|
||||
const jschar *start, *limit, *colon;
|
||||
@ -1269,14 +1269,14 @@ ParseNodeToQName(JSCompiler *jsc, JSParseNode *pn,
|
||||
}
|
||||
|
||||
if (!uri) {
|
||||
ReportCompileErrorNumber(jsc->context, &jsc->tokenStream, pn,
|
||||
ReportCompileErrorNumber(parser->context, &parser->tokenStream, pn,
|
||||
JSREPORT_ERROR, JSMSG_BAD_XML_NAMESPACE,
|
||||
js_ValueToPrintableString(jsc->context,
|
||||
js_ValueToPrintableString(parser->context,
|
||||
STRING_TO_JSVAL(prefix)));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
localName = js_NewStringCopyN(jsc->context, colon + 1, length - (offset + 1));
|
||||
localName = js_NewStringCopyN(parser->context, colon + 1, length - (offset + 1));
|
||||
if (!localName)
|
||||
return NULL;
|
||||
} else {
|
||||
@ -1301,12 +1301,12 @@ ParseNodeToQName(JSCompiler *jsc, JSParseNode *pn,
|
||||
break;
|
||||
}
|
||||
}
|
||||
prefix = uri->empty() ? jsc->context->runtime->emptyString : NULL;
|
||||
prefix = uri->empty() ? parser->context->runtime->emptyString : NULL;
|
||||
}
|
||||
localName = str;
|
||||
}
|
||||
|
||||
return NewXMLQName(jsc->context, uri, prefix, localName);
|
||||
return NewXMLQName(parser->context, uri, prefix, localName);
|
||||
}
|
||||
|
||||
static JSString *
|
||||
@ -1336,10 +1336,10 @@ ChompXMLWhitespace(JSContext *cx, JSString *str)
|
||||
}
|
||||
|
||||
static JSXML *
|
||||
ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
ParseNodeToXML(Parser *parser, JSParseNode *pn,
|
||||
JSXMLArray *inScopeNSes, uintN flags)
|
||||
{
|
||||
JSContext *cx = jsc->context;
|
||||
JSContext *cx = parser->context;
|
||||
JSXML *xml, *kid, *attr, *attrj;
|
||||
JSString *str;
|
||||
uint32 length, n, i, j;
|
||||
@ -1350,7 +1350,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
int stackDummy;
|
||||
|
||||
if (!JS_CHECK_STACK_SIZE(cx, stackDummy)) {
|
||||
ReportCompileErrorNumber(cx, &jsc->tokenStream, pn, JSREPORT_ERROR,
|
||||
ReportCompileErrorNumber(cx, &parser->tokenStream, pn, JSREPORT_ERROR,
|
||||
JSMSG_OVER_RECURSED);
|
||||
return NULL;
|
||||
}
|
||||
@ -1369,7 +1369,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
case TOK_XMLELEM:
|
||||
length = inScopeNSes->length;
|
||||
pn2 = pn->pn_head;
|
||||
xml = ParseNodeToXML(jsc, pn2, inScopeNSes, flags);
|
||||
xml = ParseNodeToXML(parser, pn2, inScopeNSes, flags);
|
||||
if (!xml)
|
||||
goto fail;
|
||||
|
||||
@ -1394,7 +1394,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
continue;
|
||||
}
|
||||
|
||||
kid = ParseNodeToXML(jsc, pn2, inScopeNSes, flags);
|
||||
kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags);
|
||||
if (kid == PN2X_SKIP_CHILD) {
|
||||
--n;
|
||||
continue;
|
||||
@ -1445,7 +1445,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
continue;
|
||||
}
|
||||
|
||||
kid = ParseNodeToXML(jsc, pn2, inScopeNSes, flags);
|
||||
kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags);
|
||||
if (kid == PN2X_SKIP_CHILD) {
|
||||
--n;
|
||||
continue;
|
||||
@ -1489,7 +1489,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
/* Enforce "Well-formedness constraint: Unique Att Spec". */
|
||||
for (pn3 = head; pn3 != pn2; pn3 = pn3->pn_next->pn_next) {
|
||||
if (pn3->pn_atom == pn2->pn_atom) {
|
||||
ReportCompileErrorNumber(cx, &jsc->tokenStream, pn2,
|
||||
ReportCompileErrorNumber(cx, &parser->tokenStream, pn2,
|
||||
JSREPORT_ERROR, JSMSG_DUPLICATE_XML_ATTR,
|
||||
js_ValueToPrintableString(cx,
|
||||
ATOM_KEY(pn2->pn_atom)));
|
||||
@ -1573,7 +1573,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
|
||||
/* Second pass: process tag name and attributes, using namespaces. */
|
||||
pn2 = pn->pn_head;
|
||||
qn = ParseNodeToQName(jsc, pn2, inScopeNSes, JS_FALSE);
|
||||
qn = ParseNodeToQName(parser, pn2, inScopeNSes, JS_FALSE);
|
||||
if (!qn)
|
||||
goto fail;
|
||||
xml->name = qn;
|
||||
@ -1584,7 +1584,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
goto fail;
|
||||
|
||||
for (i = 0; (pn2 = pn2->pn_next) != NULL; i++) {
|
||||
qn = ParseNodeToQName(jsc, pn2, inScopeNSes, JS_TRUE);
|
||||
qn = ParseNodeToQName(parser, pn2, inScopeNSes, JS_TRUE);
|
||||
if (!qn) {
|
||||
xml->xml_attrs.length = i;
|
||||
goto fail;
|
||||
@ -1599,7 +1599,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
attrjqn = attrj->name;
|
||||
if (js_EqualStrings(GetURI(attrjqn), GetURI(qn)) &&
|
||||
js_EqualStrings(GetLocalName(attrjqn), GetLocalName(qn))) {
|
||||
ReportCompileErrorNumber(cx, &jsc->tokenStream, pn2,
|
||||
ReportCompileErrorNumber(cx, &parser->tokenStream, pn2,
|
||||
JSREPORT_ERROR, JSMSG_DUPLICATE_XML_ATTR,
|
||||
js_ValueToPrintableString(cx,
|
||||
ATOM_KEY(pn2->pn_atom)));
|
||||
@ -1639,7 +1639,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
xml_class = JSXML_CLASS_COMMENT;
|
||||
} else if (pn->pn_type == TOK_XMLPI) {
|
||||
if (IS_XML(str)) {
|
||||
ReportCompileErrorNumber(cx, &jsc->tokenStream, pn,
|
||||
ReportCompileErrorNumber(cx, &parser->tokenStream, pn,
|
||||
JSREPORT_ERROR, JSMSG_RESERVED_ID,
|
||||
js_ValueToPrintableString(cx,
|
||||
STRING_TO_JSVAL(str)));
|
||||
@ -1649,7 +1649,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn,
|
||||
if (flags & XSF_IGNORE_PROCESSING_INSTRUCTIONS)
|
||||
goto skip_child;
|
||||
|
||||
qn = ParseNodeToQName(jsc, pn, inScopeNSes, JS_FALSE);
|
||||
qn = ParseNodeToQName(parser, pn, inScopeNSes, JS_FALSE);
|
||||
if (!qn)
|
||||
goto fail;
|
||||
|
||||
@ -1687,7 +1687,7 @@ skip_child:
|
||||
#undef PN2X_SKIP_CHILD
|
||||
|
||||
syntax:
|
||||
ReportCompileErrorNumber(cx, &jsc->tokenStream, pn, JSREPORT_ERROR, JSMSG_BAD_XML_MARKUP);
|
||||
ReportCompileErrorNumber(cx, &parser->tokenStream, pn, JSREPORT_ERROR, JSMSG_BAD_XML_MARKUP);
|
||||
fail:
|
||||
js_LeaveLocalRootScope(cx);
|
||||
return NULL;
|
||||
@ -1843,12 +1843,12 @@ ParseXMLSource(JSContext *cx, JSString *src)
|
||||
}
|
||||
|
||||
{
|
||||
JSCompiler jsc(cx);
|
||||
if (jsc.init(chars, length, NULL, filename, lineno)) {
|
||||
pn = jsc.parseXMLText(js_GetTopStackFrame(cx)->scopeChain, false);
|
||||
Parser parser(cx);
|
||||
if (parser.init(chars, length, NULL, filename, lineno)) {
|
||||
pn = parser.parseXMLText(js_GetTopStackFrame(cx)->scopeChain, false);
|
||||
if (pn && XMLArrayInit(cx, &nsarray, 1)) {
|
||||
if (GetXMLSettingFlags(cx, &flags))
|
||||
xml = ParseNodeToXML(&jsc, pn, &nsarray, flags);
|
||||
xml = ParseNodeToXML(&parser, pn, &nsarray, flags);
|
||||
|
||||
XMLArrayFinish(cx, &nsarray);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user