Bug 1359622 - Fix assert for calling Function.toString on class constructors when the compartment has had source discarded. (r=Yoric)
☠☠ backed out by 11f3f002c7f4 ☠ ☠
authorShu-yu Guo <shu@rfrn.org>
Tue, 09 May 2017 14:45:26 -0700
changeset 357442 3258871b49026edd782b308ad82ecfd48cb64908
parent 357441 2713f06c0631f0e8696bdbc37a013f68c2ff29a3
child 357443 8756a6262190bdd3945a873f80c6aadd41da3aad
push id31792
push usercbook@mozilla.com
push dateWed, 10 May 2017 13:07:59 +0000
treeherdermozilla-central@ebbcdaa5b580 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1359622
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1359622 - Fix assert for calling Function.toString on class constructors when the compartment has had source discarded. (r=Yoric)
js/src/jit-test/tests/class/bug1359622.js
js/src/jsfun.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/class/bug1359622.js
@@ -0,0 +1,4 @@
+setDiscardSource(true)
+evaluate(`
+  unescape(class get { static staticMethod() {} });
+`);
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -1085,18 +1085,20 @@ js::FunctionToString(JSContext* cx, Hand
         if (!AppendPrelude() ||
             !out.append("() {\n    ") ||
             !out.append("[sourceless code]") ||
             !out.append("\n}"))
         {
             return nullptr;
         }
     } else {
-        // Default class constructors should always haveSource.
-        MOZ_ASSERT(!fun->infallibleIsDefaultClassConstructor(cx));
+        // Default class constructors should always haveSource unless source
+        // has been discarded for the whole compartment.
+        MOZ_ASSERT(!fun->infallibleIsDefaultClassConstructor(cx) ||
+                   fun->compartment()->behaviors().discardSource());
 
         if (!AppendPrelude() ||
             !out.append("() {\n    "))
             return nullptr;
 
         if (!out.append("[native code]"))
             return nullptr;