1283712 - Part 5: Support notes in Debugger.

This commit is contained in:
Gaming4JC 2019-06-09 14:38:36 -04:00 • committed by Roy Tam
commit f8f673d986
4 changed files with 85 additions and 0 deletions

View file

@ -921,6 +921,52 @@ js::ReportValueErrorFlags(JSContext* cx, unsigned flags, const unsigned errorNum
return ok; return ok;
} }
JSObject*
js::CreateErrorNotesArray(JSContext* cx, JSErrorReport* report)
{
RootedArrayObject notesArray(cx, NewDenseEmptyArray(cx));
if (!notesArray)
return nullptr;
if (!report->notes)
return notesArray;
for (auto&& note : *report->notes) {
RootedPlainObject noteObj(cx, NewBuiltinClassInstance<PlainObject>(cx));
if (!noteObj)
return nullptr;
RootedString messageStr(cx, note->newMessageString(cx));
if (!messageStr)
return nullptr;
RootedValue messageVal(cx, StringValue(messageStr));
if (!DefineProperty(cx, noteObj, cx->names().message, messageVal))
return nullptr;
RootedValue filenameVal(cx);
if (note->filename) {
RootedString filenameStr(cx, NewStringCopyZ<CanGC>(cx, note->filename));
if (!filenameStr)
return nullptr;
filenameVal = StringValue(filenameStr);
}
if (!DefineProperty(cx, noteObj, cx->names().fileName, filenameVal))
return nullptr;
RootedValue linenoVal(cx, Int32Value(note->lineno));
if (!DefineProperty(cx, noteObj, cx->names().lineNumber, linenoVal))
return nullptr;
RootedValue columnVal(cx, Int32Value(note->column));
if (!DefineProperty(cx, noteObj, cx->names().columnNumber, columnVal))
return nullptr;
if (!NewbornArrayPush(cx, notesArray, ObjectValue(*noteObj)))
return nullptr;
}
return notesArray;
}
const JSErrorFormatString js_ErrorFormatString[JSErr_Limit] = { const JSErrorFormatString js_ErrorFormatString[JSErr_Limit] = {
#define MSG_DEF(name, count, exception, format) \ #define MSG_DEF(name, count, exception, format) \
{ #name, format, count, exception } , { #name, format, count, exception } ,

View file

@ -685,6 +685,9 @@ ReportValueErrorFlags(JSContext* cx, unsigned flags, const unsigned errorNumber,
((void)ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \ ((void)ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
spindex, v, fallback, arg1, arg2)) spindex, v, fallback, arg1, arg2))
JSObject*
CreateErrorNotesArray(JSContext* cx, JSErrorReport* report);
} /* namespace js */ } /* namespace js */
extern const JSErrorFormatString js_ErrorFormatString[JSErr_Limit]; extern const JSErrorFormatString js_ErrorFormatString[JSErr_Limit];

View file

@ -8665,6 +8665,14 @@ DebuggerObject::errorMessageNameGetter(JSContext *cx, unsigned argc, Value* vp)
return true; return true;
} }
/* static */ bool
DebuggerObject::errorNotesGetter(JSContext *cx, unsigned argc, Value* vp)
{
THIS_DEBUGOBJECT(cx, argc, vp, "get errorNotes", args, object)
return DebuggerObject::getErrorNotes(cx, object, args.rval());
}
/* static */ bool /* static */ bool
DebuggerObject::errorLineNumberGetter(JSContext *cx, unsigned argc, Value* vp) DebuggerObject::errorLineNumberGetter(JSContext *cx, unsigned argc, Value* vp)
{ {
@ -9324,6 +9332,7 @@ const JSPropertySpec DebuggerObject::properties_[] = {
JS_PSG("global", DebuggerObject::globalGetter, 0), JS_PSG("global", DebuggerObject::globalGetter, 0),
JS_PSG("allocationSite", DebuggerObject::allocationSiteGetter, 0), JS_PSG("allocationSite", DebuggerObject::allocationSiteGetter, 0),
JS_PSG("errorMessageName", DebuggerObject::errorMessageNameGetter, 0), JS_PSG("errorMessageName", DebuggerObject::errorMessageNameGetter, 0),
JS_PSG("errorNotes", DebuggerObject::errorNotesGetter, 0),
JS_PSG("errorLineNumber", DebuggerObject::errorLineNumberGetter, 0), JS_PSG("errorLineNumber", DebuggerObject::errorLineNumberGetter, 0),
JS_PSG("errorColumnNumber", DebuggerObject::errorColumnNumberGetter, 0), JS_PSG("errorColumnNumber", DebuggerObject::errorColumnNumberGetter, 0),
JS_PSG("isProxy", DebuggerObject::isProxyGetter, 0), JS_PSG("isProxy", DebuggerObject::isProxyGetter, 0),
@ -9694,6 +9703,30 @@ DebuggerObject::getErrorMessageName(JSContext* cx, HandleDebuggerObject object,
return true; return true;
} }
/* static */ bool
DebuggerObject::getErrorNotes(JSContext* cx, HandleDebuggerObject object,
MutableHandleValue result)
{
RootedObject referent(cx, object->referent());
JSErrorReport* report;
if (!getErrorReport(cx, referent, report))
return false;
if (!report) {
result.setUndefined();
return true;
}
RootedObject errorNotesArray(cx, CreateErrorNotesArray(cx, report));
if (!errorNotesArray)
return false;
if (!cx->compartment()->wrap(cx, &errorNotesArray))
return false;
result.setObject(*errorNotesArray);
return true;
}
/* static */ bool /* static */ bool
DebuggerObject::getErrorLineNumber(JSContext* cx, HandleDebuggerObject object, DebuggerObject::getErrorLineNumber(JSContext* cx, HandleDebuggerObject object,
MutableHandleValue result) MutableHandleValue result)

View file

@ -1246,6 +1246,8 @@ class DebuggerObject : public NativeObject
MutableHandleObject result); MutableHandleObject result);
static MOZ_MUST_USE bool getErrorMessageName(JSContext* cx, HandleDebuggerObject object, static MOZ_MUST_USE bool getErrorMessageName(JSContext* cx, HandleDebuggerObject object,
MutableHandleString result); MutableHandleString result);
static MOZ_MUST_USE bool getErrorNotes(JSContext* cx, HandleDebuggerObject object,
MutableHandleValue result);
static MOZ_MUST_USE bool getErrorLineNumber(JSContext* cx, HandleDebuggerObject object, static MOZ_MUST_USE bool getErrorLineNumber(JSContext* cx, HandleDebuggerObject object,
MutableHandleValue result); MutableHandleValue result);
static MOZ_MUST_USE bool getErrorColumnNumber(JSContext* cx, HandleDebuggerObject object, static MOZ_MUST_USE bool getErrorColumnNumber(JSContext* cx, HandleDebuggerObject object,
@ -1371,6 +1373,7 @@ class DebuggerObject : public NativeObject
static MOZ_MUST_USE bool globalGetter(JSContext* cx, unsigned argc, Value* vp); static MOZ_MUST_USE bool globalGetter(JSContext* cx, unsigned argc, Value* vp);
static MOZ_MUST_USE bool allocationSiteGetter(JSContext* cx, unsigned argc, Value* vp); static MOZ_MUST_USE bool allocationSiteGetter(JSContext* cx, unsigned argc, Value* vp);
static MOZ_MUST_USE bool errorMessageNameGetter(JSContext* cx, unsigned argc, Value* vp); static MOZ_MUST_USE bool errorMessageNameGetter(JSContext* cx, unsigned argc, Value* vp);
static MOZ_MUST_USE bool errorNotesGetter(JSContext* cx, unsigned argc, Value* vp);
static MOZ_MUST_USE bool errorLineNumberGetter(JSContext* cx, unsigned argc, Value* vp); static MOZ_MUST_USE bool errorLineNumberGetter(JSContext* cx, unsigned argc, Value* vp);
static MOZ_MUST_USE bool errorColumnNumberGetter(JSContext* cx, unsigned argc, Value* vp); static MOZ_MUST_USE bool errorColumnNumberGetter(JSContext* cx, unsigned argc, Value* vp);
static MOZ_MUST_USE bool isProxyGetter(JSContext* cx, unsigned argc, Value* vp); static MOZ_MUST_USE bool isProxyGetter(JSContext* cx, unsigned argc, Value* vp);