Bug 1417962 - Don't unbox proxies when reporting strict assignment error. r=jandem a=gchang
authorTom Schuster <evilpies@gmail.com>
Tue, 21 Nov 2017 21:03:39 +0100
changeset 444971 a93c70fa29f5b5206c2a58f335e00704ee619388
parent 444970 2ba1587bf12713250479dc310e7cede145575b32
child 444972 e7a7bffc4fdc62b2cc46e12bcdf34cfebb6fd0c7
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, gchang
bugs1417962
milestone58.0
Bug 1417962 - Don't unbox proxies when reporting strict assignment error. r=jandem a=gchang
js/src/jit-test/tests/basic/assign-primitive-proxy-class-error.js
js/src/jsapi.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/assign-primitive-proxy-class-error.js
@@ -0,0 +1,14 @@
+'use strict';
+
+load(libdir + 'asserts.js');
+
+let hook = {}
+let Base = function() {}
+Base.prototype = new Proxy(Base.prototype, hook);
+class Derived extends Base {
+    testPrimitiveReceiver() {
+        super.foo = "Derived";
+    }
+}
+assertTypeErrorMessage(() => Derived.prototype.testPrimitiveReceiver.call(null),
+                       `can't assign to property "foo" on ({}): not an object`)
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -174,19 +174,21 @@ JS::ObjectOpResult::reportStrictErrorOrW
             return false;
 
         JSAutoByteString propName;
         if (!propName.encodeUtf8(cx, str))
             return false;
 
         if (code_ == JSMSG_SET_NON_OBJECT_RECEIVER) {
             // We know that the original receiver was a primitive, so unbox it.
-            RootedValue val(cx);
-            if (!Unbox(cx, obj, &val))
-                return false;
+            RootedValue val(cx, ObjectValue(*obj));
+            if (!obj->is<ProxyObject>()) {
+                if (!Unbox(cx, obj, &val))
+                    return false;
+            }
             return ReportValueErrorFlags(cx, flags, code_, JSDVG_IGNORE_STACK, val,
                                          nullptr, propName.ptr(), nullptr);
         }
 
         if (ErrorTakesObjectArgument(code_)) {
             return JS_ReportErrorFlagsAndNumberUTF8(cx, flags, GetErrorMessage, nullptr, code_,
                                                     obj->getClass()->name, propName.ptr());
         }