Bug 861530 - unwrap for _content. r=bholley

This commit is contained in:
Andrew McCreight 2013-04-29 17:50:25 -07:00
parent a9a7e40c63
commit aaf7fd6730
2 changed files with 20 additions and 15 deletions

View File

@ -5043,24 +5043,26 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// compatibility, this should spit out an message on the JS
// console.
JSObject *windowObj = win->GetGlobalJSObject();
JSObject* windowObj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
NS_ENSURE_TRUE(windowObj, NS_ERROR_DOM_SECURITY_ERR);
JSAutoCompartment ac(cx, windowObj);
JSAutoRequest ar(cx);
JSFunction *fun = ::JS_NewFunction(cx, ContentWindowGetter, 0, 0,
windowObj, "_content");
if (!fun) {
return NS_ERROR_OUT_OF_MEMORY;
JSObject *funObj;
{
JSAutoCompartment ac(cx, windowObj);
JSFunction *fun = ::JS_NewFunction(cx, ContentWindowGetter, 0, 0,
windowObj, "_content");
if (!fun) {
return NS_ERROR_OUT_OF_MEMORY;
}
funObj = ::JS_GetFunctionObject(fun);
}
JSObject *funObj = ::JS_GetFunctionObject(fun);
if (!::JS_DefinePropertyById(cx, windowObj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funObj),
JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_GETTER |
JSPROP_SHARED)) {
if (!JS_WrapObject(cx, &funObj) ||
!JS_DefinePropertyById(cx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funObj),
JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_GETTER |
JSPROP_SHARED)) {
return NS_ERROR_FAILURE;
}

View File

@ -28,6 +28,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=741267
function doTest() {
var win = $("t").contentWindow;
var sandbox = Components.utils.Sandbox(win, { sandboxPrototype: win });
is(sandbox._content, sandbox.content, "_content and content returned the same thing");
try {
var css = Components.utils.evalInSandbox("CSSStyleDeclaration", sandbox);
is(css.prototype, "[object CSSStyleDeclarationPrototype]", "'CSSStyleDeclaration.prototype' in a sandbox should return the CSSStyleDeclaration interface prototype object");