summaryrefslogtreecommitdiff
path: root/test/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-receiver.js
blob: 534177d59ba9a7028a9533d8dcf0ae9260bdd9ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.13
description: >
  Set value on an accessor descriptor property with receiver as `this`.
info: |
  26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] )

  ...
  4. If receiver is not present, then
    a. Let receiver be target.
  5. Return target.[[Set]](key, V, receiver).

  9.1.9 [[Set]] ( P, V, Receiver)

  ...
  6. Assert: IsAccessorDescriptor(ownDesc) is true.
  7. Let setter be ownDesc.[[Set]].
  8. If setter is undefined, return false.
  9. Let setterResult be Call(setter, Receiver, «V»).
  10. ReturnIfAbrupt(setterResult).
  11. Return true.
---*/

var args;
var count = 0
var o1 = {};
var receiver = {};
var _receiver;
Object.defineProperty(o1, 'p', {
  set: function(a) {
    count++;
    args = arguments;
    _receiver = this;
    return false;
  }
});

var result = Reflect.set(o1, 'p', 42, receiver);
assert.sameValue(
  result, true,
  'returns true if target.p has an accessor descriptor'
);
assert.sameValue(args.length, 1, 'target.p set is called with 1 argument');
assert.sameValue(args[0], 42, 'target.p set is called with V');
assert.sameValue(count, 1, 'target.p set is called once');
assert.sameValue(
  _receiver, receiver,
  'target.p set is called with receiver as `this`'
);