Bug 754180 - Give ObjectBox and FunctionBox constructors. r=jorendorff.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 16 May 2012 18:42:34 -0700
changeset 94199 37f2536e975e3fc45fbbd976990708c5a4a95796
parent 94198 521cd92d3c0828e5749761a4b49398c697ad9fb7
child 94200 d3b11e443f045e5f5c3de3a9b7a54483271b4cf0
child 94289 f2b2b99108a20379283763389aae595f463aa1a4
push id9510
push usernnethercote@mozilla.com
push dateThu, 17 May 2012 03:46:03 +0000
treeherdermozilla-inbound@37f2536e975e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs754180
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 754180 - Give ObjectBox and FunctionBox constructors. r=jorendorff.
js/src/frontend/ParseNode.h
js/src/frontend/Parser.cpp
--- a/js/src/frontend/ParseNode.h
+++ b/js/src/frontend/ParseNode.h
@@ -1524,16 +1524,18 @@ LinkUseToDef(ParseNode *pn, Definition *
     pn->pn_lexdef = dn;
 }
 
 struct ObjectBox {
     ObjectBox           *traceLink;
     ObjectBox           *emitLink;
     JSObject            *object;
     bool                isFunctionBox;
+
+    ObjectBox(ObjectBox *traceLink, JSObject *obj);
 };
 
 #define JSFB_LEVEL_BITS 14
 
 struct FunctionBox : public ObjectBox
 {
     ParseNode       *node;
     FunctionBox     *siblings;
@@ -1544,16 +1546,18 @@ struct FunctionBox : public ObjectBox
     bool            queued:1;
     bool            inLoop:1;               /* in a loop in parent function */
     bool            inWith:1;               /* some enclosing scope is a with-statement
                                                or E4X filter-expression */
     bool            inGenexpLambda:1;       /* lambda from generator expression */
 
     ContextFlags    cxFlags;
 
+    FunctionBox(ObjectBox* traceListHead, JSObject *obj, ParseNode *fn, TreeContext *tc);
+
     bool funIsHeavyweight()      const { return cxFlags.funIsHeavyweight; }
     bool funIsGenerator()        const { return cxFlags.funIsGenerator; }
     bool funHasExtensibleScope() const { return cxFlags.funHasExtensibleScope; }
 
     void setFunIsHeavyweight()         { cxFlags.funIsHeavyweight = true; }
 
     JSFunction *function() const { return (JSFunction *) object; }
 
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -164,91 +164,99 @@ Parser::setPrincipals(JSPrincipals *prin
     principals = prin;
     if (principals)
         JS_HoldPrincipals(principals);
     originPrincipals = originPrin;
     if (originPrincipals)
         JS_HoldPrincipals(originPrincipals);
 }
 
+ObjectBox::ObjectBox(ObjectBox* traceLink, JSObject *obj)
+  : traceLink(traceLink),
+    emitLink(NULL),
+    object(obj),
+    isFunctionBox(false)
+{
+}
+
 ObjectBox *
 Parser::newObjectBox(JSObject *obj)
 {
     JS_ASSERT(obj && !IsPoisonedPtr(obj));
 
     /*
      * We use JSContext.tempLifoAlloc to allocate parsed objects and place them
      * on a list in this Parser to ensure GC safety. Thus the tempLifoAlloc
      * arenas containing the entries must be alive until we are done with
      * scanning, parsing and code generation for the whole script or top-level
      * function.
      */
-    ObjectBox *objbox = context->tempLifoAlloc().new_<ObjectBox>();
+
+    ObjectBox *objbox = context->tempLifoAlloc().new_<ObjectBox>(traceListHead, obj);
     if (!objbox) {
         js_ReportOutOfMemory(context);
         return NULL;
     }
-    objbox->traceLink = traceListHead;
+
     traceListHead = objbox;
-    objbox->emitLink = NULL;
-    objbox->object = obj;
-    objbox->isFunctionBox = false;
+
     return objbox;
 }
 
+FunctionBox::FunctionBox(ObjectBox* traceListHead, JSObject *obj, ParseNode *fn, TreeContext *tc)
+  : ObjectBox(traceListHead, obj),
+    node(fn),
+    siblings(tc->sc->functionList),
+    kids(NULL),
+    parent(tc->sc->funbox),
+    bindings(tc->sc->context),
+    level(tc->sc->staticLevel),
+    queued(false),
+    inLoop(false),
+    inWith(!!tc->innermostWith),
+    inGenexpLambda(false),
+    cxFlags(tc->sc->context)     // the cxFlags are set in LeaveFunction
+{
+    isFunctionBox = true;
+    for (StmtInfo *stmt = tc->sc->topStmt; stmt; stmt = stmt->down) {
+        if (STMT_IS_LOOP(stmt)) {
+            inLoop = true;
+            break;
+        }
+    }
+    if (!tc->sc->inFunction) {
+        JSObject *scope = tc->sc->scopeChain();
+        while (scope) {
+            if (scope->isWith())
+                inWith = true;
+            scope = scope->enclosingScope();
+        }
+    }
+}
+
 FunctionBox *
 Parser::newFunctionBox(JSObject *obj, ParseNode *fn, TreeContext *tc)
 {
     JS_ASSERT(obj && !IsPoisonedPtr(obj));
     JS_ASSERT(obj->isFunction());
 
     /*
      * We use JSContext.tempLifoAlloc to allocate parsed objects and place them
      * on a list in this Parser to ensure GC safety. Thus the tempLifoAlloc
      * arenas containing the entries must be alive until we are done with
      * scanning, parsing and code generation for the whole script or top-level
      * function.
      */
-    FunctionBox *funbox = context->tempLifoAlloc().newPod<FunctionBox>();
+    FunctionBox *funbox = context->tempLifoAlloc().new_<FunctionBox>(traceListHead, obj, fn, tc);
     if (!funbox) {
         js_ReportOutOfMemory(context);
         return NULL;
     }
-    funbox->traceLink = traceListHead;
-    traceListHead = funbox;
-    funbox->emitLink = NULL;
-    funbox->object = obj;
-    funbox->isFunctionBox = true;
-    funbox->node = fn;
-    funbox->siblings = tc->sc->functionList;
-    tc->sc->functionList = funbox;
-    funbox->kids = NULL;
-    funbox->parent = tc->sc->funbox;
-    new (&funbox->bindings) Bindings(context);
-    funbox->queued = false;
-    funbox->inLoop = false;
-    for (StmtInfo *stmt = tc->sc->topStmt; stmt; stmt = stmt->down) {
-        if (STMT_IS_LOOP(stmt)) {
-            funbox->inLoop = true;
-            break;
-        }
-    }
-    funbox->level = tc->sc->staticLevel;
-    funbox->inWith = !!tc->innermostWith;
-    if (!tc->sc->inFunction) {
-        JSObject *scope = tc->sc->scopeChain();
-        while (scope) {
-            if (scope->isWith())
-                funbox->inWith = true;
-            scope = scope->enclosingScope();
-        }
-    }
-    funbox->inGenexpLambda = false;
-    
-    new (&funbox->cxFlags) ContextFlags(context);  // the cxFlags are set in LeaveFunction
+
+    traceListHead = tc->sc->functionList = funbox;
 
     return funbox;
 }
 
 void
 Parser::trace(JSTracer *trc)
 {
     ObjectBox *objbox = traceListHead;