Struct js::jsapi::ObjectOpResult
[−]
[src]
#[repr(C)]pub struct ObjectOpResult { pub code_: usize, }
Per ES6, the [[DefineOwnProperty]] internal method has three different possible outcomes:
It can throw an exception (which we indicate by returning false).
It can return true, indicating unvarnished success.
It can return false, indicating "strict failure". The property could not be defined. It's an error, but no exception was thrown.
It's not just [[DefineOwnProperty]]: all the mutating internal methods have the same three outcomes. (The other affected internal methods are [[Set]], [[Delete]], [[SetPrototypeOf]], and [[PreventExtensions]].)
If you think this design is awful, you're not alone. But as it's the standard, we must represent these boolean "success" values somehow. ObjectOpSuccess is the class for this. It's like a bool, but when it's false it also stores an error code.
Typical usage:
ObjectOpResult result; if (!DefineProperty(cx, obj, id, ..., result)) return false; if (!result) return result.reportError(cx, obj, id);
Users don't have to call result.report()
; another possible ending is:
argv.rval().setBoolean(bool(result)); return true;
Fields
code_: usize
code_ is either one of the special codes OkCode or Uninitialized, or an error code. For now the error codes are private to the JS engine; they're defined in js/src/js.msg.
code_ is uintptr_t (rather than uint32_t) for the convenience of the JITs, which would otherwise have to deal with either padding or stack alignment on 64-bit platforms.
Methods
impl ObjectOpResult
[src]
pub unsafe fn failCantRedefineProp(&mut self) -> bool
[src]
pub unsafe fn failReadOnly(&mut self) -> bool
[src]
pub unsafe fn failGetterOnly(&mut self) -> bool
[src]
pub unsafe fn failCantDelete(&mut self) -> bool
[src]
pub unsafe fn failCantSetInterposed(&mut self) -> bool
[src]
pub unsafe fn failCantDefineWindowElement(&mut self) -> bool
[src]
pub unsafe fn failCantDeleteWindowElement(&mut self) -> bool
[src]
pub unsafe fn failCantDeleteWindowNamedProperty(&mut self) -> bool
[src]
pub unsafe fn failCantPreventExtensions(&mut self) -> bool
[src]
pub unsafe fn failCantSetProto(&mut self) -> bool
[src]
pub unsafe fn failNoNamedSetter(&mut self) -> bool
[src]
pub unsafe fn failNoIndexedSetter(&mut self) -> bool
[src]
pub unsafe fn reportStrictErrorOrWarning(
&mut self,
cx: *mut JSContext,
obj: HandleObject,
id: HandleId,
strict: bool
) -> bool
[src]
&mut self,
cx: *mut JSContext,
obj: HandleObject,
id: HandleId,
strict: bool
) -> bool
pub unsafe fn reportStrictErrorOrWarning1(
&mut self,
cx: *mut JSContext,
obj: HandleObject,
strict: bool
) -> bool
[src]
&mut self,
cx: *mut JSContext,
obj: HandleObject,
strict: bool
) -> bool