Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Fix Promise.prototype.catch closure issue
Browse files Browse the repository at this point in the history
Manually import ES6Promise polyfill and closure export `catch` function
Fixes #837
  • Loading branch information
dfreedm committed Sep 11, 2017
1 parent 7a7f8d6 commit 7f09cdc
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 112 deletions.
2 changes: 1 addition & 1 deletion entrypoints/webcomponents-hi-sd-ce-pf-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN

import '../node_modules/@webcomponents/webcomponents-platform/webcomponents-platform.js';
import '../node_modules/@webcomponents/template/template.js';
import '../node_modules/es6-promise/lib/es6-promise.auto.js';
import '../src/promise.js';
import '../node_modules/@webcomponents/html-imports/src/html-imports.js';
import '../src/pre-polyfill.js';
import '../node_modules/@webcomponents/shadydom/src/shadydom.js';
Expand Down
20 changes: 20 additions & 0 deletions src/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
'use strict';
import ES6Promise from '../node_modules/es6-promise/lib/es6-promise.js';

/*
Assign the ES6 promise polyfill to window ourselves instead of using the "auto" polyfill
to work around https://github.com/webcomponents/webcomponentsjs/issues/837
*/
if (!window.Promise) {
window.Promise = ES6Promise;
ES6Promise.prototype['catch'] = ES6Promise.prototype.catch;
}
27 changes: 27 additions & 0 deletions tests/promise.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>Test Promise Polyfill</title>
<script>window.Promise = null;</script>
<script src="../webcomponents-loader.js"></script>
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
<script>
suite('Promise', () => {
test('catch works', () => {
return Promise.reject('nope!').catch(() => {});
});
})
</script>
</body>
</html>
3 changes: 2 additions & 1 deletion tests/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// 'ce-upgradedocumenttree.html', // Does not exist in the v1 polyfill
'ce-upgrade-order.html',
// 'ce-import-upgrade.html', // Order of upgrade/import is different in v1
// 'ce-import-upgrade-async.html'
// 'ce-import-upgrade-async.html',
'promise.html'
]);
</script>
Loading

0 comments on commit 7f09cdc

Please sign in to comment.