Bug 1492090 - Part 1: Fix some comments, remove a #define, and make one fclose call more robust. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D151445
This commit is contained in:
André Bargull
2023-05-23 12:11:38 +00:00
parent efe26ea153
commit 8c9431d7d0
6 changed files with 14 additions and 16 deletions

View File

@@ -259,9 +259,7 @@ void XPCShellEnvironment::ProcessFile(JSContext* cx, const char* filename,
* It's not interactive - just execute it.
*
* Support the UNIX #! shell hack; gobble the first line if it starts
* with '#'. TODO - this isn't quite compatible with sharp variables,
* as a legal js program (using sharp variables) might start with '#'.
* But that would require multi-character lookahead.
* with '#'.
*/
int ch = fgetc(file);
if (ch == '#') {

View File

@@ -233,8 +233,8 @@ class JS_PUBLIC_API TransitiveCompileOptions {
bool deoptimizeModuleGlobalVars = false;
/**
* |introductionType| is a statically allocated C string: one of "eval",
* "Function", or "GeneratorFunction".
* |introductionType| is a statically allocated C string. See JSScript.h
* for more information.
*/
const char* introductionType = nullptr;

View File

@@ -4173,6 +4173,11 @@ static bool DumpHeap(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
FILE* dumpFile = stdout;
auto closeFile = mozilla::MakeScopeExit([&dumpFile] {
if (dumpFile != stdout) {
fclose(dumpFile);
}
});
if (args.length() > 1) {
RootedObject callee(cx, &args.callee());
@@ -4204,10 +4209,6 @@ static bool DumpHeap(JSContext* cx, unsigned argc, Value* vp) {
js::DumpHeap(cx, dumpFile, js::IgnoreNurseryObjects);
if (dumpFile != stdout) {
fclose(dumpFile);
}
args.rval().setUndefined();
return true;
}

View File

@@ -177,13 +177,12 @@ JSObject* Library::Create(JSContext* cx, HandleValue path,
PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW);
if (!library) {
#define MAX_ERROR_LEN 1024
char error[MAX_ERROR_LEN] = "Cannot get error from NSPR.";
constexpr size_t MaxErrorLength = 1024;
char error[MaxErrorLength] = "Cannot get error from NSPR.";
uint32_t errorLen = PR_GetErrorTextLength();
if (errorLen && errorLen < MAX_ERROR_LEN) {
if (errorLen && errorLen < MaxErrorLength) {
PR_GetErrorText(error);
}
#undef MAX_ERROR_LEN
if (JS::StringIsASCII(error)) {
if (JS::UniqueChars pathCharsUTF8 = JS_EncodeStringToUTF8(cx, pathStr)) {

View File

@@ -583,6 +583,8 @@ class ScriptSource {
// A string indicating how this source code was introduced into the system.
// This is a constant, statically allocated C string, so does not need memory
// management.
//
// TODO: Document the various additional introduction type constants.
const char* introductionType_ = nullptr;
// Bytecode offset in caller script that generated this code. This is

View File

@@ -793,9 +793,7 @@ static bool ProcessFile(AutoJSAPI& jsapi, const char* filename, FILE* file,
* It's not interactive - just execute it.
*
* Support the UNIX #! shell hack; gobble the first line if it starts
* with '#'. TODO - this isn't quite compatible with sharp variables,
* as a legal js program (using sharp variables) might start with '#'.
* But that would require multi-character lookahead.
* with '#'.
*/
int ch = fgetc(file);
if (ch == '#') {