Bug 869479 - GC: Fix rooting hazards in jsapi tests r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 08 May 2013 11:38:12 +0100
changeset 142195 e28bac451f8830753f6ab8079d00bcad3b174571
parent 142194 898b2c5eaa5d9d109fae14a92646c756476ce277
child 142196 bce4dc724d4a92605c342d6c5065941cc0492ac1
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs869479
milestone23.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 869479 - GC: Fix rooting hazards in jsapi tests r=terrence
js/src/jsapi-tests/testXDR.cpp
--- a/js/src/jsapi-tests/testXDR.cpp
+++ b/js/src/jsapi-tests/testXDR.cpp
@@ -33,28 +33,29 @@ CompileScriptForPrincipalsVersionOrigin(
            .setFileAndLine(filename, lineno)
            .setVersion(version);
     JSScript *script = JS::Compile(cx, obj, options, chars, nchars);
     free(chars);
     return script;
 }
 
 JSScript *
-FreezeThaw(JSContext *cx, JSScript *script)
+FreezeThaw(JSContext *cx, JS::HandleScript script)
 {
     // freeze
     uint32_t nbytes;
     void *memory = JS_EncodeScript(cx, script, &nbytes);
     if (!memory)
         return NULL;
 
     // thaw
-    script = JS_DecodeScript(cx, memory, nbytes, script->principals(), script->originPrincipals);
+    JSScript *script2 = JS_DecodeScript(cx, memory, nbytes,
+                                        script->principals(), script->originPrincipals);
     js_free(memory);
-    return script;
+    return script2;
 }
 
 static JSScript *
 GetScript(JSContext *cx, JS::HandleObject funobj)
 {
     return JS_GetFunctionScript(cx, JS_GetObjectFunction(funobj));
 }
 
@@ -118,19 +119,19 @@ enum TestCase {
 
 JSScript *createScriptViaXDR(JSPrincipals *prin, JSPrincipals *orig, int testCase)
 {
     const char src[] =
         "function f() { return 1; }\n"
         "f;\n";
 
     JS::RootedObject global(cx, JS_GetGlobalObject(cx));
-    JSScript *script = CompileScriptForPrincipalsVersionOrigin(cx, global, prin, orig,
-                                                               src, strlen(src), "test", 1,
-                                                               JSVERSION_DEFAULT);
+    JS::RootedScript script(cx, CompileScriptForPrincipalsVersionOrigin(cx, global, prin, orig,
+                                                                        src, strlen(src), "test", 1,
+                                                                        JSVERSION_DEFAULT));
     if (!script)
         return NULL;
 
     if (testCase == TEST_SCRIPT || testCase == TEST_SERIALIZED_FUNCTION) {
         script = FreezeThaw(cx, script);
         if (!script)
             return NULL;
         if (testCase == TEST_SCRIPT)
@@ -158,17 +159,17 @@ BEGIN_TEST(testXDR_bug506491)
         "function makeClosure(s, name, value) {\n"
         "    eval(s);\n"
         "    Math.sin(value);\n"
         "    return let (n = name, v = value) function () { return String(v); };\n"
         "}\n"
         "var f = makeClosure('0;', 'status', 'ok');\n";
 
     // compile
-    JSScript *script = JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__);
+    JS::RootedScript script(cx, JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__));
     CHECK(script);
 
     script = FreezeThaw(cx, script);
     CHECK(script);
 
     // execute
     JS::RootedValue v2(cx);
     CHECK(JS_ExecuteScript(cx, global, script, v2.address()));
@@ -182,17 +183,17 @@ BEGIN_TEST(testXDR_bug506491)
     CHECK_SAME(v2, trueval);
     return true;
 }
 END_TEST(testXDR_bug506491)
 
 BEGIN_TEST(testXDR_bug516827)
 {
     // compile an empty script
-    JSScript *script = JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__);
+    JS::RootedScript script(cx, JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__));
     CHECK(script);
 
     script = FreezeThaw(cx, script);
     CHECK(script);
 
     // execute with null result meaning no result wanted
     CHECK(JS_ExecuteScript(cx, global, script, NULL));
     return true;
@@ -203,17 +204,17 @@ BEGIN_TEST(testXDR_source)
 {
     const char *samples[] = {
         // This can't possibly fail to compress well, can it?
         "function f(x) { return x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x }",
         "short",
         NULL
     };
     for (const char **s = samples; *s; s++) {
-        JSScript *script = JS_CompileScript(cx, global, *s, strlen(*s), __FILE__, __LINE__);
+        JS::RootedScript script(cx, JS_CompileScript(cx, global, *s, strlen(*s), __FILE__, __LINE__));
         CHECK(script);
         script = FreezeThaw(cx, script);
         CHECK(script);
         JSString *out = JS_DecompileScript(cx, script, "testing", 0);
         CHECK(out);
         JSBool equal;
         CHECK(JS_StringEqualsAscii(cx, out, *s, &equal));
         CHECK(equal);