summaryrefslogtreecommitdiff
path: root/js/src/jscntxt.cpp
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2023-06-17 16:05:46 +0200
committerMartok <martok@martoks-place.de>2023-06-29 22:27:28 +0200
commitbed754c21c712013b425417a9be3b18125695252 (patch)
treebd71d33ac3448298b5f7ec7c840c7981292cfe02 /js/src/jscntxt.cpp
parent85efbc0c1e4d62098b385ffa141add07b811429d (diff)
downloaduxp-bed754c21c712013b425417a9be3b18125695252.tar.gz
Issue #2259 - Add mozilla::Result<V, E> and JS::Result<> for fallible return values
Based-on: m-c 1283562, 1277368/1, 1324828
Diffstat (limited to 'js/src/jscntxt.cpp')
-rw-r--r--js/src/jscntxt.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp
index dc14b83fd9..66a548d6e8 100644
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -240,6 +240,13 @@ js::ReportOutOfMemory(ExclusiveContext* cxArg)
cx->setPendingException(oomMessage, nullptr);
}
+mozilla::GenericErrorResult<OOM&>
+js::ReportOutOfMemoryResult(ExclusiveContext* cx)
+{
+ ReportOutOfMemory(cx);
+ return cx->alreadyReportedOOM();
+}
+
void
js::ReportOverRecursed(JSContext* maybecx, unsigned errorNumber)
{
@@ -1004,6 +1011,34 @@ ExclusiveContext::recoverFromOutOfMemory()
task->outOfMemory = false;
}
+JS::Error ExclusiveContext::reportedError;
+JS::OOM ExclusiveContext::reportedOOM;
+
+mozilla::GenericErrorResult<OOM&>
+ExclusiveContext::alreadyReportedOOM()
+{
+#ifdef DEBUG
+ if (JSContext* maybecx = maybeJSContext()) {
+ MOZ_ASSERT(maybecx->isThrowingOutOfMemory());
+ } else {
+ // Keep in sync with addPendingOutOfMemory.
+ if (ParseTask* task = helperThread()->parseTask())
+ MOZ_ASSERT(task->outOfMemory);
+ }
+#endif
+ return mozilla::MakeGenericErrorResult(reportedOOM);
+}
+
+mozilla::GenericErrorResult<JS::Error&>
+ExclusiveContext::alreadyReportedError()
+{
+#ifdef DEBUG
+ if (JSContext* maybecx = maybeJSContext())
+ MOZ_ASSERT(maybecx->isExceptionPending());
+#endif
+ return mozilla::MakeGenericErrorResult(reportedError);
+}
+
JSContext::JSContext(JSRuntime* parentRuntime)
: ExclusiveContext(this, &this->JSRuntime::mainThread, Context_JS, JS::ContextOptions()),
JSRuntime(parentRuntime),