Backed out 8 changesets (bug 1475228) for wpt failures e.g. html/semantics/scripting-1/the-script-element/execution-timing/088.html on a CLOSED TREE

Backed out changeset b2d18ea619ec (bug 1475228)
Backed out changeset 45d3ffe3308e (bug 1475228)
Backed out changeset 02b27f8441be (bug 1475228)
Backed out changeset b82c2cf4b3f1 (bug 1475228)
Backed out changeset 2bc8f24dc3fc (bug 1475228)
Backed out changeset 6104ea971587 (bug 1475228)
Backed out changeset 7c83633262db (bug 1475228)
Backed out changeset 34fb24d52f08 (bug 1475228)
This commit is contained in:
Andreea Pavel 2018-07-30 16:49:02 +03:00
Родитель 445b25d385
Коммит 840f785b1e
25 изменённых файлов: 258 добавлений и 233 удалений

Просмотреть файл

@ -94,12 +94,11 @@ nsJSUtils::CompileFunction(AutoJSAPI& jsapi,
// Compile.
JS::Rooted<JSFunction*> fun(cx);
JS::SourceBufferHolder source(PromiseFlatString(aBody).get(), aBody.Length(),
JS::SourceBufferHolder::NoOwnership);
if (!JS::CompileFunction(cx, aScopeChain, aOptions,
PromiseFlatCString(aName).get(),
aArgCount, aArgArray,
source, &fun))
PromiseFlatString(aBody).get(),
aBody.Length(), &fun))
{
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -166,7 +166,7 @@ ScriptLoadRequest::SetTextSource()
{
MOZ_ASSERT(IsUnknownDataType());
mDataType = DataType::eTextSource;
mScriptData.emplace(VariantType<ScriptTextBuffer>());
mScriptData.emplace(VariantType<Vector<char16_t>>());
}
void
@ -175,7 +175,7 @@ ScriptLoadRequest::SetBinASTSource()
#ifdef JS_BUILD_BINAST
MOZ_ASSERT(IsUnknownDataType());
mDataType = DataType::eBinASTSource;
mScriptData.emplace(VariantType<BinASTSourceBuffer>());
mScriptData.emplace(VariantType<Vector<uint8_t>>());
#else
MOZ_CRASH("BinAST not supported");
#endif

Просмотреть файл

@ -171,28 +171,21 @@ public:
void SetBinASTSource();
void SetBytecode();
using ScriptTextBuffer = Vector<char16_t, 0, JSMallocAllocPolicy>;
using BinASTSourceBuffer = Vector<uint8_t>;
const ScriptTextBuffer& ScriptText() const
{
const Vector<char16_t>& ScriptText() const {
MOZ_ASSERT(IsTextSource());
return mScriptData->as<ScriptTextBuffer>();
return mScriptData->as<Vector<char16_t>>();
}
ScriptTextBuffer& ScriptText()
{
Vector<char16_t>& ScriptText() {
MOZ_ASSERT(IsTextSource());
return mScriptData->as<ScriptTextBuffer>();
return mScriptData->as<Vector<char16_t>>();
}
const BinASTSourceBuffer& ScriptBinASTData() const
{
const Vector<uint8_t>& ScriptBinASTData() const {
MOZ_ASSERT(IsBinASTSource());
return mScriptData->as<BinASTSourceBuffer>();
return mScriptData->as<Vector<uint8_t>>();
}
BinASTSourceBuffer& ScriptBinASTData()
{
Vector<uint8_t>& ScriptBinASTData() {
MOZ_ASSERT(IsBinASTSource());
return mScriptData->as<BinASTSourceBuffer>();
return mScriptData->as<Vector<uint8_t>>();
}
enum class ScriptMode : uint8_t {
@ -259,7 +252,7 @@ public:
// Holds script source data for non-inline scripts. Don't use nsString so we
// can give ownership to jsapi. Holds either char16_t source text characters
// or BinAST encoded bytes depending on mSourceEncoding.
Maybe<Variant<ScriptTextBuffer, BinASTSourceBuffer>> mScriptData;
Maybe<Variant<Vector<char16_t>, Vector<uint8_t>>> mScriptData;
// Holds the SRI serialized hash and the script bytecode for non-inline
// scripts.

Просмотреть файл

@ -491,7 +491,8 @@ ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest)
rv = FillCompileOptionsForRequest(aes, aRequest, global, &options);
if (NS_SUCCEEDED(rv)) {
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
nsAutoString inlineData;
SourceBufferHolder srcBuf = GetScriptSource(aRequest, inlineData);
rv = nsJSUtils::CompileModule(cx, srcBuf, global, options, &module);
}
}
@ -1777,16 +1778,14 @@ OffThreadScriptLoaderCallback(JS::OffThreadToken* aToken, void* aCallbackData)
}
nsresult
ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
bool* aCouldCompileOut)
ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest)
{
MOZ_ASSERT_IF(!aRequest->IsModuleRequest(), aRequest->IsReadyToRun());
MOZ_ASSERT(!aRequest->mWasCompiledOMT);
MOZ_ASSERT(aCouldCompileOut && !*aCouldCompileOut);
// Don't off-thread compile inline scripts.
if (aRequest->mIsInline) {
return NS_OK;
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject();
@ -1810,19 +1809,19 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
if (aRequest->IsTextSource()) {
if (!JS::CanCompileOffThread(cx, options, aRequest->ScriptText().length())) {
return NS_OK;
return NS_ERROR_FAILURE;
}
#ifdef JS_BUILD_BINAST
} else if (aRequest->IsBinASTSource()) {
if (!JS::CanDecodeBinASTOffThread(cx, options, aRequest->ScriptBinASTData().length())) {
return NS_OK;
return NS_ERROR_FAILURE;
}
#endif
} else {
MOZ_ASSERT(aRequest->IsBytecode());
size_t length = aRequest->mScriptBytecode.length() - aRequest->mBytecodeOffset;
if (!JS::CanDecodeOffThread(cx, options, length)) {
return NS_OK;
return NS_ERROR_FAILURE;
}
}
@ -1831,9 +1830,9 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
if (aRequest->IsModuleRequest()) {
MOZ_ASSERT(aRequest->IsTextSource());
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
if (!JS::CompileOffThreadModule(cx, options,
srcBuf,
aRequest->ScriptText().begin(),
aRequest->ScriptText().length(),
OffThreadScriptLoaderCallback,
static_cast<void*>(runnable))) {
return NS_ERROR_OUT_OF_MEMORY;
@ -1859,9 +1858,9 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
#endif
} else {
MOZ_ASSERT(aRequest->IsTextSource());
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
if (!JS::CompileOffThread(cx, options,
srcBuf,
aRequest->ScriptText().begin(),
aRequest->ScriptText().length(),
OffThreadScriptLoaderCallback,
static_cast<void*>(runnable))) {
return NS_ERROR_OUT_OF_MEMORY;
@ -1874,7 +1873,6 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
// to call ScriptLoader::ProcessOffThreadRequest with the same request.
aRequest->mProgress = ScriptLoadRequest::Progress::eCompiling;
*aCouldCompileOut = true;
Unused << runnable.forget();
return NS_OK;
}
@ -1889,42 +1887,33 @@ ScriptLoader::CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest)
NS_ASSERTION(!aRequest->InCompilingStage(),
"Candidate for off-thread compile is already in compiling stage.");
bool couldCompile = false;
nsresult rv = AttemptAsyncScriptCompile(aRequest, &couldCompile);
if (NS_FAILED(rv)) {
HandleLoadError(aRequest, rv);
nsresult rv = AttemptAsyncScriptCompile(aRequest);
if (NS_SUCCEEDED(rv)) {
return rv;
}
if (couldCompile) {
return NS_OK;
}
return ProcessRequest(aRequest);
}
SourceBufferHolder
ScriptLoader::GetScriptSource(JSContext* aCx, ScriptLoadRequest* aRequest)
ScriptLoader::GetScriptSource(ScriptLoadRequest* aRequest, nsAutoString& inlineData)
{
// Return a SourceBufferHolder object holding the script's source text.
// Ownership of the buffer is transferred to the resulting SourceBufferHolder.
// |inlineData| is used to hold the text for inline objects.
// If there's no script text, we try to get it from the element
if (aRequest->mIsInline) {
nsAutoString inlineData;
// XXX This is inefficient - GetText makes multiple
// copies.
aRequest->mElement->GetScriptText(inlineData);
size_t nbytes = inlineData.Length() * sizeof(char16_t);
JS::UniqueTwoByteChars chars(static_cast<char16_t*>(JS_malloc(aCx, nbytes)));
MOZ_RELEASE_ASSERT(chars);
memcpy(chars.get(), inlineData.get(), nbytes);
return SourceBufferHolder(std::move(chars), inlineData.Length());
return SourceBufferHolder(inlineData.get(),
inlineData.Length(),
SourceBufferHolder::NoOwnership);
}
size_t length = aRequest->ScriptText().length();
return SourceBufferHolder(aRequest->ScriptText().extractOrCopyRawBuffer(),
length,
SourceBufferHolder::GiveOwnership);
return SourceBufferHolder(aRequest->ScriptText().begin(),
aRequest->ScriptText().length(),
SourceBufferHolder::NoOwnership);
}
nsresult
@ -2369,7 +2358,8 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
&script);
} else {
MOZ_ASSERT(aRequest->IsTextSource());
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
nsAutoString inlineData;
SourceBufferHolder srcBuf = GetScriptSource(aRequest, inlineData);
if (recordreplay::IsRecordingOrReplaying()) {
recordreplay::NoteContentParse(this, options.filename(), "application/javascript",
@ -3204,12 +3194,11 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
channel->GetURI(getter_AddRefs(request->mBaseURL));
}
// Attempt to compile off main thread.
bool couldCompile = false;
rv = AttemptAsyncScriptCompile(request, &couldCompile);
NS_ENSURE_SUCCESS(rv, rv);
if (couldCompile) {
return NS_OK;
rv = AttemptAsyncScriptCompile(request);
if (NS_SUCCEEDED(rv)) {
return rv;
}
// Otherwise compile it right away and start fetching descendents.
@ -3222,15 +3211,18 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
// If this is currently blocking the parser, attempt to compile it off-main-thread.
if (aRequest == mParserBlockingRequest && NumberOfProcessors() > 1) {
MOZ_ASSERT(!aRequest->IsModuleRequest());
bool couldCompile = false;
nsresult rv = AttemptAsyncScriptCompile(aRequest, &couldCompile);
NS_ENSURE_SUCCESS(rv, rv);
if (couldCompile) {
nsresult rv = AttemptAsyncScriptCompile(aRequest);
if (rv == NS_OK) {
MOZ_ASSERT(aRequest->mProgress == ScriptLoadRequest::Progress::eCompiling,
"Request should be off-thread compiling now.");
return NS_OK;
}
// If off-thread compile errored, return the error.
if (rv != NS_ERROR_FAILURE) {
return rv;
}
// If off-thread compile was rejected, continue with regular processing.
}

Просмотреть файл

@ -454,8 +454,7 @@ private:
void ReportErrorToConsole(ScriptLoadRequest *aRequest, nsresult aResult) const;
nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
bool* aCouldCompileOut);
nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest);
nsresult ProcessRequest(ScriptLoadRequest* aRequest);
nsresult CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest);
void FireScriptAvailable(nsresult aResult,
@ -505,8 +504,8 @@ private:
void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest);
JS::SourceBufferHolder GetScriptSource(JSContext* aCx,
ScriptLoadRequest* aRequest);
JS::SourceBufferHolder GetScriptSource(ScriptLoadRequest* aRequest,
nsAutoString& inlineData);
void SetModuleFetchStarted(ModuleLoadRequest *aRequest);
void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest* aRequest,

Просмотреть файл

@ -4867,9 +4867,8 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
JS::Rooted<JS::Value> unused(aes.cx());
JS::SourceBufferHolder srcBuf(script.BeginReading(), script.Length(),
JS::SourceBufferHolder::NoOwnership);
if (!JS::Evaluate(aes.cx(), options, srcBuf, &unused) &&
if (!JS::Evaluate(aes.cx(), options, script.BeginReading(),
script.Length(), &unused) &&
!JS_IsExceptionPending(aCx)) {
retval = false;
break;

Просмотреть файл

@ -2241,10 +2241,15 @@ 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. The JS engine has taken ownership of the
// source buffer.
MOZ_RELEASE_ASSERT(!srcBuf.ownsChars());
// compile finishes. Keep the contents of the compiled script
// alive until the compilation finishes.
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,
aSrcBuf.get(), aSrcBuf.length(),
OffThreadScriptReceiverCallback,
static_cast<void*>(aOffThreadReceiver))) {
return NS_ERROR_OUT_OF_MEMORY;

Просмотреть файл

@ -487,9 +487,8 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
JS::CompileOptions options(cx);
options.setFileAndLine("typein", 0);
JS::Rooted<JSScript*> script(cx);
JS::SourceBufferHolder srcBuf(aString.get(), aString.Length(),
JS::SourceBufferHolder::NoOwnership);
if (!JS_CompileUCScript(cx, srcBuf, options, &script))
if (!JS_CompileUCScript(cx, aString.get(), aString.Length(), options,
&script))
{
return false;
}

Просмотреть файл

@ -26,9 +26,8 @@ enum class AllocFunction {
Calloc,
Realloc
};
/* Base class allocation policies providing allocation methods. */
class AllocPolicyBase
/* Policy for using system memory functions and doing no error reporting. */
class SystemAllocPolicy
{
public:
template <typename T> T* maybe_pod_malloc(size_t numElems) { return js_pod_malloc<T>(numElems); }
@ -42,12 +41,6 @@ class AllocPolicyBase
return maybe_pod_realloc<T>(p, oldSize, newSize);
}
template <typename T> void free_(T* p, size_t numElems = 0) { js_free(p); }
};
/* Policy for using system memory functions and doing no error reporting. */
class SystemAllocPolicy : public AllocPolicyBase
{
public:
void reportAllocOverflow() const {}
bool checkSimulatedOOM() const {
return !js::oom::ShouldFailWithOOM();
@ -65,7 +58,7 @@ MOZ_COLD JS_FRIEND_API(void) ReportOutOfMemory(JSContext* cx);
* FIXME bug 647103 - rewrite this in terms of temporary allocation functions,
* not the system ones.
*/
class TempAllocPolicy : public AllocPolicyBase
class TempAllocPolicy
{
JSContext* const cx_;
@ -87,9 +80,24 @@ class TempAllocPolicy : public AllocPolicyBase
public:
MOZ_IMPLICIT TempAllocPolicy(JSContext* cx) : cx_(cx) {}
template <typename T>
T* maybe_pod_malloc(size_t numElems) {
return js_pod_malloc<T>(numElems);
}
template <typename T>
T* maybe_pod_calloc(size_t numElems) {
return js_pod_calloc<T>(numElems);
}
template <typename T>
T* maybe_pod_realloc(T* prior, size_t oldSize, size_t newSize) {
return js_pod_realloc<T>(prior, oldSize, newSize);
}
template <typename T>
T* pod_malloc(size_t numElems) {
T* p = this->maybe_pod_malloc<T>(numElems);
T* p = maybe_pod_malloc<T>(numElems);
if (MOZ_UNLIKELY(!p))
p = onOutOfMemoryTyped<T>(AllocFunction::Malloc, numElems);
return p;
@ -97,7 +105,7 @@ class TempAllocPolicy : public AllocPolicyBase
template <typename T>
T* pod_calloc(size_t numElems) {
T* p = this->maybe_pod_calloc<T>(numElems);
T* p = maybe_pod_calloc<T>(numElems);
if (MOZ_UNLIKELY(!p))
p = onOutOfMemoryTyped<T>(AllocFunction::Calloc, numElems);
return p;
@ -105,7 +113,7 @@ class TempAllocPolicy : public AllocPolicyBase
template <typename T>
T* pod_realloc(T* prior, size_t oldSize, size_t newSize) {
T* p2 = this->maybe_pod_realloc<T>(prior, oldSize, newSize);
T* p2 = maybe_pod_realloc<T>(prior, oldSize, newSize);
if (MOZ_UNLIKELY(!p2))
p2 = onOutOfMemoryTyped<T>(AllocFunction::Realloc, newSize, prior);
return p2;

Просмотреть файл

@ -234,12 +234,7 @@ impl Runtime {
let _ac = AutoCompartment::with_obj(self.cx(), glob.get());
let options = CompileOptionsWrapper::new(self.cx(), filename_cstr.as_ptr(), line_num);
let mut srcBuf = JS::SourceBufferHolder {
data_: ptr,
length_: len as _,
ownsChars_: false
};
if !JS::Evaluate(self.cx(), options.ptr, &mut srcBuf, rval) {
if !JS::Evaluate2(self.cx(), options.ptr, ptr as *const u16, len as _, rval) {
debug!("...err!");
panic::maybe_resume_unwind();
Err(())

Просмотреть файл

@ -38,7 +38,7 @@ using ValueVector = JS::GCVector<JS::Value>;
using IdVector = JS::GCVector<jsid>;
using ScriptVector = JS::GCVector<JSScript*>;
class SourceBufferHolder;
class MOZ_STACK_CLASS SourceBufferHolder;
class HandleValueArray;

Просмотреть файл

@ -5175,8 +5175,7 @@ js::TestingFunctionArgumentToScript(JSContext* cx,
RootedScript script(cx);
CompileOptions options(cx);
SourceBufferHolder source(chars, len, SourceBufferHolder::NoOwnership);
if (!JS::Compile(cx, options, source, &script))
if (!JS::Compile(cx, options, chars, len, &script))
return nullptr;
return script;
}

Просмотреть файл

@ -84,11 +84,8 @@ testCompile(bool nonSyntactic)
CHECK(CompileForNonSyntacticScope(cx, options, src, length, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), true);
{
JS::SourceBufferHolder srcBuf(src_16, length, JS::SourceBufferHolder::NoOwnership);
CHECK(CompileForNonSyntacticScope(cx, options, srcBuf, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), true);
}
CHECK(CompileForNonSyntacticScope(cx, options, src_16, length, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), true);
CHECK(Compile(cx, options, buf, &script));
@ -97,19 +94,16 @@ testCompile(bool nonSyntactic)
CHECK(Compile(cx, options, src, length, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
{
JS::SourceBufferHolder srcBuf(src_16, length, JS::SourceBufferHolder::NoOwnership);
CHECK(Compile(cx, options, srcBuf, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
}
CHECK(Compile(cx, options, src_16, length, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
options.forceAsync = true;
OffThreadTask task;
OffThreadToken* token;
SourceBufferHolder srcBuf(src_16, length, SourceBufferHolder::NoOwnership);
CHECK(CompileOffThread(cx, options, srcBuf, task.OffThreadCallback, &task));
CHECK(CompileOffThread(cx, options, src_16, length,
task.OffThreadCallback, &task));
CHECK(token = task.waitUntilDone(cx));
CHECK(script = FinishOffThreadScript(cx, token));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);

Просмотреть файл

@ -40,8 +40,7 @@ eval(const char16_t* chars, size_t len, JS::MutableHandleValue rval)
JSAutoRealm ar(cx, global);
JS::CompileOptions options(cx);
JS::SourceBufferHolder srcBuf(chars, len, JS::SourceBufferHolder::NoOwnership);
return JS::Evaluate(cx, options, srcBuf, rval);
return JS::Evaluate(cx, options, chars, len, rval);
}
template<size_t N>

Просмотреть файл

@ -17,9 +17,8 @@ BEGIN_TEST(testJSEvaluateScript)
JS::CompileOptions opts(cx);
JS::AutoObjectVector scopeChain(cx);
CHECK(scopeChain.append(obj));
JS::SourceBufferHolder srcBuf(src, ArrayLength(src) - 1, JS::SourceBufferHolder::NoOwnership);
CHECK(JS::Evaluate(cx, scopeChain, opts.setFileAndLine(__FILE__, __LINE__),
srcBuf, &retval));
src, ArrayLength(src) - 1, &retval));
bool hasProp = true;
CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));

Просмотреть файл

@ -54,8 +54,7 @@ eval(const char* asciiChars, bool mutedErrors, JS::MutableHandleValue rval)
options.setMutedErrors(mutedErrors)
.setFileAndLine("", 0);
JS::SourceBufferHolder srcBuf(chars.get(), len, JS::SourceBufferHolder::NoOwnership);
return JS::Evaluate(cx, options, srcBuf, rval);
return JS::Evaluate(cx, options, chars.get(), len, rval);
}
bool

Просмотреть файл

@ -72,8 +72,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx);
JS::SourceBufferHolder srcBuf(uc_code, code_size, JS::SourceBufferHolder::NoOwnership);
CHECK(JS_CompileUCScript(cx, srcBuf, options, &script));
CHECK(JS_CompileUCScript(cx, uc_code, code_size, options, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
@ -83,8 +82,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx);
JS::SourceBufferHolder srcBuf(uc_code, 0, JS::SourceBufferHolder::NoOwnership);
CHECK(JS_CompileUCScript(cx, srcBuf, options, &script));
CHECK(JS_CompileUCScript(cx, uc_code, 0, options, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
@ -94,8 +92,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipal
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx);
JS::SourceBufferHolder srcBuf(uc_code, code_size, JS::SourceBufferHolder::NoOwnership);
CHECK(JS_CompileUCScript(cx, srcBuf, options, &script));
CHECK(JS_CompileUCScript(cx, uc_code, code_size, options, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals)

Просмотреть файл

@ -4007,20 +4007,27 @@ Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
return !!script;
}
static bool
Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length, MutableHandleScript script)
{
SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
return ::Compile(cx, options, srcBuf, script);
}
static bool
Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length, MutableHandleScript script)
{
char16_t* chars;
UniqueTwoByteChars chars;
if (options.utf8)
chars = UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(bytes, length), &length).get();
chars.reset(UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(bytes, length), &length).get());
else
chars = InflateString(cx, bytes, length);
chars.reset(InflateString(cx, bytes, length));
if (!chars)
return false;
SourceBufferHolder source(chars, length, SourceBufferHolder::GiveOwnership);
return ::Compile(cx, options, source, script);
return ::Compile(cx, options, chars.get(), length, script);
}
static bool
@ -4060,6 +4067,13 @@ JS::Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
return ::Compile(cx, options, bytes, length, script);
}
bool
JS::Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length, JS::MutableHandleScript script)
{
return ::Compile(cx, options, chars, length, script);
}
bool
JS::Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
FILE* file, JS::MutableHandleScript script)
@ -4092,6 +4106,16 @@ JS::CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& opt
return ::Compile(cx, options, bytes, length, script);
}
bool
JS::CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
const char16_t* chars, size_t length,
JS::MutableHandleScript script)
{
CompileOptions options(cx, optionsArg);
options.setNonSyntacticScope(true);
return ::Compile(cx, options, chars, length, script);
}
bool
JS::CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
FILE* file, JS::MutableHandleScript script)
@ -4215,11 +4239,11 @@ JS::CanDecodeBinASTOffThread(JSContext* cx, const ReadOnlyCompileOptions& option
JS_PUBLIC_API(bool)
JS::CompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
OffThreadCompileCallback callback, void* callbackData)
{
MOZ_ASSERT(CanCompileOffThread(cx, options, srcBuf.length()));
return StartOffThreadParseScript(cx, options, srcBuf, callback, callbackData);
MOZ_ASSERT(CanCompileOffThread(cx, options, length));
return StartOffThreadParseScript(cx, options, chars, length, callback, callbackData);
}
JS_PUBLIC_API(JSScript*)
@ -4240,11 +4264,11 @@ JS::CancelOffThreadScript(JSContext* cx, JS::OffThreadToken* token)
JS_PUBLIC_API(bool)
JS::CompileOffThreadModule(JSContext* cx, const ReadOnlyCompileOptions& options,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
OffThreadCompileCallback callback, void* callbackData)
{
MOZ_ASSERT(CanCompileOffThread(cx, options, srcBuf.length()));
return StartOffThreadParseModule(cx, options, srcBuf, callback, callbackData);
MOZ_ASSERT(CanCompileOffThread(cx, options, length));
return StartOffThreadParseModule(cx, options, chars, length, callback, callbackData);
}
JS_PUBLIC_API(JSObject*)
@ -4337,10 +4361,10 @@ JS_CompileScript(JSContext* cx, const char* ascii, size_t length,
}
JS_PUBLIC_API(bool)
JS_CompileUCScript(JSContext* cx, JS::SourceBufferHolder& srcBuf,
JS_CompileUCScript(JSContext* cx, const char16_t* chars, size_t length,
const JS::CompileOptions& options, MutableHandleScript script)
{
return ::Compile(cx, options, srcBuf, script);
return ::Compile(cx, options, chars, length, script);
}
JS_PUBLIC_API(bool)
@ -4557,23 +4581,33 @@ JS::CompileFunction(JSContext* cx, AutoObjectVector& envChain,
scope, fun);
}
JS_PUBLIC_API(bool)
JS::CompileFunction(JSContext* cx, AutoObjectVector& envChain,
const ReadOnlyCompileOptions& options,
const char* name, unsigned nargs, const char* const* argnames,
const char16_t* chars, size_t length, MutableHandleFunction fun)
{
SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
return CompileFunction(cx, envChain, options, name, nargs, argnames,
srcBuf, fun);
}
JS_PUBLIC_API(bool)
JS::CompileFunction(JSContext* cx, AutoObjectVector& envChain,
const ReadOnlyCompileOptions& options,
const char* name, unsigned nargs, const char* const* argnames,
const char* bytes, size_t length, MutableHandleFunction fun)
{
char16_t* chars;
UniqueTwoByteChars chars;
if (options.utf8)
chars = UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(bytes, length), &length).get();
chars.reset(UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(bytes, length), &length).get());
else
chars = InflateString(cx, bytes, length);
chars.reset(InflateString(cx, bytes, length));
if (!chars)
return false;
SourceBufferHolder source(chars, length, SourceBufferHolder::GiveOwnership);
return CompileFunction(cx, envChain, options, name, nargs, argnames,
source, fun);
chars.get(), length, fun);
}
JS_PUBLIC_API(bool)
@ -4752,6 +4786,15 @@ Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOptions
return ::Evaluate(cx, scope->kind(), env, optionsArg, srcBuf, rval);
}
static bool
Evaluate(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
const char16_t* chars, size_t length, MutableHandleValue rval)
{
SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
RootedObject globalLexical(cx, &cx->global()->lexicalEnvironment());
return ::Evaluate(cx, ScopeKind::Global, globalLexical, optionsArg, srcBuf, rval);
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length, MutableHandleValue rval)
@ -4801,6 +4844,21 @@ JS::Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOpt
return ::Evaluate(cx, envChain, optionsArg, srcBuf, rval);
}
JS_PUBLIC_API(bool)
JS::Evaluate(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
const char16_t* chars, size_t length, MutableHandleValue rval)
{
return ::Evaluate(cx, optionsArg, chars, length, rval);
}
JS_PUBLIC_API(bool)
JS::Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOptions& optionsArg,
const char16_t* chars, size_t length, MutableHandleValue rval)
{
SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
return ::Evaluate(cx, envChain, optionsArg, srcBuf, rval);
}
JS_PUBLIC_API(bool)
JS::Evaluate(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
const char* filename, MutableHandleValue rval)

Просмотреть файл

@ -378,7 +378,7 @@ namespace JS {
* JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership);
* JS::Compile(cx, options, srcBuf);
*/
class SourceBufferHolder final
class MOZ_STACK_CLASS SourceBufferHolder final
{
public:
enum Ownership {
@ -391,15 +391,14 @@ class SourceBufferHolder final
length_(dataLength),
ownsChars_(ownership == GiveOwnership)
{
fixEmptyBuffer();
}
SourceBufferHolder(UniqueTwoByteChars&& data, size_t dataLength)
: data_(data.release()),
length_(dataLength),
ownsChars_(true)
{
fixEmptyBuffer();
// Ensure that null buffers properly return an unowned, empty,
// null-terminated string.
static const char16_t NullChar_ = 0;
if (!get()) {
data_ = &NullChar_;
length_ = 0;
ownsChars_ = false;
}
}
SourceBufferHolder(SourceBufferHolder&& other)
@ -449,17 +448,6 @@ class SourceBufferHolder final
SourceBufferHolder(SourceBufferHolder&) = delete;
SourceBufferHolder& operator=(SourceBufferHolder&) = delete;
void fixEmptyBuffer() {
// Ensure that null buffers properly return an unowned, empty,
// null-terminated string.
static const char16_t NullChar_ = 0;
if (!get()) {
data_ = &NullChar_;
length_ = 0;
ownsChars_ = false;
}
}
const char16_t* data_;
size_t length_;
bool ownsChars_;
@ -1329,24 +1317,6 @@ JS_freeop(JSFreeOp* fop, void* p);
extern JS_PUBLIC_API(void)
JS_updateMallocCounter(JSContext* cx, size_t nbytes);
/*
* A replacement for MallocAllocPolicy that allocates in the JS heap and adds no
* extra behaviours.
*
* This is currently used for allocating source buffers for parsing. Since these
* are temporary and will not be freed by GC, the memory is not tracked by the
* usual accounting.
*/
class JS_PUBLIC_API(JSMallocAllocPolicy) : public js::AllocPolicyBase
{
public:
void reportAllocOverflow() const {}
MOZ_MUST_USE bool checkSimulatedOOM() const {
return true;
}
};
/**
* Set the size of the native stack that should not be exceed. To disable
* stack size checking pass 0.
@ -3216,7 +3186,7 @@ JS_CompileScript(JSContext* cx, const char* ascii, size_t length,
* |script| will always be set. On failure, it will be set to nullptr.
*/
extern JS_PUBLIC_API(bool)
JS_CompileUCScript(JSContext* cx, JS::SourceBufferHolder& srcBuf,
JS_CompileUCScript(JSContext* cx, const char16_t* chars, size_t length,
const JS::CompileOptions& options,
JS::MutableHandleScript script);
@ -3629,6 +3599,10 @@ extern JS_PUBLIC_API(bool)
Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length, JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length, JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
FILE* file, JS::MutableHandleScript script);
@ -3645,6 +3619,10 @@ extern JS_PUBLIC_API(bool)
CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length, JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length, JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& options,
FILE* file, JS::MutableHandleScript script);
@ -3678,7 +3656,7 @@ CanDecodeOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t
extern JS_PUBLIC_API(bool)
CompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
OffThreadCompileCallback callback, void* callbackData);
extern JS_PUBLIC_API(JSScript*)
@ -3689,7 +3667,7 @@ CancelOffThreadScript(JSContext* cx, OffThreadToken* token);
extern JS_PUBLIC_API(bool)
CompileOffThreadModule(JSContext* cx, const ReadOnlyCompileOptions& options,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
OffThreadCompileCallback callback, void* callbackData);
extern JS_PUBLIC_API(JSObject*)
@ -3734,6 +3712,15 @@ CancelMultiOffThreadScriptsDecoder(JSContext* cx, OffThreadToken* token);
* global must not be explicitly included in the scope chain.
*/
extern JS_PUBLIC_API(bool)
CompileFunction(JSContext* cx, AutoObjectVector& envChain,
const ReadOnlyCompileOptions& options,
const char* name, unsigned nargs, const char* const* argnames,
const char16_t* chars, size_t length, JS::MutableHandleFunction fun);
/**
* Same as above, but taking a SourceBufferHolder for the function body.
*/
extern JS_PUBLIC_API(bool)
CompileFunction(JSContext* cx, AutoObjectVector& envChain,
const ReadOnlyCompileOptions& options,
const char* name, unsigned nargs, const char* const* argnames,
@ -3850,6 +3837,22 @@ extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOptions& options,
SourceBufferHolder& srcBuf, JS::MutableHandleValue rval);
/**
* Evaluate the given character buffer in the scope of the current global of cx.
*/
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length, JS::MutableHandleValue rval);
/**
* As above, but providing an explicit scope chain. envChain must not include
* the global object on it; that's implicit. It needs to contain the other
* objects that should end up on the script's scope chain.
*/
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length, JS::MutableHandleValue rval);
/**
* Evaluate the given byte buffer in the scope of the current global of cx.
*/

Просмотреть файл

@ -1985,12 +1985,10 @@ Evaluate(JSContext* cx, unsigned argc, Value* vp)
return false;
} else {
mozilla::Range<const char16_t> chars = codeChars.twoByteRange();
JS::SourceBufferHolder srcBuf(chars.begin().get(), chars.length(),
JS::SourceBufferHolder::NoOwnership);
if (envChain.length() == 0) {
(void) JS::Compile(cx, options, srcBuf, &script);
(void) JS::Compile(cx, options, chars.begin().get(), chars.length(), &script);
} else {
(void) JS::CompileForNonSyntacticScope(cx, options, srcBuf, &script);
(void) JS::CompileForNonSyntacticScope(cx, options, chars.begin().get(), chars.length(), &script);
}
}
@ -2189,8 +2187,8 @@ Run(JSContext* cx, unsigned argc, Value* vp)
if (!chars.initTwoByte(cx, str))
return false;
JS::SourceBufferHolder srcBuf(chars.twoByteRange().begin().get(), str->length(),
JS::SourceBufferHolder::NoOwnership);
const char16_t* ucbuf = chars.twoByteRange().begin().get();
size_t buflen = str->length();
RootedScript script(cx);
int64_t startClock = PRMJ_Now();
@ -2205,7 +2203,7 @@ Run(JSContext* cx, unsigned argc, Value* vp)
.setFileAndLine(filename.ptr(), 1)
.setIsRunOnce(true)
.setNoScriptRval(true);
if (!JS_CompileUCScript(cx, srcBuf, options, &script))
if (!JS_CompileUCScript(cx, ucbuf, buflen, options, &script))
return false;
}
@ -3551,8 +3549,7 @@ EvalInContext(JSContext* cx, unsigned argc, Value* vp)
}
JS::CompileOptions opts(cx);
opts.setFileAndLine(filename.get(), lineno);
JS::SourceBufferHolder srcBuf(src, srclen, JS::SourceBufferHolder::NoOwnership);
if (!JS::Evaluate(cx, opts, srcBuf, args.rval())) {
if (!JS::Evaluate(cx, opts, src, srclen, args.rval())) {
return false;
}
}
@ -3655,9 +3652,7 @@ WorkerMain(WorkerInput* input)
AutoReportException are(cx);
RootedScript script(cx);
JS::SourceBufferHolder srcBuf(input->chars.get(), input->length,
JS::SourceBufferHolder::NoOwnership);
if (!JS::Compile(cx, options, srcBuf, &script))
if (!JS::Compile(cx, options, input->chars.get(), input->length, &script))
break;
RootedValue result(cx);
JS_ExecuteScript(cx, script, &result);
@ -4243,10 +4238,8 @@ Compile(JSContext* cx, unsigned argc, Value* vp)
.setIsRunOnce(true)
.setNoScriptRval(true);
RootedScript script(cx);
JS::SourceBufferHolder srcBuf(stableChars.twoByteRange().begin().get(),
scriptContents->length(),
JS::SourceBufferHolder::NoOwnership);
bool ok = JS_CompileUCScript(cx, srcBuf, options, &script);
const char16_t* chars = stableChars.twoByteRange().begin().get();
bool ok = JS_CompileUCScript(cx, chars, scriptContents->length(), options, &script);
args.rval().setUndefined();
return ok;
}
@ -4743,9 +4736,7 @@ OffThreadCompileScript(JSContext* cx, unsigned argc, Value* vp)
if (!job)
return false;
JS::SourceBufferHolder srcBuf(job->sourceChars(), length,
JS::SourceBufferHolder::NoOwnership);
if (!JS::CompileOffThread(cx, options, srcBuf,
if (!JS::CompileOffThread(cx, options, job->sourceChars(), length,
OffThreadCompileScriptCallback, job))
{
job->cancel();
@ -4831,9 +4822,7 @@ OffThreadCompileModule(JSContext* cx, unsigned argc, Value* vp)
if (!job)
return false;
JS::SourceBufferHolder srcBuf(job->sourceChars(), length,
JS::SourceBufferHolder::NoOwnership);
if (!JS::CompileOffThreadModule(cx, options, srcBuf,
if (!JS::CompileOffThreadModule(cx, options, job->sourceChars(), length,
OffThreadCompileScriptCallback, job))
{
job->cancel();
@ -6697,16 +6686,15 @@ EntryPoints(JSContext* cx, unsigned argc, Value* vp)
AutoStableStringChars stableChars(cx);
if (!stableChars.initTwoByte(cx, codeString))
return false;
JS::SourceBufferHolder srcBuf(stableChars.twoByteRange().begin().get(),
codeString->length(),
JS::SourceBufferHolder::NoOwnership);
const char16_t* chars = stableChars.twoByteRange().begin().get();
size_t length = codeString->length();
CompileOptions options(cx);
options.setIntroductionType("entryPoint eval")
.setFileAndLine("entryPoint eval", 1);
js::shell::ShellAutoEntryMonitor sarep(cx);
if (!JS::Evaluate(cx, options, srcBuf, &dummy))
if (!JS::Evaluate(cx, options, chars, length, &dummy))
return false;
return sarep.buildResult(cx, args.rval());
}

Просмотреть файл

@ -482,21 +482,22 @@ ParseTask::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
errors.sizeOfExcludingThis(mallocSizeOf);
}
ScriptParseTask::ScriptParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
ScriptParseTask::ScriptParseTask(JSContext* cx, const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData)
: ParseTask(ParseTaskKind::Script, cx, callback, callbackData),
data(std::move(srcBuf))
data(TwoByteChars(chars, length))
{}
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, data,
options, srcBuf,
/* sourceObjectOut = */ &sourceObject.get());
if (script)
scripts.infallibleAppend(script);
@ -504,18 +505,19 @@ ScriptParseTask::parse(JSContext* cx)
sourceObjects.infallibleAppend(sourceObject);
}
ModuleParseTask::ModuleParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
ModuleParseTask::ModuleParseTask(JSContext* cx, const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData)
: ParseTask(ParseTaskKind::Module, cx, callback, callbackData),
data(std::move(srcBuf))
data(TwoByteChars(chars, length))
{}
void
ModuleParseTask::parse(JSContext* cx)
{
SourceBufferHolder srcBuf(data.begin().get(), data.length(), SourceBufferHolder::NoOwnership);
Rooted<ScriptSourceObject*> sourceObject(cx);
ModuleObject* module = frontend::CompileModule(cx, options, data, alloc, &sourceObject.get());
ModuleObject* module = frontend::CompileModule(cx, options, srcBuf, alloc, &sourceObject.get());
if (module) {
scripts.infallibleAppend(module->script());
if (sourceObject)
@ -823,10 +825,10 @@ StartOffThreadParseTask(JSContext* cx, ParseTask* task, const ReadOnlyCompileOpt
bool
js::StartOffThreadParseScript(JSContext* cx, const ReadOnlyCompileOptions& options,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData)
{
auto task = cx->make_unique<ScriptParseTask>(cx, srcBuf, callback, callbackData);
auto task = cx->make_unique<ScriptParseTask>(cx, chars, length, callback, callbackData);
if (!task || !StartOffThreadParseTask(cx, task.get(), options))
return false;
@ -836,10 +838,10 @@ js::StartOffThreadParseScript(JSContext* cx, const ReadOnlyCompileOptions& optio
bool
js::StartOffThreadParseModule(JSContext* cx, const ReadOnlyCompileOptions& options,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData)
{
auto task = cx->make_unique<ModuleParseTask>(cx, srcBuf, callback, callbackData);
auto task = cx->make_unique<ModuleParseTask>(cx, chars, length, 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,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData);
bool
StartOffThreadParseModule(JSContext* cx, const ReadOnlyCompileOptions& options,
JS::SourceBufferHolder& srcBuf,
const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData);
bool
@ -722,18 +722,18 @@ struct ParseTask : public mozilla::LinkedListElement<ParseTask>, public JS::OffT
struct ScriptParseTask : public ParseTask
{
JS::SourceBufferHolder data;
JS::TwoByteChars data;
ScriptParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
ScriptParseTask(JSContext* cx, const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData);
void parse(JSContext* cx) override;
};
struct ModuleParseTask : public ParseTask
{
JS::SourceBufferHolder data;
JS::TwoByteChars data;
ModuleParseTask(JSContext* cx, JS::SourceBufferHolder& srcBuf,
ModuleParseTask(JSContext* cx, const char16_t* chars, size_t length,
JS::OffThreadCompileCallback callback, void* callbackData);
void parse(JSContext* cx) override;
};

Просмотреть файл

@ -131,9 +131,8 @@ AsyncScriptCompiler::StartCompile(JSContext* aCx)
{
Rooted<JSObject*> global(aCx, mGlobalObject->GetGlobalJSObject());
JS::SourceBufferHolder srcBuf(std::move(mScriptText), mScriptLength);
if (JS::CanCompileOffThread(aCx, mOptions, mScriptLength)) {
if (!JS::CompileOffThread(aCx, mOptions, srcBuf,
if (!JS::CompileOffThread(aCx, mOptions, mScriptText.get(), mScriptLength,
OffThreadScriptLoaderCallback,
static_cast<void*>(this))) {
return false;
@ -144,7 +143,7 @@ AsyncScriptCompiler::StartCompile(JSContext* aCx)
}
Rooted<JSScript*> script(aCx);
if (!JS::Compile(aCx, mOptions, srcBuf, &script)) {
if (!JS::Compile(aCx, mOptions, mScriptText.get(), mScriptLength, &script)) {
return false;
}

Просмотреть файл

@ -1849,9 +1849,8 @@ xpc::EvalInSandbox(JSContext* cx, HandleObject sandboxArg, const nsAString& sour
JS::CompileOptions options(sandcx);
options.setFileAndLine(filenameBuf.get(), lineNo);
MOZ_ASSERT(JS_IsGlobalObject(sandbox));
JS::SourceBufferHolder buffer(PromiseFlatString(source).get(), source.Length(),
JS::SourceBufferHolder::NoOwnership);
ok = JS::Evaluate(sandcx, options, buffer, &v);
ok = JS::Evaluate(sandcx, options,
PromiseFlatString(source).get(), source.Length(), &v);
// If the sandbox threw an exception, grab it off the context.
if (aes.HasException()) {