From 80a1feb0df2373250042d999606a9b926a16d9f5 Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Thu, 30 Sep 2010 16:50:06 -0700 Subject: [PATCH] Bug 600402 - don't copy strings that are in the same compartment already r=mrbkap --- js/src/jscompartment.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/js/src/jscompartment.cpp b/js/src/jscompartment.cpp index d120f22a69f9..96b4ad80dd0e 100644 --- a/js/src/jscompartment.cpp +++ b/js/src/jscompartment.cpp @@ -116,16 +116,30 @@ JSCompartment::wrap(JSContext *cx, Value *vp) if (!vp->isMarkable()) return true; - /* Static strings do not have to be wrapped. */ - if (vp->isString() && JSString::isStatic(vp->toString())) - return true; + if (vp->isString()) { + JSString *str = vp->toString(); + + /* Static strings do not have to be wrapped. */ + if (JSString::isStatic(str)) + return true; + + /* If the string is already in this compartment, we are done. */ + if (str->asCell()->compartment() == this) + return true; + + /* If the string is an atom, we don't have to copy. */ + if (str->isAtomized()) { + JS_ASSERT(str->asCell()->compartment() == cx->runtime->defaultCompartment); + return true; + } + } /* Unwrap incoming objects. */ if (vp->isObject()) { JSObject *obj = &vp->toObject(); /* If the object is already in this compartment, we are done. */ - if (obj->getCompartment(cx) == this) + if (obj->compartment() == this) return true; /* Don't unwrap an outer window proxy. */