Fix off-by-one line number in JS error reporting.

Post SM60 upgrade, CompileFunction started actually adding a line in
front of the source buffer, shifting the error reporting in the
simulation and other callers of LoadScript.
The GUI isn't affected as it uses LoadGlobalScript, which uses Evaluate
directly.

Refs #5859
Fixes #5895

Differential Revision: https://code.wildfiregames.com/D3257
This was SVN commit r24455.
This commit is contained in:
wraitii committed 2020-12-27 07:51:30 +00:00
1 parent 8a77efd849
commit 1e8299dcdb
2 files changed
+6 -3

No files matched your search

+4 -1
View File
@@ -807,7 +807,10 @@ bool ScriptInterface::LoadScript(const VfsPath& filename, const std::string& cod
std::string filenameStr = filename.string8();
JS::CompileOptions options(rq.cx);
options.setFileAndLine(filenameStr.c_str(), 1);
// Set the line to 0 because CompileFunction silently adds a `(function() {` as the first line,
// and errors get misreported.
// TODO: it would probably be better to not implicitly introduce JS scopes.
options.setFileAndLine(filenameStr.c_str(), 0);
options.setIsRunOnce(false);
JS::SourceText<mozilla::Utf8Unit> src;