Bug 203957 - Getters on global are not invoked with global as this
Summary: Getters on global are not invoked with global as this
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 13
Hardware: Mac macOS 10.14
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-07 08:31 PST by Mariusz Nowak
Modified: 2019-11-12 12:09 PST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mariusz Nowak 2019-11-07 08:31:45 PST
Test case:

```
window = this;

(function() { // based on https://mathiasbynens.be/notes/globalthis
  'use strict';
  Object.defineProperty(Object.prototype, '__magic__', {
    get: function() { return this; }
  });
  print('Is __magic__ a global', __magic__ === window);
  print('Is window.__magic__ a global', window.__magic__ === window);
}());
```

eshost-cli output:

$ eshost -s test.js
#### Chakra, SpiderMonkey, V8, V8 --harmony, XS
Is __magic__ a global true
Is window.__magic__ a global true

#### JavaScriptCore
Is __magic__ a global false
Is window.__magic__ a global true
Comment 1 Mathias Bynens 2019-11-07 09:17:32 PST
Looping in some JSC folks. Note that JSC’s behavior differs from other JS engines here. Does this seem like something you’d want to change?
Comment 2 Ross Kirsling 2019-11-07 10:34:41 PST
Is there a test262 case for this?
Comment 3 Jordan Harband 2019-11-08 11:02:11 PST
I'm a bit confused; `window.__proto__ !== Object.prototype`, so why would `__magic__` be a global variable at all?
Comment 4 Mariusz Nowak 2019-11-12 01:04:51 PST
Object.prototype.isPrototypeOf(window) === true
Comment 5 Jordan Harband 2019-11-12 09:44:08 PST
ah, `window.__proto__.__proto__.__proto__.__proto__ === Object.prototype` - thanks for helping me understand :-)
Comment 6 Keith Miller 2019-11-12 10:04:29 PST
I'm not sure how hard this is to change... could be anywhere from trivial to a huge rewrite. We should probably do it though since every other engine does it.
Comment 7 Ross Kirsling 2019-11-12 10:46:00 PST
Note that this divergence only exists in strict mode -- all implementations do the same thing in sloppy mode.
Comment 8 Mariusz Nowak 2019-11-12 12:09:41 PST
Ross, in sloppy mode outcome is same, but I guess only because `this` in functions run without a context resolves to global

So whether getter context is resolved as expected or not, doesn't make result any different.