diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testUncaughtSymbol.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testUncaughtSymbol.cpp')
-rw-r--r-- | js/src/jsapi-tests/testUncaughtSymbol.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testUncaughtSymbol.cpp b/js/src/jsapi-tests/testUncaughtSymbol.cpp new file mode 100644 index 000000000..a916b23d3 --- /dev/null +++ b/js/src/jsapi-tests/testUncaughtSymbol.cpp @@ -0,0 +1,53 @@ +/* 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 "jsapi-tests/tests.h" + +using JS::CreateError; +using JS::Rooted; +using JS::ObjectValue; +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::RootedValue exn(cx); + MOZ_RELEASE_ASSERT(JS_GetPendingException(cx, &exn)); + MOZ_RELEASE_ASSERT(exn.isSymbol()); + JS_ClearPendingException(cx); + + js::ErrorReport report(cx); + MOZ_RELEASE_ASSERT(report.init(cx, exn, js::ErrorReport::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) |