From 7f21dbc657d3afeca9df02636b66c2583c57b12d Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Wed, 17 Jul 2013 09:27:49 -0400 Subject: [PATCH] Bug 893858 - More testing for CPOWs and fix some small bugs. r=dvander --- content/base/test/chrome/cpows_child.js | 9 +++++- content/base/test/chrome/cpows_parent.xul | 35 ++++++++++++++++++++++- js/ipc/JavaScriptChild.cpp | 13 +++++++-- js/src/jsapi.cpp | 11 ++++--- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/content/base/test/chrome/cpows_child.js b/content/base/test/chrome/cpows_child.js index edfbf5f311d..a53c7c1940d 100644 --- a/content/base/test/chrome/cpows_child.js +++ b/content/base/test/chrome/cpows_child.js @@ -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 }; } diff --git a/content/base/test/chrome/cpows_parent.xul b/content/base/test/chrome/cpows_parent.xul index 52461b42bcf..7d9592a8f96 100644 --- a/content/base/test/chrome/cpows_parent.xul +++ b/content/base/test/chrome/cpows_parent.xul @@ -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(); } diff --git a/js/ipc/JavaScriptChild.cpp b/js/ipc/JavaScriptChild.cpp index 9ee02c5eeba..f7906670ef8 100644 --- a/js/ipc/JavaScriptChild.cpp +++ b/js/ipc/JavaScriptChild.cpp @@ -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; diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index a0c0e7d750a..6cb66a8f106 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -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); }