diff options
Diffstat (limited to 'js/src/jscntxt.h')
-rw-r--r-- | js/src/jscntxt.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 93106d681e..c4ef783d3a 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -12,6 +12,7 @@ #include "js/CharacterEncoding.h" #include "js/GCVector.h" +#include "js/Result.h" #include "js/Utility.h" #include "js/Vector.h" #include "vm/Caches.h" @@ -314,6 +315,30 @@ class ExclusiveContext : public ContextFriendFields, bool addPendingCompileError(frontend::CompileError** err); void addPendingOverRecursed(); void addPendingOutOfMemory(); + + private: + static JS::Error reportedError; + static JS::OOM reportedOOM; + + public: + inline JS::Result<> boolToResult(bool ok); + + /** + * Intentionally awkward signpost method that is stationed on the + * boundary between Result-using and non-Result-using code. + */ + template <typename V, typename E> + bool resultToBool(JS::Result<V, E> result) { + return result.isOk(); + } + + template <typename V, typename E> + V* resultToPtr(JS::Result<V*, E> result) { + return result.isOk() ? result.unwrap() : nullptr; + } + + mozilla::GenericErrorResult<JS::OOM&> alreadyReportedOOM(); + mozilla::GenericErrorResult<JS::Error&> alreadyReportedError(); }; void ReportOverRecursed(JSContext* cx, unsigned errorNumber); @@ -340,6 +365,7 @@ struct JSContext : public js::ExclusiveContext, using ExclusiveContext::permanentAtoms; using ExclusiveContext::pod_calloc; using ExclusiveContext::pod_malloc; + using ExclusiveContext::pod_realloc; using ExclusiveContext::staticStrings; using ExclusiveContext::updateMallocCounter; using ExclusiveContext::wellKnownSymbols; @@ -490,7 +516,7 @@ struct JSContext : public js::ExclusiveContext, } public: - bool isExceptionPending() { + bool isExceptionPending() const { return throwing; } @@ -540,6 +566,17 @@ struct JSContext : public js::ExclusiveContext, namespace js { +inline JS::Result<> +ExclusiveContext::boolToResult(bool ok) +{ + if (MOZ_LIKELY(ok)) { + MOZ_ASSERT_IF(isJSContext(), !asJSContext()->isExceptionPending()); + MOZ_ASSERT_IF(isJSContext(), !asJSContext()->isPropagatingForcedReturn()); + return JS::Ok(); + } + return JS::Result<>(reportedError); +} + struct MOZ_RAII AutoResolving { public: enum Kind { |