Bug 941590 - Build jsapi-tests in unified mode. r=ehsan,luke
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 21 Nov 2013 16:42:01 +0100
changeset 171426 371af5899d2708c0951fb4898991bb6b1335506a
parent 171425 6735160dc842463f68583caa84d777fef79d838c
child 171427 1986b95f989ef1aa7e1b01e250f0c1be9b30b1c8
push idunknown
push userunknown
push dateunknown
reviewersehsan, luke
bugs941590
milestone28.0a1
Bug 941590 - Build jsapi-tests in unified mode. r=ehsan,luke
js/src/jsapi-tests/moz.build
js/src/jsapi-tests/testAddPropertyPropcache.cpp
js/src/jsapi-tests/testArgumentsObject.cpp
js/src/jsapi-tests/testArrayBuffer.cpp
js/src/jsapi-tests/testChromeBuffer.cpp
js/src/jsapi-tests/testClassGetter.cpp
js/src/jsapi-tests/testCloneScript.cpp
js/src/jsapi-tests/testCustomIterator.cpp
js/src/jsapi-tests/testDebugger.cpp
js/src/jsapi-tests/testDefineGetterSetterNonEnumerable.cpp
js/src/jsapi-tests/testEnclosingFunction.cpp
js/src/jsapi-tests/testErrorCopying.cpp
js/src/jsapi-tests/testGCFinalizeCallback.cpp
js/src/jsapi-tests/testIndexToString.cpp
js/src/jsapi-tests/testIntern.cpp
js/src/jsapi-tests/testNewObject.cpp
js/src/jsapi-tests/testOriginPrincipals.cpp
js/src/jsapi-tests/testParseJSON.cpp
js/src/jsapi-tests/testScriptInfo.cpp
js/src/jsapi-tests/testSetProperty.cpp
js/src/jsapi-tests/testSlowScript.cpp
js/src/jsapi-tests/testSourcePolicy.cpp
js/src/jsapi-tests/testXDR.cpp
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -1,17 +1,17 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 PROGRAM = 'jsapi-tests'
 
-SOURCES += [
+UNIFIED_SOURCES += [
     'selfTest.cpp',
     'testAddPropertyPropcache.cpp',
     'testArgumentsObject.cpp',
     'testArrayBuffer.cpp',
     'testBindCallable.cpp',
     'testBug604087.cpp',
     'testCallNonGenericMethodOnProxy.cpp',
     'testChromeBuffer.cpp',
--- a/js/src/jsapi-tests/testAddPropertyPropcache.cpp
+++ b/js/src/jsapi-tests/testAddPropertyPropcache.cpp
@@ -2,71 +2,74 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 /* 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 "jsapi-tests/tests.h"
 
-/* Do the test a bunch of times, because sometimes we seem to randomly
-   miss the propcache */
-static const int expectedCount = 100;
 static int callCount = 0;
 
 static bool
-addProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
+AddProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
 {
-  callCount++;
-  return true;
+    callCount++;
+    return true;
 }
 
-const JSClass addPropertyClass = {
+static const JSClass AddPropertyClass = {
     "AddPropertyTester",
     0,
-    addProperty,
+    AddProperty,
     JS_DeletePropertyStub,   /* delProperty */
     JS_PropertyStub,         /* getProperty */
     JS_StrictPropertyStub,   /* setProperty */
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub
 };
 
 BEGIN_TEST(testAddPropertyHook)
 {
+    /*
+     * Do the test a bunch of times, because sometimes we seem to randomly
+     * miss the propcache.
+     */
+    static const int ExpectedCount = 100;
+
     JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr));
     CHECK(obj);
     JS::RootedValue proto(cx, OBJECT_TO_JSVAL(obj));
-    JS_InitClass(cx, global, obj, &addPropertyClass, nullptr, 0, nullptr, nullptr, nullptr,
+    JS_InitClass(cx, global, obj, &AddPropertyClass, nullptr, 0, nullptr, nullptr, nullptr,
                  nullptr);
 
     obj = JS_NewArrayObject(cx, 0, nullptr);
     CHECK(obj);
     JS::RootedValue arr(cx, OBJECT_TO_JSVAL(obj));
 
     CHECK(JS_DefineProperty(cx, global, "arr", arr,
                             JS_PropertyStub, JS_StrictPropertyStub,
                             JSPROP_ENUMERATE));
 
-    for (int i = 0; i < expectedCount; ++i) {
-        obj = JS_NewObject(cx, &addPropertyClass, nullptr, nullptr);
+    for (int i = 0; i < ExpectedCount; ++i) {
+        obj = JS_NewObject(cx, &AddPropertyClass, nullptr, nullptr);
         CHECK(obj);
         JS::RootedValue vobj(cx, OBJECT_TO_JSVAL(obj));
         JS::RootedObject arrObj(cx, JSVAL_TO_OBJECT(arr));
         CHECK(JS_DefineElement(cx, arrObj, i, vobj,
                                JS_PropertyStub, JS_StrictPropertyStub,
                                JSPROP_ENUMERATE));
     }
 
     // Now add a prop to each of the objects, but make sure to do
     // so at the same bytecode location so we can hit the propcache.
     EXEC("'use strict';                                     \n"
          "for (var i = 0; i < arr.length; ++i)              \n"
          "  arr[i].prop = 42;                               \n"
          );
 
-    CHECK(callCount == expectedCount);
+    CHECK(callCount == ExpectedCount);
 
     return true;
 }
 END_TEST(testAddPropertyHook)
 
--- a/js/src/jsapi-tests/testArgumentsObject.cpp
+++ b/js/src/jsapi-tests/testArgumentsObject.cpp
@@ -29,26 +29,16 @@ static const char STRICT_ONE[] =
 static const char STRICT_TWO[] =
     "function f() { 'use strict'; return arguments; }";
 static const char STRICT_THREE[] =
     "function f() { 'use strict'; return arguments; }";
 
 static const char * const CALL_CODES[] =
     { "f()", "f(0)", "f(0, 1)", "f(0, 1, 2)", "f(0, 1, 2, 3)", "f(0, 1, 2, 3, 4)" };
 
-static const size_t MAX_ELEMS = 6;
-
-static void
-ClearElements(Value elems[MAX_ELEMS])
-{
-    for (size_t i = 0; i < MAX_ELEMS - 1; i++)
-        elems[i] = NullValue();
-    elems[MAX_ELEMS - 1] = Int32Value(42);
-}
-
 BEGIN_TEST(testArgumentsObject)
 {
     return ExhaustiveTest<0>(NORMAL_ZERO) &&
            ExhaustiveTest<1>(NORMAL_ZERO) &&
            ExhaustiveTest<2>(NORMAL_ZERO) &&
            ExhaustiveTest<0>(NORMAL_ONE) &&
            ExhaustiveTest<1>(NORMAL_ONE) &&
            ExhaustiveTest<2>(NORMAL_ONE) &&
@@ -79,16 +69,18 @@ BEGIN_TEST(testArgumentsObject)
            ExhaustiveTest<0>(STRICT_THREE) &&
            ExhaustiveTest<1>(STRICT_THREE) &&
            ExhaustiveTest<2>(STRICT_THREE) &&
            ExhaustiveTest<3>(STRICT_THREE) &&
            ExhaustiveTest<4>(STRICT_THREE) &&
            ExhaustiveTest<5>(STRICT_THREE);
 }
 
+static const size_t MAX_ELEMS = 6;
+
 template<size_t ArgCount> bool
 ExhaustiveTest(const char funcode[])
 {
     RootedValue v(cx);
     EVAL(funcode, v.address());
 
     EVAL(CALL_CODES[ArgCount], v.address());
     Rooted<ArgumentsObject*> argsobj(cx, &JSVAL_TO_OBJECT(v)->as<ArgumentsObject>());
@@ -104,9 +96,17 @@ ExhaustiveTest(const char funcode[])
             for (size_t k = j; k < MAX_ELEMS - 1; k++)
                 CHECK_SAME(elems[k], JSVAL_NULL);
             CHECK_SAME(elems[MAX_ELEMS - 1], INT_TO_JSVAL(42));
         }
     }
 
     return true;
 }
+
+static void
+ClearElements(Value elems[MAX_ELEMS])
+{
+    for (size_t i = 0; i < MAX_ELEMS - 1; i++)
+        elems[i] = NullValue();
+    elems[MAX_ELEMS - 1] = Int32Value(42);
+}
 END_TEST(testArgumentsObject)
--- a/js/src/jsapi-tests/testArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testArrayBuffer.cpp
@@ -1,22 +1,22 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 
 #include "jsfriendapi.h"
 
 #include "jsapi-tests/tests.h"
 
-#define NUM_TEST_BUFFERS 2
-#define MAGIC_VALUE_1 3
-#define MAGIC_VALUE_2 17
-
 BEGIN_TEST(testArrayBuffer_bug720949_steal)
 {
+    static const unsigned NUM_TEST_BUFFERS  = 2;
+    static const unsigned MAGIC_VALUE_1 = 3;
+    static const unsigned MAGIC_VALUE_2 = 17;
+
     JS::RootedObject buf_len1(cx), buf_len200(cx);
     JS::RootedObject tarray_len1(cx), tarray_len200(cx);
 
     uint32_t sizes[NUM_TEST_BUFFERS] = { sizeof(uint32_t), 200 * sizeof(uint32_t) };
     JS::HandleObject testBuf[NUM_TEST_BUFFERS] = { buf_len1, buf_len200 };
     JS::HandleObject testArray[NUM_TEST_BUFFERS] = { tarray_len1, tarray_len200 };
 
     // Single-element ArrayBuffer (uses fixed slots for storage)
@@ -87,22 +87,16 @@ BEGIN_TEST(testArrayBuffer_bug720949_ste
         CHECK(JS_GetElement(cx, dstview, 0, &v));
         CHECK_SAME(v, INT_TO_JSVAL(MAGIC_VALUE_2));
     }
 
     return true;
 }
 END_TEST(testArrayBuffer_bug720949_steal)
 
-static void GC(JSContext *cx)
-{
-    JS_GC(JS_GetRuntime(cx));
-    JS_GC(JS_GetRuntime(cx)); // Trigger another to wait for background finalization to end
-}
-
 // Varying number of views of a buffer, to test the neutering weak pointers
 BEGIN_TEST(testArrayBuffer_bug720949_viewList)
 {
     JS::RootedObject buffer(cx);
 
     // No views
     buffer = JS_NewArrayBuffer(cx, 2000);
     buffer = nullptr;
@@ -157,14 +151,20 @@ BEGIN_TEST(testArrayBuffer_bug720949_vie
         GC(cx);
         buffer = nullptr;
         GC(cx);
     }
 
     return true;
 }
 
+static void GC(JSContext *cx)
+{
+    JS_GC(JS_GetRuntime(cx));
+    JS_GC(JS_GetRuntime(cx)); // Trigger another to wait for background finalization to end
+}
+
 bool isNeutered(JS::HandleObject obj) {
     JS::RootedValue v(cx);
     return JS_GetProperty(cx, obj, "byteLength", &v) && v.toInt32() == 0;
 }
 
 END_TEST(testArrayBuffer_bug720949_viewList)
--- a/js/src/jsapi-tests/testChromeBuffer.cpp
+++ b/js/src/jsapi-tests/testChromeBuffer.cpp
@@ -1,36 +1,36 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * 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 "jsapi-tests/tests.h"
 
-JSPrincipals system_principals = {
+static JSPrincipals system_principals = {
     1
 };
 
-const JSClass global_class = {
+static const JSClass global_class = {
     "global",
     JSCLASS_IS_GLOBAL | JSCLASS_GLOBAL_FLAGS,
     JS_PropertyStub,
     JS_DeletePropertyStub,
     JS_PropertyStub,
     JS_StrictPropertyStub,
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub
 };
 
-JSObject *trusted_glob = nullptr;
-JSObject *trusted_fun = nullptr;
+static JSObject *trusted_glob = nullptr;
+static JSObject *trusted_fun = nullptr;
 
-bool
+static bool
 CallTrusted(JSContext *cx, unsigned argc, jsval *vp)
 {
     if (!JS_SaveFrameChain(cx))
         return false;
 
     bool ok = false;
     {
         JSAutoCompartment ac(cx, trusted_glob);
--- a/js/src/jsapi-tests/testClassGetter.cpp
+++ b/js/src/jsapi-tests/testClassGetter.cpp
@@ -4,18 +4,18 @@
  * Tests the JSClass::getProperty hook
  */
 /* 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 "jsapi-tests/tests.h"
 
-int called_test_fn;
-int called_test_prop_get;
+static int called_test_fn;
+static int called_test_prop_get;
 
 static bool test_prop_get( JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp )
 {
     called_test_prop_get++;
     return true;
 }
 
 static bool
--- a/js/src/jsapi-tests/testCloneScript.cpp
+++ b/js/src/jsapi-tests/testCloneScript.cpp
@@ -45,17 +45,17 @@ BEGIN_TEST(test_cloneScript)
         JSAutoCompartment b(cx, B);
         CHECK(JS_CloneFunctionObject(cx, obj, B));
     }
 
     return true;
 }
 END_TEST(test_cloneScript)
 
-void
+static void
 DestroyPrincipals(JSPrincipals *principals)
 {
     delete principals;
 }
 
 struct Principals : public JSPrincipals
 {
   public:
--- a/js/src/jsapi-tests/testCustomIterator.cpp
+++ b/js/src/jsapi-tests/testCustomIterator.cpp
@@ -1,23 +1,23 @@
 /* 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 "js/Class.h"
 #include "jsapi-tests/tests.h"
 
-int count = 0;
+static int iterCount = 0;
 
 static bool
 IterNext(JSContext *cx, unsigned argc, jsval *vp)
 {
-    if (count++ == 100)
+    if (iterCount++ == 100)
         return JS_ThrowStopIteration(cx);
-    JS_SET_RVAL(cx, vp, INT_TO_JSVAL(count));
+    JS_SET_RVAL(cx, vp, INT_TO_JSVAL(iterCount));
     return true;
 }
 
 static JSObject *
 IterHook(JSContext *cx, JS::HandleObject obj, bool keysonly)
 {
     JS::RootedObject iterObj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr));
     if (!iterObj)
@@ -46,17 +46,17 @@ const js::Class HasCustomIterClass = {
     {
         nullptr,     /* outerObject */
         nullptr,     /* innerObject */
         IterHook,
         false        /* isWrappedNative */
     }
 };
 
-bool
+static bool
 IterClassConstructor(JSContext *cx, unsigned argc, jsval *vp)
 {
     JSObject *obj = JS_NewObjectForConstructor(cx, Jsvalify(&HasCustomIterClass), vp);
     if (!obj)
         return false;
     JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
     return true;
 }
@@ -69,13 +69,13 @@ BEGIN_TEST(testCustomIterator_bug612523)
     JS::RootedValue result(cx);
     EVAL("var o = new HasCustomIter(); \n"
          "var j = 0; \n"
          "for (var i in o) { ++j; }; \n"
          "j;", result.address());
 
     CHECK(JSVAL_IS_INT(result));
     CHECK_EQUAL(JSVAL_TO_INT(result), 100);
-    CHECK_EQUAL(count, 101);
+    CHECK_EQUAL(iterCount, 101);
 
     return true;
 }
 END_TEST(testCustomIterator_bug612523)
--- a/js/src/jsapi-tests/testDebugger.cpp
+++ b/js/src/jsapi-tests/testDebugger.cpp
@@ -5,40 +5,40 @@
  * 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 "jscntxt.h"
 
 #include "js/OldDebugAPI.h"
 #include "jsapi-tests/tests.h"
 
-static int callCount[2] = {0, 0};
+static int callCounts[2] = {0, 0};
 
 static void *
 callCountHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, bool before,
               bool *ok, void *closure)
 {
-    callCount[before]++;
+    callCounts[before]++;
 
     JS::RootedValue thisv(cx);
     frame.getThisValue(cx, &thisv); // assert if fp is incomplete
 
     return cx;  // any non-null value causes the hook to be called again after
 }
 
 BEGIN_TEST(testDebugger_bug519719)
 {
     CHECK(JS_SetDebugMode(cx, true));
     JS_SetCallHook(rt, callCountHook, nullptr);
     EXEC("function call(fn) { fn(0); }\n"
          "function f(g) { for (var i = 0; i < 9; i++) call(g); }\n"
          "f(Math.sin);\n"    // record loop, starting in f
          "f(Math.cos);\n");  // side exit in f -> call
-    CHECK_EQUAL(callCount[0], 20);
-    CHECK_EQUAL(callCount[1], 20);
+    CHECK_EQUAL(callCounts[0], 20);
+    CHECK_EQUAL(callCounts[1], 20);
     return true;
 }
 END_TEST(testDebugger_bug519719)
 
 static void *
 nonStrictThisHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, bool before,
                   bool *ok, void *closure)
 {
@@ -107,23 +107,23 @@ BEGIN_TEST(testDebugger_getThisStrict)
          "(42).strict();\n"
          "strict.call(undefined);\n"
          "strict.call(null);\n");
     CHECK(!anyWrapped);
     return true;
 }
 END_TEST(testDebugger_getThisStrict)
 
-bool called = false;
+static bool calledThrowHook = false;
 
 static JSTrapStatus
 ThrowHook(JSContext *cx, JSScript *, jsbytecode *, jsval *rval, void *closure)
 {
     JS_ASSERT(!closure);
-    called = true;
+    calledThrowHook = true;
 
     JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
 
     char text[] = "new Error()";
     jsval _;
     JS_EvaluateScript(cx, global, text, strlen(text), "", 0, &_);
 
     return JSTRAP_CONTINUE;
@@ -135,17 +135,17 @@ BEGIN_TEST(testDebugger_throwHook)
     CHECK(JS_SetThrowHook(rt, ThrowHook, nullptr));
     EXEC("function foo() { throw 3 };\n"
          "for (var i = 0; i < 10; ++i) { \n"
          "  var x = {}\n"
          "  try {\n"
          "    foo(); \n"
          "  } catch(e) {}\n"
          "}\n");
-    CHECK(called);
+    CHECK(calledThrowHook);
     CHECK(JS_SetThrowHook(rt, nullptr, nullptr));
     return true;
 }
 END_TEST(testDebugger_throwHook)
 
 BEGIN_TEST(testDebugger_debuggerObjectVsDebugMode)
 {
     CHECK(JS_DefineDebuggerObject(cx, global));
--- a/js/src/jsapi-tests/testDefineGetterSetterNonEnumerable.cpp
+++ b/js/src/jsapi-tests/testDefineGetterSetterNonEnumerable.cpp
@@ -3,36 +3,36 @@
  */
 /* 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 "jsapi-tests/tests.h"
 
 static bool
-native(JSContext *cx, unsigned argc, jsval *vp)
+NativeGetterSetter(JSContext *cx, unsigned argc, jsval *vp)
 {
     return true;
 }
 
-static const char PROPERTY_NAME[] = "foo";
-
 BEGIN_TEST(testDefineGetterSetterNonEnumerable)
 {
+    static const char PROPERTY_NAME[] = "foo";
+
     JS::RootedValue vobj(cx);
     JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr));
     CHECK(obj);
     vobj = OBJECT_TO_JSVAL(obj);
 
-    JSFunction *funGet = JS_NewFunction(cx, native, 0, 0, nullptr, "get");
+    JSFunction *funGet = JS_NewFunction(cx, NativeGetterSetter, 0, 0, nullptr, "get");
     CHECK(funGet);
     JS::RootedObject funGetObj(cx, JS_GetFunctionObject(funGet));
     JS::RootedValue vget(cx, OBJECT_TO_JSVAL(funGetObj));
 
-    JSFunction *funSet = JS_NewFunction(cx, native, 1, 0, nullptr, "set");
+    JSFunction *funSet = JS_NewFunction(cx, NativeGetterSetter, 1, 0, nullptr, "set");
     CHECK(funSet);
     JS::RootedObject funSetObj(cx, JS_GetFunctionObject(funSet));
     JS::RootedValue vset(cx, OBJECT_TO_JSVAL(funSetObj));
 
     JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj));
     CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME,
                             JSVAL_VOID,
                             JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj),
--- a/js/src/jsapi-tests/testEnclosingFunction.cpp
+++ b/js/src/jsapi-tests/testEnclosingFunction.cpp
@@ -9,57 +9,57 @@
 
 #include "jsfriendapi.h"
 
 #include "js/OldDebugAPI.h"
 #include "jsapi-tests/tests.h"
 
 using namespace js;
 
-JSScript *found = nullptr;
+static JSScript *foundScript = nullptr;
 
-bool
+static bool
 CheckEnclosing(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
-    found = js::GetOutermostEnclosingFunctionOfScriptedCaller(cx);
+    foundScript = js::GetOutermostEnclosingFunctionOfScriptedCaller(cx);
 
     args.rval().set(UndefinedValue());
     return true;
 }
 
 BEGIN_TEST(test_enclosingFunction)
 {
     CHECK(JS_DefineFunction(cx, global, "checkEnclosing", CheckEnclosing, 0, 0));
 
     EXEC("checkEnclosing()");
-    CHECK(found == nullptr);
+    CHECK(foundScript == nullptr);
 
     RootedFunction fun(cx);
 
     JS::CompileOptions options(cx);
     options.setFileAndLine(__FILE__, __LINE__);
 
     const char s1chars[] = "checkEnclosing()";
     fun = JS_CompileFunction(cx, global, "s1", 0, nullptr, s1chars,
                              strlen(s1chars), options);
     CHECK(fun);
     EXEC("s1()");
-    CHECK(found == JS_GetFunctionScript(cx, fun));
+    CHECK(foundScript == JS_GetFunctionScript(cx, fun));
 
     const char s2chars[] = "return function() { checkEnclosing() }";
     fun = JS_CompileFunction(cx, global, "s2", 0, nullptr, s2chars,
                              strlen(s2chars), options);
     CHECK(fun);
     EXEC("s2()()");
-    CHECK(found == JS_GetFunctionScript(cx, fun));
+    CHECK(foundScript == JS_GetFunctionScript(cx, fun));
 
     const char s3chars[] = "return function() { let (x) { function g() { checkEnclosing() } return g() } }";
     fun = JS_CompileFunction(cx, global, "s3", 0, nullptr, s3chars,
                              strlen(s3chars), options);
     CHECK(fun);
     EXEC("s3()()");
-    CHECK(found == JS_GetFunctionScript(cx, fun));
+    CHECK(foundScript == JS_GetFunctionScript(cx, fun));
 
     return true;
 }
 END_TEST(test_enclosingFunction)
--- a/js/src/jsapi-tests/testErrorCopying.cpp
+++ b/js/src/jsapi-tests/testErrorCopying.cpp
@@ -7,27 +7,28 @@
 /* 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 "jsapi-tests/tests.h"
 
 static uint32_t column = 0;
 
-static void
-my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
-{
-    column = report->column;
-}
-
 BEGIN_TEST(testErrorCopying_columnCopied)
 {
         //0         1         2
         //0123456789012345678901234567
     EXEC("function check() { Object; foo; }");
 
     JS::RootedValue rval(cx);
     JS_SetErrorReporter(cx, my_ErrorReporter);
     CHECK(!JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address()));
     CHECK(column == 27);
     return true;
 }
+
+static void
+my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
+{
+    column = report->column;
+}
+
 END_TEST(testErrorCopying_columnCopied)
--- a/js/src/jsapi-tests/testGCFinalizeCallback.cpp
+++ b/js/src/jsapi-tests/testGCFinalizeCallback.cpp
@@ -1,29 +1,19 @@
 /* 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 "jsapi-tests/tests.h"
 
-const unsigned BufferSize = 20;
+static const unsigned BufferSize = 20;
 static unsigned FinalizeCalls = 0;
 static JSFinalizeStatus StatusBuffer[BufferSize];
 static bool IsCompartmentGCBuffer[BufferSize];
 
-static void
-FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC)
-{
-    if (FinalizeCalls < BufferSize) {
-        StatusBuffer[FinalizeCalls] = status;
-        IsCompartmentGCBuffer[FinalizeCalls] = isCompartmentGC;
-    }
-    ++FinalizeCalls;
-}
-
 BEGIN_TEST(testGCFinalizeCallback)
 {
     JS_SetGCParameter(rt, JSGC_MODE, JSGC_MODE_INCREMENTAL);
     JS_SetFinalizeCallback(rt, FinalizeCallback);
 
     /* Full GC, non-incremental. */
     FinalizeCalls = 0;
     JS_GC(rt);
@@ -166,9 +156,18 @@ bool checkFinalizeStatus()
 bool checkFinalizeIsCompartmentGC(bool isCompartmentGC)
 {
     for (unsigned i = 0; i < FinalizeCalls; ++i)
         CHECK(IsCompartmentGCBuffer[i] == isCompartmentGC);
 
     return true;
 }
 
+static void
+FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC)
+{
+    if (FinalizeCalls < BufferSize) {
+        StatusBuffer[FinalizeCalls] = status;
+        IsCompartmentGCBuffer[FinalizeCalls] = isCompartmentGC;
+    }
+    ++FinalizeCalls;
+}
 END_TEST(testGCFinalizeCallback)
--- a/js/src/jsapi-tests/testIndexToString.cpp
+++ b/js/src/jsapi-tests/testIndexToString.cpp
@@ -11,22 +11,16 @@
 #include "jsstr.h"
 
 #include "jsapi-tests/tests.h"
 
 #include "vm/String-inl.h"
 
 using mozilla::ArrayLength;
 
-template<size_t N> JSFlatString *
-NewString(JSContext *cx, const jschar (&chars)[N])
-{
-    return js_NewStringCopyN<js::CanGC>(cx, chars, N);
-}
-
 static const struct TestPair {
     uint32_t num;
     const char *expected;
 } tests[] = {
     { 0, "0" },
     { 1, "1" },
     { 2, "2" },
     { 9, "9" },
@@ -108,9 +102,16 @@ BEGIN_TEST(testStringToPropertyName)
     static const jschar maxPlusOneChars[] = { '4', '2', '9', '4', '9', '6', '7', '2', '9', '6' };
     JSFlatString *maxPlusOneStr = NewString(cx, maxPlusOneChars);
     CHECK(maxPlusOneStr);
     CHECK(!maxPlusOneStr->isIndex(&index));
     CHECK(maxPlusOneStr->toPropertyName(cx) != nullptr);
 
     return true;
 }
+
+template<size_t N> static JSFlatString *
+NewString(JSContext *cx, const jschar (&chars)[N])
+{
+    return js_NewStringCopyN<js::CanGC>(cx, chars, N);
+}
+
 END_TEST(testStringToPropertyName)
--- a/js/src/jsapi-tests/testIntern.cpp
+++ b/js/src/jsapi-tests/testIntern.cpp
@@ -23,26 +23,26 @@ BEGIN_TEST(testAtomizedIsNotInterned)
 END_TEST(testAtomizedIsNotInterned)
 
 struct StringWrapperStruct
 {
     JSString *str;
     bool     strOk;
 } sw;
 
-void
-FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC)
-{
-    if (status == JSFINALIZE_GROUP_START)
-        sw.strOk = js::gc::IsStringMarked(&sw.str);
-}
-
 BEGIN_TEST(testInternAcrossGC)
 {
     sw.str = JS_InternString(cx, "wrapped chars that another test shouldn't be using");
     sw.strOk = false;
     CHECK(sw.str);
     JS_SetFinalizeCallback(rt, FinalizeCallback);
     JS_GC(rt);
     CHECK(sw.strOk);
     return true;
 }
+
+static void
+FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC)
+{
+    if (status == JSFINALIZE_GROUP_START)
+        sw.strOk = js::gc::IsStringMarked(&sw.str);
+}
 END_TEST(testInternAcrossGC)
--- a/js/src/jsapi-tests/testNewObject.cpp
+++ b/js/src/jsapi-tests/testNewObject.cpp
@@ -2,19 +2,16 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 /* 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 "jsapi-tests/tests.h"
 
-const size_t N = 1000;
-static jsval argv[N];
-
 static bool
 constructHook(JSContext *cx, unsigned argc, jsval *vp)
 {
     JS::CallArgs args = CallArgsFromVp(argc, vp);
 
     // Check that arguments were passed properly from JS_New.
 
     JS::RootedObject obj(cx, JS_NewObject(cx, js::Jsvalify(&JSObject::class_), nullptr, nullptr));
@@ -51,16 +48,19 @@ constructHook(JSContext *cx, unsigned ar
     args[1].setUndefined();
     args[2].setUndefined();
 
     return true;
 }
 
 BEGIN_TEST(testNewObject_1)
 {
+    static const size_t N = 1000;
+    jsval argv[N];
+
     // Root the global argv test array. Only the first 2 entries really need to
     // be rooted, since we're only putting integers in the rest.
     CHECK(JS_AddNamedValueRoot(cx, &argv[0], "argv0"));
     CHECK(JS_AddNamedValueRoot(cx, &argv[1], "argv1"));
 
     JS::RootedValue v(cx);
     EVAL("Array", v.address());
     JS::RootedObject Array(cx, JSVAL_TO_OBJECT(v));
--- a/js/src/jsapi-tests/testOriginPrincipals.cpp
+++ b/js/src/jsapi-tests/testOriginPrincipals.cpp
@@ -1,25 +1,18 @@
 /* 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 "js/OldDebugAPI.h"
 #include "jsapi-tests/tests.h"
 
-JSPrincipals *sOriginPrincipalsInErrorReporter = nullptr;
-
-static void
-ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
-{
-    sOriginPrincipalsInErrorReporter = report->originPrincipals;
-}
-
-JSPrincipals prin1 = { 1 };
-JSPrincipals prin2 = { 1 };
+static JSPrincipals *sOriginPrincipalsInErrorReporter = nullptr;
+static JSPrincipals prin1 = { 1 };
+static JSPrincipals prin2 = { 1 };
 
 BEGIN_TEST(testOriginPrincipals)
 {
     /*
      * Currently, the only way to set a non-trivial originPrincipal is to use
      * JS_EvaluateUCScriptForPrincipalsVersionOrigin. This does not expose the
      * compiled script, so we can only test nested scripts.
      */
@@ -46,16 +39,22 @@ BEGIN_TEST(testOriginPrincipals)
      * NB: uncaught exceptions, when reported, have nothing on the stack so
      * both the filename and originPrincipals are null. E.g., this would fail:
      *
      *   CHECK(testError("throw 3"));
      */
     return true;
 }
 
+static void
+ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
+{
+    sOriginPrincipalsInErrorReporter = report->originPrincipals;
+}
+
 bool
 eval(const char *asciiChars, JSPrincipals *principals, JSPrincipals *originPrincipals, jsval *rval)
 {
     size_t len = strlen(asciiChars);
     jschar *chars = new jschar[len+1];
     for (size_t i = 0; i < len; ++i)
         chars[i] = asciiChars[i];
     chars[len] = 0;
--- a/js/src/jsapi-tests/testParseJSON.cpp
+++ b/js/src/jsapi-tests/testParseJSON.cpp
@@ -30,22 +30,16 @@ class AutoInflatedString {
         if (!chars_)
             abort();
     }
 
     const jschar *chars() const { return chars_; }
     size_t length() const { return length_; }
 };
 
-template<size_t N> JSFlatString *
-NewString(JSContext *cx, const jschar (&chars)[N])
-{
-    return js_NewStringCopyN<CanGC>(cx, chars, N);
-}
-
 BEGIN_TEST(testParseJSON_success)
 {
     // Primitives
     JS::RootedValue expected(cx);
     expected = JSVAL_TRUE;
     CHECK(TryParse(cx, "true", expected));
 
     expected = JSVAL_FALSE;
@@ -136,16 +130,22 @@ BEGIN_TEST(testParseJSON_success)
     obj = JSVAL_TO_OBJECT(v);
     CHECK(!JS_IsArrayObject(cx, obj));
     CHECK(JS_GetProperty(cx, obj, "f", &v2));
     CHECK_SAME(v2, INT_TO_JSVAL(17));
 
     return true;
 }
 
+template<size_t N> static JSFlatString *
+NewString(JSContext *cx, const jschar (&chars)[N])
+{
+    return js_NewStringCopyN<CanGC>(cx, chars, N);
+}
+
 template<size_t N> inline bool
 Parse(JSContext *cx, const char (&input)[N], JS::MutableHandleValue vp)
 {
     AutoInflatedString str(cx);
     str = input;
     CHECK(JS_ParseJSON(cx, str.chars(), str.length(), vp));
     return true;
 }
--- a/js/src/jsapi-tests/testScriptInfo.cpp
+++ b/js/src/jsapi-tests/testScriptInfo.cpp
@@ -17,26 +17,16 @@ try {              \n\
 	 xx += 1;  \n\
 }                  \n\
 catch (e)          \n\
 {                  \n\
 	 xx += 1;  \n\
 }\n\
 //@ sourceMappingURL=http://example.com/path/to/source-map.json";
 
-
-static bool
-CharsMatch(const jschar *p, const char *q) {
-    while (*q) {
-        if (*p++ != *q++)
-            return false;
-    }
-    return true;
-}
-
 // Bug 670958 - fix JS_GetScriptLineExtent, among others
 BEGIN_TEST(testScriptInfo)
 {
     unsigned startLine = 1000;
 
     JS::CompileOptions options(cx);
     options.setFileAndLine(__FILE__, startLine);
     JS::RootedScript script(cx, JS_CompileScript(cx, global, code, strlen(code),
@@ -50,9 +40,18 @@ BEGIN_TEST(testScriptInfo)
     CHECK_EQUAL(JS_GetScriptLineExtent(cx, script), 11);
     CHECK(strcmp(JS_GetScriptFilename(cx, script), __FILE__) == 0);
     const jschar *sourceMap = JS_GetScriptSourceMap(cx, script);
     CHECK(sourceMap);
     CHECK(CharsMatch(sourceMap, "http://example.com/path/to/source-map.json"));
 
     return true;
 }
+static bool
+CharsMatch(const jschar *p, const char *q)
+{
+    while (*q) {
+        if (*p++ != *q++)
+            return false;
+    }
+    return true;
+}
 END_TEST(testScriptInfo)
--- a/js/src/jsapi-tests/testSetProperty.cpp
+++ b/js/src/jsapi-tests/testSetProperty.cpp
@@ -2,35 +2,28 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 /* 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 "jsapi-tests/tests.h"
 
-static bool
-nativeGet(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
-{
-    vp.set(INT_TO_JSVAL(17));
-    return true;
-}
-
 BEGIN_TEST(testSetProperty_NativeGetterStubSetter)
 {
     JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr));
     CHECK(obj);
     JS::RootedValue vobj(cx, OBJECT_TO_JSVAL(obj));
 
     CHECK(JS_DefineProperty(cx, global, "globalProp", vobj,
                             JS_PropertyStub, JS_StrictPropertyStub,
                             JSPROP_ENUMERATE));
 
     CHECK(JS_DefineProperty(cx, obj, "prop", JSVAL_VOID,
-                            nativeGet, JS_StrictPropertyStub,
+                            NativeGet, JS_StrictPropertyStub,
                             JSPROP_SHARED));
 
     EXEC("'use strict';                                     \n"
          "var error, passed = false;                        \n"
          "try                                               \n"
          "{                                                 \n"
          "  this.globalProp.prop = 42;                      \n"
          "  throw new Error('setting property succeeded!'); \n"
@@ -59,16 +52,22 @@ BEGIN_TEST(testSetProperty_NativeGetterS
          "  error = e;                                      \n"
          "}                                                 \n"
          "                                                  \n"
          "if (!passed)                                      \n"
          "  throw error;                                    \n");
 
     return true;
 }
+static bool
+NativeGet(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
+{
+    vp.set(INT_TO_JSVAL(17));
+    return true;
+}
 END_TEST(testSetProperty_NativeGetterStubSetter)
 
 BEGIN_TEST(testSetProperty_InheritedGlobalSetter)
 {
     // This is a JSAPI test because jsapi-test globals do not have a resolve
     // hook and therefore can use the property cache in some cases where the
     // shell can't.
     JS_ASSERT(JS_GetClass(global)->resolve == &JS_ResolveStub);
--- a/js/src/jsapi-tests/testSlowScript.cpp
+++ b/js/src/jsapi-tests/testSlowScript.cpp
@@ -1,23 +1,23 @@
 /* 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 "jsapi-tests/tests.h"
 
-bool
+static bool
 OperationCallback(JSContext *cx)
 {
     return false;
 }
 
 static unsigned sRemain;
 
-bool
+static bool
 TriggerOperationCallback(JSContext *cx, unsigned argc, jsval *vp)
 {
     if (!sRemain--)
         JS_TriggerOperationCallback(JS_GetRuntime(cx));
     *vp = JSVAL_VOID;
     return true;
 }
 
--- a/js/src/jsapi-tests/testSourcePolicy.cpp
+++ b/js/src/jsapi-tests/testSourcePolicy.cpp
@@ -19,30 +19,30 @@ BEGIN_TEST(testBug795104)
     CHECK(JS::Evaluate(cx, global, opts, s, strLen, nullptr));
     CHECK(JS::CompileFunction(cx, global, opts, "f", 0, nullptr, s, strLen));
     JS_free(cx, s);
 
     return true;
 }
 END_TEST(testBug795104)
 
-const char *simpleSource = "var x = 4;";
-
-static void
-newScriptHook(JSContext *cx, const char *fn, unsigned lineno,
-              JSScript *script, JSFunction *fun, void *data)
-{
-    if (!JS_StringEqualsAscii(cx, script->sourceData(cx), simpleSource, (bool *)data))
-        *((bool *)data) = false;
-}
+static const char *const simpleSource = "var x = 4;";
 
 BEGIN_TEST(testScriptSourceReentrant)
 {
     JS::CompileOptions opts(cx);
     bool match = false;
-    JS_SetNewScriptHook(rt, newScriptHook, &match);
+    JS_SetNewScriptHook(rt, NewScriptHook, &match);
     CHECK(JS::Evaluate(cx, global, opts, simpleSource, strlen(simpleSource), nullptr));
     CHECK(match);
     JS_SetNewScriptHook(rt, nullptr, nullptr);
 
     return true;
 }
+
+static void
+NewScriptHook(JSContext *cx, const char *fn, unsigned lineno,
+              JSScript *script, JSFunction *fun, void *data)
+{
+    if (!JS_StringEqualsAscii(cx, script->sourceData(cx), simpleSource, (bool *)data))
+        *((bool *)data) = false;
+}
 END_TEST(testScriptSourceReentrant)
--- a/js/src/jsapi-tests/testXDR.cpp
+++ b/js/src/jsapi-tests/testXDR.cpp
@@ -31,17 +31,17 @@ CompileScriptForPrincipalsVersionOrigin(
            .setOriginPrincipals(originPrincipals)
            .setFileAndLine(filename, lineno)
            .setVersion(version);
     JSScript *script = JS::Compile(cx, obj, options, chars, nchars);
     free(chars);
     return script;
 }
 
-JSScript *
+static JSScript *
 FreezeThaw(JSContext *cx, JS::HandleScript script)
 {
     // freeze
     uint32_t nbytes;
     void *memory = JS_EncodeScript(cx, script, &nbytes);
     if (!memory)
         return nullptr;
 
@@ -53,17 +53,17 @@ FreezeThaw(JSContext *cx, JS::HandleScri
 }
 
 static JSScript *
 GetScript(JSContext *cx, JS::HandleObject funobj)
 {
     return JS_GetFunctionScript(cx, JS_GetObjectFunction(funobj));
 }
 
-JSObject *
+static JSObject *
 FreezeThaw(JSContext *cx, JS::HandleObject funobj)
 {
     // freeze
     uint32_t nbytes;
     void *memory = JS_EncodeInterpretedFunction(cx, funobj, &nbytes);
     if (!memory)
         return nullptr;