Bug 1845416 - Add JS::ReadOnlyDecodeOptions and JS::OwningDecodeOptions. r=bthrall

Differential Revision: https://phabricator.services.mozilla.com/D184543
This commit is contained in:
Tooru Fujisawa 2023-08-10 10:03:11 +00:00
Родитель ef9a0d3c1a
Коммит ec821c6d19
15 изменённых файлов: 164 добавлений и 84 удалений

Просмотреть файл

@ -1566,7 +1566,7 @@ static nsresult WriteStencil(nsIObjectOutputStream* aStream, JSContext* aCx,
}
static nsresult ReadStencil(nsIObjectInputStream* aStream, JSContext* aCx,
const JS::DecodeOptions& aOptions,
const JS::ReadOnlyDecodeOptions& aOptions,
JS::Stencil** aStencilOut) {
// We don't serialize mutedError-ness of scripts, which is fine as long as
// we only serialize system and XUL-y things. We can detect this by checking

Просмотреть файл

@ -115,7 +115,7 @@ enum class DelazificationOption : uint8_t {
};
class JS_PUBLIC_API InstantiateOptions;
class JS_PUBLIC_API DecodeOptions;
class JS_PUBLIC_API ReadOnlyDecodeOptions;
// Compilation-specific part of JS::ContextOptions which is supposed to be
// configured by user prefs.
@ -211,7 +211,7 @@ class JS_PUBLIC_API PrefableCompileOptions {
* compilation unit to another.
*/
class JS_PUBLIC_API TransitiveCompileOptions {
friend class JS_PUBLIC_API DecodeOptions;
friend class JS_PUBLIC_API ReadOnlyDecodeOptions;
protected:
// non-POD options:
@ -765,49 +765,85 @@ class JS_PUBLIC_API InstantiateOptions {
/**
* Subset of CompileOptions fields used while decoding Stencils.
*/
class JS_PUBLIC_API DecodeOptions {
class JS_PUBLIC_API ReadOnlyDecodeOptions {
public:
bool borrowBuffer = false;
bool usePinnedBytecode = false;
bool allocateInstantiationStorage = false;
bool forceAsync = false;
const JS::ConstUTF8CharsZ introducerFilename;
protected:
JS::ConstUTF8CharsZ introducerFilename_;
public:
// See `TransitiveCompileOptions::introductionType` field for details.
const char* introductionType = nullptr;
unsigned introductionLineno = 0;
uint32_t introductionOffset = 0;
DecodeOptions() = default;
protected:
ReadOnlyDecodeOptions() = default;
explicit DecodeOptions(const ReadOnlyCompileOptions& options)
: borrowBuffer(options.borrowBuffer),
usePinnedBytecode(options.usePinnedBytecode),
allocateInstantiationStorage(options.allocateInstantiationStorage),
forceAsync(options.forceAsync),
introducerFilename(options.introducerFilename()),
introductionType(options.introductionType),
introductionLineno(options.introductionLineno),
introductionOffset(options.introductionOffset) {}
ReadOnlyDecodeOptions(const ReadOnlyDecodeOptions&) = delete;
ReadOnlyDecodeOptions& operator=(const ReadOnlyDecodeOptions&) = delete;
template <typename T>
void copyPODOptions(const T& options) {
borrowBuffer = options.borrowBuffer;
usePinnedBytecode = options.usePinnedBytecode;
allocateInstantiationStorage = options.allocateInstantiationStorage;
forceAsync = options.forceAsync;
introductionType = options.introductionType;
introductionLineno = options.introductionLineno;
introductionOffset = options.introductionOffset;
}
public:
void copyTo(CompileOptions& options) const {
options.borrowBuffer = borrowBuffer;
options.usePinnedBytecode = usePinnedBytecode;
options.allocateInstantiationStorage = allocateInstantiationStorage;
options.forceAsync = forceAsync;
options.introducerFilename_ = introducerFilename;
options.introducerFilename_ = introducerFilename_;
options.introductionType = introductionType;
options.introductionLineno = introductionLineno;
options.introductionOffset = introductionOffset;
}
bool hasExternalData() const {
return introducerFilename || introductionType;
JS::ConstUTF8CharsZ introducerFilename() const { return introducerFilename_; }
};
class MOZ_STACK_CLASS JS_PUBLIC_API DecodeOptions final
: public ReadOnlyDecodeOptions {
public:
DecodeOptions() = default;
explicit DecodeOptions(const ReadOnlyCompileOptions& options) {
copyPODOptions(options);
introducerFilename_ = options.introducerFilename();
}
};
class JS_PUBLIC_API OwningDecodeOptions final : public ReadOnlyDecodeOptions {
public:
OwningDecodeOptions() = default;
~OwningDecodeOptions();
bool copy(JS::FrontendContext* maybeFc, const ReadOnlyDecodeOptions& rhs);
void infallibleCopy(const ReadOnlyDecodeOptions& rhs);
size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
private:
void release();
OwningDecodeOptions(const OwningDecodeOptions&) = delete;
OwningDecodeOptions& operator=(const OwningDecodeOptions&) = delete;
};
} // namespace JS
#endif /* js_CompileOptions_h */

Просмотреть файл

@ -15,7 +15,7 @@
#include "jstypes.h" // JS_PUBLIC_API
#include "js/CompileOptions.h" // JS::DecodeOptions, JS::ReadOnlyCompileOptions
#include "js/CompileOptions.h" // JS::ReadOnlyDecodeOptions, JS::ReadOnlyCompileOptions
struct JS_PUBLIC_API JSContext;
@ -49,9 +49,8 @@ using OffThreadCompileCallback = void (*)(OffThreadToken* token,
extern JS_PUBLIC_API bool CanCompileOffThread(
JSContext* cx, const ReadOnlyCompileOptions& options, size_t length);
extern JS_PUBLIC_API bool CanDecodeOffThread(JSContext* cx,
const DecodeOptions& options,
size_t length);
extern JS_PUBLIC_API bool CanDecodeOffThread(
JSContext* cx, const ReadOnlyDecodeOptions& options, size_t length);
} // namespace JS

Просмотреть файл

@ -23,7 +23,7 @@
#include "jstypes.h" // JS_PUBLIC_API
#include "js/CompileOptions.h" // JS::ReadOnlyCompileOptions, JS::InstantiateOptions, JS::DecodeOptions
#include "js/CompileOptions.h" // JS::ReadOnlyCompileOptions, JS::InstantiateOptions, JS::ReadOnlyDecodeOptions
#include "js/OffThreadScriptCompilation.h" // JS::OffThreadCompileCallback
#include "js/SourceText.h" // JS::SourceText
#include "js/Transcoding.h" // JS::TranscodeBuffer, JS::TranscodeRange
@ -201,14 +201,12 @@ extern JS_PUBLIC_API TranscodeResult EncodeStencil(JSContext* cx,
TranscodeBuffer& buffer);
// Deserialize data and create a new Stencil.
extern JS_PUBLIC_API TranscodeResult DecodeStencil(JSContext* cx,
const DecodeOptions& options,
const TranscodeRange& range,
Stencil** stencilOut);
extern JS_PUBLIC_API TranscodeResult DecodeStencil(JS::FrontendContext* fc,
const DecodeOptions& options,
const TranscodeRange& range,
Stencil** stencilOut);
extern JS_PUBLIC_API TranscodeResult
DecodeStencil(JSContext* cx, const ReadOnlyDecodeOptions& options,
const TranscodeRange& range, Stencil** stencilOut);
extern JS_PUBLIC_API TranscodeResult
DecodeStencil(JS::FrontendContext* fc, const ReadOnlyDecodeOptions& options,
const TranscodeRange& range, Stencil** stencilOut);
// Register an encoder on its script source, such that all functions can be
// encoded as they are delazified.
@ -255,8 +253,9 @@ extern JS_PUBLIC_API OffThreadToken* CompileModuleToStencilOffThread(
//
// `buffer` should be alive until the end of `FinishDecodeStencilOffThread`.
extern JS_PUBLIC_API OffThreadToken* DecodeStencilOffThread(
JSContext* cx, const DecodeOptions& options, const TranscodeBuffer& buffer,
size_t cursor, OffThreadCompileCallback callback, void* callbackData);
JSContext* cx, const ReadOnlyDecodeOptions& options,
const TranscodeBuffer& buffer, size_t cursor,
OffThreadCompileCallback callback, void* callbackData);
// The start of `range` should meet IsTranscodingBytecodeAligned and
// AlignTranscodingBytecodeOffset.
@ -264,8 +263,9 @@ extern JS_PUBLIC_API OffThreadToken* DecodeStencilOffThread(
//
// `range` should be alive until the end of `FinishDecodeStencilOffThread`.
extern JS_PUBLIC_API OffThreadToken* DecodeStencilOffThread(
JSContext* cx, const DecodeOptions& options, const TranscodeRange& range,
OffThreadCompileCallback callback, void* callbackData);
JSContext* cx, const ReadOnlyDecodeOptions& options,
const TranscodeRange& range, OffThreadCompileCallback callback,
void* callbackData);
// Finish the off-thread task to compile the source text into a JS::Stencil,
// started by JS::CompileToStencilOffThread, and return the result JS::Stencil.

Просмотреть файл

@ -28,11 +28,11 @@
#include "frontend/ParserAtom.h" // ParserAtom, ParserAtomIndex, TaggedParserAtomIndex, ParserAtomsTable, Length{1,2,3}StaticParserString, InstantiateMarkedAtoms, InstantiateMarkedAtomsAsPermanent, GetWellKnownAtom
#include "frontend/ScopeBindingCache.h" // ScopeBindingCache
#include "frontend/SharedContext.h"
#include "frontend/StencilXdr.h" // XDRStencilEncoder, XDRStencilDecoder
#include "gc/AllocKind.h" // gc::AllocKind
#include "gc/Tracer.h" // TraceNullableRoot
#include "js/CallArgs.h" // JSNative
#include "js/CompileOptions.h" // JS::DecodeOptions
#include "frontend/StencilXdr.h" // XDRStencilEncoder, XDRStencilDecoder
#include "gc/AllocKind.h" // gc::AllocKind
#include "gc/Tracer.h" // TraceNullableRoot
#include "js/CallArgs.h" // JSNative
#include "js/CompileOptions.h" // JS::DecodeOptions, JS::ReadOnlyDecodeOptions
#include "js/experimental/JSStencil.h" // JS::Stencil
#include "js/GCAPI.h" // JS::AutoCheckCannotGC
#include "js/Printer.h" // js::Fprinter
@ -5542,7 +5542,7 @@ JS::TranscodeResult JS::EncodeStencil(JSContext* cx, JS::Stencil* stencil,
}
JS::TranscodeResult JS::DecodeStencil(JSContext* cx,
const JS::DecodeOptions& options,
const JS::ReadOnlyDecodeOptions& options,
const JS::TranscodeRange& range,
JS::Stencil** stencilOut) {
AutoReportFrontendContext fc(cx);
@ -5550,7 +5550,7 @@ JS::TranscodeResult JS::DecodeStencil(JSContext* cx,
}
JS::TranscodeResult JS::DecodeStencil(JS::FrontendContext* fc,
const JS::DecodeOptions& options,
const JS::ReadOnlyDecodeOptions& options,
const JS::TranscodeRange& range,
JS::Stencil** stencilOut) {
RefPtr<ScriptSource> source = fc->getAllocator()->new_<ScriptSource>();

Просмотреть файл

@ -1216,7 +1216,7 @@ XDRResult StencilXDR::codeSourceData(XDRState<mode>* const xdr,
template <XDRMode mode>
/* static */
XDRResult StencilXDR::codeSource(XDRState<mode>* xdr,
const JS::DecodeOptions* maybeOptions,
const JS::ReadOnlyDecodeOptions* maybeOptions,
RefPtr<ScriptSource>& source) {
FrontendContext* fc = xdr->fc();
@ -1310,9 +1310,9 @@ XDRResult StencilXDR::codeSource(XDRState<mode>* xdr,
if (mode == XDR_DECODE) {
source->introductionType_ = maybeOptions->introductionType;
source->setIntroductionOffset(maybeOptions->introductionOffset);
if (maybeOptions->introducerFilename) {
if (maybeOptions->introducerFilename()) {
if (!source->setIntroducerFilename(
fc, maybeOptions->introducerFilename.c_str())) {
fc, maybeOptions->introducerFilename().c_str())) {
return xdr->fail(JS::TranscodeResult::Throw);
}
}
@ -1326,12 +1326,12 @@ XDRResult StencilXDR::codeSource(XDRState<mode>* xdr,
template /* static */
XDRResult
StencilXDR::codeSource(XDRState<XDR_ENCODE>* xdr,
const JS::DecodeOptions* maybeOptions,
const JS::ReadOnlyDecodeOptions* maybeOptions,
RefPtr<ScriptSource>& holder);
template /* static */
XDRResult
StencilXDR::codeSource(XDRState<XDR_DECODE>* xdr,
const JS::DecodeOptions* maybeOptions,
const JS::ReadOnlyDecodeOptions* maybeOptions,
RefPtr<ScriptSource>& holder);
JS_PUBLIC_API bool JS::GetScriptTranscodingBuildId(
@ -1406,7 +1406,7 @@ static XDRResult VersionCheck(XDRState<mode>* xdr) {
template <XDRMode mode>
static XDRResult XDRStencilHeader(XDRState<mode>* xdr,
const JS::DecodeOptions* maybeOptions,
const JS::ReadOnlyDecodeOptions* maybeOptions,
RefPtr<ScriptSource>& source) {
// The XDR-Stencil header is inserted at beginning of buffer, but it is
// computed at the end the incremental-encoding process.
@ -1468,7 +1468,8 @@ bool StencilIncrementalEncoderPtr::addDelazification(
}
XDRResult XDRStencilDecoder::codeStencil(
const JS::DecodeOptions& options, frontend::CompilationStencil& stencil) {
const JS::ReadOnlyDecodeOptions& options,
frontend::CompilationStencil& stencil) {
#ifdef DEBUG
auto sanityCheck = mozilla::MakeScopeExit(
[&] { MOZ_ASSERT(validateResultCode(fc(), resultCode())); });

Просмотреть файл

@ -15,7 +15,7 @@
namespace JS {
class DecodeOptions;
class ReadOnlyDecodeOptions;
} // namespace JS
@ -88,7 +88,7 @@ class StencilXDR {
public:
template <XDRMode mode>
static XDRResult codeSource(XDRState<mode>* xdr,
const JS::DecodeOptions* maybeOptions,
const JS::ReadOnlyDecodeOptions* maybeOptions,
RefPtr<ScriptSource>& source);
template <XDRMode mode>
@ -182,16 +182,16 @@ class XDRStencilDecoder : public XDRState<XDR_DECODE> {
MOZ_ASSERT(JS::IsTranscodingBytecodeAligned(range.begin().get()));
}
XDRResult codeStencil(const JS::DecodeOptions& options,
XDRResult codeStencil(const JS::ReadOnlyDecodeOptions& options,
frontend::CompilationStencil& stencil);
const JS::DecodeOptions& options() {
const JS::ReadOnlyDecodeOptions& options() {
MOZ_ASSERT(options_);
return *options_;
}
private:
const JS::DecodeOptions* options_ = nullptr;
const JS::ReadOnlyDecodeOptions* options_ = nullptr;
};
class XDRStencilEncoder : public XDRState<XDR_ENCODE> {

Просмотреть файл

@ -2447,6 +2447,43 @@ CompileOptions& CompileOptions::setIntroductionInfoToCaller(
return setIntroductionType(introductionType);
}
JS::OwningDecodeOptions::~OwningDecodeOptions() { release(); }
void JS::OwningDecodeOptions::release() {
js_free(const_cast<char*>(introducerFilename_.c_str()));
introducerFilename_ = JS::ConstUTF8CharsZ();
}
bool JS::OwningDecodeOptions::copy(JS::FrontendContext* maybeFc,
const JS::ReadOnlyDecodeOptions& rhs) {
copyPODOptions(rhs);
if (rhs.introducerFilename()) {
MOZ_ASSERT(maybeFc);
const char* str =
DuplicateString(maybeFc, rhs.introducerFilename().c_str()).release();
if (!str) {
return false;
}
introducerFilename_ = JS::ConstUTF8CharsZ(str);
}
return true;
}
void JS::OwningDecodeOptions::infallibleCopy(
const JS::ReadOnlyDecodeOptions& rhs) {
copyPODOptions(rhs);
MOZ_ASSERT(!rhs.introducerFilename());
}
size_t JS::OwningDecodeOptions::sizeOfExcludingThis(
mozilla::MallocSizeOf mallocSizeOf) const {
return mallocSizeOf(introducerFilename_.c_str());
}
JS_PUBLIC_API JSObject* JS_GetGlobalFromScript(JSScript* script) {
return &script->global();
}

Просмотреть файл

@ -19,7 +19,7 @@
#include "jit/IonCompileTask.h"
#include "jit/JitRuntime.h"
#include "jit/JitScript.h"
#include "js/CompileOptions.h" // JS::CompileOptions, JS::DecodeOptions, JS::ReadOnlyCompileOptions
#include "js/CompileOptions.h" // JS::CompileOptions, JS::ReadOnlyDecodeOptions, JS::ReadOnlyCompileOptions
#include "js/experimental/CompileScript.h"
#include "js/experimental/JSStencil.h"
#include "js/friend/StackLimits.h" // js::ReportOverRecursed
@ -1104,7 +1104,7 @@ JS::OffThreadToken* js::StartOffThreadCompileModuleToStencil(
}
JS::OffThreadToken* js::StartOffThreadDecodeStencil(
JSContext* cx, const JS::DecodeOptions& options,
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
const JS::TranscodeRange& range, JS::OffThreadCompileCallback callback,
void* callbackData) {
auto task =

Просмотреть файл

@ -28,6 +28,7 @@ union Utf8Unit;
namespace JS {
class OffThreadToken {};
class JS_PUBLIC_API ReadOnlyCompileOptions;
class JS_PUBLIC_API ReadOnlyDecodeOptions;
class Zone;
template <typename UnitT>
@ -234,7 +235,7 @@ JS::OffThreadToken* StartOffThreadCompileModuleToStencil(
JS::OffThreadCompileCallback callback, void* callbackData);
JS::OffThreadToken* StartOffThreadDecodeStencil(
JSContext* cx, const JS::DecodeOptions& options,
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
const JS::TranscodeRange& range, JS::OffThreadCompileCallback callback,
void* callbackData);

Просмотреть файл

@ -91,8 +91,9 @@ JS_PUBLIC_API JS::OffThreadToken* JS::CompileModuleToStencilOffThread(
}
JS_PUBLIC_API JS::OffThreadToken* JS::DecodeStencilOffThread(
JSContext* cx, const DecodeOptions& options, const TranscodeBuffer& buffer,
size_t cursor, OffThreadCompileCallback callback, void* callbackData) {
JSContext* cx, const ReadOnlyDecodeOptions& options,
const TranscodeBuffer& buffer, size_t cursor,
OffThreadCompileCallback callback, void* callbackData) {
JS::TranscodeRange range(buffer.begin() + cursor, buffer.length() - cursor);
MOZ_ASSERT(CanDecodeOffThread(cx, options, range.length()));
return StartOffThreadDecodeStencil(cx, options, range, callback,
@ -100,8 +101,9 @@ JS_PUBLIC_API JS::OffThreadToken* JS::DecodeStencilOffThread(
}
JS_PUBLIC_API JS::OffThreadToken* JS::DecodeStencilOffThread(
JSContext* cx, const DecodeOptions& options, const TranscodeRange& range,
OffThreadCompileCallback callback, void* callbackData) {
JSContext* cx, const ReadOnlyDecodeOptions& options,
const TranscodeRange& range, OffThreadCompileCallback callback,
void* callbackData) {
MOZ_ASSERT(CanDecodeOffThread(cx, options, range.length()));
return StartOffThreadDecodeStencil(cx, options, range, callback,
callbackData);
@ -125,7 +127,7 @@ JS_PUBLIC_API void JS::CancelOffThreadToken(JSContext* cx,
}
JS_PUBLIC_API bool JS::CanDecodeOffThread(JSContext* cx,
const DecodeOptions& options,
const ReadOnlyDecodeOptions& options,
size_t length) {
return CanDoOffThread(cx, options, length);
}

Просмотреть файл

@ -939,7 +939,8 @@ void ScriptPreloader::FillDecodeOptionsForCachedStencil(
}
already_AddRefed<JS::Stencil> ScriptPreloader::GetCachedStencil(
JSContext* cx, const JS::DecodeOptions& options, const nsCString& path) {
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
const nsCString& path) {
MOZ_RELEASE_ASSERT(
!(XRE_IsContentProcess() && !mCacheInitialized),
"ScriptPreloader must be initialized before getting cached "
@ -965,7 +966,8 @@ already_AddRefed<JS::Stencil> ScriptPreloader::GetCachedStencil(
}
already_AddRefed<JS::Stencil> ScriptPreloader::GetCachedStencilInternal(
JSContext* cx, const JS::DecodeOptions& options, const nsCString& path) {
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
const nsCString& path) {
auto* cachedScript = mScripts.Get(path);
if (cachedScript) {
return WaitForCachedStencil(cx, options, cachedScript);
@ -974,7 +976,8 @@ already_AddRefed<JS::Stencil> ScriptPreloader::GetCachedStencilInternal(
}
already_AddRefed<JS::Stencil> ScriptPreloader::WaitForCachedStencil(
JSContext* cx, const JS::DecodeOptions& options, CachedStencil* script) {
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
CachedStencil* script) {
if (!script->mReadyToExecute) {
MOZ_ASSERT(mDecodedStencils);
@ -1184,7 +1187,7 @@ void ScriptPreloader::StartDecodeTask(JS::HandleObject scope) {
}
bool ScriptPreloader::StartDecodeTask(
JS::DecodeOptions decodeOptions,
const JS::ReadOnlyDecodeOptions& decodeOptions,
Vector<JS::TranscodeSource>&& decodingSources) {
mDecodedStencils.emplace(decodingSources.length());
MOZ_ASSERT(mDecodedStencils);
@ -1269,7 +1272,7 @@ bool ScriptPreloader::CachedStencil::XDREncode(JSContext* cx) {
}
already_AddRefed<JS::Stencil> ScriptPreloader::CachedStencil::GetStencil(
JSContext* cx, const JS::DecodeOptions& options) {
JSContext* cx, const JS::ReadOnlyDecodeOptions& options) {
MOZ_ASSERT(mReadyToExecute);
if (mStencil) {
return do_AddRef(mStencil);

Просмотреть файл

@ -29,7 +29,7 @@
#include "nsIThread.h"
#include "nsITimer.h"
#include "js/CompileOptions.h" // JS::DecodeOptions
#include "js/CompileOptions.h" // JS::DecodeOptions, JS::ReadOnlyDecodeOptions
#include "js/experimental/JSStencil.h" // JS::Stencil
#include "js/GCAnnotations.h" // for JS_HAZ_NON_GC_POINTER
#include "js/RootingAPI.h" // for Handle, Heap
@ -108,7 +108,8 @@ class ScriptPreloader : public nsIObserver,
// Retrieves the stencil with the given cache key from the cache.
// Returns null if the stencil is not cached.
already_AddRefed<JS::Stencil> GetCachedStencil(
JSContext* cx, const JS::DecodeOptions& options, const nsCString& path);
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
const nsCString& path);
// Notes the execution of a script with the given URL and cache key.
// Depending on the stage of startup, the script may be serialized and
@ -137,7 +138,8 @@ class ScriptPreloader : public nsIObserver,
private:
Result<Ok, nsresult> InitCacheInternal(JS::Handle<JSObject*> scope = nullptr);
already_AddRefed<JS::Stencil> GetCachedStencilInternal(
JSContext* cx, const JS::DecodeOptions& options, const nsCString& path);
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
const nsCString& path);
public:
static ProcessType CurrentProcessType() {
@ -310,8 +312,8 @@ class ScriptPreloader : public nsIObserver,
bool HasArray() { return mXDRData.constructed<nsTArray<uint8_t>>(); }
already_AddRefed<JS::Stencil> GetStencil(JSContext* cx,
const JS::DecodeOptions& options);
already_AddRefed<JS::Stencil> GetStencil(
JSContext* cx, const JS::ReadOnlyDecodeOptions& options);
size_t HeapSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) {
auto size = mallocSizeOf(this);
@ -436,30 +438,28 @@ class ScriptPreloader : public nsIObserver,
// Waits for the given cached script to finish compiling off-thread, or
// decodes it synchronously on the main thread, as appropriate.
already_AddRefed<JS::Stencil> WaitForCachedStencil(
JSContext* cx, const JS::DecodeOptions& options, CachedStencil* script);
JSContext* cx, const JS::ReadOnlyDecodeOptions& options,
CachedStencil* script);
void StartDecodeTask(JS::Handle<JSObject*> scope);
private:
bool StartDecodeTask(JS::DecodeOptions decodeOptions,
bool StartDecodeTask(const JS::ReadOnlyDecodeOptions& decodeOptions,
Vector<JS::TranscodeSource>&& decodingSources);
class DecodeTask : public Runnable {
ScriptPreloader* mPreloader;
JS::DecodeOptions mDecodeOptions;
JS::OwningDecodeOptions mDecodeOptions;
Vector<JS::TranscodeSource> mDecodingSources;
public:
DecodeTask(ScriptPreloader* preloader, JS::DecodeOptions decodeOptions,
DecodeTask(ScriptPreloader* preloader,
const JS::ReadOnlyDecodeOptions& decodeOptions,
Vector<JS::TranscodeSource>&& decodingSources)
: Runnable("ScriptPreloaderDecodeTask"),
mPreloader(preloader),
mDecodeOptions(decodeOptions),
mDecodingSources(std::move(decodingSources)) {
// NOTE: the JS::DecodeOptions is created on the main thread and is going
// to be used off main thread. There shouldn't be any external data
// reference, such as filename.
MOZ_ASSERT(!decodeOptions.hasExternalData());
mDecodeOptions.infallibleCopy(decodeOptions);
}
NS_IMETHOD Run() override;

Просмотреть файл

@ -35,7 +35,8 @@ static nsresult HandleTranscodeResult(JSContext* cx,
}
nsresult ReadCachedStencil(StartupCache* cache, nsACString& cachePath,
JSContext* cx, const JS::DecodeOptions& options,
JSContext* cx,
const JS::ReadOnlyDecodeOptions& options,
JS::Stencil** stencilOut) {
MOZ_ASSERT(options.borrowBuffer);
MOZ_ASSERT(!options.usePinnedBytecode);

Просмотреть файл

@ -10,7 +10,7 @@
#include "nsString.h"
#include "js/experimental/JSStencil.h"
#include "js/CompileOptions.h" // JS::DecodeOptions
#include "js/CompileOptions.h" // JS::ReadOnlyDecodeOptions
namespace mozilla {
namespace scache {
@ -20,7 +20,7 @@ class StartupCache;
nsresult ReadCachedStencil(mozilla::scache::StartupCache* cache,
nsACString& cachePath, JSContext* cx,
const JS::DecodeOptions& options,
const JS::ReadOnlyDecodeOptions& options,
JS::Stencil** stencilOut);
nsresult WriteCachedStencil(mozilla::scache::StartupCache* cache,