Bug 893858 - More testing for CPOWs and two small bug fixes. r=dvander

This commit is contained in:
Tom Schuster 2013-07-17 09:27:49 -04:00
parent 46fe724e6d
commit 78d54d5af2
4 changed files with 48 additions and 9 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) {
@ -57,7 +90,7 @@
run_tests("inprocess");
return;
}
finish();
}

View File

@ -434,7 +434,7 @@ JavaScriptChild::AnswerIsExtensible(const ObjectId &objId, ReturnStatus *rs, boo
return fail(cx, rs);
*result = !!extensible;
return true;
return ok(rs);
}
bool

View File

@ -7206,12 +7206,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);
}