File: proxy-getOwnPropertyDescriptor.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (126 lines) | stat: -rw-r--r-- 4,253 bytes parent folder | download | duplicates (18)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>getOwnPropertyDescriptor() is correct for Proxy with host object target</title>
  <link rel="help" href="https://html.spec.whatwg.org/multipage/#window">
  <link rel="help" href="https://webidl.spec.whatwg.org/#Unforgeable">
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
'use strict';

const assert_accessor_descriptor_equals = (actual, expected) => {
  assert_equals(actual.get, expected.get, 'get');
  assert_equals(actual.set, expected.set, 'set');
  assert_equals(actual.enumerable, expected.enumerable, 'enumerable');
  assert_equals(actual.configurable, expected.configurable, 'configurable');
};

const assert_data_descriptor_equals = (actual, expected) => {
  assert_equals(actual.value, expected.value, 'value');
  assert_equals(actual.writable, expected.writable, 'writable');
  assert_equals(actual.enumerable, expected.enumerable, 'enumerable');
  assert_equals(actual.configurable, expected.configurable, 'configurable');
};

test(() => {
  const windowProxy = new Proxy(window, {});
  name = 'old_name';
  const descriptor = Object.getOwnPropertyDescriptor(windowProxy, 'name');

  assert_equals(descriptor.get.call(window), 'old_name');
  descriptor.set.call(window, 'new_name');
  assert_equals(name, 'new_name');
  assert_true(descriptor.enumerable);
  assert_true(descriptor.configurable);
}, 'Window target, no trap, "name" attribute');

test(() => {
  let trapCalls = 0;
  const windowProxy = new Proxy(window, {
    getOwnPropertyDescriptor(...args) {
      trapCalls++;
      return Reflect.getOwnPropertyDescriptor(...args);
    },
  });

  assert_accessor_descriptor_equals(
    Object.getOwnPropertyDescriptor(windowProxy, 'document'),
    Object.getOwnPropertyDescriptor(window, 'document')
  );
  assert_equals(trapCalls, 1);
}, 'Window target, forwarding trap, [LegacyUnforgeable] "document" attribute');

test(() => {
  const trapResult = {get() {}, set(_val) {}, enumerable: false, configurable: true};
  const windowProxy = new Proxy(new Proxy(window, {}), {
    getOwnPropertyDescriptor: () => trapResult,
  });

  assert_accessor_descriptor_equals(
    Object.getOwnPropertyDescriptor(windowProxy, 'onclick'),
    trapResult
  );
}, 'Window proxy target, custom trap, "onclick" event handler attribute');

test(() => {
  let trapCalls = 0;
  const documentProxy = new Proxy(document, {
    getOwnPropertyDescriptor(...args) {
      trapCalls++;
      return Reflect.getOwnPropertyDescriptor(...args);
    },
  });

  assert_accessor_descriptor_equals(
    Object.getOwnPropertyDescriptor(documentProxy, 'location'),
    Object.getOwnPropertyDescriptor(document, 'location')
  );
  assert_equals(trapCalls, 1);
}, 'Document target, forwarding trap, [LegacyUnforgeable] "location" attribute');

test(() => {
  const trapResult = {value: 4, writable: false, enumerable: true, configurable: true};
  const documentProxy = new Proxy(new Proxy(document, {}), {
    getOwnPropertyDescriptor: () => trapResult,
  });

  assert_data_descriptor_equals(
    Object.getOwnPropertyDescriptor(documentProxy, 'foo'),
    trapResult
  );
}, 'Document proxy target, custom trap, non-existent value attribute');

test(() => {
  const locationProxy = new Proxy(location, {});
  location.hash = '#old';
  const descriptor = Object.getOwnPropertyDescriptor(locationProxy, 'hash');

  assert_equals(descriptor.get.call(location), '#old');
  descriptor.set.call(location, '#new');
  assert_equals(location.hash, '#new');
  assert_true(descriptor.enumerable);
  assert_false(descriptor.configurable);
}, 'Location target, no trap, [LegacyUnforgeable] "hash" attribute');

test(() => {
  let trapCalls = 0;
  const locationProxy = new Proxy(new Proxy(location, {}), {
    getOwnPropertyDescriptor(...args) {
      trapCalls++;
      return Reflect.getOwnPropertyDescriptor(...args);
    },
  });

  assert_data_descriptor_equals(
    Object.getOwnPropertyDescriptor(locationProxy, 'reload'),
    Object.getOwnPropertyDescriptor(location, 'reload')
  );
  assert_equals(trapCalls, 1);
}, 'Location proxy target, forwarding trap, [LegacyUnforgeable] "reload" method');
</script>
</body>
</html>