Bug 1139834 - TraceLogger: refactor to add fail function, r=bbouvier

This commit is contained in:
Hannes Verschore 2015-03-09 15:25:55 +01:00
Родитель 1df9e925e2
Коммит 1a22e29af0
2 изменённых файлов: 20 добавлений и 19 удалений

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

@ -208,27 +208,29 @@ TraceLoggerThread::enable()
return true;
}
bool
TraceLoggerThread::fail(JSContext *cx, const char *error)
{
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TRACELOGGER_ENABLE_FAIL, error);
failed = true;
enabled = 0;
return false;
}
bool
TraceLoggerThread::enable(JSContext *cx)
{
if (!enable()) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TRACELOGGER_ENABLE_FAIL,
"internal error");
return false;
}
if (!enable())
return fail(cx, "internal error");
if (enabled == 1) {
// Get the top Activation to log the top script/pc (No inlined frames).
ActivationIterator iter(cx->runtime());
Activation *act = iter.activation();
if (!act) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TRACELOGGER_ENABLE_FAIL,
"internal error");
failed = true;
enabled = 0;
return false;
}
if (!act)
return fail(cx, "internal error");
JSScript *script = nullptr;
int32_t engine = 0;
@ -255,13 +257,8 @@ TraceLoggerThread::enable(JSContext *cx)
script = fp->script();
engine = TraceLogger_Interpreter;
if (script->compartment() != cx->compartment()) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TRACELOGGER_ENABLE_FAIL,
"compartment mismatch");
failed = true;
enabled = 0;
return false;
}
if (script->compartment() != cx->compartment())
return fail(cx, "compartment mismatch");
}
TraceLoggerEvent event(this, TraceLogger_Scripts, script);

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

@ -195,6 +195,10 @@ class TraceLoggerThread
bool enable(JSContext *cx);
bool disable();
private:
bool fail(JSContext *cx, const char *error);
public:
// Given the previous iteration and lastEntryId, return an array of events
// (there could be lost events). At the same time update the iteration and
// lastEntry and gives back how many events there are.