Bug 813278 - Overload JSAutoCompartment for TimeZoneSettingObserver. r=luke, a=blocking-basecamp
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 20 Nov 2012 01:39:26 -0800
changeset 118379 8e0eab3895cc
parent 118378 e6265a22c963
child 118380 3e184d0a1984
push id2760
push userryanvm@gmail.com
push dateThu, 22 Nov 2012 05:11:12 +0000
treeherdermozilla-aurora@a81094b387a2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke, blocking-basecamp
bugs813278
milestone19.0a2
Bug 813278 - Overload JSAutoCompartment for TimeZoneSettingObserver. r=luke, a=blocking-basecamp
dom/system/gonk/TimeZoneSettingObserver.cpp
js/src/jsapi.cpp
js/src/jsapi.h
--- a/dom/system/gonk/TimeZoneSettingObserver.cpp
+++ b/dom/system/gonk/TimeZoneSettingObserver.cpp
@@ -77,17 +77,17 @@ public:
       settingsService->CreateLock(getter_AddRefs(lock));
       lock->Set(TIME_TIMEZONE, STRING_TO_JSVAL(jsStr), nullptr, nullptr);
       return NS_OK;
     }
 
     // Set the system timezone based on the current settings.
     if (aResult.isString()) {
       JSAutoRequest ar(cx);
-      JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(aResult));
+      JSAutoCompartment ac(cx, aResult.toString());
       return TimeZoneSettingObserver::SetTimeZone(aResult, cx);
     }
 
     return NS_OK;
   }
 
   NS_IMETHOD HandleError(const nsAString &aName) {
     ERR("TimeZoneSettingCb::HandleError: %s\n", NS_LossyConvertUTF16toASCII(aName).get());
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1483,16 +1483,24 @@ JSAutoCompartment::JSAutoCompartment(JSC
 JSAutoCompartment::JSAutoCompartment(JSContext *cx, JSStackFrame *target)
   : cx_(cx),
     oldCompartment_(cx->compartment)
 {
     AssertHeapIsIdleOrIterating(cx_);
     cx_->enterCompartment(Valueify(target)->global().compartment());
 }
 
+JSAutoCompartment::JSAutoCompartment(JSContext *cx, JSString *target)
+  : cx_(cx),
+    oldCompartment_(cx->compartment)
+{
+    AssertHeapIsIdleOrIterating(cx_);
+    cx_->enterCompartment(target->compartment());
+}
+
 JSAutoCompartment::~JSAutoCompartment()
 {
     cx_->leaveCompartment(oldCompartment_);
 }
 
 JS_PUBLIC_API(void)
 JS_SetCompartmentPrivate(JSCompartment *compartment, void *data)
 {
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -3151,16 +3151,17 @@ JS_RefreshCrossCompartmentWrappers(JSCon
 class JS_PUBLIC_API(JSAutoCompartment)
 {
     JSContext *cx_;
     JSCompartment *oldCompartment_;
   public:
     JSAutoCompartment(JSContext *cx, JSRawObject target);
     JSAutoCompartment(JSContext *cx, JSScript *target);
     JSAutoCompartment(JSContext *cx, JSStackFrame *target);
+    JSAutoCompartment(JSContext *cx, JSString *target);
     ~JSAutoCompartment();
 };
 
 /* NB: This API is infallible; a NULL return value does not indicate error. */
 extern JS_PUBLIC_API(JSCompartment *)
 JS_EnterCompartment(JSContext *cx, JSRawObject target);
 
 extern JS_PUBLIC_API(void)