Bug 813278 - Overload JSAutoCompartment for TimeZoneSettingObserver - r=luke
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 20 Nov 2012 01:39:26 -0800
changeset 113759 26544b27ef13
parent 113758 ac86426a764e
child 113760 2739c46c2239
push id18371
push userjgilbert@mozilla.com
push dateTue, 20 Nov 2012 09:40:17 +0000
treeherdermozilla-inbound@26544b27ef13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs813278
milestone20.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 813278 - Overload JSAutoCompartment for TimeZoneSettingObserver - r=luke
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)