summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testUncaughtSymbol.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jsapi-tests/testUncaughtSymbol.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jsapi-tests/testUncaughtSymbol.cpp')
-rw-r--r--js/src/jsapi-tests/testUncaughtSymbol.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testUncaughtSymbol.cpp b/js/src/jsapi-tests/testUncaughtSymbol.cpp
new file mode 100644
index 0000000000..ce026a48c6
--- /dev/null
+++ b/js/src/jsapi-tests/testUncaughtSymbol.cpp
@@ -0,0 +1,57 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "js/Exception.h"
+#include "jsapi-tests/tests.h"
+
+using JS::CreateError;
+using JS::ObjectValue;
+using JS::Rooted;
+using JS::Value;
+
+enum SymbolExceptionType {
+ NONE,
+ SYMBOL_ITERATOR,
+ SYMBOL_FOO,
+ SYMBOL_EMPTY,
+};
+
+BEGIN_TEST(testUncaughtSymbol) {
+ CHECK(!execDontReport("throw Symbol.iterator;", __FILE__, __LINE__));
+ CHECK(GetSymbolExceptionType(cx) == SYMBOL_ITERATOR);
+
+ CHECK(!execDontReport("throw Symbol('foo');", __FILE__, __LINE__));
+ CHECK(GetSymbolExceptionType(cx) == SYMBOL_FOO);
+
+ CHECK(!execDontReport("throw Symbol();", __FILE__, __LINE__));
+ CHECK(GetSymbolExceptionType(cx) == SYMBOL_EMPTY);
+
+ return true;
+}
+
+static SymbolExceptionType GetSymbolExceptionType(JSContext* cx) {
+ JS::ExceptionStack exnStack(cx);
+ MOZ_RELEASE_ASSERT(JS::StealPendingExceptionStack(cx, &exnStack));
+ MOZ_RELEASE_ASSERT(exnStack.exception().isSymbol());
+
+ JS::ErrorReportBuilder report(cx);
+ MOZ_RELEASE_ASSERT(
+ report.init(cx, exnStack, JS::ErrorReportBuilder::WithSideEffects));
+
+ if (strcmp(report.toStringResult().c_str(),
+ "uncaught exception: Symbol(Symbol.iterator)") == 0) {
+ return SYMBOL_ITERATOR;
+ }
+ if (strcmp(report.toStringResult().c_str(),
+ "uncaught exception: Symbol(foo)") == 0) {
+ return SYMBOL_FOO;
+ }
+ if (strcmp(report.toStringResult().c_str(), "uncaught exception: Symbol()") ==
+ 0) {
+ return SYMBOL_EMPTY;
+ }
+ MOZ_CRASH("Unexpected symbol");
+}
+
+END_TEST(testUncaughtSymbol)