-
-
Notifications
You must be signed in to change notification settings - Fork 184
Closed
Description
Problem in brief
Properties of window.location are not enumerated by methods such as Object.keys(), Object.entries(), Oject.getOwnPropertyNames() but are when location.__proto__ is queried instead.
Reproducing
Below code shows expected behaviour (tested in Chrome, Firefox, Edge) and that of HtmlUnit 2.66.
<!DOCTYPE html>
<html>
<head>
<script>
// Expected: [href,origin,protocol,host,hostname,port,pathname,search,hash,assign,replace,reload,toString]
// HtmlUnit 2.66: []
console.log(Object.keys(location));
// Expected: []
// HtmlUnit 2.66: [search,hostname,protocol,port,origin,host,href,hash,pathname,reload,replace,toString,assign]
console.log(Object.keys(location.__proto__))
</script>
</head>
<body>
</body>
</html>- FWIW, in IE it was enumerated in both cases.
More details
This practical consequence of this issue and the site it was discovered was using code like this:
let abc = {}
console.log(Object.assign(abc, location).href)The issue is complicated by the fact this expected behaviour seems more or less specific to window.location. For other properties such as those under window.screen the way HtmlUnit behaves is the expected:
<!DOCTYPE html>
<html>
<head>
<script>
// Expected: []
// HtmlUnit 2.66: []
console.log(Object.keys(screen));
// Expected: [availWidth, availHeight, width, height, colorDepth, pixelDepth, availLeft, availTop, orientation, onchange, isExtended]
// HtmlUnit 2.66: [orientation, onchange, availLeft, availWidth, pixelDepth, top, left, availTop, width, colorDepth, mozOrientation, height, availHeight]
console.log(Object.keys(screen.__proto__))
</script>
</head>
<body>
</body>
</html>duonglaiquang and Claudemirovsky
Metadata
Metadata
Assignees
Labels
No labels