Bug 1353580 - Remove support for !HAVE_PR_MEMMAP in mozJSComponentLoader. r=mrbkap

This was only ever used for BeOS and OS2, which have likely long ago
stopped working for other reasons.

MozReview-Commit-ID: AT1jNEB1ydY

--HG--
extra : rebase_source : 8ab13e574c57f0ea96158af86e01ea8f22f6bff7
This commit is contained in:
Andrew McCreight 2017-04-04 16:53:56 -07:00
parent 7034d3800d
commit 1b37fc293a

View File

@ -63,8 +63,6 @@ static const char kXPConnectServiceContractID[] = "@mozilla.org/js/xpc/XPConnect
static const char kObserverServiceContractID[] = "@mozilla.org/observer-service;1";
static const char kJSCachePrefix[] = "jsloader";
#define HAVE_PR_MEMMAP
/**
* Buffer sizes for serialization and deserialization of scripts.
* FIXME: bug #411579 (tune this macro!) Last updated: Jan 2008
@ -507,7 +505,6 @@ mozJSComponentLoader::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
}
// Some stack based classes for cleaning up on early return
#ifdef HAVE_PR_MEMMAP
class FileAutoCloser
{
public:
@ -525,16 +522,6 @@ class FileMapAutoCloser
private:
PRFileMap* mMap;
};
#else
class ANSIFileAutoCloser
{
public:
explicit ANSIFileAutoCloser(FILE* file) : mFile(file) {}
~ANSIFileAutoCloser() { fclose(mFile); }
private:
FILE* mFile;
};
#endif
JSObject*
mozJSComponentLoader::PrepareObjectForLocation(JSContext* aCx,
@ -752,7 +739,6 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo& aInfo,
.setSourceIsLazy(!mReuseLoaderGlobal && !!cache);
if (realFile) {
#ifdef HAVE_PR_MEMMAP
int64_t fileSize;
rv = aComponentFile->GetFileSize(&fileSize);
if (NS_FAILED(rv)) {
@ -810,58 +796,6 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo& aInfo,
}
PR_MemUnmap(buf, fileSize32);
#else /* HAVE_PR_MEMMAP */
/**
* No memmap implementation, so fall back to
* reading in the file
*/
FILE* fileHandle;
rv = aComponentFile->OpenANSIFileDesc("r", &fileHandle);
if (NS_FAILED(rv)) {
return NS_ERROR_FILE_NOT_FOUND;
}
// Ensure file fclose
ANSIFileAutoCloser fileCloser(fileHandle);
int64_t len;
rv = aComponentFile->GetFileSize(&len);
if (NS_FAILED(rv) || len < 0) {
NS_WARNING("Failed to get file size");
return NS_ERROR_FAILURE;
}
char* buf = (char*) malloc(len * sizeof(char));
if (!buf) {
return NS_ERROR_FAILURE;
}
size_t rlen = fread(buf, 1, len, fileHandle);
if (rlen != (uint64_t)len) {
free(buf);
NS_WARNING("Failed to read file");
return NS_ERROR_FAILURE;
}
if (!mReuseLoaderGlobal) {
script = Compile(cx, options, buf, fileSize32);
} else {
// Note: exceptions will get handled further down;
// don't early return for them here.
AutoObjectVector envChain(cx);
if (envChain.append(obj)) {
CompileFunction(cx, envChain,
options, nullptr, 0, nullptr,
buf, fileSize32, &function);
}
}
free(buf);
#endif /* HAVE_PR_MEMMAP */
} else {
rv = aInfo.EnsureScriptChannel();
NS_ENSURE_SUCCESS(rv, rv);