summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Proxy/defineProperty/targetdesc-not-configurable-writable-desc-not-writable.js
blob: 902c835c0418a4bf1b5cc50a7fc19a43f88a4443 (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
// Copyright (C) 2019 Aleksey 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-defineownproperty-p-desc
description: >
    Throw a TypeError exception if trap result is true, targetDesc is not configurable
    and writable, while Desc is not writable.
info: |
    [[DefineOwnProperty]] (P, Desc)

    ...
    16. Else targetDesc is not undefined,
        ...
        c. If IsDataDescriptor(targetDesc) is true, targetDesc.[[Configurable]] is
        false, and targetDesc.[[Writable]] is true, then
            i. If Desc has a [[Writable]] field and Desc.[[Writable]] is
            false, throw a TypeError exception.
    ...
features: [Proxy, Reflect, proxy-missing-checks]
---*/

var trapCalls = 0;
var p = new Proxy({}, {
  defineProperty: function(t, prop, desc) {
    Object.defineProperty(t, prop, {
      configurable: false,
      writable: true,
    });

    trapCalls++;
    return true;
  },
});

assert.throws(TypeError, function() {
  Reflect.defineProperty(p, "prop", {
    writable: false,
  });
});
assert.sameValue(trapCalls, 1);

reportCompare(0, 0);