From b97410bfd2405f923f1eae5c85fa37624296550d Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Tue, 4 May 2010 18:02:00 -0700 Subject: [PATCH] Outerize the results of nsIDOMWindowUtils.getParent and the jsshell's parent() methods. r=orange --HG-- extra : rebase_source : 848ad247e5094b6eb8edce6198bfb1d368c31bc3 --- dom/base/nsDOMWindowUtils.cpp | 12 +++++++++++- js/src/shell/js.cpp | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index df63899aaa9a..4d616dd5a0ea 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -1313,7 +1313,17 @@ nsDOMWindowUtils::GetParent() if(JSVAL_IS_PRIMITIVE(argv[0])) return NS_ERROR_XPC_BAD_CONVERT_JS; - *rval = OBJECT_TO_JSVAL(JS_GetParent(cx, JSVAL_TO_OBJECT(argv[0]))); + JSObject *parent = JS_GetParent(cx, JSVAL_TO_OBJECT(argv[0])); + *rval = OBJECT_TO_JSVAL(parent); + + // Outerize if necessary. Embrace the ugliness! + JSClass *clasp = JS_GetClass(cx, parent); + if (clasp->flags & JSCLASS_IS_EXTENDED) { + JSExtendedClass *xclasp = reinterpret_cast(clasp); + if (JSObjectOp outerize = xclasp->outerObject) + *rval = OBJECT_TO_JSVAL(outerize(cx, parent)); + } + cc->SetReturnValueWasSet(PR_TRUE); return NS_OK; } diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 12401a87eaab..c143f49af2a2 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -3672,7 +3672,17 @@ Parent(JSContext *cx, uintN argc, jsval *vp) return JS_FALSE; } - *vp = OBJECT_TO_JSVAL(JS_GetParent(cx, JSVAL_TO_OBJECT(v))); + JSObject *parent = JS_GetParent(cx, JSVAL_TO_OBJECT(v)); + *rval = OBJECT_TO_JSVAL(parent); + + /* Outerize if necessary. Embrace the ugliness! */ + JSClass *clasp = JS_GetClass(cx, parent); + if (clasp->flags & JSCLASS_IS_EXTENDED) { + JSExtendedClass *xclasp = reinterpret_cast(clasp); + if (JSObjectOp outerize = xclasp->outerObject) + *rval = OBJECT_TO_JSVAL(outerize(cx, parent)); + } + return JS_TRUE; }