proxy-polyfill
proxy-polyfill copied to clipboard
throw TypeError in strict mode if set trap doesn't return true
See MDN.
This code will work inside the calling code, but that's not really what we want:
let strictMode = (function() { return !this; })();
For eager contributors: I want to point out that we need to work out whether the caller is in strict mode (not the proxy code itself). This is possible under some very limited circumstances, but not always. I suspect this issue is unsolvable.
I can give it a shot. I plan to use the same strictMode check that @samthor posted. I am not aware of any edge cases where it would fail, but I could be mistaken.
I noticed that the specs don't seem to define a specific TypeError message for this case. Any preference there? I'm imagining something along the lines of 'handler.set: Assignment failed in strict mode'.
Working out whether the caller is in strict mode is never going to happen.
I'd probably add an option to the polyfill constructor to run in strict mode, to throw an Error if there's a problem.
There’s a possible way to do this using setter.caller
, which throws or returns null
if the caller is strict mode code or an async or generator function.