mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 04:09:50 +00:00
Bug 1700954 - Remove remaining BinAST fragments from ScriptLoader. r=arai,hsivonen,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D109765
This commit is contained in:
parent
eebd53c51c
commit
9b6e632d81
@ -133,7 +133,6 @@ js/public/
|
||||
js/xpconnect/
|
||||
js/src/devtools/
|
||||
js/src/jit-test/
|
||||
js/src/jsapi-tests/binast/
|
||||
js/src/tests/
|
||||
js/src/Y.js
|
||||
|
||||
|
@ -247,16 +247,6 @@ nsresult JSExecutionContext::JoinDecode(JS::OffThreadToken** aOffThreadToken) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult JSExecutionContext::JoinDecodeBinAST(
|
||||
JS::OffThreadToken** aOffThreadToken) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult JSExecutionContext::DecodeBinAST(JS::CompileOptions& aCompileOptions,
|
||||
const uint8_t* aBuf, size_t aLength) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
JSScript* JSExecutionContext::GetScript() {
|
||||
#ifdef DEBUG
|
||||
MOZ_ASSERT(!mSkip);
|
||||
|
@ -137,12 +137,6 @@ class MOZ_STACK_CLASS JSExecutionContext final {
|
||||
// thread.
|
||||
nsresult JoinDecode(JS::OffThreadToken** aOffThreadToken);
|
||||
|
||||
nsresult JoinDecodeBinAST(JS::OffThreadToken** aOffThreadToken);
|
||||
|
||||
// Decode a BinAST encoded script contained in a buffer.
|
||||
nsresult DecodeBinAST(JS::CompileOptions& aCompileOptions,
|
||||
const uint8_t* aBuf, size_t aLength);
|
||||
|
||||
// Get a successfully compiled script.
|
||||
JSScript* GetScript();
|
||||
|
||||
|
@ -63,8 +63,6 @@ class nsJSUtils {
|
||||
const nsAString& aBody,
|
||||
JSObject** aFunctionObject);
|
||||
|
||||
static bool BinASTEncodingEnabled() { return false; }
|
||||
|
||||
static nsresult CompileModule(JSContext* aCx,
|
||||
JS::SourceText<char16_t>& aSrcBuf,
|
||||
JS::Handle<JSObject*> aEvaluationGlobal,
|
||||
|
@ -151,18 +151,6 @@ ScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader,
|
||||
rv = DecodeRawData(aData, aDataLength, /* aEndOfStream = */ false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// If SRI is required for this load, appending new bytes to the hash.
|
||||
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
|
||||
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
|
||||
}
|
||||
} else if (mRequest->IsBinASTSource()) {
|
||||
if (!mRequest->ScriptBinASTData().append(aData, aDataLength)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Below we will/shall consume entire data chunk.
|
||||
*aConsumedLength = aDataLength;
|
||||
|
||||
// If SRI is required for this load, appending new bytes to the hash.
|
||||
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
|
||||
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
|
||||
@ -326,28 +314,6 @@ nsresult ScriptLoadHandler::EnsureKnownDataType(
|
||||
MOZ_ASSERT(altDataType.IsEmpty());
|
||||
}
|
||||
|
||||
if (nsJSUtils::BinASTEncodingEnabled()) {
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(req);
|
||||
if (httpChannel) {
|
||||
nsAutoCString mimeType;
|
||||
httpChannel->GetContentType(mimeType);
|
||||
if (mimeType.LowerCaseEqualsASCII(APPLICATION_JAVASCRIPT_BINAST)) {
|
||||
if (mRequest->ShouldAcceptBinASTEncoding()) {
|
||||
mRequest->SetBinASTSource();
|
||||
TRACE_FOR_TEST(mRequest->GetScriptElement(),
|
||||
"scriptloader_load_source");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If the request isn't allowed to accept BinAST, fallback to text
|
||||
// source. The possibly binary source will be passed to normal
|
||||
// JS parser and will throw error there.
|
||||
mRequest->SetTextSource();
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mRequest->SetTextSource();
|
||||
TRACE_FOR_TEST(mRequest->GetScriptElement(), "scriptloader_load_source");
|
||||
|
||||
@ -396,15 +362,6 @@ ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
LOG(("ScriptLoadRequest (%p): Source length in code units = %u",
|
||||
mRequest.get(), unsigned(mRequest->ScriptTextLength())));
|
||||
|
||||
// If SRI is required for this load, appending new bytes to the hash.
|
||||
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
|
||||
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
|
||||
}
|
||||
} else if (mRequest->IsBinASTSource()) {
|
||||
if (!mRequest->ScriptBinASTData().append(aData, aDataLength)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// If SRI is required for this load, appending new bytes to the hash.
|
||||
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
|
||||
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
|
||||
|
@ -221,22 +221,14 @@ void ScriptLoadRequest::SetTextSource() {
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptLoadRequest::SetBinASTSource() { MOZ_CRASH("BinAST not supported"); }
|
||||
|
||||
void ScriptLoadRequest::SetBytecode() {
|
||||
MOZ_ASSERT(IsUnknownDataType());
|
||||
mDataType = DataType::eBytecode;
|
||||
}
|
||||
|
||||
bool ScriptLoadRequest::ShouldAcceptBinASTEncoding() const {
|
||||
MOZ_CRASH("BinAST not supported");
|
||||
}
|
||||
|
||||
void ScriptLoadRequest::ClearScriptSource() {
|
||||
if (IsTextSource()) {
|
||||
ClearScriptText();
|
||||
} else if (IsBinASTSource()) {
|
||||
ScriptBinASTData().clearAndFree();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,22 +162,15 @@ class ScriptLoadRequest
|
||||
}
|
||||
|
||||
// Type of data provided by the nsChannel.
|
||||
enum class DataType : uint8_t {
|
||||
eUnknown,
|
||||
eTextSource,
|
||||
eBinASTSource,
|
||||
eBytecode
|
||||
};
|
||||
enum class DataType : uint8_t { eUnknown, eTextSource, eBytecode };
|
||||
|
||||
bool IsUnknownDataType() const { return mDataType == DataType::eUnknown; }
|
||||
bool IsTextSource() const { return mDataType == DataType::eTextSource; }
|
||||
bool IsBinASTSource() const { return false; }
|
||||
bool IsSource() const { return IsTextSource() || IsBinASTSource(); }
|
||||
bool IsSource() const { return IsTextSource(); }
|
||||
bool IsBytecode() const { return mDataType == DataType::eBytecode; }
|
||||
|
||||
void SetUnknownDataType();
|
||||
void SetTextSource();
|
||||
void SetBinASTSource();
|
||||
void SetBytecode();
|
||||
|
||||
// Use a vector backed by the JS allocator for script text so that contents
|
||||
@ -186,10 +179,6 @@ class ScriptLoadRequest
|
||||
template <typename Unit>
|
||||
using ScriptTextBuffer = Vector<Unit, 0, js::MallocAllocPolicy>;
|
||||
|
||||
// BinAST data isn't transferred to the JS engine, so it doesn't need to use
|
||||
// the JS allocator.
|
||||
using BinASTSourceBuffer = Vector<uint8_t>;
|
||||
|
||||
bool IsUTF16Text() const {
|
||||
return mScriptData->is<ScriptTextBuffer<char16_t>>();
|
||||
}
|
||||
@ -208,15 +197,6 @@ class ScriptLoadRequest
|
||||
return mScriptData->as<ScriptTextBuffer<Unit>>();
|
||||
}
|
||||
|
||||
const BinASTSourceBuffer& ScriptBinASTData() const {
|
||||
MOZ_ASSERT(IsBinASTSource());
|
||||
return mScriptData->as<BinASTSourceBuffer>();
|
||||
}
|
||||
BinASTSourceBuffer& ScriptBinASTData() {
|
||||
MOZ_ASSERT(IsBinASTSource());
|
||||
return mScriptData->as<BinASTSourceBuffer>();
|
||||
}
|
||||
|
||||
size_t ScriptTextLength() const {
|
||||
MOZ_ASSERT(IsTextSource());
|
||||
return IsUTF16Text() ? ScriptText<char16_t>().length()
|
||||
@ -288,8 +268,6 @@ class ScriptLoadRequest
|
||||
return element->GetParserCreated();
|
||||
}
|
||||
|
||||
bool ShouldAcceptBinASTEncoding() const;
|
||||
|
||||
void ClearScriptSource();
|
||||
|
||||
void SetScript(JSScript* aScript);
|
||||
@ -334,8 +312,7 @@ class ScriptLoadRequest
|
||||
JS::Heap<JSScript*> mScript;
|
||||
|
||||
// Holds script source data for non-inline scripts.
|
||||
Maybe<Variant<ScriptTextBuffer<char16_t>, ScriptTextBuffer<Utf8Unit>,
|
||||
BinASTSourceBuffer>>
|
||||
Maybe<Variant<ScriptTextBuffer<char16_t>, ScriptTextBuffer<Utf8Unit>>>
|
||||
mScriptData;
|
||||
|
||||
// The length of script source text, set when reading completes. This is used
|
||||
|
@ -324,7 +324,6 @@ static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) {
|
||||
} else if (aRequest->IsTextSource()) {
|
||||
AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::SourceFallback);
|
||||
}
|
||||
// TODO: Add telemetry for BinAST encoded source.
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->IsLoading());
|
||||
if (aRequest->IsTextSource()) {
|
||||
@ -332,7 +331,6 @@ static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) {
|
||||
} else if (aRequest->IsBytecode()) {
|
||||
AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::AltData);
|
||||
}
|
||||
// TODO: Add telemetry for BinAST encoded source.
|
||||
}
|
||||
}
|
||||
|
||||
@ -1667,10 +1665,6 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) {
|
||||
if (httpChannel) {
|
||||
// HTTP content negotation has little value in this context.
|
||||
nsAutoCString acceptTypes("*/*");
|
||||
if (nsJSUtils::BinASTEncodingEnabled() &&
|
||||
aRequest->ShouldAcceptBinASTEncoding()) {
|
||||
acceptTypes = APPLICATION_JAVASCRIPT_BINAST ", */*";
|
||||
}
|
||||
rv = httpChannel->SetRequestHeader("Accept"_ns, acceptTypes, false);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
@ -2446,8 +2440,6 @@ NotifyOffThreadScriptLoadCompletedRunnable::Run() {
|
||||
ProfilerString8View scriptSourceString;
|
||||
if (request->IsTextSource()) {
|
||||
scriptSourceString = "ScriptCompileOffThread";
|
||||
} else if (request->IsBinASTSource()) {
|
||||
scriptSourceString = "BinASTDecodeOffThread";
|
||||
} else {
|
||||
MOZ_ASSERT(request->IsBytecode());
|
||||
scriptSourceString = "BytecodeDecodeOffThread";
|
||||
@ -2955,7 +2947,6 @@ bool ScriptLoader::ShouldCacheBytecode(ScriptLoadRequest* aRequest) {
|
||||
bool hasSourceLengthMin = false;
|
||||
bool hasFetchCountMin = false;
|
||||
size_t sourceLengthMin = 100;
|
||||
size_t binASTLengthMin = 70;
|
||||
int32_t fetchCountMin = 4;
|
||||
|
||||
LOG(("ScriptLoadRequest (%p): Bytecode-cache: strategy = %d.", aRequest,
|
||||
@ -2978,7 +2969,6 @@ bool ScriptLoader::ShouldCacheBytecode(ScriptLoadRequest* aRequest) {
|
||||
hasSourceLengthMin = true;
|
||||
hasFetchCountMin = true;
|
||||
sourceLengthMin = 1024;
|
||||
binASTLengthMin = 700;
|
||||
// If we were to optimize only for speed, without considering the impact
|
||||
// on memory, we should set this threshold to 2. (Bug 900784 comment 120)
|
||||
fetchCountMin = 4;
|
||||
@ -2992,14 +2982,9 @@ bool ScriptLoader::ShouldCacheBytecode(ScriptLoadRequest* aRequest) {
|
||||
if (hasSourceLengthMin) {
|
||||
size_t sourceLength;
|
||||
size_t minLength;
|
||||
if (aRequest->IsTextSource()) {
|
||||
sourceLength = aRequest->mScriptTextLength;
|
||||
minLength = sourceLengthMin;
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->IsBinASTSource());
|
||||
sourceLength = aRequest->ScriptBinASTData().length();
|
||||
minLength = binASTLengthMin;
|
||||
}
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
sourceLength = aRequest->mScriptTextLength;
|
||||
minLength = sourceLengthMin;
|
||||
if (sourceLength < minLength) {
|
||||
LOG(("ScriptLoadRequest (%p): Bytecode-cache: Script is too small.",
|
||||
aRequest));
|
||||
@ -3292,42 +3277,26 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
|
||||
("ScriptLoadRequest (%p): Join (off-thread parsing) and "
|
||||
"Execute",
|
||||
aRequest));
|
||||
if (aRequest->IsBinASTSource()) {
|
||||
rv = exec.JoinDecodeBinAST(&aRequest->mOffThreadToken);
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
rv = exec.JoinCompile(&aRequest->mOffThreadToken);
|
||||
}
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
rv = exec.JoinCompile(&aRequest->mOffThreadToken);
|
||||
} else {
|
||||
// Main thread parsing (inline and small scripts)
|
||||
LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest));
|
||||
if (aRequest->IsBinASTSource()) {
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
MaybeSourceText maybeSource;
|
||||
rv = GetScriptSource(cx, aRequest, &maybeSource);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
AUTO_PROFILER_MARKER_TEXT(
|
||||
"BinASTDecodeMainThread", JS,
|
||||
"ScriptCompileMainThread", JS,
|
||||
MarkerInnerWindowIdFromDocShell(docShell),
|
||||
profilerLabelString);
|
||||
|
||||
rv = exec.DecodeBinAST(options,
|
||||
aRequest->ScriptBinASTData().begin(),
|
||||
aRequest->ScriptBinASTData().length());
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
MaybeSourceText maybeSource;
|
||||
rv = GetScriptSource(cx, aRequest, &maybeSource);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
AUTO_PROFILER_MARKER_TEXT(
|
||||
"ScriptCompileMainThread", JS,
|
||||
MarkerInnerWindowIdFromDocShell(docShell),
|
||||
profilerLabelString);
|
||||
|
||||
rv = maybeSource.constructed<SourceText<char16_t>>()
|
||||
? exec.Compile(
|
||||
options,
|
||||
maybeSource.ref<SourceText<char16_t>>())
|
||||
: exec.Compile(
|
||||
options,
|
||||
maybeSource.ref<SourceText<Utf8Unit>>());
|
||||
}
|
||||
rv =
|
||||
maybeSource.constructed<SourceText<char16_t>>()
|
||||
? exec.Compile(options,
|
||||
maybeSource.ref<SourceText<char16_t>>())
|
||||
: exec.Compile(options,
|
||||
maybeSource.ref<SourceText<Utf8Unit>>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,6 @@
|
||||
#define APPLICATION_RDF_XML "application/rdf+xml"
|
||||
#define APPLICATION_WAPXHTML_XML "application/vnd.wap.xhtml+xml"
|
||||
#define APPLICATION_PACKAGE "application/package"
|
||||
#define APPLICATION_JAVASCRIPT_BINAST "application/javascript-binast"
|
||||
#define APPLICATION_WASM "application/wasm"
|
||||
|
||||
#define AUDIO_BASIC "audio/basic"
|
||||
|
Loading…
x
Reference in New Issue
Block a user