Bug 1100579 part 2. Kill off JS_Evaluate(UC)Script. r=waldo

This commit is contained in:
Boris Zbarsky 2014-11-18 23:27:16 -05:00
Родитель 67d7197390
Коммит dcb78a0257
10 изменённых файлов: 38 добавлений и 83 удалений

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

@ -72,7 +72,7 @@ tests.h:
EXEC(const char *code);
Execute some JS code in global scope, using JS_EvaluateScript. Return
Execute some JS code in global scope, using JS::Evaluate. Return
false if that fails. (This means that if the code throws an uncaught JS
exception, the test fails.)

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

@ -93,7 +93,9 @@ CreateDataView(JSContext *cx)
static const char code[] = "new DataView(new ArrayBuffer(8))";
JS::Rooted<JS::Value> val(cx);
if (!JS_EvaluateScript(cx, global, code, strlen(code), __FILE__, __LINE__, &val))
JS::CompileOptions opts(cx);
if (!JS::Evaluate(cx, global, opts.setFileAndLine(__FILE__, __LINE__),
code, strlen(code), &val))
return nullptr;
JS::Rooted<JSObject*> dv(cx, &val.toObject());

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

@ -41,7 +41,9 @@ 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));
JS::CompileOptions opts(cx);
CHECK(JS::Evaluate(cx, g, opts.setFileAndLine(__FILE__, __LINE__),
data, mozilla::ArrayLength(data) - 1, &v));
return true;
}

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

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

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

@ -14,7 +14,9 @@ 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));
JS::CompileOptions opts(cx);
CHECK(JS::Evaluate(cx, obj, opts.setFileAndLine(__FILE__, __LINE__),
src, sizeof(src) - 1, &retval));
bool hasProp = true;
CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));
@ -29,7 +31,8 @@ BEGIN_TEST(testJSEvaluateScript)
static const char src2[] = "var y = 5;";
CHECK(JS_EvaluateScript(cx, obj, src2, sizeof(src2) - 1, __FILE__, __LINE__, &retval));
CHECK(JS::Evaluate(cx, obj, opts.setFileAndLine(__FILE__, __LINE__),
src2, sizeof(src2) - 1, &retval));
hasProp = false;
CHECK(JS_AlreadyHasOwnProperty(cx, obj, "y", &hasProp));

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

@ -54,7 +54,9 @@ bool JSAPITest::exec(const char *bytes, const char *filename, int lineno)
{
JS::RootedValue v(cx);
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(this->global.unsafeGet());
return JS_EvaluateScript(cx, global, bytes, strlen(bytes), filename, lineno, &v) ||
JS::CompileOptions opts(cx);
opts.setFileAndLine(filename, lineno);
return JS::Evaluate(cx, global, opts, bytes, strlen(bytes), &v) ||
fail(JSAPITestString(bytes), filename, lineno);
}
@ -62,7 +64,9 @@ bool JSAPITest::evaluate(const char *bytes, const char *filename, int lineno,
JS::MutableHandleValue vp)
{
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(this->global.unsafeGet());
return JS_EvaluateScript(cx, global, bytes, strlen(bytes), filename, lineno, vp) ||
JS::CompileOptions opts(cx);
opts.setFileAndLine(filename, lineno);
return JS::Evaluate(cx, global, opts, bytes, strlen(bytes), vp) ||
fail(JSAPITestString(bytes), filename, lineno);
}

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

@ -4883,48 +4883,6 @@ JS::Evaluate(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &opti
return ::Evaluate(cx, obj, optionsArg, filename, rval);
}
JS_PUBLIC_API(bool)
JS_EvaluateUCScript(JSContext *cx, HandleObject obj, const char16_t *chars, unsigned length,
const char *filename, unsigned lineno, MutableHandleValue rval)
{
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return ::Evaluate(cx, obj, options, chars, length, rval);
}
JS_PUBLIC_API(bool)
JS_EvaluateUCScript(JSContext *cx, HandleObject obj, SourceBufferHolder &srcBuf,
const char *filename, unsigned lineno, MutableHandleValue rval)
{
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return ::Evaluate(cx, obj, options, srcBuf, rval);
}
JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, HandleObject obj, const char *bytes, unsigned nbytes,
const char *filename, unsigned lineno, MutableHandleValue rval)
{
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return JS::Evaluate(cx, obj, options, bytes, nbytes, rval);
}
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)
.setNoScriptRval(true);
RootedValue unused(cx);
return JS::Evaluate(cx, obj, options, bytes, nbytes, &unused);
}
JS_PUBLIC_API(bool)
JS_CallFunction(JSContext *cx, HandleObject obj, HandleFunction fun, const HandleValueArray& args,
MutableHandleValue rval)

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

@ -4006,7 +4006,7 @@ extern JS_PUBLIC_API(JSString *)
JS_DecompileFunctionBody(JSContext *cx, JS::Handle<JSFunction*> fun, unsigned indent);
/*
* NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj
* NB: JS_ExecuteScript and the JS::Evaluate APIs use the obj
* parameter as the initial scope chain header, the 'this' keyword value, and
* the variables object (ECMA parlance for where 'var' and 'function' bind
* names) of the execution context for script.
@ -4026,17 +4026,16 @@ JS_DecompileFunctionBody(JSContext *cx, JS::Handle<JSFunction*> fun, unsigned in
* non-ECMA explicit vs. implicit variable creation.
*
* Caveat embedders: unless you already depend on this buggy variables object
* binding behavior, you should call ContextOptionsRef(cx).setVarObjFix(true)
* binding behavior, you should call RuntimeOptionsRef(rt).setVarObjFix(true)
* for each context in the application, if you pass parented objects as the obj
* parameter, or may ever pass such objects in the future.
*
* Why a runtime option? The alternative is to add six or so new API entry
* points with signatures matching the following six, and that doesn't seem
* worth the code bloat cost. Such new entry points would probably have less
* obvious names, too, so would not tend to be used. The JS_SetOption call,
* OTOH, can be more easily hacked into existing code that does not depend on
* the bug; such code can continue to use the familiar JS_EvaluateScript,
* etc., entry points.
* Why a runtime option? The alternative is to add APIs duplicating those below
* for the other value of varobjfix, and that doesn't seem worth the code bloat
* cost. Such new entry points would probably have less obvious names, too, so
* would not tend to be used. The RuntimeOptionsRef adjustment, OTOH, can be
* more easily hacked into existing code that does not depend on the bug; such
* code can continue to use the familiar JS::Evaluate, etc., entry points.
*/
extern JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval);
@ -4067,23 +4066,6 @@ CloneAndExecuteScript(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<JSScr
} /* namespace JS */
extern JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, JS::HandleObject obj,
const char *bytes, unsigned length,
const char *filename, unsigned lineno,
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,
const char16_t *chars, unsigned length,
const char *filename, unsigned lineno,
JS::MutableHandle<JS::Value> rval);
namespace JS {
extern JS_PUBLIC_API(bool)
@ -4959,7 +4941,7 @@ namespace JS {
*
* Typical usage:
*
* bool ok = JS_EvaluateScript(cx, ...);
* bool ok = JS::Evaluate(cx, ...);
* AutoSaveExceptionState savedExc(cx);
* ... cleanup that might re-enter JS ...
* return ok;

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

@ -2625,10 +2625,9 @@ EvalInContext(JSContext *cx, unsigned argc, jsval *vp)
JS_ReportError(cx, "Invalid scope argument to evalcx");
return false;
}
if (!JS_EvaluateUCScript(cx, sobj, src, srclen,
filename.get(),
lineno,
args.rval())) {
JS::CompileOptions opts(cx);
opts.setFileAndLine(filename.get(), lineno);
if (!JS::Evaluate(cx, sobj, opts, src, srclen, args.rval())) {
return false;
}
}
@ -5404,7 +5403,9 @@ 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))
JS::CompileOptions opts(cx);
opts.setFileAndLine("-e", 1);
if (!JS::Evaluate(cx, obj, opts, code, strlen(code), &rval))
return gExitCode ? gExitCode : EXITCODE_RUNTIME_ERROR;
codeChunks.popFront();
}

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

@ -1066,7 +1066,9 @@ 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);
JS::CompileOptions opts(cx);
opts.setFileAndLine("-e", 1);
JS::Evaluate(cx, obj, opts, argv[i], strlen(argv[i]), &rval);
isInteractive = false;
break;