From 5ebabfa48acba193f1dfd7e56bdf470358c67cab Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Wed, 20 Sep 2006 01:21:25 +0000 Subject: [PATCH] Don't bother spending time to root the jsval if it's a string -- in this case we make a copy of the string data anyway, so we don't need the jsval. Bug 311582, r+sr=jst git-svn-id: svn://10.0.0.236/trunk@212045 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/xpconnect/src/xpcvariant.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mozilla/js/src/xpconnect/src/xpcvariant.cpp b/mozilla/js/src/xpconnect/src/xpcvariant.cpp index 6229445edd2..b58b396282a 100644 --- a/mozilla/js/src/xpconnect/src/xpcvariant.cpp +++ b/mozilla/js/src/xpconnect/src/xpcvariant.cpp @@ -53,8 +53,10 @@ XPCVariant::XPCVariant() XPCVariant::~XPCVariant() { nsVariant::Cleanup(&mData); - - if(JSVAL_IS_GCTHING(mJSVal)) + + // We don't root strings; see comments in newVariant. Note that even if + // the string went away testing JSVAL_IS_STRING(mJSVal) is safe. + if(JSVAL_IS_GCTHING(mJSVal) && !JSVAL_IS_STRING(mJSVal)) { JSRuntime* rt; nsIJSRuntimeService* rtsrvc = nsXPConnect::GetJSRuntimeService(); @@ -75,7 +77,9 @@ XPCVariant* XPCVariant::newVariant(XPCCallContext& ccx, jsval aJSVal) variant->mJSVal = aJSVal; - if(JSVAL_IS_GCTHING(variant->mJSVal)) + // We don't need to root mJSVal if it's a string -- in that case we'll just + // make a copy of the string data. + if(JSVAL_IS_GCTHING(variant->mJSVal) && !JSVAL_IS_STRING(variant->mJSVal)) { JSRuntime* rt; if(NS_FAILED(ccx.GetRuntime()->GetJSRuntimeService()->GetRuntime(&rt))||