-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core,ext): Fix not to be affected by Promise.prototype.then
#16326
Conversation
ee43201
to
171405d
Compare
It seems that if I rewrite |
I ran the following file and had no problem. It seems that the problem is not with console.log("start");
const original = Promise.prototype.then;
Promise.prototype.then = function () {
console.log("bang!");
return original.apply(this, arguments);
};
await new Promise((resolve) => setTimeout(resolve, 100));
console.log("end"); |
// Wrapping on a new Promise is necessary to not expose the SafePromise | ||
// prototype to user-land. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it unsafe to expose SafePromise.prototype
to user-land? I think it can't be modified even if it's exposed because it's frozen. (I might be missing something...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation is referenced from SafePromisePrototypeFinally
. I think it is meant to prevent the internal code from being strangely utilized in user-land.
Lines 439 to 455 in 45ac6e6
/** | |
* Attaches a callback that is invoked when the Promise is settled (fulfilled or | |
* rejected). The resolved value cannot be modified from the callback. | |
* Prefer using async functions when possible. | |
* @param {Promise<any>} thisPromise | |
* @param {() => void) | undefined | null} onFinally The callback to execute | |
* when the Promise is settled (fulfilled or rejected). | |
* @returns A Promise for the completion of the callback. | |
*/ | |
primordials.SafePromisePrototypeFinally = (thisPromise, onFinally) => | |
// Wrapping on a new Promise is necessary to not expose the SafePromise | |
// prototype to user-land. | |
new Promise((a, b) => | |
new SafePromise((a, b) => PromisePrototypeThen(thisPromise, a, b)) | |
.finally(onFinally) | |
.then(a, b) | |
); |
Can you add some integration test cases that modify |
d47cabe
to
b2e5f80
Compare
@kt3k I added tests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
While I think the usages of |
Great to see it's landed! Is it also good to have some lint rule to enforce (or at least make developers be aware of) the use of these new |
That makes sense to me. |
Yeah that's true. My rudimentary idea is that we have the linter check for all |
Opened an issue for deno_lint denoland/deno_lint#1095 |
fix #16196