Skip to content

Commit

Permalink
Bug 1847469 - Part 26: Use column number types in JS::CompileOptions.…
Browse files Browse the repository at this point in the history
… r=iain

Differential Revision: https://phabricator.services.mozilla.com/D185764
  • Loading branch information
arai-a committed Aug 16, 2023
1 parent 35123cf commit 70cc385
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
7 changes: 5 additions & 2 deletions dom/script/ScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "prsystem.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "js/Array.h" // JS::GetArrayLength
#include "js/Array.h" // JS::GetArrayLength
#include "js/ColumnNumber.h" // #include "js/CompilationAndEvaluation.h"

#include "js/CompilationAndEvaluation.h"
#include "js/ContextOptions.h" // JS::ContextOptionsRef
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
Expand Down Expand Up @@ -2027,7 +2029,8 @@ nsresult ScriptLoader::FillCompileOptionsForRequest(
if (aRequest->GetScriptLoadContext()->mIsInline &&
aRequest->GetScriptLoadContext()->GetParserCreated() ==
FROM_PARSER_NETWORK) {
aOptions->setColumn(aRequest->GetScriptLoadContext()->mColumnNo);
aOptions->setColumn(JS::ColumnNumberZeroOrigin(
aRequest->GetScriptLoadContext()->mColumnNo));
}
aOptions->setIsRunOnce(true);
aOptions->setNoScriptRval(true);
Expand Down
9 changes: 5 additions & 4 deletions js/public/CompileOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "jstypes.h" // JS_PUBLIC_API

#include "js/CharacterEncoding.h" // JS::ConstUTF8CharsZ
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/TypeDecls.h" // JS::MutableHandle (fwd)

namespace js {
Expand Down Expand Up @@ -455,8 +456,8 @@ class JS_PUBLIC_API ReadOnlyCompileOptions : public TransitiveCompileOptions {

// Line number of the first character (1-origin).
uint32_t lineno = 1;
// Column number of the first character in UTF-16 code units (0-origin).
uint32_t column = 0;
// Column number of the first character in UTF-16 code units.
JS::ColumnNumberZeroOrigin column;

// The offset within the ScriptSource's full uncompressed text of the first
// character we're presenting for compilation with this CompileOptions.
Expand Down Expand Up @@ -490,7 +491,7 @@ class JS_PUBLIC_API ReadOnlyCompileOptions : public TransitiveCompileOptions {
this->TransitiveCompileOptions::dumpWith(print);
# define PrintFields_(Name) print(#Name, Name)
PrintFields_(lineno);
PrintFields_(column);
print("column", column.zeroOriginValue());
PrintFields_(scriptSourceOffset);
PrintFields_(isRunOnce);
PrintFields_(noScriptRval);
Expand Down Expand Up @@ -622,7 +623,7 @@ class MOZ_STACK_CLASS JS_PUBLIC_API CompileOptions final
return *this;
}

CompileOptions& setColumn(uint32_t c) {
CompileOptions& setColumn(JS::ColumnNumberZeroOrigin c) {
column = c;
return *this;
}
Expand Down
3 changes: 2 additions & 1 deletion js/src/builtin/TestingUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "jsapi.h" // JS_NewPlainObject, JS_WrapValue
#include "js/CharacterEncoding.h" // JS_EncodeStringToUTF8
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/CompileOptions.h" // JS::CompileOptions
#include "js/Conversions.h" // JS::ToBoolean, JS::ToString, JS::ToUint32, JS::ToInt32
#include "js/PropertyAndElement.h" // JS_GetProperty, JS_DefineProperty
Expand Down Expand Up @@ -84,7 +85,7 @@ bool js::ParseCompileOptions(JSContext* cx, JS::CompileOptions& options,
if (!JS::ToInt32(cx, v, &c)) {
return false;
}
options.setColumn(c);
options.setColumn(JS::ColumnNumberZeroOrigin(c));
}

if (!JS_GetProperty(cx, opts, "sourceIsLazy", &v)) {
Expand Down
5 changes: 3 additions & 2 deletions js/src/debugger/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include "debugger/NoExecute.h" // for LeaveDebuggeeNoExecute
#include "debugger/Script.h" // for DebuggerScript
#include "debugger/Source.h" // for DebuggerSource
#include "gc/Tracer.h" // for TraceManuallyBarrieredCrossCompartmentEdge
#include "gc/Tracer.h" // for TraceManuallyBarrieredCrossCompartmentEdge
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/CompilationAndEvaluation.h" // for Compile
#include "js/Conversions.h" // for ToObject
#include "js/experimental/JitInfo.h" // for JSJitInfo
Expand Down Expand Up @@ -1260,7 +1261,7 @@ bool DebuggerObject::CallData::createSource() {

JS::CompileOptions compileOptions(cx);
compileOptions.lineno = startLine;
compileOptions.column = startColumn;
compileOptions.column = JS::ColumnNumberZeroOrigin(startColumn);

if (!JS::StringHasLatin1Chars(url)) {
JS_ReportErrorASCII(cx, "URL must be a narrow string");
Expand Down
4 changes: 2 additions & 2 deletions js/src/debugger/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "debugger/Script.h" // for DebuggerScript
#include "frontend/FrontendContext.h" // for AutoReportFrontendContext
#include "gc/Tracer.h" // for TraceManuallyBarrieredCrossCompartmentEdge
#include "js/ColumnNumber.h" // JS::WasmFunctionIndex
#include "js/ColumnNumber.h" // JS::WasmFunctionIndex, JS::ColumnNumberZeroOrigin
#include "js/CompilationAndEvaluation.h" // for Compile
#include "js/ErrorReport.h" // for JS_ReportErrorASCII, JS_ReportErrorNumberASCII
#include "js/experimental/TypedData.h" // for JS_NewUint8Array
Expand Down Expand Up @@ -623,7 +623,7 @@ static JSScript* ReparseSource(JSContext* cx, Handle<ScriptSourceObject*> sso) {
JS::CompileOptions options(cx);
options.setHideScriptFromDebugger(true);
options.setFileAndLine(ss->filename(), ss->startLine());
options.setColumn(ss->startColumn().zeroOriginValue());
options.setColumn(JS::ColumnNumberZeroOrigin(ss->startColumn()));

UncompressedSourceCache::AutoHoldEntry holder;

Expand Down
6 changes: 3 additions & 3 deletions js/src/frontend/BytecodeCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "frontend/UsedNameTracker.h" // UsedNameTracker, UsedNameMap
#include "js/AllocPolicy.h" // js::SystemAllocPolicy, ReportOutOfMemory
#include "js/CharacterEncoding.h" // JS_EncodeStringToUTF8
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin, JS::ColumnNumberZeroOrigin
#include "js/ErrorReport.h" // JS_ReportErrorASCII
#include "js/experimental/JSStencil.h"
#include "js/GCVector.h" // JS::StackGCVector
Expand Down Expand Up @@ -1573,7 +1573,7 @@ static bool DelazifyCanonicalScriptedFunctionImpl(JSContext* cx,
JS::CompileOptions options(cx);
options.setMutedErrors(lazy->mutedErrors())
.setFileAndLine(lazy->filename(), lazy->lineno())
.setColumn(lazy->column().zeroOriginValue())
.setColumn(JS::ColumnNumberZeroOrigin(lazy->column()))
.setScriptSourceOffset(lazy->sourceStart())
.setNoScriptRval(false)
.setSelfHostingMode(false)
Expand Down Expand Up @@ -1649,7 +1649,7 @@ DelazifyCanonicalScriptedFunctionImpl(
JS::CompileOptions options(prefableOptions);
options.setMutedErrors(ss->mutedErrors())
.setFileAndLine(ss->filename(), extra.extent.lineno)
.setColumn(extra.extent.column.zeroOriginValue())
.setColumn(JS::ColumnNumberZeroOrigin(extra.extent.column))
.setScriptSourceOffset(sourceStart)
.setNoScriptRval(false)
.setSelfHostingMode(false);
Expand Down
5 changes: 3 additions & 2 deletions js/src/frontend/TokenStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ TokenStreamSpecific<Unit, AnyCharsAccess>::TokenStreamSpecific(

bool TokenStreamAnyChars::checkOptions() {
// Constrain starting columns to where they will saturate.
if (options().column > JS::LimitedColumnNumberZeroOrigin::Limit) {
if (options().column.zeroOriginValue() >
JS::LimitedColumnNumberZeroOrigin::Limit) {
reportErrorNoOffset(JSMSG_BAD_COLUMN_NUMBER);
return false;
}
Expand Down Expand Up @@ -842,7 +843,7 @@ GeneralTokenStreamChars<Unit, AnyCharsAccess>::computeColumn(
return JS::LimitedColumnNumberZeroOrigin::limit();
}

uint32_t firstLineOffset = anyChars.options_.column;
uint32_t firstLineOffset = anyChars.options_.column.zeroOriginValue();
column += JS::ColumnNumberOffset(firstLineOffset);
}

Expand Down

0 comments on commit 70cc385

Please sign in to comment.