Bug 607148 - Remove unnamed namespaces from SpiderMonkey code. rs=luke
authorJeff Walden <jwalden@mit.edu>
Mon, 25 Oct 2010 16:47:11 -0700
changeset 56593 4e4f70452d86f53d05515fc7bb1d84fe4fcdc7a5
parent 56592 cf8e99750fb658158372447834d1b5aa29df5a56
child 56594 d217b7dccfc6f9a190c835f408a45c971dc3bb71
push idunknown
push userunknown
push dateunknown
reviewersluke
bugs607148
milestone2.0b8pre
Bug 607148 - Remove unnamed namespaces from SpiderMonkey code. rs=luke
js/src/jsarray.cpp
js/src/jsdate.cpp
js/src/jsexn.cpp
js/src/jsfun.cpp
js/src/jsnum.cpp
js/src/jsstr.cpp
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -907,37 +907,33 @@ array_trace(JSTracer *trc, JSObject *obj
     }
 
     if (IS_GC_MARKING_TRACER(trc) && holes > MIN_SPARSE_INDEX && holes > capacity / 4 * 3) {
         /* This might fail, in which case we don't slowify it. */
         static_cast<GCMarker *>(trc)->arraysToSlowify.append(obj);
     }
 }
 
-namespace {
-
-JSBool
+static JSBool
 array_fix(JSContext *cx, JSObject *obj, bool *success, AutoIdVector *props)
 {
     JS_ASSERT(obj->isDenseArray());
 
     /*
      * We must slowify dense arrays; otherwise, we'd need to detect assignments to holes,
      * since that is effectively adding a new property to the array.
      */
     if (!obj->makeDenseArraySlow(cx) ||
         !GetPropertyNames(cx, obj, JSITER_HIDDEN | JSITER_OWNONLY, props))
         return false;
 
     *success = true;
     return true;
 }
 
-} // namespace
-
 Class js_ArrayClass = {
     "Array",
     Class::NON_NATIVE |
     JSCLASS_HAS_PRIVATE |
     JSCLASS_HAS_CACHED_PROTO(JSProto_Array),
     PropertyStub,   /* addProperty */
     PropertyStub,   /* delProperty */
     PropertyStub,   /* getProperty */
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -2014,20 +2014,18 @@ date_toGMTString(JSContext *cx, uintN ar
 }
 
 static JSBool
 date_toISOString(JSContext *cx, uintN argc, Value *vp)
 {
     return date_utc_format(cx, vp, print_iso_string);
 }
 
-namespace {
-
 /* ES5 15.9.5.44. */
-JSBool
+static JSBool
 date_toJSON(JSContext *cx, uintN argc, Value *vp)
 {
     /* Step 1. */
     JSObject *obj = js_ValueToNonNullObject(cx, vp[1]);
     if (!obj)
         return false;
 
     /* Step 2. */
@@ -2063,18 +2061,16 @@ date_toJSON(JSContext *cx, uintN argc, V
     args.thisv().setObject(*obj);
 
     if (!Invoke(cx, args, 0))
         return false;
     *vp = args.rval();
     return true;
 }
 
-}
-
 /* for Date.toLocaleString; interface to PRMJTime date struct.
  */
 static void
 new_explode(jsdouble timeval, PRMJTime *split, JSContext *cx)
 {
     jsint year = YearFromTime(timeval);
 
     split->tm_usec = (int32) msFromTime(timeval) * 1000;
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -254,29 +254,25 @@ GetStackTraceValueBuffer(JSExnPrivate *p
      * assert allows us to assume that no gap after stackElems is necessary to
      * align the buffer properly.
      */
     JS_STATIC_ASSERT(sizeof(JSStackTraceElem) % sizeof(jsval) == 0);
 
     return (jsval *)(priv->stackElems + priv->stackDepth);
 }
 
-namespace {
-
 struct CopyTo
 {
     Value *dst;
     CopyTo(jsval *dst) : dst(Valueify(dst)) {}
     void operator()(uintN, Value *src) {
         *dst++ = *src;
     }
 };
 
-}
-
 static JSBool
 InitExnPrivate(JSContext *cx, JSObject *exnObject, JSString *message,
                JSString *filename, uintN lineno, JSErrorReport *report)
 {
     JSSecurityCallbacks *callbacks;
     CheckAccessOp checkAccess;
     JSErrorReporter older;
     JSExceptionState *state;
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -204,31 +204,27 @@ NewArguments(JSContext *cx, JSObject *pa
 
     argsobj->setArgsLength(argc);
     argsobj->setArgsData(data);
     data->callee.setObject(callee);
 
     return argsobj;
 }
 
-namespace {
-
 struct STATIC_SKIP_INFERENCE PutArg
 {
     PutArg(Value *dst) : dst(dst) {}
     Value *dst;
     void operator()(uintN, Value *src) {
         if (!dst->isMagic(JS_ARGS_HOLE))
             *dst = *src;
         ++dst;
     }
 };
 
-}
-
 JSObject *
 js_GetArgsObject(JSContext *cx, JSStackFrame *fp)
 {
     /*
      * We must be in a function activation; the function must be lightweight
      * or else fp must have a variable object.
      */
     JS_ASSERT_IF(fp->fun()->isHeavyweight(), fp->hasCallObj());
@@ -646,19 +642,17 @@ args_enumerate(JSContext *cx, JSObject *
         JSObject *pobj;
         JSProperty *prop;
         if (!js_LookupProperty(cx, obj, id, &pobj, &prop))
             return false;
     }
     return true;
 }
 
-namespace {
-
-JSBool
+static JSBool
 StrictArgGetter(JSContext *cx, JSObject *obj, jsid id, Value *vp)
 {
     LeaveTrace(cx);
 
     if (!InstanceOf(cx, obj, &StrictArgumentsClass, NULL))
         return true;
 
     if (JSID_IS_INT(id)) {
@@ -675,17 +669,17 @@ StrictArgGetter(JSContext *cx, JSObject 
     } else {
         JS_ASSERT(JSID_IS_ATOM(id, cx->runtime->atomState.lengthAtom));
         if (!obj->isArgsLengthOverridden())
             vp->setInt32(obj->getArgsInitialLength());
     }
     return true;
 }
 
-JSBool
+static JSBool
 StrictArgSetter(JSContext *cx, JSObject *obj, jsid id, Value *vp)
 {
     if (!InstanceOf(cx, obj, &StrictArgumentsClass, NULL))
         return true;
 
     if (JSID_IS_INT(id)) {
         uintN arg = uintN(JSID_TO_INT(id));
         if (arg < obj->getArgsInitialLength()) {
@@ -702,17 +696,17 @@ StrictArgSetter(JSContext *cx, JSObject 
      * args_delProperty to clear the corresponding reserved slot so the GC can
      * collect its value.
      */
     AutoValueRooter tvr(cx);
     return js_DeleteProperty(cx, obj, id, tvr.addr(), true) &&
            js_SetProperty(cx, obj, id, vp, true);
 }
 
-JSBool
+static JSBool
 strictargs_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, JSObject **objp)
 {
     JS_ASSERT(obj->isStrictArguments());
 
     *objp = NULL;
     bool valid = false;
     uintN attrs = JSPROP_SHARED;
     if (JSID_IS_INT(id)) {
@@ -752,17 +746,17 @@ strictargs_resolve(JSContext *cx, JSObje
         Value tmp = UndefinedValue();
         if (!js_DefineProperty(cx, obj, id, &tmp, StrictArgGetter, StrictArgSetter, attrs))
             return false;
         *objp = obj;
     }
     return true;
 }
 
-JSBool
+static JSBool
 strictargs_enumerate(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj->isStrictArguments());
 
     /*
      * Trigger reflection in strictargs_resolve using a series of
      * js_LookupProperty calls.
      */
@@ -784,18 +778,16 @@ strictargs_enumerate(JSContext *cx, JSOb
     for (uint32 i = 0, argc = obj->getArgsInitialLength(); i < argc; i++) {
         if (!js_LookupProperty(cx, obj, INT_TO_JSID(i), &pobj, &prop))
             return false;
     }
 
     return true;
 }
 
-} // namespace
-
 static void
 args_finalize(JSContext *cx, JSObject *obj)
 {
     cx->free((void *) obj->getArgsData());
 }
 
 /*
  * If a generator's arguments or call object escapes, and the generator frame
@@ -1606,44 +1598,40 @@ fun_getProperty(JSContext *cx, JSObject 
         if (fp && fp->isFunctionFrame() && uint16(slot) < fp->numFormalArgs())
             *vp = fp->formalArg(slot);
         break;
     }
 
     return true;
 }
 
-namespace {
-
 struct LazyFunctionDataProp {
     uint16      atomOffset;
     int8        tinyid;
     uint8       attrs;
 };
 
 struct PoisonPillProp {
     uint16       atomOffset;
     int8         tinyid;
 };
 
 /* NB: no sentinels at ends -- use JS_ARRAY_LENGTH to bound loops. */
 
-const LazyFunctionDataProp lazyFunctionDataProps[] = {
+static const LazyFunctionDataProp lazyFunctionDataProps[] = {
     {ATOM_OFFSET(arity),     FUN_ARITY,      JSPROP_PERMANENT|JSPROP_READONLY},
     {ATOM_OFFSET(name),      FUN_NAME,       JSPROP_PERMANENT|JSPROP_READONLY},
 };
 
 /* Properties censored into [[ThrowTypeError]] in strict mode. */
-const PoisonPillProp poisonPillProps[] = {
+static const PoisonPillProp poisonPillProps[] = {
     {ATOM_OFFSET(arguments), FUN_ARGUMENTS },
     {ATOM_OFFSET(caller),    FUN_CALLER    },
 };
 
-}
-
 static JSBool
 fun_enumerate(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj->isFunction());
 
     jsid id;
     bool found;
 
@@ -2233,34 +2221,30 @@ js_fun_call(JSContext *cx, uintN argc, V
     args.thisv() = thisv;
     memcpy(args.argv(), argv, argc * sizeof *argv);
 
     bool ok = Invoke(cx, args, 0);
     *vp = args.rval();
     return ok;
 }
 
-namespace {
-
 struct STATIC_SKIP_INFERENCE CopyNonHoleArgs
 {
     CopyNonHoleArgs(JSObject *aobj, Value *dst) : aobj(aobj), dst(dst) {}
     JSObject *aobj;
     Value *dst;
     void operator()(uintN argi, Value *src) {
         if (aobj->getArgsElement(argi).isMagic(JS_ARGS_HOLE))
             dst->setUndefined();
         else
             *dst = *src;
         ++dst;
     }
 };
 
-}
-
 /* ES5 15.3.4.3 */
 JSBool
 js_fun_apply(JSContext *cx, uintN argc, Value *vp)
 {
     JSObject *obj = ComputeThisFromVp(cx, vp);
     if (!obj)
         return false;
 
@@ -2355,21 +2339,18 @@ js_fun_apply(JSContext *cx, uintN argc, 
 
     /* Step 9. */
     if (!Invoke(cx, args, 0))
         return false;
     *vp = args.rval();
     return true;
 }
 
-namespace {
-
-JSBool
+static JSBool
 CallOrConstructBoundFunction(JSContext *cx, uintN argc, Value *vp);
-}
 
 inline bool
 JSObject::initBoundFunction(JSContext *cx, const Value &thisArg,
                             const Value *args, uintN argslen)
 {
     JS_ASSERT(isFunction());
 
     flags |= JSObject::BOUND_FUNCTION;
@@ -2419,20 +2400,18 @@ JSObject::getBoundFunctionArguments(uint
     JS_ASSERT(isBoundFunction());
 
     argslen = getSlot(JSSLOT_BOUND_FUNCTION_ARGS_COUNT).toPrivateUint32();
     JS_ASSERT_IF(argslen > 0, numSlots() >= argslen);
 
     return getSlots() + FUN_CLASS_RESERVED_SLOTS;
 }
 
-namespace {
-
 /* ES5 15.3.4.5.1 and 15.3.4.5.2. */
-JSBool
+static JSBool
 CallOrConstructBoundFunction(JSContext *cx, uintN argc, Value *vp)
 {
     JSObject *obj = &vp[0].toObject();
     JS_ASSERT(obj->isFunction());
     JS_ASSERT(obj->isBoundFunction());
 
     LeaveTrace(cx);
 
@@ -2470,17 +2449,17 @@ CallOrConstructBoundFunction(JSContext *
     if (constructing ? !InvokeConstructor(cx, args) : !Invoke(cx, args, 0))
         return false;
 
     *vp = args.rval();
     return true;
 }
 
 /* ES5 15.3.4.5. */
-JSBool
+static JSBool
 fun_bind(JSContext *cx, uintN argc, Value *vp)
 {
     /* Step 1. */
     JSObject *target = ComputeThisFromVp(cx, vp);
     if (!target)
         return false;
 
     /* Step 2. */
@@ -2529,18 +2508,16 @@ fun_bind(JSContext *cx, uintN argc, Valu
     /* Steps 17, 19-21 are handled by fun_resolve. */
     /* Step 18 is the default for new functions. */
 
     /* Step 22. */
     vp->setObject(*funobj);
     return true;
 }
 
-}
-
 static JSFunctionSpec function_methods[] = {
 #if JS_HAS_TOSOURCE
     JS_FN(js_toSource_str,   fun_toSource,   0,0),
 #endif
     JS_FN(js_toString_str,   fun_toString,   0,0),
     JS_FN(js_apply_str,      js_fun_apply,   2,0),
     JS_FN(js_call_str,       js_fun_call,    1,0),
     JS_FN("bind",            fun_bind,       1,0),
@@ -2761,28 +2738,24 @@ Function(JSContext *cx, uintN argc, Valu
         str = cx->runtime->emptyString;
     }
 
     return Compiler::compileFunctionBody(cx, fun, principals,
                                          str->chars(), str->length(),
                                          filename, lineno);
 }
 
-namespace {
-
-JSBool
+static JSBool
 ThrowTypeError(JSContext *cx, uintN argc, Value *vp)
 {
     JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL,
                                  JSMSG_THROW_TYPE_ERROR);
     return false;
 }
 
-}
-
 JSObject *
 js_InitFunctionClass(JSContext *cx, JSObject *obj)
 {
     JSObject *proto = js_InitClass(cx, obj, NULL, &js_FunctionClass, Function, 1,
                                    NULL, function_methods, NULL, NULL);
     if (!proto)
         return NULL;
 
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -99,24 +99,22 @@ JS_STATIC_ASSERT(uintptr_t(-1) == UINTPT
 JS_STATIC_ASSERT(size_t(-1) == SIZE_MAX);
 JS_STATIC_ASSERT(PTRDIFF_MAX > PTRDIFF_MIN);
 JS_STATIC_ASSERT(ptrdiff_t(PTRDIFF_MAX) == PTRDIFF_MAX);
 JS_STATIC_ASSERT(ptrdiff_t(PTRDIFF_MIN) == PTRDIFF_MIN);
 JS_STATIC_ASSERT(uintptr_t(PTRDIFF_MAX) + uintptr_t(1) == uintptr_t(PTRDIFF_MIN));
 
 #endif /* JS_HAVE_STDINT_H */
 
-namespace {
-
 /*
  * If we're accumulating a decimal number and the number is >= 2^53, then the
  * fast result from the loop in GetPrefixInteger may be inaccurate. Call
  * js_strtod_harder to get the correct answer.
  */
-bool
+static bool
 ComputeAccurateDecimalInteger(JSContext *cx, const jschar *start, const jschar *end, jsdouble *dp)
 {
     size_t length = end - start;
     char *cstr = static_cast<char *>(cx->malloc(length + 1));
     if (!cstr)
         return false;
 
     for (size_t i = 0; i < length; i++) {
@@ -181,17 +179,17 @@ class BinaryDigitReader
  * The fast result might also have been inaccurate for power-of-two bases. This
  * happens if the addition in value * 2 + digit causes a round-down to an even
  * least significant mantissa bit when the first dropped bit is a one.  If any
  * of the following digits in the number (which haven't been added in yet) are
  * nonzero, then the correct action would have been to round up instead of
  * down.  An example occurs when reading the number 0x1000000000000081, which
  * rounds to 0x1000000000000000 instead of 0x1000000000000100.
  */
-jsdouble
+static jsdouble
 ComputeAccurateBinaryBaseInteger(JSContext *cx, const jschar *start, const jschar *end, int base)
 {
     BinaryDigitReader bdr(base, start, end);
 
     /* Skip leading zeroes. */
     int bit;
     do {
         bit = bdr.nextDigit();
@@ -221,18 +219,16 @@ ComputeAccurateBinaryBaseInteger(JSConte
         }
         value += bit2 & (bit | sticky);
         value *= factor;
     }
 
     return value;
 }
 
-} // namespace
-
 namespace js {
 
 bool
 GetPrefixInteger(JSContext *cx, const jschar *start, const jschar *end, int base,
                  const jschar **endp, jsdouble *dp)
 {
     JS_ASSERT(start <= end);
     JS_ASSERT(2 <= base && base <= 36);
@@ -341,19 +337,17 @@ ParseFloat(JSContext* cx, JSString* str)
 
     str->getCharsAndEnd(bp, end);
     if (!js_strtod(cx, bp, end, &ep, &d) || ep == bp)
         return js_NaN;
     return d;
 }
 #endif
 
-namespace {
-
-bool
+static bool
 ParseIntStringHelper(JSContext *cx, const jschar *ws, const jschar *end, int maybeRadix,
                      bool stripPrefix, jsdouble *dp)
 {
     JS_ASSERT(maybeRadix == 0 || (2 <= maybeRadix && maybeRadix <= 36));
     JS_ASSERT(ws <= end);
 
     const jschar *s = js_SkipWhiteSpace(ws, end);
     JS_ASSERT(ws <= s);
@@ -396,30 +390,28 @@ ParseIntStringHelper(JSContext *cx, cons
         return false;
     if (s == actualEnd)
         *dp = js_NaN;
     else if (negative)
         *dp = -*dp;
     return true;
 }
 
-jsdouble
+static jsdouble
 ParseIntDoubleHelper(jsdouble d)
 {
     if (!JSDOUBLE_IS_FINITE(d))
         return js_NaN;
     if (d > 0)
         return floor(d);
     if (d < 0)
         return -floor(-d);
     return 0;
 }
 
-} // namespace
-
 /* See ECMA 15.1.2.2. */
 static JSBool
 num_parseInt(JSContext *cx, uintN argc, Value *vp)
 {
     /* Fast paths and exceptional cases. */
     if (argc == 0) {
         vp->setDouble(js_NaN);
         return true;
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -1224,18 +1224,16 @@ js_BoyerMooreHorspool(const jschar *text
                 break;
             if (j == 0)
                 return static_cast<jsint>(i);  /* safe: max string size */
         }
     }
     return -1;
 }
 
-namespace {
-
 struct MemCmp {
     typedef jsuint Extent;
     static JS_ALWAYS_INLINE Extent computeExtent(const jschar *, jsuint patlen) {
         return (patlen - 1) * sizeof(jschar);
     }
     static JS_ALWAYS_INLINE bool match(const jschar *p, const jschar *t, Extent extent) {
         return memcmp(p, t, extent) == 0;
     }
@@ -1250,18 +1248,16 @@ struct ManualCmp {
         for (; p != extent; ++p, ++t) {
             if (*p != *t)
                 return false;
         }
         return true;
     }
 };
 
-}
-
 template <class InnerMatch>
 static jsint
 UnrolledMatch(const jschar *text, jsuint textlen, const jschar *pat, jsuint patlen)
 {
     JS_ASSERT(patlen > 0 && textlen > 0);
     const jschar *textend = text + textlen - (patlen - 1);
     const jschar p0 = *pat;
     const jschar *const patNext = pat + 1;