1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "js/Exception.h"
6 #include "jsapi-tests/tests.h"
13 enum SymbolExceptionType
{
20 BEGIN_TEST(testUncaughtSymbol
) {
21 CHECK(!execDontReport("throw Symbol.iterator;", __FILE__
, __LINE__
));
22 CHECK(GetSymbolExceptionType(cx
) == SYMBOL_ITERATOR
);
24 CHECK(!execDontReport("throw Symbol('foo');", __FILE__
, __LINE__
));
25 CHECK(GetSymbolExceptionType(cx
) == SYMBOL_FOO
);
27 CHECK(!execDontReport("throw Symbol();", __FILE__
, __LINE__
));
28 CHECK(GetSymbolExceptionType(cx
) == SYMBOL_EMPTY
);
33 static SymbolExceptionType
GetSymbolExceptionType(JSContext
* cx
) {
34 JS::ExceptionStack
exnStack(cx
);
35 MOZ_RELEASE_ASSERT(JS::StealPendingExceptionStack(cx
, &exnStack
));
36 MOZ_RELEASE_ASSERT(exnStack
.exception().isSymbol());
38 JS::ErrorReportBuilder
report(cx
);
40 report
.init(cx
, exnStack
, JS::ErrorReportBuilder::WithSideEffects
));
42 if (strcmp(report
.toStringResult().c_str(),
43 "uncaught exception: Symbol(Symbol.iterator)") == 0) {
44 return SYMBOL_ITERATOR
;
46 if (strcmp(report
.toStringResult().c_str(),
47 "uncaught exception: Symbol(foo)") == 0) {
50 if (strcmp(report
.toStringResult().c_str(), "uncaught exception: Symbol()") ==
54 MOZ_CRASH("Unexpected symbol");
57 END_TEST(testUncaughtSymbol
)