Created
January 24, 2014 22:55
-
-
Save bterlson/8608516 to your computer and use it in GitHub Desktop.
This file contains 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
function assertOrderOfOps(act, exp) { | |
exp.forEach(function(e, i) { | |
if(act[i][0] !== exp[i][0] || act[i][1] !== exp[i][1]) { | |
throw new Error('Expected operation ' + i + ' to be ' + exp[i] + ' but was ' + act[i]); | |
} | |
}); | |
if(act.length > exp.length) { | |
throw new Error('More operations than expected: ' + | |
act.slice(exp.length).map(function(e) { return e[0] }) | |
); | |
} | |
} | |
function createLoggerProxy(obj) { | |
var ops = []; | |
var proxy = new Proxy(obj, new Proxy({}, { | |
get: function(o, v, r) { | |
return function() { | |
ops.push([v, arguments[1]]); | |
return Reflect[v].apply(this, arguments); | |
} | |
} | |
})) | |
return { | |
log: ops, | |
proxy: proxy | |
} | |
} |
Brian,
Based upon spec bug reports I've received, I think the Chrome guys may already be using something like this
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example test case (can run in firefox with tvcutsem's Reflect polyfill script included):
Small snippet to include the polyfill in your current context: