Bug 801712 part 3. Make object return values faster by only doing the JS_WrapValue if needed. r=peterv

This commit is contained in:
Boris Zbarsky 2012-10-22 13:08:52 -04:00
parent b598ec354c
commit 800cb6581d
2 changed files with 14 additions and 3 deletions

View File

@ -402,6 +402,17 @@ CreateInterfaceObjects(JSContext* cx, JSObject* global, JSObject* receiver,
const NativeProperties* chromeProperties,
const char* name);
inline bool
MaybeWrapValue(JSContext* cx, JSObject* obj, JS::Value* vp)
{
if (vp->isObject() &&
js::GetObjectCompartment(&vp->toObject()) != js::GetObjectCompartment(obj)) {
return JS_WrapValue(cx, vp);
}
return true;
}
template <class T>
inline bool
WrapNewBindingObject(JSContext* cx, JSObject* scope, T* value, JS::Value* vp)

View File

@ -2752,17 +2752,17 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
def setValue(value, callWrapValue=False):
"""
Returns the code to set the jsval to value. If "callWrapValue" is true
JS_WrapValue will be called on the jsval.
MaybeWrapValue will be called on the jsval.
"""
if not callWrapValue:
tail = successCode
elif haveSuccessCode:
tail = ("if (!JS_WrapValue(cx, ${jsvalPtr})) {\n" +
tail = ("if (!MaybeWrapValue(cx, ${obj}, ${jsvalPtr})) {\n" +
" return false;\n" +
"}\n" +
successCode)
else:
tail = "return JS_WrapValue(cx, ${jsvalPtr});"
tail = "return MaybeWrapValue(cx, ${obj}, ${jsvalPtr});"
return ("${jsvalRef} = %s;\n" +
tail) % (value)