mirror of
				https://github.com/tc39/test262.git
				synced 2025-10-31 11:44:31 +01:00 
			
		
		
		
	Proxy: get
This commit is contained in:
		
							parent
							
								
									54e82687d7
								
							
						
					
					
						commit
						21a1fbe68e
					
				
							
								
								
									
										36
									
								
								test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,36 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     if trap result is not undefined, then proxy must report the same value for a | ||||||
|  |     non-configurable accessor property with an undefined get. | ||||||
|  | info: > | ||||||
|  |     13. If targetDesc is not undefined, then | ||||||
|  |         b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] | ||||||
|  |         is false and targetDesc.[[Get]] is undefined, then | ||||||
|  |             i. If trapResult is not undefined, throw a TypeError exception. | ||||||
|  | 
 | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = {}; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 2; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | Object.defineProperty(target, 'attr', { | ||||||
|  |     configurable: false, | ||||||
|  |     get: undefined | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p.attr; | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p['attr']; | ||||||
|  | }); | ||||||
							
								
								
									
										41
									
								
								test/built-ins/Proxy/get/call-parameters.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								test/built-ins/Proxy/get/call-parameters.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     9. Let trapResult be Call(trap, handler, «target, P, Receiver»). | ||||||
|  | info: > | ||||||
|  |     6.1.7.2 Object Internal Methods and Internal Slots | ||||||
|  | 
 | ||||||
|  |     (...) Receiver is used as the this value when evaluating the code | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var _target, _handler, _prop, _receiver; | ||||||
|  | var target = { | ||||||
|  |     attr: 1 | ||||||
|  | }; | ||||||
|  | var handler = { | ||||||
|  |     get: function(t, prop, receiver) { | ||||||
|  |         _handler = this; | ||||||
|  |         _target = t; | ||||||
|  |         _prop = prop; | ||||||
|  |         _receiver = receiver; | ||||||
|  |     } | ||||||
|  | }; | ||||||
|  | var p = new Proxy(target, handler); | ||||||
|  | 
 | ||||||
|  | p.attr; | ||||||
|  | 
 | ||||||
|  | assert.sameValue(_handler, handler); | ||||||
|  | assert.sameValue(_target, target); | ||||||
|  | assert.sameValue(_prop, "attr"); | ||||||
|  | assert.sameValue(_receiver, p, "receiver is the Proxy object"); | ||||||
|  | 
 | ||||||
|  | _prop = null; | ||||||
|  | p["attr"]; | ||||||
|  | assert.sameValue( | ||||||
|  |     _prop, "attr", | ||||||
|  |     "trap is triggered both by p.attr and p['attr']" | ||||||
|  | ); | ||||||
| @ -0,0 +1,37 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     Throws if proxy return has not the same value for a non-writable, | ||||||
|  |     non-configurable property | ||||||
|  | info: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     13. If targetDesc is not undefined, then | ||||||
|  |         a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is | ||||||
|  |         false and targetDesc.[[Writable]] is false, then | ||||||
|  |             i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a | ||||||
|  |             TypeError exception. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = {}; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 2; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | Object.defineProperty(target, 'attr', { | ||||||
|  |     configurable: false, | ||||||
|  |     writable: false, | ||||||
|  |     value: 1 | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p.attr; | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p['attr']; | ||||||
|  | }); | ||||||
							
								
								
									
										21
									
								
								test/built-ins/Proxy/get/null-handler.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								test/built-ins/Proxy/get/null-handler.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     2. If handler is null, throw a TypeError exception. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var p = Proxy.revocable({}, {}); | ||||||
|  | 
 | ||||||
|  | p.revoke(); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p.proxy.attr; | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p.proxy['attr']; | ||||||
|  | }); | ||||||
							
								
								
									
										27
									
								
								test/built-ins/Proxy/get/return-is-abrupt.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								test/built-ins/Proxy/get/return-is-abrupt.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     Trap returns abrupt. | ||||||
|  | info: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     9. Let trapResult be Call(trap, handler, «target, P, Receiver»). | ||||||
|  |     10. ReturnIfAbrupt(trapResult). | ||||||
|  | includes: [Test262Error.js] | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var p = new Proxy({}, { | ||||||
|  |     get: function() { | ||||||
|  |         throw new Test262Error(); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(Test262Error, function() { | ||||||
|  |     p.attr; | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(Test262Error, function() { | ||||||
|  |     p["attr"]; | ||||||
|  | }); | ||||||
| @ -0,0 +1,25 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     14. Return trapResult. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = {}; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 2; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | Object.defineProperty(target, 'attr', { | ||||||
|  |     get: function() { | ||||||
|  |         return 1; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 2); | ||||||
|  | assert.sameValue(p['attr'], 2); | ||||||
| @ -0,0 +1,25 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     14. Return trapResult. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = {}; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 2; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | Object.defineProperty(target, 'attr', { | ||||||
|  |     configurable: false, | ||||||
|  |     writable: true, | ||||||
|  |     value: 1 | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 2); | ||||||
|  | assert.sameValue(p['attr'], 2); | ||||||
| @ -0,0 +1,24 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     14. Return trapResult. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = {}; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 2; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | Object.defineProperty(target, 'attr', { | ||||||
|  |     configurable: true, | ||||||
|  |     get: undefined | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 2); | ||||||
|  | assert.sameValue(p['attr'], 2); | ||||||
| @ -0,0 +1,25 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     14. Return trapResult. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = {}; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 2; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | Object.defineProperty(target, 'attr', { | ||||||
|  |     configurable: true, | ||||||
|  |     writable: false, | ||||||
|  |     value: 1 | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 2); | ||||||
|  | assert.sameValue(p['attr'], 2); | ||||||
| @ -0,0 +1,34 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     Proxy must report the same value for a non-writable, non-configurable | ||||||
|  |     property. | ||||||
|  | info: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     13. If targetDesc is not undefined, then | ||||||
|  |         a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is | ||||||
|  |         false and targetDesc.[[Writable]] is false, then | ||||||
|  |             i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a | ||||||
|  |             TypeError exception. | ||||||
|  |         ... | ||||||
|  |     14. Return trapResult. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = {}; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 1; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | Object.defineProperty(target, 'attr', { | ||||||
|  |     configurable: false, | ||||||
|  |     writable: false, | ||||||
|  |     value: 1 | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 1); | ||||||
|  | assert.sameValue(p['attr'], 1); | ||||||
							
								
								
									
										24
									
								
								test/built-ins/Proxy/get/return-trap-result.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								test/built-ins/Proxy/get/return-trap-result.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     14. Return trapResult. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = { | ||||||
|  |     attr: 1 | ||||||
|  | }; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: function() { | ||||||
|  |         return 2; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 2); | ||||||
|  | assert.sameValue(p.foo, 2); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p['attr'], 2); | ||||||
|  | assert.sameValue(p['foo'], 2); | ||||||
							
								
								
									
										28
									
								
								test/built-ins/Proxy/get/trap-is-not-callable.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								test/built-ins/Proxy/get/trap-is-not-callable.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     Trap is not callable. | ||||||
|  | info: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     6. Let trap be GetMethod(handler, "get"). | ||||||
|  |     ... | ||||||
|  | 
 | ||||||
|  |     7.3.9 GetMethod (O, P) | ||||||
|  | 
 | ||||||
|  |     5. If IsCallable(func) is false, throw a TypeError exception. | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var p = new Proxy({}, { | ||||||
|  |     get: {} | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p.attr; | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.throws(TypeError, function() { | ||||||
|  |     p["attr"]; | ||||||
|  | }); | ||||||
							
								
								
									
										19
									
								
								test/built-ins/Proxy/get/trap-is-undefined-no-property.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/built-ins/Proxy/get/trap-is-undefined-no-property.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     8. If trap is undefined, then return target.[[Get]](P, Receiver). | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = { | ||||||
|  |     attr: 1 | ||||||
|  | }; | ||||||
|  | var p = new Proxy(target, {}); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 1, 'return target.attr'); | ||||||
|  | assert.sameValue(p.foo, undefined, 'return target.foo'); | ||||||
|  | assert.sameValue(p['attr'], 1, 'return target.attr'); | ||||||
|  | assert.sameValue(p['foo'], undefined, 'return target.foo'); | ||||||
							
								
								
									
										20
									
								
								test/built-ins/Proxy/get/trap-is-undefined.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								test/built-ins/Proxy/get/trap-is-undefined.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | |||||||
|  | // Copyright (C) 2015 the V8 project authors. All rights reserved.
 | ||||||
|  | // This code is governed by the BSD license found in the LICENSE file.
 | ||||||
|  | /*--- | ||||||
|  | es6id: 9.5.8 | ||||||
|  | description: > | ||||||
|  |     [[Get]] (P, Receiver) | ||||||
|  | 
 | ||||||
|  |     8. If trap is undefined, then return target.[[Get]](P, Receiver). | ||||||
|  | 
 | ||||||
|  | ---*/ | ||||||
|  | 
 | ||||||
|  | var target = { | ||||||
|  |     attr: 1 | ||||||
|  | }; | ||||||
|  | var p = new Proxy(target, { | ||||||
|  |     get: undefined | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | assert.sameValue(p.attr, 1, 'return target.attr'); | ||||||
|  | assert.sameValue(p.foo, undefined, 'return target.foo'); | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user