Bug 845862 - Transitively apply waivers for accessor descriptors. r=mrbkap

This commit is contained in:
Bobby Holley 2013-04-03 11:41:22 -07:00
parent 345295f71d
commit 1f82d91ffb
3 changed files with 35 additions and 2 deletions

View File

@ -0,0 +1,13 @@
const Cu = Components.utils;
function run_test() {
// We rely on the crazy "wantXrays:false also causes values return from the
// sandbox to be waived" behavior, because it's the simplest way to get
// waivers out of the sandbox (which has no native objects). :-(
var sb = new Cu.Sandbox('http://www.example.com', {wantXrays: false});
Cu.evalInSandbox("this.foo = {}; Object.defineProperty(foo, 'bar', {get: function() {return {};}});", sb);
do_check_true(sb.foo != XPCNativeWrapper(sb.foo), "sb.foo is waived");
var desc = Object.getOwnPropertyDescriptor(sb.foo, 'bar');
var b = desc.get();
do_check_true(b != XPCNativeWrapper(b), "results from accessor descriptors are waived");
}

View File

@ -17,6 +17,7 @@ tail =
[test_bug809652.js]
[test_bug813901.js]
[test_bug845201.js]
[test_bug845862.js]
[test_bug849730.js]
[test_bug851895.js]
[test_bug854558.js]

View File

@ -15,6 +15,25 @@
namespace xpc {
static bool
WaiveAccessors(JSContext *cx, js::PropertyDescriptor *desc)
{
if ((desc->attrs & JSPROP_GETTER) && desc->getter) {
JS::Value v = JS::ObjectValue(*JS_FUNC_TO_DATA_PTR(JSObject *, desc->getter));
if (!WrapperFactory::WaiveXrayAndWrap(cx, &v))
return false;
desc->getter = js::CastAsJSPropertyOp(&v.toObject());
}
if ((desc->attrs & JSPROP_SETTER) && desc->setter) {
JS::Value v = JS::ObjectValue(*JS_FUNC_TO_DATA_PTR(JSObject *, desc->setter));
if (!WrapperFactory::WaiveXrayAndWrap(cx, &v))
return false;
desc->setter = js::CastAsJSStrictPropertyOp(&v.toObject());
}
return true;
}
WaiveXrayWrapper::WaiveXrayWrapper(unsigned flags) : js::CrossCompartmentWrapper(flags)
{
}
@ -29,7 +48,7 @@ WaiveXrayWrapper::getPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*>wrap
unsigned flags)
{
return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, desc, flags) &&
WrapperFactory::WaiveXrayAndWrap(cx, &desc->value);
WrapperFactory::WaiveXrayAndWrap(cx, &desc->value) && WaiveAccessors(cx, desc);
}
bool
@ -38,7 +57,7 @@ WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*>
unsigned flags)
{
return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc, flags) &&
WrapperFactory::WaiveXrayAndWrap(cx, &desc->value);
WrapperFactory::WaiveXrayAndWrap(cx, &desc->value) && WaiveAccessors(cx, desc);
}
bool