Skip to content

Instantly share code, notes, and snippets.

@rektide
Last active June 28, 2017 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rektide/569dfe16be465eb296abd4b3e6c4f5be to your computer and use it in GitHub Desktop.
Save rektide/569dfe16be465eb296abd4b3e6c4f5be to your computer and use it in GitHub Desktop.
monkeypatch tracking origins onto Promise
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