diff --git a/js/public/OffThreadScriptCompilation.h b/js/public/OffThreadScriptCompilation.h index 79d807b874bb..40c2e47002f2 100644 --- a/js/public/OffThreadScriptCompilation.h +++ b/js/public/OffThreadScriptCompilation.h @@ -40,12 +40,6 @@ class OffThreadToken; using OffThreadCompileCallback = void (*)(OffThreadToken* token, void* callbackData); -extern JS_PUBLIC_API bool CanCompileOffThread( - JSContext* cx, const ReadOnlyCompileOptions& options, size_t length); - -extern JS_PUBLIC_API bool CanDecodeOffThread( - JSContext* cx, const ReadOnlyCompileOptions& options, size_t length); - /* * Off thread compilation control flow. * @@ -63,6 +57,9 @@ extern JS_PUBLIC_API bool CanDecodeOffThread( * to FinishOffThreadScript. */ +extern JS_PUBLIC_API bool CanCompileOffThread( + JSContext* cx, const ReadOnlyCompileOptions& options, size_t length); + extern JS_PUBLIC_API bool CompileOffThread( JSContext* cx, const ReadOnlyCompileOptions& options, SourceText& srcBuf, OffThreadCompileCallback callback, @@ -103,6 +100,9 @@ extern JS_PUBLIC_API JSObject* FinishOffThreadModule(JSContext* cx, extern JS_PUBLIC_API void CancelOffThreadModule(JSContext* cx, OffThreadToken* token); +extern JS_PUBLIC_API bool CanDecodeOffThread( + JSContext* cx, const ReadOnlyCompileOptions& options, size_t length); + extern JS_PUBLIC_API bool DecodeOffThreadScript( JSContext* cx, const ReadOnlyCompileOptions& options, mozilla::Vector& buffer /* TranscodeBuffer& */, size_t cursor, @@ -136,6 +136,13 @@ extern JS_PUBLIC_API void CancelMultiOffThreadScriptsDecoder( extern JS_PUBLIC_API bool CanDecodeBinASTOffThread( JSContext* cx, const ReadOnlyCompileOptions& options, size_t length); +extern JS_PUBLIC_API bool DecodeBinASTOffThread( + JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* buf, + size_t length, OffThreadCompileCallback callback, void* callbackData); + +extern JS_PUBLIC_API JSScript* FinishOffThreadBinASTDecode( + JSContext* cx, OffThreadToken* token); + #endif // defined(JS_BUILD_BINAST) } // namespace JS diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 0c991fcc5f2a..8ae91b77cb32 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3626,19 +3626,6 @@ JSScript* JS::DecodeBinAST(JSContext* cx, const ReadOnlyCompileOptions& options, return DecodeBinAST(cx, options, fileContents.begin(), fileContents.length()); } -JS_PUBLIC_API bool JS::DecodeBinASTOffThread( - JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* buf, - size_t length, OffThreadCompileCallback callback, void* callbackData) { - return StartOffThreadDecodeBinAST(cx, options, buf, length, callback, - callbackData); -} - -JS_PUBLIC_API JSScript* JS::FinishOffThreadBinASTDecode( - JSContext* cx, JS::OffThreadToken* token) { - MOZ_ASSERT(cx); - MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime())); - return HelperThreadState().finishBinASTDecodeTask(cx, token); -} #endif JS_PUBLIC_API JSObject* JS_GetGlobalFromScript(JSScript* script) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 43f77a1acf1f..6ba7562452df 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -1974,16 +1974,6 @@ extern JS_PUBLIC_API JSScript* DecodeBinAST( JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* buf, size_t length); -extern JS_PUBLIC_API bool CanDecodeBinASTOffThread( - JSContext* cx, const ReadOnlyCompileOptions& options, size_t length); - -extern JS_PUBLIC_API bool DecodeBinASTOffThread( - JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* buf, - size_t length, OffThreadCompileCallback callback, void* callbackData); - -extern JS_PUBLIC_API JSScript* FinishOffThreadBinASTDecode( - JSContext* cx, OffThreadToken* token); - } /* namespace JS */ #endif /* JS_BUILD_BINAST */ diff --git a/js/src/vm/OffThreadScriptCompilation.cpp b/js/src/vm/OffThreadScriptCompilation.cpp index 9f4e478699db..5ac0bb3ed18b 100644 --- a/js/src/vm/OffThreadScriptCompilation.cpp +++ b/js/src/vm/OffThreadScriptCompilation.cpp @@ -70,19 +70,6 @@ JS_PUBLIC_API bool JS::CanCompileOffThread( return CanDoOffThread(cx, options, length, OffThread::Compile); } -JS_PUBLIC_API bool JS::CanDecodeOffThread(JSContext* cx, - const ReadOnlyCompileOptions& options, - size_t length) { - return CanDoOffThread(cx, options, length, OffThread::Decode); -} - -#ifdef JS_BUILD_BINAST -JS_PUBLIC_API bool JS::CanDecodeBinASTOffThread( - JSContext* cx, const ReadOnlyCompileOptions& options, size_t length) { - return CanDoOffThread(cx, options, length, OffThread::DecodeBinAST); -} -#endif - JS_PUBLIC_API bool JS::CompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, JS::SourceText& srcBuf, @@ -147,6 +134,12 @@ JS_PUBLIC_API void JS::CancelOffThreadModule(JSContext* cx, token); } +JS_PUBLIC_API bool JS::CanDecodeOffThread(JSContext* cx, + const ReadOnlyCompileOptions& options, + size_t length) { + return CanDoOffThread(cx, options, length, OffThread::Decode); +} + JS_PUBLIC_API bool JS::DecodeOffThreadScript( JSContext* cx, const ReadOnlyCompileOptions& options, mozilla::Vector& buffer /* TranscodeBuffer& */, size_t cursor, @@ -164,21 +157,6 @@ JS_PUBLIC_API bool JS::DecodeOffThreadScript( return StartOffThreadDecodeScript(cx, options, range, callback, callbackData); } -JS_PUBLIC_API bool JS::DecodeMultiOffThreadScripts( - JSContext* cx, const ReadOnlyCompileOptions& options, - TranscodeSources& sources, OffThreadCompileCallback callback, - void* callbackData) { -#ifdef DEBUG - size_t length = 0; - for (auto& source : sources) { - length += source.range.length(); - } - MOZ_ASSERT(CanCompileOffThread(cx, options, length)); -#endif - return StartOffThreadDecodeMultiScripts(cx, options, sources, callback, - callbackData); -} - JS_PUBLIC_API JSScript* JS::FinishOffThreadScriptDecoder( JSContext* cx, JS::OffThreadToken* token) { MOZ_ASSERT(cx); @@ -194,6 +172,21 @@ JS_PUBLIC_API void JS::CancelOffThreadScriptDecoder(JSContext* cx, ParseTaskKind::ScriptDecode, token); } +JS_PUBLIC_API bool JS::DecodeMultiOffThreadScripts( + JSContext* cx, const ReadOnlyCompileOptions& options, + TranscodeSources& sources, OffThreadCompileCallback callback, + void* callbackData) { +#ifdef DEBUG + size_t length = 0; + for (auto& source : sources) { + length += source.range.length(); + } + MOZ_ASSERT(CanCompileOffThread(cx, options, length)); +#endif + return StartOffThreadDecodeMultiScripts(cx, options, sources, callback, + callbackData); +} + JS_PUBLIC_API bool JS::FinishMultiOffThreadScriptsDecoder( JSContext* cx, JS::OffThreadToken* token, MutableHandle scripts) { @@ -209,3 +202,26 @@ JS_PUBLIC_API void JS::CancelMultiOffThreadScriptsDecoder( HelperThreadState().cancelParseTask(cx->runtime(), ParseTaskKind::MultiScriptsDecode, token); } + +#ifdef JS_BUILD_BINAST + +JS_PUBLIC_API bool JS::CanDecodeBinASTOffThread( + JSContext* cx, const ReadOnlyCompileOptions& options, size_t length) { + return CanDoOffThread(cx, options, length, OffThread::DecodeBinAST); +} + +JS_PUBLIC_API bool JS::DecodeBinASTOffThread( + JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* buf, + size_t length, OffThreadCompileCallback callback, void* callbackData) { + return StartOffThreadDecodeBinAST(cx, options, buf, length, callback, + callbackData); +} + +JS_PUBLIC_API JSScript* JS::FinishOffThreadBinASTDecode( + JSContext* cx, JS::OffThreadToken* token) { + MOZ_ASSERT(cx); + MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime())); + return HelperThreadState().finishBinASTDecodeTask(cx, token); +} + +#endif // JS_BUILD_BINAST