From 6d7cc2b0abd26d32e35197ec923beb9da01d6816 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 13 Jul 2019 23:12:12 -0400 Subject: [PATCH] 1359622 - Fix assert for calling Function.toString on class constructors when the compartment has had source discarded. --- js/src/jit-test/tests/class/bug1359622.js | 4 ++++ js/src/jsfun.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 js/src/jit-test/tests/class/bug1359622.js diff --git a/js/src/jit-test/tests/class/bug1359622.js b/js/src/jit-test/tests/class/bug1359622.js new file mode 100644 index 0000000000..b4a0df7490 --- /dev/null +++ b/js/src/jit-test/tests/class/bug1359622.js @@ -0,0 +1,4 @@ +setDiscardSource(true) +evaluate(` + unescape(class get { static staticMethod() {} }); +`); diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 0886923fda..06dc40162a 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -1022,8 +1022,10 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) 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 "))