Bug 1724236 - Move Decode to ScriptLoader r=arai

ScriptLoader is the only place that calls it, and inlining it made the call
site too hard to follow.

Differential Revision: https://phabricator.services.mozilla.com/D218453
This commit is contained in:
Bryan Thrall
2024-10-30 13:41:45 +00:00
parent 6f37de74e2
commit dd1514b033
3 changed files with 20 additions and 23 deletions

View File

@@ -2722,6 +2722,26 @@ nsresult ScriptLoader::EvaluateScriptElement(ScriptLoadRequest* aRequest) {
return EvaluateScript(globalObject, aRequest);
}
// Decode a script contained in a buffer.
static void Decode(JSContext* aCx, JS::CompileOptions& aCompileOptions,
const JS::TranscodeRange& aBytecodeBuf,
RefPtr<JS::Stencil>& aStencil, ErrorResult& aRv) {
JS::DecodeOptions decodeOptions(aCompileOptions);
decodeOptions.borrowBuffer = true;
MOZ_ASSERT(aCompileOptions.noScriptRval);
JS::TranscodeResult tr = JS::DecodeStencil(aCx, decodeOptions, aBytecodeBuf,
getter_AddRefs(aStencil));
// These errors are external parameters which should be handled before the
// decoding phase, and which are the only reasons why you might want to
// fallback on decoding failures.
MOZ_ASSERT(tr != JS::TranscodeResult::Failure_BadBuildId);
if (tr != JS::TranscodeResult::Ok) {
aRv = NS_ERROR_DOM_JS_DECODING_ERROR;
return;
}
}
void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
JSContext* aCx, JSExecutionContext& aExec,
JS::CompileOptions& aCompileOptions, ScriptLoadRequest* aRequest,