Backed out 7 changesets (bug 1475228) for causing Spidermonkey rust failures on Linux x64 debug

Backed out changeset e91802969fb7 (bug 1475228)
Backed out changeset 623af73419eb (bug 1475228)
Backed out changeset bf96bd78dc11 (bug 1475228)
Backed out changeset 104817d51d1b (bug 1475228)
Backed out changeset d3829c85f650 (bug 1475228)
Backed out changeset 74d10b32b3ea (bug 1475228)
Backed out changeset dde64fbe2f0d (bug 1475228)
This commit is contained in:
Margareta Eliza Balazs 2018-07-17 17:57:55 +03:00
Родитель b25dbdce5c
Коммит ad89a11136
23 изменённых файлов: 256 добавлений и 225 удалений

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

@ -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);
}
}
@ -1769,16 +1770,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();
@ -1802,19 +1801,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;
}
}
@ -1823,9 +1822,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;
@ -1851,9 +1850,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;
@ -1866,7 +1865,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;
}
@ -1881,42 +1879,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
@ -2361,7 +2350,8 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
&script);
} else {
MOZ_ASSERT(aRequest->IsTextSource());
SourceBufferHolder srcBuf = GetScriptSource(cx, aRequest);
nsAutoString inlineData;
SourceBufferHolder srcBuf = GetScriptSource(aRequest, inlineData);
rv = exec.CompileAndExec(options, srcBuf, &script);
}
}
@ -3190,12 +3180,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.
@ -3208,15 +3197,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,

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

@ -4941,9 +4941,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;

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

@ -2376,10 +2376,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;
}

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

@ -2417,7 +2417,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);
}
void free_(void* p) { 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;

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

@ -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;

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

@ -5180,8 +5180,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);

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

@ -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)

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

@ -3995,20 +3995,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
@ -4048,6 +4055,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)
@ -4080,6 +4094,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)
@ -4201,11 +4225,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*)
@ -4226,11 +4250,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*)
@ -4323,10 +4347,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)
@ -4543,23 +4567,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)
@ -4738,6 +4772,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)
@ -4787,6 +4830,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_;
@ -1316,24 +1304,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.
@ -3203,7 +3173,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);
@ -3616,6 +3586,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);
@ -3632,6 +3606,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);
@ -3665,7 +3643,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*)
@ -3676,7 +3654,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*)
@ -3721,6 +3699,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,
@ -3837,6 +3824,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.
*/

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

@ -1986,12 +1986,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);
}
}
@ -2190,8 +2188,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();
@ -2206,7 +2204,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;
}
@ -3534,8 +3532,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;
}
}
@ -3638,9 +3635,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);
@ -4226,10 +4221,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;
}
@ -4726,9 +4719,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();
@ -4814,9 +4805,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();
@ -6680,16 +6669,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;

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

@ -589,12 +589,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
@ -720,18 +720,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;
}

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

@ -1848,9 +1848,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()) {