Skip to content

Commit

Permalink
Detecting a Promise bug in v8 (node 0.11 and 0.12).
Browse files Browse the repository at this point in the history
v8 bug: https://code.google.com/p/chromium/issues/detail?id=371021
examples: https://gist.github.com/getify/bd11ccf1eff2efdac0fb

The test isn't currently a failing test, because the v8 Promise implementation doesn't support subclassing, which we already detect - but this way we'll explicitly detect both bugs.
  • Loading branch information
ljharb committed May 17, 2014
1 parent 4942990 commit e1436c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
13 changes: 11 additions & 2 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1411,9 +1411,18 @@
// In Chrome 33 (and thereabouts) Promise is defined, but the
// implementation is buggy in a number of ways. Let's check subclassing
// support to see if we have a buggy implementation.
if (!supportsSubclassing(globals.Promise, function(S) {
var promiseSupportsSubclassing = supportsSubclassing(globals.Promise, function(S) {
return S.resolve(42) instanceof S;
})) {
});
var promiseIgnoresNonFunctionThenCallbacks = (function () {
try {
Promise.reject(42).then(null,5).then(null, function () {});
return true;
} catch (ex) {
return false;
}
}());
if (!promiseSupportsSubclassing || !promiseIgnoresNonFunctionThenCallbacks) {
globals.Promise = PromiseShim;
}

Expand Down
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="math.js"></script>
<script src="number.js"></script>
<script src="object.js"></script>
<script src="promise.js"></script>
<script src="string.js"></script>
<script src="worker-test.js"></script>
<script src="promise/all.js"></script>
Expand Down
10 changes: 10 additions & 0 deletions test/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* This file is for testing implementation regressions of Promises. */

describe('Promise', function () {
it('ignores non-function .then arguments', function () {
expect(function () {
Promise.reject(42).then(null,5).then(null, function () {});
}).not.to.throw();
});
});

1 change: 1 addition & 0 deletions testling.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script src="test/math.js"></script>
<script src="test/number.js"></script>
<script src="test/object.js"></script>
<script src="test/promise.js"></script>
<script src="test/string.js"></script>
<script src="test/promise/all.js"></script>
<script src="test/promise/evil-promises.js"></script>
Expand Down

0 comments on commit e1436c9

Please sign in to comment.