Bug 682298 - Calling shell-only clear() function with no arguments reads garbage. r=luke.
authorJason Orendorff <jorendorff@mozilla.com>
Tue, 30 Aug 2011 06:10:09 -0500
changeset 77543 efcd1318cf4d48fc5544a1a84f928d826bea2461
parent 77542 77c5e531f7cbcde17e8a5096ced366fc8d84b0bc
child 77544 9eaca4ef5880a4b7f8916476061891164a61327f
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs682298
milestone9.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 682298 - Calling shell-only clear() function with no arguments reads garbage. r=luke.
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2661,21 +2661,26 @@ BuildDate(JSContext *cx, uintN argc, jsv
     *vp = JSVAL_VOID;
     return JS_TRUE;
 }
 
 static JSBool
 Clear(JSContext *cx, uintN argc, jsval *vp)
 {
     JSObject *obj;
-    if (argc != 0 && !JS_ValueToObject(cx, JS_ARGV(cx, vp)[0], &obj))
-        return JS_FALSE;
+    if (argc == 0) {
+        obj = JS_GetGlobalForScopeChain(cx);
+        if (!obj)
+            return false;
+    } else if (!JS_ValueToObject(cx, JS_ARGV(cx, vp)[0], &obj)) {
+        return false;
+    }
     JS_ClearScope(cx, obj);
     JS_SET_RVAL(cx, vp, JSVAL_VOID);
-    return JS_TRUE;
+    return true;
 }
 
 static JSBool
 Intern(JSContext *cx, uintN argc, jsval *vp)
 {
     JSString *str = JS_ValueToString(cx, argc == 0 ? JSVAL_VOID : vp[2]);
     if (!str)
         return false;