Bug 1364974: Part 1 - Switch to Variant for holding decode task data. r=shu

We'll need to be able to support more than two parse data types in order to
support multi-script decode operations. Since MaybeOneOf only supports two
types, that means switching to Variant.

MozReview-Commit-ID: HMYZ0R4dife

--HG--
extra : rebase_source : c70133fe393c1f6de56403a1e29561596c85deb0
This commit is contained in:
Kris Maglione 2017-05-16 00:12:08 -07:00
parent 2ac2023c15
commit 3d777bb838
2 changed files with 6 additions and 9 deletions

View File

@ -300,27 +300,25 @@ static const JSClass parseTaskGlobalClass = {
ParseTask::ParseTask(ParseTaskKind kind, JSContext* cx, JSObject* parseGlobal,
const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData)
: kind(kind), options(cx),
: kind(kind), options(cx), data(AsVariant(TwoByteChars(chars, length))),
alloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE),
parseGlobal(parseGlobal),
callback(callback), callbackData(callbackData),
script(nullptr), sourceObject(nullptr),
overRecursed(false), outOfMemory(false)
{
data.construct<TwoByteChars>(chars, length);
}
ParseTask::ParseTask(ParseTaskKind kind, JSContext* cx, JSObject* parseGlobal,
const JS::TranscodeRange& range,
JS::OffThreadCompileCallback callback, void* callbackData)
: kind(kind), options(cx),
: kind(kind), options(cx), data(AsVariant(range)),
alloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE),
parseGlobal(parseGlobal),
callback(callback), callbackData(callbackData),
script(nullptr), sourceObject(nullptr),
overRecursed(false), outOfMemory(false)
{
data.construct<const JS::TranscodeRange>(range);
}
bool
@ -387,7 +385,7 @@ ScriptParseTask::ScriptParseTask(JSContext* cx, JSObject* parseGlobal,
void
ScriptParseTask::parse(JSContext* cx)
{
auto& range = data.ref<TwoByteChars>();
auto& range = data.as<TwoByteChars>();
SourceBufferHolder srcBuf(range.begin().get(), range.length(), SourceBufferHolder::NoOwnership);
script = frontend::CompileGlobalScript(cx, alloc, ScopeKind::Global,
options, srcBuf,
@ -405,7 +403,7 @@ ModuleParseTask::ModuleParseTask(JSContext* cx, JSObject* parseGlobal,
void
ModuleParseTask::parse(JSContext* cx)
{
auto& range = data.ref<TwoByteChars>();
auto& range = data.as<TwoByteChars>();
SourceBufferHolder srcBuf(range.begin().get(), range.length(), SourceBufferHolder::NoOwnership);
ModuleObject* module = frontend::CompileModule(cx, options, srcBuf, alloc, &sourceObject);
if (module)
@ -425,7 +423,7 @@ ScriptDecodeTask::parse(JSContext* cx)
{
RootedScript resultScript(cx);
XDROffThreadDecoder decoder(cx, alloc, &options, /* sourceObjectOut = */ &sourceObject,
data.ref<const JS::TranscodeRange>());
data.as<const JS::TranscodeRange>());
decoder.codeScript(&resultScript);
MOZ_ASSERT(bool(resultScript) == (decoder.resultCode() == JS::TranscodeResult_Ok));
if (decoder.resultCode() == JS::TranscodeResult_Ok) {

View File

@ -15,7 +15,6 @@
#include "mozilla/Attributes.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/MaybeOneOf.h"
#include "mozilla/PodOperations.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Variant.h"
@ -595,7 +594,7 @@ struct ParseTask
ParseTaskKind kind;
OwningCompileOptions options;
mozilla::MaybeOneOf<const JS::TranscodeRange, JS::TwoByteChars> data;
mozilla::Variant<const JS::TranscodeRange, JS::TwoByteChars> data;
LifoAlloc alloc;