Bug 812314 part 1 - Use fewer namespace js {...} blocks in .cpp files in js/src, js/src/builtin, js/src/vm. r=luke.
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 16 Nov 2012 15:59:26 -0600
changeset 113837 7600a1ab2d7c79b541c67c8978ff3b12f31c9604
parent 113836 0b94284158d4daf9fc9937e8b3d47b08cc3eff95
child 113838 d19500da9c1679236fa7b2e2ff0343d2687c14df
push id18408
push userjorendorff@mozilla.com
push dateTue, 20 Nov 2012 22:26:07 +0000
treeherdermozilla-inbound@d19500da9c16 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs812314
milestone20.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 812314 part 1 - Use fewer namespace js {...} blocks in .cpp files in js/src, js/src/builtin, js/src/vm. r=luke.
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_localStorage_before_after.js
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_localStorage_before_after_page.html
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_localStorage_before_after_page2.html
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_placestitle.js
browser/components/privatebrowsing/test/browser/global/title.sjs
js/src/TraceLogging.cpp
js/src/builtin/TestingFunctions.cpp
js/src/jsalloc.cpp
js/src/jsanalyze.cpp
js/src/jsapi.cpp
js/src/jsarray.cpp
js/src/jsatom.cpp
js/src/jsatominlines.h
js/src/jsbool.cpp
js/src/jsboolinlines.h
js/src/jsclone.cpp
js/src/jscntxt.cpp
js/src/jscntxtinlines.h
js/src/jscrashreport.cpp
js/src/jsdbgapi.cpp
js/src/jsexn.cpp
js/src/jsfriendapi.cpp
js/src/jsfun.cpp
js/src/jsfun.h
js/src/jsfuninlines.h
js/src/jsgc.cpp
js/src/jsgc.h
js/src/jsgcinlines.h
js/src/jsinfer.cpp
js/src/jsinferinlines.h
js/src/jsiter.cpp
js/src/jslock.h
js/src/jsmemorymetrics.cpp
js/src/jsnativestack.cpp
js/src/jsnum.cpp
js/src/jsobj.cpp
js/src/json.cpp
js/src/jsopcode.cpp
js/src/jsreflect.cpp
js/src/jsreflect.h
js/src/jsscript.cpp
js/src/jsstr.cpp
js/src/jsweakmap.cpp
js/src/jswrapper.cpp
js/src/jsxml.cpp
js/src/vm/GlobalObject.cpp
js/src/vm/ScopeObject.cpp
js/src/vm/Unicode.cpp
js/src/vm/Xdr.cpp
js/src/vm/make_unicode.py
--- a/js/src/TraceLogging.cpp
+++ b/js/src/TraceLogging.cpp
@@ -7,45 +7,45 @@
 #include "TraceLogging.h"
 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>
 #include <unistd.h>
 #include <string.h>
 #include <stdint.h>
 
+using namespace js;
+
 #ifndef TRACE_LOG_DIR
 # if defined(_WIN32)
 #  define TRACE_LOG_DIR ""
 # else
 #  define TRACE_LOG_DIR "/tmp/"
 # endif
 #endif
 
-namespace js {
-
 #if defined(__i386__)
 static __inline__ uint64_t
-rdtsc(void)
+js::rdtsc(void)
 {
     uint64_t x;
     __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
     return x;
 }
 #elif defined(__x86_64__)
 static __inline__ uint64_t
-rdtsc(void)
+js::rdtsc(void)
 {
     unsigned hi, lo;
     __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
     return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 );
 }
 #elif defined(__powerpc__)
 static __inline__ uint64_t
-rdtsc(void)
+js::rdtsc(void)
 {
     uint64_t result=0;
     uint32_t upper, lower,tmp;
     __asm__ volatile(
             "0:                  \n"
             "\tmftbu   %0           \n"
             "\tmftb    %1           \n"
             "\tmftbu   %2           \n"
@@ -237,24 +237,24 @@ TraceLogging::releaseDefaultLogger()
     if (_defaultLogger != NULL) {
         delete _defaultLogger;
         _defaultLogger = NULL;
     }
 }
 
 /* Helper functions for asm calls */
 void
-TraceLog(TraceLogging* logger, TraceLogging::Type type, JSScript* script)
+js::TraceLog(TraceLogging* logger, TraceLogging::Type type, JSScript* script)
 {
     logger->log(type, script);
 }
+
 void
-TraceLog(TraceLogging* logger, const char* log)
+js::TraceLog(TraceLogging* logger, const char* log)
 {
     logger->log(log);
 }
+
 void
-TraceLog(TraceLogging* logger, TraceLogging::Type type)
+js::TraceLog(TraceLogging* logger, TraceLogging::Type type)
 {
     logger->log(type);
 }
-
-}  /* namespace js */
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -9,16 +9,17 @@
 #include "jscompartment.h"
 #include "jsfriendapi.h"
 #include "jsgc.h"
 #include "jsobj.h"
 #include "jsobjinlines.h"
 #include "jsprf.h"
 #include "jswrapper.h"
 
+#include "builtin/TestingFunctions.h"
 #include "methodjit/MethodJIT.h"
 
 #include "vm/Stack-inl.h"
 
 using namespace js;
 using namespace JS;
 
 using mozilla::ArrayLength;
@@ -920,17 +921,13 @@ static JSFunctionSpecWithHelp TestingFun
 "displayName(fn)",
 "  Gets the display name for a function, which can possibly be a guessed or\n"
 "  inferred name based on where the function was defined. This can be\n"
 "  different from the 'name' property on the function."),
 
     JS_FS_HELP_END
 };
 
-namespace js {
-
 bool
-DefineTestingFunctions(JSContext *cx, HandleObject obj)
+js::DefineTestingFunctions(JSContext *cx, HandleObject obj)
 {
     return JS_DefineFunctionsWithHelp(cx, obj, TestingFunctions);
 }
-
-} /* namespace js */
--- a/js/src/jsalloc.cpp
+++ b/js/src/jsalloc.cpp
@@ -3,23 +3,21 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsalloc.h"
 #include "jscntxt.h"
 
-namespace js {
+using namespace js;
 
 void *
 TempAllocPolicy::onOutOfMemory(void *p, size_t nbytes)
 {
     return cx->runtime->onOutOfMemory(p, nbytes, cx);
 }
 
 void
 TempAllocPolicy::reportAllocOverflow() const
 {
     js_ReportAllocationOverflow(cx);
 }
-
-} /* namespace js */
--- a/js/src/jsanalyze.cpp
+++ b/js/src/jsanalyze.cpp
@@ -8,40 +8,39 @@
 #include "jsautooplen.h"
 #include "jscompartment.h"
 #include "jscntxt.h"
 
 #include "jsinferinlines.h"
 #include "jsobjinlines.h"
 
 using mozilla::DebugOnly;
-
-namespace js {
-namespace analyze {
+using namespace js;
+using namespace js::analyze;
 
 /////////////////////////////////////////////////////////////////////
 // Bytecode
 /////////////////////////////////////////////////////////////////////
 
 #ifdef DEBUG
 void
-PrintBytecode(JSContext *cx, JSScript *scriptArg, jsbytecode *pc)
+analyze::PrintBytecode(JSContext *cx, JSScript *scriptArg, jsbytecode *pc)
 {
     RootedScript script(cx, scriptArg);
 
     printf("#%u:", script->id());
     Sprinter sprinter(cx);
     if (!sprinter.init())
         return;
     js_Disassemble1(cx, script, pc, pc - script->code, true, &sprinter);
     fprintf(stdout, "%s", sprinter.string());
 }
 #endif
 
-inline bool
+static inline bool
 IsJumpOpcode(JSOp op)
 {
     uint32_t type = JOF_TYPE(js_CodeSpec[op].format);
 
     /*
      * LABEL opcodes have type JOF_JUMP but are no-ops, don't treat them as
      * jumps to avoid degrading precision.
      */
@@ -2124,11 +2123,8 @@ SSAValue::print() const
 
 void
 ScriptAnalysis::assertMatchingDebugMode()
 {
     JS_ASSERT(!!script_->compartment()->debugMode() == !!originalDebugMode_);
 }
 
 #endif  /* DEBUG */
-
-} /* namespace analyze */
-} /* namespace js */
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -675,59 +675,53 @@ JS_IsBuiltinFunctionConstructor(JSFuncti
  * Has a new runtime ever been created?  This flag is used to control things
  * that should happen only once across all runtimes.
  */
 static JSBool js_NewRuntimeWasCalled = JS_FALSE;
 
 /*
  * Thread Local Storage slot for storing the runtime for a thread.
  */
-namespace js {
-mozilla::ThreadLocal<PerThreadData *> TlsPerThreadData;
-}
-
-namespace JS {
+mozilla::ThreadLocal<PerThreadData *> js::TlsPerThreadData;
 
 #ifdef DEBUG
 JS_FRIEND_API(void)
-EnterAssertNoGCScope()
+JS::EnterAssertNoGCScope()
 {
     ++TlsPerThreadData.get()->gcAssertNoGCDepth;
 }
 
 JS_FRIEND_API(void)
-LeaveAssertNoGCScope()
+JS::LeaveAssertNoGCScope()
 {
     --TlsPerThreadData.get()->gcAssertNoGCDepth;
     JS_ASSERT(TlsPerThreadData.get()->gcAssertNoGCDepth >= 0);
 }
 
 JS_FRIEND_API(bool)
-InNoGCScope()
+JS::InNoGCScope()
 {
     return TlsPerThreadData.get()->gcAssertNoGCDepth > 0;
 }
 
 JS_FRIEND_API(bool)
-NeedRelaxedRootChecks()
+JS::NeedRelaxedRootChecks()
 {
     return TlsPerThreadData.get()->gcRelaxRootChecks;
 }
 #else
-JS_FRIEND_API(void) EnterAssertNoGCScope() {}
-JS_FRIEND_API(void) LeaveAssertNoGCScope() {}
-JS_FRIEND_API(bool) InNoGCScope() { return false; }
-JS_FRIEND_API(bool) NeedRelaxedRootChecks() { return false; }
+JS_FRIEND_API(void) JS::EnterAssertNoGCScope() {}
+JS_FRIEND_API(void) JS::LeaveAssertNoGCScope() {}
+JS_FRIEND_API(bool) JS::InNoGCScope() { return false; }
+JS_FRIEND_API(bool) JS::NeedRelaxedRootChecks() { return false; }
 #endif
 
-} /* namespace JS */
-
 static const JSSecurityCallbacks NullSecurityCallbacks = { };
 
-js::PerThreadData::PerThreadData(JSRuntime *runtime)
+PerThreadData::PerThreadData(JSRuntime *runtime)
   : runtime_(runtime)
 #ifdef DEBUG
   , gcRelaxRootChecks(false)
   , gcAssertNoGCDepth(0)
 #endif
 {}
 
 JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
@@ -5765,31 +5759,27 @@ JS_CallFunctionValue(JSContext *cx, JSOb
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj, fval, JSValueArray(argv, argc));
     AutoLastFrameCheck lfc(cx);
 
     return Invoke(cx, ObjectOrNullValue(obj), fval, argc, argv, rval);
 }
 
-namespace JS {
-
 JS_PUBLIC_API(bool)
-Call(JSContext *cx, jsval thisv, jsval fval, unsigned argc, jsval *argv, jsval *rval)
+JS::Call(JSContext *cx, jsval thisv, jsval fval, unsigned argc, jsval *argv, jsval *rval)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, thisv, fval, JSValueArray(argv, argc));
     AutoLastFrameCheck lfc(cx);
 
     return Invoke(cx, thisv, fval, argc, argv, rval);
 }
 
-} // namespace JS
-
 JS_PUBLIC_API(JSObject *)
 JS_New(JSContext *cx, JSObject *ctorArg, unsigned argc, jsval *argv)
 {
     RootedObject ctor(cx, ctorArg);
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, ctor, JSValueArray(argv, argc));
     AutoLastFrameCheck lfc(cx);
@@ -7101,37 +7091,33 @@ JS_CallOnce(JSCallOnceType *once, JSInit
         *once = true;
         return func();
     } else {
         return JS_TRUE;
     }
 #endif
 }
 
-namespace JS {
-
 AutoGCRooter::AutoGCRooter(JSContext *cx, ptrdiff_t tag)
   : down(cx->runtime->autoGCRooters), tag(tag), stackTop(&cx->runtime->autoGCRooters)
 {
     JS_ASSERT(this != *stackTop);
     *stackTop = this;
 }
 
 #ifdef DEBUG
 JS_PUBLIC_API(void)
-AssertArgumentsAreSane(JSContext *cx, const JS::Value &value)
+JS::AssertArgumentsAreSane(JSContext *cx, const JS::Value &value)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, value);
 }
 #endif /* DEBUG */
 
-} // namespace JS
-
 JS_PUBLIC_API(void *)
 JS_EncodeScript(JSContext *cx, JSRawScript scriptArg, uint32_t *lengthp)
 {
     XDREncoder encoder(cx);
     RootedScript script(cx, scriptArg);
     if (!encoder.codeScript(&script))
         return NULL;
     return encoder.forgetData(lengthp);
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -115,20 +115,18 @@
 using namespace js;
 using namespace js::gc;
 using namespace js::types;
 
 using mozilla::ArrayLength;
 using mozilla::DebugOnly;
 using mozilla::PointerRangeSize;
 
-namespace js {
-
 JSBool
-GetLengthProperty(JSContext *cx, HandleObject obj, uint32_t *lengthp)
+js::GetLengthProperty(JSContext *cx, HandleObject obj, uint32_t *lengthp)
 {
     if (obj->isArray()) {
         *lengthp = obj->getArrayLength();
         return true;
     }
 
     if (obj->isArguments()) {
         ArgumentsObject &argsobj = obj->asArguments();
@@ -165,17 +163,17 @@ GetLengthProperty(JSContext *cx, HandleO
  * In our implementation, it would be sufficient to check for JSVAL_IS_INT(id)
  * except that by using signed 31-bit integers we miss the top half of the
  * valid range. This function checks the string representation itself; note
  * that calling a standard conversion routine might allow strings such as
  * "08" or "4.0" as array indices, which they are not.
  *
  */
 JS_FRIEND_API(bool)
-StringIsArrayIndex(JSLinearString *str, uint32_t *indexp)
+js::StringIsArrayIndex(JSLinearString *str, uint32_t *indexp)
 {
     const jschar *s = str->chars();
     uint32_t length = str->length();
     const jschar *end = s + length;
 
     if (length == 0 || length > (sizeof("4294967294") - 1) || !JS7_ISDEC(*s))
         return false;
 
@@ -202,30 +200,28 @@ StringIsArrayIndex(JSLinearString *str, 
         *indexp = index;
         return true;
     }
 
     return false;
 }
 
 Shape *
-GetDenseArrayShape(JSContext *cx, HandleObject globalObj)
+js::GetDenseArrayShape(JSContext *cx, HandleObject globalObj)
 {
     JS_ASSERT(globalObj);
 
     JSObject *proto = globalObj->global().getOrCreateArrayPrototype(cx);
     if (!proto)
         return NULL;
 
     return EmptyShape::getInitialShape(cx, &ArrayClass, proto, proto->getParent(),
                                        gc::FINALIZE_OBJECT0);
 }
 
-}
-
 bool
 JSObject::willBeSparseDenseArray(unsigned requiredCapacity, unsigned newElementsHint)
 {
     JS_ASSERT(isDenseArray());
     JS_ASSERT(requiredCapacity > MIN_SPARSE_INDEX);
 
     unsigned cap = getDenseArrayCapacity();
     JS_ASSERT(requiredCapacity >= cap);
@@ -359,31 +355,29 @@ GetElement(JSContext *cx, HandleObject o
             *hole = JS_FALSE;
             return true;
         }
     }
 
     return DoGetElement(cx, obj, index, hole, vp);
 }
 
-namespace js {
-
 static bool
 GetElementsSlow(JSContext *cx, HandleObject aobj, uint32_t length, Value *vp)
 {
     for (uint32_t i = 0; i < length; i++) {
         if (!JSObject::getElement(cx, aobj, aobj, i, MutableHandleValue::fromMarkedLocation(&vp[i])))
             return false;
     }
 
     return true;
 }
 
 bool
-GetElements(JSContext *cx, HandleObject aobj, uint32_t length, Value *vp)
+js::GetElements(JSContext *cx, HandleObject aobj, uint32_t length, Value *vp)
 {
     if (aobj->isDenseArray() && length <= aobj->getDenseArrayInitializedLength() &&
         !js_PrototypeHasIndexedProperties(aobj)) {
         /* The prototype does not have indexed properties so hole = undefined */
         const Value *srcbeg = aobj->getDenseArrayElements();
         const Value *srcend = srcbeg + length;
         const Value *src = srcbeg;
         for (Value *dst = vp; src < srcend; ++dst, ++src)
@@ -397,18 +391,16 @@ GetElements(JSContext *cx, HandleObject 
             if (argsobj.maybeGetElements(0, length, vp))
                 return true;
         }
     }
 
     return GetElementsSlow(cx, aobj, length, vp);
 }
 
-}
-
 /*
  * Set the value of the property at the given index to v assuming v is rooted.
  */
 static JSBool
 SetArrayElement(JSContext *cx, HandleObject obj, double index, HandleValue v)
 {
     JS_ASSERT(index >= 0);
 
@@ -979,22 +971,20 @@ array_defineGeneric(JSContext *cx, Handl
 static JSBool
 array_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, HandleValue value,
                      JSPropertyOp getter, StrictPropertyOp setter, unsigned attrs)
 {
     Rooted<jsid> id(cx, NameToId(name));
     return array_defineGeneric(cx, obj, id, value, getter, setter, attrs);
 }
 
-namespace js {
-
 /* non-static for direct definition of array elements within the engine */
 JSBool
-array_defineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue value,
-                    PropertyOp getter, StrictPropertyOp setter, unsigned attrs)
+js::array_defineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue value,
+                        PropertyOp getter, StrictPropertyOp setter, unsigned attrs)
 {
     if (!obj->isDenseArray())
         return baseops::DefineElement(cx, obj, index, value, getter, setter, attrs);
 
     do {
         /*
          * UINT32_MAX is not an array index and must not affect the length
          * property, so specifically reject it.
@@ -1018,18 +1008,16 @@ array_defineElement(JSContext *cx, Handl
 
     AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter);
 
     if (!JSObject::makeDenseArraySlow(cx, obj))
         return false;
     return baseops::DefineElement(cx, obj, index, value, getter, setter, attrs);
 }
 
-} // namespace js
-
 static JSBool
 array_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, HandleValue value,
                     PropertyOp getter, StrictPropertyOp setter, unsigned attrs)
 {
     Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
     return array_defineGeneric(cx, obj, id, value, getter, setter, attrs);
 }
 
@@ -1103,40 +1091,36 @@ array_deleteProperty(JSContext *cx, Hand
         rval.setBoolean(false);
         return true;
     }
 
     rval.setBoolean(true);
     return true;
 }
 
-namespace js {
-
 /* non-static for direct deletion of array elements within the engine */
 JSBool
-array_deleteElement(JSContext *cx, HandleObject obj, uint32_t index,
-                    MutableHandleValue rval, JSBool strict)
+js::array_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleValue rval,
+                        JSBool strict)
 {
     if (!obj->isDenseArray())
         return baseops::DeleteElement(cx, obj, index, rval, strict);
 
     if (index < obj->getDenseArrayInitializedLength()) {
         obj->markDenseArrayNotPacked(cx);
         obj->setDenseArrayElement(index, MagicValue(JS_ARRAY_HOLE));
     }
 
     if (!js_SuppressDeletedElement(cx, obj, index))
         return false;
 
     rval.setBoolean(true);
     return true;
 }
 
-} // namespace js
-
 static JSBool
 array_deleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid,
                     MutableHandleValue rval, JSBool strict)
 {
     if (!obj->isDenseArray())
         return baseops::DeleteSpecial(cx, obj, sid, rval, strict);
 
     rval.setBoolean(true);
@@ -3610,17 +3594,16 @@ js_InitArrayClass(JSContext *cx, HandleO
         return NULL;
 
     return arrayProto;
 }
 
 /*
  * Array allocation functions.
  */
-namespace js {
 
 static inline bool
 EnsureNewArrayElements(JSContext *cx, JSObject *obj, uint32_t length)
 {
     /*
      * If ensureElements creates dynamically allocated slots, then having
      * fixedSlots is a waste.
      */
@@ -3687,29 +3670,29 @@ NewArray(JSContext *cx, uint32_t length,
     if (allocateCapacity && !EnsureNewArrayElements(cx, obj, length))
         return NULL;
 
     Probes::createObject(cx, obj);
     return obj;
 }
 
 JSObject * JS_FASTCALL
-NewDenseEmptyArray(JSContext *cx, RawObject proto /* = NULL */)
+js::NewDenseEmptyArray(JSContext *cx, RawObject proto /* = NULL */)
 {
     return NewArray<false>(cx, 0, proto);
 }
 
 JSObject * JS_FASTCALL
-NewDenseAllocatedArray(JSContext *cx, uint32_t length, RawObject proto /* = NULL */)
+js::NewDenseAllocatedArray(JSContext *cx, uint32_t length, RawObject proto /* = NULL */)
 {
     return NewArray<true>(cx, length, proto);
 }
 
 JSObject * JS_FASTCALL
-NewDenseUnallocatedArray(JSContext *cx, uint32_t length, RawObject proto /* = NULL */)
+js::NewDenseUnallocatedArray(JSContext *cx, uint32_t length, RawObject proto /* = NULL */)
 {
     return NewArray<false>(cx, length, proto);
 }
 
 #ifdef JS_METHODJIT
 JSObject * JS_FASTCALL
 mjit::stubs::NewDenseUnallocatedArray(VMFrame &f, uint32_t length)
 {
@@ -3717,17 +3700,18 @@ mjit::stubs::NewDenseUnallocatedArray(VM
     if (!obj)
         THROWV(NULL);
 
     return obj;
 }
 #endif
 
 JSObject *
-NewDenseCopiedArray(JSContext *cx, uint32_t length, HandleObject src, uint32_t elementOffset, RawObject proto /* = NULL */)
+js::NewDenseCopiedArray(JSContext *cx, uint32_t length, HandleObject src, uint32_t elementOffset,
+                        RawObject proto /* = NULL */)
 {
     JSObject* obj = NewArray<true>(cx, length, proto);
     if (!obj)
         return NULL;
 
     JS_ASSERT(obj->getDenseArrayCapacity() >= length);
 
     const Value* vp = src->getDenseArrayElements() + elementOffset;
@@ -3736,45 +3720,44 @@ NewDenseCopiedArray(JSContext *cx, uint3
     if (vp)
         obj->initDenseArrayElements(0, vp, length);
 
     return obj;
 }
 
 // values must point at already-rooted Value objects
 JSObject *
-NewDenseCopiedArray(JSContext *cx, uint32_t length, const Value *values, RawObject proto /* = NULL */)
+js::NewDenseCopiedArray(JSContext *cx, uint32_t length, const Value *values,
+                        RawObject proto /* = NULL */)
 {
     JSObject* obj = NewArray<true>(cx, length, proto);
     if (!obj)
         return NULL;
 
     JS_ASSERT(obj->getDenseArrayCapacity() >= length);
 
     obj->setDenseArrayInitializedLength(values ? length : 0);
 
     if (values)
         obj->initDenseArrayElements(0, values, length);
 
     return obj;
 }
 
 JSObject *
-NewSlowEmptyArray(JSContext *cx)
+js::NewSlowEmptyArray(JSContext *cx)
 {
     RootedObject obj(cx, NewBuiltinClassInstance(cx, &SlowArrayClass));
     if (!obj || !AddLengthProperty(cx, obj))
         return NULL;
 
     JSObject::setArrayLength(cx, obj, 0);
     return obj;
 }
 
-} // namespace js
-
 #ifdef DEBUG
 JSBool
 js_ArrayInfo(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     JSObject *array;
 
     for (unsigned i = 0; i < args.length(); i++) {
--- a/js/src/jsatom.cpp
+++ b/js/src/jsatom.cpp
@@ -366,37 +366,33 @@ js::AtomizeChars(JSContext *cx, const js
     CHECK_REQUEST(cx);
 
     if (!JSString::validateLength(cx, length))
         return NULL;
 
     return AtomizeInline(cx, &chars, length, ib);
 }
 
-namespace js {
-
 bool
-IndexToIdSlow(JSContext *cx, uint32_t index, jsid *idp)
+js::IndexToIdSlow(JSContext *cx, uint32_t index, jsid *idp)
 {
     JS_ASSERT(index > JSID_INT_MAX);
 
     jschar buf[UINT32_CHAR_BUFFER_LENGTH];
     RangedPtr<jschar> end(ArrayEnd(buf), buf, ArrayEnd(buf));
     RangedPtr<jschar> start = BackfillIndexInCharBuffer(index, end);
 
     JSAtom *atom = AtomizeChars(cx, start.get(), end - start);
     if (!atom)
         return false;
 
     *idp = JSID_FROM_BITS((size_t)atom);
     return true;
 }
 
-} /* namespace js */
-
 bool
 js::InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
                           jsid *idp, MutableHandleValue vp)
 {
 #if JS_HAS_XML_SUPPORT
     if (idval.isObject()) {
         JSObject *idobj = &idval.toObject();
 
--- a/js/src/jsatominlines.h
+++ b/js/src/jsatominlines.h
@@ -89,27 +89,29 @@ BackfillIndexInCharBuffer(uint32_t index
         uint32_t next = index / 10, digit = index % 10;
         *--end = '0' + digit;
         index = next;
     } while (index > 0);
 
     return end;
 }
 
+bool
+IndexToIdSlow(JSContext *cx, uint32_t index, jsid *idp);
+
 inline bool
 IndexToId(JSContext *cx, uint32_t index, jsid *idp)
 {
     MaybeCheckStackRoots(cx);
 
     if (index <= JSID_INT_MAX) {
         *idp = INT_TO_JSID(index);
         return true;
     }
 
-    extern bool IndexToIdSlow(JSContext *cx, uint32_t index, jsid *idp);
     return IndexToIdSlow(cx, index, idp);
 }
 
 inline jsid
 AtomToId(JSAtom *atom)
 {
     JS_STATIC_ASSERT(JSID_INT_MIN == 0);
 
--- a/js/src/jsbool.cpp
+++ b/js/src/jsbool.cpp
@@ -21,16 +21,17 @@
 #include "jslock.h"
 #include "jsnum.h"
 #include "jsobj.h"
 #include "jsstr.h"
 
 #include "vm/GlobalObject.h"
 #include "vm/StringBuffer.h"
 
+#include "jsboolinlines.h"
 #include "jsinferinlines.h"
 #include "jsobjinlines.h"
 
 #include "vm/BooleanObject-inl.h"
 #include "vm/GlobalObject-inl.h"
 
 using namespace js;
 using namespace js::types;
@@ -187,34 +188,28 @@ js_InitBooleanClass(JSContext *cx, Handl
 }
 
 JSString *
 js_BooleanToString(JSContext *cx, JSBool b)
 {
     return b ? cx->runtime->atomState.true_ : cx->runtime->atomState.false_;
 }
 
-namespace js {
-
 JS_PUBLIC_API(bool)
-ToBooleanSlow(const Value &v)
+js::ToBooleanSlow(const Value &v)
 {
     JS_ASSERT(v.isString());
     return v.toString()->length() != 0;
 }
 
 bool
-BooleanGetPrimitiveValueSlow(JSContext *cx, JSObject &obj, Value *vp)
+js::BooleanGetPrimitiveValueSlow(JSContext *cx, JSObject &obj, Value *vp)
 {
     InvokeArgsGuard ag;
     if (!cx->stack.pushInvokeArgs(cx, 0, &ag))
         return false;
     ag.setCallee(cx->compartment->maybeGlobal()->booleanValueOf());
     ag.setThis(ObjectValue(obj));
     if (!Invoke(cx, ag))
         return false;
     *vp = ag.rval();
     return true;
 }
-
-}  /* namespace js */
-
-
--- a/js/src/jsboolinlines.h
+++ b/js/src/jsboolinlines.h
@@ -8,23 +8,24 @@
 #define jsboolinlines_h___
 
 #include "jsobjinlines.h"
 
 #include "vm/BooleanObject-inl.h"
 
 namespace js {
 
+bool BooleanGetPrimitiveValueSlow(JSContext *, JSObject &, Value *);
+
 inline bool
 BooleanGetPrimitiveValue(JSContext *cx, JSObject &obj, Value *vp)
 {
     if (obj.isBoolean()) {
         *vp = BooleanValue(obj.asBoolean().unbox());
         return true;
     }
 
-    extern bool BooleanGetPrimitiveValueSlow(JSContext *, JSObject &, Value *);
     return BooleanGetPrimitiveValueSlow(cx, obj, vp);
 }
 
 } /* namespace js */
 
 #endif /* jsboolinlines_h___ */
--- a/js/src/jsclone.cpp
+++ b/js/src/jsclone.cpp
@@ -115,43 +115,41 @@ SwapBytes(uint64_t u)
            ((u & 0x0000ff0000000000LLU) >> 24) |
            ((u & 0x00ff000000000000LLU) >> 40) |
            ((u & 0xff00000000000000LLU) >> 56);
 #else
     return u;
 #endif
 }
 
-namespace js {
-
 bool
-WriteStructuredClone(JSContext *cx, const Value &v, uint64_t **bufp, size_t *nbytesp,
-                     const JSStructuredCloneCallbacks *cb, void *cbClosure,
-                     jsval transferable)
+js::WriteStructuredClone(JSContext *cx, const Value &v, uint64_t **bufp, size_t *nbytesp,
+                         const JSStructuredCloneCallbacks *cb, void *cbClosure,
+                         jsval transferable)
 {
     SCOutput out(cx);
     JSStructuredCloneWriter w(out, cb, cbClosure, transferable);
     return w.init() && w.write(v) && out.extractBuffer(bufp, nbytesp);
 }
 
 bool
-ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, Value *vp,
-                    const JSStructuredCloneCallbacks *cb, void *cbClosure)
+js::ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, Value *vp,
+                        const JSStructuredCloneCallbacks *cb, void *cbClosure)
 {
     SCInput in(cx, data, nbytes);
 
     /* XXX disallow callers from using internal pointers to GC things. */
     SkipRoot skip(cx, &in);
 
     JSStructuredCloneReader r(in, cb, cbClosure);
     return r.read(vp);
 }
 
 bool
-ClearStructuredClone(const uint64_t *data, size_t nbytes)
+js::ClearStructuredClone(const uint64_t *data, size_t nbytes)
 {
     const uint64_t *point = data;
     const uint64_t *end = data + nbytes / 8;
 
     uint64_t u = SwapBytes(*point++);
     uint32_t tag = uint32_t(u >> 32);
     if (tag == SCTAG_TRANSFER_MAP_HEADER) {
         if ((TransferableMapHeader)uint32_t(u) == SCTAG_TM_NOT_MARKED) {
@@ -166,34 +164,31 @@ ClearStructuredClone(const uint64_t *dat
         }
     }
 
     js_free((void *)data);
     return true;
 }
 
 bool
-StructuredCloneHasTransferObjects(const uint64_t *data, size_t nbytes,
-                                  bool *hasTransferable)
+js::StructuredCloneHasTransferObjects(const uint64_t *data, size_t nbytes, bool *hasTransferable)
 {
     *hasTransferable = false;
 
     if (data) {
         uint64_t u = SwapBytes(*data);
         uint32_t tag = uint32_t(u >> 32);
         if (tag == SCTAG_TRANSFER_MAP_HEADER) {
             *hasTransferable = true;
         }
     }
 
     return true;
 }
 
-} /* namespace js */
-
 static inline uint64_t
 PairToUInt64(uint32_t tag, uint32_t data)
 {
     return uint64_t(data) | (uint64_t(tag) << 32);
 }
 
 bool
 SCInput::eof()
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -536,33 +536,29 @@ js::DestroyContext(JSContext *cx, Destro
     } else if (mode == DCM_FORCE_GC) {
         JS_ASSERT(!rt->isHeapBusy());
         PrepareForFullGC(rt);
         GC(rt, GC_NORMAL, gcreason::DESTROY_CONTEXT);
     }
     js_delete(cx);
 }
 
-namespace js {
-
 bool
 AutoResolving::alreadyStartedSlow() const
 {
     JS_ASSERT(link);
     AutoResolving *cursor = link;
     do {
         JS_ASSERT(this != cursor);
         if (object.get() == cursor->object && id.get() == cursor->id && kind == cursor->kind)
             return true;
     } while (!!(cursor = cursor->link));
     return false;
 }
 
-} /* namespace js */
-
 static void
 ReportError(JSContext *cx, const char *message, JSErrorReport *reportp,
             JSErrorCallback callback, void *userRef)
 {
     AssertCanGC();
 
     /*
      * Check the error report, and set a JavaScript-catchable exception
@@ -749,21 +745,19 @@ js_ReportErrorVA(JSContext *cx, unsigned
     warning = JSREPORT_IS_WARNING(report.flags);
 
     ReportError(cx, message, &report, NULL, NULL);
     js_free(message);
     js_free(ucmessage);
     return warning;
 }
 
-namespace js {
-
 /* |callee| requires a usage string provided by JS_DefineFunctionsWithHelp. */
 void
-ReportUsageError(JSContext *cx, HandleObject callee, const char *msg)
+js::ReportUsageError(JSContext *cx, HandleObject callee, const char *msg)
 {
     const char *usageStr = "usage";
     PropertyName *usageAtom = Atomize(cx, usageStr, strlen(usageStr))->asPropertyName();
     DebugOnly<Shape *> shape = callee->nativeLookup(cx, NameToId(usageAtom));
     JS_ASSERT(!shape->configurable());
     JS_ASSERT(!shape->writable());
     JS_ASSERT(shape->hasDefaultGetter());
 
@@ -779,18 +773,18 @@ ReportUsageError(JSContext *cx, HandleOb
         const jschar *chars = JS_GetStringCharsZ(cx, str);
         if (!chars)
             return;
         JS_ReportError(cx, "%s. Usage: %hs", msg, chars);
     }
 }
 
 bool
-PrintError(JSContext *cx, FILE *file, const char *message, JSErrorReport *report,
-           bool reportWarnings)
+js::PrintError(JSContext *cx, FILE *file, const char *message, JSErrorReport *report,
+               bool reportWarnings)
 {
     if (!report) {
         fprintf(file, "%s\n", message);
         fflush(file);
         return false;
     }
 
     /* Conditionally ignore reported warnings. */
@@ -850,18 +844,16 @@ PrintError(JSContext *cx, FILE *file, co
         fputc('^', file);
     }
     fputc('\n', file);
     fflush(file);
     JS_free(cx, prefix);
     return true;
 }
 
-} /* namespace js */
-
 /*
  * The arguments from ap need to be packaged up into an array and stored
  * into the report struct.
  *
  * The format string addressed by the error number may contain operands
  * identified by the format {N}, where N is a decimal digit. Each of these
  * is to be replaced by the Nth argument from the va_list. The complete
  * message is placed into reportp->ucmessage converted to a JSString.
@@ -1605,18 +1597,16 @@ JSContext::mark(JSTracer *trc)
     if (isExceptionPending())
         MarkValueRoot(trc, &exception, "exception");
 
     TraceCycleDetectionSet(trc, cycleDetectorSet);
 
     MarkValueRoot(trc, &iterValue, "iterValue");
 }
 
-namespace JS {
-
 #if defined JS_THREADSAFE && defined DEBUG
 
 AutoCheckRequestDepth::AutoCheckRequestDepth(JSContext *cx)
     : cx(cx)
 {
     JS_ASSERT(cx->runtime->requestDepth || cx->runtime->isHeapBusy());
     cx->runtime->assertValidThread();
     cx->runtime->checkRequestDepth++;
@@ -1624,10 +1614,8 @@ AutoCheckRequestDepth::AutoCheckRequestD
 
 AutoCheckRequestDepth::~AutoCheckRequestDepth()
 {
     JS_ASSERT(cx->runtime->checkRequestDepth != 0);
     cx->runtime->checkRequestDepth--;
 }
 
 #endif
-
-} // namespace JS
--- a/js/src/jscntxtinlines.h
+++ b/js/src/jscntxtinlines.h
@@ -380,18 +380,16 @@ CallNativeImpl(JSContext *cx, NativeImpl
     bool ok = impl(cx, args);
     if (ok) {
         assertSameCompartment(cx, args.rval());
         JS_ASSERT_IF(!alreadyThrowing, !cx->isExceptionPending());
     }
     return ok;
 }
 
-extern JSBool CallOrConstructBoundFunction(JSContext *, unsigned, js::Value *);
-
 STATIC_PRECONDITION(ubound(args.argv_) >= argc)
 JS_ALWAYS_INLINE bool
 CallJSNativeConstructor(JSContext *cx, Native native, const CallArgs &args)
 {
 #ifdef DEBUG
     RootedObject callee(cx, &args.callee());
 #endif
 
--- a/js/src/jscrashreport.cpp
+++ b/js/src/jscrashreport.cpp
@@ -7,18 +7,18 @@
 
 #include "jsapi.h"
 #include "jscntxt.h"
 #include "jscrashreport.h"
 #include "jscrashformat.h"
 
 #include <time.h>
 
-namespace js {
-namespace crash {
+using namespace js;
+using namespace js::crash;
 
 const static int stack_snapshot_max_size = 32768;
 
 #if defined(XP_WIN)
 
 #include <windows.h>
 
 static bool
@@ -134,16 +134,19 @@ GetStack(uint64_t *stack, uint64_t *stac
 static bool
 GetStack(uint64_t *stack, uint64_t *stack_len, CrashRegisters *regs, char *buffer, size_t size)
 {
     return false;
 }
 
 #endif
 
+namespace js {
+namespace crash {
+
 class Stack : private CrashStack
 {
 public:
     Stack(uint64_t id);
 
     bool snapshot();
 };
 
@@ -201,49 +204,46 @@ Ring::copyBytes(void *data, size_t size)
         js_memcpy(buffer, (char *)data + first, second);
         offset = second;
     } else {
         js_memcpy(&buffer[offset], data, size);
         offset += size;
     }
 }
 
+} /* namespace crash */
+} /* namespace js */
+
 static bool gInitialized;
 
 static Stack gGCStack(JS_CRASH_STACK_GC);
 static Stack gErrorStack(JS_CRASH_STACK_ERROR);
 static Ring gRingBuffer(JS_CRASH_RING);
 
 void
-SnapshotGCStack()
+js::crash::SnapshotGCStack()
 {
     if (gInitialized)
         gGCStack.snapshot();
 }
 
 void
-SnapshotErrorStack()
+js::crash::SnapshotErrorStack()
 {
     if (gInitialized)
         gErrorStack.snapshot();
 }
 
 void
-SaveCrashData(uint64_t tag, void *ptr, size_t size)
+js::crash::SaveCrashData(uint64_t tag, void *ptr, size_t size)
 {
     if (gInitialized)
         gRingBuffer.push(tag, ptr, size);
 }
 
-} /* namespace crash */
-} /* namespace js */
-
-using namespace js;
-using namespace js::crash;
-
 JS_PUBLIC_API(void)
 JS_EnumerateDiagnosticMemoryRegions(JSEnumerateDiagnosticMemoryCallback callback)
 {
 #ifdef JS_CRASH_DIAGNOSTICS
     if (!gInitialized) {
         gInitialized = true;
         (*callback)(&gGCStack, sizeof(gGCStack));
         (*callback)(&gErrorStack, sizeof(gErrorStack));
--- a/js/src/jsdbgapi.cpp
+++ b/js/src/jsdbgapi.cpp
@@ -65,20 +65,18 @@ JS_SetDebugMode(JSContext *cx, JSBool de
 }
 
 JS_PUBLIC_API(void)
 JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug)
 {
     rt->debugMode = !!debug;
 }
 
-namespace js {
-
 JSTrapStatus
-ScriptDebugPrologue(JSContext *cx, StackFrame *fp)
+js::ScriptDebugPrologue(JSContext *cx, StackFrame *fp)
 {
     JS_ASSERT(fp == cx->fp());
 
     if (fp->isFramePushedByExecute()) {
         if (JSInterpreterHook hook = cx->runtime->debugHooks.executeHook)
             fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->runtime->debugHooks.executeHookData));
     } else {
         if (JSInterpreterHook hook = cx->runtime->debugHooks.callHook)
@@ -101,17 +99,17 @@ ScriptDebugPrologue(JSContext *cx, Stack
         break;
       default:
         JS_NOT_REACHED("bad Debugger::onEnterFrame JSTrapStatus value");
     }
     return status;
 }
 
 bool
-ScriptDebugEpilogue(JSContext *cx, StackFrame *fp, bool okArg)
+js::ScriptDebugEpilogue(JSContext *cx, StackFrame *fp, bool okArg)
 {
     JS_ASSERT(fp == cx->fp());
     JSBool ok = okArg;
 
     if (void *hookData = fp->maybeHookData()) {
         if (fp->isFramePushedByExecute()) {
             if (JSInterpreterHook hook = cx->runtime->debugHooks.executeHook)
                 hook(cx, Jsvalify(fp), false, &ok, hookData);
@@ -119,18 +117,16 @@ ScriptDebugEpilogue(JSContext *cx, Stack
             if (JSInterpreterHook hook = cx->runtime->debugHooks.callHook)
                 hook(cx, Jsvalify(fp), false, &ok, hookData);
         }
     }
 
     return Debugger::onLeaveFrame(cx, ok);
 }
 
-} /* namespace js */
-
 JS_FRIEND_API(JSBool)
 JS_SetDebugModeForAllCompartments(JSContext *cx, JSBool debug)
 {
     AutoDebugModeGC dmgc(cx->runtime);
 
     for (CompartmentsIter c(cx->runtime); !c.done(); c.next()) {
         // Ignore special compartments (atoms, JSD compartments)
         if (c->principals) {
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -870,36 +870,32 @@ js_GetLocalizedErrorMessage(JSContext* c
         errorString = cx->localeCallbacks
                         ->localeGetErrorMessage(userRef, locale, errorNumber);
     }
     if (!errorString)
         errorString = js_GetErrorMessage(userRef, locale, errorNumber);
     return errorString;
 }
 
-namespace js {
-
 JS_FRIEND_API(const jschar*)
-GetErrorTypeName(JSContext* cx, int16_t exnType)
+js::GetErrorTypeName(JSContext* cx, int16_t exnType)
 {
     /*
      * JSEXN_INTERNALERR returns null to prevent that "InternalError: "
      * is prepended before "uncaught exception: "
      */
     if (exnType <= JSEXN_NONE || exnType >= JSEXN_LIMIT ||
         exnType == JSEXN_INTERNALERR)
     {
         return NULL;
     }
     JSProtoKey key = GetExceptionProtoKey(exnType);
     return ClassName(key, cx)->chars();
 }
 
-} /* namespace js */
-
 #if defined ( DEBUG_mccabe ) && defined ( PRINTNAMES )
 /* For use below... get character strings for error name and exception name */
 static struct exnname { char *name; char *exception; } errortoexnname[] = {
 #define MSG_DEF(name, number, count, exception, format) \
     {#name, #exception},
 #include "js.msg"
 #undef MSG_DEF
 };
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -497,34 +497,37 @@ js::SetPreserveWrapperCallback(JSRuntime
     rt->preserveWrapperCallback = callback;
 }
 
 /*
  * The below code is for temporary telemetry use. It can be removed when
  * sufficient data has been harvested.
  */
 
+// Defined in jsxml.cpp.
 extern size_t sE4XObjectsCreated;
 
 JS_FRIEND_API(size_t)
 JS_GetE4XObjectsCreated(JSContext *)
 {
     return sE4XObjectsCreated;
 }
 
 namespace js {
+// Defined in vm/GlobalObject.cpp.
 extern size_t sSetProtoCalled;
 }
 
 JS_FRIEND_API(size_t)
 JS_SetProtoCalled(JSContext *)
 {
     return sSetProtoCalled;
 }
 
+// Defined in jsiter.cpp.
 extern size_t sCustomIteratorCount;
 
 JS_FRIEND_API(size_t)
 JS_GetCustomIteratorCount(JSContext *cx)
 {
     return sCustomIteratorCount;
 }
 
@@ -712,102 +715,100 @@ js::DumpHeapComplete(JSRuntime *rt, FILE
     IterateCompartmentsArenasCells(rt, &dtrc,
                                    DumpHeapVisitCompartment,
                                    DumpHeapVisitArena,
                                    DumpHeapVisitCell);
 
     fflush(dtrc.output);
 }
 
-namespace js {
-
 JS_FRIEND_API(const JSStructuredCloneCallbacks *)
-GetContextStructuredCloneCallbacks(JSContext *cx)
+js::GetContextStructuredCloneCallbacks(JSContext *cx)
 {
     return cx->runtime->structuredCloneCallbacks;
 }
 
 JS_FRIEND_API(JSVersion)
-VersionSetMoarXML(JSVersion version, bool enable)
+js::VersionSetMoarXML(JSVersion version, bool enable)
 {
     return enable ? JSVersion(uint32_t(version) | VersionFlags::MOAR_XML)
                   : JSVersion(uint32_t(version) & ~VersionFlags::MOAR_XML);
 }
 
 JS_FRIEND_API(bool)
-CanCallContextDebugHandler(JSContext *cx)
+js::CanCallContextDebugHandler(JSContext *cx)
 {
     return !!cx->runtime->debugHooks.debuggerHandler;
 }
 
 JS_FRIEND_API(JSTrapStatus)
-CallContextDebugHandler(JSContext *cx, JSScript *script, jsbytecode *bc, Value *rval)
+js::CallContextDebugHandler(JSContext *cx, JSScript *script, jsbytecode *bc, Value *rval)
 {
     if (!cx->runtime->debugHooks.debuggerHandler)
         return JSTRAP_RETURN;
 
     return cx->runtime->debugHooks.debuggerHandler(cx, script, bc, rval,
                                                    cx->runtime->debugHooks.debuggerHandlerData);
 }
 
 #ifdef JS_THREADSAFE
 void *
-GetOwnerThread(const JSContext *cx)
+js::GetOwnerThread(const JSContext *cx)
 {
     return cx->runtime->ownerThread();
 }
 
 JS_FRIEND_API(bool)
-ContextHasOutstandingRequests(const JSContext *cx)
+js::ContextHasOutstandingRequests(const JSContext *cx)
 {
     return cx->outstandingRequests > 0;
 }
 #endif
 
 JS_FRIEND_API(JSCompartment *)
-GetContextCompartment(const JSContext *cx)
+js::GetContextCompartment(const JSContext *cx)
 {
     return cx->compartment;
 }
 
 JS_FRIEND_API(bool)
-HasUnrootedGlobal(const JSContext *cx)
+js::HasUnrootedGlobal(const JSContext *cx)
 {
     return cx->hasRunOption(JSOPTION_UNROOTED_GLOBAL);
 }
 
 JS_FRIEND_API(void)
-SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg)
+js::SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg)
 {
     rt->activityCallback = cb;
     rt->activityCallbackArg = arg;
 }
 
 JS_FRIEND_API(bool)
-IsContextRunningJS(JSContext *cx)
+js::IsContextRunningJS(JSContext *cx)
 {
     return !cx->stack.empty();
 }
 
 JS_FRIEND_API(const CompartmentVector&)
-GetRuntimeCompartments(JSRuntime *rt)
+js::GetRuntimeCompartments(JSRuntime *rt)
 {
     return rt->compartments;
 }
 
 JS_FRIEND_API(GCSliceCallback)
-SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback)
+js::SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback)
 {
     GCSliceCallback old = rt->gcSliceCallback;
     rt->gcSliceCallback = callback;
     return old;
 }
 
 JS_FRIEND_API(bool)
-WasIncrementalGC(JSRuntime *rt)
+js::WasIncrementalGC(JSRuntime *rt)
 {
     return rt->gcIsIncremental;
 }
 
 jschar *
 GCDescription::formatMessage(JSRuntime *rt) const
 {
     return rt->gcStats.formatMessage();
@@ -815,25 +816,25 @@ GCDescription::formatMessage(JSRuntime *
 
 jschar *
 GCDescription::formatJSON(JSRuntime *rt, uint64_t timestamp) const
 {
     return rt->gcStats.formatJSON(timestamp);
 }
 
 JS_FRIEND_API(AnalysisPurgeCallback)
-SetAnalysisPurgeCallback(JSRuntime *rt, AnalysisPurgeCallback callback)
+js::SetAnalysisPurgeCallback(JSRuntime *rt, AnalysisPurgeCallback callback)
 {
     AnalysisPurgeCallback old = rt->analysisPurgeCallback;
     rt->analysisPurgeCallback = callback;
     return old;
 }
 
 JS_FRIEND_API(void)
-NotifyDidPaint(JSRuntime *rt)
+js::NotifyDidPaint(JSRuntime *rt)
 {
     if (rt->gcZeal() == gc::ZealFrameVerifierPreValue) {
         gc::VerifyBarriers(rt, gc::PreBarrierVerifier);
         return;
     }
 
     if (rt->gcZeal() == gc::ZealFrameVerifierPostValue) {
         gc::VerifyBarriers(rt, gc::PostBarrierVerifier);
@@ -849,60 +850,60 @@ NotifyDidPaint(JSRuntime *rt)
     if (IsIncrementalGCInProgress(rt) && !rt->gcInterFrameGC) {
         PrepareForIncrementalGC(rt);
         GCSlice(rt, GC_NORMAL, gcreason::REFRESH_FRAME);
     }
 
     rt->gcInterFrameGC = false;
 }
 
-extern JS_FRIEND_API(bool)
-IsIncrementalGCEnabled(JSRuntime *rt)
+JS_FRIEND_API(bool)
+js::IsIncrementalGCEnabled(JSRuntime *rt)
 {
     return rt->gcIncrementalEnabled && rt->gcMode == JSGC_MODE_INCREMENTAL;
 }
 
 JS_FRIEND_API(bool)
-IsIncrementalGCInProgress(JSRuntime *rt)
+js::IsIncrementalGCInProgress(JSRuntime *rt)
 {
     return (rt->gcIncrementalState != gc::NO_INCREMENTAL && !rt->gcVerifyPreData);
 }
 
-extern JS_FRIEND_API(void)
-DisableIncrementalGC(JSRuntime *rt)
+JS_FRIEND_API(void)
+js::DisableIncrementalGC(JSRuntime *rt)
 {
     rt->gcIncrementalEnabled = false;
 }
 
 JS_FRIEND_API(bool)
-IsIncrementalBarrierNeeded(JSRuntime *rt)
+js::IsIncrementalBarrierNeeded(JSRuntime *rt)
 {
     return (rt->gcIncrementalState == gc::MARK && !rt->isHeapBusy());
 }
 
 JS_FRIEND_API(bool)
-IsIncrementalBarrierNeeded(JSContext *cx)
+js::IsIncrementalBarrierNeeded(JSContext *cx)
 {
     return IsIncrementalBarrierNeeded(cx->runtime);
 }
 
 JS_FRIEND_API(bool)
-IsIncrementalBarrierNeededOnObject(RawObject obj)
+js::IsIncrementalBarrierNeededOnObject(RawObject obj)
 {
     return obj->compartment()->needsBarrier();
 }
 
 JS_FRIEND_API(bool)
-IsIncrementalBarrierNeededOnScript(JSScript *script)
+js::IsIncrementalBarrierNeededOnScript(JSScript *script)
 {
     return script->compartment()->needsBarrier();
 }
 
-extern JS_FRIEND_API(void)
-IncrementalReferenceBarrier(void *ptr)
+JS_FRIEND_API(void)
+js::IncrementalReferenceBarrier(void *ptr)
 {
     if (!ptr)
         return;
 
     gc::Cell *cell = static_cast<gc::Cell *>(ptr);
     JS_ASSERT(!cell->compartment()->rt->isHeapBusy());
 
     AutoMarkInDeadCompartment amn(cell->compartment());
@@ -919,87 +920,84 @@ IncrementalReferenceBarrier(void *ptr)
     else if (kind == JSTRACE_BASE_SHAPE)
         BaseShape::writeBarrierPre((BaseShape *) ptr);
     else if (kind == JSTRACE_TYPE_OBJECT)
         types::TypeObject::writeBarrierPre((types::TypeObject *) ptr);
     else
         JS_NOT_REACHED("invalid trace kind");
 }
 
-extern JS_FRIEND_API(void)
-IncrementalValueBarrier(const Value &v)
+JS_FRIEND_API(void)
+js::IncrementalValueBarrier(const Value &v)
 {
     HeapValue::writeBarrierPre(v);
 }
 
-extern JS_FRIEND_API(void)
-PokeGC(JSRuntime *rt)
+JS_FRIEND_API(void)
+js::PokeGC(JSRuntime *rt)
 {
     rt->gcPoke = true;
 }
 
 JS_FRIEND_API(JSObject *)
-GetTestingFunctions(JSContext *cx)
+js::GetTestingFunctions(JSContext *cx)
 {
     RootedObject obj(cx, JS_NewObject(cx, NULL, NULL, NULL));
     if (!obj)
         return NULL;
 
     if (!DefineTestingFunctions(cx, obj))
         return NULL;
 
     return obj;
 }
 
 JS_FRIEND_API(void)
-SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size,
-                         uint32_t max)
+js::SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, uint32_t max)
 {
     rt->spsProfiler.setProfilingStack(stack, size, max);
 }
 
 JS_FRIEND_API(void)
-EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled)
+js::EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled)
 {
     rt->spsProfiler.enable(enabled);
 }
 
 JS_FRIEND_API(jsbytecode*)
-ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip)
+js::ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip)
 {
     return rt->spsProfiler.ipToPC(script, size_t(ip));
 }
 
 JS_FRIEND_API(void)
-SetDOMCallbacks(JSRuntime *rt, const DOMCallbacks *callbacks)
+js::SetDOMCallbacks(JSRuntime *rt, const DOMCallbacks *callbacks)
 {
     rt->DOMcallbacks = callbacks;
 }
 
 JS_FRIEND_API(const DOMCallbacks *)
-GetDOMCallbacks(JSRuntime *rt)
+js::GetDOMCallbacks(JSRuntime *rt)
 {
     return rt->DOMcallbacks;
 }
 
 static void *gListBaseHandlerFamily = NULL;
 static uint32_t gListBaseExpandoSlot = 0;
 
 JS_FRIEND_API(void)
-SetListBaseInformation(void *listBaseHandlerFamily, uint32_t listBaseExpandoSlot)
+js::SetListBaseInformation(void *listBaseHandlerFamily, uint32_t listBaseExpandoSlot)
 {
     gListBaseHandlerFamily = listBaseHandlerFamily;
     gListBaseExpandoSlot = listBaseExpandoSlot;
 }
 
 void *
-GetListBaseHandlerFamily()
+js::GetListBaseHandlerFamily()
 {
     return gListBaseHandlerFamily;
 }
 
 uint32_t
-GetListBaseExpandoSlot()
+js::GetListBaseExpandoSlot()
 {
     return gListBaseExpandoSlot;
 }
-
-} // namespace js
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -961,23 +961,16 @@ js_fun_apply(JSContext *cx, unsigned arg
     /* Step 9. */
     if (!Invoke(cx, args))
         return false;
 
     *vp = args.rval();
     return true;
 }
 
-namespace js {
-
-JSBool
-CallOrConstructBoundFunction(JSContext *cx, unsigned argc, Value *vp);
-
-}
-
 static const uint32_t JSSLOT_BOUND_FUNCTION_THIS       = 0;
 static const uint32_t JSSLOT_BOUND_FUNCTION_ARGS_COUNT = 1;
 
 static const uint32_t BOUND_FUNCTION_RESERVED_SLOTS = 2;
 
 inline bool
 JSFunction::initBoundFunction(JSContext *cx, HandleValue thisArg,
                               const Value *args, unsigned argslen)
@@ -1041,21 +1034,19 @@ inline size_t
 JSFunction::getBoundFunctionArgumentCount() const
 {
     JS_ASSERT(isFunction());
     JS_ASSERT(isBoundFunction());
 
     return getSlot(JSSLOT_BOUND_FUNCTION_ARGS_COUNT).toPrivateUint32();
 }
 
-namespace js {
-
 /* ES5 15.3.4.5.1 and 15.3.4.5.2. */
 JSBool
-CallOrConstructBoundFunction(JSContext *cx, unsigned argc, Value *vp)
+js::CallOrConstructBoundFunction(JSContext *cx, unsigned argc, Value *vp)
 {
     JSFunction *fun = vp[0].toObject().toFunction();
     JS_ASSERT(fun->isBoundFunction());
 
     bool constructing = IsConstructing(vp);
 
     /* 15.3.4.5.1 step 1, 15.3.4.5.2 step 3. */
     unsigned argslen = fun->getBoundFunctionArgumentCount();
@@ -1088,18 +1079,16 @@ CallOrConstructBoundFunction(JSContext *
 
     if (constructing ? !InvokeConstructor(cx, args) : !Invoke(cx, args))
         return false;
 
     *vp = args.rval();
     return true;
 }
 
-}
-
 #if JS_HAS_GENERATORS
 static JSBool
 fun_isGenerator(JSContext *cx, unsigned argc, Value *vp)
 {
     AutoAssertNoGC nogc;
 
     RawFunction fun;
     if (!IsFunctionObject(vp[1], &fun)) {
@@ -1195,34 +1184,32 @@ OnBadFormal(JSContext *cx, TokenKind tt)
 {
     if (tt != TOK_ERROR)
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_FORMAL);
     else
         JS_ASSERT(cx->isExceptionPending());
     return false;
 }
 
-namespace js {
-
-JSFunctionSpec function_methods[] = {
+JSFunctionSpec js::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),
 #if JS_HAS_GENERATORS
     JS_FN("isGenerator",     fun_isGenerator,0,0),
 #endif
     JS_FS_END
 };
 
 JSBool
-Function(JSContext *cx, unsigned argc, Value *vp)
+js::Function(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     RootedString arg(cx);   // used multiple times below
 
     /* Block this call if security callbacks forbid it. */
     Rooted<GlobalObject*> global(cx, &args.callee().global());
     if (!global->isRuntimeCodeGenEnabled(cx)) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CSP_BLOCKED_FUNCTION);
@@ -1407,26 +1394,25 @@ Function(JSContext *cx, unsigned argc, V
         fun->setHasRest();
 
     bool ok = frontend::CompileFunctionBody(cx, fun, options, formals, chars, length);
     args.rval().setObject(*fun);
     return ok;
 }
 
 bool
-IsBuiltinFunctionConstructor(JSFunction *fun)
+js::IsBuiltinFunctionConstructor(JSFunction *fun)
 {
     return fun->maybeNative() == Function;
 }
 
-} /* namespace js */
-
 JSFunction *
 js_NewFunction(JSContext *cx, HandleObject funobjArg, Native native, unsigned nargs,
-               JSFunction::Flags flags, HandleObject parent, HandleAtom atom, js::gc::AllocKind kind)
+               JSFunction::Flags flags, HandleObject parent, HandleAtom atom,
+               js::gc::AllocKind kind)
 {
     JS_ASSERT(kind == JSFunction::FinalizeKind || kind == JSFunction::ExtendedFinalizeKind);
     JS_ASSERT(sizeof(JSFunction) <= gc::Arena::thingSize(JSFunction::FinalizeKind));
     JS_ASSERT(sizeof(FunctionExtended) <= gc::Arena::thingSize(JSFunction::ExtendedFinalizeKind));
 
     RootedObject funobj(cx, funobjArg);
     if (funobj) {
         JS_ASSERT(funobj->isFunction());
--- a/js/src/jsfun.h
+++ b/js/src/jsfun.h
@@ -344,16 +344,21 @@ ReportIncompatibleMethod(JSContext *cx, 
 
 /*
  * Report an error that call.thisv is not an acceptable this for the callee
  * function.
  */
 extern void
 ReportIncompatible(JSContext *cx, CallReceiver call);
 
+JSBool
+CallOrConstructBoundFunction(JSContext *, unsigned, js::Value *);
+
+extern JSFunctionSpec function_methods[];
+
 } /* namespace js */
 
 extern JSBool
 js_fun_apply(JSContext *cx, unsigned argc, js::Value *vp);
 
 extern JSBool
 js_fun_call(JSContext *cx, unsigned argc, js::Value *vp);
 
--- a/js/src/jsfuninlines.h
+++ b/js/src/jsfuninlines.h
@@ -201,18 +201,16 @@ inline const char *
 GetFunctionNameBytes(JSContext *cx, JSFunction *fun, JSAutoByteString *bytes)
 {
     JSAtom *atom = fun->atom();
     if (atom)
         return bytes->encode(cx, atom);
     return js_anonymous_str;
 }
 
-extern JSFunctionSpec function_methods[];
-
 extern JSBool
 Function(JSContext *cx, unsigned argc, Value *vp);
 
 extern bool
 IsBuiltinFunctionConstructor(JSFunction *fun);
 
 static inline JSObject *
 SkipScopeParent(JSObject *parent)
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -80,16 +80,17 @@
 #include "vm/Debugger.h"
 #include "vm/String.h"
 #include "ion/IonCode.h"
 #ifdef JS_ION
 # include "ion/IonMacroAssembler.h"
 #include "ion/IonFrameIterator.h"
 #endif
 
+#include "jsgcinlines.h"
 #include "jsinterpinlines.h"
 #include "jsobjinlines.h"
 
 #include "vm/ScopeObject-inl.h"
 #include "vm/String-inl.h"
 
 #ifdef MOZ_VALGRIND
 # define JS_VALGRIND
@@ -110,45 +111,41 @@
 
 using namespace js;
 using namespace js::gc;
 
 using mozilla::ArrayEnd;
 using mozilla::DebugOnly;
 using mozilla::Maybe;
 
-namespace js {
-
-namespace gc {
-
 /* Perform a Full GC every 20 seconds if MaybeGC is called */
 static const uint64_t GC_IDLE_FULL_SPAN = 20 * 1000 * 1000;
 
 /* Increase the IGC marking slice time if we are in highFrequencyGC mode. */
-const int IGC_MARK_SLICE_MULTIPLIER = 2;
+static const int IGC_MARK_SLICE_MULTIPLIER = 2;
 
 #ifdef JS_GC_ZEAL
 static void
 StartVerifyPreBarriers(JSRuntime *rt);
 
 static void
 EndVerifyPreBarriers(JSRuntime *rt);
 
 static void
 StartVerifyPostBarriers(JSRuntime *rt);
 
 static void
 EndVerifyPostBarriers(JSRuntime *rt);
 
-void
+static void
 FinishVerifier(JSRuntime *rt);
 #endif
 
 /* This array should be const, but that doesn't link right under GCC. */
-AllocKind slotsToThingKind[] = {
+AllocKind gc::slotsToThingKind[] = {
     /* 0 */  FINALIZE_OBJECT0,  FINALIZE_OBJECT2,  FINALIZE_OBJECT2,  FINALIZE_OBJECT4,
     /* 4 */  FINALIZE_OBJECT4,  FINALIZE_OBJECT8,  FINALIZE_OBJECT8,  FINALIZE_OBJECT8,
     /* 8 */  FINALIZE_OBJECT8,  FINALIZE_OBJECT12, FINALIZE_OBJECT12, FINALIZE_OBJECT12,
     /* 12 */ FINALIZE_OBJECT12, FINALIZE_OBJECT16, FINALIZE_OBJECT16, FINALIZE_OBJECT16,
     /* 16 */ FINALIZE_OBJECT16
 };
 
 JS_STATIC_ASSERT(JS_ARRAY_LENGTH(slotsToThingKind) == SLOTS_TO_THING_KIND_LIMIT);
@@ -412,17 +409,17 @@ void ArenaList::insert(ArenaHeader *a)
     JS_ASSERT_IF(!head, cursor == &head);
     a->next = *cursor;
     *cursor = a;
     if (!a->hasFreeThings())
         cursor = &a->next;
 }
 
 template<typename T>
-inline bool
+static inline bool
 FinalizeTypedArenas(FreeOp *fop,
                     ArenaHeader **src,
                     ArenaList &dest,
                     AllocKind thingKind,
                     SliceBudget &budget)
 {
     /*
      * Finalize arenas from src list, releasing empty arenas and inserting the
@@ -689,17 +686,17 @@ Chunk::init()
         arenas[i].aheader.next = (i + 1 < ArenasPerChunk)
                                  ? &arenas[i + 1].aheader
                                  : NULL;
     }
 
     /* The rest of info fields are initialized in PickChunk. */
 }
 
-inline Chunk **
+static inline Chunk **
 GetAvailableChunkList(JSCompartment *comp)
 {
     JSRuntime *rt = comp->rt;
     return comp->isSystemCompartment
            ? &rt->gcSystemAvailableChunkListHead
            : &rt->gcUserAvailableChunkListHead;
 }
 
@@ -859,19 +856,16 @@ Chunk::releaseArena(ArenaHeader *aheader
         JS_ASSERT(info.prevp);
     } else {
         rt->gcChunkSet.remove(this);
         removeFromAvailableList();
         rt->gcChunkPool.put(this);
     }
 }
 
-} /* namespace gc */
-} /* namespace js */
-
 /* The caller must hold the GC lock. */
 static Chunk *
 PickChunk(JSCompartment *comp)
 {
     JSRuntime *rt = comp->rt;
     Chunk **listHeadp = GetAvailableChunkList(comp);
     Chunk *chunk = *listHeadp;
     if (chunk)
@@ -932,19 +926,17 @@ js_InitGC(JSRuntime *rt, uint32_t maxbyt
     rt->setGCMaxMallocBytes(maxbytes);
 
 #ifndef JS_MORE_DETERMINISTIC
     rt->gcJitReleaseTime = PRMJ_Now() + JIT_SCRIPT_RELEASE_TYPES_INTERVAL;
 #endif
     return true;
 }
 
-namespace js {
-
-inline bool
+static inline bool
 InFreeList(ArenaHeader *aheader, uintptr_t addr)
 {
     if (!aheader->hasFreeThings())
         return false;
 
     FreeSpan firstSpan(aheader->getFirstFreeSpan());
 
     for (const FreeSpan *span = &firstSpan;;) {
@@ -1025,17 +1017,17 @@ enum ConservativeGCTest
     CGCT_NOTLIVE,   /* gcthing is not allocated */
     CGCT_END
 };
 
 /*
  * Tests whether w is a (possibly dead) GC thing. Returns CGCT_VALID and
  * details about the thing if so. On failure, returns the reason for rejection.
  */
-inline ConservativeGCTest
+static inline ConservativeGCTest
 IsAddressableGCThing(JSRuntime *rt, uintptr_t w,
                      bool skipUncollectedCompartments,
                      gc::AllocKind *thingKindPtr,
                      ArenaHeader **arenaHeader,
                      void **thing)
 {
     /*
      * We assume that the compiler never uses sub-word alignment to store
@@ -1103,17 +1095,17 @@ IsAddressableGCThing(JSRuntime *rt, uint
         *thingKindPtr = thingKind;
     return CGCT_VALID;
 }
 
 /*
  * Returns CGCT_VALID and mark it if the w can be a  live GC thing and sets
  * thingKind accordingly. Otherwise returns the reason for rejection.
  */
-inline ConservativeGCTest
+static inline ConservativeGCTest
 MarkIfGCThingWord(JSTracer *trc, uintptr_t w)
 {
     void *thing;
     ArenaHeader *aheader;
     AllocKind thingKind;
     ConservativeGCTest status =
         IsAddressableGCThing(trc->runtime, w, IS_GC_MARKING_TRACER(trc),
                              &thingKind, &aheader, &thing);
@@ -1239,17 +1231,17 @@ MarkConservativeStackRoots(JSTracer *trc
     MarkRangeConservativelyAndSkipIon(trc, rt, stackMin, stackEnd);
     MarkRangeConservatively(trc, cgcd->registerSnapshot.words,
                             ArrayEnd(cgcd->registerSnapshot.words));
 }
 
 #endif /* JSGC_USE_EXACT_ROOTING */
 
 void
-MarkStackRangeConservatively(JSTracer *trc, Value *beginv, Value *endv)
+js::MarkStackRangeConservatively(JSTracer *trc, Value *beginv, Value *endv)
 {
     const uintptr_t *begin = beginv->payloadUIntPtr();
     const uintptr_t *end = endv->payloadUIntPtr();
 #ifdef JS_NUNBOX32
     /*
      * With 64-bit jsvals on 32-bit systems, we can optimize a bit by
      * scanning only the payloads.
      */
@@ -1290,18 +1282,16 @@ RecordNativeStackTopForGC(JSRuntime *rt)
 #ifdef JS_THREADSAFE
     /* Record the stack top here only if we are called from a request. */
     if (!rt->requestDepth)
         return;
 #endif
     cgcd->recordStackTop();
 }
 
-} /* namespace js */
-
 void
 js_FinishGC(JSRuntime *rt)
 {
     /*
      * Wait until the background finalization stops and the helper thread
      * shuts down before we forcefully release any remaining GC memory.
      */
     rt->gcHelperThread.finish();
@@ -1445,19 +1435,16 @@ JSCompartment::reduceGCTriggerBytes(size
 {
     JS_ASSERT(amount > 0);
     JS_ASSERT(gcTriggerBytes >= amount);
     if (gcTriggerBytes - amount < rt->gcAllocationThreshold * gcHeapGrowthFactor)
         return;
     gcTriggerBytes -= amount;
 }
 
-namespace js {
-namespace gc {
-
 inline void
 ArenaLists::prepareForIncrementalGC(JSRuntime *rt)
 {
     for (size_t i = 0; i != FINALIZE_LIMIT; ++i) {
         FreeSpan *headSpan = &freeLists[i];
         if (!headSpan->isEmpty()) {
             ArenaHeader *aheader = headSpan->arenaHeader();
             aheader->allocatedDuringIncremental = true;
@@ -1804,19 +1791,16 @@ ArenaLists::refillFreeList(JSContext *cx
             break;
         runGC = true;
     }
 
     js_ReportOutOfMemory(cx);
     return NULL;
 }
 
-} /* namespace gc */
-} /* namespace js */
-
 JSGCTraceKind
 js_GetGCThingTraceKind(void *thing)
 {
     return GetGCThingTraceKind(thing);
 }
 
 JSBool
 js_LockGCThingRT(JSRuntime *rt, void *thing)
@@ -1849,20 +1833,18 @@ js_UnlockGCThingRT(JSRuntime *rt, void *
 
     if (GCLocks::Ptr p = rt->gcLocksHash.lookup(thing)) {
         rt->gcPoke = true;
         if (--p->value == 0)
             rt->gcLocksHash.remove(p);
     }
 }
 
-namespace js {
-
 void
-InitTracer(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback)
+js::InitTracer(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback)
 {
     trc->runtime = rt;
     trc->callback = callback;
     trc->debugPrinter = NULL;
     trc->debugPrintArg = NULL;
     trc->debugPrintIndex = size_t(-1);
     trc->eagerlyTraceWeakMaps = true;
 #ifdef JS_GC_ZEAL
@@ -2173,34 +2155,28 @@ GCMarker::GrayCallback(JSTracer *trc, vo
 size_t
 GCMarker::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf) const
 {
     return stack.sizeOfExcludingThis(mallocSizeOf) +
            grayRoots.sizeOfExcludingThis(mallocSizeOf);
 }
 
 void
-SetMarkStackLimit(JSRuntime *rt, size_t limit)
+js::SetMarkStackLimit(JSRuntime *rt, size_t limit)
 {
     JS_ASSERT(!rt->isHeapBusy());
     rt->gcMarker.setSizeLimit(limit);
 }
 
-} /* namespace js */
-
-namespace js {
-
 void
-MarkCompartmentActive(StackFrame *fp)
+js::MarkCompartmentActive(StackFrame *fp)
 {
     fp->script()->compartment()->active = true;
 }
 
-} /* namespace js */
-
 void
 AutoIdArray::trace(JSTracer *trc)
 {
     JS_ASSERT(tag == IDARRAY);
     gc::MarkIdRange(trc, idArray->length, idArray->vector, "JSAutoIdArray.idArray");
 }
 
 inline void
@@ -2472,18 +2448,16 @@ RegExpStatics::AutoRooter::trace(JSTrace
 }
 
 void
 HashableValue::AutoRooter::trace(JSTracer *trc)
 {
     MarkValueRoot(trc, reinterpret_cast<Value*>(&v->value), "HashableValue::AutoRooter");
 }
 
-namespace js {
-
 static void
 MarkRuntime(JSTracer *trc, bool useSavedRoots = false)
 {
     JSRuntime *rt = trc->runtime;
     JS_ASSERT(trc->callback != GCMarker::GrayCallback);
 
     if (IS_GC_MARKING_TRACER(trc)) {
         for (CompartmentsIter c(rt); !c.done(); c.next()) {
@@ -2610,29 +2584,29 @@ TriggerOperationCallback(JSRuntime *rt, 
         return;
 
     rt->gcIsNeeded = true;
     rt->gcTriggerReason = reason;
     rt->triggerOperationCallback();
 }
 
 void
-TriggerGC(JSRuntime *rt, gcreason::Reason reason)
+js::TriggerGC(JSRuntime *rt, gcreason::Reason reason)
 {
     rt->assertValidThread();
 
     if (rt->isHeapBusy())
         return;
 
     PrepareForFullGC(rt);
     TriggerOperationCallback(rt, reason);
 }
 
 void
-TriggerCompartmentGC(JSCompartment *comp, gcreason::Reason reason)
+js::TriggerCompartmentGC(JSCompartment *comp, gcreason::Reason reason)
 {
     JSRuntime *rt = comp->rt;
     rt->assertValidThread();
 
     if (rt->isHeapBusy())
         return;
 
     if (rt->gcZeal() == ZealAllocValue) {
@@ -2646,17 +2620,17 @@ TriggerCompartmentGC(JSCompartment *comp
         return;
     }
 
     PrepareCompartmentForGC(comp);
     TriggerOperationCallback(rt, reason);
 }
 
 void
-MaybeGC(JSContext *cx)
+js::MaybeGC(JSContext *cx)
 {
     JSRuntime *rt = cx->runtime;
     rt->assertValidThread();
 
     if (rt->gcZeal() == ZealAllocValue || rt->gcZeal() == ZealPokeValue) {
         PrepareForFullGC(rt);
         GC(rt, GC_NORMAL, gcreason::MAYBEGC);
         return;
@@ -2869,17 +2843,17 @@ AssertBackgroundSweepingFinished(JSRunti
         for (unsigned i = 0 ; i < FINALIZE_LIMIT ; ++i) {
             JS_ASSERT(!c->arenas.arenaListsToSweep[i]);
             JS_ASSERT(c->arenas.doneBackgroundFinalize(AllocKind(i)));
         }
     }
 }
 
 unsigned
-GetCPUCount()
+js::GetCPUCount()
 {
     static unsigned ncpus = 0;
     if (ncpus == 0) {
 # ifdef XP_WIN
         SYSTEM_INFO sysinfo;
         GetSystemInfo(&sysinfo);
         ncpus = unsigned(sysinfo.dwNumberOfProcessors);
 # else
@@ -3162,18 +3136,16 @@ GCHelperThread::doSweep()
      */
     if (!shrinking && shrinkFlag) {
         shrinkFlag = false;
         ExpireChunksAndArenas(rt, true);
     }
 }
 #endif /* JS_THREADSAFE */
 
-} /* namespace js */
-
 static bool
 ReleaseObservedTypes(JSRuntime *rt)
 {
     bool releaseTypes = rt->gcZeal() != 0;
 
 #ifndef JS_MORE_DETERMINISTIC
     int64_t now = PRMJ_Now();
     if (now >= rt->gcJitReleaseTime)
@@ -4709,70 +4681,68 @@ Collect(JSRuntime *rt, bool incremental,
 
         /*
          * On shutdown, iterate until finalizers or the JSGC_END callback
          * stop creating garbage.
          */
     } while (rt->gcPoke && rt->gcShouldCleanUpEverything);
 }
 
-namespace js {
-
 void
-GC(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason)
+js::GC(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason)
 {
     AssertCanGC();
     Collect(rt, false, SliceBudget::Unlimited, gckind, reason);
 }
 
 void
-GCSlice(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason, int64_t millis)
+js::GCSlice(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason, int64_t millis)
 {
     AssertCanGC();
     int64_t sliceBudget;
     if (millis)
         sliceBudget = SliceBudget::TimeBudget(millis);
     else if (rt->gcHighFrequencyGC && rt->gcDynamicMarkSlice)
         sliceBudget = rt->gcSliceBudget * IGC_MARK_SLICE_MULTIPLIER;
     else
         sliceBudget = rt->gcSliceBudget;
 
     Collect(rt, true, sliceBudget, gckind, reason);
 }
 
 void
-GCFinalSlice(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason)
+js::GCFinalSlice(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason)
 {
     AssertCanGC();
     Collect(rt, true, SliceBudget::Unlimited, gckind, reason);
 }
 
 void
-GCDebugSlice(JSRuntime *rt, bool limit, int64_t objCount)
+js::GCDebugSlice(JSRuntime *rt, bool limit, int64_t objCount)
 {
     AssertCanGC();
     int64_t budget = limit ? SliceBudget::WorkBudget(objCount) : SliceBudget::Unlimited;
     PrepareForDebugGC(rt);
     Collect(rt, true, budget, GC_NORMAL, gcreason::API);
 }
 
 /* Schedule a full GC unless a compartment will already be collected. */
 void
-PrepareForDebugGC(JSRuntime *rt)
+js::PrepareForDebugGC(JSRuntime *rt)
 {
     for (CompartmentsIter c(rt); !c.done(); c.next()) {
         if (c->isGCScheduled())
             return;
     }
 
     PrepareForFullGC(rt);
 }
 
 void
-ShrinkGCBuffers(JSRuntime *rt)
+js::ShrinkGCBuffers(JSRuntime *rt)
 {
     AutoLockGC lock(rt);
     JS_ASSERT(!rt->isHeapBusy());
 
     if (!rt->useHelperThreads())
         ExpireChunksAndArenas(rt, true);
     else
         rt->gcHelperThread.startBackgroundShrink();
@@ -4799,17 +4769,17 @@ struct AutoPrepareForTracing
     AutoPrepareForTracing(JSRuntime *rt)
       : finish(rt),
         session(rt),
         copy(rt)
     {}
 };
 
 void
-TraceRuntime(JSTracer *trc)
+js::TraceRuntime(JSTracer *trc)
 {
     JS_ASSERT(!IS_GC_MARKING_TRACER(trc));
 
     AutoPrepareForTracing prep(trc->runtime);
     RecordNativeStackTopForGC(trc->runtime);
     MarkRuntime(trc);
 }
 
@@ -4837,20 +4807,20 @@ struct IterateCellCallbackOp
     IterateCellCallbackOp(JSRuntime *rt, void *data, IterateCellCallback callback,
                           JSGCTraceKind traceKind, size_t thingSize)
         : rt(rt), data(data), callback(callback), traceKind(traceKind), thingSize(thingSize)
     {}
     void operator()(Cell *cell) { (*callback)(rt, data, cell, traceKind, thingSize); }
 };
 
 void
-IterateCompartmentsArenasCells(JSRuntime *rt, void *data,
-                               JSIterateCompartmentCallback compartmentCallback,
-                               IterateArenaCallback arenaCallback,
-                               IterateCellCallback cellCallback)
+js::IterateCompartmentsArenasCells(JSRuntime *rt, void *data,
+                                   JSIterateCompartmentCallback compartmentCallback,
+                                   IterateArenaCallback arenaCallback,
+                                   IterateCellCallback cellCallback)
 {
     AutoPrepareForTracing prop(rt);
 
     for (CompartmentsIter c(rt); !c.done(); c.next()) {
         (*compartmentCallback)(rt, data, c);
 
         for (size_t thingKind = 0; thingKind != FINALIZE_LIMIT; thingKind++) {
             JSGCTraceKind traceKind = MapAllocToTraceKind(AllocKind(thingKind));
@@ -4858,27 +4828,27 @@ IterateCompartmentsArenasCells(JSRuntime
             IterateArenaCallbackOp arenaOp(rt, data, arenaCallback, traceKind, thingSize);
             IterateCellCallbackOp cellOp(rt, data, cellCallback, traceKind, thingSize);
             ForEachArenaAndCell(c, AllocKind(thingKind), arenaOp, cellOp);
         }
     }
 }
 
 void
-IterateChunks(JSRuntime *rt, void *data, IterateChunkCallback chunkCallback)
+js::IterateChunks(JSRuntime *rt, void *data, IterateChunkCallback chunkCallback)
 {
     AutoPrepareForTracing prep(rt);
 
     for (js::GCChunkSet::Range r = rt->gcChunkSet.all(); !r.empty(); r.popFront())
         chunkCallback(rt, data, r.front());
 }
 
 void
-IterateCells(JSRuntime *rt, JSCompartment *compartment, AllocKind thingKind,
-             void *data, IterateCellCallback cellCallback)
+js::IterateCells(JSRuntime *rt, JSCompartment *compartment, AllocKind thingKind,
+                 void *data, IterateCellCallback cellCallback)
 {
     AutoPrepareForTracing prep(rt);
 
     JSGCTraceKind traceKind = MapAllocToTraceKind(thingKind);
     size_t thingSize = Arena::thingSize(thingKind);
 
     if (compartment) {
         for (CellIterUnderGC i(compartment, thingKind); !i.done(); i.next())
@@ -4887,34 +4857,32 @@ IterateCells(JSRuntime *rt, JSCompartmen
         for (CompartmentsIter c(rt); !c.done(); c.next()) {
             for (CellIterUnderGC i(c, thingKind); !i.done(); i.next())
                 cellCallback(rt, data, i.getCell(), traceKind, thingSize);
         }
     }
 }
 
 void
-IterateGrayObjects(JSCompartment *compartment, GCThingCallback *cellCallback, void *data)
+js::IterateGrayObjects(JSCompartment *compartment, GCThingCallback *cellCallback, void *data)
 {
     JS_ASSERT(compartment);
     AutoPrepareForTracing prep(compartment->rt);
 
     for (size_t finalizeKind = 0; finalizeKind <= FINALIZE_OBJECT_LAST; finalizeKind++) {
         for (CellIterUnderGC i(compartment, AllocKind(finalizeKind)); !i.done(); i.next()) {
             Cell *cell = i.getCell();
             if (cell->isMarked(GRAY))
                 cellCallback(data, cell);
         }
     }
 }
 
-namespace gc {
-
 JSCompartment *
-NewCompartment(JSContext *cx, JSPrincipals *principals)
+gc::NewCompartment(JSContext *cx, JSPrincipals *principals)
 {
     JSRuntime *rt = cx->runtime;
     JS_AbortIfWrongThread(rt);
 
     JSCompartment *compartment = cx->new_<JSCompartment>(rt);
     if (compartment && compartment->init(cx)) {
 
         // Set up the principals.
@@ -4934,17 +4902,17 @@ NewCompartment(JSContext *cx, JSPrincipa
 
         js_ReportOutOfMemory(cx);
     }
     js_delete(compartment);
     return NULL;
 }
 
 void
-RunDebugGC(JSContext *cx)
+gc::RunDebugGC(JSContext *cx)
 {
 #ifdef JS_GC_ZEAL
     JSRuntime *rt = cx->runtime;
     PrepareForDebugGC(cx->runtime);
 
     int type = rt->gcZeal();
     if (type == ZealIncrementalRootsThenFinish ||
         type == ZealIncrementalMarkAllThenFinish ||
@@ -4985,34 +4953,31 @@ RunDebugGC(JSContext *cx)
     } else {
         Collect(rt, false, SliceBudget::Unlimited, GC_NORMAL, gcreason::DEBUG_GC);
     }
 
 #endif
 }
 
 void
-SetDeterministicGC(JSContext *cx, bool enabled)
+gc::SetDeterministicGC(JSContext *cx, bool enabled)
 {
 #ifdef JS_GC_ZEAL
     JSRuntime *rt = cx->runtime;
     rt->gcDeterministicOnly = enabled;
 #endif
 }
 
 void
-SetValidateGC(JSContext *cx, bool enabled)
+gc::SetValidateGC(JSContext *cx, bool enabled)
 {
     JSRuntime *rt = cx->runtime;
     rt->gcValidate = enabled;
 }
 
-} /* namespace gc */
-} /* namespace js */
-
 #if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
 
 JS_ALWAYS_INLINE bool
 CheckStackRootThing(uintptr_t *w, void *address, ThingRootKind kind)
 {
     if (kind != THING_ROOT_BINDINGS)
         return address == static_cast<void*>(w);
 
@@ -5192,19 +5157,16 @@ JS::CheckStackRoots(JSContext *cx)
     JS_ASSERT(stackMin <= stackEnd);
     CheckStackRootsRangeAndSkipIon(rt, &checker, stackMin, stackEnd);
     CheckStackRootsRange(&checker, cgcd->registerSnapshot.words,
                          ArrayEnd(cgcd->registerSnapshot.words));
 }
 
 #endif /* DEBUG && JS_GC_ZEAL && JSGC_ROOT_ANALYSIS && !JS_THREADSAFE */
 
-namespace js {
-namespace gc {
-
 #ifdef JS_GC_ZEAL
 
 /*
  * Write barrier verification
  *
  * The next few functions are for write barrier verification.
  *
  * The VerifyBarriers function is a shorthand. It checks if a verification phase
@@ -5319,18 +5281,17 @@ MakeNode(VerifyPreTracer *trc, void *thi
         node->count = 0;
         node->kind = kind;
         trc->nodemap.add(p, thing, node);
         return node;
     }
     return NULL;
 }
 
-static
-VerifyNode *
+static VerifyNode *
 NextNode(VerifyNode *node)
 {
     if (node->count == 0)
         return (VerifyNode *)((char *)node + sizeof(VerifyNode) - sizeof(EdgeValue));
     else
         return (VerifyNode *)((char *)node + sizeof(VerifyNode) +
                              sizeof(EdgeValue)*(node->count - 1));
 }
@@ -5695,17 +5656,17 @@ VerifyPostBarriers(JSRuntime *rt)
 {
     if (rt->gcVerifyPostData)
         EndVerifyPostBarriers(rt);
     else
         StartVerifyPostBarriers(rt);
 }
 
 void
-VerifyBarriers(JSRuntime *rt, VerifierType type)
+gc::VerifyBarriers(JSRuntime *rt, VerifierType type)
 {
     if (type == PreBarrierVerifier)
         VerifyPreBarriers(rt);
     else
         VerifyPostBarriers(rt);
 }
 
 static void
@@ -5734,17 +5695,17 @@ MaybeVerifyPostBarriers(JSRuntime *rt, b
             return;
 
         EndVerifyPostBarriers(rt);
     }
     StartVerifyPostBarriers(rt);
 }
 
 void
-MaybeVerifyBarriers(JSContext *cx, bool always)
+gc::MaybeVerifyBarriers(JSContext *cx, bool always)
 {
     MaybeVerifyPreBarriers(cx->runtime, always);
     MaybeVerifyPostBarriers(cx->runtime, always);
 }
 
 void
 FinishVerifier(JSRuntime *rt)
 {
@@ -5761,19 +5722,18 @@ FinishVerifier(JSRuntime *rt)
             c->gcStoreBuffer.disable();
         }
     }
 #endif
 }
 
 #endif /* JS_GC_ZEAL */
 
-} /* namespace gc */
-
-void ReleaseAllJITCode(FreeOp *fop)
+void
+js::ReleaseAllJITCode(FreeOp *fop)
 {
 #ifdef JS_METHODJIT
     for (CompartmentsIter c(fop->runtime()); !c.done(); c.next()) {
         mjit::ClearAllFrames(c);
 # ifdef JS_ION
         ion::InvalidateAll(fop, c);
 # endif
 
@@ -5823,33 +5783,33 @@ ReleaseScriptCounts(FreeOp *fop)
     for (size_t i = 0; i < vec.length(); i++)
         vec[i].scriptCounts.destroy(fop);
 
     fop->delete_(rt->scriptAndCountsVector);
     rt->scriptAndCountsVector = NULL;
 }
 
 JS_FRIEND_API(void)
-StartPCCountProfiling(JSContext *cx)
+js::StartPCCountProfiling(JSContext *cx)
 {
     JSRuntime *rt = cx->runtime;
 
     if (rt->profilingScripts)
         return;
 
     if (rt->scriptAndCountsVector)
         ReleaseScriptCounts(rt->defaultFreeOp());
 
     ReleaseAllJITCode(rt->defaultFreeOp());
 
     rt->profilingScripts = true;
 }
 
 JS_FRIEND_API(void)
-StopPCCountProfiling(JSContext *cx)
+js::StopPCCountProfiling(JSContext *cx)
 {
     JSRuntime *rt = cx->runtime;
 
     if (!rt->profilingScripts)
         return;
     JS_ASSERT(!rt->scriptAndCountsVector);
 
     ReleaseAllJITCode(rt->defaultFreeOp());
@@ -5871,29 +5831,29 @@ StopPCCountProfiling(JSContext *cx)
         }
     }
 
     rt->profilingScripts = false;
     rt->scriptAndCountsVector = vec;
 }
 
 JS_FRIEND_API(void)
-PurgePCCounts(JSContext *cx)
+js::PurgePCCounts(JSContext *cx)
 {
     JSRuntime *rt = cx->runtime;
 
     if (!rt->scriptAndCountsVector)
         return;
     JS_ASSERT(!rt->profilingScripts);
 
     ReleaseScriptCounts(rt->defaultFreeOp());
 }
 
 void
-PurgeJITCaches(JSCompartment *c)
+js::PurgeJITCaches(JSCompartment *c)
 {
 #ifdef JS_METHODJIT
     mjit::ClearAllFrames(c);
 
     for (CellIterUnderGC i(c, FINALIZE_SCRIPT); !i.done(); i.next()) {
         JSScript *script = i.get<JSScript>();
 
         /* Discard JM caches. */
@@ -5932,18 +5892,16 @@ AutoMaybeTouchDeadCompartments::~AutoMay
     if (inIncremental && runtime->gcObjectsMarkedInDeadCompartments != markCount) {
         PrepareForFullGC(runtime);
         js::GC(runtime, GC_NORMAL, gcreason::TRANSPLANT);
     }
 
     runtime->gcManipulatingDeadCompartments = manipulatingDeadCompartments;
 }
 
-} /* namespace js */
-
 JS_PUBLIC_API(void)
 JS_IterateCompartments(JSRuntime *rt, void *data,
                        JSIterateCompartmentCallback compartmentCallback)
 {
     JS_ASSERT(!rt->isHeapBusy());
 
     AutoTraceSession session(rt);
     rt->gcHelperThread.waitBackgroundSweepOrAllocEnd();
--- a/js/src/jsgc.h
+++ b/js/src/jsgc.h
@@ -540,20 +540,16 @@ extern void
 GCFinalSlice(JSRuntime *rt, JSGCInvocationKind gckind, js::gcreason::Reason reason);
 
 extern void
 GCDebugSlice(JSRuntime *rt, bool limit, int64_t objCount);
 
 extern void
 PrepareForDebugGC(JSRuntime *rt);
 
-} /* namespace js */
-
-namespace js {
-
 void
 InitTracer(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback);
 
 /*
  * Helper that implements sweeping and allocation for kinds that can be swept
  * and allocated off the main thread.
  *
  * In non-threadsafe builds, all actual sweeping and allocation is performed
--- a/js/src/jsgcinlines.h
+++ b/js/src/jsgcinlines.h
@@ -59,22 +59,22 @@ GetGCThingTraceKind(const void *thing)
     JS_ASSERT(thing);
     const Cell *cell = reinterpret_cast<const Cell *>(thing);
     return MapAllocToTraceKind(cell->getAllocKind());
 }
 
 /* Capacity for slotsToThingKind */
 const size_t SLOTS_TO_THING_KIND_LIMIT = 17;
 
+extern AllocKind slotsToThingKind[];
+
 /* Get the best kind to use when making an object with the given slot count. */
 static inline AllocKind
 GetGCObjectKind(size_t numSlots)
 {
-    extern AllocKind slotsToThingKind[];
-
     AutoAssertNoGC nogc;
     if (numSlots >= SLOTS_TO_THING_KIND_LIMIT)
         return FINALIZE_OBJECT16;
     return slotsToThingKind[numSlots];
 }
 
 static inline AllocKind
 GetGCObjectKind(Class *clasp)
--- a/js/src/jsinfer.cpp
+++ b/js/src/jsinfer.cpp
@@ -5128,21 +5128,18 @@ ScriptAnalysis::printTypes(JSContext *cx
 #endif /* DEBUG */
 
 }
 
 /////////////////////////////////////////////////////////////////////
 // Interface functions
 /////////////////////////////////////////////////////////////////////
 
-namespace js {
-namespace types {
-
 void
-MarkIteratorUnknownSlow(JSContext *cx)
+types::MarkIteratorUnknownSlow(JSContext *cx)
 {
     /* Check whether we are actually at an ITER opcode. */
 
     jsbytecode *pc;
     RootedScript script(cx, cx->stack.currentScript(&pc));
     if (!script || !pc)
         return;
 
@@ -5192,17 +5189,18 @@ MarkIteratorUnknownSlow(JSContext *cx)
         if (!analysis->maybeCode(pc))
             continue;
         if (JSOp(*pc) == JSOP_ITERNEXT)
             analysis->pushedTypes(pc, 0)->addType(cx, Type::UnknownType());
     }
 }
 
 void
-TypeMonitorCallSlow(JSContext *cx, HandleObject callee, const CallArgs &args, bool constructing)
+types::TypeMonitorCallSlow(JSContext *cx, HandleObject callee, const CallArgs &args,
+                           bool constructing)
 {
     unsigned nargs = callee->toFunction()->nargs;
     RootedScript script(cx, callee->toFunction()->script());
 
     if (!constructing)
         TypeScript::SetThis(cx, script, args.thisv());
 
     /*
@@ -5225,17 +5223,17 @@ IsAboutToBeFinalized(TypeObjectKey *key)
     /* Mask out the low bit indicating whether this is a type or JS object. */
     gc::Cell *tmp = reinterpret_cast<gc::Cell *>(uintptr_t(key) & ~1);
     bool isMarked = IsCellMarked(&tmp);
     JS_ASSERT(tmp == reinterpret_cast<gc::Cell *>(uintptr_t(key) & ~1));
     return !isMarked;
 }
 
 void
-TypeDynamicResult(JSContext *cx, HandleScript script, jsbytecode *pc, Type type)
+types::TypeDynamicResult(JSContext *cx, HandleScript script, jsbytecode *pc, Type type)
 {
     JS_ASSERT(cx->typeInferenceEnabled());
     AutoEnterTypeInference enter(cx);
 
     /* Directly update associated type sets for applicable bytecodes. */
     if (js_CodeSpec[*pc].format & JOF_TYPESET) {
         if (!script->ensureRanAnalysis(cx)) {
             cx->compartment->types.setPendingNukeTypes(cx);
@@ -5327,17 +5325,17 @@ TypeDynamicResult(JSContext *cx, HandleS
 
     if (script->hasAnalysis() && script->analysis()->ranInference()) {
         TypeSet *pushed = script->analysis()->pushedTypes(pc, 0);
         pushed->addType(cx, type);
     }
 }
 
 void
-TypeMonitorResult(JSContext *cx, HandleScript script, jsbytecode *pc, const js::Value &rval)
+types::TypeMonitorResult(JSContext *cx, HandleScript script, jsbytecode *pc, const js::Value &rval)
 {
     /* Allow the non-TYPESET scenario to simplify stubs used in compound opcodes. */
     if (!(js_CodeSpec[*pc].format & JOF_TYPESET))
         return;
 
     AutoEnterTypeInference enter(cx);
 
     if (!script->ensureRanAnalysis(cx)) {
@@ -5350,18 +5348,16 @@ TypeMonitorResult(JSContext *cx, HandleS
     if (types->hasType(type))
         return;
 
     InferSpew(ISpewOps, "bytecodeType: #%u:%05u: %s",
               script->id(), pc - script->code, TypeString(type));
     types->addType(cx, type);
 }
 
-} } /* namespace js::types */
-
 /////////////////////////////////////////////////////////////////////
 // TypeScript
 /////////////////////////////////////////////////////////////////////
 
 /*
  * Returns true if we don't expect to compute the correct types for some value
  * pushed by the specified bytecode.
  */
--- a/js/src/jsinferinlines.h
+++ b/js/src/jsinferinlines.h
@@ -500,39 +500,39 @@ GetTypeCallerInitObject(JSContext *cx, J
         jsbytecode *pc;
         RootedScript script(cx, cx->stack.currentScript(&pc));
         if (script)
             return TypeScript::InitObject(cx, script, pc, key);
     }
     return GetTypeNewObject(cx, key);
 }
 
+void MarkIteratorUnknownSlow(JSContext *cx);
+
 /*
  * When using a custom iterator within the initialization of a 'for in' loop,
  * mark the iterator values as unknown.
  */
 inline void
 MarkIteratorUnknown(JSContext *cx)
 {
-    extern void MarkIteratorUnknownSlow(JSContext *cx);
-
     if (cx->typeInferenceEnabled())
         MarkIteratorUnknownSlow(cx);
 }
 
+void TypeMonitorCallSlow(JSContext *cx, HandleObject callee, const CallArgs &args,
+                         bool constructing);
+
 /*
  * Monitor a javascript call, either on entry to the interpreter or made
  * from within the interpreter.
  */
 inline bool
 TypeMonitorCall(JSContext *cx, const js::CallArgs &args, bool constructing)
 {
-    extern void TypeMonitorCallSlow(JSContext *cx, HandleObject callee,
-                                    const CallArgs &args, bool constructing);
-
     js::RootedObject callee(cx, &args.callee());
     if (callee->isFunction()) {
         JSFunction *fun = callee->toFunction();
         if (fun->isInterpreted()) {
             js::RootedScript script(cx, fun->script());
             if (!script->ensureRanAnalysis(cx))
                 return false;
             if (cx->typeInferenceEnabled())
--- a/js/src/jsiter.cpp
+++ b/js/src/jsiter.cpp
@@ -512,28 +512,26 @@ VectorToKeyIterator(JSContext *cx, Handl
 
     iterobj->setNativeIterator(ni);
     vp.setObject(*iterobj);
 
     RegisterEnumerator(cx, iterobj, ni);
     return true;
 }
 
-namespace js {
-
 bool
-VectorToKeyIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &props,
-                    MutableHandleValue vp)
+js::VectorToKeyIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &props,
+                        MutableHandleValue vp)
 {
     return VectorToKeyIterator(cx, obj, flags, props, 0, 0, vp);
 }
 
 bool
-VectorToValueIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &keys,
-                      MutableHandleValue vp)
+js::VectorToValueIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &keys,
+                          MutableHandleValue vp)
 {
     JS_ASSERT(flags & JSITER_FOREACH);
 
     if (obj) {
         if (obj->hasSingletonType() && !obj->setIteratedSingleton(cx))
             return false;
         types::MarkTypeObjectFlags(cx, obj, types::OBJECT_FLAG_ITERATED);
     }
@@ -550,35 +548,35 @@ VectorToValueIterator(JSContext *cx, Han
     iterobj->setNativeIterator(ni);
     vp.setObject(*iterobj);
 
     RegisterEnumerator(cx, iterobj, ni);
     return true;
 }
 
 bool
-EnumeratedIdVectorToIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &props,
-                             MutableHandleValue vp)
+js::EnumeratedIdVectorToIterator(JSContext *cx, HandleObject obj, unsigned flags,
+                                 AutoIdVector &props, MutableHandleValue vp)
 {
     if (!(flags & JSITER_FOREACH))
         return VectorToKeyIterator(cx, obj, flags, props, vp);
 
     return VectorToValueIterator(cx, obj, flags, props, vp);
 }
 
 static inline void
 UpdateNativeIterator(NativeIterator *ni, RawObject obj)
 {
     // Update the object for which the native iterator is associated, so
     // SuppressDeletedPropertyHelper will recognize the iterator as a match.
     ni->obj = obj;
 }
 
 bool
-GetIterator(JSContext *cx, HandleObject obj, unsigned flags, MutableHandleValue vp)
+js::GetIterator(JSContext *cx, HandleObject obj, unsigned flags, MutableHandleValue vp)
 {
     if (flags == JSITER_FOR_OF) {
         // for-of loop. The iterator is simply |obj.iterator()|.
         RootedValue method(cx);
         if (!JSObject::getProperty(cx, obj, obj, cx->names().iterator, &method))
             return false;
 
         // Throw if obj.iterator isn't callable. js::Invoke is about to check
@@ -724,26 +722,24 @@ GetIterator(JSContext *cx, HandleObject 
         cx->runtime->nativeIterCache.set(key, iterobj);
 
     if (shapes.length() == 2)
         cx->runtime->nativeIterCache.last = iterobj;
     return true;
 }
 
 JSObject *
-GetIteratorObject(JSContext *cx, HandleObject obj, uint32_t flags)
+js::GetIteratorObject(JSContext *cx, HandleObject obj, uint32_t flags)
 {
     RootedValue value(cx);
     if (!GetIterator(cx, obj, flags, &value))
         return NULL;
     return &value.toObject();
 }
 
-} /* namespace js */
-
 JSBool
 js_ThrowStopIteration(JSContext *cx)
 {
     JS_ASSERT(!JS_IsExceptionPending(cx));
     RootedValue v(cx);
     if (js_FindClassObject(cx, JSProto_StopIteration, &v))
         cx->setPendingException(v);
     return JS_FALSE;
--- a/js/src/jslock.h
+++ b/js/src/jslock.h
@@ -17,16 +17,17 @@
 # include "prinit.h"
 
 # define JS_ATOMIC_INCREMENT(p)      PR_ATOMIC_INCREMENT((int32_t *)(p))
 # define JS_ATOMIC_DECREMENT(p)      PR_ATOMIC_DECREMENT((int32_t *)(p))
 # define JS_ATOMIC_ADD(p,v)          PR_ATOMIC_ADD((int32_t *)(p), (int32_t)(v))
 # define JS_ATOMIC_SET(p,v)          PR_ATOMIC_SET((int32_t *)(p), (int32_t)(v))
 
 namespace js {
+    // Defined in jsgc.cpp.
     unsigned GetCPUCount();
 }
 
 #else  /* JS_THREADSAFE */
 
 typedef struct PRThread PRThread;
 typedef struct PRCondVar PRCondVar;
 typedef struct PRLock PRLock;
--- a/js/src/jsmemorymetrics.cpp
+++ b/js/src/jsmemorymetrics.cpp
@@ -17,31 +17,26 @@
 #include "jsscope.h"
 #include "jsscript.h"
 
 #include "jsobjinlines.h"
 
 #include "ion/IonCode.h"
 #include "ion/Ion.h"
 
-namespace js {
+using namespace js;
 
-size_t MemoryReportingSundriesThreshold()
+JS_FRIEND_API(size_t)
+js::MemoryReportingSundriesThreshold()
 {
     return 8 * 1024;
 }
 
-} // namespace js
-
 #ifdef JS_THREADSAFE
 
-namespace JS {
-
-using namespace js;
-
 typedef HashSet<ScriptSource *, DefaultHasher<ScriptSource *>, SystemAllocPolicy> SourceSet;
 
 struct IteratorClosure
 {
   RuntimeStats *rtStats;
   ObjectPrivateVisitor *opv;
   SourceSet seenSources;
   IteratorClosure(RuntimeStats *rt, ObjectPrivateVisitor *v) : rtStats(rt), opv(v) {}
@@ -270,17 +265,17 @@ StatsCellCallback(JSRuntime *rt, void *d
     }
 #endif
     }
     // Yes, this is a subtraction:  see StatsArenaCallback() for details.
     cStats->gcHeapUnusedGcThings -= thingSize;
 }
 
 JS_PUBLIC_API(bool)
-CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv)
+JS::CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv)
 {
     if (!rtStats->compartmentStatsVector.reserve(rt->compartments.length()))
         return false;
 
     rtStats->gcHeapChunkTotal =
         size_t(JS_GetGCParameter(rt, JSGC_TOTAL_CHUNKS)) * gc::ChunkSize;
 
     rtStats->gcHeapUnusedChunks =
@@ -323,47 +318,45 @@ CollectRuntimeStats(JSRuntime *rt, Runti
                                   rtStats->totals.gcHeapUnusedGcThings -
                                   rtStats->gcHeapChunkAdmin -
                                   rtStats->totals.gcHeapArenaAdmin -
                                   rtStats->gcHeapGcThings;
     return true;
 }
 
 JS_PUBLIC_API(int64_t)
-GetExplicitNonHeapForRuntime(JSRuntime *rt, JSMallocSizeOfFun mallocSizeOf)
+JS::GetExplicitNonHeapForRuntime(JSRuntime *rt, JSMallocSizeOfFun mallocSizeOf)
 {
     // explicit/<compartment>/gc-heap/*
     size_t n = size_t(JS_GetGCParameter(rt, JSGC_TOTAL_CHUNKS)) * gc::ChunkSize;
 
     // explicit/runtime/mjit-code
     // explicit/runtime/regexp-code
     // explicit/runtime/stack-committed
     // explicit/runtime/unused-code-memory
     n += rt->sizeOfExplicitNonHeap();
 
     return int64_t(n);
 }
 
 JS_PUBLIC_API(size_t)
-SystemCompartmentCount(const JSRuntime *rt)
+JS::SystemCompartmentCount(const JSRuntime *rt)
 {
     size_t n = 0;
     for (size_t i = 0; i < rt->compartments.length(); i++) {
         if (rt->compartments[i]->isSystemCompartment)
             ++n;
     }
     return n;
 }
 
 JS_PUBLIC_API(size_t)
-UserCompartmentCount(const JSRuntime *rt)
+JS::UserCompartmentCount(const JSRuntime *rt)
 {
     size_t n = 0;
     for (size_t i = 0; i < rt->compartments.length(); i++) {
         if (!rt->compartments[i]->isSystemCompartment)
             ++n;
     }
     return n;
 }
 
-} // namespace JS
-
 #endif // JS_THREADSAFE
--- a/js/src/jsnativestack.cpp
+++ b/js/src/jsnativestack.cpp
@@ -23,22 +23,20 @@
 #  include <pthread_np.h>
 # endif
 
 #else
 # error "Unsupported platform"
 
 #endif
 
-namespace js {
-
 #if defined(XP_WIN)
 
 void *
-GetNativeStackBaseImpl()
+js::GetNativeStackBaseImpl()
 {
 # if defined(_M_IX86) && defined(_MSC_VER)
     /*
      * offset 0x18 from the FS segment register gives a pointer to
      * the thread information block for the current thread
      */
     NT_TIB* pTib;
     __asm {
@@ -61,54 +59,54 @@ GetNativeStackBaseImpl()
 
 #elif defined(SOLARIS)
 
 #include <ucontext.h>
 
 JS_STATIC_ASSERT(JS_STACK_GROWTH_DIRECTION < 0);
 
 void *
-GetNativeStackBaseImpl()
+js::GetNativeStackBaseImpl()
 {
     stack_t st;
     stack_getbounds(&st);
     return static_cast<char*>(st.ss_sp) + st.ss_size;
 }
 
 #elif defined(AIX)
 
 #include <ucontext.h>
 
 JS_STATIC_ASSERT(JS_STACK_GROWTH_DIRECTION < 0);
 
 void *
-GetNativeStackBaseImpl()
+js::GetNativeStackBaseImpl()
 {
     ucontext_t context;
     getcontext(&context);
     return static_cast<char*>(context.uc_stack.ss_sp) +
         context.uc_stack.ss_size;
 }
 
 #elif defined(XP_OS2)
 
 void *
-GetNativeStackBaseImpl()
+js::GetNativeStackBaseImpl()
 {
     PTIB  ptib;
     PPIB  ppib;
 
     DosGetInfoBlocks(&ptib, &ppib);
     return ptib->tib_pstacklimit;
 }
 
 #else /* XP_UNIX */
 
 void *
-GetNativeStackBaseImpl()
+js::GetNativeStackBaseImpl()
 {
     pthread_t thread = pthread_self();
 # if defined(XP_MACOSX) || defined(DARWIN)
     return pthread_get_stackaddr_np(thread);
 
 # else
     pthread_attr_t sattr;
     pthread_attr_init(&sattr);
@@ -145,10 +143,8 @@ GetNativeStackBaseImpl()
     return stackBase;
 #  else
     return static_cast<char*>(stackBase) + stackSize;
 #  endif
 # endif
 }
 
 #endif /* !XP_WIN */
-
-} /* namespace js */
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -175,21 +175,19 @@ ComputeAccurateBinaryBaseInteger(const j
         }
         value += bit2 & (bit | sticky);
         value *= factor;
     }
 
     return value;
 }
 
-namespace js {
-
 bool
-GetPrefixInteger(JSContext *cx, const jschar *start, const jschar *end, int base,
-                 const jschar **endp, double *dp)
+js::GetPrefixInteger(JSContext *cx, const jschar *start, const jschar *end, int base,
+                     const jschar **endp, double *dp)
 {
     JS_ASSERT(start <= end);
     JS_ASSERT(2 <= base && base <= 36);
 
     const jschar *s = start;
     double d = 0.0;
     for (; s < end; s++) {
         int digit;
@@ -222,18 +220,16 @@ GetPrefixInteger(JSContext *cx, const js
     if (base == 10)
         return ComputeAccurateDecimalInteger(cx, start, s, dp);
     if ((base & (base - 1)) == 0)
         *dp = ComputeAccurateBinaryBaseInteger(start, s, base);
 
     return true;
 }
 
-} // namespace js
-
 static JSBool
 num_isNaN(JSContext *cx, unsigned argc, Value *vp)
 {
     if (argc == 0) {
         vp->setBoolean(true);
         return JS_TRUE;
     }
     double x;
@@ -1032,20 +1028,18 @@ inline void FIX_FPU() {
 }
 
 #else
 
 #define FIX_FPU() ((void)0)
 
 #endif
 
-namespace js {
-
 bool
-InitRuntimeNumberState(JSRuntime *rt)
+js::InitRuntimeNumberState(JSRuntime *rt)
 {
     FIX_FPU();
 
     double d;
 
     /*
      * Our NaN must be one particular canonical value, because we rely on NaN
      * encoding for our value representation.  See jsval.h.
@@ -1106,28 +1100,26 @@ InitRuntimeNumberState(JSRuntime *rt)
     storage += decimalPointSize;
 
     js_memcpy(storage, grouping, groupingSize);
     rt->numGrouping = grouping;
     return true;
 }
 
 void
-FinishRuntimeNumberState(JSRuntime *rt)
+js::FinishRuntimeNumberState(JSRuntime *rt)
 {
     /*
      * The free also releases the memory for decimalSeparator and numGrouping
      * strings.
      */
     char *storage = const_cast<char *>(rt->thousandsSeparator);
     js_free(storage);
 }
 
-} /* namespace js */
-
 JSObject *
 js_InitNumberClass(JSContext *cx, HandleObject obj)
 {
     JS_ASSERT(obj->isNative());
 
     /* XXX must do at least once per new thread, so do it per JSContext... */
     FIX_FPU();
 
@@ -1174,18 +1166,16 @@ js_InitNumberClass(JSContext *cx, Handle
     }
 
     if (!DefineConstructorAndPrototype(cx, global, JSProto_Number, ctor, numberProto))
         return NULL;
 
     return numberProto;
 }
 
-namespace js {
-
 static char *
 FracNumberToCString(JSContext *cx, ToCStringBuf *cbuf, double d, int base = 10)
 {
 #ifdef DEBUG
     {
         int32_t _;
         JS_ASSERT(!MOZ_DOUBLE_IS_INT32(d, &_));
     }
@@ -1207,26 +1197,24 @@ FracNumberToCString(JSContext *cx, ToCSt
         numStr = builder.Finalize();
     } else {
         numStr = cbuf->dbuf = js_dtobasestr(cx->runtime->dtoaState, base, d);
     }
     return numStr;
 }
 
 char *
-NumberToCString(JSContext *cx, ToCStringBuf *cbuf, double d, int base/* = 10*/)
+js::NumberToCString(JSContext *cx, ToCStringBuf *cbuf, double d, int base/* = 10*/)
 {
     int32_t i;
     return MOZ_DOUBLE_IS_INT32(d, &i)
            ? IntToCString(cbuf, i, base)
            : FracNumberToCString(cx, cbuf, d, base);
 }
 
-}
-
 static JSString * JS_FASTCALL
 js_NumberToStringWithBase(JSContext *cx, double d, int base)
 {
     ToCStringBuf cbuf;
     char *numStr;
 
     /*
      * Caller is responsible for error reporting. When called from trace,
@@ -1276,28 +1264,26 @@ js_NumberToStringWithBase(JSContext *cx,
 }
 
 JSString *
 js_NumberToString(JSContext *cx, double d)
 {
     return js_NumberToStringWithBase(cx, d, 10);
 }
 
-namespace js {
-
 JSFlatString *
-NumberToString(JSContext *cx, double d)
+js::NumberToString(JSContext *cx, double d)
 {
     if (JSString *str = js_NumberToStringWithBase(cx, d, 10))
         return &str->asFlat();
     return NULL;
 }
 
 JSFlatString *
-IndexToString(JSContext *cx, uint32_t index)
+js::IndexToString(JSContext *cx, uint32_t index)
 {
     if (StaticStrings::hasUint(index))
         return cx->runtime->staticStrings.getUint(index);
 
     JSCompartment *c = cx->compartment;
     if (JSFlatString *str = c->dtoaCache.lookup(10, index))
         return str;
 
@@ -1314,17 +1300,17 @@ IndexToString(JSContext *cx, uint32_t in
     jschar *dst = str->init(end - start);
     PodCopy(dst, start.get(), end - start + 1);
 
     c->dtoaCache.cache(10, index, str);
     return str;
 }
 
 bool JS_FASTCALL
-NumberValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb)
+js::NumberValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb)
 {
     /* Convert to C-string. */
     ToCStringBuf cbuf;
     const char *cstr;
     if (v.isInt32()) {
         cstr = IntToCString(&cbuf, v.toInt32());
     } else {
         cstr = NumberToCString(cx, &cbuf, v.toDouble());
@@ -1339,17 +1325,17 @@ NumberValueToStringBuffer(JSContext *cx,
      * even if jschars are UTF-8, all chars should map to one jschar.
      */
     size_t cstrlen = strlen(cstr);
     JS_ASSERT(!cbuf.dbuf && cstrlen < cbuf.sbufSize);
     return sb.appendInflated(cstr, cstrlen);
 }
 
 JS_PUBLIC_API(bool)
-ToNumberSlow(JSContext *cx, Value v, double *out)
+js::ToNumberSlow(JSContext *cx, Value v, double *out)
 {
     AssertCanGC();
 #ifdef DEBUG
     /*
      * MSVC bizarrely miscompiles this, complaining about the first brace below
      * being unmatched (!).  The error message points at both this opening brace
      * and at the corresponding SkipRoot constructor.  The error seems to derive
      * from the presence guard-object macros on the SkipRoot class/constructor,
@@ -1402,17 +1388,17 @@ ToNumberSlow(JSContext *cx, Value v, dou
     return true;
 }
 
 /*
  * Convert a value to an int64_t, according to the WebIDL rules for long long
  * conversion. Return converted value in *out on success, false on failure.
  */
 JS_PUBLIC_API(bool)
-ToInt64Slow(JSContext *cx, const Value &v, int64_t *out)
+js::ToInt64Slow(JSContext *cx, const Value &v, int64_t *out)
 {
     JS_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else {
         if (!ToNumberSlow(cx, v, &d))
             return false;
@@ -1421,62 +1407,62 @@ ToInt64Slow(JSContext *cx, const Value &
     return true;
 }
 
 /*
  * Convert a value to an uint64_t, according to the WebIDL rules for unsigned long long
  * conversion. Return converted value in *out on success, false on failure.
  */
 JS_PUBLIC_API(bool)
-ToUint64Slow(JSContext *cx, const Value &v, uint64_t *out)
+js::ToUint64Slow(JSContext *cx, const Value &v, uint64_t *out)
 {
     JS_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else {
         if (!ToNumberSlow(cx, v, &d))
             return false;
     }
     *out = ToUint64(d);
     return true;
 }
 
 JS_PUBLIC_API(bool)
-ToInt32Slow(JSContext *cx, const Value &v, int32_t *out)
+js::ToInt32Slow(JSContext *cx, const Value &v, int32_t *out)
 {
     JS_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else {
         if (!ToNumberSlow(cx, v, &d))
             return false;
     }
     *out = ToInt32(d);
     return true;
 }
 
 JS_PUBLIC_API(bool)
-ToUint32Slow(JSContext *cx, const Value &v, uint32_t *out)
+js::ToUint32Slow(JSContext *cx, const Value &v, uint32_t *out)
 {
     JS_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else {
         if (!ToNumberSlow(cx, v, &d))
             return false;
     }
     *out = ToUint32(d);
     return true;
 }
 
 JS_PUBLIC_API(bool)
-ToUint16Slow(JSContext *cx, const Value &v, uint16_t *out)
+js::ToUint16Slow(JSContext *cx, const Value &v, uint16_t *out)
 {
     JS_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else if (!ToNumberSlow(cx, v, &d)) {
         return false;
     }
@@ -1498,18 +1484,16 @@ ToUint16Slow(JSContext *cx, const Value 
     unsigned m = JS_BIT(16);
     d = fmod(d, (double) m);
     if (d < 0)
         d += m;
     *out = (uint16_t) d;
     return true;
 }
 
-}  /* namespace js */
-
 JSBool
 js_strtod(JSContext *cx, const jschar *s, const jschar *send,
           const jschar **ep, double *dp)
 {
     size_t i;
     char cbuf[32];
     char *cstr, *istr, *estr;
     JSBool negative;
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -284,64 +284,60 @@ obj_toSource(JSContext *cx, unsigned arg
     RawString str = buf.finishString();
     if (!str)
         return false;
     args.rval().setString(str);
     return true;
 }
 #endif /* JS_HAS_TOSOURCE */
 
-namespace js {
-
 JSString *
-obj_toStringHelper(JSContext *cx, JSObject *obj)
+js::obj_toStringHelper(JSContext *cx, JSObject *obj)
 {
     if (obj->isProxy())
         return Proxy::obj_toString(cx, obj);
 
     StringBuffer sb(cx);
     const char *className = obj->getClass()->name;
     if (!sb.append("[object ") || !sb.appendInflated(className, strlen(className)) ||
         !sb.append("]"))
     {
         return NULL;
     }
     return sb.finishString();
 }
 
 JSObject *
-NonNullObject(JSContext *cx, const Value &v)
+js::NonNullObject(JSContext *cx, const Value &v)
 {
     if (v.isPrimitive()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_NONNULL_OBJECT);
         return NULL;
     }
     return &v.toObject();
 }
 
 const char *
-InformalValueTypeName(const Value &v)
+js::InformalValueTypeName(const Value &v)
 {
     if (v.isObject())
         return v.toObject().getClass()->name;
     if (v.isString())
         return "string";
     if (v.isNumber())
         return "number";
     if (v.isBoolean())
         return "boolean";
     if (v.isNull())
         return "null";
     if (v.isUndefined())
         return "undefined";
     return "value";
 }
 
-} /* namespace js */
-
 /* ES5 15.2.4.2.  Note steps 1 and 2 are errata. */
 static JSBool
 obj_toString(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     /* Step 1. */
     if (args.thisv().isUndefined()) {
@@ -797,20 +793,18 @@ obj_getPrototypeOf(JSContext *cx, unsign
     nested.setCallee(cx->global()->protoGetter());
     nested.setThis(args[0]);
     if (!Invoke(cx, nested))
         return false;
     args.rval().set(nested.rval());
     return true;
 }
 
-namespace js {
-
 bool
-NewPropertyDescriptorObject(JSContext *cx, const PropertyDescriptor *desc, Value *vp)
+js::NewPropertyDescriptorObject(JSContext *cx, const PropertyDescriptor *desc, Value *vp)
 {
     if (!desc->obj) {
         vp->setUndefined();
         return true;
     }
 
     /* We have our own property, so start creating the descriptor. */
     PropDesc d;
@@ -884,17 +878,18 @@ PropDesc::makeObject(JSContext *cx)
         return false;
     }
 
     pd_.setObject(*obj);
     return true;
 }
 
 bool
-GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id, PropertyDescriptor *desc)
+js::GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id,
+                             PropertyDescriptor *desc)
 {
     // FIXME: Call TrapGetOwnProperty directly once ScriptedIndirectProxies is removed
     if (obj->isProxy())
         return Proxy::getOwnPropertyDescriptor(cx, obj, id, false, desc);
 
     RootedObject pobj(cx);
     RootedShape shape(cx);
     if (!js_HasOwnProperty(cx, obj->getOps()->lookupGeneric, obj, id, &pobj, &shape))
@@ -924,26 +919,26 @@ GetOwnPropertyDescriptor(JSContext *cx, 
         return false;
 
     desc->value = value;
     desc->obj = obj;
     return true;
 }
 
 bool
-GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id, Value *vp)
+js::GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id, Value *vp)
 {
     AutoPropertyDescriptorRooter desc(cx);
     return GetOwnPropertyDescriptor(cx, obj, id, &desc) &&
            NewPropertyDescriptorObject(cx, &desc, vp);
 }
 
 bool
-GetFirstArgumentAsObject(JSContext *cx, unsigned argc, Value *vp, const char *method,
-                         MutableHandleObject objp)
+js::GetFirstArgumentAsObject(JSContext *cx, unsigned argc, Value *vp, const char *method,
+                             MutableHandleObject objp)
 {
     if (argc == 0) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
                              method, "0", "s");
         return false;
     }
 
     RootedValue v(cx, vp[2]);
@@ -956,18 +951,16 @@ GetFirstArgumentAsObject(JSContext *cx, 
         js_free(bytes);
         return false;
     }
 
     objp.set(&v.toObject());
     return true;
 }
 
-} /* namespace js */
-
 static JSBool
 obj_getOwnPropertyDescriptor(JSContext *cx, unsigned argc, Value *vp)
 {
     RootedObject obj(cx);
     if (!GetFirstArgumentAsObject(cx, argc, vp, "Object.getOwnPropertyDescriptor", &obj))
         return JS_FALSE;
     RootedId id(cx);
     if (!ValueToId(cx, argc >= 2 ? vp[3] : UndefinedValue(), id.address()))
@@ -1160,50 +1153,46 @@ PropDesc::complete()
         attrs &= ~JSPROP_ENUMERATE;
     }
     if (!hasConfigurable_) {
         hasConfigurable_ = true;
         attrs |= JSPROP_PERMANENT;
     }
 }
 
-namespace js {
-
 bool
-Throw(JSContext *cx, jsid id, unsigned errorNumber)
+js::Throw(JSContext *cx, jsid id, unsigned errorNumber)
 {
     JS_ASSERT(js_ErrorFormatString[errorNumber].argCount == 1);
 
     JSString *idstr = IdToString(cx, id);
     if (!idstr)
        return false;
     JSAutoByteString bytes(cx, idstr);
     if (!bytes)
         return false;
     JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, errorNumber, bytes.ptr());
     return false;
 }
 
 bool
-Throw(JSContext *cx, JSObject *obj, unsigned errorNumber)
+js::Throw(JSContext *cx, JSObject *obj, unsigned errorNumber)
 {
     if (js_ErrorFormatString[errorNumber].argCount == 1) {
         RootedValue val(cx, ObjectValue(*obj));
         js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber,
                                  JSDVG_IGNORE_STACK, val, NullPtr(),
                                  NULL, NULL);
     } else {
         JS_ASSERT(js_ErrorFormatString[errorNumber].argCount == 0);
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, errorNumber);
     }
     return false;
 }
 
-} /* namespace js */
-
 static JSBool
 Reject(JSContext *cx, unsigned errorNumber, bool throwError, jsid id, bool *rval)
 {
     if (throwError)
         return Throw(cx, id, errorNumber);
 
     *rval = false;
     return true;
@@ -1603,21 +1592,19 @@ DefinePropertyOnArray(JSContext *cx, Han
 
         *rval = true;
         return JS_TRUE;
     }
 
     return DefinePropertyOnObject(cx, obj, id, desc, throwError, rval);
 }
 
-namespace js {
-
 bool
-DefineProperty(JSContext *cx, HandleObject obj, HandleId id, const PropDesc &desc, bool throwError,
-               bool *rval)
+js::DefineProperty(JSContext *cx, HandleObject obj, HandleId id, const PropDesc &desc,
+                   bool throwError, bool *rval)
 {
     if (obj->isArray())
         return DefinePropertyOnArray(cx, obj, id, desc, throwError, rval);
 
     if (obj->getOps()->lookupGeneric) {
         /*
          * FIXME: Once ScriptedIndirectProxies are removed, this code should call
          * TrapDefineOwnProperty directly
@@ -1625,20 +1612,19 @@ DefineProperty(JSContext *cx, HandleObje
         if (obj->isProxy())
             return Proxy::defineProperty(cx, obj, id, desc.pd());
         return Reject(cx, obj, JSMSG_OBJECT_NOT_EXTENSIBLE, throwError, rval);
     }
 
     return DefinePropertyOnObject(cx, obj, id, desc, throwError, rval);
 }
 
-} /* namespace js */
-
 JSBool
-js_DefineOwnProperty(JSContext *cx, HandleObject obj, HandleId id, const Value &descriptor, JSBool *bp)
+js_DefineOwnProperty(JSContext *cx, HandleObject obj, HandleId id, const Value &descriptor,
+                     JSBool *bp)
 {
     AutoPropDescArrayRooter descs(cx);
     PropDesc *desc = descs.append();
     if (!desc || !desc->initialize(cx, descriptor))
         return false;
 
     bool rval;
     if (!DefineProperty(cx, obj, id, *desc, true, &rval))
@@ -1664,21 +1650,19 @@ obj_defineProperty(JSContext *cx, unsign
     JSBool junk;
     if (!js_DefineOwnProperty(cx, obj, id, descval, &junk))
         return false;
 
     vp->setObject(*obj);
     return true;
 }
 
-namespace js {
-
 bool
-ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccessors,
-                        AutoIdVector *ids, AutoPropDescArrayRooter *descs)
+js::ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccessors,
+                            AutoIdVector *ids, AutoPropDescArrayRooter *descs)
 {
     if (!GetPropertyNames(cx, props, JSITER_OWNONLY, ids))
         return false;
 
     RootedId id(cx);
     for (size_t i = 0, len = ids->length(); i < len; i++) {
         id = (*ids)[i];
         PropDesc* desc = descs->append();
@@ -1688,18 +1672,16 @@ ReadPropertyDescriptors(JSContext *cx, H
             !desc->initialize(cx, v, checkAccessors))
         {
             return false;
         }
     }
     return true;
 }
 
-} /* namespace js */
-
 static bool
 DefineProperties(JSContext *cx, HandleObject obj, HandleObject props)
 {
     AutoIdVector ids(cx);
     AutoPropDescArrayRooter descs(cx);
     if (!ReadPropertyDescriptors(cx, props, true, &ids, &descs))
         return false;
 
@@ -2985,18 +2967,16 @@ DefineStandardSlot(JSContext *cx, Handle
         }
     }
 
     named = JSObject::defineGeneric(cx, obj, id,
                                     v, JS_PropertyStub, JS_StrictPropertyStub, attrs);
     return named;
 }
 
-namespace js {
-
 static void
 SetClassObject(JSObject *obj, JSProtoKey key, JSObject *cobj, JSObject *proto)
 {
     JS_ASSERT(!obj->getParent());
     if (!obj->isGlobal())
         return;
 
     obj->setReservedSlot(key, ObjectOrNullValue(cobj));
@@ -3010,22 +2990,22 @@ ClearClassObject(JSObject *obj, JSProtoK
     if (!obj->isGlobal())
         return;
 
     obj->setSlot(key, UndefinedValue());
     obj->setSlot(JSProto_LIMIT + key, UndefinedValue());
 }
 
 JSObject *
-DefineConstructorAndPrototype(JSContext *cx, HandleObject obj, JSProtoKey key, HandleAtom atom,
-                              JSObject *protoProto, Class *clasp,
-                              Native constructor, unsigned nargs,
-                              JSPropertySpec *ps, JSFunctionSpec *fs,
-                              JSPropertySpec *static_ps, JSFunctionSpec *static_fs,
-                              JSObject **ctorp, AllocKind ctorKind)
+js::DefineConstructorAndPrototype(JSContext *cx, HandleObject obj, JSProtoKey key, HandleAtom atom,
+                                  JSObject *protoProto, Class *clasp,
+                                  Native constructor, unsigned nargs,
+                                  JSPropertySpec *ps, JSFunctionSpec *fs,
+                                  JSPropertySpec *static_ps, JSFunctionSpec *static_fs,
+                                  JSObject **ctorp, AllocKind ctorKind)
 {
     /*
      * Create a prototype object for this class.
      *
      * FIXME: lazy standard (built-in) class initialization and even older
      * eager boostrapping code rely on all of these properties:
      *
      * 1. NewObject attempting to compute a default prototype object when
@@ -3161,39 +3141,37 @@ bad:
  * Otherwise, when we delete them, we might accidentally recreate them via a
  * lazy initialization. We use the presence of a ctor or proto in the
  * global object's slot to indicate that they've been constructed, but this only
  * works for classes which have a proto and ctor. Classes which don't have one
  * can call MarkStandardClassInitializedNoProto(), and we can always check
  * whether a class is initialized by calling IsStandardClassResolved().
  */
 bool
-IsStandardClassResolved(JSObject *obj, js::Class *clasp)
+js::IsStandardClassResolved(JSObject *obj, js::Class *clasp)
 {
     JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(clasp);
 
     /* If the constructor is undefined, then it hasn't been initialized. */
     return (obj->getReservedSlot(key) != UndefinedValue());
 }
 
 void
-MarkStandardClassInitializedNoProto(JSObject *obj, js::Class *clasp)
+js::MarkStandardClassInitializedNoProto(JSObject *obj, js::Class *clasp)
 {
     JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(clasp);
 
     /*
      * We use True so that it's obvious what we're doing (instead of, say,
      * Null, which might be miscontrued as an error in setting Undefined).
      */
     if (obj->getReservedSlot(key) == UndefinedValue())
         obj->setSlot(key, BooleanValue(true));
 }
 
-}
-
 JSObject *
 js_InitClass(JSContext *cx, HandleObject obj, JSObject *protoProto_,
              Class *clasp, Native constructor, unsigned nargs,
              JSPropertySpec *ps, JSFunctionSpec *fs,
              JSPropertySpec *static_ps, JSFunctionSpec *static_fs,
              JSObject **ctorp, AllocKind ctorKind)
 {
     RootedObject protoProto(cx, protoProto_);
@@ -3518,20 +3496,18 @@ JS_FOR_EACH_PROTOTYPE(DECLARE_PROTOTYPE_
 #undef DECLARE_PROTOTYPE_CLASS_INIT
 
 static JSClassInitializerOp lazy_prototype_init[JSProto_LIMIT] = {
 #define LAZY_PROTOTYPE_INIT(name,code,init) init,
     JS_FOR_EACH_PROTOTYPE(LAZY_PROTOTYPE_INIT)
 #undef LAZY_PROTOTYPE_INIT
 };
 
-namespace js {
-
 bool
-SetProto(JSContext *cx, HandleObject obj, Handle<js::TaggedProto> proto, bool checkForCycles)
+js::SetProto(JSContext *cx, HandleObject obj, Handle<js::TaggedProto> proto, bool checkForCycles)
 {
     JS_ASSERT_IF(!checkForCycles, obj.get() != proto.raw());
 
 #if JS_HAS_XML_SUPPORT
     if (proto.isObject() && proto.toObject()->isXML()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_XML_PROTO_FORBIDDEN);
         return false;
     }
@@ -3611,23 +3587,19 @@ SetProto(JSContext *cx, HandleObject obj
      */
     MarkTypeObjectUnknownProperties(cx, obj->type(), true);
     MarkTypeObjectUnknownProperties(cx, type, true);
 
     obj->setType(type);
     return true;
 }
 
-}
-
 bool
-js_GetClassObject(JSContext *cx, RawObject obj, JSProtoKey key,
-                  MutableHandleObject objp)
+js_GetClassObject(JSContext *cx, RawObject obj, JSProtoKey key, MutableHandleObject objp)
 {
-
     RootedObject global(cx, &obj->global());
     if (!global->isGlobal()) {
         objp.set(NULL);
         return true;
     }
 
     Value v = global->getReservedSlot(key);
     if (v.isObject()) {
@@ -3901,22 +3873,20 @@ CallAddPropertyHook(JSContext *cx, Class
         if (value.get() != nominal) {
             if (shape->hasSlot())
                 JSObject::nativeSetSlotWithType(cx, obj, shape, value);
         }
     }
     return true;
 }
 
-namespace js {
-
 Shape *
-DefineNativeProperty(JSContext *cx, HandleObject obj, HandleId id, HandleValue value,
-                     PropertyOp getter, StrictPropertyOp setter, unsigned attrs,
-                     unsigned flags, int shortid, unsigned defineHow /* = 0 */)
+js::DefineNativeProperty(JSContext *cx, HandleObject obj, HandleId id, HandleValue value,
+                         PropertyOp getter, StrictPropertyOp setter, unsigned attrs,
+                         unsigned flags, int shortid, unsigned defineHow /* = 0 */)
 {
     JS_ASSERT((defineHow & ~(DNP_CACHE_RESULT | DNP_DONT_PURGE |
                              DNP_SKIP_TYPE)) == 0);
     JS_ASSERT(!(attrs & JSPROP_NATIVE_ACCESSORS));
 
     AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter);
 
     /*
@@ -3999,18 +3969,16 @@ DefineNativeProperty(JSContext *cx, Hand
     if (!CallAddPropertyHook(cx, clasp, obj, shape, value)) {
         obj->removeProperty(cx, id);
         return NULL;
     }
 
     return shape;
 }
 
-} /* namespace js */
-
 /*
  * Call obj's resolve hook.
  *
  * cx, id, and flags are the parameters initially passed to the ongoing lookup;
  * objp and propp are its out parameters. obj is an object along the prototype
  * chain from where the lookup started.
  *
  * There are four possible outcomes:
@@ -4833,20 +4801,18 @@ baseops::DeleteElement(JSContext *cx, Ha
 JSBool
 baseops::DeleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid,
                        MutableHandleValue rval, JSBool strict)
 {
     Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
     return baseops::DeleteGeneric(cx, obj, id, rval, strict);
 }
 
-namespace js {
-
 bool
-HasDataProperty(JSContext *cx, HandleObject obj, jsid id, Value *vp)
+js::HasDataProperty(JSContext *cx, HandleObject obj, jsid id, Value *vp)
 {
     if (Shape *shape = obj->nativeLookup(cx, id)) {
         if (shape->hasDefaultGetter() && shape->hasSlot()) {
             *vp = obj->nativeGetSlot(shape->slot());
             return true;
         }
     }
 
@@ -4869,17 +4835,17 @@ MaybeCallMethod(JSContext *cx, HandleObj
     if (!js_IsCallable(vp)) {
         vp.setObject(*obj);
         return true;
     }
     return Invoke(cx, ObjectValue(*obj), vp, 0, NULL, vp.address());
 }
 
 JSBool
-DefaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp)
+js::DefaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp)
 {
     JS_ASSERT(hint == JSTYPE_NUMBER || hint == JSTYPE_STRING || hint == JSTYPE_VOID);
 #if JS_HAS_XML_SUPPORT
     JS_ASSERT(!obj->isXML());
 #endif
 
     Rooted<jsid> id(cx);
 
@@ -4949,18 +4915,16 @@ DefaultValue(JSContext *cx, HandleObject
     }
 
     RootedValue val(cx, ObjectValue(*obj));
     js_ReportValueError2(cx, JSMSG_CANT_CONVERT_TO, JSDVG_SEARCH_STACK, val, str,
                          (hint == JSTYPE_VOID) ? "primitive type" : TypeStrings[hint]);
     return false;
 }
 
-} /* namespace js */
-
 JS_FRIEND_API(JSBool)
 JS_EnumerateState(JSContext *cx, JSHandleObject obj, JSIterateOp enum_op,
                   JSMutableHandleValue statep, JSMutableHandleId idp)
 {
     /* If the class has a custom JSCLASS_NEW_ENUMERATE hook, call it. */
     Class *clasp = obj->getClass();
     JSEnumerateOp enumerate = clasp->enumerate;
     if (clasp->flags & JSCLASS_NEW_ENUMERATE) {
@@ -4972,21 +4936,19 @@ JS_EnumerateState(JSContext *cx, JSHandl
         return false;
 
     /* Tell InitNativeIterator to treat us like a native object. */
     JS_ASSERT(enum_op == JSENUMERATE_INIT || enum_op == JSENUMERATE_INIT_ALL);
     statep.setMagic(JS_NATIVE_ENUMERATE);
     return true;
 }
 
-namespace js {
-
 JSBool
-CheckAccess(JSContext *cx, JSObject *obj_, HandleId id, JSAccessMode mode,
-            MutableHandleValue vp, unsigned *attrsp)
+js::CheckAccess(JSContext *cx, JSObject *obj_, HandleId id, JSAccessMode mode,
+                MutableHandleValue vp, unsigned *attrsp)
 {
     JSBool writing;
     RootedObject obj(cx, obj_), pobj(cx);
 
     while (JS_UNLIKELY(obj->isWith()))
         obj = obj->getProto();
 
     writing = (mode & JSACC_WRITE) != 0;
@@ -5046,18 +5008,16 @@ CheckAccess(JSContext *cx, JSObject *obj
      * unintended) runtime sharing across trust boundaries.
      */
     JSCheckAccessOp check = pobj->getClass()->checkAccess;
     if (!check)
         check = cx->runtime->securityCallbacks->checkObjectAccess;
     return !check || check(cx, pobj, id, mode, vp);
 }
 
-}
-
 JSType
 baseops::TypeOf(JSContext *cx, HandleObject obj)
 {
     return obj->isCallable() ? JSTYPE_FUNCTION : JSTYPE_OBJECT;
 }
 
 bool
 js::IsDelegate(JSContext *cx, HandleObject obj, const js::Value &v, bool *result)
@@ -5151,21 +5111,19 @@ js_ValueToObjectOrNull(JSContext *cx, co
         obj = PrimitiveToObject(cx, v);
         if (!obj)
             return false;
     }
     objp.set(obj);
     return true;
 }
 
-namespace js {
-
 /* Callers must handle the already-object case . */
 JSObject *
-ToObjectSlow(JSContext *cx, HandleValue val, bool reportScanStack)
+js::ToObjectSlow(JSContext *cx, HandleValue val, bool reportScanStack)
 {
     JS_ASSERT(!val.isMagic());
     JS_ASSERT(!val.isObject());
 
     if (val.isNullOrUndefined()) {
         if (reportScanStack) {
             js_ReportIsNullOrUndefined(cx, JSDVG_SEARCH_STACK, val, NullPtr());
         } else {
@@ -5173,18 +5131,16 @@ ToObjectSlow(JSContext *cx, HandleValue 
                                  val.isNull() ? "null" : "undefined", "object");
         }
         return NULL;
     }
 
     return PrimitiveToObject(cx, val);
 }
 
-}
-
 JSObject *
 js_ValueToNonNullObject(JSContext *cx, const Value &v)
 {
     RootedObject obj(cx);
 
     if (!js_ValueToObjectOrNull(cx, v, &obj))
         return NULL;
     if (!obj) {
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -857,36 +857,32 @@ Revive(JSContext *cx, HandleValue revive
 
     if (!JSObject::defineProperty(cx, obj, cx->names().empty, vp))
         return false;
 
     Rooted<jsid> id(cx, NameToId(cx->names().empty));
     return Walk(cx, obj, id, reviver, vp);
 }
 
-namespace js {
-
 JSBool
-ParseJSONWithReviver(JSContext *cx, StableCharPtr chars, size_t length, HandleValue reviver,
-                     MutableHandleValue vp, DecodingMode decodingMode /* = STRICT */)
+js::ParseJSONWithReviver(JSContext *cx, StableCharPtr chars, size_t length, HandleValue reviver,
+                         MutableHandleValue vp, DecodingMode decodingMode /* = STRICT */)
 {
     /* 15.12.2 steps 2-3. */
     JSONParser parser(cx, chars, length,
                       decodingMode == STRICT ? JSONParser::StrictJSON : JSONParser::LegacyJSON);
     if (!parser.parse(vp))
         return false;
 
     /* 15.12.2 steps 4-5. */
     if (js_IsCallable(reviver))
         return Revive(cx, reviver, vp);
     return true;
 }
 
-} /* namespace js */
-
 #if JS_HAS_TOSOURCE
 static JSBool
 json_toSource(JSContext *cx, unsigned argc, Value *vp)
 {
     vp->setString(cx->names().JSON);
     return JS_TRUE;
 }
 #endif
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -6543,20 +6543,18 @@ ReconstructPCStack(JSContext *cx, JSScri
     LOCAL_ASSERT(pc == target);
     AssertPCDepth(script, pc, pcdepth);
     return pcdepth;
 }
 
 #undef LOCAL_ASSERT
 #undef LOCAL_ASSERT_RV
 
-namespace js {
-
 bool
-CallResultEscapes(jsbytecode *pc)
+js::CallResultEscapes(jsbytecode *pc)
 {
     /*
      * If we see any of these sequences, the result is unused:
      * - call / pop
      *
      * If we see any of these sequences, the result is only tested for nullness:
      * - call / ifeq
      * - call / not / ifeq
@@ -6572,29 +6570,29 @@ CallResultEscapes(jsbytecode *pc)
 
     if (*pc == JSOP_NOT)
         pc += JSOP_NOT_LENGTH;
 
     return (*pc != JSOP_IFEQ);
 }
 
 extern bool
-IsValidBytecodeOffset(JSContext *cx, JSScript *script, size_t offset)
+js::IsValidBytecodeOffset(JSContext *cx, JSScript *script, size_t offset)
 {
     // This could be faster (by following jump instructions if the target is <= offset).
     for (BytecodeRange r(script); !r.empty(); r.popFront()) {
         size_t here = r.frontOffset();
         if (here >= offset)
             return here == offset;
     }
     return false;
 }
 
 JS_FRIEND_API(size_t)
-GetPCCountScriptCount(JSContext *cx)
+js::GetPCCountScriptCount(JSContext *cx)
 {
     JSRuntime *rt = cx->runtime;
 
     if (!rt->scriptAndCountsVector)
         return 0;
 
     return rt->scriptAndCountsVector->length();
 }
@@ -6621,17 +6619,17 @@ AppendArrayJSONProperties(JSContext *cx,
             AppendJSONProperty(buf, names[i], comma);
             comma = COMMA;
             NumberValueToStringBuffer(cx, DoubleValue(values[i]), buf);
         }
     }
 }
 
 JS_FRIEND_API(JSString *)
-GetPCCountScriptSummary(JSContext *cx, size_t index)
+js::GetPCCountScriptSummary(JSContext *cx, size_t index)
 {
     JSRuntime *rt = cx->runtime;
 
     if (!rt->scriptAndCountsVector || index >= rt->scriptAndCountsVector->length()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BUFFER_TOO_SMALL);
         return NULL;
     }
 
@@ -6914,17 +6912,17 @@ GetPCCountJSON(JSContext *cx, const Scri
     }
 
     buf.append('}');
 
     return !cx->isExceptionPending();
 }
 
 JS_FRIEND_API(JSString *)
-GetPCCountScriptContents(JSContext *cx, size_t index)
+js::GetPCCountScriptContents(JSContext *cx, size_t index)
 {
     JSRuntime *rt = cx->runtime;
 
     if (!rt->scriptAndCountsVector || index >= rt->scriptAndCountsVector->length()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BUFFER_TOO_SMALL);
         return NULL;
     }
 
@@ -6939,10 +6937,8 @@ GetPCCountScriptContents(JSContext *cx, 
     {
         AutoCompartment ac(cx, &script->global());
         if (!GetPCCountJSON(cx, sac, buf))
             return NULL;
     }
 
     return buf.finishString();
 }
-
-} // namespace js
--- a/js/src/jsreflect.cpp
+++ b/js/src/jsreflect.cpp
@@ -32,34 +32,32 @@
 #include "jsscriptinlines.h"
 
 using namespace js;
 using namespace js::frontend;
 
 using mozilla::DebugOnly;
 using mozilla::ArrayLength;
 
-namespace js {
-
-char const *aopNames[] = {
+char const *js::aopNames[] = {
     "=",    /* AOP_ASSIGN */
     "+=",   /* AOP_PLUS */
     "-=",   /* AOP_MINUS */
     "*=",   /* AOP_STAR */
     "/=",   /* AOP_DIV */
     "%=",   /* AOP_MOD */
     "<<=",  /* AOP_LSH */
     ">>=",  /* AOP_RSH */
     ">>>=", /* AOP_URSH */
     "|=",   /* AOP_BITOR */
     "^=",   /* AOP_BITXOR */
     "&="    /* AOP_BITAND */
 };
 
-char const *binopNames[] = {
+char const *js::binopNames[] = {
     "==",         /* BINOP_EQ */
     "!=",         /* BINOP_NE */
     "===",        /* BINOP_STRICTEQ */
     "!==",        /* BINOP_STRICTNE */
     "<",          /* BINOP_LT */
     "<=",         /* BINOP_LE */
     ">",          /* BINOP_GT */
     ">=",         /* BINOP_GE */
@@ -74,34 +72,34 @@ char const *binopNames[] = {
     "|",          /* BINOP_BITOR */
     "^",          /* BINOP_BITXOR */
     "&",          /* BINOP_BITAND */
     "in",         /* BINOP_IN */
     "instanceof", /* BINOP_INSTANCEOF */
     "..",         /* BINOP_DBLDOT */
 };
 
-char const *unopNames[] = {
+char const *js::unopNames[] = {
     "delete",  /* UNOP_DELETE */
     "-",       /* UNOP_NEG */
     "+",       /* UNOP_POS */
     "!",       /* UNOP_NOT */
     "~",       /* UNOP_BITNOT */
     "typeof",  /* UNOP_TYPEOF */
     "void"     /* UNOP_VOID */
 };
 
-char const *nodeTypeNames[] = {
+char const *js::nodeTypeNames[] = {
 #define ASTDEF(ast, str, method) str,
 #include "jsast.tbl"
 #undef ASTDEF
     NULL
 };
 
-char const *callbackNames[] = {
+static char const *callbackNames[] = {
 #define ASTDEF(ast, str, method) method,
 #include "jsast.tbl"
 #undef ASTDEF
     NULL
 };
 
 typedef AutoValueVector NodeVector;
 
@@ -1680,23 +1678,21 @@ NodeBuilder::xmlPI(HandleValue target, H
         return callback(cb, target, contents, pos, dst);
 
     return newNode(AST_XMLPI, pos,
                    "target", target,
                    "contents", contents,
                    dst);
 }
 
-
 /*
  * Serialization of parse nodes to JavaScript objects.
  *
  * All serialization methods take a non-nullable ParseNode pointer.
  */
-
 class ASTSerializer
 {
     JSContext           *cx;
     Parser              *parser;
     NodeBuilder         builder;
     DebugOnly<uint32_t> lineno;
 
     RawValue unrootedAtomContents(RawAtom atom) {
@@ -3381,18 +3377,16 @@ ASTSerializer::functionBody(ParseNode *p
         RootedValue child(cx);
         if (!sourceElement(next, &child) || !elts.append(child))
             return false;
     }
 
     return builder.blockStatement(elts, pos, dst);
 }
 
-} /* namespace js */
-
 static JSBool
 reflect_parse(JSContext *cx, uint32_t argc, jsval *vp)
 {
     if (argc < 1) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
                              "Reflect.parse", "0", "s");
         return JS_FALSE;
     }
@@ -3510,17 +3504,16 @@ reflect_parse(JSContext *cx, uint32_t ar
     return JS_TRUE;
 }
 
 static JSFunctionSpec static_methods[] = {
     JS_FN("parse", reflect_parse, 1, 0),
     JS_FS_END
 };
 
-
 JS_PUBLIC_API(JSObject *)
 JS_InitReflect(JSContext *cx, JSObject *objArg)
 {
     RootedObject obj(cx, objArg);
     RootedObject Reflect(cx, NewObjectWithClassProto(cx, &ObjectClass, NULL, obj));
     if (!Reflect || !JSObject::setSingletonType(cx, Reflect))
         return NULL;
 
--- a/js/src/jsreflect.h
+++ b/js/src/jsreflect.h
@@ -93,10 +93,9 @@ enum PropKind {
 
 extern char const *aopNames[];
 extern char const *binopNames[];
 extern char const *unopNames[];
 extern char const *nodeTypeNames[];
 
 } /* namespace js */
 
-
 #endif /* jsreflect_h___ */
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -1933,31 +1933,27 @@ JSScript::finalize(FreeOp *fop)
     scriptSource_->decref(fop->runtime());
 
     if (data) {
         JS_POISON(data, 0xdb, computedSizeOfData());
         fop->free_(data);
     }
 }
 
-namespace js {
-
 static const uint32_t GSN_CACHE_THRESHOLD = 100;
 static const uint32_t GSN_CACHE_MAP_INIT_SIZE = 20;
 
 void
 GSNCache::purge()
 {
     code = NULL;
     if (map.initialized())
         map.finish();
 }
 
-} /* namespace js */
-
 jssrcnote *
 js_GetSrcNote(JSContext *cx, RawScript script, jsbytecode *pc)
 {
     GSNCache *cache = &cx->runtime->gsnCache;
     cx = NULL;  // nulling |cx| ensures GC can't be triggered, so |RawScript script| is safe
 
     size_t target = pc - script->code;
     if (target >= size_t(script->length))
@@ -2128,28 +2124,26 @@ js_GetScriptLineExtent(RawScript script)
     }
 
     if (maxLineNo > lineno)
         lineno = maxLineNo;
 
     return 1 + lineno - script->lineno;
 }
 
-namespace js {
-
 unsigned
-CurrentLine(JSContext *cx)
+js::CurrentLine(JSContext *cx)
 {
     AutoAssertNoGC nogc;
     return PCToLineNumber(cx->fp()->script().get(nogc), cx->regs().pc);
 }
 
 void
-CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *linenop,
-                                JSPrincipals **origin)
+js::CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *linenop,
+                                    JSPrincipals **origin)
 {
     AutoAssertNoGC nogc;
     NonBuiltinScriptFrameIter iter(cx);
 
     if (iter.done()) {
         *file = NULL;
         *linenop = 0;
         *origin = NULL;
@@ -2157,18 +2151,16 @@ CurrentScriptFileLineOriginSlow(JSContex
     }
 
     RawScript script = iter.script().get(nogc);
     *file = script->filename;
     *linenop = PCToLineNumber(iter.script().get(nogc), iter.pc());
     *origin = script->originPrincipals;
 }
 
-}  /* namespace js */
-
 template <class T>
 static inline T *
 Rebase(RawScript dst, RawScript src, T *srcp)
 {
     size_t off = reinterpret_cast<uint8_t *>(srcp) - src->data;
     return reinterpret_cast<T *>(dst->data + off);
 }
 
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -3455,20 +3455,18 @@ js_ValueToSource(JSContext *cx, const Va
     if (js_IsCallable(fval)) {
         if (!Invoke(cx, ObjectValue(*obj), fval, 0, NULL, &rval))
             return NULL;
     }
 
     return ToString(cx, rval);
 }
 
-namespace js {
-
 bool
-EqualStrings(JSContext *cx, JSString *str1, JSString *str2, bool *result)
+js::EqualStrings(JSContext *cx, JSString *str1, JSString *str2, bool *result)
 {
     if (str1 == str2) {
         *result = true;
         return true;
     }
 
     size_t length1 = str1->length();
     if (length1 != str2->length()) {
@@ -3483,32 +3481,28 @@ EqualStrings(JSContext *cx, JSString *st
     if (!linear2)
         return false;
 
     *result = PodEqual(linear1->chars(), linear2->chars(), length1);
     return true;
 }
 
 bool
-EqualStrings(JSLinearString *str1, JSLinearString *str2)
+js::EqualStrings(JSLinearString *str1, JSLinearString *str2)
 {
     if (str1 == str2)
         return true;
 
     size_t length1 = str1->length();
     if (length1 != str2->length())
         return false;
 
     return PodEqual(str1->chars(), str2->chars(), length1);
 }
 
-}  /* namespace js */
-
-namespace js {
-
 static bool
 CompareStringsImpl(JSContext *cx, JSString *str1, JSString *str2, int32_t *result)
 {
     JS_ASSERT(str1);
     JS_ASSERT(str2);
 
     if (str1 == str2) {
         *result = 0;
@@ -3522,45 +3516,39 @@ CompareStringsImpl(JSContext *cx, JSStri
     const jschar *s2 = str2->getChars(cx);
     if (!s2)
         return false;
 
     return CompareChars(s1, str1->length(), s2, str2->length(), result);
 }
 
 bool
-CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result)
+js::CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result)
 {
     return CompareStringsImpl(cx, str1, str2, result);
 }
 
-}  /* namespace js */
-
-namespace js {
-
 bool
-StringEqualsAscii(JSLinearString *str, const char *asciiBytes)
+js::StringEqualsAscii(JSLinearString *str, const char *asciiBytes)
 {
     size_t length = strlen(asciiBytes);
 #ifdef DEBUG
     for (size_t i = 0; i != length; ++i)
         JS_ASSERT(unsigned(asciiBytes[i]) <= 127);
 #endif
     if (length != str->length())
         return false;
     const jschar *chars = str->chars();
     for (size_t i = 0; i != length; ++i) {
         if (unsigned(asciiBytes[i]) != unsigned(chars[i]))
             return false;
     }
     return true;
 }
 
-} /* namespacejs */
-
 size_t
 js_strlen(const jschar *s)
 {
     const jschar *t;
 
     for (t = s; *t != 0; t++)
         continue;
     return (size_t)(t - s);
@@ -3595,20 +3583,18 @@ js_strchr_limit(const jschar *s, jschar 
     while (s < limit) {
         if (*s == c)
             return (jschar *)s;
         s++;
     }
     return NULL;
 }
 
-namespace js {
-
 jschar *
-InflateString(JSContext *cx, const char *bytes, size_t *lengthp)
+js::InflateString(JSContext *cx, const char *bytes, size_t *lengthp)
 {
     AssertCanGC();
     size_t nchars;
     jschar *chars;
     size_t nbytes = *lengthp;
 
     nchars = nbytes;
     chars = cx->pod_malloc<jschar>(nchars + 1);
@@ -3625,17 +3611,17 @@ InflateString(JSContext *cx, const char 
      * For compatibility with callers of JS_DecodeBytes we must zero lengthp
      * on errors.
      */
     *lengthp = 0;
     return NULL;
 }
 
 jschar *
-InflateUTF8String(JSContext *cx, const char *bytes, size_t *lengthp)
+js::InflateUTF8String(JSContext *cx, const char *bytes, size_t *lengthp)
 {
     AssertCanGC();
     size_t nchars;
     jschar *chars;
     size_t nbytes = *lengthp;
 
     // Malformed UTF8 chars could trigger errors and hence GC
     MaybeCheckStackRoots(cx);
@@ -3658,39 +3644,39 @@ InflateUTF8String(JSContext *cx, const c
     *lengthp = 0;
     return NULL;
 }
 
 /*
  * May be called with null cx.
  */
 char *
-DeflateString(JSContext *maybecx, const jschar *chars, size_t nchars)
+js::DeflateString(JSContext *maybecx, const jschar *chars, size_t nchars)
 {
     AutoAssertNoGC nogc;
     size_t nbytes = nchars;
     char *bytes = maybecx
                   ? maybecx->pod_malloc<char>(nbytes + 1)
                   : js_pod_malloc<char>(nbytes + 1);
     if (!bytes)
         return NULL;
     for (size_t i = 0; i < nbytes; i++)
         bytes[i] = (char) chars[i];
     bytes[nbytes] = 0;
     return bytes;
 }
 
 size_t
-GetDeflatedStringLength(JSContext *cx, const jschar *chars, size_t nchars)
+js::GetDeflatedStringLength(JSContext *cx, const jschar *chars, size_t nchars)
 {
     return nchars;
 }
 
 bool
-DeflateStringToBuffer(JSContext *maybecx, const jschar *src, size_t srclen,
+js::DeflateStringToBuffer(JSContext *maybecx, const jschar *src, size_t srclen,
                           char *dst, size_t *dstlenp)
 {
     size_t dstlen = *dstlenp;
     if (srclen > dstlen) {
         for (size_t i = 0; i < dstlen; i++)
             dst[i] = (char) src[i];
         if (maybecx) {
             JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL,
@@ -3699,19 +3685,18 @@ DeflateStringToBuffer(JSContext *maybecx
         return JS_FALSE;
     }
     for (size_t i = 0; i < srclen; i++)
         dst[i] = (char) src[i];
     *dstlenp = srclen;
     return JS_TRUE;
 }
 
-
 bool
-InflateStringToBuffer(JSContext *maybecx, const char *src, size_t srclen,
+js::InflateStringToBuffer(JSContext *maybecx, const char *src, size_t srclen,
                           jschar *dst, size_t *dstlenp)
 {
     if (dst) {
         size_t dstlen = *dstlenp;
         if (srclen > dstlen) {
             for (size_t i = 0; i < dstlen; i++)
                 dst[i] = (unsigned char) src[i];
             if (maybecx) {
@@ -3723,17 +3708,17 @@ InflateStringToBuffer(JSContext *maybecx
         for (size_t i = 0; i < srclen; i++)
             dst[i] = (unsigned char) src[i];
     }
     *dstlenp = srclen;
     return JS_TRUE;
 }
 
 bool
-InflateUTF8StringToBuffer(JSContext *cx, const char *src, size_t srclen,
+js::InflateUTF8StringToBuffer(JSContext *cx, const char *src, size_t srclen,
                               jschar *dst, size_t *dstlenp)
 {
     size_t dstlen, origDstlen, offset, j, n;
     uint32_t v;
 
     dstlen = dst ? *dstlenp : (size_t) -1;
     origDstlen = dstlen;
     offset = 0;
@@ -3803,18 +3788,16 @@ bufferTooSmall:
     *dstlenp = (origDstlen - dstlen);
     if (cx) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                              JSMSG_BUFFER_TOO_SMALL);
     }
     return JS_FALSE;
 }
 
-} /* namepsace js */
-
 const jschar js_uriReservedPlusPound_ucstr[] =
     {';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '#', 0};
 const jschar js_uriUnescaped_ucstr[] =
     {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
      'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
      'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
      'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
@@ -4179,20 +4162,19 @@ Utf8ToOneUcs4Char(const uint8_t *utf8Buf
     }
 
     if (JS_UNLIKELY(ucs4Char < minucs4Char || (ucs4Char >= 0xD800 && ucs4Char <= 0xDFFF)))
         return INVALID_UTF8;
 
     return ucs4Char;
 }
 
-namespace js {
-
 size_t
-PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, JSLinearString *str, uint32_t quote)
+js::PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, JSLinearString *str,
+                         uint32_t quote)
 {
     enum {
         STOP, FIRST_QUOTE, LAST_QUOTE, CHARS, ESCAPE_START, ESCAPE_MORE
     } state;
 
     JS_ASSERT(quote == 0 || quote == '\'' || quote == '"');
     JS_ASSERT_IF(!buffer, bufferSize == 0);
     JS_ASSERT_IF(fp, !buffer);
@@ -4291,10 +4273,8 @@ PutEscapedStringImpl(char *buffer, size_
         }
         n++;
     }
   stop:
     if (buffer)
         buffer[n] = '\0';
     return n;
 }
-
-} /* namespace js */
--- a/js/src/jsweakmap.cpp
+++ b/js/src/jsweakmap.cpp
@@ -16,18 +16,16 @@
 #include "gc/Marking.h"
 #include "vm/GlobalObject.h"
 
 #include "jsgcinlines.h"
 #include "jsobjinlines.h"
 
 using namespace js;
 
-namespace js {
-
 bool
 WeakMapBase::markAllIteratively(JSTracer *tracer)
 {
     bool markedAny = false;
     JSRuntime *rt = tracer->runtime;
     for (WeakMapBase *m = rt->gcWeakMapList; m; m = m->next) {
         if (m->markIteratively(tracer))
             markedAny = true;
@@ -84,18 +82,16 @@ WeakMapBase::restoreWeakMapList(JSRuntim
     for (WeakMapBase **p = vector.begin(); p != vector.end(); p++) {
         WeakMapBase *m = *p;
         JS_ASSERT(m->next == WeakMapNotInList);
         m->next = rt->gcWeakMapList;
         rt->gcWeakMapList = m;
     }
 }
 
-} /* namespace js */
-
 typedef WeakMap<EncapsulatedPtrObject, RelocatableValue> ObjectValueMap;
 
 static ObjectValueMap *
 GetObjectMap(JSObject *obj)
 {
     JS_ASSERT(obj->isWeakMap());
     return (ObjectValueMap *)obj->getPrivate();
 }
--- a/js/src/jswrapper.cpp
+++ b/js/src/jswrapper.cpp
@@ -24,19 +24,17 @@
 #include "jsobjinlines.h"
 
 #include "builtin/Iterator-inl.h"
 #include "vm/RegExpObject-inl.h"
 
 using namespace js;
 using namespace js::gc;
 
-namespace js {
-int sWrapperFamily;
-}
+int js::sWrapperFamily;
 
 void *
 Wrapper::getWrapperFamily()
 {
     return &sWrapperFamily;
 }
 
 JSObject *
@@ -820,18 +818,16 @@ SecurityWrapper<Base>::regexp_toShared(J
 {
     return Base::regexp_toShared(cx, obj, g);
 }
 
 
 template class js::SecurityWrapper<Wrapper>;
 template class js::SecurityWrapper<CrossCompartmentWrapper>;
 
-namespace js {
-
 DeadObjectProxy::DeadObjectProxy()
   : BaseProxyHandler(&sDeadObjectFamily)
 {
 }
 
 bool
 DeadObjectProxy::getPropertyDescriptor(JSContext *cx, JSObject *wrapper,
                                        jsid id, bool set,
@@ -964,18 +960,16 @@ DeadObjectProxy::getPrototypeOf(JSContex
 {
     *protop = NULL;
     return true;
 }
 
 DeadObjectProxy DeadObjectProxy::singleton;
 int DeadObjectProxy::sDeadObjectFamily;
 
-} // namespace js
-
 JSObject *
 js::NewDeadProxyObject(JSContext *cx, JSObject *parent)
 {
     return NewProxyObject(cx, &DeadObjectProxy::singleton, NullValue(),
                           NULL, parent, NULL, NULL);
 }
 
 bool
--- a/js/src/jsxml.cpp
+++ b/js/src/jsxml.cpp
@@ -2828,32 +2828,28 @@ ToAttributeName(JSContext *cx, jsval v)
 
 static void
 ReportBadXMLName(JSContext *cx, const Value &idval)
 {
     RootedValue val(cx, idval);
     js_ReportValueError(cx, JSMSG_BAD_XML_NAME, JSDVG_IGNORE_STACK, val, NullPtr());
 }
 
-namespace js {
-
 bool
-GetLocalNameFromFunctionQName(JSObject *qn, JSAtom **namep, JSContext *cx)
+js::GetLocalNameFromFunctionQName(JSObject *qn, JSAtom **namep, JSContext *cx)
 {
     JSAtom *atom = cx->names().functionNamespaceURI;
     JSLinearString *uri = qn->getNameURI();
     if (uri && (uri == atom || EqualStrings(uri, atom))) {
         *namep = qn->getQNameLocalName();
         return true;
     }
     return false;
 }
 
-} /* namespace js */
-
 bool
 js_GetLocalNameFromFunctionQName(JSObject *obj, jsid *funidp, JSContext *cx)
 {
     if (!obj->isQName())
         return false;
     JSAtom *name;
     if (GetLocalNameFromFunctionQName(obj, &name, cx)) {
         *funidp = AtomToId(name);
@@ -7462,18 +7458,16 @@ js_InitXMLClasses(JSContext *cx, HandleO
 {
     if (!js_InitNamespaceClass(cx, obj))
         return NULL;
     if (!js_InitQNameClass(cx, obj))
         return NULL;
     return js_InitXMLClass(cx, obj);
 }
 
-namespace js {
-
 bool
 GlobalObject::getFunctionNamespace(JSContext *cx, Value *vp)
 {
     Value v = getSlot(FUNCTION_NS);
     if (v.isUndefined()) {
         HandlePropertyName prefix = cx->names().function;
         HandlePropertyName uri = cx->names().functionNamespaceURI;
         RootedObject obj(cx, NewXMLNamespace(cx, prefix, uri, JS_FALSE));
@@ -7493,18 +7487,16 @@ GlobalObject::getFunctionNamespace(JSCon
         v = ObjectValue(*obj);
         setSlot(FUNCTION_NS, v);
     }
 
     *vp = v;
     return true;
 }
 
-} // namespace js
-
 /*
  * Note the asymmetry between js_GetDefaultXMLNamespace and js_SetDefaultXML-
  * Namespace.  Get searches fp->scopeChain for JS_DEFAULT_XML_NAMESPACE_ID,
  * while Set sets JS_DEFAULT_XML_NAMESPACE_ID in fp->varobj. There's no
  * requirement that fp->varobj lie directly on fp->scopeChain, although
  * it should be reachable using the prototype chain from a scope object (cf.
  * JSOPTION_VAROBJFIX in jsapi.h).
  *
--- a/js/src/vm/GlobalObject.cpp
+++ b/js/src/vm/GlobalObject.cpp
@@ -52,18 +52,16 @@ js_InitFunctionClass(JSContext *cx, Hand
 static JSBool
 ThrowTypeError(JSContext *cx, unsigned argc, Value *vp)
 {
     JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL,
                                  JSMSG_THROW_TYPE_ERROR);
     return false;
 }
 
-namespace js {
-
 static bool
 TestProtoGetterThis(const Value &v)
 {
     return !v.isNullOrUndefined();
 }
 
 static bool
 ProtoGetterImpl(JSContext *cx, CallArgs args)
@@ -87,17 +85,19 @@ ProtoGetterImpl(JSContext *cx, CallArgs 
 
 static JSBool
 ProtoGetter(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     return CallNonGenericMethod(cx, TestProtoGetterThis, ProtoGetterImpl, args);
 }
 
+namespace js {
 size_t sSetProtoCalled = 0;
+} // namespace js
 
 static bool
 TestProtoSetterThis(const Value &v)
 {
     if (v.isNullOrUndefined())
         return false;
 
     /* These will work as if on a boxed primitive; dumb, but whatever. */
@@ -528,44 +528,44 @@ GlobalObject::createBlankPrototype(JSCon
 
 JSObject *
 GlobalObject::createBlankPrototypeInheriting(JSContext *cx, Class *clasp, JSObject &proto)
 {
     return CreateBlankProto(cx, clasp, proto, *this);
 }
 
 bool
-LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor_, JSObject *proto_)
+js::LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor_, JSObject *proto_)
 {
     RootedObject ctor(cx, ctor_), proto(cx, proto_);
 
     RootedValue protoVal(cx, ObjectValue(*proto));
     RootedValue ctorVal(cx, ObjectValue(*ctor));
 
     return JSObject::defineProperty(cx, ctor, cx->names().classPrototype,
                                     protoVal, JS_PropertyStub, JS_StrictPropertyStub,
                                     JSPROP_PERMANENT | JSPROP_READONLY) &&
            JSObject::defineProperty(cx, proto, cx->names().constructor,
                                     ctorVal, JS_PropertyStub, JS_StrictPropertyStub, 0);
 }
 
 bool
-DefinePropertiesAndBrand(JSContext *cx, JSObject *obj_,
-                         const JSPropertySpec *ps, const JSFunctionSpec *fs)
+js::DefinePropertiesAndBrand(JSContext *cx, JSObject *obj_,
+                             const JSPropertySpec *ps, const JSFunctionSpec *fs)
 {
     RootedObject obj(cx, obj_);
 
     if (ps && !JS_DefineProperties(cx, obj, const_cast<JSPropertySpec*>(ps)))
         return false;
     if (fs && !JS_DefineFunctions(cx, obj, const_cast<JSFunctionSpec*>(fs)))
         return false;
     return true;
 }
 
-void
+static void
 GlobalDebuggees_finalize(FreeOp *fop, RawObject obj)
 {
     fop->delete_((GlobalObject::DebuggerVector *) obj->getPrivate());
 }
 
 static Class
 GlobalDebuggees_class = {
     "GlobalDebuggee", JSCLASS_HAS_PRIVATE,
@@ -615,10 +615,8 @@ GlobalObject::addDebugger(JSContext *cx,
     if (debuggers->empty() && !global->compartment()->addDebuggee(cx, global))
         return false;
     if (!debuggers->append(dbg)) {
         global->compartment()->removeDebuggee(cx->runtime->defaultFreeOp(), global);
         return false;
     }
     return true;
 }
-
-} // namespace js
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -1063,18 +1063,16 @@ ScopeIterKey::match(ScopeIterKey si1, Sc
            (!si1.fp_ ||
             (si1.cur_   == si2.cur_   &&
              si1.block_ == si2.block_ &&
              si1.type_  == si2.type_));
 }
 
 /*****************************************************************************/
 
-namespace js {
-
 /*
  * DebugScopeProxy is the handler for DebugScopeObject proxy objects. Having a
  * custom handler (rather than trying to reuse js::Wrapper) gives us several
  * important abilities:
  *  - We want to pass the ScopeObject as the receiver to forwarded scope
  *    property ops on aliased variables so that Call/Block/With ops do not all
  *    require a 'normalization' step.
  *  - The debug scope proxy can directly manipulate the stack frame to allow
@@ -1456,18 +1454,16 @@ class DebugScopeProxy : public BaseProxy
     bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) MOZ_OVERRIDE
     {
         RootedValue idval(cx, IdToValue(id));
         return js_ReportValueErrorFlags(cx, JSREPORT_ERROR, JSMSG_CANT_DELETE,
                                         JSDVG_IGNORE_STACK, idval, NullPtr(), NULL, NULL);
     }
 };
 
-}  /* namespace js */
-
 int DebugScopeProxy::family = 0;
 DebugScopeProxy DebugScopeProxy::singleton;
 
 /* static */ DebugScopeObject *
 DebugScopeObject::create(JSContext *cx, ScopeObject &scope, HandleObject enclosing)
 {
     JSObject *obj = NewProxyObject(cx, &DebugScopeProxy::singleton, ObjectValue(scope),
                                    NULL /* proto */, &scope.global(),
--- a/js/src/vm/Unicode.cpp
+++ b/js/src/vm/Unicode.cpp
@@ -1,18 +1,18 @@
 /* Generated by make_unicode.py DO NOT MODIFY */
 
 /*
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/licenses/publicdomain/
  */
 #include "Unicode.h"
 
-namespace js {
-namespace unicode {
+using namespace js;
+using namespace js::unicode;
 
 /*
  * So how does indexing work?
  * First let's have a look at a jschar, 16-bits:
  *              [................]
  * Step 1:
  *  Extracting the upper 10 bits from the jschar.
  *   upper = char >> 6 ([**********......])
@@ -48,17 +48,17 @@ namespace unicode {
  *     push element to index2
  *    put index as chunk in cache
  *
  *   push index >> shift to index1
  *
  *  increase shift
  *  stop if you found the best shift
  */
-const CharacterInfo js_charinfo[] = {
+const CharacterInfo unicode::js_charinfo[] = {
     {0, 0, 0},
     {0, 0, 1},
     {0, 0, 4},
     {0, 32, 2},
     {65504, 0, 2},
     {0, 0, 2},
     {743, 0, 2},
     {121, 0, 2},
@@ -192,17 +192,17 @@ const CharacterInfo js_charinfo[] = {
     {0, 54756, 2},
     {0, 54787, 2},
     {0, 54753, 2},
     {0, 54754, 2},
     {0, 54721, 2},
     {58272, 0, 2},
 };
 
-const uint8_t index1[] = {
+const uint8_t unicode::index1[] = {
       0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16,  17,
      18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,
      36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,
      54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  26,  26,  26,  26,
      26,  68,  69,  70,  71,  72,  73,  74,  75,  26,  26,  26,  26,  26,  26,  26,  26,  76,
      77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,
      95,  96,  97,  98,  99, 100,  94, 101,  26, 102,  26, 103, 104, 104, 105, 104, 106, 107,
     108, 109, 110, 111, 112, 113, 114, 115, 116,  94,  94,  94,  94,  94,  94,  94,  94,  94,
@@ -252,17 +252,17 @@ const uint8_t index1[] = {
      94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,
      94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,
      94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,
      94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,  94,
      94,  94,  94,  94,  94,  94,  26,  26,  26,  26,  26, 159,  26, 160, 161, 162, 163, 164,
      26,  26,  26,  26, 165, 166, 167, 168, 169, 170,  26, 171, 172, 173, 174, 175,
 };
 
-const uint8_t index2[] = {
+const uint8_t unicode::index2[] = {
       0,   0,   0,   0,   0,   0,   0,   0,   0,   1,   1,   1,   1,   1,   0,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   1,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   2,   2,   2,   2,   2,   2,
       2,   2,   2,   2,   0,   0,   0,   0,   0,   0,   0,   3,   3,   3,   3,   3,   3,   3,
       3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,
       3,   0,   0,   0,   0,   2,   0,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,
       4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
@@ -881,11 +881,9 @@ const uint8_t index2[] = {
       5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,
       5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,
       5,   5,   5,   0,   0,   0,   5,   5,   5,   5,   5,   5,   0,   0,   5,   5,   5,   5,
       5,   5,   0,   0,   5,   5,   5,   5,   5,   5,   0,   0,   5,   5,   5,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
 };
 
-} /* namespace unicode */
-} /* namespace js */
 
--- a/js/src/vm/Xdr.cpp
+++ b/js/src/vm/Xdr.cpp
@@ -23,18 +23,16 @@
 #include "Debugger.h"
 
 #include "jsobjinlines.h"
 
 using namespace js;
 
 using mozilla::DebugOnly;
 
-namespace js {
-
 void
 XDRBuffer::freeBuffer()
 {
     js_free(base);
 #ifdef DEBUG
     memset(this, 0xe2, sizeof *this);
 #endif
 }
@@ -162,13 +160,10 @@ XDRDecoder::XDRDecoder(JSContext *cx, co
                        JSPrincipals *principals, JSPrincipals *originPrincipals)
   : XDRState<XDR_DECODE>(cx)
 {
     buf.setData(data, length);
     this->principals = principals;
     this->originPrincipals = JSScript::normalizeOriginPrincipals(principals, originPrincipals);
 }
 
-template class XDRState<XDR_ENCODE>;
-template class XDRState<XDR_DECODE>;
-
-} /* namespace js */
-
+template class js::XDRState<XDR_ENCODE>;
+template class js::XDRState<XDR_DECODE>;
--- a/js/src/vm/make_unicode.py
+++ b/js/src/vm/make_unicode.py
@@ -250,29 +250,29 @@ if (typeof reportCompare === "function")
  *
  *  increase shift
  *  stop if you found the best shift
  */
 """
     data_file.write('/* Generated by make_unicode.py DO NOT MODIFY */\n')
     data_file.write(public_domain)
     data_file.write('#include "Unicode.h"\n\n')
-    data_file.write('namespace js {\n')
-    data_file.write('namespace unicode {\n')
+    data_file.write('using namespace js;\n')
+    data_file.write('using namespace js::unicode;\n')
     data_file.write(comment)
-    data_file.write('const CharacterInfo js_charinfo[] = {\n')
+    data_file.write('const CharacterInfo unicode::js_charinfo[] = {\n')
     for d in table:
         data_file.write('    {')
         data_file.write(', '.join((str(e) for e in d)))
         data_file.write('},\n')
     data_file.write('};\n')
     data_file.write('\n')
 
     def dump(data, name, file):
-        file.write('const uint8_t ' + name + '[] = {\n')
+        file.write('const uint8_t unicode::' + name + '[] = {\n')
 
         line = pad = ' ' * 4
         lines = []
         for entry in data:
             assert entry < 256
             s = str(entry)
             s = s.rjust(3)
 
@@ -286,18 +286,16 @@ if (typeof reportCompare === "function")
         file.write('\n'.join(lines))
         file.write('\n};\n')
 
     dump(index1, 'index1', data_file)
     data_file.write('\n')
     dump(index2, 'index2', data_file)
     data_file.write('\n')
 
-    data_file.write('} /* namespace unicode */\n')
-    data_file.write('} /* namespace js */\n')
     data_file.write('\n')
 
 def getsize(data):
     """ return smallest possible integer size for the given array """
     maxdata = max(data)
     assert maxdata < 2**32
 
     if maxdata < 256: