Bug 1100579 part 1. Remove the overloads of JS::Evaluate that don't take an rval mutable handle, and control the behavior via the JS::CompileOptions instead. r=waldo,bholley

This commit is contained in:
Boris Zbarsky 2014-11-18 23:27:16 -05:00
parent 7583c5ae7e
commit 67d7197390
7 changed files with 39 additions and 93 deletions

View File

@ -253,11 +253,7 @@ nsJSUtils::EvaluateString(JSContext* aCx,
ok = false;
}
} else if (ok) {
if (!aCompileOptions.noScriptRval) {
ok = JS::Evaluate(aCx, scopeChain, aCompileOptions, aSrcBuf, aRetValue);
} else {
ok = JS::Evaluate(aCx, scopeChain, aCompileOptions, aSrcBuf);
}
ok = JS::Evaluate(aCx, scopeChain, aCompileOptions, aSrcBuf, aRetValue);
}
if (ok && aEvaluateOptions.coerceToString && !aRetValue.isUndefined()) {

View File

@ -758,7 +758,8 @@ ScriptExecutorRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
loadInfo.mScriptTextBuf = nullptr;
loadInfo.mScriptTextLength = 0;
if (!JS::Evaluate(aCx, global, options, srcBuf)) {
JS::Rooted<JS::Value> unused(aCx);
if (!JS::Evaluate(aCx, global, options, srcBuf, &unused)) {
return true;
}

View File

@ -5631,8 +5631,10 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
options.setFileAndLine(info->mFilename.get(), info->mLineNumber)
.setNoScriptRval(true);
JS::Rooted<JS::Value> unused(aCx);
if ((expression.IsEmpty() ||
!JS::Evaluate(aCx, global, options, expression.get(), expression.Length())) &&
!JS::Evaluate(aCx, global, options,
expression.get(), expression.Length(), &unused)) &&
!JS_ReportPendingException(aCx)) {
retval = false;
break;

View File

@ -16,9 +16,15 @@ BEGIN_TEST(testBug795104)
s[0] = '"';
memset(s + 1, 'x', strLen - 2);
s[strLen - 1] = '"';
CHECK(JS::Evaluate(cx, global, opts, s, strLen));
// We don't want an rval for our Evaluate call
opts.setNoScriptRval(true);
JS::RootedValue unused(cx);
CHECK(JS::Evaluate(cx, global, opts, s, strLen, &unused));
JS::RootedFunction fun(cx);
JS::AutoObjectVector emptyScopeChain(cx);
// But when compiling a function we don't want to use no-rval
// mode, since it's not supported for functions.
opts.setNoScriptRval(false);
CHECK(JS::CompileFunction(cx, emptyScopeChain, opts, "f", 0, nullptr, s, strLen, &fun));
CHECK(fun);
JS_free(cx, s);

View File

@ -4764,7 +4764,7 @@ static const unsigned LARGE_SCRIPT_LENGTH = 500*1024;
static bool
Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
SourceBufferHolder &srcBuf, JS::Value *rval)
SourceBufferHolder &srcBuf, MutableHandleValue rval)
{
CompileOptions options(cx, optionsArg);
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
@ -4775,7 +4775,6 @@ Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsA
AutoLastFrameCheck lfc(cx);
options.setCompileAndGo(obj->is<GlobalObject>());
options.setNoScriptRval(!rval);
SourceCompressionTask sct(cx);
RootedScript script(cx, frontend::CompileScript(cx, &cx->tempLifoAlloc(),
obj, NullPtr(), options,
@ -4785,7 +4784,8 @@ Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsA
MOZ_ASSERT(script->getVersion() == options.version);
bool result = Execute(cx, script, *obj, rval);
bool result = Execute(cx, script, *obj,
options.noScriptRval ? nullptr : rval.address());
if (!sct.complete())
result = false;
@ -4805,7 +4805,7 @@ Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsA
static bool
Evaluate(JSContext *cx, AutoObjectVector &scopeChain, const ReadOnlyCompileOptions &optionsArg,
SourceBufferHolder &srcBuf, JS::Value *rval)
SourceBufferHolder &srcBuf, MutableHandleValue rval)
{
RootedObject dynamicScope(cx);
RootedObject unusedStaticScope(cx);
@ -4816,15 +4816,15 @@ Evaluate(JSContext *cx, AutoObjectVector &scopeChain, const ReadOnlyCompileOptio
static bool
Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char16_t *chars, size_t length, JS::Value *rval)
const char16_t *chars, size_t length, MutableHandleValue rval)
{
SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
return ::Evaluate(cx, obj, optionsArg, srcBuf, rval);
}
static bool
Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, JS::Value *rval)
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, MutableHandleValue rval)
{
char16_t *chars;
if (options.utf8)
@ -4841,7 +4841,7 @@ Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
static bool
Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char *filename, JS::Value *rval)
const char *filename, MutableHandleValue rval)
{
FileContents buffer(cx);
{
@ -4855,74 +4855,32 @@ Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsA
return Evaluate(cx, obj, options, buffer.begin(), buffer.length(), rval);
}
extern JS_PUBLIC_API(bool)
JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
SourceBufferHolder &srcBuf, MutableHandleValue rval)
{
return ::Evaluate(cx, obj, optionsArg, srcBuf, rval.address());
return ::Evaluate(cx, obj, optionsArg, srcBuf, rval);
}
extern JS_PUBLIC_API(bool)
JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, AutoObjectVector &scopeChain, const ReadOnlyCompileOptions &optionsArg,
SourceBufferHolder &srcBuf, MutableHandleValue rval)
{
return ::Evaluate(cx, scopeChain, optionsArg, srcBuf, rval.address());
return ::Evaluate(cx, scopeChain, optionsArg, srcBuf, rval);
}
extern JS_PUBLIC_API(bool)
JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char16_t *chars, size_t length, MutableHandleValue rval)
{
return ::Evaluate(cx, obj, optionsArg, chars, length, rval.address());
return ::Evaluate(cx, obj, optionsArg, chars, length, rval);
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, MutableHandleValue rval)
{
return ::Evaluate(cx, obj, options, bytes, length, rval.address());
}
extern JS_PUBLIC_API(bool)
JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char *filename, MutableHandleValue rval)
{
return ::Evaluate(cx, obj, optionsArg, filename, rval.address());
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
SourceBufferHolder &srcBuf)
{
return ::Evaluate(cx, obj, optionsArg, srcBuf, nullptr);
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, AutoObjectVector &scopeChain, const ReadOnlyCompileOptions &optionsArg,
SourceBufferHolder &srcBuf)
{
return ::Evaluate(cx, scopeChain, optionsArg, srcBuf, nullptr);
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char16_t *chars, size_t length)
{
return ::Evaluate(cx, obj, optionsArg, chars, length, nullptr);
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length)
{
return ::Evaluate(cx, obj, options, bytes, length, nullptr);
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char *filename)
{
return ::Evaluate(cx, obj, optionsArg, filename, nullptr);
return ::Evaluate(cx, obj, optionsArg, filename, rval);
}
JS_PUBLIC_API(bool)
@ -4932,7 +4890,7 @@ JS_EvaluateUCScript(JSContext *cx, HandleObject obj, const char16_t *chars, unsi
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return ::Evaluate(cx, obj, options, chars, length, rval.address());
return ::Evaluate(cx, obj, options, chars, length, rval);
}
JS_PUBLIC_API(bool)
@ -4942,7 +4900,7 @@ JS_EvaluateUCScript(JSContext *cx, HandleObject obj, SourceBufferHolder &srcBuf,
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return ::Evaluate(cx, obj, options, srcBuf, rval.address());
return ::Evaluate(cx, obj, options, srcBuf, rval);
}
JS_PUBLIC_API(bool)
@ -4952,7 +4910,7 @@ JS_EvaluateScript(JSContext *cx, HandleObject obj, const char *bytes, unsigned n
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return ::Evaluate(cx, obj, options, bytes, nbytes, rval.address());
return JS::Evaluate(cx, obj, options, bytes, nbytes, rval);
}
JS_PUBLIC_API(bool)
@ -4960,9 +4918,11 @@ JS_EvaluateScript(JSContext *cx, HandleObject obj, const char *bytes, unsigned n
const char *filename, unsigned lineno)
{
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
options.setFileAndLine(filename, lineno)
.setNoScriptRval(true);
return ::Evaluate(cx, obj, options, bytes, nbytes, nullptr);
RootedValue unused(cx);
return JS::Evaluate(cx, obj, options, bytes, nbytes, &unused);
}
JS_PUBLIC_API(bool)

View File

@ -4106,26 +4106,6 @@ extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char *filename, JS::MutableHandleValue rval);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
SourceBufferHolder &srcBuf);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, AutoObjectVector &scopeChain,
const ReadOnlyCompileOptions &options, SourceBufferHolder &srcBuf);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char16_t *chars, size_t length);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char *filename);
} /* namespace JS */
extern JS_PUBLIC_API(bool)

View File

@ -860,8 +860,9 @@ LoadScript(JSContext *cx, unsigned argc, jsval *vp, bool scriptRelative)
.setCompileAndGo(true)
.setNoScriptRval(true);
RootedScript script(cx);
RootedValue unused(cx);
if ((compileOnly && !Compile(cx, thisobj, opts, filename.ptr(), &script)) ||
!Evaluate(cx, thisobj, opts, filename.ptr()))
!Evaluate(cx, thisobj, opts, filename.ptr(), &unused))
{
return false;
}