mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1597153 - Part 1: Add JS::BinASTFormat enum and use it in API. r=Yoric
Differential Revision: https://phabricator.services.mozilla.com/D53365 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
28a120ee26
commit
c66f627242
@ -14,6 +14,7 @@
|
||||
#include "nsJSUtils.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "js/BinASTFormat.h" // JS::BinASTFormat
|
||||
#include "js/CompilationAndEvaluation.h"
|
||||
#include "js/Modules.h" // JS::CompileModule{,DontInflate}, JS::GetModuleScript, JS::Module{Instantiate,Evaluate}
|
||||
#include "js/OffThreadScriptCompilation.h"
|
||||
@ -371,7 +372,8 @@ nsresult nsJSUtils::ExecutionContext::DecodeBinAST(
|
||||
mWantsReturnValue = !aCompileOptions.noScriptRval;
|
||||
# endif
|
||||
|
||||
mScript.set(JS::DecodeBinAST(mCx, aCompileOptions, aBuf, aLength));
|
||||
mScript.set(JS::DecodeBinAST(mCx, aCompileOptions, aBuf, aLength,
|
||||
JS::BinASTFormat::Multipart));
|
||||
|
||||
if (!mScript) {
|
||||
mSkip = true;
|
||||
|
@ -2114,7 +2114,7 @@ nsresult ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
|
||||
MOZ_ASSERT(aRequest->IsSource());
|
||||
if (!JS::DecodeBinASTOffThread(
|
||||
cx, options, aRequest->ScriptBinASTData().begin(),
|
||||
aRequest->ScriptBinASTData().length(),
|
||||
aRequest->ScriptBinASTData().length(), JS::BinASTFormat::Multipart,
|
||||
OffThreadScriptLoaderCallback, static_cast<void*>(runnable))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
20
js/public/BinASTFormat.h
Normal file
20
js/public/BinASTFormat.h
Normal file
@ -0,0 +1,20 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef js_BinASTFormat_h
|
||||
#define js_BinASTFormat_h
|
||||
|
||||
#if defined(JS_BUILD_BINAST)
|
||||
|
||||
namespace JS {
|
||||
|
||||
enum class BinASTFormat { Multipart, Context };
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
#endif /* JS_BUILD_BINAST */
|
||||
|
||||
#endif /* js_BinASTFormat_h */
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "jstypes.h" // JS_PUBLIC_API
|
||||
|
||||
#include "js/BinASTFormat.h" // JS::BinASTFormat
|
||||
#include "js/CompileOptions.h" // JS::ReadOnlyCompileOptions
|
||||
#include "js/GCVector.h" // JS::GCVector
|
||||
#include "js/Transcoding.h" // JS::TranscodeSource
|
||||
@ -138,7 +139,8 @@ extern JS_PUBLIC_API bool CanDecodeBinASTOffThread(
|
||||
|
||||
extern JS_PUBLIC_API bool DecodeBinASTOffThread(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* buf,
|
||||
size_t length, OffThreadCompileCallback callback, void* callbackData);
|
||||
size_t length, JS::BinASTFormat format, OffThreadCompileCallback callback,
|
||||
void* callbackData);
|
||||
|
||||
extern JS_PUBLIC_API JSScript* FinishOffThreadBinASTDecode(
|
||||
JSContext* cx, OffThreadToken* token);
|
||||
|
@ -741,7 +741,7 @@ ScriptSourceObject* frontend::CreateScriptSourceObject(
|
||||
|
||||
JSScript* frontend::CompileGlobalBinASTScript(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* src,
|
||||
size_t len, ScriptSourceObject** sourceObjectOut) {
|
||||
size_t len, JS::BinASTFormat format, ScriptSourceObject** sourceObjectOut) {
|
||||
AutoAssertReportedException assertException(cx);
|
||||
|
||||
LifoAllocScope allocScope(&cx->tempLifoAlloc());
|
||||
@ -768,6 +768,8 @@ JSScript* frontend::CompileGlobalBinASTScript(
|
||||
GlobalSharedContext globalsc(cx, ScopeKind::Global, directives,
|
||||
options.extraWarningsOption);
|
||||
|
||||
MOZ_ASSERT(format == JS::BinASTFormat::Multipart);
|
||||
|
||||
frontend::BinASTParser<BinASTTokenReaderMultipart> parser(cx, parseInfo,
|
||||
options, sourceObj);
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "NamespaceImports.h"
|
||||
|
||||
#include "js/BinASTFormat.h" // JS::BinASTFormat
|
||||
#include "js/CompileOptions.h"
|
||||
#include "js/SourceText.h"
|
||||
#include "vm/Scope.h"
|
||||
@ -112,7 +113,7 @@ class ParseNode;
|
||||
|
||||
JSScript* CompileGlobalBinASTScript(
|
||||
JSContext* cx, const JS::ReadOnlyCompileOptions& options,
|
||||
const uint8_t* src, size_t len,
|
||||
const uint8_t* src, size_t len, JS::BinASTFormat format,
|
||||
ScriptSourceObject** sourceObjectOut = nullptr);
|
||||
|
||||
MOZ_MUST_USE bool CompileLazyBinASTFunction(JSContext* cx,
|
||||
|
@ -3660,22 +3660,24 @@ CompileOptions& CompileOptions::setIntroductionInfoToCaller(
|
||||
#if defined(JS_BUILD_BINAST)
|
||||
|
||||
JSScript* JS::DecodeBinAST(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const uint8_t* buf, size_t length) {
|
||||
const uint8_t* buf, size_t length,
|
||||
JS::BinASTFormat format) {
|
||||
MOZ_ASSERT(!cx->zone()->isAtomsZone());
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
|
||||
return frontend::CompileGlobalBinASTScript(cx, options, buf, length);
|
||||
return frontend::CompileGlobalBinASTScript(cx, options, buf, length, format);
|
||||
}
|
||||
|
||||
JSScript* JS::DecodeBinAST(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
FILE* file) {
|
||||
FILE* file, JS::BinASTFormat format) {
|
||||
FileContents fileContents(cx);
|
||||
if (!ReadCompleteFile(cx, file, fileContents)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DecodeBinAST(cx, options, fileContents.begin(), fileContents.length());
|
||||
return DecodeBinAST(cx, options, fileContents.begin(), fileContents.length(),
|
||||
format);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -4581,7 +4583,7 @@ JS_PUBLIC_API bool JS_EncodeStringToBuffer(JSContext* cx, JSString* str,
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API mozilla::Maybe<mozilla::Tuple<size_t, size_t> >
|
||||
JS_PUBLIC_API mozilla::Maybe<mozilla::Tuple<size_t, size_t>>
|
||||
JS_EncodeStringToUTF8BufferPartial(JSContext* cx, JSString* str,
|
||||
mozilla::Span<char> buffer) {
|
||||
AssertHeapIsIdle();
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "jspubtd.h"
|
||||
|
||||
#include "js/AllocPolicy.h"
|
||||
#include "js/BinASTFormat.h" // JS::BinASTFormat
|
||||
#include "js/CallArgs.h"
|
||||
#include "js/CharacterEncoding.h"
|
||||
#include "js/Class.h"
|
||||
@ -1950,11 +1951,12 @@ extern JS_PUBLIC_API void SetScriptPrivateReferenceHooks(
|
||||
namespace JS {
|
||||
|
||||
extern JS_PUBLIC_API JSScript* DecodeBinAST(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options, FILE* file);
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options, FILE* file,
|
||||
JS::BinASTFormat format);
|
||||
|
||||
extern JS_PUBLIC_API JSScript* DecodeBinAST(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* buf,
|
||||
size_t length);
|
||||
size_t length, JS::BinASTFormat format);
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
|
@ -124,6 +124,7 @@ EXPORTS.js += [
|
||||
'../public/AllocationRecording.h',
|
||||
'../public/AllocPolicy.h',
|
||||
'../public/ArrayBuffer.h',
|
||||
'../public/BinASTFormat.h',
|
||||
'../public/BuildId.h',
|
||||
'../public/CallArgs.h',
|
||||
'../public/CallNonGenericMethod.h',
|
||||
|
@ -920,7 +920,7 @@ static MOZ_MUST_USE bool RunBinAST(JSContext* cx, const char* filename,
|
||||
.setIsRunOnce(true)
|
||||
.setNoScriptRval(true);
|
||||
|
||||
script = JS::DecodeBinAST(cx, options, file);
|
||||
script = JS::DecodeBinAST(cx, options, file, JS::BinASTFormat::Multipart);
|
||||
if (!script) {
|
||||
return false;
|
||||
}
|
||||
|
@ -684,11 +684,12 @@ void ScriptDecodeTask::parse(JSContext* cx) {
|
||||
#if defined(JS_BUILD_BINAST)
|
||||
|
||||
BinASTDecodeTask::BinASTDecodeTask(JSContext* cx, const uint8_t* buf,
|
||||
size_t length,
|
||||
size_t length, JS::BinASTFormat format,
|
||||
JS::OffThreadCompileCallback callback,
|
||||
void* callbackData)
|
||||
: ParseTask(ParseTaskKind::BinAST, cx, callback, callbackData),
|
||||
data(buf, length) {}
|
||||
data(buf, length),
|
||||
format(format) {}
|
||||
|
||||
void BinASTDecodeTask::parse(JSContext* cx) {
|
||||
MOZ_ASSERT(cx->isHelperThreadContext());
|
||||
@ -696,7 +697,8 @@ void BinASTDecodeTask::parse(JSContext* cx) {
|
||||
RootedScriptSourceObject sourceObject(cx);
|
||||
|
||||
JSScript* script = frontend::CompileGlobalBinASTScript(
|
||||
cx, options, data.begin().get(), data.length(), &sourceObject.get());
|
||||
cx, options, data.begin().get(), data.length(), format,
|
||||
&sourceObject.get());
|
||||
if (script) {
|
||||
scripts.infallibleAppend(script);
|
||||
if (sourceObject) {
|
||||
@ -1070,14 +1072,15 @@ bool js::StartOffThreadDecodeMultiScripts(JSContext* cx,
|
||||
bool js::StartOffThreadDecodeBinAST(JSContext* cx,
|
||||
const ReadOnlyCompileOptions& options,
|
||||
const uint8_t* buf, size_t length,
|
||||
JS::BinASTFormat format,
|
||||
JS::OffThreadCompileCallback callback,
|
||||
void* callbackData) {
|
||||
if (!cx->runtime()->binast().ensureBinTablesInitialized(cx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto task = cx->make_unique<BinASTDecodeTask>(cx, buf, length, callback,
|
||||
callbackData);
|
||||
auto task = cx->make_unique<BinASTDecodeTask>(cx, buf, length, format,
|
||||
callback, callbackData);
|
||||
if (!task) {
|
||||
return false;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "ds/Fifo.h"
|
||||
#include "jit/Ion.h"
|
||||
#include "js/BinASTFormat.h" // JS::BinASTFormat
|
||||
#include "js/CompileOptions.h"
|
||||
#include "js/SourceText.h"
|
||||
#include "js/TypeDecls.h"
|
||||
@ -635,6 +636,7 @@ bool StartOffThreadDecodeScript(JSContext* cx,
|
||||
bool StartOffThreadDecodeBinAST(JSContext* cx,
|
||||
const JS::ReadOnlyCompileOptions& options,
|
||||
const uint8_t* buf, size_t length,
|
||||
JS::BinASTFormat format,
|
||||
JS::OffThreadCompileCallback callback,
|
||||
void* callbackData);
|
||||
|
||||
@ -777,8 +779,10 @@ struct ScriptDecodeTask : public ParseTask {
|
||||
|
||||
struct BinASTDecodeTask : public ParseTask {
|
||||
mozilla::Range<const uint8_t> data;
|
||||
JS::BinASTFormat format;
|
||||
|
||||
BinASTDecodeTask(JSContext* cx, const uint8_t* buf, size_t length,
|
||||
JS::BinASTFormat format,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData);
|
||||
void parse(JSContext* cx) override;
|
||||
};
|
||||
|
@ -212,8 +212,9 @@ JS_PUBLIC_API bool JS::CanDecodeBinASTOffThread(
|
||||
|
||||
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,
|
||||
size_t length, JS::BinASTFormat format, OffThreadCompileCallback callback,
|
||||
void* callbackData) {
|
||||
return StartOffThreadDecodeBinAST(cx, options, buf, length, format, callback,
|
||||
callbackData);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user