From a33e0ccc84c785b3c83286a5115fc4ae347f6257 Mon Sep 17 00:00:00 2001 From: Stan Date: Mon, 28 Mar 2022 21:58:22 +0000 Subject: [PATCH] Remove some duplicated code from ScriptInterface.cpp Tested by: @Langbart Patch by: @smiley Differential Revision: https://code.wildfiregames.com/D4574 This was SVN commit r26725. --- source/scriptinterface/ScriptInterface.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/source/scriptinterface/ScriptInterface.cpp b/source/scriptinterface/ScriptInterface.cpp index 4661473fa5..fca266d8fe 100644 --- a/source/scriptinterface/ScriptInterface.cpp +++ b/source/scriptinterface/ScriptInterface.cpp @@ -663,7 +663,6 @@ bool ScriptInterface::LoadGlobalScript(const VfsPath& filename, const std::strin bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path) const { - ScriptRequest rq(this); if (!VfsFileExists(path)) { LOGERROR("File '%s' does not exist", path.string8()); @@ -682,21 +681,7 @@ bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path) const CStr code = file.DecodeUTF8(); // assume it's UTF-8 - uint lineNo = 1; - // CompileOptions does not copy the contents of the filename string pointer. - // Passing a temporary string there will cause undefined behaviour, so we create a separate string to avoid the temporary. - std::string filenameStr = path.string8(); - - JS::RootedValue rval(rq.cx); - JS::CompileOptions opts(rq.cx); - opts.setFileAndLine(filenameStr.c_str(), lineNo); - JS::SourceText src; - ENSURE(src.init(rq.cx, code.c_str(), code.length(), JS::SourceOwnership::Borrowed)); - if (JS::Evaluate(rq.cx, opts, src, &rval)) - return true; - - ScriptException::CatchPending(rq); - return false; + return LoadGlobalScript(path, code); } bool ScriptInterface::Eval(const char* code) const