(obj, prop, expectedValue)
| 9698 | * `tameFauxDataProperty` is not in a position to tell. |
| 9699 | */ |
| 9700 | const tameFauxDataProperty= (obj, prop, expectedValue)=> { |
| 9701 | if( obj=== undefined) { |
| 9702 | // The object does not exist in this version of the platform |
| 9703 | return false; |
| 9704 | } |
| 9705 | const desc= getOwnPropertyDescriptor(obj, prop); |
| 9706 | if( !desc|| 'value'in desc) { |
| 9707 | // The property either doesn't exist, or is already an actual data property. |
| 9708 | return false; |
| 9709 | } |
| 9710 | const { get, set}= desc; |
| 9711 | if( typeof get!== 'function'|| typeof set!== 'function') { |
| 9712 | // A faux data property has both a getter and a setter |
| 9713 | return false; |
| 9714 | } |
| 9715 | if( get()!== expectedValue) { |
| 9716 | // The getter called by itself should produce the expectedValue |
| 9717 | return false; |
| 9718 | } |
| 9719 | if( apply(get, obj, [])!== expectedValue) { |
| 9720 | // The getter called with `this === obj` should also return the |
| 9721 | // expectedValue. |
| 9722 | return false; |
| 9723 | } |
| 9724 | const testValue= 'Seems to be a setter'; |
| 9725 | const subject1= { __proto__: null}; |
| 9726 | apply(set, subject1, [testValue]); |
| 9727 | if( subject1[prop]!== testValue) { |
| 9728 | // The setter called with an unrelated object as `this` should |
| 9729 | // set the property on the object. |
| 9730 | return false; |
| 9731 | } |
| 9732 | const subject2= { __proto__: obj}; |
| 9733 | apply(set, subject2, [testValue]); |
| 9734 | if( subject2[prop]!== testValue) { |
| 9735 | // The setter called on an object that inherits from `obj` should |
| 9736 | // override the property from `obj` as if by assignment. |
| 9737 | return false; |
| 9738 | } |
| 9739 | if( !throws(()=> apply(set, obj, [expectedValue]))) { |
| 9740 | // The setter called with `this === obj` should throw without having |
| 9741 | // caused any effect. |
| 9742 | // This is the test that has the greatest danger of leaving behind some |
| 9743 | // persistent side effect. The most obvious one is to emulate a |
| 9744 | // successful assignment to the property. That's why this test |
| 9745 | // uses `expectedValue`, so that case is likely not to actually |
| 9746 | // change anything. |
| 9747 | return false; |
| 9748 | } |
| 9749 | if( 'originalValue'in get) { |
| 9750 | // The ses-shim uniquely, as far as we know, puts an `originalValue` |
| 9751 | // property on the getter, so that reflect property tranversal algorithms, |
| 9752 | // like `harden`, will traverse into the enulated value without |
| 9753 | // calling the getter. That does not happen until `permits-intrinsics.js` |
| 9754 | // which is much later. So if we see one this early, we should |
| 9755 | // not assume we understand what's going on. |
| 9756 | return false; |
| 9757 | } |
no test coverage detected