зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1475228 - Make asynchronous compile APIs take SourceBufferHolders r=jandem
This commit is contained in:
Родитель
c6cb9bdf25
Коммит
cdfffa27fe
|
@ -1830,9 +1830,11 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest)
|
|||
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
JS::SourceBufferHolder srcBuf(aRequest->ScriptText().begin(),
|
||||
aRequest->ScriptText().length(),
|
||||
JS::SourceBufferHolder::NoOwnership);
|
||||
if (!JS::CompileOffThreadModule(cx, options,
|
||||
aRequest->ScriptText().begin(),
|
||||
aRequest->ScriptText().length(),
|
||||
srcBuf,
|
||||
OffThreadScriptLoaderCallback,
|
||||
static_cast<void*>(runnable))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -1858,9 +1860,11 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest)
|
|||
#endif
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
JS::SourceBufferHolder srcBuf(aRequest->ScriptText().begin(),
|
||||
aRequest->ScriptText().length(),
|
||||
JS::SourceBufferHolder::NoOwnership);
|
||||
if (!JS::CompileOffThread(cx, options,
|
||||
aRequest->ScriptText().begin(),
|
||||
aRequest->ScriptText().length(),
|
||||
srcBuf,
|
||||
OffThreadScriptLoaderCallback,
|
||||
static_cast<void*>(runnable))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
|
@ -2241,15 +2241,10 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
rv = mCurrentScriptProto->Compile(srcBuf, uri, 1, this, this);
|
||||
if (NS_SUCCEEDED(rv) && !mCurrentScriptProto->HasScriptObject()) {
|
||||
// We will be notified via OnOffThreadCompileComplete when the
|
||||
// compile finishes. Keep the contents of the compiled script
|
||||
// alive until the compilation finishes.
|
||||
// compile finishes. The JS engine has taken ownership of the
|
||||
// source buffer.
|
||||
MOZ_RELEASE_ASSERT(!srcBuf.ownsChars());
|
||||
mOffThreadCompiling = true;
|
||||
// If the JS engine did not take the source buffer, then take
|
||||
// it back here to ensure it remains alive.
|
||||
mOffThreadCompileStringBuf = srcBuf.take();
|
||||
if (mOffThreadCompileStringBuf) {
|
||||
mOffThreadCompileStringLength = srcBuf.length();
|
||||
}
|
||||
BlockOnload();
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -2257,7 +2257,7 @@ nsXULPrototypeScript::Compile(JS::SourceBufferHolder& aSrcBuf,
|
|||
|
||||
if (aOffThreadReceiver && JS::CanCompileOffThread(cx, options, aSrcBuf.length())) {
|
||||
if (!JS::CompileOffThread(cx, options,
|
||||
aSrcBuf.get(), aSrcBuf.length(),
|
||||
aSrcBuf,
|
||||
OffThreadScriptReceiverCallback,
|
||||
static_cast<void*>(aOffThreadReceiver))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
|
@ -38,7 +38,7 @@ using ValueVector = JS::GCVector<JS::Value>;
|
|||
using IdVector = JS::GCVector<jsid>;
|
||||
using ScriptVector = JS::GCVector<JSScript*>;
|
||||
|
||||
class MOZ_STACK_CLASS SourceBufferHolder;
|
||||
class SourceBufferHolder;
|
||||
|
||||
class HandleValueArray;
|
||||
|
||||
|
|
|
@ -108,8 +108,8 @@ testCompile(bool nonSyntactic)
|
|||
OffThreadTask task;
|
||||
OffThreadToken* token;
|
||||
|
||||
CHECK(CompileOffThread(cx, options, src_16, length,
|
||||
task.OffThreadCallback, &task));
|
||||
SourceBufferHolder srcBuf(src_16, length, SourceBufferHolder::NoOwnership);
|
||||
CHECK(CompileOffThread(cx, options, srcBuf, task.OffThreadCallback, &task));
|
||||
CHECK(token = task.waitUntilDone(cx));
|
||||
CHECK(script = FinishOffThreadScript(cx, token));
|
||||
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
|
||||
|
|
|
@ -4215,11 +4215,11 @@ JS::CanDecodeBinASTOffThread(JSContext* cx, const ReadOnlyCompileOptions& option
|
|||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS::CompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
OffThreadCompileCallback callback, void* callbackData)
|
||||
{
|
||||
MOZ_ASSERT(CanCompileOffThread(cx, options, length));
|
||||
return StartOffThreadParseScript(cx, options, chars, length, callback, callbackData);
|
||||
MOZ_ASSERT(CanCompileOffThread(cx, options, srcBuf.length()));
|
||||
return StartOffThreadParseScript(cx, options, srcBuf, callback, callbackData);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSScript*)
|
||||
|
@ -4240,11 +4240,11 @@ JS::CancelOffThreadScript(JSContext* cx, JS::OffThreadToken* token)
|
|||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS::CompileOffThreadModule(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
OffThreadCompileCallback callback, void* callbackData)
|
||||
{
|
||||
MOZ_ASSERT(CanCompileOffThread(cx, options, length));
|
||||
return StartOffThreadParseModule(cx, options, chars, length, callback, callbackData);
|
||||
MOZ_ASSERT(CanCompileOffThread(cx, options, srcBuf.length()));
|
||||
return StartOffThreadParseModule(cx, options, srcBuf, callback, callbackData);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject*)
|
||||
|
|
|
@ -378,7 +378,7 @@ namespace JS {
|
|||
* JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership);
|
||||
* JS::Compile(cx, options, srcBuf);
|
||||
*/
|
||||
class MOZ_STACK_CLASS SourceBufferHolder final
|
||||
class SourceBufferHolder final
|
||||
{
|
||||
public:
|
||||
enum Ownership {
|
||||
|
@ -3648,7 +3648,7 @@ CanDecodeOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t
|
|||
|
||||
extern JS_PUBLIC_API(bool)
|
||||
CompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
OffThreadCompileCallback callback, void* callbackData);
|
||||
|
||||
extern JS_PUBLIC_API(JSScript*)
|
||||
|
@ -3659,7 +3659,7 @@ CancelOffThreadScript(JSContext* cx, OffThreadToken* token);
|
|||
|
||||
extern JS_PUBLIC_API(bool)
|
||||
CompileOffThreadModule(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
OffThreadCompileCallback callback, void* callbackData);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject*)
|
||||
|
|
|
@ -4743,7 +4743,9 @@ OffThreadCompileScript(JSContext* cx, unsigned argc, Value* vp)
|
|||
if (!job)
|
||||
return false;
|
||||
|
||||
if (!JS::CompileOffThread(cx, options, job->sourceChars(), length,
|
||||
JS::SourceBufferHolder srcBuf(job->sourceChars(), length,
|
||||
JS::SourceBufferHolder::NoOwnership);
|
||||
if (!JS::CompileOffThread(cx, options, srcBuf,
|
||||
OffThreadCompileScriptCallback, job))
|
||||
{
|
||||
job->cancel();
|
||||
|
@ -4829,7 +4831,9 @@ OffThreadCompileModule(JSContext* cx, unsigned argc, Value* vp)
|
|||
if (!job)
|
||||
return false;
|
||||
|
||||
if (!JS::CompileOffThreadModule(cx, options, job->sourceChars(), length,
|
||||
JS::SourceBufferHolder srcBuf(job->sourceChars(), length,
|
||||
JS::SourceBufferHolder::NoOwnership);
|
||||
if (!JS::CompileOffThreadModule(cx, options, srcBuf,
|
||||
OffThreadCompileScriptCallback, job))
|
||||
{
|
||||
job->cancel();
|
||||
|
|
|
@ -482,22 +482,21 @@ ParseTask::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
|
|||
errors.sizeOfExcludingThis(mallocSizeOf);
|
||||
}
|
||||
|
||||
ScriptParseTask::ScriptParseTask(JSContext* cx, const char16_t* chars, size_t length,
|
||||
ScriptParseTask::ScriptParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData)
|
||||
: ParseTask(ParseTaskKind::Script, cx, callback, callbackData),
|
||||
data(TwoByteChars(chars, length))
|
||||
data(std::move(srcBuf))
|
||||
{}
|
||||
|
||||
void
|
||||
ScriptParseTask::parse(JSContext* cx)
|
||||
{
|
||||
SourceBufferHolder srcBuf(data.begin().get(), data.length(), SourceBufferHolder::NoOwnership);
|
||||
Rooted<ScriptSourceObject*> sourceObject(cx);
|
||||
|
||||
ScopeKind scopeKind = options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global;
|
||||
|
||||
JSScript* script = frontend::CompileGlobalScript(cx, alloc, scopeKind,
|
||||
options, srcBuf,
|
||||
options, data,
|
||||
/* sourceObjectOut = */ &sourceObject.get());
|
||||
if (script)
|
||||
scripts.infallibleAppend(script);
|
||||
|
@ -505,19 +504,18 @@ ScriptParseTask::parse(JSContext* cx)
|
|||
sourceObjects.infallibleAppend(sourceObject);
|
||||
}
|
||||
|
||||
ModuleParseTask::ModuleParseTask(JSContext* cx, const char16_t* chars, size_t length,
|
||||
ModuleParseTask::ModuleParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData)
|
||||
: ParseTask(ParseTaskKind::Module, cx, callback, callbackData),
|
||||
data(TwoByteChars(chars, length))
|
||||
data(std::move(srcBuf))
|
||||
{}
|
||||
|
||||
void
|
||||
ModuleParseTask::parse(JSContext* cx)
|
||||
{
|
||||
SourceBufferHolder srcBuf(data.begin().get(), data.length(), SourceBufferHolder::NoOwnership);
|
||||
Rooted<ScriptSourceObject*> sourceObject(cx);
|
||||
|
||||
ModuleObject* module = frontend::CompileModule(cx, options, srcBuf, alloc, &sourceObject.get());
|
||||
ModuleObject* module = frontend::CompileModule(cx, options, data, alloc, &sourceObject.get());
|
||||
if (module) {
|
||||
scripts.infallibleAppend(module->script());
|
||||
if (sourceObject)
|
||||
|
@ -825,10 +823,10 @@ StartOffThreadParseTask(JSContext* cx, ParseTask* task, const ReadOnlyCompileOpt
|
|||
|
||||
bool
|
||||
js::StartOffThreadParseScript(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData)
|
||||
{
|
||||
auto task = cx->make_unique<ScriptParseTask>(cx, chars, length, callback, callbackData);
|
||||
auto task = cx->make_unique<ScriptParseTask>(cx, srcBuf, callback, callbackData);
|
||||
if (!task || !StartOffThreadParseTask(cx, task.get(), options))
|
||||
return false;
|
||||
|
||||
|
@ -838,10 +836,10 @@ js::StartOffThreadParseScript(JSContext* cx, const ReadOnlyCompileOptions& optio
|
|||
|
||||
bool
|
||||
js::StartOffThreadParseModule(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData)
|
||||
{
|
||||
auto task = cx->make_unique<ModuleParseTask>(cx, chars, length, callback, callbackData);
|
||||
auto task = cx->make_unique<ModuleParseTask>(cx, srcBuf, callback, callbackData);
|
||||
if (!task || !StartOffThreadParseTask(cx, task.get(), options))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -591,12 +591,12 @@ CancelOffThreadParses(JSRuntime* runtime);
|
|||
*/
|
||||
bool
|
||||
StartOffThreadParseScript(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData);
|
||||
|
||||
bool
|
||||
StartOffThreadParseModule(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
const char16_t* chars, size_t length,
|
||||
JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData);
|
||||
|
||||
bool
|
||||
|
@ -722,18 +722,18 @@ struct ParseTask : public mozilla::LinkedListElement<ParseTask>, public JS::OffT
|
|||
|
||||
struct ScriptParseTask : public ParseTask
|
||||
{
|
||||
JS::TwoByteChars data;
|
||||
JS::SourceBufferHolder data;
|
||||
|
||||
ScriptParseTask(JSContext* cx, const char16_t* chars, size_t length,
|
||||
ScriptParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData);
|
||||
void parse(JSContext* cx) override;
|
||||
};
|
||||
|
||||
struct ModuleParseTask : public ParseTask
|
||||
{
|
||||
JS::TwoByteChars data;
|
||||
JS::SourceBufferHolder data;
|
||||
|
||||
ModuleParseTask(JSContext* cx, const char16_t* chars, size_t length,
|
||||
ModuleParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
|
||||
JS::OffThreadCompileCallback callback, void* callbackData);
|
||||
void parse(JSContext* cx) override;
|
||||
};
|
||||
|
|
|
@ -131,8 +131,10 @@ AsyncScriptCompiler::StartCompile(JSContext* aCx)
|
|||
{
|
||||
Rooted<JSObject*> global(aCx, mGlobalObject->GetGlobalJSObject());
|
||||
|
||||
JS::SourceBufferHolder srcBuf(mScriptText.get(), mScriptLength,
|
||||
JS::SourceBufferHolder::NoOwnership);
|
||||
if (JS::CanCompileOffThread(aCx, mOptions, mScriptLength)) {
|
||||
if (!JS::CompileOffThread(aCx, mOptions, mScriptText.get(), mScriptLength,
|
||||
if (!JS::CompileOffThread(aCx, mOptions, srcBuf,
|
||||
OffThreadScriptLoaderCallback,
|
||||
static_cast<void*>(this))) {
|
||||
return false;
|
||||
|
@ -143,8 +145,6 @@ AsyncScriptCompiler::StartCompile(JSContext* aCx)
|
|||
}
|
||||
|
||||
Rooted<JSScript*> script(aCx);
|
||||
JS::SourceBufferHolder srcBuf(mScriptText.get(), mScriptLength,
|
||||
JS::SourceBufferHolder::NoOwnership);
|
||||
if (!JS::Compile(aCx, mOptions, srcBuf, &script)) {
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче