trap-is-missing-target-is-proxy.js (1206B)
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver 6 description: > 7 If "set" trap is null or undefined, [[Set]] call is properly 8 forwarded to [[ProxyTarget]] (which is also a Proxy object). 9 info: | 10 [[Set]] ( P, V, Receiver ) 11 12 [...] 13 5. Let target be O.[[ProxyTarget]]. 14 6. Let trap be ? GetMethod(handler, "set"). 15 7. If trap is undefined, then 16 a. Return ? target.[[Set]](P, V, Receiver). 17 features: [Proxy, Reflect] 18 ---*/ 19 20 var barValue; 21 var plainObject = { 22 get foo() {}, 23 set bar(value) { 24 barValue = value; 25 }, 26 }; 27 28 var plainObjectTarget = new Proxy(plainObject, {}); 29 var plainObjectProxy = new Proxy(plainObjectTarget, {}); 30 31 plainObjectProxy.bar = 1; 32 assert.sameValue(barValue, 1); 33 34 assert.throws(TypeError, function() { 35 "use strict"; 36 plainObjectProxy.foo = 2; 37 }); 38 39 40 var regExp = /(?:)/g; 41 var regExpTarget = new Proxy(regExp, {}); 42 var regExpProxy = new Proxy(regExpTarget, {}); 43 44 assert(!Reflect.set(regExpProxy, "global", true)); 45 46 regExpProxy.lastIndex = 1; 47 assert.sameValue(regExp.lastIndex, 1); 48 49 reportCompare(0, 0);