diff options
Diffstat (limited to 'js/public/Class.h')
-rw-r--r-- | js/public/Class.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/js/public/Class.h b/js/public/Class.h index 094e4a7ed7..6f1960a308 100644 --- a/js/public/Class.h +++ b/js/public/Class.h @@ -131,16 +131,24 @@ class ObjectOpResult Uninitialized = uintptr_t(-1) }; + static const uintptr_t SoftFailBit = uintptr_t(1) << (sizeof(uintptr_t) * 8 - 1); + ObjectOpResult() : code_(Uninitialized) {} - /* Return true if succeed() was called. */ + /* Return true if succeed() or failSoft() was called. */ bool ok() const { MOZ_ASSERT(code_ != Uninitialized); - return code_ == OkCode; + return code_ == OkCode || (code_ & SoftFailBit); } explicit operator bool() const { return ok(); } + /* Return true if succeed() was called. */ + bool confirmOk() const { + MOZ_ASSERT(code_ != Uninitialized); + return code_ == OkCode; + } + /* Set this ObjectOpResult to true and return true. */ bool succeed() { code_ = OkCode; @@ -160,10 +168,26 @@ class ObjectOpResult */ bool fail(uint32_t msg) { MOZ_ASSERT(msg != OkCode); + MOZ_ASSERT((msg & SoftFailBit) == 0); code_ = msg; return true; } + /* + * DEPRECATED: This is a non-standard compatibility hack. + * + * Set this ObjectOpResult to true, but remembers an error code. + * This is used for situations where we really want to fail, + * but can't for legacy reasons. + * + * Always returns true, as a convenience. + */ + bool failSoft(uint32_t msg) { + // The msg code is currently never extracted again. + code_ = msg | SoftFailBit; + return true; + } + JS_PUBLIC_API(bool) failCantRedefineProp(); JS_PUBLIC_API(bool) failReadOnly(); JS_PUBLIC_API(bool) failGetterOnly(); |