Bug 1465350 - Use UniquePtr instead of ScopedJSFreePtr for JSErrorReporter. r=Waldo

This commit is contained in:
André Bargull 2018-06-13 09:47:21 -07:00
Родитель 77fbd62447
Коммит e11bf8d4ef
5 изменённых файлов: 36 добавлений и 31 удалений

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

@ -7093,7 +7093,7 @@ JSErrorNotes::copy(JSContext* cx)
}
for (auto&& note : *this) {
js::UniquePtr<JSErrorNotes::Note> copied(CopyErrorNote(cx, note.get()));
UniquePtr<JSErrorNotes::Note> copied = CopyErrorNote(cx, note.get());
if (!copied)
return nullptr;

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

@ -14,6 +14,7 @@
#include "mozilla/Sprintf.h"
#include <string.h>
#include <utility>
#include "jsapi.h"
#include "jsnum.h"
@ -23,6 +24,7 @@
#include "gc/FreeOp.h"
#include "gc/Marking.h"
#include "js/CharacterEncoding.h"
#include "js/UniquePtr.h"
#include "js/Wrapper.h"
#include "util/StringBuffer.h"
#include "vm/ErrorObject.h"
@ -267,7 +269,7 @@ CopyExtraData(JSContext* cx, uint8_t** cursor, JSErrorNotes::Note* copy, JSError
}
template <typename T>
static T*
static UniquePtr<T>
CopyErrorHelper(JSContext* cx, T* report)
{
/*
@ -298,7 +300,7 @@ CopyErrorHelper(JSContext* cx, T* report)
if (!cursor)
return nullptr;
T* copy = new (cursor) T();
UniquePtr<T> copy(new (cursor) T());
cursor += sizeof(T);
if (report->message()) {
@ -313,13 +315,10 @@ CopyErrorHelper(JSContext* cx, T* report)
cursor += filenameSize;
}
if (!CopyExtraData(cx, &cursor, copy, report)) {
/* js_delete calls destructor for T and js_free for pod_calloc. */
js_delete(copy);
if (!CopyExtraData(cx, &cursor, copy.get(), report))
return nullptr;
}
MOZ_ASSERT(cursor == (uint8_t*)copy + mallocSize);
MOZ_ASSERT(cursor == (uint8_t*)copy.get() + mallocSize);
/* Copy non-pointer members. */
copy->lineno = report->lineno;
@ -329,13 +328,13 @@ CopyErrorHelper(JSContext* cx, T* report)
return copy;
}
JSErrorNotes::Note*
UniquePtr<JSErrorNotes::Note>
js::CopyErrorNote(JSContext* cx, JSErrorNotes::Note* note)
{
return CopyErrorHelper(cx, note);
}
JSErrorReport*
UniquePtr<JSErrorReport>
js::CopyErrorReport(JSContext* cx, JSErrorReport* report)
{
return CopyErrorHelper(cx, report);
@ -686,12 +685,12 @@ js::ErrorToException(JSContext* cx, JSErrorReport* reportp,
if (!CaptureStack(cx, &stack))
return;
js::ScopedJSFreePtr<JSErrorReport> report(CopyErrorReport(cx, reportp));
UniquePtr<JSErrorReport> report = CopyErrorReport(cx, reportp);
if (!report)
return;
RootedObject errObject(cx, ErrorObject::create(cx, exnType, stack, fileName,
lineNumber, columnNumber, &report, messageStr));
RootedObject errObject(cx, ErrorObject::create(cx, exnType, stack, fileName, lineNumber,
columnNumber, std::move(report), messageStr));
if (!errObject)
return;
@ -990,7 +989,7 @@ ErrorReport::populateUncaughtExceptionReportUTF8VA(JSContext* cx, va_list ap)
JSObject*
js::CopyErrorObject(JSContext* cx, Handle<ErrorObject*> err)
{
js::ScopedJSFreePtr<JSErrorReport> copyReport;
UniquePtr<JSErrorReport> copyReport;
if (JSErrorReport* errorReport = err->getErrorReport()) {
copyReport = CopyErrorReport(cx, errorReport);
if (!copyReport)
@ -1012,7 +1011,7 @@ js::CopyErrorObject(JSContext* cx, Handle<ErrorObject*> err)
// Create the Error object.
return ErrorObject::create(cx, errorType, stack, fileName,
lineNumber, columnNumber, &copyReport, message);
lineNumber, columnNumber, std::move(copyReport), message);
}
JS_PUBLIC_API(bool)
@ -1023,13 +1022,15 @@ JS::CreateError(JSContext* cx, JSExnType type, HandleObject stack, HandleString
assertSameCompartment(cx, stack, fileName, message);
AssertObjectIsSavedFrameOrWrapper(cx, stack);
js::ScopedJSFreePtr<JSErrorReport> rep;
if (report)
js::UniquePtr<JSErrorReport> rep;
if (report) {
rep = CopyErrorReport(cx, report);
if (!rep)
return false;
}
RootedObject obj(cx,
js::ErrorObject::create(cx, type, stack, fileName,
lineNumber, columnNumber, &rep, message));
JSObject* obj = js::ErrorObject::create(cx, type, stack, fileName, lineNumber, columnNumber,
std::move(rep), message);
if (!obj)
return false;

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

@ -14,15 +14,16 @@
#include "jsapi.h"
#include "NamespaceImports.h"
#include "js/UniquePtr.h"
#include "vm/JSContext.h"
namespace js {
class ErrorObject;
JSErrorNotes::Note*
UniquePtr<JSErrorNotes::Note>
CopyErrorNote(JSContext* cx, JSErrorNotes::Note* note);
JSErrorReport*
UniquePtr<JSErrorReport>
CopyErrorReport(JSContext* cx, JSErrorReport* report);
JSString*

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

@ -9,6 +9,8 @@
#include "mozilla/Range.h"
#include <utility>
#include "jsexn.h"
#include "js/CallArgs.h"
@ -38,7 +40,7 @@ js::ErrorObject::assignInitialShape(JSContext* cx, Handle<ErrorObject*> obj)
/* static */ bool
js::ErrorObject::init(JSContext* cx, Handle<ErrorObject*> obj, JSExnType type,
ScopedJSFreePtr<JSErrorReport>* errorReport, HandleString fileName,
UniquePtr<JSErrorReport> errorReport, HandleString fileName,
HandleObject stack, uint32_t lineNumber, uint32_t columnNumber,
HandleString message)
{
@ -72,7 +74,7 @@ js::ErrorObject::init(JSContext* cx, Handle<ErrorObject*> obj, JSExnType type,
MOZ_ASSERT(JSEXN_ERR <= type && type < JSEXN_LIMIT);
JSErrorReport* report = errorReport ? errorReport->forget() : nullptr;
JSErrorReport* report = errorReport.release();
obj->initReservedSlot(EXNTYPE_SLOT, Int32Value(type));
obj->initReservedSlot(STACK_SLOT, ObjectOrNullValue(stack));
obj->setReservedSlot(ERROR_REPORT_SLOT, PrivateValue(report));
@ -88,7 +90,7 @@ js::ErrorObject::init(JSContext* cx, Handle<ErrorObject*> obj, JSExnType type,
/* static */ ErrorObject*
js::ErrorObject::create(JSContext* cx, JSExnType errorType, HandleObject stack,
HandleString fileName, uint32_t lineNumber, uint32_t columnNumber,
ScopedJSFreePtr<JSErrorReport>* report, HandleString message,
UniquePtr<JSErrorReport> report, HandleString message,
HandleObject protoArg /* = nullptr */)
{
AssertObjectIsSavedFrameOrWrapper(cx, stack);
@ -109,7 +111,7 @@ js::ErrorObject::create(JSContext* cx, JSExnType errorType, HandleObject stack,
errObject = &obj->as<ErrorObject>();
}
if (!ErrorObject::init(cx, errObject, errorType, report, fileName, stack,
if (!ErrorObject::init(cx, errObject, errorType, std::move(report), fileName, stack,
lineNumber, columnNumber, message))
{
return nullptr;
@ -156,11 +158,11 @@ js::ErrorObject::getOrCreateErrorReport(JSContext* cx)
report.initOwnedMessage(utf8.release());
// Cache and return.
JSErrorReport* copy = CopyErrorReport(cx, &report);
UniquePtr<JSErrorReport> copy = CopyErrorReport(cx, &report);
if (!copy)
return nullptr;
setReservedSlot(ERROR_REPORT_SLOT, PrivateValue(copy));
return copy;
setReservedSlot(ERROR_REPORT_SLOT, PrivateValue(copy.get()));
return copy.release();
}
static bool

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

@ -9,6 +9,7 @@
#include "mozilla/ArrayUtils.h"
#include "js/UniquePtr.h"
#include "vm/NativeObject.h"
#include "vm/SavedStacks.h"
#include "vm/Shape.h"
@ -35,7 +36,7 @@ class ErrorObject : public NativeObject
static bool
init(JSContext* cx, Handle<ErrorObject*> obj, JSExnType type,
ScopedJSFreePtr<JSErrorReport>* errorReport, HandleString fileName, HandleObject stack,
UniquePtr<JSErrorReport> errorReport, HandleString fileName, HandleObject stack,
uint32_t lineNumber, uint32_t columnNumber, HandleString message);
static const ClassSpec classSpecs[JSEXN_ERROR_LIMIT];
@ -70,7 +71,7 @@ class ErrorObject : public NativeObject
// property.
static ErrorObject*
create(JSContext* cx, JSExnType type, HandleObject stack, HandleString fileName,
uint32_t lineNumber, uint32_t columnNumber, ScopedJSFreePtr<JSErrorReport>* report,
uint32_t lineNumber, uint32_t columnNumber, UniquePtr<JSErrorReport> report,
HandleString message, HandleObject proto = nullptr);
/*