зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1532935 - Enable ESLint for dom/promise (automatic changes). r=mccr8
# ignore-this-changeset Differential Revision: https://phabricator.services.mozilla.com/D29645 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
36f9d91fe8
Коммит
6614404241
|
@ -5,14 +5,14 @@ function schedulePromiseTask(f) {
|
|||
}
|
||||
|
||||
setTimeout(function() {
|
||||
log.push('t1start');
|
||||
log.push("t1start");
|
||||
schedulePromiseTask(function() {
|
||||
log.push('promise');
|
||||
log.push("promise");
|
||||
});
|
||||
log.push('t1end');
|
||||
log.push("t1end");
|
||||
}, 10);
|
||||
|
||||
setTimeout(function() {
|
||||
log.push('t2');
|
||||
postMessage(log.join(', '));
|
||||
log.push("t2");
|
||||
postMessage(log.join(", "));
|
||||
}, 10);
|
||||
|
|
|
@ -35,10 +35,10 @@ function passPrimitive(global) {
|
|||
function passThenable(global) {
|
||||
var called = false;
|
||||
var thenable = {
|
||||
then: function(f) {
|
||||
then(f) {
|
||||
called = true;
|
||||
f(7);
|
||||
}
|
||||
},
|
||||
};
|
||||
var p = getPromise(global, thenable);
|
||||
verifyPromiseGlobal(p, global, "Promise wrapping thenable");
|
||||
|
|
|
@ -17,7 +17,7 @@ function testThrownException(global) {
|
|||
var p = global.TestFunctions.throwToRejectPromise();
|
||||
verifyPromiseGlobal(p, global, "throwToRejectPromise return value");
|
||||
return p.then(() => {}).catch((err) => {
|
||||
var expected = expectedExceptionGlobal(global)
|
||||
var expected = expectedExceptionGlobal(global);
|
||||
is(SpecialPowers.unwrap(SpecialPowers.Cu.getGlobalForObject(err)),
|
||||
expected,
|
||||
"Should have an exception object from the right global too");
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
<html>
|
||||
<script>
|
||||
function vendGetter(name) {
|
||||
return function() { throw "Getting " + String(name) };
|
||||
return function() { throw "Getting " + String(name); };
|
||||
}
|
||||
function vendSetter(name) {
|
||||
return function() { throw "Setting " + String(name) };
|
||||
return function() { throw "Setting " + String(name); };
|
||||
}
|
||||
var setupThrew = false;
|
||||
try {
|
||||
|
|
|
@ -21,7 +21,7 @@ Debugger.prototype.onNewPromise.
|
|||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
is(Object.prototype.toString.call(new Promise(function () {})),
|
||||
is(Object.prototype.toString.call(new Promise(function() {})),
|
||||
"[object Promise]",
|
||||
"We should have the native DOM promise implementation.");
|
||||
|
||||
|
@ -32,9 +32,9 @@ Debugger.prototype.onNewPromise.
|
|||
var dbg = new dbgGlobal.Debugger(this);
|
||||
|
||||
var wrappedPromise;
|
||||
dbg.onNewPromise = function (wp) { wrappedPromise = wp; };
|
||||
dbg.onNewPromise = function(wp) { wrappedPromise = wp; };
|
||||
|
||||
var promise = new Promise(function () {});
|
||||
var promise = new Promise(function() {});
|
||||
debugger;
|
||||
ok(wrappedPromise);
|
||||
is(wrappedPromise.unsafeDereference(), promise);
|
||||
|
|
|
@ -23,7 +23,7 @@ Debugger.prototype.onPromiseResolved.
|
|||
<script type="application/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
is(Object.prototype.toString.call(new Promise(function () {})),
|
||||
is(Object.prototype.toString.call(new Promise(function() {})),
|
||||
"[object Promise]",
|
||||
"We should have the native DOM promise implementation.");
|
||||
|
||||
|
@ -34,16 +34,16 @@ Debugger.prototype.onPromiseResolved.
|
|||
var dbg = new dbgGlobal.Debugger(this);
|
||||
|
||||
var wrappedPromise;
|
||||
dbg.onPromiseSettled = function (wp) { wrappedPromise = wp; };
|
||||
dbg.onPromiseSettled = function(wp) { wrappedPromise = wp; };
|
||||
|
||||
var promise = Promise.resolve();
|
||||
promise
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
ok(wrappedPromise);
|
||||
is(wrappedPromise.unsafeDereference(), promise);
|
||||
dbg.onPromiseSettled = undefined;
|
||||
})
|
||||
.catch(function (e) {
|
||||
.catch(function(e) {
|
||||
ok(false, "Got an unexpected error: " + e);
|
||||
})
|
||||
.then(SimpleTest.finish);
|
||||
|
|
|
@ -22,7 +22,7 @@ Bug 1084065 - Test that Debugger.prototype.onPromiseResolved doesn't get dupes.
|
|||
<script type="application/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
is(Object.prototype.toString.call(new Promise(function () {})),
|
||||
is(Object.prototype.toString.call(new Promise(function() {})),
|
||||
"[object Promise]",
|
||||
"We should have the native DOM promise implementation.");
|
||||
|
||||
|
@ -33,22 +33,22 @@ Bug 1084065 - Test that Debugger.prototype.onPromiseResolved doesn't get dupes.
|
|||
var dbg = new dbgGlobal.Debugger(this);
|
||||
|
||||
var seen = new Set();
|
||||
dbg.onPromiseSettled = function (wp) {
|
||||
dbg.onPromiseSettled = function(wp) {
|
||||
is(seen.has(wp), false);
|
||||
seen.add(wp);
|
||||
};
|
||||
|
||||
var promise = new Promise(function (fulfill, reject) {
|
||||
var promise = new Promise(function(fulfill, reject) {
|
||||
fulfill(1);
|
||||
fulfill(2);
|
||||
fulfill(3);
|
||||
});
|
||||
|
||||
promise
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
dbg.onPromiseSettled = undefined;
|
||||
})
|
||||
.catch(function (e) {
|
||||
.catch(function(e) {
|
||||
ok(false, "Got an unexpected error: " + e);
|
||||
})
|
||||
.then(SimpleTest.finish);
|
||||
|
|
|
@ -169,8 +169,7 @@ function promiseAsync_ResolveThenTimeout() {
|
|||
ok(!handlerExecuted, "Handlers are not called before 'then' returns.");
|
||||
}
|
||||
|
||||
function promiseAsync_SyncXHR()
|
||||
{
|
||||
function promiseAsync_SyncXHR() {
|
||||
var handlerExecuted = false;
|
||||
|
||||
Promise.resolve().then(function() {
|
||||
|
@ -322,7 +321,7 @@ function promiseRejectThenCatchThen() {
|
|||
promise2.then(function(what) {
|
||||
ok(true, "Then.resolve has been called");
|
||||
is(what, 43, "Value == 43");
|
||||
return what+1;
|
||||
return what + 1;
|
||||
}).catch(function(what) {
|
||||
ok(false, "Catch has been called");
|
||||
}).then(function(what) {
|
||||
|
@ -340,11 +339,11 @@ function promiseRejectThenCatchThen2() {
|
|||
promise.then(function(what) {
|
||||
ok(true, "Then.resolve has been called");
|
||||
is(what, 42, "Value == 42");
|
||||
return what+1;
|
||||
return what + 1;
|
||||
}).catch(function(what) {
|
||||
is(what, 42, "Value == 42");
|
||||
ok(true, "Catch has been called");
|
||||
return what+1;
|
||||
return what + 1;
|
||||
}).then(function(what) {
|
||||
ok(true, "Then.resolve has been called");
|
||||
is(what, 43, "Value == 43");
|
||||
|
@ -362,7 +361,7 @@ function promiseRejectThenCatchExceptionThen() {
|
|||
}, function(what) {
|
||||
ok(true, "Then.reject has been called");
|
||||
is(what, 42, "Value == 42");
|
||||
throw(what + 1);
|
||||
throw (what + 1);
|
||||
}).catch(function(what) {
|
||||
ok(true, "Catch has been called");
|
||||
is(what, 43, "Value == 43");
|
||||
|
@ -401,7 +400,7 @@ function promiseThenCatchOrderingReject() {
|
|||
var global = 0;
|
||||
var f = new Promise(function(r1, r2) {
|
||||
r2(42);
|
||||
})
|
||||
});
|
||||
|
||||
f.then(function() {}, function() {
|
||||
f.then(function() {
|
||||
|
@ -452,7 +451,7 @@ function promiseNestedNestedPromise() {
|
|||
resolve(new Promise(function(resolve, reject) {
|
||||
ok(true, "Nested promise is executed");
|
||||
resolve(42);
|
||||
}).then(function(what) { return what+1; }));
|
||||
}).then(function(what) { return what + 1; }));
|
||||
}).then(function(value) {
|
||||
is(value, 43, "Nested promise is executed and then == 43");
|
||||
runTest();
|
||||
|
@ -524,7 +523,7 @@ function promiseResolveNestedPromise() {
|
|||
}
|
||||
|
||||
function promiseSimpleThenableResolve() {
|
||||
var thenable = { then: function(resolve) { resolve(5); } };
|
||||
var thenable = { then(resolve) { resolve(5); } };
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
resolve(thenable);
|
||||
});
|
||||
|
@ -538,7 +537,7 @@ function promiseSimpleThenableResolve() {
|
|||
}
|
||||
|
||||
function promiseSimpleThenableReject() {
|
||||
var thenable = { then: function(resolve, reject) { reject(5); } };
|
||||
var thenable = { then(resolve, reject) { reject(5); } };
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
resolve(thenable);
|
||||
});
|
||||
|
@ -553,7 +552,7 @@ function promiseSimpleThenableReject() {
|
|||
}
|
||||
|
||||
function promiseThenableThrowsBeforeCallback() {
|
||||
var thenable = { then: function(resolve) {
|
||||
var thenable = { then(resolve) {
|
||||
throw new TypeError("Hi there");
|
||||
resolve(5);
|
||||
}};
|
||||
|
@ -569,7 +568,7 @@ function promiseThenableThrowsBeforeCallback() {
|
|||
}
|
||||
|
||||
function promiseThenableThrowsAfterCallback() {
|
||||
var thenable = { then: function(resolve) {
|
||||
var thenable = { then(resolve) {
|
||||
resolve(5);
|
||||
throw new TypeError("Hi there");
|
||||
}};
|
||||
|
@ -585,7 +584,7 @@ function promiseThenableThrowsAfterCallback() {
|
|||
}
|
||||
|
||||
function promiseThenableRejectThenResolve() {
|
||||
var thenable = { then: function(resolve, reject) {
|
||||
var thenable = { then(resolve, reject) {
|
||||
reject(new TypeError("Hi there"));
|
||||
resolve(5);
|
||||
}};
|
||||
|
@ -609,7 +608,7 @@ function promiseWithThenReplaced() {
|
|||
// Rogue `then` always rejects.
|
||||
promise.then = function(onFulfill, onReject) {
|
||||
onReject(new TypeError("Foo"));
|
||||
}
|
||||
};
|
||||
|
||||
var promise2 = Promise.resolve(promise);
|
||||
promise2.then(function(v) {
|
||||
|
@ -639,7 +638,7 @@ function promiseStrictExecutorThisArg() {
|
|||
}
|
||||
|
||||
function promiseResolveArray() {
|
||||
var p = Promise.resolve([1,2,3]);
|
||||
var p = Promise.resolve([1, 2, 3]);
|
||||
ok(p instanceof Promise, "Should return a Promise.");
|
||||
p.then(function(v) {
|
||||
ok(Array.isArray(v), "Resolved value should be an Array");
|
||||
|
@ -652,7 +651,7 @@ function promiseResolveArray() {
|
|||
}
|
||||
|
||||
function promiseResolveThenable() {
|
||||
var p = Promise.resolve({ then: function(onFulfill, onReject) { onFulfill(2); } });
|
||||
var p = Promise.resolve({ then(onFulfill, onReject) { onFulfill(2); } });
|
||||
ok(p instanceof Promise, "Should cast to a Promise.");
|
||||
p.then(function(v) {
|
||||
is(v, 2, "Should resolve to 2.");
|
||||
|
@ -681,7 +680,7 @@ function promiseResolvePromise() {
|
|||
// https://gist.github.com/getify/d64bb01751b50ed6b281#file-bug1-js.
|
||||
function promiseResolveThenableCleanStack() {
|
||||
function immed(s) { x++; s(); }
|
||||
function incX(){ x++; }
|
||||
function incX() { x++; }
|
||||
|
||||
var x = 0;
|
||||
var thenable = { then: immed };
|
||||
|
@ -692,7 +691,7 @@ function promiseResolveThenableCleanStack() {
|
|||
|
||||
// check what happens after all "next cycle" steps
|
||||
// have had a chance to complete
|
||||
setTimeout(function(){
|
||||
setTimeout(function() {
|
||||
// Result should be [0, 2] since `thenable` will be called async.
|
||||
is(results[0], 0, "Expected thenable to be called asynchronously");
|
||||
// See Bug 1023547 comment 13 for why this check has to be gated on p.
|
||||
|
@ -701,7 +700,7 @@ function promiseResolveThenableCleanStack() {
|
|||
is(results[1], 2, "Expected thenable to be called asynchronously");
|
||||
runTest();
|
||||
});
|
||||
},1000);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// Bug 1008467 - Promise fails with "too much recursion".
|
||||
|
@ -719,39 +718,37 @@ function promiseResolveThenableCleanStack() {
|
|||
// `m` when `p` invoked them (on account of itself being resolved, possibly
|
||||
// synchronously. A chain of these 'Promise resolved by a Promise' would lead to
|
||||
// stack overflow.
|
||||
function promiseTestAsyncThenableResolution()
|
||||
{
|
||||
function promiseTestAsyncThenableResolution() {
|
||||
var k = 3000;
|
||||
Promise.resolve().then(function next() {
|
||||
k--;
|
||||
if (k > 0) return Promise.resolve().then(next);
|
||||
}).then(function () {
|
||||
}).then(function() {
|
||||
ok(true, "Resolution of a chain of thenables should not be synchronous.");
|
||||
runTest();
|
||||
});
|
||||
}
|
||||
|
||||
// Bug 1062323
|
||||
function promiseWrapperAsyncResolution()
|
||||
{
|
||||
var p = new Promise(function(resolve, reject){
|
||||
function promiseWrapperAsyncResolution() {
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
resolve();
|
||||
});
|
||||
|
||||
var results = [];
|
||||
var q = p.then(function () {
|
||||
var q = p.then(function() {
|
||||
results.push("1-1");
|
||||
}).then(function () {
|
||||
}).then(function() {
|
||||
results.push("1-2");
|
||||
}).then(function () {
|
||||
}).then(function() {
|
||||
results.push("1-3");
|
||||
});
|
||||
|
||||
var r = p.then(function () {
|
||||
var r = p.then(function() {
|
||||
results.push("2-1");
|
||||
}).then(function () {
|
||||
}).then(function() {
|
||||
results.push("2-2");
|
||||
}).then(function () {
|
||||
}).then(function() {
|
||||
results.push("2-3");
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<script>
|
||||
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, "*"); }
|
||||
window.postMessage = function(msg) { origPostMessage.call(window, msg, "*"); };
|
||||
window.onmessage = t.step_func_done(function(e) {
|
||||
assert_equals(e.data, "t1start, t1end, promise, t2");
|
||||
});
|
||||
|
|
|
@ -30,7 +30,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1323324
|
|||
|
||||
addLoadEvent(function() {
|
||||
frames[0].label = "child";
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
|
||||
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
|
||||
runPromiseArgumentTests.bind(undefined,
|
||||
SimpleTest.finish));
|
||||
});
|
||||
|
|
|
@ -80,7 +80,7 @@ function nextTest() {
|
|||
|
||||
addLoadEvent(function() {
|
||||
frames[0].label = "child";
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
|
||||
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
|
||||
nextTest);
|
||||
});
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1323324
|
|||
|
||||
addLoadEvent(function() {
|
||||
frames[0].label = "child";
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
|
||||
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
|
||||
runPromiseArgumentTests.bind(undefined,
|
||||
SimpleTest.finish));
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1436276.
|
|||
|
||||
addLoadEvent(function() {
|
||||
frames[0].label = "child";
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
|
||||
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
|
||||
runPromiseRetvalTests.bind(undefined,
|
||||
SimpleTest.finish));
|
||||
});
|
||||
|
|
|
@ -84,7 +84,7 @@ function nextTest() {
|
|||
|
||||
addLoadEvent(function() {
|
||||
frames[0].label = "child";
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
|
||||
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
|
||||
nextTest);
|
||||
});
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
onmessage = function(evt) {
|
||||
ok(true, "finished");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
};
|
||||
|
||||
function go() {
|
||||
var script = document.createElement("script");
|
||||
|
@ -28,7 +28,7 @@ function go() {
|
|||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, go);
|
||||
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, go);
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
|
@ -90,7 +90,7 @@ function promiseAllWaitsForAllPromises() {
|
|||
}),
|
||||
new Promise(function(resolve) {
|
||||
setTimeout(resolve.bind(undefined, 4), 20);
|
||||
})
|
||||
}),
|
||||
];
|
||||
|
||||
var p = Promise.all(arr);
|
||||
|
@ -121,7 +121,7 @@ function promiseAllRejectFails() {
|
|||
}),
|
||||
new Promise(function(resolve) {
|
||||
setTimeout(resolve.bind(undefined, 4), 20);
|
||||
})
|
||||
}),
|
||||
];
|
||||
|
||||
var p = Promise.all(arr);
|
||||
|
@ -136,7 +136,7 @@ function promiseAllRejectFails() {
|
|||
}
|
||||
|
||||
function promiseAllCastError() {
|
||||
var p = Promise.all([Promise.resolve(2), { then: function() { foo(); } }]);
|
||||
var p = Promise.all([Promise.resolve(2), { then() { foo(); } }]);
|
||||
ok(p instanceof Promise, "Should cast to a Promise.");
|
||||
p.then(function(v) {
|
||||
ok(false, "promiseAllCastError: should've rejected.");
|
||||
|
@ -247,7 +247,7 @@ function promiseRaceReject() {
|
|||
Promise.reject(new Error("Fail bad!")),
|
||||
new Promise(function(resolve) {
|
||||
setTimeout(resolve, 0);
|
||||
})
|
||||
}),
|
||||
]);
|
||||
|
||||
p.then(function() {
|
||||
|
@ -268,7 +268,7 @@ function promiseRaceThrow() {
|
|||
}),
|
||||
new Promise(function(resolve) {
|
||||
setTimeout(resolve, 0);
|
||||
})
|
||||
}),
|
||||
]);
|
||||
|
||||
p.then(function() {
|
||||
|
|
|
@ -270,7 +270,7 @@ function testReject2() {
|
|||
|
||||
function testThen1() {
|
||||
var p = win.Promise.resolve(5);
|
||||
var q = p.then((x) => x*x);
|
||||
var q = p.then((x) => x * x);
|
||||
ok(q instanceof win.Promise,
|
||||
"Promise.then should return a promise from the right global");
|
||||
q.then(
|
||||
|
@ -285,7 +285,7 @@ function testThen1() {
|
|||
|
||||
function testThen2() {
|
||||
var p = win.Promise.resolve(5);
|
||||
var q = p.then((x) => Promise.resolve(x*x));
|
||||
var q = p.then((x) => Promise.resolve(x * x));
|
||||
ok(q instanceof win.Promise,
|
||||
"Promise.then should return a promise from the right global");
|
||||
q.then(
|
||||
|
@ -301,7 +301,7 @@ function testThen2() {
|
|||
function testCatch1() {
|
||||
var p = win.Promise.reject(5);
|
||||
ok(p instanceof win.Promise, "Promise.reject should return a promise");
|
||||
var q = p.catch((x) => x*x);
|
||||
var q = p.catch((x) => x * x);
|
||||
ok(q instanceof win.Promise,
|
||||
"Promise.catch should return a promise from the right global");
|
||||
q.then(
|
||||
|
|
|
@ -28,7 +28,7 @@ var tests = [
|
|||
function() {},
|
||||
window,
|
||||
undefined,
|
||||
document.createElement('input'),
|
||||
document.createElement("input"),
|
||||
new Date(),
|
||||
];
|
||||
|
||||
|
@ -50,7 +50,7 @@ function runTest() {
|
|||
ok(test === what, "What is: " + what);
|
||||
}, cbError).then(function() {
|
||||
new Promise(function(resolve, reject) {
|
||||
reject(test)
|
||||
reject(test);
|
||||
}).then(cbError, function(what) {
|
||||
ok(test === what, "What is: " + what);
|
||||
}).then(runTest, cbError);
|
||||
|
|
|
@ -17,11 +17,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1120235
|
|||
is(rej(2), undefined, "Reject function should return undefined");
|
||||
|
||||
var thenable = {
|
||||
then: function(resolve, reject) {
|
||||
then(resolve, reject) {
|
||||
is(resolve(3), undefined, "Thenable resolve argument should return undefined");
|
||||
is(reject(4), undefined, "Thenable reject argument should return undefined");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
|
|
@ -19,6 +19,5 @@ test(function() {
|
|||
assert_equals(getter.call(thing), thing,
|
||||
"Getter should return its this value");
|
||||
}
|
||||
|
||||
}, "Promise should have an @@species getter that works per spec");
|
||||
</script>
|
||||
|
|
|
@ -12,7 +12,7 @@ t.step(function() {
|
|||
p0.then = function(resolved, rejected) {
|
||||
customThenCalled = true;
|
||||
Promise.prototype.then.call(this, resolved, rejected);
|
||||
}
|
||||
};
|
||||
var p1 = new Promise(function(r) { r(p0); });
|
||||
delete p0.then;
|
||||
var p2 = new Promise(function(r) { r(p0); });
|
||||
|
|
|
@ -11,14 +11,14 @@
|
|||
<body>
|
||||
<script>
|
||||
const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
|
||||
const wasmIsSupported = SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported
|
||||
const wasmIsSupported = SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported;
|
||||
|
||||
// The test_webassembly_compile_sample.wasm is a medium-sized module with 100
|
||||
// functions that call each other recursively, returning a computed sum.
|
||||
// Any other non-trivial module could be generated and used.
|
||||
var sampleCode;
|
||||
const sampleURL = 'test_webassembly_compile_sample.wasm';
|
||||
const sampleExportName = 'run';
|
||||
const sampleURL = "test_webassembly_compile_sample.wasm";
|
||||
const sampleExportName = "run";
|
||||
const sampleResult = 1275;
|
||||
|
||||
function checkSampleModule(m) {
|
||||
|
@ -36,13 +36,13 @@ function checkSampleInstance(i) {
|
|||
function fetchSampleModuleCode() {
|
||||
fetch(sampleURL)
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => {sampleCode = buffer; runTest()})
|
||||
.then(buffer => { sampleCode = buffer; runTest(); })
|
||||
.catch(err => ok(false, String(err)));
|
||||
}
|
||||
|
||||
function propertiesExist() {
|
||||
if (!wasmIsSupported()) {
|
||||
ok(!this["WebAssembly"], "If the device doesn't support, there will be no WebAssembly object");
|
||||
ok(!this.WebAssembly, "If the device doesn't support, there will be no WebAssembly object");
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
@ -54,17 +54,17 @@ function propertiesExist() {
|
|||
|
||||
function compileFail() {
|
||||
WebAssembly.compile().then(
|
||||
() => { ok(false, "should have failed"); runTest() }
|
||||
() => { ok(false, "should have failed"); runTest(); }
|
||||
).catch(
|
||||
err => { ok(err instanceof TypeError, "empty compile failed"); runTest() }
|
||||
err => { ok(err instanceof TypeError, "empty compile failed"); runTest(); }
|
||||
);
|
||||
}
|
||||
|
||||
function compileSuccess() {
|
||||
WebAssembly.compile(sampleCode).then(
|
||||
m => { checkSampleModule(m); runTest() }
|
||||
m => { checkSampleModule(m); runTest(); }
|
||||
).catch(
|
||||
err => { ok(false, String(err)); runTest() }
|
||||
err => { ok(false, String(err)); runTest(); }
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -77,13 +77,13 @@ function compileManySuccess() {
|
|||
|
||||
SpecialPowers.gc();
|
||||
|
||||
Promise.all(arr).then (ms => {
|
||||
Promise.all(arr).then(ms => {
|
||||
ok(ms.length === N, "got the right number");
|
||||
for (var i = 0; i < N; i++)
|
||||
checkSampleModule(ms[i]);
|
||||
runTest();
|
||||
}).catch(
|
||||
err => { ok(false, String(err)); runTest() }
|
||||
err => { ok(false, String(err)); runTest(); }
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -108,22 +108,22 @@ function terminateCompileInWorker() {
|
|||
ok(e.data === "ok", "worker finished first step");
|
||||
w.terminate();
|
||||
runTest();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function instantiateFail() {
|
||||
WebAssembly.instantiate().then(
|
||||
() => { ok(false, "should have failed"); runTest() }
|
||||
() => { ok(false, "should have failed"); runTest(); }
|
||||
).catch(
|
||||
err => { ok(err instanceof TypeError, "empty compile failed"); runTest() }
|
||||
err => { ok(err instanceof TypeError, "empty compile failed"); runTest(); }
|
||||
);
|
||||
}
|
||||
|
||||
function instantiateSuccess() {
|
||||
WebAssembly.instantiate(sampleCode).then(
|
||||
r => { checkSampleModule(r.module); checkSampleInstance(r.instance); runTest() }
|
||||
r => { checkSampleModule(r.module); checkSampleInstance(r.instance); runTest(); }
|
||||
).catch(
|
||||
err => { ok(false, String(err)); runTest() }
|
||||
err => { ok(false, String(err)); runTest(); }
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -131,60 +131,60 @@ function chainSuccess() {
|
|||
WebAssembly.compile(sampleCode).then(
|
||||
m => WebAssembly.instantiate(m)
|
||||
).then(
|
||||
i => { checkSampleInstance(i); runTest() }
|
||||
i => { checkSampleInstance(i); runTest(); }
|
||||
).catch(
|
||||
err => { ok(false, String(err)); runTest() }
|
||||
err => { ok(false, String(err)); runTest(); }
|
||||
);
|
||||
}
|
||||
|
||||
function compileStreamingNonResponse() {
|
||||
WebAssembly.compileStreaming({})
|
||||
.then(() => { ok(false) })
|
||||
.catch(err => { ok(err instanceof TypeError, "rejected {}"); runTest() });
|
||||
.then(() => { ok(false); })
|
||||
.catch(err => { ok(err instanceof TypeError, "rejected {}"); runTest(); });
|
||||
}
|
||||
|
||||
function compileStreamingNoMime() {
|
||||
WebAssembly.compileStreaming(new Response(new ArrayBuffer()))
|
||||
.then(() => { ok(false) })
|
||||
.catch(err => { ok(err instanceof TypeError, "rejected no MIME type"); runTest() });
|
||||
.then(() => { ok(false); })
|
||||
.catch(err => { ok(err instanceof TypeError, "rejected no MIME type"); runTest(); });
|
||||
}
|
||||
|
||||
function compileStreamingBadMime() {
|
||||
var badMimes = [
|
||||
'',
|
||||
'application/js',
|
||||
'application/js;application/wasm',
|
||||
'application/wasm;application/js',
|
||||
'application/wasm;',
|
||||
'application/wasm1'
|
||||
"",
|
||||
"application/js",
|
||||
"application/js;application/wasm",
|
||||
"application/wasm;application/js",
|
||||
"application/wasm;",
|
||||
"application/wasm1",
|
||||
];
|
||||
var promises = [];
|
||||
for (let mimeType of badMimes) {
|
||||
var init = { headers: { 'Content-Type' : mimeType } };
|
||||
var init = { headers: { "Content-Type": mimeType } };
|
||||
promises.push(
|
||||
WebAssembly.compileStreaming(new Response(sampleCode, init))
|
||||
.then(() => Promise.reject(), err => Promise.resolve())
|
||||
);
|
||||
}
|
||||
Promise.all(promises)
|
||||
.then(() => { ok(true, "all bad MIME types rejected"); runTest() })
|
||||
.then(() => { ok(true, "all bad MIME types rejected"); runTest(); });
|
||||
}
|
||||
|
||||
function compileStreamingGoodMime() {
|
||||
var badMimes = [
|
||||
'application/wasm',
|
||||
' application/wasm ',
|
||||
'application/wasm '
|
||||
"application/wasm",
|
||||
" application/wasm ",
|
||||
"application/wasm ",
|
||||
];
|
||||
var promises = [];
|
||||
for (let mimeType of badMimes) {
|
||||
var init = { headers: { 'Content-Type' : mimeType } };
|
||||
var init = { headers: { "Content-Type": mimeType } };
|
||||
promises.push(
|
||||
WebAssembly.compileStreaming(new Response(sampleCode, init))
|
||||
);
|
||||
}
|
||||
Promise.all(promises)
|
||||
.then(() => { ok(true, "all good MIME types accepted"); runTest() })
|
||||
.then(() => { ok(true, "all good MIME types accepted"); runTest(); });
|
||||
}
|
||||
|
||||
function compileStreamingDoubleUseFail() {
|
||||
|
@ -193,32 +193,32 @@ function compileStreamingDoubleUseFail() {
|
|||
WebAssembly.compileStreaming(response)
|
||||
.then(m => {
|
||||
checkSampleModule(m);
|
||||
return WebAssembly.compileStreaming(response)
|
||||
return WebAssembly.compileStreaming(response);
|
||||
})
|
||||
.then(
|
||||
() => ok(false, "should have failed on second use"),
|
||||
err => { ok(true, "failed on second use"); runTest() }
|
||||
err => { ok(true, "failed on second use"); runTest(); }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function compileStreamingNullBody() {
|
||||
var init = { headers: { 'Content-Type' : 'application/wasm' } };
|
||||
var init = { headers: { "Content-Type": "application/wasm" } };
|
||||
WebAssembly.compileStreaming(new Response(undefined, init))
|
||||
.then(() => { ok(false) })
|
||||
.catch(err => { ok(err instanceof WebAssembly.CompileError, "null body"); runTest() });
|
||||
.then(() => { ok(false); })
|
||||
.catch(err => { ok(err instanceof WebAssembly.CompileError, "null body"); runTest(); });
|
||||
}
|
||||
|
||||
function compileStreamingFetch() {
|
||||
WebAssembly.compileStreaming(fetch(sampleURL))
|
||||
.then(m => { checkSampleModule(m); runTest(); })
|
||||
.catch(err => { ok(false, String(err)) });
|
||||
.catch(err => { ok(false, String(err)); });
|
||||
}
|
||||
|
||||
function instantiateStreamingFetch() {
|
||||
WebAssembly.instantiateStreaming(fetch(sampleURL))
|
||||
.then(({module,instance}) => { checkSampleModule(module); checkSampleInstance(instance); runTest(); })
|
||||
.catch(err => { ok(false, String(err)) });
|
||||
.then(({module, instance}) => { checkSampleModule(module); checkSampleInstance(instance); runTest(); })
|
||||
.catch(err => { ok(false, String(err)); });
|
||||
}
|
||||
|
||||
function compileManyStreamingFetch() {
|
||||
|
@ -230,32 +230,32 @@ function compileManyStreamingFetch() {
|
|||
|
||||
SpecialPowers.gc();
|
||||
|
||||
Promise.all(arr).then (ms => {
|
||||
Promise.all(arr).then(ms => {
|
||||
ok(ms.length === N, "got the right number");
|
||||
for (var i = 0; i < N; i++)
|
||||
checkSampleModule(ms[i]);
|
||||
runTest();
|
||||
}).catch(
|
||||
err => { ok(false, String(err)); runTest() }
|
||||
err => { ok(false, String(err)); runTest(); }
|
||||
);
|
||||
}
|
||||
|
||||
function runWorkerTests() {
|
||||
var w = new Worker('test_webassembly_compile_worker.js');
|
||||
var w = new Worker("test_webassembly_compile_worker.js");
|
||||
w.postMessage(sampleCode);
|
||||
w.onmessage = e => {
|
||||
ok(e.data === "ok", "worker test: " + e.data);
|
||||
runTest();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function terminateCompileStreamingInWorker() {
|
||||
var w = new Worker('test_webassembly_compile_worker_terminate.js');
|
||||
var w = new Worker("test_webassembly_compile_worker_terminate.js");
|
||||
w.onmessage = e => {
|
||||
ok(e.data === "ok", "worker streaming terminate test: " + e.data);
|
||||
w.terminate();
|
||||
runTest();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var tests = [ propertiesExist,
|
||||
|
@ -276,7 +276,7 @@ var tests = [ propertiesExist,
|
|||
instantiateStreamingFetch,
|
||||
compileManyStreamingFetch,
|
||||
runWorkerTests,
|
||||
terminateCompileStreamingInWorker
|
||||
terminateCompileStreamingInWorker,
|
||||
];
|
||||
|
||||
// This initialization must always run
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const sampleURL = 'test_webassembly_compile_sample.wasm';
|
||||
const sampleExportName = 'run';
|
||||
const sampleURL = "test_webassembly_compile_sample.wasm";
|
||||
const sampleExportName = "run";
|
||||
const sampleResult = 1275;
|
||||
|
||||
function checkSampleModule(m) {
|
||||
|
@ -19,21 +19,21 @@ function checkSampleInstance(i) {
|
|||
throw "wrong result";
|
||||
}
|
||||
|
||||
const initObj = { headers: { 'Content-Type' : 'application/wasm' } };
|
||||
const initObj = { headers: { "Content-Type": "application/wasm" } };
|
||||
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const sampleURL = 'test_webassembly_compile_sample.wasm';
|
||||
const sampleURL = "test_webassembly_compile_sample.wasm";
|
||||
|
||||
function spawnWork() {
|
||||
const N = 50;
|
||||
|
|
|
@ -45,7 +45,7 @@ add_task(async function test_observe_uncaught() {
|
|||
this.blocker = new Promise(resolve => this.resolve = resolve);
|
||||
};
|
||||
CallbackResults.prototype = {
|
||||
observe: function(promise) {
|
||||
observe(promise) {
|
||||
info(this.name + " observing Promise " + names.get(promise));
|
||||
Assert.equal(PromiseDebugging.getState(promise).state, "rejected",
|
||||
this.name + " observed a rejected Promise");
|
||||
|
@ -55,11 +55,10 @@ add_task(async function test_observe_uncaught() {
|
|||
names.get(promise) +
|
||||
" (" + PromiseDebugging.getPromiseID(promise) +
|
||||
", " + PromiseDebugging.getAllocationStack(promise) + ")");
|
||||
|
||||
}
|
||||
Assert.ok(this.expected.delete(promise),
|
||||
this.name + " observed a Promise that it expected to observe, " +
|
||||
names.get(promise) + " (" + PromiseDebugging.getPromiseID(promise) + ")");
|
||||
names.get(promise) + " (" + PromiseDebugging.getPromiseID(promise) + ")");
|
||||
Assert.ok(!this.observed.has(promise),
|
||||
this.name + " observed a Promise that it has not observed yet");
|
||||
this.observed.add(promise);
|
||||
|
@ -76,10 +75,10 @@ add_task(async function test_observe_uncaught() {
|
|||
let onConsumed = new CallbackResults("onConsumed");
|
||||
|
||||
let observer = {
|
||||
onLeftUncaught: function(promise, data) {
|
||||
onLeftUncaught(promise, data) {
|
||||
onLeftUncaught.observe(promise);
|
||||
},
|
||||
onConsumed: function(promise) {
|
||||
onConsumed(promise) {
|
||||
onConsumed.observe(promise);
|
||||
},
|
||||
};
|
||||
|
@ -90,7 +89,7 @@ add_task(async function test_observe_uncaught() {
|
|||
let rejectLater = function(delay = 20) {
|
||||
return new Promise((resolve, reject) => setTimeout(reject, delay));
|
||||
};
|
||||
let makeSamples = function*() {
|
||||
let makeSamples = function* () {
|
||||
yield {
|
||||
promise: Promise.resolve(0),
|
||||
name: "Promise.resolve",
|
||||
|
@ -101,7 +100,7 @@ add_task(async function test_observe_uncaught() {
|
|||
};
|
||||
yield {
|
||||
promise: Promise.resolve(0).catch(null),
|
||||
name: "`catch(null)`"
|
||||
name: "`catch(null)`",
|
||||
};
|
||||
yield {
|
||||
promise: Promise.reject(0).catch(() => {}),
|
||||
|
@ -133,10 +132,10 @@ add_task(async function test_observe_uncaught() {
|
|||
yield {
|
||||
promise: Promise.all([
|
||||
Promise.resolve("Promise.all"),
|
||||
rejectLater()
|
||||
rejectLater(),
|
||||
]),
|
||||
leftUncaught: true,
|
||||
name: "Rejecting through Promise.all"
|
||||
name: "Rejecting through Promise.all",
|
||||
};
|
||||
yield {
|
||||
promise: Promise.race([
|
||||
|
@ -149,7 +148,7 @@ add_task(async function test_observe_uncaught() {
|
|||
yield {
|
||||
promise: Promise.race([
|
||||
Promise.resolve(),
|
||||
rejectLater(500)
|
||||
rejectLater(500),
|
||||
]),
|
||||
leftUncaught: false, // The resolution wins the race.
|
||||
name: "Resolving through Promise.race",
|
||||
|
@ -241,11 +240,11 @@ add_task(async function test_uninstall_observer() {
|
|||
PromiseDebugging.removeUncaughtRejectionObserver(this);
|
||||
}
|
||||
},
|
||||
onLeftUncaught: function() {
|
||||
onLeftUncaught() {
|
||||
Assert.ok(this._active, "This observer is active.");
|
||||
this.resolve();
|
||||
},
|
||||
onConsumed: function() {
|
||||
onConsumed() {
|
||||
Assert.ok(false, "We should not consume any Promise.");
|
||||
},
|
||||
};
|
||||
|
@ -266,7 +265,3 @@ add_task(async function test_uninstall_observer() {
|
|||
// Normally, `deactivate` should not be notified of the uncaught rejection.
|
||||
wait.active = false;
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче