Bug 1650776 - Introduce Debugger.Object.isError to check for error objects. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D82454
This commit is contained in:
Tom Schuster 2020-07-06 21:04:33 +00:00
Родитель 7a7a796fc2
Коммит 7ba7c125fe
4 изменённых файлов: 45 добавлений и 1 удалений

Просмотреть файл

@ -171,6 +171,7 @@ struct MOZ_STACK_CLASS DebuggerObject::CallData {
bool boundThisGetter();
bool boundArgumentsGetter();
bool allocationSiteGetter();
bool isErrorGetter();
bool errorMessageNameGetter();
bool errorNotesGetter();
bool errorLineNumberGetter();
@ -517,6 +518,11 @@ bool DebuggerObject::CallData::errorMessageNameGetter() {
return true;
}
bool DebuggerObject::CallData::isErrorGetter() {
args.rval().setBoolean(object->isError());
return true;
}
bool DebuggerObject::CallData::errorNotesGetter() {
return DebuggerObject::getErrorNotes(cx, object, args.rval());
}
@ -1538,6 +1544,7 @@ const JSPropertySpec DebuggerObject::properties_[] = {
JS_DEBUG_PSG("boundThis", boundThisGetter),
JS_DEBUG_PSG("boundArguments", boundArgumentsGetter),
JS_DEBUG_PSG("allocationSite", allocationSiteGetter),
JS_DEBUG_PSG("isError", isErrorGetter),
JS_DEBUG_PSG("errorMessageName", errorMessageNameGetter),
JS_DEBUG_PSG("errorNotes", errorNotesGetter),
JS_DEBUG_PSG("errorLineNumber", errorLineNumberGetter),
@ -1682,7 +1689,7 @@ bool DebuggerObject::isPromise() const {
JSObject* referent = this->referent();
if (IsCrossCompartmentWrapper(referent)) {
/* We only care about promises, so CheckedUnwrapStatic is OK. */
// We only care about promises, so CheckedUnwrapStatic is OK.
referent = CheckedUnwrapStatic(referent);
if (!referent) {
return false;
@ -1692,6 +1699,20 @@ bool DebuggerObject::isPromise() const {
return referent->is<PromiseObject>();
}
bool DebuggerObject::isError() const {
JSObject* referent = this->referent();
if (IsCrossCompartmentWrapper(referent)) {
// We only check for error classes, so CheckedUnwrapStatic is OK.
referent = CheckedUnwrapStatic(referent);
if (!referent) {
return false;
}
}
return referent->is<ErrorObject>();
}
/* static */
bool DebuggerObject::getClassName(JSContext* cx, HandleDebuggerObject object,
MutableHandleString result) {

Просмотреть файл

@ -169,6 +169,7 @@ class DebuggerObject : public NativeObject {
bool isGlobal() const;
bool isScriptedProxy() const;
bool isPromise() const;
bool isError() const;
JSAtom* name(JSContext* cx) const;
JSAtom* displayName(JSContext* cx) const;
JS::PromiseState promiseState() const;

Просмотреть файл

@ -154,6 +154,9 @@ If the referent is a function that is debuggee code, a
environment enclosing the function when it was created. If the referent
is a function proxy or not debuggee code, this is `undefined`.
### `isError`
`true` if the referent is any potentially wrapped Error; `false` otherwise.
### `errorMessageName`
If the referent is an error created with an engine internal message template
this is a string which is the name of the template; `undefined` otherwise.

Просмотреть файл

@ -0,0 +1,19 @@
let g = newGlobal({newCompartment: true});
let dbg = new Debugger();
let gw = dbg.addDebuggee(g);
g.error1 = new Error()
g.error2 = new g.Error()
g.error3 = new g.TypeError();
let error1DO = gw.getOwnPropertyDescriptor('error1').value;
let error2DO = gw.getOwnPropertyDescriptor('error2').value;
let error3DO = gw.getOwnPropertyDescriptor('error3').value;
assertEq(error1DO.isError, true);
assertEq(error2DO.isError, true);
assertEq(error3DO.isError, true);
g.nonError = new Array();
let nonErrorDO = gw.getOwnPropertyDescriptor('nonError').value;
assertEq(nonErrorDO.isError, false);