Bug 1847469 - Part 21: Use column number types in ErrorObject. r=iain

Differential Revision: https://phabricator.services.mozilla.com/D185759
This commit is contained in:
Tooru Fujisawa 2023-08-16 10:26:32 +00:00
Родитель ee81f946a2
Коммит 52394e4a4f
6 изменённых файлов: 34 добавлений и 25 удалений

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

@ -352,9 +352,9 @@ bool js::ErrorToException(JSContext* cx, JSErrorReport* reportp,
return false; return false;
} }
ErrorObject* errObject = ErrorObject::create( ErrorObject* errObject =
cx, exnType, stack, fileName, sourceId, lineNumber, ErrorObject::create(cx, exnType, stack, fileName, sourceId, lineNumber,
columnNumber.oneOriginValue(), std::move(report), messageStr, cause); columnNumber, std::move(report), messageStr, cause);
if (!errObject) { if (!errObject) {
return false; return false;
} }
@ -741,7 +741,7 @@ JSObject* js::CopyErrorObject(JSContext* cx, Handle<ErrorObject*> err) {
} }
uint32_t sourceId = err->sourceId(); uint32_t sourceId = err->sourceId();
uint32_t lineNumber = err->lineNumber(); uint32_t lineNumber = err->lineNumber();
uint32_t columnNumber = err->columnNumber(); JS::ColumnNumberOneOrigin columnNumber = err->columnNumber();
JSExnType errorType = err->type(); JSExnType errorType = err->type();
// Create the Error object. // Create the Error object.
@ -768,9 +768,9 @@ JS_PUBLIC_API bool JS::CreateError(JSContext* cx, JSExnType type,
} }
} }
JSObject* obj = js::ErrorObject::create( JSObject* obj =
cx, type, stack, fileName, 0, lineNumber, columnNumber.oneOriginValue(), js::ErrorObject::create(cx, type, stack, fileName, 0, lineNumber,
std::move(rep), message, cause); columnNumber, std::move(rep), message, cause);
if (!obj) { if (!obj) {
return false; return false;
} }

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

@ -9,6 +9,8 @@
#include "vm/ErrorObject.h" #include "vm/ErrorObject.h"
#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin
#include "vm/JSAtomState.h" #include "vm/JSAtomState.h"
#include "vm/JSContext.h" #include "vm/JSContext.h"
@ -27,9 +29,10 @@ inline uint32_t js::ErrorObject::lineNumber() const {
return val.isInt32() ? val.toInt32() : 0; return val.isInt32() ? val.toInt32() : 0;
} }
inline uint32_t js::ErrorObject::columnNumber() const { inline JS::ColumnNumberOneOrigin js::ErrorObject::columnNumber() const {
Value val = getReservedSlot(COLUMNNUMBER_SLOT); Value val = getReservedSlot(COLUMNNUMBER_SLOT);
return val.isInt32() ? val.toInt32() : 0; return val.isInt32() ? JS::ColumnNumberOneOrigin(val.toInt32())
: JS::ColumnNumberOneOrigin::zero();
} }
inline JSObject* js::ErrorObject::stack() const { inline JSObject* js::ErrorObject::stack() const {

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

@ -277,8 +277,7 @@ static ErrorObject* CreateErrorObject(JSContext* cx, const CallArgs& args,
} }
return ErrorObject::create(cx, exnType, stack, fileName, sourceId, lineNumber, return ErrorObject::create(cx, exnType, stack, fileName, sourceId, lineNumber,
columnNumber.oneOriginValue(), nullptr, message, columnNumber, nullptr, message, cause, proto);
cause, proto);
} }
static bool Error(JSContext* cx, unsigned argc, Value* vp) { static bool Error(JSContext* cx, unsigned argc, Value* vp) {
@ -448,7 +447,8 @@ bool js::ErrorObject::init(JSContext* cx, Handle<ErrorObject*> obj,
JSExnType type, UniquePtr<JSErrorReport> errorReport, JSExnType type, UniquePtr<JSErrorReport> errorReport,
HandleString fileName, HandleObject stack, HandleString fileName, HandleObject stack,
uint32_t sourceId, uint32_t lineNumber, uint32_t sourceId, uint32_t lineNumber,
uint32_t columnNumber, HandleString message, JS::ColumnNumberOneOrigin columnNumber,
HandleString message,
Handle<mozilla::Maybe<JS::Value>> cause) { Handle<mozilla::Maybe<JS::Value>> cause) {
MOZ_ASSERT(JSEXN_ERR <= type && type < JSEXN_ERROR_LIMIT); MOZ_ASSERT(JSEXN_ERR <= type && type < JSEXN_ERROR_LIMIT);
AssertObjectIsSavedFrameOrWrapper(cx, stack); AssertObjectIsSavedFrameOrWrapper(cx, stack);
@ -504,7 +504,8 @@ bool js::ErrorObject::init(JSContext* cx, Handle<ErrorObject*> obj,
obj->setReservedSlot(ERROR_REPORT_SLOT, PrivateValue(report)); obj->setReservedSlot(ERROR_REPORT_SLOT, PrivateValue(report));
obj->initReservedSlot(FILENAME_SLOT, StringValue(fileName)); obj->initReservedSlot(FILENAME_SLOT, StringValue(fileName));
obj->initReservedSlot(LINENUMBER_SLOT, Int32Value(lineNumber)); obj->initReservedSlot(LINENUMBER_SLOT, Int32Value(lineNumber));
obj->initReservedSlot(COLUMNNUMBER_SLOT, Int32Value(columnNumber)); obj->initReservedSlot(COLUMNNUMBER_SLOT,
Int32Value(columnNumber.oneOriginValue()));
if (message) { if (message) {
obj->initReservedSlot(MESSAGE_SLOT, StringValue(message)); obj->initReservedSlot(MESSAGE_SLOT, StringValue(message));
} }
@ -526,7 +527,7 @@ bool js::ErrorObject::init(JSContext* cx, Handle<ErrorObject*> obj,
ErrorObject* js::ErrorObject::create(JSContext* cx, JSExnType errorType, ErrorObject* js::ErrorObject::create(JSContext* cx, JSExnType errorType,
HandleObject stack, HandleString fileName, HandleObject stack, HandleString fileName,
uint32_t sourceId, uint32_t lineNumber, uint32_t sourceId, uint32_t lineNumber,
uint32_t columnNumber, JS::ColumnNumberOneOrigin columnNumber,
UniquePtr<JSErrorReport> report, UniquePtr<JSErrorReport> report,
HandleString message, HandleString message,
Handle<mozilla::Maybe<JS::Value>> cause, Handle<mozilla::Maybe<JS::Value>> cause,
@ -585,7 +586,7 @@ JSErrorReport* js::ErrorObject::getOrCreateErrorReport(JSContext* cx) {
// Coordinates. // Coordinates.
report.sourceId = sourceId(); report.sourceId = sourceId();
report.lineno = lineNumber(); report.lineno = lineNumber();
report.column = JS::ColumnNumberOneOrigin(columnNumber()); report.column = columnNumber();
// Message. Note that |new Error()| will result in an undefined |message| // Message. Note that |new Error()| will result in an undefined |message|
// slot, so we need to explicitly substitute the empty string in that case. // slot, so we need to explicitly substitute the empty string in that case.

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

@ -17,6 +17,7 @@
#include "NamespaceImports.h" #include "NamespaceImports.h"
#include "js/Class.h" #include "js/Class.h"
#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin
#include "js/ErrorReport.h" #include "js/ErrorReport.h"
#include "js/RootingAPI.h" #include "js/RootingAPI.h"
#include "js/TypeDecls.h" #include "js/TypeDecls.h"
@ -35,7 +36,7 @@ class ErrorObject : public NativeObject {
static bool init(JSContext* cx, Handle<ErrorObject*> obj, JSExnType type, static bool init(JSContext* cx, Handle<ErrorObject*> obj, JSExnType type,
UniquePtr<JSErrorReport> errorReport, HandleString fileName, UniquePtr<JSErrorReport> errorReport, HandleString fileName,
HandleObject stack, uint32_t sourceId, uint32_t lineNumber, HandleObject stack, uint32_t sourceId, uint32_t lineNumber,
uint32_t columnNumber, HandleString message, JS::ColumnNumberOneOrigin columnNumber, HandleString message,
Handle<mozilla::Maybe<JS::Value>> cause); Handle<mozilla::Maybe<JS::Value>> cause);
static const ClassSpec classSpecs[JSEXN_ERROR_LIMIT]; static const ClassSpec classSpecs[JSEXN_ERROR_LIMIT];
@ -73,10 +74,10 @@ class ErrorObject : public NativeObject {
// info. If |message| is non-null, then the error will have a .message // info. If |message| is non-null, then the error will have a .message
// property with that value; otherwise the error will have no .message // property with that value; otherwise the error will have no .message
// property. // property.
// columnNumber is 1-origin.
static ErrorObject* create(JSContext* cx, JSExnType type, HandleObject stack, static ErrorObject* create(JSContext* cx, JSExnType type, HandleObject stack,
HandleString fileName, uint32_t sourceId, HandleString fileName, uint32_t sourceId,
uint32_t lineNumber, uint32_t columnNumber, uint32_t lineNumber,
JS::ColumnNumberOneOrigin columnNumber,
UniquePtr<JSErrorReport> report, UniquePtr<JSErrorReport> report,
HandleString message, HandleString message,
Handle<mozilla::Maybe<JS::Value>> cause, Handle<mozilla::Maybe<JS::Value>> cause,
@ -111,8 +112,8 @@ class ErrorObject : public NativeObject {
// Line number (1-origin). // Line number (1-origin).
inline uint32_t lineNumber() const; inline uint32_t lineNumber() const;
// Column number in UTF-16 code units (1-origin). // Column number in UTF-16 code units.
inline uint32_t columnNumber() const; inline JS::ColumnNumberOneOrigin columnNumber() const;
inline JSObject* stack() const; inline JSObject* stack() const;

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

@ -45,7 +45,7 @@
#include "builtin/MapObject.h" #include "builtin/MapObject.h"
#include "js/Array.h" // JS::GetArrayLength, JS::IsArrayObject #include "js/Array.h" // JS::GetArrayLength, JS::IsArrayObject
#include "js/ArrayBuffer.h" // JS::{ArrayBufferHasData,DetachArrayBuffer,IsArrayBufferObject,New{,Mapped}ArrayBufferWithContents,ReleaseMappedArrayBufferContents} #include "js/ArrayBuffer.h" // JS::{ArrayBufferHasData,DetachArrayBuffer,IsArrayBufferObject,New{,Mapped}ArrayBufferWithContents,ReleaseMappedArrayBufferContents}
#include "js/ColumnNumber.h" // JS::TaggedColumnNumberOneOrigin #include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin, JS::TaggedColumnNumberOneOrigin
#include "js/Date.h" #include "js/Date.h"
#include "js/experimental/TypedData.h" // JS_NewDataView, JS_New{{Ui,I}nt{8,16,32},Float{32,64},Uint8Clamped,Big{Ui,I}nt64}ArrayWithBuffer #include "js/experimental/TypedData.h" // JS_NewDataView, JS_New{{Ui,I}nt{8,16,32},Float{32,64},Uint8Clamped,Big{Ui,I}nt64}ArrayWithBuffer
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_* #include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
@ -1983,7 +1983,7 @@ bool JSStructuredCloneWriter::traverseError(HandleObject obj) {
return false; return false;
} }
val = Int32Value(unwrapped->columnNumber()); val = Int32Value(*unwrapped->columnNumber().addressOfValueForTranscode());
return writePrimitive(val); return writePrimitive(val);
} }
@ -3604,8 +3604,10 @@ JSObject* JSStructuredCloneReader::readErrorHeader(uint32_t type) {
} }
RootedString fileName(cx, val.toString()); RootedString fileName(cx, val.toString());
uint32_t lineNumber, columnNumber; uint32_t lineNumber;
if (!readUint32(&lineNumber) || !readUint32(&columnNumber)) { JS::ColumnNumberOneOrigin columnNumber;
if (!readUint32(&lineNumber) ||
!readUint32(columnNumber.addressOfValueForTranscode())) {
return nullptr; return nullptr;
} }

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

@ -37,6 +37,7 @@
#include "jit/JitContext.h" #include "jit/JitContext.h"
#include "jit/JitOptions.h" #include "jit/JitOptions.h"
#include "jit/Simulator.h" #include "jit/Simulator.h"
#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin
#include "js/ForOfIterator.h" #include "js/ForOfIterator.h"
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_* #include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/Printf.h" #include "js/Printf.h"
@ -4228,7 +4229,8 @@ static bool Reject(JSContext* cx, const CompileArgs& args,
RootedObject errorObj( RootedObject errorObj(
cx, ErrorObject::create(cx, JSEXN_WASMCOMPILEERROR, stack, fileName, 0, cx, ErrorObject::create(cx, JSEXN_WASMCOMPILEERROR, stack, fileName, 0,
line, 0, nullptr, message, cause)); line, JS::ColumnNumberOneOrigin::zero(), nullptr,
message, cause));
if (!errorObj) { if (!errorObj) {
return false; return false;
} }