near-membrane
near-membrane copied to clipboard
Proxy traps to handle `Object` and `Reflect` APIs consistently.
Throwing errors is appropriate for Object methods like Object.defineProperty when run in strict mode code. However, Reflect.defineProperty should return false without throwing an error. The proxy traps need to be constructed in a way to handle this. To solve this in esm I did two things.
- I virtually shimmed the
ReflectAPI to catch errors thrown in their methods and return booleans - I had a way to detect if a call was coming from strict-code using the V8 specific
Error.prepareStackTraceAPI to walk the the stack and detect strict mode code. That's a bit involved and requires punching a sloppy-mode hole into the webpack bundle to get it right.
Since we own the secure realm though we can monkey-patch Reflect to avoid throwing and return booleans.
@jdalton do you think is there anything missing here?
I'll check and report/back close as necessary.
Update:
Ok, so it's still an issue. I'll look into it.
Update:
We can fix this with a Reflect distortion.
@jdalton but Reflect does not go through the membrane because it is an intrinsic. Can you elaborate more on the issue?
Right now because of our proxy traps for defineProperty, set, deleteProperty some Reflect method calls for Reflect.deleteProperty, Reflect.defineProperty, Reflect.set will throw instead of returning false. The distortion would be to catch the error about to be thrown in the reflect method and check to make sure it should else return false.