Skip to content

Commit

Permalink
Remove nonstandard Promise.prototype.done implementation
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[General][Breaking] - Remove nonstandard Promise.prototype.done

`Promise.prototype.done` has been deprecated since D34222667 (3580096). Here we remove it from React Native's default Promise polyfill. Users should switch to using standard Promise features like `.then()`, or install their own custom polyfills for advanced use cases.

Reviewed By: kodafb

Differential Revision: D36001688

fbshipit-source-id: 37f452000c16279280ef6a50b2ce616776377c4e
  • Loading branch information
motiz88 authored and facebook-github-bot committed May 5, 2022
1 parent 20d9d3a commit 018d5cf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
32 changes: 0 additions & 32 deletions Libraries/Core/polyfillPromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'use strict';

const {polyfillGlobal} = require('../Utilities/PolyfillFunctions');
const warnOnce = require('../Utilities/warnOnce');

/**
* Set up Promise. The native Promise implementation throws the following error:
Expand All @@ -37,34 +36,3 @@ if (global?.HermesInternal?.hasPromise?.()) {
} else {
polyfillGlobal('Promise', () => require('../Promise'));
}

if (__DEV__) {
// $FlowFixMe
const done = Promise.prototype.done;
if (done != null) {
let depth = 0;
/* eslint-disable no-extend-native */
// $FlowFixMe
Promise.prototype.done = function () {
++depth;
try {
// Avoid infinite recursion if done() happens to be triggered by warnOnce.
if (depth === 1) {
// Warn once per unique call stack. Not super efficient, but we're in
// __DEV__ and .done() calls are rare to begin with.
const key = new Error().stack;
warnOnce(
key,
'Promise.prototype.done(): This nonstandard polyfill ' +
'has been deprecated and will be removed in a future release. ' +
'Please instead use `.then()`.',
);
}
} finally {
--depth;
}
return done.apply(this, arguments);
};
/* eslint-enable no-extend-native */
}
}
1 change: 0 additions & 1 deletion Libraries/Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

const Promise = require('promise/setimmediate/es6-extensions');

require('promise/setimmediate/done');
require('promise/setimmediate/finally');

if (__DEV__) {
Expand Down

0 comments on commit 018d5cf

Please sign in to comment.