blob: 43c412ae5a1d789c4e473a837b0e35063198e2c4 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>getOwnPropertyDescriptor() is correct for Proxy with host object target</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script>
'use strict';
test(() => {
let windowProxy = new Proxy(window, {});
name = 'old_name';
let 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 windowProxy = new Proxy(window, {});
assert_object_equals(
Object.getOwnPropertyDescriptor(windowProxy, 'document'),
Object.getOwnPropertyDescriptor(window, 'document')
);
}, 'Window target, forwarding trap, [Unforgeable] "document" attribute');
test(() => {
let trapResult = {get() {}, set(_val) {}, enumerable: false, configurable: true};
let windowProxy = new Proxy(new Proxy(window, {}), {
getOwnPropertyDescriptor: () => trapResult,
});
assert_object_equals(
Object.getOwnPropertyDescriptor(windowProxy, 'onclick'),
trapResult
);
}, 'Window proxy target, custom trap, "onclick" event handler attribute');
test(() => {
let documentProxy = new Proxy(document, {
getOwnPropertyDescriptor: Reflect.getOwnPropertyDescriptor,
});
assert_object_equals(
Object.getOwnPropertyDescriptor(documentProxy, 'location'),
Object.getOwnPropertyDescriptor(document, 'location')
);
}, 'Document target, forwarding trap, [Unforgeable] "location" attribute');
test(() => {
let trapResult = {value: 4, writable: false, enumerable: true, configurable: true};
let documentProxy = new Proxy(new Proxy(document, {}), {
getOwnPropertyDescriptor: () => trapResult,
});
assert_object_equals(
Object.getOwnPropertyDescriptor(documentProxy, 'foo'),
trapResult
);
}, 'Document proxy target, custom trap, non-existent value attribute');
test(() => {
let locationProxy = new Proxy(location, {});
location.hash = '#old';
let 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, [Unforgeable] "hash" attribute');
test(() => {
let locationProxy = new Proxy(new Proxy(location, {}), {
getOwnPropertyDescriptor: Reflect.getOwnPropertyDescriptor,
});
assert_object_equals(
Object.getOwnPropertyDescriptor(locationProxy, 'reload'),
Object.getOwnPropertyDescriptor(location, 'reload')
);
}, 'Location proxy target, forwarding trap, [Unforgeable] "reload" method');
</script>
</body>
</html>