Commit aa803c7d authored by Nicholas Nethercote's avatar Nicholas Nethercote
Browse files

Bug 752816 (part 2) - Remove TCF_{NO_SCRIPT_RVAL,NEED_SCRIPT_GLOBAL} from...

Bug 752816 (part 2) - Remove TCF_{NO_SCRIPT_RVAL,NEED_SCRIPT_GLOBAL} from TreeContextFlags.  r=luke.

--HG--
extra : rebase_source : 26aacee3d6663be4a77a758b5ebab77a48c797e5
parent ee228e76
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ MarkInnerAndOuterFunctions(JSContext *cx, JSScript* script)
JSScript *
frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerFrame,
                        JSPrincipals *principals, JSPrincipals *originPrincipals,
                        uint32_t tcflags,
                        bool compileAndGo, bool noScriptRval, bool needScriptGlobal,
                        const jschar *chars, size_t length,
                        const char *filename, unsigned lineno, JSVersion version,
                        JSString *source /* = NULL */,
@@ -111,13 +111,11 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
    ParseNode *pn;
    bool inDirectivePrologue;

    JS_ASSERT(!(tcflags & ~(TCF_COMPILE_N_GO | TCF_NO_SCRIPT_RVAL | TCF_NEED_SCRIPT_GLOBAL)));

    /*
     * The scripted callerFrame can only be given for compile-and-go scripts
     * and non-zero static level requires callerFrame.
     */
    JS_ASSERT_IF(callerFrame, tcflags & TCF_COMPILE_N_GO);
    JS_ASSERT_IF(callerFrame, compileAndGo);
    JS_ASSERT_IF(staticLevel != 0, callerFrame);

    Parser parser(cx, principals, originPrincipals, callerFrame);
@@ -132,7 +130,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
    if (!tc.init(cx))
        return NULL;

    BytecodeEmitter bce(&parser, &sc, tokenStream.getLineno());
    BytecodeEmitter bce(&parser, &sc, tokenStream.getLineno(), noScriptRval, needScriptGlobal);
    if (!bce.init())
        return NULL;

@@ -149,8 +147,9 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF

    RootedVar<JSScript*> script(cx);

    sc.flags |= compileAndGo ? TCF_COMPILE_N_GO : 0;

    GlobalScope globalScope(cx, globalObj);
    bce.sc->flags |= tcflags;
    bce.sc->setScopeChain(scopeChain);
    bce.globalScope = &globalScope;
    if (!SetStaticLevel(bce.sc, staticLevel))
@@ -168,7 +167,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
    bool savedCallerFun;
    savedCallerFun = false;
#endif
    if (tcflags & TCF_COMPILE_N_GO) {
    if (compileAndGo) {
        if (source) {
            /*
             * Save eval program source in script->atoms[0] for the
@@ -306,7 +305,8 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
    if (!funtc.init(cx))
        return NULL;

    BytecodeEmitter funbce(&parser, &funsc, tokenStream.getLineno());
    BytecodeEmitter funbce(&parser, &funsc, tokenStream.getLineno(),
                           /* noScriptRval = */ false, /* needsScriptGlobal = */ false);
    if (!funbce.init())
        return false;

+2 −1
Original line number Diff line number Diff line
@@ -55,7 +55,8 @@ CompileFunctionBody(JSContext *cx, JSFunction *fun,
JSScript *
CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerFrame,
              JSPrincipals *principals, JSPrincipals *originPrincipals,
              uint32_t tcflags, const jschar *chars, size_t length,
              bool compileAndGo, bool noScriptRval, bool needScriptGlobal,
              const jschar *chars, size_t length,
              const char *filename, unsigned lineno, JSVersion version,
              JSString *source = NULL, unsigned staticLevel = 0);

+14 −5
Original line number Diff line number Diff line
@@ -98,7 +98,8 @@ NewTryNote(JSContext *cx, BytecodeEmitter *bce, JSTryNoteKind kind, unsigned sta
static JSBool
SetSrcNoteOffset(JSContext *cx, BytecodeEmitter *bce, unsigned index, unsigned which, ptrdiff_t offset);

BytecodeEmitter::BytecodeEmitter(Parser *parser, SharedContext *sc, unsigned lineno)
BytecodeEmitter::BytecodeEmitter(Parser *parser, SharedContext *sc, unsigned lineno,
                                 bool noScriptRval, bool needScriptGlobal)
  : sc(sc),
    parent(NULL),
    parser(parser),
@@ -112,7 +113,9 @@ BytecodeEmitter::BytecodeEmitter(Parser *parser, SharedContext *sc, unsigned lin
    globalScope(NULL),
    closedArgs(sc->context),
    closedVars(sc->context),
    typesetCount(0)
    typesetCount(0),
    noScriptRval(noScriptRval),
    needScriptGlobal(needScriptGlobal)
{
    memset(&prolog, 0, sizeof prolog);
    memset(&main, 0, sizeof main);
@@ -4828,7 +4831,8 @@ EmitFunc(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)

    {
        SharedContext sc(cx);
        BytecodeEmitter bce2(bce->parser, &sc, pn->pn_pos.begin.lineno);
        BytecodeEmitter bce2(bce->parser, &sc, pn->pn_pos.begin.lineno,
                             /* noScriptRval = */ false, /* needsScriptGlobal = */ false);
        if (!bce2.init())
            return false;

@@ -5200,8 +5204,13 @@ EmitStatement(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
     * API users may also set the JSOPTION_NO_SCRIPT_RVAL option when
     * calling JS_Compile* to suppress JSOP_POPV.
     */
    bool wantval;
    JSBool useful = wantval = !(bce->sc->flags & (TCF_IN_FUNCTION | TCF_NO_SCRIPT_RVAL));
    bool wantval = false;
    JSBool useful = JS_FALSE;
    if (bce->sc->inFunction()) {
        JS_ASSERT(!bce->noScriptRval);
    } else {
        useful = wantval = !bce->noScriptRval;
    }

    /* Don't eliminate expressions with side effects. */
    if (!useful) {
+7 −1
Original line number Diff line number Diff line
@@ -154,7 +154,13 @@ struct BytecodeEmitter

    uint16_t        typesetCount;   /* Number of JOF_TYPESET opcodes generated */

    BytecodeEmitter(Parser *parser, SharedContext *sc, unsigned lineno);
    /* These two should only be true if sc->inFunction() is false. */
    const bool      noScriptRval:1;     /* The caller is JS_Compile*Script*. */
    const bool      needScriptGlobal:1; /* API caller does not want result value 
                                           from global script. */

    BytecodeEmitter(Parser *parser, SharedContext *sc, unsigned lineno,
                    bool noScriptRval, bool needScriptGlobal);
    bool init();

    /*
+8 −14
Original line number Diff line number Diff line
@@ -76,15 +76,12 @@ JS_ENUM_HEADER(TreeContextFlags, uint32_t)
    // script can optimize name references based on scope chain
    TCF_COMPILE_N_GO =                        0x20,

    // API caller does not want result value from global script
    TCF_NO_SCRIPT_RVAL =                      0x40,

    // This function/global/eval code body contained a Use Strict Directive.
    // Treat certain strict warnings as errors, and forbid the use of 'with'.
    // See also TSF_STRICT_MODE_CODE, JSScript::strictModeCode, and
    // JSREPORT_STRICT_ERROR.
    //
    TCF_STRICT_MODE_CODE =                    0x80,
    TCF_STRICT_MODE_CODE =                    0x40,

    // The (static) bindings of this script need to support dynamic name
    // read/write access. Here, 'dynamic' means dynamic dictionary lookup on
@@ -106,17 +103,17 @@ JS_ENUM_HEADER(TreeContextFlags, uint32_t)
    // taken not to turn off the whole 'arguments' optimization). To answer the
    // more general "is this argument aliased" question, script->needsArgsObj
    // should be tested (see JSScript::argIsAlised).
    TCF_BINDINGS_ACCESSED_DYNAMICALLY =      0x100,
    TCF_BINDINGS_ACCESSED_DYNAMICALLY =       0x80,

    // The function or a function that encloses it may define new local names
    // at runtime through means other than calling eval.
    TCF_FUN_MIGHT_ALIAS_LOCALS =             0x200,
    TCF_FUN_MIGHT_ALIAS_LOCALS =             0x100,

    // The script contains singleton initialiser JSOP_OBJECT.
    TCF_HAS_SINGLETONS =                     0x400,
    TCF_HAS_SINGLETONS =                     0x200,

    // Some enclosing scope is a with-statement or E4X filter-expression.
    TCF_IN_WITH =                            0x800,
    TCF_IN_WITH =                            0x400,

    // This function does something that can extend the set of bindings in its
    // call objects --- it does a direct eval in non-strict code, or includes a
@@ -125,10 +122,7 @@ JS_ENUM_HEADER(TreeContextFlags, uint32_t)
    // This flag is *not* inherited by enclosed or enclosing functions; it
    // applies only to the function in whose flags it appears.
    //
    TCF_FUN_EXTENSIBLE_SCOPE =              0x1000,

    // The caller is JS_Compile*Script*.
    TCF_NEED_SCRIPT_GLOBAL =                0x2000,
    TCF_FUN_EXTENSIBLE_SCOPE =               0x800,

    // Technically, every function has a binding named 'arguments'. Internally,
    // this binding is only added when 'arguments' is mentioned by the function
@@ -151,7 +145,7 @@ JS_ENUM_HEADER(TreeContextFlags, uint32_t)
    // have no special semantics: the initial value is unconditionally the
    // actual argument (or undefined if nactual < nformal).
    //
    TCF_ARGUMENTS_HAS_LOCAL_BINDING =       0x4000,
    TCF_ARGUMENTS_HAS_LOCAL_BINDING =       0x1000,

    // In many cases where 'arguments' has a local binding (as described above)
    // we do not need to actually create an arguments object in the function
@@ -162,7 +156,7 @@ JS_ENUM_HEADER(TreeContextFlags, uint32_t)
    // be unsound in several cases. The frontend filters out such cases by
    // setting this flag which eagerly sets script->needsArgsObj to true.
    //
    TCF_DEFINITELY_NEEDS_ARGS_OBJ =         0x8000
    TCF_DEFINITELY_NEEDS_ARGS_OBJ =         0x2000

} JS_ENUM_FOOTER(TreeContextFlags);

Loading