Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testUncaughtSymbol.cpp
blobce026a48c6283d009704e013e6af24187d3e57d0
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"
8 using JS::CreateError;
9 using JS::ObjectValue;
10 using JS::Rooted;
11 using JS::Value;
13 enum SymbolExceptionType {
14 NONE,
15 SYMBOL_ITERATOR,
16 SYMBOL_FOO,
17 SYMBOL_EMPTY,
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);
30 return true;
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);
39 MOZ_RELEASE_ASSERT(
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) {
48 return SYMBOL_FOO;
50 if (strcmp(report.toStringResult().c_str(), "uncaught exception: Symbol()") ==
51 0) {
52 return SYMBOL_EMPTY;
54 MOZ_CRASH("Unexpected symbol");
57 END_TEST(testUncaughtSymbol)