diff --git a/content/base/test/chrome/cpows_child.js b/content/base/test/chrome/cpows_child.js index edfbf5f311d4..a53c7c1940d5 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 52461b42bcf2..7d9592a8f96f 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 9ee02c5eebaa..52bcfc904726 100644 --- a/js/ipc/JavaScriptChild.cpp +++ b/js/ipc/JavaScriptChild.cpp @@ -434,7 +434,7 @@ JavaScriptChild::AnswerIsExtensible(const ObjectId &objId, ReturnStatus *rs, boo return fail(cx, rs); *result = !!extensible; - return true; + return ok(rs); } bool diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 57711331d614..76dc052a843e 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -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); }