Last active
June 28, 2017 20:27
-
-
Save rektide/569dfe16be465eb296abd4b3e6c4f5be to your computer and use it in GitHub Desktop.
monkeypatch tracking origins onto Promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var promiseSource = new WeakMap() | |
(function(){ | |
const promiseConstructor = Promise.constructor | |
Promise.constructor = function(fn){ | |
console.log("monkeypatch successful") | |
promiseConstructor.call(this, fn) | |
promiseSource.set(this, new Error().stack) | |
} | |
}()) | |
var sample = new Promise(x => x(42)) // expecting: "monkeypatch successful" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment