From 8c13f0684f2c5ede7411af8c23b349e4b18414bf Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Tue, 20 Nov 2012 01:39:26 -0800 Subject: [PATCH] Bug 813278 - Overload JSAutoCompartment for TimeZoneSettingObserver - r=luke --- dom/system/gonk/TimeZoneSettingObserver.cpp | 2 +- js/src/jsapi.cpp | 8 ++++++++ js/src/jsapi.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dom/system/gonk/TimeZoneSettingObserver.cpp b/dom/system/gonk/TimeZoneSettingObserver.cpp index 79158383816..c742f844b43 100644 --- a/dom/system/gonk/TimeZoneSettingObserver.cpp +++ b/dom/system/gonk/TimeZoneSettingObserver.cpp @@ -82,7 +82,7 @@ public: // 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); } diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 6eb395e63c0..6c77b904fdd 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1488,6 +1488,14 @@ JSAutoCompartment::JSAutoCompartment(JSContext *cx, JSStackFrame *target) 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_); diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 0635f2ff49c..ba4ed5550f4 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3156,6 +3156,7 @@ class JS_PUBLIC_API(JSAutoCompartment) JSAutoCompartment(JSContext *cx, JSRawObject target); JSAutoCompartment(JSContext *cx, JSScript *target); JSAutoCompartment(JSContext *cx, JSStackFrame *target); + JSAutoCompartment(JSContext *cx, JSString *target); ~JSAutoCompartment(); };