proxy-polyfill icon indicating copy to clipboard operation
proxy-polyfill copied to clipboard

throw TypeError in strict mode if set trap doesn't return true

Open samthor opened this issue 8 years ago • 3 comments

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.

samthor avatar Mar 27 '16 00:03 samthor

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'.

Nathan-Schwartz avatar Nov 02 '16 15:11 Nathan-Schwartz

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.

samthor avatar Oct 17 '19 11:10 samthor

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.


See https://github.com/claudepache/es-legacy-function-reflection/blob/master/analysis.md#value-returned-by-caller-per-type-of-the-purported-caller

ExE-Boss avatar Jul 01 '20 13:07 ExE-Boss