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 117096 f3b8cb5ab8fd
parent 117095 43bb139d67f4
child 117097 b5abc0422693
push id1736
push userryanvm@gmail.com
push dateThu, 22 Nov 2012 05:10:47 +0000
treeherdermozilla-beta@ab5d992d637e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke, blocking-basecamp
bugs813278
milestone18.0
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
@@ -1471,16 +1471,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
@@ -3248,16 +3248,17 @@ JS_END_EXTERN_C
 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();
 };
 
 JS_BEGIN_EXTERN_C
 #endif
 
 /* NB: This API is infallible; a NULL return value does not indicate error. */
 extern JS_PUBLIC_API(JSCompartment *)