forked from mirrors/gecko-dev
Bug 1532935 - Enable ESLint for dom/promise (manual changes). r=mccr8
Patch by Alec, updated by Standard8. Differential Revision: https://phabricator.services.mozilla.com/D29646 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
6614404241
commit
6a56241703
18 changed files with 77 additions and 42 deletions
|
|
@ -15,7 +15,6 @@ obj*/**
|
|||
dom/base/*.*
|
||||
dom/media/test/**
|
||||
!dom/media/test/marionette/yttest/*.js
|
||||
dom/promise/**
|
||||
dom/xhr/**
|
||||
|
||||
# build/ third-party code
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@
|
|||
* 4) A subframe (frames[0]) which can be used as a second global for creating
|
||||
* promises.
|
||||
*/
|
||||
|
||||
/* global verifyPromiseGlobal, getPromise, isXrayArgumentTest */
|
||||
|
||||
var label = "parent";
|
||||
|
||||
function passBasicPromise() {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
* 3) A subframe (frames[0]) which can be used as a second global for creating
|
||||
* promises.
|
||||
*/
|
||||
|
||||
/* global verifyPromiseGlobal, expectedExceptionGlobal */
|
||||
|
||||
var label = "parent";
|
||||
|
||||
function testThrownException(global) {
|
||||
|
|
|
|||
|
|
@ -2,16 +2,18 @@
|
|||
<html>
|
||||
<script>
|
||||
function vendGetter(name) {
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
return function() { throw "Getting " + String(name); };
|
||||
}
|
||||
function vendSetter(name) {
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
return function() { throw "Setting " + String(name); };
|
||||
}
|
||||
var setupThrew = false;
|
||||
try {
|
||||
// Neuter everything we can think of on Promise.
|
||||
for (var obj of [Promise, Promise.prototype]) {
|
||||
propNames = Object.getOwnPropertyNames(obj);
|
||||
let propNames = Object.getOwnPropertyNames(obj);
|
||||
propNames = propNames.concat(Object.getOwnPropertySymbols(obj));
|
||||
for (var propName of propNames) {
|
||||
if ((propName == "prototype" ||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
/* global TestFunctions */
|
||||
|
||||
postMessage("Done", "*");
|
||||
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ Debugger.prototype.onNewPromise.
|
|||
dbg.onNewPromise = function(wp) { wrappedPromise = wp; };
|
||||
|
||||
var promise = new Promise(function() {});
|
||||
// eslint-disable-next-line no-debugger
|
||||
debugger;
|
||||
ok(wrappedPromise);
|
||||
is(wrappedPromise.unsafeDereference(), promise);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ function promiseResolve() {
|
|||
ok(reject, "Promise.reject exists");
|
||||
|
||||
resolve(42);
|
||||
}).then(function(what) {
|
||||
});
|
||||
promise.then(function(what) {
|
||||
ok(true, "Then - resolveCb has been called");
|
||||
is(what, 42, "ResolveCb received 42");
|
||||
runTest();
|
||||
|
|
@ -40,7 +41,8 @@ function promiseResolveNoArg() {
|
|||
ok(reject, "Promise.reject exists");
|
||||
|
||||
resolve();
|
||||
}).then(function(what) {
|
||||
});
|
||||
promise.then(function(what) {
|
||||
ok(true, "Then - resolveCb has been called");
|
||||
is(what, undefined, "ResolveCb received undefined");
|
||||
runTest();
|
||||
|
|
@ -53,7 +55,8 @@ function promiseResolveNoArg() {
|
|||
function promiseReject() {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
reject(42);
|
||||
}).then(function(what) {
|
||||
});
|
||||
promise.then(function(what) {
|
||||
ok(false, "Then - resolveCb has been called");
|
||||
runTest();
|
||||
}, function(what) {
|
||||
|
|
@ -66,7 +69,9 @@ function promiseReject() {
|
|||
function promiseRejectNoHandler() {
|
||||
// This test only checks that the code that reports unhandled errors in the
|
||||
// Promises implementation does not crash or leak.
|
||||
var promise = new Promise(function(res, rej) {
|
||||
|
||||
new Promise(function(res, rej) {
|
||||
// eslint-disable-next-line no-undef
|
||||
noSuchMethod();
|
||||
});
|
||||
runTest();
|
||||
|
|
@ -75,7 +80,8 @@ function promiseRejectNoHandler() {
|
|||
function promiseRejectNoArg() {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
reject();
|
||||
}).then(function(what) {
|
||||
});
|
||||
promise.then(function(what) {
|
||||
ok(false, "Then - resolveCb has been called");
|
||||
runTest();
|
||||
}, function(what) {
|
||||
|
|
@ -87,8 +93,10 @@ function promiseRejectNoArg() {
|
|||
|
||||
function promiseException() {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
throw 42;
|
||||
}).then(function(what) {
|
||||
});
|
||||
promise.then(function(what) {
|
||||
ok(false, "Then - resolveCb has been called");
|
||||
runTest();
|
||||
}, function(what) {
|
||||
|
|
@ -102,7 +110,8 @@ function promiseGC() {
|
|||
var resolve;
|
||||
var promise = new Promise(function(r1, r2) {
|
||||
resolve = r1;
|
||||
}).then(function(what) {
|
||||
});
|
||||
promise.then(function(what) {
|
||||
ok(true, "Then - promise is still alive");
|
||||
runTest();
|
||||
});
|
||||
|
|
@ -219,6 +228,7 @@ function promiseThenException() {
|
|||
|
||||
promise.then(function(what) {
|
||||
ok(true, "Then.resolve has been called");
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
throw "booh";
|
||||
}).catch(function(e) {
|
||||
ok(true, "window.onerror has been called!");
|
||||
|
|
@ -361,6 +371,7 @@ function promiseRejectThenCatchExceptionThen() {
|
|||
}, function(what) {
|
||||
ok(true, "Then.reject has been called");
|
||||
is(what, 42, "Value == 42");
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
throw (what + 1);
|
||||
}).catch(function(what) {
|
||||
ok(true, "Catch has been called");
|
||||
|
|
@ -436,9 +447,9 @@ function promiseCatchNoArg() {
|
|||
|
||||
function promiseNestedPromise() {
|
||||
new Promise(function(resolve, reject) {
|
||||
resolve(new Promise(function(resolve, reject) {
|
||||
resolve(new Promise(function(res, rej) {
|
||||
ok(true, "Nested promise is executed");
|
||||
resolve(42);
|
||||
res(42);
|
||||
}));
|
||||
}).then(function(value) {
|
||||
is(value, 42, "Nested promise is executed and then == 42");
|
||||
|
|
@ -448,9 +459,9 @@ function promiseNestedPromise() {
|
|||
|
||||
function promiseNestedNestedPromise() {
|
||||
new Promise(function(resolve, reject) {
|
||||
resolve(new Promise(function(resolve, reject) {
|
||||
resolve(new Promise(function(res, rej) {
|
||||
ok(true, "Nested promise is executed");
|
||||
resolve(42);
|
||||
res(42);
|
||||
}).then(function(what) { return what + 1; }));
|
||||
}).then(function(value) {
|
||||
is(value, 43, "Nested promise is executed and then == 43");
|
||||
|
|
@ -475,11 +486,11 @@ function promiseWrongNestedPromise() {
|
|||
|
||||
function promiseLoop() {
|
||||
new Promise(function(resolve, reject) {
|
||||
resolve(new Promise(function(r1, r2) {
|
||||
resolve(new Promise(function(res, rej) {
|
||||
ok(true, "Nested promise is executed");
|
||||
r1(new Promise(function(r1, r2) {
|
||||
res(new Promise(function(resInner, rejInner) {
|
||||
ok(true, "Nested nested promise is executed");
|
||||
r1(42);
|
||||
resInner(42);
|
||||
}));
|
||||
}));
|
||||
}).then(function(value) {
|
||||
|
|
@ -491,7 +502,8 @@ function promiseLoop() {
|
|||
}
|
||||
|
||||
function promiseStaticReject() {
|
||||
var promise = Promise.reject(42).then(function(what) {
|
||||
var promise = Promise.reject(42);
|
||||
promise.then(function(what) {
|
||||
ok(false, "This should not be called");
|
||||
}, function(what) {
|
||||
is(what, 42, "Value == 42");
|
||||
|
|
@ -500,7 +512,8 @@ function promiseStaticReject() {
|
|||
}
|
||||
|
||||
function promiseStaticResolve() {
|
||||
var promise = Promise.resolve(42).then(function(what) {
|
||||
var promise = Promise.resolve(42);
|
||||
promise.then(function(what) {
|
||||
is(what, 42, "Value == 42");
|
||||
runTest();
|
||||
}, function() {
|
||||
|
|
@ -514,7 +527,8 @@ function promiseResolveNestedPromise() {
|
|||
r(42);
|
||||
}, function() {
|
||||
ok(false, "This should not be called");
|
||||
})).then(function(what) {
|
||||
}));
|
||||
promise.then(function(what) {
|
||||
is(what, 42, "Value == 42");
|
||||
runTest();
|
||||
}, function() {
|
||||
|
|
@ -554,6 +568,8 @@ function promiseSimpleThenableReject() {
|
|||
function promiseThenableThrowsBeforeCallback() {
|
||||
var thenable = { then(resolve) {
|
||||
throw new TypeError("Hi there");
|
||||
|
||||
// eslint-disable-next-line no-unreachable
|
||||
resolve(5);
|
||||
}};
|
||||
|
||||
|
|
@ -630,7 +646,7 @@ function promiseStrictHandlers() {
|
|||
}
|
||||
|
||||
function promiseStrictExecutorThisArg() {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
new Promise(function(resolve, reject) {
|
||||
"use strict";
|
||||
ok(this === undefined, "thisArg should be undefined.");
|
||||
runTest();
|
||||
|
|
@ -723,6 +739,7 @@ function promiseTestAsyncThenableResolution() {
|
|||
Promise.resolve().then(function next() {
|
||||
k--;
|
||||
if (k > 0) return Promise.resolve().then(next);
|
||||
return undefined;
|
||||
}).then(function() {
|
||||
ok(true, "Resolution of a chain of thenables should not be synchronous.");
|
||||
runTest();
|
||||
|
|
@ -825,4 +842,3 @@ runTest();
|
|||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
/* global async_test, assert_equals */
|
||||
var t = async_test("Promise callbacks should run immediately after the setTimeout handler that enqueues them");
|
||||
var origPostMessage = window.postMessage;
|
||||
window.postMessage = function(msg) { origPostMessage.call(window, msg, "*"); };
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
/* global async_test, assert_equals */
|
||||
var t = async_test("Promise callbacks in workers should run immediately after the setTimeout handler that enqueues them");
|
||||
var w = new Worker("file_promise_and_timeout_ordering.js");
|
||||
w.onmessage = t.step_func_done(function(e) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1323324
|
|||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script src="file_promise_argument_tests.js"></script>
|
||||
<script type="application/javascript">
|
||||
/* global TestFunctions */
|
||||
|
||||
/** Test for Bug 1323324 **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1436276.
|
|||
frames[0].label = "child";
|
||||
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
|
||||
runPromiseRetvalTests.bind(undefined,
|
||||
SimpleTest.finish));
|
||||
SimpleTest.finish));
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
|||
|
|
@ -136,7 +136,9 @@ function promiseAllRejectFails() {
|
|||
}
|
||||
|
||||
function promiseAllCastError() {
|
||||
var p = Promise.all([Promise.resolve(2), { then() { foo(); } }]);
|
||||
var p = Promise.all([Promise.resolve(2), { then() {
|
||||
throw new ReferenceError("placeholder for nonexistent function call");
|
||||
} }]);
|
||||
ok(p instanceof Promise, "Should cast to a Promise.");
|
||||
p.then(function(v) {
|
||||
ok(false, "promiseAllCastError: should've rejected.");
|
||||
|
|
@ -152,7 +154,7 @@ function promiseAllEnumerable() {
|
|||
var p = Promise.all([1, new Date(), Promise.resolve("firefox")]);
|
||||
p.then(function(v) {
|
||||
var count = 0;
|
||||
for (key in v) {
|
||||
for (let key in v) {
|
||||
++count;
|
||||
ok(v[key] === 1 || v[key] instanceof Date || v[key] === "firefox",
|
||||
"Enumerated properties don't match.");
|
||||
|
|
@ -193,14 +195,6 @@ function promiseRaceValuesArray() {
|
|||
}
|
||||
|
||||
function promiseRacePromiseArray() {
|
||||
function timeoutPromise(n) {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(function() {
|
||||
resolve(n);
|
||||
}, n);
|
||||
});
|
||||
}
|
||||
|
||||
var arr = [
|
||||
new Promise(function(resolve) {
|
||||
resolve("first");
|
||||
|
|
@ -264,7 +258,7 @@ function promiseRaceReject() {
|
|||
function promiseRaceThrow() {
|
||||
var p = Promise.race([
|
||||
new Promise(function(resolve) {
|
||||
nonExistent();
|
||||
throw new ReferenceError("placeholder for nonexistent function call");
|
||||
}),
|
||||
new Promise(function(resolve) {
|
||||
setTimeout(resolve, 0);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ function testRace1() {
|
|||
|
||||
function testRace2() {
|
||||
var p = win.Promise.race(
|
||||
new Array(win.Promise.resolve(1), win.Promise.resolve(2)));
|
||||
[win.Promise.resolve(1), win.Promise.resolve(2)]);
|
||||
p.then(
|
||||
function(arg) {
|
||||
ok(arg == 1 || arg == 2,
|
||||
|
|
@ -140,7 +140,7 @@ function testAll1() {
|
|||
|
||||
function testAll2() {
|
||||
var p = win.Promise.all(
|
||||
new Array(win.Promise.resolve(1), win.Promise.resolve(2)));
|
||||
[win.Promise.resolve(1), win.Promise.resolve(2)]);
|
||||
p.then(
|
||||
function(arg) {
|
||||
ok(arg instanceof win.Array, "Should get an Array from Promise.all (2)");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
/* global test, assert_not_equals, assert_equals */
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(Promise, Symbol.species);
|
||||
assert_not_equals(desc, undefined, "Should have a property");
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
/* global async_test, assert_true, assert_equals */
|
||||
|
||||
var t = async_test("A promise resolved first (with a thenable) should trigger its callbacks before a promise resolved second (with a promise).");
|
||||
t.step(function() {
|
||||
var customThenCalled = false;
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ function compileManySuccess() {
|
|||
|
||||
Promise.all(arr).then(ms => {
|
||||
ok(ms.length === N, "got the right number");
|
||||
for (var i = 0; i < N; i++)
|
||||
checkSampleModule(ms[i]);
|
||||
for (var j = 0; j < N; j++)
|
||||
checkSampleModule(ms[j]);
|
||||
runTest();
|
||||
}).catch(
|
||||
err => { ok(false, String(err)); runTest(); }
|
||||
|
|
@ -232,8 +232,8 @@ function compileManyStreamingFetch() {
|
|||
|
||||
Promise.all(arr).then(ms => {
|
||||
ok(ms.length === N, "got the right number");
|
||||
for (var i = 0; i < N; i++)
|
||||
checkSampleModule(ms[i]);
|
||||
for (var j = 0; j < N; j++)
|
||||
checkSampleModule(ms[j]);
|
||||
runTest();
|
||||
}).catch(
|
||||
err => { ok(false, String(err)); runTest(); }
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ const sampleURL = "test_webassembly_compile_sample.wasm";
|
|||
const sampleExportName = "run";
|
||||
const sampleResult = 1275;
|
||||
|
||||
/* eslint-disable no-throw-literal */
|
||||
|
||||
function checkSampleModule(m) {
|
||||
if (!(m instanceof WebAssembly.Module))
|
||||
throw "not a module";
|
||||
|
|
@ -25,15 +27,15 @@ onmessage = e => {
|
|||
WebAssembly.compile(e.data)
|
||||
.then(m => checkSampleModule(m))
|
||||
.then(() => WebAssembly.instantiate(e.data))
|
||||
.then(({module, instance}) => { checkSampleModule(module), checkSampleInstance(instance); })
|
||||
.then(({module, instance}) => { checkSampleModule(module); checkSampleInstance(instance); })
|
||||
.then(() => WebAssembly.compileStreaming(new Response(e.data, initObj)))
|
||||
.then(m => checkSampleModule(m))
|
||||
.then(() => WebAssembly.instantiateStreaming(new Response(e.data, initObj)))
|
||||
.then(({module, instance}) => { checkSampleModule(module), checkSampleInstance(instance); })
|
||||
.then(({module, instance}) => { checkSampleModule(module); checkSampleInstance(instance); })
|
||||
.then(() => WebAssembly.compileStreaming(fetch(sampleURL)))
|
||||
.then(m => checkSampleModule(m))
|
||||
.then(() => WebAssembly.instantiateStreaming(fetch(sampleURL)))
|
||||
.then(({module, instance}) => { checkSampleModule(module), checkSampleInstance(instance); })
|
||||
.then(({module, instance}) => { checkSampleModule(module); checkSampleInstance(instance); })
|
||||
.then(() => postMessage("ok"))
|
||||
.catch(err => postMessage("fail: " + err));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -84,9 +84,11 @@ add_task(async function test_observe_uncaught() {
|
|||
};
|
||||
|
||||
let resolveLater = function(delay = 20) {
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
return new Promise((resolve, reject) => setTimeout(resolve, delay));
|
||||
};
|
||||
let rejectLater = function(delay = 20) {
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
return new Promise((resolve, reject) => setTimeout(reject, delay));
|
||||
};
|
||||
let makeSamples = function* () {
|
||||
|
|
@ -119,6 +121,8 @@ add_task(async function test_observe_uncaught() {
|
|||
|
||||
// Reject a promise now, consume it later.
|
||||
let p = Promise.reject("Reject now, consume later");
|
||||
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
setTimeout(() => p.catch(() => {
|
||||
info("Consumed promise");
|
||||
}), 200);
|
||||
|
|
@ -261,6 +265,7 @@ add_task(async function test_uninstall_observer() {
|
|||
let wait = new Observer();
|
||||
Promise.reject("I am another uncaught rejection.");
|
||||
await wait.blocker;
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
// Normally, `deactivate` should not be notified of the uncaught rejection.
|
||||
wait.active = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue