forked from mirrors/gecko-dev
Bug 1857536 - Remove unneeded struct CompilationStorage r=arai
Differential Revision: https://phabricator.services.mozilla.com/D203632
This commit is contained in:
parent
8e891db9c2
commit
73e160f12c
13 changed files with 63 additions and 179 deletions
|
|
@ -207,9 +207,8 @@ JSValidatorChild::ValidatorResult JSValidatorChild::ShouldAllowJS(
|
||||||
prefableOptions.setAsmJSOption(JS::AsmJSOption::DisabledByAsmJSPref);
|
prefableOptions.setAsmJSOption(JS::AsmJSOption::DisabledByAsmJSPref);
|
||||||
|
|
||||||
JS::CompileOptions options(prefableOptions);
|
JS::CompileOptions options(prefableOptions);
|
||||||
JS::CompilationStorage storage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
JS::CompileGlobalScriptToStencil(fc, options, srcBuf, storage);
|
JS::CompileGlobalScriptToStencil(fc, options, srcBuf);
|
||||||
|
|
||||||
if (!stencil) {
|
if (!stencil) {
|
||||||
JS::ClearFrontendErrors(fc);
|
JS::ClearFrontendErrors(fc);
|
||||||
|
|
|
||||||
|
|
@ -1891,14 +1891,13 @@ class ScriptOrModuleCompileTask final : public CompileOrDecodeTask {
|
||||||
JS::SetNativeStackQuota(mFrontendContext,
|
JS::SetNativeStackQuota(mFrontendContext,
|
||||||
JS::ThreadStackQuotaForSize(stackSize));
|
JS::ThreadStackQuotaForSize(stackSize));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
auto compile = [&](auto& source) {
|
auto compile = [&](auto& source) {
|
||||||
if constexpr (target == CompilationTarget::Script) {
|
if constexpr (target == CompilationTarget::Script) {
|
||||||
return JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions,
|
return JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions,
|
||||||
source, compileStorage);
|
source);
|
||||||
}
|
}
|
||||||
return JS::CompileModuleScriptToStencil(mFrontendContext, mOptions,
|
return JS::CompileModuleScriptToStencil(mFrontendContext, mOptions,
|
||||||
source, compileStorage);
|
source);
|
||||||
};
|
};
|
||||||
return mMaybeSource.mapNonEmpty(compile);
|
return mMaybeSource.mapNonEmpty(compile);
|
||||||
}
|
}
|
||||||
|
|
@ -1962,7 +1961,6 @@ class ScriptDecodeTask final : public CompileOrDecodeTask {
|
||||||
already_AddRefed<JS::Stencil> Decode() {
|
already_AddRefed<JS::Stencil> Decode() {
|
||||||
// NOTE: JS::DecodeStencil doesn't need the stack quota.
|
// NOTE: JS::DecodeStencil doesn't need the stack quota.
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil;
|
RefPtr<JS::Stencil> stencil;
|
||||||
mResult = JS::DecodeStencil(mFrontendContext, mDecodeOptions, mRange,
|
mResult = JS::DecodeStencil(mFrontendContext, mDecodeOptions, mRange,
|
||||||
getter_AddRefs(stencil));
|
getter_AddRefs(stencil));
|
||||||
|
|
|
||||||
|
|
@ -1839,9 +1839,8 @@ class ScriptCompileTask final : public Task {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
mStencil =
|
||||||
mStencil = JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions,
|
JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions, srcBuf);
|
||||||
srcBuf, compileStorage);
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Chrome-privileged code shouldn't have any compilation error.
|
// Chrome-privileged code shouldn't have any compilation error.
|
||||||
CheckErrorsAndWarnings(mFrontendContext, mOptions);
|
CheckErrorsAndWarnings(mFrontendContext, mOptions);
|
||||||
|
|
|
||||||
|
|
@ -105,71 +105,21 @@ JS_PUBLIC_API const JSErrorReport* GetFrontendWarningAt(
|
||||||
JS::FrontendContext* fc, size_t index,
|
JS::FrontendContext* fc, size_t index,
|
||||||
const JS::ReadOnlyCompileOptions& options);
|
const JS::ReadOnlyCompileOptions& options);
|
||||||
|
|
||||||
// Temporary storage used during compiling and preparing to instantiate a
|
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileGlobalScriptToStencil(
|
||||||
// Stencil.
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
||||||
//
|
JS::SourceText<mozilla::Utf8Unit>& srcBuf);
|
||||||
// Off-thread consumers can allocate this instance off main thread, and pass it
|
|
||||||
// back to the main thread, in order to reduce the main thread allocation.
|
|
||||||
struct JS_PUBLIC_API CompilationStorage {
|
|
||||||
private:
|
|
||||||
// Owned CompilationInput.
|
|
||||||
//
|
|
||||||
// This uses raw pointer instead of UniquePtr because CompilationInput
|
|
||||||
// is opaque.
|
|
||||||
JS_HAZ_NON_GC_POINTER js::frontend::CompilationInput* input_ = nullptr;
|
|
||||||
bool isBorrowed_ = false;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CompilationStorage() = default;
|
|
||||||
explicit CompilationStorage(js::frontend::CompilationInput* input)
|
|
||||||
: input_(input), isBorrowed_(true) {}
|
|
||||||
CompilationStorage(CompilationStorage&& other)
|
|
||||||
: input_(other.input_), isBorrowed_(other.isBorrowed_) {
|
|
||||||
other.input_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
~CompilationStorage();
|
|
||||||
|
|
||||||
private:
|
|
||||||
CompilationStorage(const CompilationStorage& other) = delete;
|
|
||||||
void operator=(const CompilationStorage& aOther) = delete;
|
|
||||||
|
|
||||||
public:
|
|
||||||
bool hasInput() { return !!input_; }
|
|
||||||
|
|
||||||
// Internal function that initializes the CompilationInput. It should only be
|
|
||||||
// called once.
|
|
||||||
bool allocateInput(FrontendContext* fc,
|
|
||||||
const JS::ReadOnlyCompileOptions& options);
|
|
||||||
|
|
||||||
js::frontend::CompilationInput& getInput() {
|
|
||||||
MOZ_ASSERT(hasInput());
|
|
||||||
return *input_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size of dynamic data. Note that GC data is counted by GC and not here.
|
|
||||||
size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
||||||
|
|
||||||
void trace(JSTracer* trc);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileGlobalScriptToStencil(
|
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileGlobalScriptToStencil(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
||||||
JS::SourceText<mozilla::Utf8Unit>& srcBuf,
|
JS::SourceText<char16_t>& srcBuf);
|
||||||
JS::CompilationStorage& compileStorage);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileGlobalScriptToStencil(
|
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
|
||||||
JS::SourceText<char16_t>& srcBuf, JS::CompilationStorage& compileStorage);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileModuleScriptToStencil(
|
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileModuleScriptToStencil(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
||||||
JS::SourceText<mozilla::Utf8Unit>& srcBuf,
|
JS::SourceText<mozilla::Utf8Unit>& srcBuf);
|
||||||
JS::CompilationStorage& compileStorage);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileModuleScriptToStencil(
|
extern JS_PUBLIC_API already_AddRefed<JS::Stencil> CompileModuleScriptToStencil(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
||||||
JS::SourceText<char16_t>& srcBuf, JS::CompilationStorage& compileStorage);
|
JS::SourceText<char16_t>& srcBuf);
|
||||||
|
|
||||||
extern JS_PUBLIC_API bool PrepareForInstantiate(
|
extern JS_PUBLIC_API bool PrepareForInstantiate(
|
||||||
JS::FrontendContext* fc, JS::Stencil& stencil,
|
JS::FrontendContext* fc, JS::Stencil& stencil,
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,6 @@ struct PreallocatedCompilationGCOutput;
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
struct JS_PUBLIC_API CompilationStorage;
|
|
||||||
|
|
||||||
using Stencil = js::frontend::CompilationStencil;
|
using Stencil = js::frontend::CompilationStencil;
|
||||||
using FrontendContext = js::FrontendContext;
|
using FrontendContext = js::FrontendContext;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7240,13 +7240,10 @@ static bool CompileToStencil(JSContext* cx, uint32_t argc, Value* vp) {
|
||||||
|
|
||||||
AutoReportFrontendContext fc(cx);
|
AutoReportFrontendContext fc(cx);
|
||||||
RefPtr<JS::Stencil> stencil;
|
RefPtr<JS::Stencil> stencil;
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
if (isModule) {
|
if (isModule) {
|
||||||
stencil =
|
stencil = JS::CompileModuleScriptToStencil(&fc, options, srcBuf);
|
||||||
JS::CompileModuleScriptToStencil(&fc, options, srcBuf, compileStorage);
|
|
||||||
} else {
|
} else {
|
||||||
stencil =
|
stencil = JS::CompileGlobalScriptToStencil(&fc, options, srcBuf);
|
||||||
JS::CompileGlobalScriptToStencil(&fc, options, srcBuf, compileStorage);
|
|
||||||
}
|
}
|
||||||
if (!stencil) {
|
if (!stencil) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -87,73 +87,46 @@ JS_PUBLIC_API const JSErrorReport* JS::GetFrontendWarningAt(
|
||||||
return &fc->warnings()[index];
|
return &fc->warnings()[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::CompilationStorage::~CompilationStorage() {
|
|
||||||
if (input_ && !isBorrowed_) {
|
|
||||||
js_delete(input_);
|
|
||||||
input_ = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t JS::CompilationStorage::sizeOfIncludingThis(
|
|
||||||
mozilla::MallocSizeOf mallocSizeOf) const {
|
|
||||||
size_t sizeOfCompilationInput =
|
|
||||||
input_ ? input_->sizeOfExcludingThis(mallocSizeOf) : 0;
|
|
||||||
return mallocSizeOf(this) + sizeOfCompilationInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JS::CompilationStorage::allocateInput(
|
|
||||||
FrontendContext* fc, const JS::ReadOnlyCompileOptions& options) {
|
|
||||||
MOZ_ASSERT(!input_);
|
|
||||||
input_ = fc->getAllocator()->new_<frontend::CompilationInput>(options);
|
|
||||||
return !!input_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JS::CompilationStorage::trace(JSTracer* trc) {
|
|
||||||
if (input_) {
|
|
||||||
input_->trace(trc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename CharT>
|
template <typename CharT>
|
||||||
static already_AddRefed<JS::Stencil> CompileGlobalScriptToStencilImpl(
|
static already_AddRefed<JS::Stencil> CompileGlobalScriptToStencilImpl(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
||||||
JS::SourceText<CharT>& srcBuf, JS::CompilationStorage& compilationStorage) {
|
JS::SourceText<CharT>& srcBuf) {
|
||||||
ScopeKind scopeKind =
|
ScopeKind scopeKind =
|
||||||
options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global;
|
options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global;
|
||||||
|
|
||||||
JS::SourceText<CharT> data(std::move(srcBuf));
|
JS::SourceText<CharT> data(std::move(srcBuf));
|
||||||
|
|
||||||
compilationStorage.allocateInput(fc, options);
|
frontend::CompilationInput compilationInput(options);
|
||||||
if (!compilationStorage.hasInput()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
frontend::NoScopeBindingCache scopeCache;
|
frontend::NoScopeBindingCache scopeCache;
|
||||||
LifoAlloc tempLifoAlloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE);
|
LifoAlloc tempLifoAlloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE);
|
||||||
RefPtr<frontend::CompilationStencil> stencil_ =
|
RefPtr<JS::Stencil> stencil_ = frontend::CompileGlobalScriptToStencil(
|
||||||
frontend::CompileGlobalScriptToStencil(nullptr, fc, tempLifoAlloc,
|
nullptr, fc, tempLifoAlloc, compilationInput, &scopeCache, data,
|
||||||
compilationStorage.getInput(),
|
scopeKind);
|
||||||
&scopeCache, data, scopeKind);
|
// CompilationInput initialized with CompileGlobalScriptToStencil only
|
||||||
|
// references information from the JS::Stencil context and the
|
||||||
|
// ref-counted ScriptSource, which are both GC-free.
|
||||||
|
JS_HAZ_VALUE_IS_GC_SAFE(compilationInput);
|
||||||
return stencil_.forget();
|
return stencil_.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename CharT>
|
template <typename CharT>
|
||||||
static already_AddRefed<JS::Stencil> CompileModuleScriptToStencilImpl(
|
static already_AddRefed<JS::Stencil> CompileModuleScriptToStencilImpl(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput,
|
||||||
JS::SourceText<CharT>& srcBuf, JS::CompilationStorage& compilationStorage) {
|
JS::SourceText<CharT>& srcBuf) {
|
||||||
JS::CompileOptions options(nullptr, optionsInput);
|
JS::CompileOptions options(nullptr, optionsInput);
|
||||||
options.setModule();
|
options.setModule();
|
||||||
|
|
||||||
compilationStorage.allocateInput(fc, options);
|
frontend::CompilationInput compilationInput(options);
|
||||||
if (!compilationStorage.hasInput()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
NoScopeBindingCache scopeCache;
|
NoScopeBindingCache scopeCache;
|
||||||
js::LifoAlloc tempLifoAlloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE);
|
js::LifoAlloc tempLifoAlloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE);
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil = ParseModuleToStencil(
|
||||||
ParseModuleToStencil(nullptr, fc, tempLifoAlloc,
|
nullptr, fc, tempLifoAlloc, compilationInput, &scopeCache, srcBuf);
|
||||||
compilationStorage.getInput(), &scopeCache, srcBuf);
|
// CompilationInput initialized with ParseModuleToStencil only
|
||||||
|
// references information from the JS::Stencil context and the
|
||||||
|
// ref-counted ScriptSource, which are both GC-free.
|
||||||
|
JS_HAZ_VALUE_IS_GC_SAFE(compilationInput);
|
||||||
if (!stencil) {
|
if (!stencil) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -164,42 +137,38 @@ static already_AddRefed<JS::Stencil> CompileModuleScriptToStencilImpl(
|
||||||
|
|
||||||
already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
||||||
JS::SourceText<mozilla::Utf8Unit>& srcBuf,
|
JS::SourceText<mozilla::Utf8Unit>& srcBuf) {
|
||||||
JS::CompilationStorage& compileStorage) {
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fc->assertNativeStackLimitThread();
|
fc->assertNativeStackLimitThread();
|
||||||
#endif
|
#endif
|
||||||
return CompileGlobalScriptToStencilImpl(fc, options, srcBuf, compileStorage);
|
return CompileGlobalScriptToStencilImpl(fc, options, srcBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options,
|
||||||
JS::SourceText<char16_t>& srcBuf, JS::CompilationStorage& compileStorage) {
|
JS::SourceText<char16_t>& srcBuf) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fc->assertNativeStackLimitThread();
|
fc->assertNativeStackLimitThread();
|
||||||
#endif
|
#endif
|
||||||
return CompileGlobalScriptToStencilImpl(fc, options, srcBuf, compileStorage);
|
return CompileGlobalScriptToStencilImpl(fc, options, srcBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<JS::Stencil> JS::CompileModuleScriptToStencil(
|
already_AddRefed<JS::Stencil> JS::CompileModuleScriptToStencil(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput,
|
||||||
JS::SourceText<mozilla::Utf8Unit>& srcBuf,
|
JS::SourceText<mozilla::Utf8Unit>& srcBuf) {
|
||||||
JS::CompilationStorage& compileStorage) {
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fc->assertNativeStackLimitThread();
|
fc->assertNativeStackLimitThread();
|
||||||
#endif
|
#endif
|
||||||
return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf,
|
return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf);
|
||||||
compileStorage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<JS::Stencil> JS::CompileModuleScriptToStencil(
|
already_AddRefed<JS::Stencil> JS::CompileModuleScriptToStencil(
|
||||||
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput,
|
JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput,
|
||||||
JS::SourceText<char16_t>& srcBuf, JS::CompilationStorage& compileStorage) {
|
JS::SourceText<char16_t>& srcBuf) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fc->assertNativeStackLimitThread();
|
fc->assertNativeStackLimitThread();
|
||||||
#endif
|
#endif
|
||||||
return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf,
|
return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf);
|
||||||
compileStorage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JS::PrepareForInstantiate(JS::FrontendContext* fc, JS::Stencil& stencil,
|
bool JS::PrepareForInstantiate(JS::FrontendContext* fc, JS::Stencil& stencil,
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,8 @@ bool testCompile() {
|
||||||
CHECK(buf16.init(cx, src_16.data(), src_16.length(),
|
CHECK(buf16.init(cx, src_16.data(), src_16.length(),
|
||||||
JS::SourceOwnership::Borrowed));
|
JS::SourceOwnership::Borrowed));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileGlobalScriptToStencil(fc, options, buf16, compileStorage);
|
CompileGlobalScriptToStencil(fc, options, buf16);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
CHECK(stencil->scriptExtra.size() == 1);
|
CHECK(stencil->scriptExtra.size() == 1);
|
||||||
CHECK(stencil->scriptExtra[0].extent.sourceStart == 0);
|
CHECK(stencil->scriptExtra[0].extent.sourceStart == 0);
|
||||||
|
|
@ -63,7 +62,6 @@ bool testCompile() {
|
||||||
CHECK(stencil->scriptData.size() == 1);
|
CHECK(stencil->scriptData.size() == 1);
|
||||||
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
||||||
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
||||||
CHECK(compileStorage.hasInput());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // 8-bit characters
|
{ // 8-bit characters
|
||||||
|
|
@ -71,9 +69,8 @@ bool testCompile() {
|
||||||
CHECK(
|
CHECK(
|
||||||
buf8.init(cx, src.data(), src.length(), JS::SourceOwnership::Borrowed));
|
buf8.init(cx, src.data(), src.length(), JS::SourceOwnership::Borrowed));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileGlobalScriptToStencil(fc, options, buf8, compileStorage);
|
CompileGlobalScriptToStencil(fc, options, buf8);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
CHECK(stencil->scriptExtra.size() == 1);
|
CHECK(stencil->scriptExtra.size() == 1);
|
||||||
CHECK(stencil->scriptExtra[0].extent.sourceStart == 0);
|
CHECK(stencil->scriptExtra[0].extent.sourceStart == 0);
|
||||||
|
|
@ -81,7 +78,6 @@ bool testCompile() {
|
||||||
CHECK(stencil->scriptData.size() == 1);
|
CHECK(stencil->scriptData.size() == 1);
|
||||||
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
||||||
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
||||||
CHECK(compileStorage.hasInput());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // propagates failures
|
{ // propagates failures
|
||||||
|
|
@ -90,9 +86,8 @@ bool testCompile() {
|
||||||
CHECK(srcBuf.init(cx, badSrc.data(), badSrc.length(),
|
CHECK(srcBuf.init(cx, badSrc.data(), badSrc.length(),
|
||||||
JS::SourceOwnership::Borrowed));
|
JS::SourceOwnership::Borrowed));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileGlobalScriptToStencil(fc, options, srcBuf, compileStorage);
|
CompileGlobalScriptToStencil(fc, options, srcBuf);
|
||||||
CHECK(!stencil);
|
CHECK(!stencil);
|
||||||
CHECK(fc->maybeError().isSome());
|
CHECK(fc->maybeError().isSome());
|
||||||
const js::CompileError& error = fc->maybeError().ref();
|
const js::CompileError& error = fc->maybeError().ref();
|
||||||
|
|
@ -120,9 +115,8 @@ bool testNonsyntacticCompile() {
|
||||||
auto destroyFc =
|
auto destroyFc =
|
||||||
mozilla::MakeScopeExit([fc] { JS::DestroyFrontendContext(fc); });
|
mozilla::MakeScopeExit([fc] { JS::DestroyFrontendContext(fc); });
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileGlobalScriptToStencil(fc, options, srcBuf, compileStorage);
|
CompileGlobalScriptToStencil(fc, options, srcBuf);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
|
|
||||||
JS::InstantiateOptions instantiateOptions(options);
|
JS::InstantiateOptions instantiateOptions(options);
|
||||||
|
|
@ -153,9 +147,8 @@ bool testCompileModule() {
|
||||||
CHECK(buf16.init(cx, src_16.data(), src_16.length(),
|
CHECK(buf16.init(cx, src_16.data(), src_16.length(),
|
||||||
JS::SourceOwnership::Borrowed));
|
JS::SourceOwnership::Borrowed));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileModuleScriptToStencil(fc, options, buf16, compileStorage);
|
CompileModuleScriptToStencil(fc, options, buf16);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
CHECK(stencil->isModule());
|
CHECK(stencil->isModule());
|
||||||
CHECK(stencil->scriptExtra.size() == 1);
|
CHECK(stencil->scriptExtra.size() == 1);
|
||||||
|
|
@ -164,7 +157,6 @@ bool testCompileModule() {
|
||||||
CHECK(stencil->scriptData.size() == 1);
|
CHECK(stencil->scriptData.size() == 1);
|
||||||
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
||||||
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
||||||
CHECK(compileStorage.hasInput());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // 8-bit characters
|
{ // 8-bit characters
|
||||||
|
|
@ -172,9 +164,8 @@ bool testCompileModule() {
|
||||||
CHECK(
|
CHECK(
|
||||||
buf8.init(cx, src.data(), src.length(), JS::SourceOwnership::Borrowed));
|
buf8.init(cx, src.data(), src.length(), JS::SourceOwnership::Borrowed));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileModuleScriptToStencil(fc, options, buf8, compileStorage);
|
CompileModuleScriptToStencil(fc, options, buf8);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
CHECK(stencil->scriptExtra.size() == 1);
|
CHECK(stencil->scriptExtra.size() == 1);
|
||||||
CHECK(stencil->scriptExtra[0].extent.sourceStart == 0);
|
CHECK(stencil->scriptExtra[0].extent.sourceStart == 0);
|
||||||
|
|
@ -182,7 +173,6 @@ bool testCompileModule() {
|
||||||
CHECK(stencil->scriptData.size() == 1);
|
CHECK(stencil->scriptData.size() == 1);
|
||||||
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
CHECK(stencil->scriptData[0].hasSharedData()); // has generated bytecode
|
||||||
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
CHECK(stencil->scriptData[0].gcThingsLength == 1);
|
||||||
CHECK(compileStorage.hasInput());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // propagates failures
|
{ // propagates failures
|
||||||
|
|
@ -191,9 +181,8 @@ bool testCompileModule() {
|
||||||
CHECK(srcBuf.init(cx, badSrc.data(), badSrc.length(),
|
CHECK(srcBuf.init(cx, badSrc.data(), badSrc.length(),
|
||||||
JS::SourceOwnership::Borrowed));
|
JS::SourceOwnership::Borrowed));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileModuleScriptToStencil(fc, options, srcBuf, compileStorage);
|
CompileModuleScriptToStencil(fc, options, srcBuf);
|
||||||
CHECK(!stencil);
|
CHECK(!stencil);
|
||||||
CHECK(fc->maybeError().isSome());
|
CHECK(fc->maybeError().isSome());
|
||||||
const js::CompileError& error = fc->maybeError().ref();
|
const js::CompileError& error = fc->maybeError().ref();
|
||||||
|
|
@ -220,15 +209,12 @@ bool testPrepareForInstantiate() {
|
||||||
auto destroyFc =
|
auto destroyFc =
|
||||||
mozilla::MakeScopeExit([fc] { JS::DestroyFrontendContext(fc); });
|
mozilla::MakeScopeExit([fc] { JS::DestroyFrontendContext(fc); });
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
CompileGlobalScriptToStencil(fc, options, buf16, compileStorage);
|
CompileGlobalScriptToStencil(fc, options, buf16);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
CHECK(stencil->scriptData.size() == 2);
|
CHECK(stencil->scriptData.size() == 2);
|
||||||
CHECK(stencil->scopeData.size() == 1); // function f
|
CHECK(stencil->scopeData.size() == 1); // function f
|
||||||
CHECK(stencil->parserAtomData.size() == 1); // 'field'
|
CHECK(stencil->parserAtomData.size() == 1); // 'field'
|
||||||
CHECK(compileStorage.hasInput());
|
|
||||||
CHECK(compileStorage.getInput().atomCache.empty());
|
|
||||||
|
|
||||||
JS::InstantiationStorage storage;
|
JS::InstantiationStorage storage;
|
||||||
CHECK(JS::PrepareForInstantiate(fc, *stencil, storage));
|
CHECK(JS::PrepareForInstantiate(fc, *stencil, storage));
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,9 @@ BEGIN_FRONTEND_TEST(testFrontendContextCompileGlobalScriptToStencil) {
|
||||||
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
||||||
CHECK(
|
CHECK(
|
||||||
srcBuf.init(fc, source, strlen(source), JS::SourceOwnership::Borrowed));
|
srcBuf.init(fc, source, strlen(source), JS::SourceOwnership::Borrowed));
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
JS::CompileGlobalScriptToStencil(fc, options, srcBuf, compileStorage);
|
JS::CompileGlobalScriptToStencil(fc, options, srcBuf);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
CHECK(compileStorage.hasInput());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -54,11 +52,9 @@ BEGIN_FRONTEND_TEST(testFrontendContextCompileGlobalScriptToStencil) {
|
||||||
JS::SourceText<char16_t> srcBuf;
|
JS::SourceText<char16_t> srcBuf;
|
||||||
CHECK(srcBuf.init(fc, source, std::char_traits<char16_t>::length(source),
|
CHECK(srcBuf.init(fc, source, std::char_traits<char16_t>::length(source),
|
||||||
JS::SourceOwnership::Borrowed));
|
JS::SourceOwnership::Borrowed));
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
JS::CompileGlobalScriptToStencil(fc, options, srcBuf, compileStorage);
|
JS::CompileGlobalScriptToStencil(fc, options, srcBuf);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
CHECK(compileStorage.hasInput());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::DestroyFrontendContext(fc);
|
JS::DestroyFrontendContext(fc);
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,8 @@ BEGIN_TEST(testFrontendErrors_error) {
|
||||||
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
||||||
CHECK(
|
CHECK(
|
||||||
srcBuf.init(fc, source, strlen(source), JS::SourceOwnership::Borrowed));
|
srcBuf.init(fc, source, strlen(source), JS::SourceOwnership::Borrowed));
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
JS::CompileGlobalScriptToStencil(fc, options, srcBuf, compileStorage);
|
JS::CompileGlobalScriptToStencil(fc, options, srcBuf);
|
||||||
CHECK(!stencil);
|
CHECK(!stencil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,9 +132,8 @@ BEGIN_TEST(testFrontendErrors_warning) {
|
||||||
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
||||||
CHECK(
|
CHECK(
|
||||||
srcBuf.init(fc, source, strlen(source), JS::SourceOwnership::Borrowed));
|
srcBuf.init(fc, source, strlen(source), JS::SourceOwnership::Borrowed));
|
||||||
JS::CompilationStorage compileStorage;
|
|
||||||
RefPtr<JS::Stencil> stencil =
|
RefPtr<JS::Stencil> stencil =
|
||||||
JS::CompileGlobalScriptToStencil(fc, options, srcBuf, compileStorage);
|
JS::CompileGlobalScriptToStencil(fc, options, srcBuf);
|
||||||
CHECK(stencil);
|
CHECK(stencil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@
|
||||||
#include "js/ErrorReport.h" // JS::PrintError
|
#include "js/ErrorReport.h" // JS::PrintError
|
||||||
#include "js/Exception.h" // JS::StealPendingExceptionStack
|
#include "js/Exception.h" // JS::StealPendingExceptionStack
|
||||||
#include "js/experimental/CodeCoverage.h" // js::EnableCodeCoverage
|
#include "js/experimental/CodeCoverage.h" // js::EnableCodeCoverage
|
||||||
#include "js/experimental/CompileScript.h" // JS::NewFrontendContext, JS::DestroyFrontendContext, JS::HadFrontendErrors, JS::ConvertFrontendErrorsToRuntimeErrors, JS::CompileGlobalScriptToStencil, JS::CompileModuleScriptToStencil, JS::CompilationStorage
|
#include "js/experimental/CompileScript.h" // JS::NewFrontendContext, JS::DestroyFrontendContext, JS::HadFrontendErrors, JS::ConvertFrontendErrorsToRuntimeErrors, JS::CompileGlobalScriptToStencil, JS::CompileModuleScriptToStencil
|
||||||
#include "js/experimental/CTypes.h" // JS::InitCTypesClass
|
#include "js/experimental/CTypes.h" // JS::InitCTypesClass
|
||||||
#include "js/experimental/Intl.h" // JS::AddMoz{DateTimeFormat,DisplayNames}Constructor
|
#include "js/experimental/Intl.h" // JS::AddMoz{DateTimeFormat,DisplayNames}Constructor
|
||||||
#include "js/experimental/JitInfo.h" // JSJit{Getter,Setter,Method}CallArgs, JSJitGetterInfo, JSJit{Getter,Setter}Op, JSJitInfo
|
#include "js/experimental/JitInfo.h" // JSJit{Getter,Setter,Method}CallArgs, JSJitGetterInfo, JSJit{Getter,Setter}Op, JSJitInfo
|
||||||
|
|
@ -637,15 +637,11 @@ void OffThreadJob::run() {
|
||||||
|
|
||||||
switch (kind_) {
|
switch (kind_) {
|
||||||
case Kind::CompileScript: {
|
case Kind::CompileScript: {
|
||||||
JS::CompilationStorage compileStorage;
|
stencil_ = JS::CompileGlobalScriptToStencil(fc_, options_, srcBuf_);
|
||||||
stencil_ = JS::CompileGlobalScriptToStencil(fc_, options_, srcBuf_,
|
|
||||||
compileStorage);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Kind::CompileModule: {
|
case Kind::CompileModule: {
|
||||||
JS::CompilationStorage compileStorage;
|
stencil_ = JS::CompileModuleScriptToStencil(fc_, options_, srcBuf_);
|
||||||
stencil_ = JS::CompileModuleScriptToStencil(fc_, options_, srcBuf_,
|
|
||||||
compileStorage);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Kind::Decode: {
|
case Kind::Decode: {
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,12 @@
|
||||||
#include <stdint.h> // uint32_t, uint64_t
|
#include <stdint.h> // uint32_t, uint64_t
|
||||||
#include <utility> // std::move
|
#include <utility> // std::move
|
||||||
|
|
||||||
#include "ds/Fifo.h" // Fifo
|
#include "ds/Fifo.h" // Fifo
|
||||||
#include "frontend/CompilationStencil.h" // frontend::CompilationStencil
|
#include "frontend/CompilationStencil.h" // frontend::CompilationStencil
|
||||||
#include "gc/GCRuntime.h" // gc::GCRuntime
|
#include "gc/GCRuntime.h" // gc::GCRuntime
|
||||||
#include "js/AllocPolicy.h" // SystemAllocPolicy
|
#include "js/AllocPolicy.h" // SystemAllocPolicy
|
||||||
#include "js/CompileOptions.h" // JS::ReadOnlyCompileOptions
|
#include "js/CompileOptions.h" // JS::ReadOnlyCompileOptions
|
||||||
#include "js/experimental/CompileScript.h" // JS::CompilationStorage
|
#include "js/experimental/JSStencil.h" // JS::InstantiationStorage
|
||||||
#include "js/experimental/JSStencil.h" // JS::InstantiationStorage
|
|
||||||
#include "js/HelperThreadAPI.h" // JS::HelperThreadTaskCallback, JS::DispatchReason
|
#include "js/HelperThreadAPI.h" // JS::HelperThreadTaskCallback, JS::DispatchReason
|
||||||
#include "js/MemoryMetrics.h" // JS::GlobalStats
|
#include "js/MemoryMetrics.h" // JS::GlobalStats
|
||||||
#include "js/ProfilingStack.h" // JS::RegisterThreadCallback, JS::UnregisterThreadCallback
|
#include "js/ProfilingStack.h" // JS::RegisterThreadCallback, JS::UnregisterThreadCallback
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
#include "js/CompileOptions.h" // JS::CompileOptions, JS::OwningCompileOptions
|
#include "js/CompileOptions.h" // JS::CompileOptions, JS::OwningCompileOptions
|
||||||
#include "js/CompilationAndEvaluation.h"
|
#include "js/CompilationAndEvaluation.h"
|
||||||
#include "js/experimental/CompileScript.h" // JS::CompileGlobalScriptToStencil, JS::NewFrontendContext, JS::DestroyFrontendContext, JS::SetNativeStackQuota, JS::ThreadStackQuotaForSize, JS::HadFrontendErrors, JS::ConvertFrontendErrorsToRuntimeErrors
|
#include "js/experimental/CompileScript.h" // JS::CompileGlobalScriptToStencil, JS::NewFrontendContext, JS::DestroyFrontendContext, JS::SetNativeStackQuota, JS::ThreadStackQuotaForSize, JS::HadFrontendErrors, JS::ConvertFrontendErrorsToRuntimeErrors
|
||||||
#include "js/experimental/JSStencil.h" // JS::Stencil, JS::CompileGlobalScriptToStencil, JS::InstantiateGlobalStencil, JS::CompilationStorage
|
#include "js/experimental/JSStencil.h" // JS::Stencil, JS::CompileGlobalScriptToStencil, JS::InstantiateGlobalStencil
|
||||||
#include "js/SourceText.h" // JS::SourceText
|
#include "js/SourceText.h" // JS::SourceText
|
||||||
#include "js/Utility.h"
|
#include "js/Utility.h"
|
||||||
|
|
||||||
#include "mozilla/AlreadyAddRefed.h" // already_AddRefed
|
#include "mozilla/AlreadyAddRefed.h" // already_AddRefed
|
||||||
|
|
@ -119,9 +119,8 @@ class AsyncScriptCompileTask final : public Task {
|
||||||
JS::SetNativeStackQuota(mFrontendContext,
|
JS::SetNativeStackQuota(mFrontendContext,
|
||||||
JS::ThreadStackQuotaForSize(stackSize));
|
JS::ThreadStackQuotaForSize(stackSize));
|
||||||
|
|
||||||
JS::CompilationStorage compileStorage;
|
mStencil =
|
||||||
mStencil = JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions,
|
JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions, mSrcBuf);
|
||||||
mSrcBuf, compileStorage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel the task.
|
// Cancel the task.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue