From fa7bcd268b4015a21bbd2009b7455e4f35cbbde1 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Mon, 29 Mar 2010 12:24:03 -0700 Subject: [PATCH] Readd jsregexp.{cpp,h} (and to users of the regex-statics save/restore methods) and nsJSEnvironment.{cpp,h} changes for bug 548702. --- dom/base/nsJSEnvironment.cpp | 12 ++++-------- dom/base/nsJSEnvironment.h | 9 ++++++--- js/src/jsregexp.cpp | 11 +++++------ js/src/jsregexp.h | 6 ++++-- js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp | 6 +++--- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index d741e3f0528..e48c772fc0f 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2108,15 +2108,11 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, void *aScope, void *aHandler return NS_OK; } - jsval targetVal = JSVAL_VOID; - JSAutoTempValueRooter tvr(mContext, 1, &targetVal); - JSObject* target = nsnull; nsresult rv = JSObjectFromInterface(aTarget, aScope, &target); NS_ENSURE_SUCCESS(rv, rv); - targetVal = OBJECT_TO_JSVAL(target); - + js::AutoObjectRooter targetVal(mContext, target); jsval rval = JSVAL_VOID; // This one's a lot easier than EvaluateString because we don't have to @@ -2140,7 +2136,7 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, void *aScope, void *aHandler jsval *argv = nsnull; js::LazilyConstructed poolRelease; - js::LazilyConstructed tvr; + js::LazilyConstructed tvr; // Use |target| as the scope for wrapping the arguments, since aScope is // the safe scope in many cases, which isn't very useful. Wrapping aTarget @@ -2654,7 +2650,7 @@ nsJSContext::SetProperty(void *aTarget, const char *aPropName, nsISupports *aArg JSAutoRequest ar(mContext); js::LazilyConstructed poolRelease; - js::LazilyConstructed tvr; + js::LazilyConstructed tvr; nsresult rv; rv = ConvertSupportsTojsvals(aArgs, GetNativeGlobal(), &argc, @@ -2689,7 +2685,7 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs, PRUint32 *aArgc, jsval **aArgv, js::LazilyConstructed &aPoolRelease, - js::LazilyConstructed &aRooter) + js::LazilyConstructed &aRooter) { nsresult rv = NS_OK; diff --git a/dom/base/nsJSEnvironment.h b/dom/base/nsJSEnvironment.h index 785d53c109e..cec89748f9b 100644 --- a/dom/base/nsJSEnvironment.h +++ b/dom/base/nsJSEnvironment.h @@ -49,8 +49,11 @@ class nsIXPConnectJSObjectHolder; class nsAutoPoolRelease; -class JSAutoTempValueRooter; -namespace js { template class LazilyConstructed; } +namespace js { +class AutoObjectRooter; +class AutoArrayRooter; +template class LazilyConstructed; +} class nsJSContext : public nsIScriptContext, public nsIXPCScriptNotify @@ -215,7 +218,7 @@ protected: PRUint32 *aArgc, jsval **aArgv, js::LazilyConstructed &aPoolRelease, - js::LazilyConstructed &aRooter); + js::LazilyConstructed &aRooter); nsresult AddSupportsPrimitiveTojsvals(nsISupports *aArg, jsval *aArgv); diff --git a/js/src/jsregexp.cpp b/js/src/jsregexp.cpp index e5d902d0b1e..fcbcb4f1dfa 100644 --- a/js/src/jsregexp.cpp +++ b/js/src/jsregexp.cpp @@ -5226,11 +5226,11 @@ js_InitRegExpStatics(JSContext *cx) JS_FRIEND_API(void) js_SaveAndClearRegExpStatics(JSContext *cx, JSRegExpStatics *statics, - JSTempValueRooter *tvr) + AutoValueRooter *tvr) { *statics = cx->regExpStatics; - JS_PUSH_TEMP_ROOT_STRING(cx, statics->input, tvr); - + if (statics->input) + tvr->setString(statics->input); /* * Prevent JS_ClearRegExpStatics from freeing moreParens, since we've only * moved it elsewhere (into statics->moreParens). @@ -5241,12 +5241,11 @@ js_SaveAndClearRegExpStatics(JSContext *cx, JSRegExpStatics *statics, JS_FRIEND_API(void) js_RestoreRegExpStatics(JSContext *cx, JSRegExpStatics *statics, - JSTempValueRooter *tvr) + AutoValueRooter *tvr) { /* Clear/free any new JSRegExpStatics data before clobbering. */ JS_ClearRegExpStatics(cx); cx->regExpStatics = *statics; - JS_POP_TEMP_ROOT(cx, tvr); } void @@ -5839,7 +5838,7 @@ js_NewRegExpObject(JSContext *cx, TokenStream *ts, str = js_NewStringCopyN(cx, chars, length); if (!str) return NULL; - JSAutoTempValueRooter tvr(cx, str); + AutoValueRooter tvr(cx, str); re = js_NewRegExp(cx, ts, str, flags, JS_FALSE); if (!re) return NULL; diff --git a/js/src/jsregexp.h b/js/src/jsregexp.h index 63680651e86..73cfee81745 100644 --- a/js/src/jsregexp.h +++ b/js/src/jsregexp.h @@ -65,13 +65,15 @@ struct JSRegExpStatics { JSSubString rightContext; /* input to right of last match (perl $') */ }; +namespace js { class AutoValueRooter; } + extern JS_FRIEND_API(void) js_SaveAndClearRegExpStatics(JSContext *cx, JSRegExpStatics *statics, - JSTempValueRooter *tvr); + js::AutoValueRooter *tvr); extern JS_FRIEND_API(void) js_RestoreRegExpStatics(JSContext *cx, JSRegExpStatics *statics, - JSTempValueRooter *tvr); + js::AutoValueRooter *tvr); /* * This struct holds a bitmap representation of a class from a regexp. diff --git a/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp b/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp index a0ec10566de..074cb8e4594 100644 --- a/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp +++ b/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp @@ -478,7 +478,7 @@ XPC_SJOW_DelProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) NS_STACK_CLASS class SafeCallGuard { public: SafeCallGuard(JSContext *cx, nsIPrincipal *principal) - : cx(cx) { + : cx(cx), tvr(cx) { nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager(); if (ssm) { // Note: We pass null as the target frame pointer because we know that @@ -517,7 +517,7 @@ public: private: JSContext *cx; JSRegExpStatics statics; - JSTempValueRooter tvr; + js::AutoValueRooter tvr; uint32 options; JSStackFrame *fp; }; @@ -957,7 +957,7 @@ XPC_SJOW_Iterator(JSContext *cx, JSObject *obj, JSBool keysonly) return nsnull; } - JSAutoTempValueRooter tvr(cx, OBJECT_TO_JSVAL(wrapperIter)); + js::AutoValueRooter tvr(cx, OBJECT_TO_JSVAL(wrapperIter)); // Initialize the wrapper. return XPCWrapper::CreateIteratorObj(cx, wrapperIter, obj, unsafeObj,