Bug 614325 - Make Shape::initRuntimeState not do its thing with macros, so that a text search for any of the empty*Shape fields actually shows the location where they're assigned. r=dvander
authorJeff Walden <jwalden@mit.edu>
Tue, 16 Nov 2010 15:30:54 -0800
changeset 58292 a4f8e9da4f951a02b7ef32e599544104e6ad9610
parent 58291 eedeb03352c7880a35d1069917f0c2c3c3302c39
child 58293 d216da8609cbb9021a0d25b23af5c7e99adf8f38
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersdvander
bugs614325
milestone2.0b8pre
Bug 614325 - Make Shape::initRuntimeState not do its thing with macros, so that a text search for any of the empty*Shape fields actually shows the location where they're assigned. r=dvander
js/src/jsscope.cpp
--- a/js/src/jsscope.cpp
+++ b/js/src/jsscope.cpp
@@ -198,70 +198,72 @@ Shape::maybeHash(JSContext *cx)
 
 #ifdef DEBUG
 # include "jsprf.h"
 # define LIVE_SCOPE_METER(cx,expr) JS_LOCK_RUNTIME_VOID(cx->runtime,expr)
 #else
 # define LIVE_SCOPE_METER(cx,expr) /* nothing */
 #endif
 
+static inline bool
+InitField(JSContext *cx, EmptyShape *JSRuntime:: *field, Class *clasp, uint32 shape)
+{
+    if (EmptyShape *emptyShape = EmptyShape::create(cx, clasp)) {
+        cx->runtime->*field = emptyShape;
+        JS_ASSERT(emptyShape->shape == shape);
+        return true;
+    }
+    return false;
+}
+
 /* static */
 bool
 Shape::initRuntimeState(JSContext *cx)
 {
-    JSRuntime *rt = cx->runtime;
-
-#define SHAPE(Name) rt->empty##Name##Shape
-#define CLASP(Name) &js_##Name##Class
-
-#define INIT_EMPTY_SHAPE(Name,NAME)                                           \
-    INIT_EMPTY_SHAPE_WITH_CLASS(Name, NAME, CLASP(Name))
-
-#define INIT_EMPTY_SHAPE_WITH_CLASS(Name,NAME,clasp)                          \
-    JS_BEGIN_MACRO                                                            \
-        SHAPE(Name) = EmptyShape::create(cx, clasp);                          \
-        if (!SHAPE(Name))                                                     \
-            return false;                                                     \
-        JS_ASSERT(SHAPE(Name)->shape == Shape::EMPTY_##NAME##_SHAPE);         \
-    JS_END_MACRO
-
     /*
      * NewArguments allocates dslots to have enough room for the argc of the
      * particular arguments object being created.
      * never mutated, it's safe to pretend to have all the slots possible.
      *
      * Note how the fast paths in jsinterp.cpp for JSOP_LENGTH and JSOP_GETELEM
      * bypass resolution of scope properties for length and element indices on
      * arguments objects. This helps ensure that any arguments object needing
      * its own mutable scope (with unique shape) is a rare event.
      */
-    INIT_EMPTY_SHAPE(Arguments, ARGUMENTS);
+    if (!InitField(cx, &JSRuntime::emptyArgumentsShape, &js_ArgumentsClass,
+                   Shape::EMPTY_ARGUMENTS_SHAPE)) {
+        return false;
+    }
 
-    INIT_EMPTY_SHAPE(Block, BLOCK);
+    if (!InitField(cx, &JSRuntime::emptyBlockShape, &js_BlockClass, Shape::EMPTY_BLOCK_SHAPE))
+        return false;
 
     /*
      * Initialize the shared scope for all empty Call objects so gets for args
      * and vars do not force the creation of a mutable scope for the particular
      * call object being accessed.
      */
-    INIT_EMPTY_SHAPE(Call, CALL);
+    if (!InitField(cx, &JSRuntime::emptyCallShape, &js_CallClass, Shape::EMPTY_CALL_SHAPE))
+        return false;
 
     /* A DeclEnv object holds the name binding for a named function expression. */
-    INIT_EMPTY_SHAPE(DeclEnv, DECL_ENV);
+    if (!InitField(cx, &JSRuntime::emptyDeclEnvShape, &js_DeclEnvClass,
+                   Shape::EMPTY_DECL_ENV_SHAPE)) {
+        return false;
+    }
 
     /* Non-escaping native enumerator objects share this empty scope. */
-    INIT_EMPTY_SHAPE_WITH_CLASS(Enumerator, ENUMERATOR, &js_IteratorClass);
+    if (!InitField(cx, &JSRuntime::emptyEnumeratorShape, &js_IteratorClass,
+                   Shape::EMPTY_ENUMERATOR_SHAPE)) {
+        return false;
+    }
 
     /* Same drill for With objects. */
-    INIT_EMPTY_SHAPE(With, WITH);
-
-#undef SHAPE
-#undef CLASP
-#undef INIT_EMPTY_SHAPE
-#undef INIT_EMPTY_SHAPE_WITH_CLASS
+    if (!InitField(cx, &JSRuntime::emptyWithShape, &js_WithClass, Shape::EMPTY_WITH_SHAPE))
+        return false;
 
     return true;
 }
 
 /* static */
 void
 Shape::finishRuntimeState(JSContext *cx)
 {