Bug 893858 - More testing for CPOWs and fix some small bugs. r=dvander

This commit is contained in:
Tom Schuster 2013-07-17 09:27:49 -04:00
parent c3a3b8fa79
commit 7f21dbc657
4 changed files with 57 additions and 11 deletions

View File

@ -27,8 +27,15 @@ function make_object()
o.b = true;
o.s = "hello";
o.x = { i: 10 };
o.f = function () { return 99; }
o.f = function () { return 99; };
// Doing anything with this Proxy will throw.
var throwing = new Proxy({}, new Proxy({}, {
get: function (trap) { throw trap; }
}));
return { "data": o,
"throwing": throwing,
"document": content.document
};
}

View File

@ -37,6 +37,39 @@
ok(data.b === false, "boolean property");
ok(data.s === "bye", "string property");
ok(data.x === null, "nested property");
let throwing = message.objects.throwing;
// Based on the table on:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
let tests = [
() => Object.getOwnPropertyDescriptor(throwing, 'test'),
() => Object.getOwnPropertyNames(throwing),
() => Object.defineProperty(throwing, 'test', {value: 1}),
() => delete throwing.test,
() => "test" in throwing,
() => Object.prototype.hasOwnProperty.call(throwing, 'test'),
() => throwing.test,
() => { throwing.test = 1 },
// () => { for (let prop in throwing) {} }, Bug 783829
() => { for (let prop of throwing) {} },
() => Object.keys(throwing),
() => Function.prototype.call.call(throwing),
() => new throwing,
() => Object.preventExtensions(throwing),
() => Object.freeze(throwing),
() => Object.seal(throwing),
]
for (let test of tests) {
let threw = false;
try {
test()
} catch (e) {
threw = true;
}
ok(threw, "proxy operation threw exception");
}
}
function recvAsyncMessage(message) {

View File

@ -271,6 +271,8 @@ JavaScriptChild::AnswerDelete(const ObjectId &objId, const nsString &id, ReturnS
AutoSafeJSContext cx;
JSAutoRequest request(cx);
*success = false;
RootedObject obj(cx, findObject(objId));
if (!obj)
return false;
@ -299,6 +301,8 @@ JavaScriptChild::AnswerHas(const ObjectId &objId, const nsString &id, ReturnStat
AutoSafeJSContext cx;
JSAutoRequest request(cx);
*bp = false;
RootedObject obj(cx, findObject(objId));
if (!obj)
return false;
@ -323,6 +327,8 @@ JavaScriptChild::AnswerHasOwn(const ObjectId &objId, const nsString &id, ReturnS
AutoSafeJSContext cx;
JSAutoRequest request(cx);
*bp = false;
RootedObject obj(cx, findObject(objId));
if (!obj)
return false;
@ -434,7 +440,7 @@ JavaScriptChild::AnswerIsExtensible(const ObjectId &objId, ReturnStatus *rs, boo
return fail(cx, rs);
*result = !!extensible;
return true;
return ok(rs);
}
bool
@ -548,7 +554,6 @@ JavaScriptChild::AnswerObjectClassIs(const ObjectId &objId, const uint32_t &clas
JSAutoCompartment comp(cx, obj);
*result = js_ObjectClassIs(cx, obj, (js::ESClassValue)classValue);
return true;
}
@ -588,7 +593,7 @@ JavaScriptChild::AnswerGetPropertyNames(const ObjectId &objId, const uint32_t &f
for (size_t i = 0; i < props.length(); i++) {
nsString name;
if (!convertIdToGeckoString(cx, props.handleAt(i), &name))
return false;
return fail(cx, rs);
names->AppendElement(name);
}
@ -603,6 +608,8 @@ JavaScriptChild::AnswerInstanceOf(const ObjectId &objId, const JSIID &iid, Retur
AutoSafeJSContext cx;
JSAutoRequest request(cx);
*instanceof = false;
RootedObject obj(cx, findObject(objId));
if (!obj)
return false;

View File

@ -7212,12 +7212,11 @@ JS_GetScriptedGlobal(JSContext *cx)
JS_PUBLIC_API(JSBool)
JS_PreventExtensions(JSContext *cx, JS::HandleObject obj)
{
JSBool extensible;
if (!JS_IsExtensible(cx, obj, &extensible))
return JS_TRUE;
if (extensible)
return JS_TRUE;
bool extensible;
if (!JSObject::isExtensible(cx, obj, &extensible))
return false;
if (!extensible)
return true;
return JSObject::preventExtensions(cx, obj);
}