mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 21:45:04 +02:00
Improve Proxy/set call parameters coverage (#2347)
* Tweak front matter of basic test * Simplify basic test * Add test for proxy as prototype * Add test for proxy as prototype and __proto__
This commit is contained in:
parent
ff83fb2922
commit
256f5f4b46
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver
|
||||||
|
description: >
|
||||||
|
Ordinary [[Set]] forwards call to Proxy "set" trap with correct arguments.
|
||||||
|
Property name is "__proto__".
|
||||||
|
info: |
|
||||||
|
OrdinarySet ( O, P, V, Receiver )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).
|
||||||
|
|
||||||
|
OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
|
||||||
|
|
||||||
|
...
|
||||||
|
2. If ownDesc is undefined, then
|
||||||
|
a. Let parent be ? O.[[GetPrototypeOf]]().
|
||||||
|
b. If parent is not null, then
|
||||||
|
i. Return ? parent.[[Set]](P, V, Receiver).
|
||||||
|
|
||||||
|
[[Set]] ( P, V, Receiver )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, V, Receiver »)).
|
||||||
|
...
|
||||||
|
12. Return true.
|
||||||
|
features: [Proxy]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var _handler, _target, _prop, _value, _receiver;
|
||||||
|
var target = {};
|
||||||
|
var handler = {
|
||||||
|
set: function(target, prop, value, receiver) {
|
||||||
|
_handler = this;
|
||||||
|
_target = target;
|
||||||
|
_prop = prop;
|
||||||
|
_value = value;
|
||||||
|
_receiver = receiver;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
var proxy = new Proxy(target, handler);
|
||||||
|
var receiver = Object.create(proxy);
|
||||||
|
var prop = '__proto__';
|
||||||
|
var value = {};
|
||||||
|
|
||||||
|
receiver[prop] = value;
|
||||||
|
|
||||||
|
assert.sameValue(_handler, handler, 'handler object is the trap context');
|
||||||
|
assert.sameValue(_target, target, 'first argument is the target object');
|
||||||
|
assert.sameValue(_prop, prop, 'second argument is the property name');
|
||||||
|
assert.sameValue(_value, value, 'third argument is the new value');
|
||||||
|
assert.sameValue(_receiver, receiver, 'fourth argument is the receiver object');
|
52
test/built-ins/Proxy/set/call-parameters-prototype.js
Normal file
52
test/built-ins/Proxy/set/call-parameters-prototype.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver
|
||||||
|
description: >
|
||||||
|
Ordinary [[Set]] forwards call to Proxy "set" trap with correct arguments.
|
||||||
|
info: |
|
||||||
|
OrdinarySet ( O, P, V, Receiver )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).
|
||||||
|
|
||||||
|
OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
|
||||||
|
|
||||||
|
...
|
||||||
|
2. If ownDesc is undefined, then
|
||||||
|
a. Let parent be ? O.[[GetPrototypeOf]]().
|
||||||
|
b. If parent is not null, then
|
||||||
|
i. Return ? parent.[[Set]](P, V, Receiver).
|
||||||
|
|
||||||
|
[[Set]] ( P, V, Receiver )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, V, Receiver »)).
|
||||||
|
...
|
||||||
|
12. Return true.
|
||||||
|
features: [Proxy]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var _handler, _target, _prop, _value, _receiver;
|
||||||
|
var target = {};
|
||||||
|
var handler = {
|
||||||
|
set: function(target, prop, value, receiver) {
|
||||||
|
_handler = this;
|
||||||
|
_target = target;
|
||||||
|
_prop = prop;
|
||||||
|
_value = value;
|
||||||
|
_receiver = receiver;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
var proxy = new Proxy(target, handler);
|
||||||
|
var receiver = Object.create(proxy);
|
||||||
|
|
||||||
|
receiver.prop = 'value';
|
||||||
|
|
||||||
|
assert.sameValue(_handler, handler, 'handler object is the trap context');
|
||||||
|
assert.sameValue(_target, target, 'first argument is the target object');
|
||||||
|
assert.sameValue(_prop, 'prop', 'second argument is the property name');
|
||||||
|
assert.sameValue(_value, 'value', 'third argument is the new value');
|
||||||
|
assert.sameValue(_receiver, receiver, 'fourth argument is the receiver object');
|
@ -1,13 +1,16 @@
|
|||||||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
es6id: 9.5.9
|
esid: sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver
|
||||||
description: >
|
description: >
|
||||||
[[Set]] ( P, V, Receiver)
|
Proxy "set" trap is called with correct arguments.
|
||||||
|
info: |
|
||||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V,
|
[[Set]] ( P, V, Receiver )
|
||||||
Receiver»)).
|
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, V, Receiver »)).
|
||||||
|
...
|
||||||
|
12. Return true.
|
||||||
features: [Proxy]
|
features: [Proxy]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
@ -20,7 +23,7 @@ var handler = {
|
|||||||
_prop = prop;
|
_prop = prop;
|
||||||
_value = value;
|
_value = value;
|
||||||
_receiver = receiver;
|
_receiver = receiver;
|
||||||
return t[prop] = value;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var p = new Proxy(target, handler);
|
var p = new Proxy(target, handler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user