Bug 1390106 - Stop using versioned scripts in tests. r?jmaher
MozReview-Commit-ID: ErqU4M1f7Oj
--- a/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
+++ b/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
@@ -84,17 +84,17 @@ struct DevTools : public ::testing::Test
return &globalClass;
}
JSObject* createGlobal()
{
/* Create the global object. */
JS::RootedObject newGlobal(cx);
JS::CompartmentOptions options;
- options.behaviors().setVersion(JSVERSION_LATEST);
+ options.behaviors().setVersion(JSVERSION_DEFAULT);
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
JS::FireOnNewGlobalHook, options);
if (!newGlobal)
return nullptr;
JSAutoCompartment ac(cx, newGlobal);
/* Populate the global object with the standard globals, like Object and
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -446,17 +446,17 @@ XPCShellEnvironment::Init()
rv = NS_NewBackstagePass(getter_AddRefs(backstagePass));
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create backstage pass!");
return false;
}
JS::CompartmentOptions options;
options.creationOptions().setSystemZone();
- options.behaviors().setVersion(JSVERSION_LATEST);
+ options.behaviors().setVersion(JSVERSION_DEFAULT);
if (xpc::SharedMemoryEnabled())
options.creationOptions().setSharedMemoryAndAtomicsEnabled(true);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->InitClassesWithNewWrappedGlobal(cx,
static_cast<nsIGlobalObject *>(backstagePass),
principal, 0,
options,
--- a/testing/xpcshell/selftest.py
+++ b/testing/xpcshell/selftest.py
@@ -154,52 +154,52 @@ add_test(function test_unicode_print ()
});
'''
ADD_TASK_SINGLE = '''
Components.utils.import("resource://gre/modules/Promise.jsm");
function run_test() { run_next_test(); }
-add_task(function test_task() {
+add_task(function* test_task() {
yield Promise.resolve(true);
yield Promise.resolve(false);
});
'''
ADD_TASK_MULTIPLE = '''
Components.utils.import("resource://gre/modules/Promise.jsm");
function run_test() { run_next_test(); }
-add_task(function test_task() {
+add_task(function* test_task() {
yield Promise.resolve(true);
});
-add_task(function test_2() {
+add_task(function* test_2() {
yield Promise.resolve(true);
});
'''
ADD_TASK_REJECTED = '''
Components.utils.import("resource://gre/modules/Promise.jsm");
function run_test() { run_next_test(); }
-add_task(function test_failing() {
+add_task(function* test_failing() {
yield Promise.reject(new Error("I fail."));
});
'''
ADD_TASK_FAILURE_INSIDE = '''
Components.utils.import("resource://gre/modules/Promise.jsm");
function run_test() { run_next_test(); }
-add_task(function test() {
+add_task(function* test() {
let result = yield Promise.resolve(false);
do_check_true(result);
});
'''
ADD_TASK_RUN_NEXT_TEST = '''
function run_test() { run_next_test(); }
@@ -219,29 +219,16 @@ function run_test() { run_next_test(); }
add_task(function* this_test_will_fail() {
for (let i = 0; i < 10; ++i) {
yield Promise.resolve();
}
Assert.ok(false);
});
'''
-ADD_TASK_STACK_TRACE_WITHOUT_STAR = '''
-Components.utils.import("resource://gre/modules/Promise.jsm", this);
-
-function run_test() { run_next_test(); }
-
-add_task(function this_test_will_fail() {
- for (let i = 0; i < 10; ++i) {
- yield Promise.resolve();
- }
- Assert.ok(false);
-});
-'''
-
ADD_TASK_SKIP = '''
add_task(async function skipMeNot1() {
Assert.ok(true, "Well well well.");
});
add_task(async function skipMe1() {
Assert.ok(false, "Not skipped after all.");
}).skip();
@@ -325,18 +312,17 @@ function run_test() {
# A test for failure to load a test due to a syntax error
LOAD_ERROR_SYNTAX_ERROR = '''
function run_test(
'''
# A test for failure to load a test due to an error other than a syntax error
LOAD_ERROR_OTHER_ERROR = '''
function run_test() {
- yield "foo";
- return "foo"; // can't use return in a generator!
+ 1 = "foo"; // invalid assignment left-hand side
};
'''
# A test for asynchronous cleanup functions
ASYNC_CLEANUP = '''
function run_test() {
Components.utils.import("resource://gre/modules/Promise.jsm", this);
@@ -431,21 +417,21 @@ NO_RUN_TEST_ADD_TASK_FAIL = '''
add_task(function no_run_test_add_task_fail() {
do_check_true(false);
});
'''
NO_RUN_TEST_ADD_TASK_MULTIPLE = '''
Components.utils.import("resource://gre/modules/Promise.jsm");
-add_task(function test_task() {
+add_task(function* test_task() {
yield Promise.resolve(true);
});
-add_task(function test_2() {
+add_task(function* test_2() {
yield Promise.resolve(true);
});
'''
LOAD_MOZINFO = '''
function run_test() {
do_check_neq(typeof mozinfo, undefined);
do_check_neq(typeof mozinfo.os, undefined);
@@ -1061,32 +1047,16 @@ add_test({
self.writeManifest(["test_add_task_stack_trace.js"])
self.assertTestResult(False)
self.assertInLog("this_test_will_fail")
self.assertInLog("run_next_test")
self.assertInLog("run_test")
self.assertNotInLog("Task.jsm")
- def testAddTaskStackTraceWithoutStar(self):
- """
- Ensuring that calling Assert.ok(false) from inside add_task()
- results in a human-readable stack trace. This variant uses deprecated
- `function()` syntax instead of now standard `function*()`.
- """
- self.writeFile("test_add_task_stack_trace_without_star.js",
- ADD_TASK_STACK_TRACE)
- self.writeManifest(["test_add_task_stack_trace_without_star.js"])
-
- self.assertTestResult(False)
- self.assertInLog("this_test_will_fail")
- self.assertInLog("run_next_test")
- self.assertInLog("run_test")
- self.assertNotInLog("Task.jsm")
-
def testAddTaskSkip(self):
self.writeFile("test_tasks_skip.js", ADD_TASK_SKIP)
self.writeManifest(["test_tasks_skip.js"])
self.assertTestResult(True)
self.assertEquals(1, self.x.testCount)
self.assertEquals(1, self.x.passCount)
self.assertEquals(0, self.x.failCount)
@@ -1211,18 +1181,18 @@ add_test({
Check that attempting to load a test file containing an error other
than a syntax error generates details of the error in the log
"""
self.writeFile("test_error.js", LOAD_ERROR_OTHER_ERROR)
self.writeManifest(["test_error.js"])
self.assertTestResult(False)
self.assertInLog(TEST_FAIL_STRING)
- self.assertInLog("TypeError: generator function can't return a value at")
- self.assertInLog("test_error.js:4")
+ self.assertInLog("ReferenceError: invalid assignment left-hand side at")
+ self.assertInLog("test_error.js:3")
self.assertNotInLog(TEST_PASS_STRING)
def testDoPrintWhenVerboseNotExplicit(self):
"""
Check that do_print() and similar calls that generate output do
not have the output when not run verbosely.
"""
self.writeFile("test_verbose.js", ADD_TEST_VERBOSE)
--- a/toolkit/modules/tests/xpcshell/test_DeferredTask.js
+++ b/toolkit/modules/tests/xpcshell/test_DeferredTask.js
@@ -179,38 +179,35 @@ add_test(function test_arm_async() {
do_timeout(13 * T, function() {
do_check_false(deferredTask.isRunning);
do_check_true(finishedExecutionAgain);
run_next_test();
});
});
/**
- * Checks that "arm" accepts a Task.jsm generator function.
+ * Checks that "arm" accepts a Task.jsm async function.
*/
-add_test(function test_arm_async_generator() {
+add_test(function test_arm_async_function() {
let deferredTask = new DeferredTask(async function() {
await Promise.resolve();
run_next_test();
}, 50);
deferredTask.arm();
});
/**
- * Checks that "arm" accepts a Task.jsm legacy generator function.
+ * Checks that "arm" accepts a Task.jsm generator function.
*/
-add_test(function test_arm_async_legacy_generator() {
- // ESLint cannot parse legacy generator functions, so we need an eval block.
- /* eslint-disable no-eval */
- let deferredTask = new DeferredTask(eval(`(function() {
+add_test(function test_arm_async_generator() {
+ let deferredTask = new DeferredTask(function*() {
yield Promise.resolve();
run_next_test();
- })`), 50);
- /* eslint-enable no-eval */
+ }, 50);
deferredTask.arm();
});
/**
* Checks that an armed task can be disarmed.
*/
add_test(function test_disarm() {
--- a/toolkit/modules/tests/xpcshell/test_task.js
+++ b/toolkit/modules/tests/xpcshell/test_task.js
@@ -33,66 +33,16 @@ function promiseResolvedLater(aValue) {
////////////////////////////////////////////////////////////////////////////////
/// Tests
function run_test()
{
run_next_test();
}
-add_test(function test_normal()
-{
- Task.spawn(function () {
- let result = yield Promise.resolve("Value");
- for (let i = 0; i < 3; i++) {
- result += yield promiseResolvedLater("!");
- }
- throw new Task.Result("Task result: " + result);
- }).then(function (result) {
- do_check_eq("Task result: Value!!!", result);
- run_next_test();
- }, function (ex) {
- do_throw("Unexpected error: " + ex);
- });
-});
-
-add_test(function test_exceptions()
-{
- Task.spawn(function () {
- try {
- yield Promise.reject("Rejection result by promise.");
- do_throw("Exception expected because the promise was rejected.");
- } catch (ex) {
- // We catch this exception now, we will throw a different one later.
- do_check_eq("Rejection result by promise.", ex);
- }
- throw new Error("Exception uncaught by task.");
- }).then(function (result) {
- do_throw("Unexpected success!");
- }, function (ex) {
- do_check_eq("Exception uncaught by task.", ex.message);
- run_next_test();
- });
-});
-
-add_test(function test_recursion()
-{
- function task_fibonacci(n) {
- throw new Task.Result(n < 2 ? n : (yield task_fibonacci(n - 1)) +
- (yield task_fibonacci(n - 2)));
- };
-
- Task.spawn(task_fibonacci(6)).then(function (result) {
- do_check_eq(8, result);
- run_next_test();
- }, function (ex) {
- do_throw("Unexpected error: " + ex);
- });
-});
-
add_test(function test_spawn_primitive()
{
function fibonacci(n) {
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
};
// Polymorphism between task and non-task functions (see "test_recursion").
Task.spawn(fibonacci(6)).then(function (result) {
@@ -178,31 +128,31 @@ add_test(function test_spawn_function_ta
run_next_test();
}, function (ex) {
do_throw("Unexpected error: " + ex);
});
});
add_test(function test_yielded_undefined()
{
- Task.spawn(function () {
+ Task.spawn(function* () {
yield;
- throw new Task.Result("We continued correctly.");
+ return "We continued correctly.";
}).then(function (result) {
do_check_eq("We continued correctly.", result);
run_next_test();
}, function (ex) {
do_throw("Unexpected error: " + ex);
});
});
add_test(function test_yielded_primitive()
{
- Task.spawn(function () {
- throw new Task.Result("Primitive " + (yield "value."));
+ Task.spawn(function* () {
+ return "Primitive " + (yield "value.");
}).then(function (result) {
do_check_eq("Primitive value.", result);
run_next_test();
}, function (ex) {
do_throw("Unexpected error: " + ex);
});
});
@@ -251,21 +201,21 @@ add_test(function test_star_recursion()
Task.spawn(task_fibonacci(6)).then(function (result) {
do_check_eq(8, result);
run_next_test();
}, function (ex) {
do_throw("Unexpected error: " + ex);
});
});
-add_test(function test_mixed_legacy_and_star()
+add_test(function test_nested_star()
{
Task.spawn(function* () {
- return yield (function() {
- throw new Task.Result(yield 5);
+ return yield (function* () {
+ return yield 5;
})();
}).then(function (result) {
do_check_eq(5, result);
run_next_test();
}, function (ex) {
do_throw("Unexpected error: " + ex);
});
});
--- a/xpcom/tests/gtest/TestGCPostBarriers.cpp
+++ b/xpcom/tests/gtest/TestGCPostBarriers.cpp
@@ -92,17 +92,17 @@ CreateGlobalAndRunTest(JSContext* cx)
};
static const JSClass GlobalClass = {
"global", JSCLASS_GLOBAL_FLAGS,
&GlobalClassOps
};
JS::CompartmentOptions options;
- options.behaviors().setVersion(JSVERSION_LATEST);
+ options.behaviors().setVersion(JSVERSION_DEFAULT);
JS::PersistentRootedObject global(cx);
global = JS_NewGlobalObject(cx, &GlobalClass, nullptr, JS::FireOnNewGlobalHook, options);
ASSERT_TRUE(global != nullptr);
JSCompartment *oldCompartment = JS_EnterCompartment(cx, global);
typedef Heap<JSObject*> ElementT;