mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 14:25:52 +00:00
Bug 845862 - Transitively apply waivers for accessor descriptors. r=mrbkap
This commit is contained in:
parent
a0bbe1ad3e
commit
38f05e866f
13
js/xpconnect/tests/unit/test_bug845862.js
Normal file
13
js/xpconnect/tests/unit/test_bug845862.js
Normal 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");
|
||||
}
|
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user