Bug 959787 - Handlify JS_ExecuteScript and JS::Evaluate APIs r=terrence r=bz

This commit is contained in:
Jon Coppeard 2014-04-01 11:34:39 +01:00
Родитель 0d05dddd89
Коммит fb6ccb11db
32 изменённых файлов: 231 добавлений и 112 удалений

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

@ -1433,7 +1433,7 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL,
ok = JS_CallFunctionValue(cx, global, methodVal,
JS::HandleValueArray::empty(), &rval);
} else if (script) {
ok = JS_ExecuteScript(cx, global, script, nullptr);
ok = JS_ExecuteScript(cx, global, script);
}
if (!ok) {

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

@ -1088,9 +1088,7 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
JS::CompileOptions options(entryScript.cx());
FillCompileOptionsForRequest(aRequest, global, &options);
nsJSUtils::EvaluateOptions evalOptions;
nsresult rv = nsJSUtils::EvaluateString(entryScript.cx(), aScript, global,
options, evalOptions, nullptr,
nsresult rv = nsJSUtils::EvaluateString(entryScript.cx(), aScript, global, options,
aOffThreadToken);
// Put the old script back in case it wants to do anything else.

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

@ -3679,8 +3679,7 @@ XULDocument::ExecuteScript(nsIScriptContext * aContext,
JS::ExposeObjectToActiveJS(global);
xpc_UnmarkGrayScript(aScriptObject);
JSAutoCompartment ac(cx, global);
JS::Rooted<JS::Value> unused(cx);
if (!JS_ExecuteScript(cx, global, aScriptObject, unused.address()))
if (!JS_ExecuteScript(cx, global, aScriptObject))
nsJSUtils::ReportPendingException(cx);
return NS_OK;
}

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

@ -11854,9 +11854,8 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
options.setFileAndLine(filename, lineNo)
.setVersion(JSVERSION_DEFAULT);
JS::Rooted<JSObject*> global(entryScript.cx(), FastGetGlobalJSObject());
nsJSUtils::EvaluateOptions evalOptions;
nsJSUtils::EvaluateString(entryScript.cx(), nsDependentString(script),
global, options, evalOptions, nullptr);
global, options);
} else {
// Hold strong ref to ourselves while we call the callback.
nsCOMPtr<nsISupports> me(static_cast<nsIDOMWindow *>(this));

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

@ -176,24 +176,24 @@ nsJSUtils::EvaluateString(JSContext* aCx,
const nsAString& aScript,
JS::Handle<JSObject*> aScopeObject,
JS::CompileOptions& aCompileOptions,
EvaluateOptions& aEvaluateOptions,
JS::Value* aRetValue,
const EvaluateOptions& aEvaluateOptions,
JS::MutableHandle<JS::Value> aRetValue,
void **aOffThreadToken)
{
PROFILER_LABEL("JS", "EvaluateString");
MOZ_ASSERT_IF(aCompileOptions.versionSet,
aCompileOptions.version != JSVERSION_UNKNOWN);
MOZ_ASSERT_IF(aEvaluateOptions.coerceToString, aRetValue);
MOZ_ASSERT_IF(!aEvaluateOptions.reportUncaught, aRetValue);
MOZ_ASSERT_IF(aEvaluateOptions.coerceToString, aEvaluateOptions.needResult);
MOZ_ASSERT_IF(!aEvaluateOptions.reportUncaught, aEvaluateOptions.needResult);
MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext());
// Unfortunately, the JS engine actually compiles scripts with a return value
// in a different, less efficient way. Furthermore, it can't JIT them in many
// cases. So we need to be explicitly told whether the caller cares about the
// return value. Callers use null to indicate they don't care.
if (aRetValue) {
*aRetValue = JSVAL_VOID;
}
// return value. Callers can do this by calling the other overload of
// EvaluateString() which calls this function with aEvaluateOptions.needResult
// set to false.
aRetValue.setUndefined();
JS::ExposeObjectToActiveJS(aScopeObject);
nsAutoMicroTask mt;
@ -221,53 +221,77 @@ nsJSUtils::EvaluateString(JSContext* aCx,
script(aCx, JS::FinishOffThreadScript(aCx, JS_GetRuntime(aCx), *aOffThreadToken));
*aOffThreadToken = nullptr; // Mark the token as having been finished.
if (script) {
ok = JS_ExecuteScript(aCx, rootedScope, script, aRetValue);
if (aEvaluateOptions.needResult) {
ok = JS_ExecuteScript(aCx, rootedScope, script, aRetValue);
} else {
ok = JS_ExecuteScript(aCx, rootedScope, script);
}
} else {
ok = false;
}
} else {
ok = JS::Evaluate(aCx, rootedScope, aCompileOptions,
PromiseFlatString(aScript).get(),
aScript.Length(), aRetValue);
if (aEvaluateOptions.needResult) {
ok = JS::Evaluate(aCx, rootedScope, aCompileOptions,
PromiseFlatString(aScript).get(),
aScript.Length(), aRetValue);
} else {
ok = JS::Evaluate(aCx, rootedScope, aCompileOptions,
PromiseFlatString(aScript).get(),
aScript.Length());
}
}
if (ok && aEvaluateOptions.coerceToString && !aRetValue->isUndefined()) {
JS::Rooted<JS::Value> value(aCx, *aRetValue);
if (ok && aEvaluateOptions.coerceToString && !aRetValue.isUndefined()) {
JS::Rooted<JS::Value> value(aCx, aRetValue);
JSString* str = JS::ToString(aCx, value);
ok = !!str;
*aRetValue = ok ? JS::StringValue(str) : JS::UndefinedValue();
aRetValue.set(ok ? JS::StringValue(str) : JS::UndefinedValue());
}
}
if (!ok) {
if (aEvaluateOptions.reportUncaught) {
ReportPendingException(aCx);
if (aRetValue) {
*aRetValue = JS::UndefinedValue();
if (aEvaluateOptions.needResult) {
aRetValue.setUndefined();
}
} else {
rv = JS_IsExceptionPending(aCx) ? NS_ERROR_FAILURE
: NS_ERROR_OUT_OF_MEMORY;
JS::Rooted<JS::Value> exn(aCx);
JS_GetPendingException(aCx, &exn);
if (aRetValue) {
*aRetValue = exn;
if (aEvaluateOptions.needResult) {
aRetValue.set(exn);
}
JS_ClearPendingException(aCx);
}
}
// Wrap the return value into whatever compartment aCx was in.
if (aRetValue) {
JS::Rooted<JS::Value> v(aCx, *aRetValue);
if (aEvaluateOptions.needResult) {
JS::Rooted<JS::Value> v(aCx, aRetValue);
if (!JS_WrapValue(aCx, &v)) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aRetValue = v;
aRetValue.set(v);
}
return rv;
}
nsresult
nsJSUtils::EvaluateString(JSContext* aCx,
const nsAString& aScript,
JS::Handle<JSObject*> aScopeObject,
JS::CompileOptions& aCompileOptions,
void **aOffThreadToken)
{
EvaluateOptions options;
options.setNeedResult(false);
JS::RootedValue unused(aCx);
return EvaluateString(aCx, aScript, aScopeObject, aCompileOptions,
options, &unused, aOffThreadToken);
}
//
// nsDOMJSUtils.h
//

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

@ -64,9 +64,11 @@ public:
struct EvaluateOptions {
bool coerceToString;
bool reportUncaught;
bool needResult;
explicit EvaluateOptions() : coerceToString(false)
, reportUncaught(true)
, needResult(true)
{}
EvaluateOptions& setCoerceToString(bool aCoerce) {
@ -78,14 +80,26 @@ public:
reportUncaught = aReport;
return *this;
}
EvaluateOptions& setNeedResult(bool aNeedResult) {
needResult = aNeedResult;
return *this;
}
};
static nsresult EvaluateString(JSContext* aCx,
const nsAString& aScript,
JS::Handle<JSObject*> aScopeObject,
JS::CompileOptions &aCompileOptions,
EvaluateOptions& aEvaluateOptions,
JS::Value* aRetValue,
const EvaluateOptions& aEvaluateOptions,
JS::MutableHandle<JS::Value> aRetValue,
void **aOffThreadToken = nullptr);
static nsresult EvaluateString(JSContext* aCx,
const nsAString& aScript,
JS::Handle<JSObject*> aScopeObject,
JS::CompileOptions &aCompileOptions,
void **aOffThreadToken = nullptr);
};

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

@ -1558,7 +1558,7 @@ _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result)
JS::Rooted<JS::Value> rval(cx);
nsJSUtils::EvaluateOptions evalOptions;
nsresult rv = nsJSUtils::EvaluateString(cx, utf16script, obj, options,
evalOptions, rval.address());
evalOptions, &rval);
return NS_SUCCEEDED(rv) &&
(!result || JSValToNPVariant(npp, cx, rval, result));

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

@ -315,8 +315,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
nsJSUtils::EvaluateOptions evalOptions;
evalOptions.setCoerceToString(true);
rv = nsJSUtils::EvaluateString(cx, NS_ConvertUTF8toUTF16(script),
globalJSObject, options, evalOptions,
v.address());
globalJSObject, options, evalOptions, &v);
// If there's an error on cx as a result of that call, report
// it now -- either we're just running under the event loop,

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

@ -717,7 +717,7 @@ ScriptExecutorRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
JS::CompileOptions options(aCx);
options.setFileAndLine(filename.get(), 1);
if (!JS::Evaluate(aCx, global, options, loadInfo.mScriptText.get(),
loadInfo.mScriptText.Length(), nullptr)) {
loadInfo.mScriptText.Length())) {
return true;
}

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

@ -5428,8 +5428,7 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
options.setFileAndLine(info->mFilename.get(), info->mLineNumber);
if ((expression.IsEmpty() ||
!JS::Evaluate(aCx, global, options, expression.get(),
expression.Length(), nullptr)) &&
!JS::Evaluate(aCx, global, options, expression.get(), expression.Length())) &&
!JS_ReportPendingException(aCx)) {
retval = false;
break;

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

@ -431,7 +431,7 @@ nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
rv = nsJSUtils::EvaluateString(cx, nsDependentString(mFieldText,
mFieldTextLength),
wrappedNode, options, evalOptions,
result.address());
&result);
if (NS_FAILED(rv)) {
return rv;
}

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

@ -170,8 +170,7 @@ Load(JSContext *cx,
if (!script)
return false;
JS::Rooted<JS::Value> result(cx);
if (!JS_ExecuteScript(cx, obj, script, result.address())) {
if (!JS_ExecuteScript(cx, obj, script)) {
return false;
}
}
@ -337,7 +336,7 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
.setFileAndLine(filename, 1);
JS::Rooted<JSScript*> script(cx, JS::Compile(cx, obj, options, file));
if (script)
(void)JS_ExecuteScript(cx, obj, script, result.address());
(void)JS_ExecuteScript(cx, obj, script, &result);
return;
}
@ -377,7 +376,7 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
if (script) {
JSErrorReporter older;
ok = JS_ExecuteScript(cx, obj, script, result.address());
ok = JS_ExecuteScript(cx, obj, script, &result);
if (ok && result != JSVAL_VOID) {
/* Suppress error reports from JS::ToString(). */
older = JS_SetErrorReporter(cx, nullptr);
@ -592,7 +591,7 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
}
JS::Rooted<JS::Value> result(cx);
bool ok = JS_ExecuteScript(cx, global, script, result.address());
bool ok = JS_ExecuteScript(cx, global, script, &result);
if (ok && result != JSVAL_VOID) {
JSErrorReporter old = JS_SetErrorReporter(cx, nullptr);
JSString* str = JS::ToString(cx, result);

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

@ -126,7 +126,7 @@ ThrowHook(JSContext *cx, JSScript *, jsbytecode *, jsval *rval, void *closure)
char text[] = "new Error()";
JS::RootedValue _(cx);
JS_EvaluateScript(cx, global, text, strlen(text), "", 0, _.address());
JS_EvaluateScript(cx, global, text, strlen(text), "", 0, &_);
return JSTRAP_CONTINUE;
}

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

@ -40,7 +40,7 @@ BEGIN_TEST(testRedefineGlobalEval)
CHECK(JS_GetProperty(cx, g, "Object", &v));
static const char data[] = "Object.defineProperty(this, 'eval', { configurable: false });";
CHECK(JS_EvaluateScript(cx, g, data, mozilla::ArrayLength(data) - 1, __FILE__, __LINE__, v.address()));
CHECK(JS_EvaluateScript(cx, g, data, mozilla::ArrayLength(data) - 1, __FILE__, __LINE__, &v));
return true;
}

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

@ -29,8 +29,7 @@ BEGIN_TEST(testGCOutOfMemory)
" array.push({});"
" array = []; array.push(0);"
"})();";
bool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1,
root.address());
bool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1, &root);
/* Check that we get OOM. */
CHECK(!ok);

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

@ -14,8 +14,7 @@ BEGIN_TEST(testJSEvaluateScript)
static const char src[] = "var x = 5;";
JS::RootedValue retval(cx);
CHECK(JS_EvaluateScript(cx, obj, src, sizeof(src) - 1, __FILE__, __LINE__,
retval.address()));
CHECK(JS_EvaluateScript(cx, obj, src, sizeof(src) - 1, __FILE__, __LINE__, &retval));
bool hasProp = true;
CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));
@ -30,8 +29,7 @@ BEGIN_TEST(testJSEvaluateScript)
static const char src2[] = "var y = 5;";
CHECK(JS_EvaluateScript(cx, obj, src2, sizeof(src2) - 1, __FILE__, __LINE__,
retval.address()));
CHECK(JS_EvaluateScript(cx, obj, src2, sizeof(src2) - 1, __FILE__, __LINE__, &retval));
hasProp = false;
CHECK(JS_AlreadyHasOwnProperty(cx, obj, "y", &hasProp));

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

@ -69,7 +69,7 @@ eval(const char *asciiChars, JSPrincipals *principals, JSPrincipals *originPrinc
options.setOriginPrincipals(originPrincipals)
.setFileAndLine("", 0);
bool ok = JS::Evaluate(cx, global, options, chars, len, rval.address());
bool ok = JS::Evaluate(cx, global, options, chars, len, rval);
delete[] chars;
return ok;

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

@ -27,7 +27,7 @@ struct ScriptObjectFixture : public JSAPITest {
/* After a garbage collection, the script should still work. */
JS::RootedValue result(cx);
CHECK(JS_ExecuteScript(cx, global, script, result.address()));
CHECK(JS_ExecuteScript(cx, global, script, &result));
return true;
}

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

@ -16,7 +16,7 @@ BEGIN_TEST(testBug795104)
s[0] = '"';
memset(s + 1, 'x', strLen - 2);
s[strLen - 1] = '"';
CHECK(JS::Evaluate(cx, global, opts, s, strLen, nullptr));
CHECK(JS::Evaluate(cx, global, opts, s, strLen));
CHECK(JS::CompileFunction(cx, global, opts, "f", 0, nullptr, s, strLen));
JS_free(cx, s);
@ -31,7 +31,7 @@ BEGIN_TEST(testScriptSourceReentrant)
JS::CompileOptions opts(cx);
bool match = false;
JS_SetNewScriptHook(rt, NewScriptHook, &match);
CHECK(JS::Evaluate(cx, global, opts, simpleSource, strlen(simpleSource), nullptr));
CHECK(JS::Evaluate(cx, global, opts, simpleSource, strlen(simpleSource)));
CHECK(match);
JS_SetNewScriptHook(rt, nullptr, nullptr);

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

@ -42,7 +42,7 @@ BEGIN_TEST(testTrap_gc)
// execute
JS::RootedValue v2(cx);
CHECK(JS_ExecuteScript(cx, global, script, v2.address()));
CHECK(JS_ExecuteScript(cx, global, script, &v2));
CHECK(v2.isObject());
CHECK_EQUAL(emptyTrapCallCount, 0);
@ -73,7 +73,7 @@ BEGIN_TEST(testTrap_gc)
}
// execute
CHECK(JS_ExecuteScript(cx, global, script, v2.address()));
CHECK(JS_ExecuteScript(cx, global, script, &v2));
CHECK_EQUAL(emptyTrapCallCount, 11);
JS_GC(rt);

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

@ -136,7 +136,7 @@ JSScript *createScriptViaXDR(JSPrincipals *orig, int testCase)
}
JS::RootedValue v(cx);
bool ok = JS_ExecuteScript(cx, global, script, v.address());
bool ok = JS_ExecuteScript(cx, global, script, &v);
if (!ok || !v.isObject())
return nullptr;
JS::RootedObject funobj(cx, &v.toObject());
@ -172,7 +172,7 @@ BEGIN_TEST(testXDR_bug506491)
// execute
JS::RootedValue v2(cx);
CHECK(JS_ExecuteScript(cx, global, script, v2.address()));
CHECK(JS_ExecuteScript(cx, global, script, &v2));
// try to break the Block object that is the parent of f
JS_GC(rt);
@ -197,7 +197,7 @@ BEGIN_TEST(testXDR_bug516827)
CHECK(script);
// execute with null result meaning no result wanted
CHECK(JS_ExecuteScript(cx, global, script, nullptr));
CHECK(JS_ExecuteScript(cx, global, script));
return true;
}
END_TEST(testXDR_bug516827)

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

@ -32,7 +32,7 @@ bool JSAPITest::exec(const char *bytes, const char *filename, int lineno)
{
JS::RootedValue v(cx);
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(&this->global);
return JS_EvaluateScript(cx, global, bytes, strlen(bytes), filename, lineno, v.address()) ||
return JS_EvaluateScript(cx, global, bytes, strlen(bytes), filename, lineno, &v) ||
fail(bytes, filename, lineno);
}
@ -40,7 +40,7 @@ bool JSAPITest::evaluate(const char *bytes, const char *filename, int lineno,
JS::MutableHandleValue vp)
{
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(&this->global);
return JS_EvaluateScript(cx, global, bytes, strlen(bytes), filename, lineno, vp.address()) ||
return JS_EvaluateScript(cx, global, bytes, strlen(bytes), filename, lineno, vp) ||
fail(bytes, filename, lineno);
}

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

@ -4712,8 +4712,8 @@ JS_DecompileFunctionBody(JSContext *cx, HandleFunction fun, unsigned indent)
return FunctionToString(cx, fun, true, !(indent & JS_DONT_PRETTY_PRINT));
}
MOZ_NEVER_INLINE JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext *cx, HandleObject obj, HandleScript scriptArg, jsval *rval)
MOZ_NEVER_INLINE static bool
ExecuteScript(JSContext *cx, HandleObject obj, HandleScript scriptArg, jsval *rval)
{
RootedScript script(cx, scriptArg);
@ -4744,18 +4744,36 @@ JS_ExecuteScript(JSContext *cx, HandleObject obj, HandleScript scriptArg, jsval
return Execute(cx, script, *obj, rval);
}
JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, HandleObject obj, HandleScript script, jsval *rval,
JSVersion version)
MOZ_NEVER_INLINE JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext *cx, HandleObject obj, HandleScript scriptArg, MutableHandleValue rval)
{
return JS_ExecuteScript(cx, obj, script, rval);
return ExecuteScript(cx, obj, scriptArg, rval.address());
}
MOZ_NEVER_INLINE JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext *cx, HandleObject obj, HandleScript scriptArg)
{
return ExecuteScript(cx, obj, scriptArg, nullptr);
}
JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, HandleObject obj, HandleScript script,
MutableHandleValue rval, JSVersion version)
{
return ExecuteScript(cx, obj, script, rval.address());
}
JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, HandleObject obj, HandleScript script, JSVersion version)
{
return ExecuteScript(cx, obj, script, nullptr);
}
static const unsigned LARGE_SCRIPT_LENGTH = 500*1024;
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const jschar *chars, size_t length, jsval *rval)
static bool
Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const jschar *chars, size_t length, JS::Value *rval)
{
CompileOptions options(cx, optionsArg);
JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
@ -4788,32 +4806,32 @@ JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &opti
if (script->length() > LARGE_SCRIPT_LENGTH) {
script = nullptr;
PrepareZoneForGC(cx->zone());
GC(cx->runtime(), GC_NORMAL, gcreason::FINISH_LARGE_EVALUTE);
GC(cx->runtime(), GC_NORMAL, JS::gcreason::FINISH_LARGE_EVALUTE);
}
return result;
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, jsval *rval)
static bool
Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, JS::Value *rval)
{
jschar *chars;
if (options.utf8)
chars = UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(bytes, length), &length).get();
chars = UTF8CharsToNewTwoByteCharsZ(cx, JS::UTF8Chars(bytes, length), &length).get();
else
chars = InflateString(cx, bytes, &length);
if (!chars)
return false;
bool ok = Evaluate(cx, obj, options, chars, length, rval);
bool ok = ::Evaluate(cx, obj, options, chars, length, rval);
js_free(chars);
return ok;
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char *filename, jsval *rval)
static bool
Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const char *filename, JS::Value *rval)
{
FileContents buffer(cx);
{
@ -4827,6 +4845,48 @@ JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &opti
return Evaluate(cx, obj, options, buffer.begin(), buffer.length(), rval);
}
extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg,
const jschar *chars, size_t length, MutableHandleValue rval)
{
return ::Evaluate(cx, obj, optionsArg, chars, length, rval.address());
}
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::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,
const jschar *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);
}
JS_PUBLIC_API(bool)
JS_EvaluateUCScript(JSContext *cx, HandleObject obj, const jschar *chars, unsigned length,
const char *filename, unsigned lineno, MutableHandleValue rval)
@ -4834,17 +4894,27 @@ JS_EvaluateUCScript(JSContext *cx, HandleObject obj, const jschar *chars, unsign
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return Evaluate(cx, obj, options, chars, length, rval.address());
return ::Evaluate(cx, obj, options, chars, length, rval.address());
}
JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, HandleObject obj, const char *bytes, unsigned nbytes,
const char *filename, unsigned lineno, jsval *rval)
const char *filename, unsigned lineno, MutableHandleValue rval)
{
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return Evaluate(cx, obj, options, bytes, nbytes, rval);
return ::Evaluate(cx, obj, options, bytes, nbytes, rval.address());
}
JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, HandleObject obj, const char *bytes, unsigned nbytes,
const char *filename, unsigned lineno)
{
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return ::Evaluate(cx, obj, options, bytes, nbytes, nullptr);
}
JS_PUBLIC_API(bool)

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

@ -3702,17 +3702,29 @@ JS_DecompileFunctionBody(JSContext *cx, JS::Handle<JSFunction*> fun, unsigned in
* etc., entry points.
*/
extern JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, jsval *rval);
JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval);
extern JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, jsval *rval,
JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script);
extern JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script,
JS::MutableHandleValue rval, JSVersion version);
extern JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script,
JSVersion version);
extern JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, JS::HandleObject obj,
const char *bytes, unsigned length,
const char *filename, unsigned lineno,
jsval *rval);
JS::MutableHandleValue rval);
extern JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, JS::HandleObject obj,
const char *bytes, unsigned length,
const char *filename, unsigned lineno);
extern JS_PUBLIC_API(bool)
JS_EvaluateUCScript(JSContext *cx, JS::Handle<JSObject*> obj,
@ -3724,15 +3736,27 @@ namespace JS {
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const jschar *chars, size_t length, jsval *rval);
const jschar *chars, size_t length, JS::MutableHandleValue rval);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, jsval *rval);
const char *bytes, size_t length, JS::MutableHandleValue rval);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char *filename, jsval *rval);
const char *filename, JS::MutableHandleValue rval);
extern JS_PUBLIC_API(bool)
Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const jschar *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 */

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

@ -453,7 +453,7 @@ RunFile(JSContext *cx, Handle<JSObject*> obj, const char *filename, FILE *file,
AnalyzeEntrainedVariables(cx, script);
#endif
if (script && !compileOnly) {
if (!JS_ExecuteScript(cx, obj, script, nullptr)) {
if (!JS_ExecuteScript(cx, obj, script)) {
if (!gQuitting && !gTimedOut)
gExitCode = EXITCODE_RUNTIME_ERROR;
}
@ -480,7 +480,7 @@ EvalAndPrint(JSContext *cx, Handle<JSObject*> global, const char *bytes, size_t
if (compileOnly)
return true;
RootedValue result(cx);
if (!JS_ExecuteScript(cx, global, script, result.address()))
if (!JS_ExecuteScript(cx, global, script, &result))
return false;
if (!result.isUndefined()) {
@ -790,7 +790,7 @@ LoadScript(JSContext *cx, unsigned argc, jsval *vp, bool scriptRelative)
.setCompileAndGo(true)
.setNoScriptRval(true);
if ((compileOnly && !Compile(cx, thisobj, opts, filename.ptr())) ||
!Evaluate(cx, thisobj, opts, filename.ptr(), nullptr))
!Evaluate(cx, thisobj, opts, filename.ptr()))
{
return false;
}
@ -1242,7 +1242,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
if (!script->scriptSource()->setSourceMapURL(cx, smurl))
return false;
}
if (!JS_ExecuteScript(cx, global, script, vp)) {
if (!JS_ExecuteScript(cx, global, script, args.rval())) {
if (catchTermination && !JS_IsExceptionPending(cx)) {
JSAutoCompartment ac1(cx, callerGlobal);
JSString *str = JS_NewStringCopyZ(cx, "terminated");
@ -1414,7 +1414,7 @@ Run(JSContext *cx, unsigned argc, jsval *vp)
return false;
}
if (!JS_ExecuteScript(cx, thisobj, script, nullptr))
if (!JS_ExecuteScript(cx, thisobj, script))
return false;
int64_t endClock = PRMJ_Now();
@ -2881,7 +2881,7 @@ WorkerMain(void *arg)
if (!script)
break;
RootedValue result(cx);
JS_ExecuteScript(cx, global, script, result.address());
JS_ExecuteScript(cx, global, script, &result);
} while (0);
DestroyContext(cx, false);
@ -3695,7 +3695,7 @@ runOffThreadScript(JSContext *cx, unsigned argc, jsval *vp)
if (!script)
return false;
return JS_ExecuteScript(cx, cx->global(), script, args.rval().address());
return JS_ExecuteScript(cx, cx->global(), script, args.rval());
}
#endif // JS_THREADSAFE
@ -5722,7 +5722,7 @@ ProcessArgs(JSContext *cx, JSObject *obj_, OptionParser *op)
} else {
const char *code = codeChunks.front();
RootedValue rval(cx);
if (!JS_EvaluateScript(cx, obj, code, strlen(code), "-e", 1, rval.address()))
if (!JS_EvaluateScript(cx, obj, code, strlen(code), "-e", 1, &rval))
return gExitCode ? gExitCode : EXITCODE_RUNTIME_ERROR;
codeChunks.popFront();
}

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

@ -943,7 +943,7 @@ JSRuntime::initSelfHosting(JSContext *cx)
const char *src = rawSources;
#endif
ok = Evaluate(cx, shg, options, src, srcLen, rv.address());
ok = Evaluate(cx, shg, options, src, srcLen, &rv);
}
JS_SetErrorReporter(cx, oldReporter);
if (receivesDefaultObject)

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

@ -1023,7 +1023,7 @@ mozJSComponentLoader::ObjectForLocation(nsIFile *aComponentFile,
if (aPropagateExceptions)
ContextOptionsRef(cx).setDontReportUncaught(true);
if (script) {
ok = JS_ExecuteScriptVersion(cx, obj, script, nullptr, JSVERSION_LATEST);
ok = JS_ExecuteScriptVersion(cx, obj, script, JSVERSION_LATEST);
} else {
RootedValue rval(cx);
ok = JS_CallFunction(cx, obj, function, JS::HandleValueArray::empty(), &rval);

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

@ -350,7 +350,7 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString &url,
ok = JS_CallFunction(cx, targetObj, function, JS::HandleValueArray::empty(),
retval);
} else {
ok = JS_ExecuteScriptVersion(cx, targetObj, script, retval.address(), version);
ok = JS_ExecuteScriptVersion(cx, targetObj, script, retval, version);
}
if (ok) {

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

@ -536,7 +536,7 @@ EvalInWindow(JSContext *cx, const nsAString &source, HandleObject scope, Mutable
targetScope,
compileOptions,
evaluateOptions,
rval.address());
rval);
if (NS_FAILED(rv)) {
// If there was an exception we get it as a return value, if
@ -1721,8 +1721,7 @@ xpc::EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& sour
options.setVersion(jsVersion);
JS::RootedObject rootedSandbox(sandcx, sandbox);
ok = JS::Evaluate(sandcx, rootedSandbox, options,
PromiseFlatString(source).get(), source.Length(),
v.address());
PromiseFlatString(source).get(), source.Length(), &v);
if (ok && returnStringOnly && !v.isUndefined()) {
JSString *str = ToString(sandcx, v);
ok = !!str;

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

@ -344,8 +344,7 @@ Load(JSContext *cx, unsigned argc, jsval *vp)
if (!script)
return false;
JS::Rooted<JS::Value> result(cx);
if (!compileOnly && !JS_ExecuteScript(cx, obj, script, result.address()))
if (!compileOnly && !JS_ExecuteScript(cx, obj, script))
return false;
}
args.rval().setUndefined();
@ -928,7 +927,7 @@ ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj, const char *filename, FILE
.setFileAndLine(filename, 1);
script = JS::Compile(cx, obj, options, file);
if (script && !compileOnly)
(void)JS_ExecuteScript(cx, obj, script, result.address());
(void)JS_ExecuteScript(cx, obj, script, &result);
DoEndRequest(cx);
return;
@ -967,7 +966,7 @@ ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj, const char *filename, FILE
JSErrorReporter older;
if (!compileOnly) {
ok = JS_ExecuteScript(cx, obj, script, result.address());
ok = JS_ExecuteScript(cx, obj, script, &result);
if (ok && result != JSVAL_VOID) {
/* Suppress error reports from JS::ToString(). */
older = JS_SetErrorReporter(cx, nullptr);
@ -1154,8 +1153,7 @@ ProcessArgs(JSContext *cx, JS::Handle<JSObject*> obj, char **argv, int argc, XPC
return usage();
}
JS_EvaluateScript(cx, obj, argv[i], strlen(argv[i]), "-e", 1,
rval.address());
JS_EvaluateScript(cx, obj, argv[i], strlen(argv[i]), "-e", 1, &rval);
isInteractive = false;
break;

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

@ -634,7 +634,7 @@ ProxyAutoConfig::SetupJS()
options.setFileAndLine(mPACURI.get(), 1);
JS::Rooted<JSScript*> script(cx, JS_CompileScript(cx, global, mPACScript.get(),
mPACScript.Length(), options));
if (!script || !JS_ExecuteScript(cx, global, script, nullptr)) {
if (!script || !JS_ExecuteScript(cx, global, script)) {
nsString alertMessage(NS_LITERAL_STRING("PAC file failed to install from "));
if (isDataURI) {
alertMessage += NS_LITERAL_STRING("data: URI");

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

@ -2200,7 +2200,7 @@ nsCryptoRunnable::Run()
bool ok =
JS_EvaluateScript(cx, scope, m_args->m_jsCallback,
strlen(m_args->m_jsCallback), nullptr, 0, nullptr);
strlen(m_args->m_jsCallback), nullptr, 0);
return ok ? NS_OK : NS_ERROR_FAILURE;
}