Bug 158116 - Partly implement Function.prototype.{caller,arguments} reflection proposal
Summary: Partly implement Function.prototype.{caller,arguments} reflection proposal
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Alexey Shvayka
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-05-26 05:09 PDT by Claude Pache
Modified: 2021-07-25 15:33 PDT (History)
13 users (show)

See Also:


Attachments
Patch (62.17 KB, patch)
2021-06-07 17:29 PDT, Alexey Shvayka
no flags Details | Formatted Diff | Diff
Patch (75.00 KB, patch)
2021-06-08 12:32 PDT, Alexey Shvayka
no flags Details | Formatted Diff | Diff
Patch (75.58 KB, patch)
2021-07-03 10:57 PDT, Alexey Shvayka
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Claude Pache 2016-05-26 05:09:24 PDT
According to [ES6 6.7.1.3] Invariants of the Essential Internal Methods:


     If a property P is described as a data property with Desc.[[Value]] equal to v and Desc.[[Writable]] and Desc.[[Configurable]] are both false, then the SameValue must be returned for the Desc.[[Value]] attribute of the property on all future calls to [[GetOwnProperty]] ( P ).

[ES6 6.7.1.3]: http://www.ecma-international.org/ecma-262/6.0/#sec-invariants-of-the-essential-internal-methods


Testcase against `Function#arguments`

```js
function f() { return Object.getOwnPropertyDescriptor(f, 'arguments'); }
Object.getOwnPropertyDescriptor(f, 'arguments');
// value: null, writable: false, configurable: false
f();
// value: Arguments[], writable: false, configurable: false
```


Testcase against `Function#caller`

```js
function g() { return Object.getOwnPropertyDescriptor(g, 'caller'); }
function h() { return g(); }
Object.getOwnPropertyDescriptor(g, 'caller');
// value: null, writable: false, configurable: false
h();
// value: function h(), writable: false, configurable: false
```


Suggested fix: Use getters.


Similar bug: Bug 151348
Comment 1 Leo Balter 2020-05-29 16:24:13 PDT
I've observed this bug within a non directly related code: 

```
(function() {
  'use strict';
  class Foo {}
  const a = new Proxy(function() {}, { ownKeys() { return Reflect.ownKeys(Foo) } });
  console.log(Object.getOwnPropertySymbols(a));
})(); // strict mode, ok
 
(function() {
  'use sloppy';
  class Foo {}
  const a = new Proxy(function() {}, { ownKeys() { return Reflect.ownKeys(Foo) } });
  console.log(Object.getOwnPropertySymbols(a));
})();
```

The code in sloppy mode breaks in Chrome and Safari because the function object will have non-configurable own properties arguments and caller and the Proxy trap is required to list all non-configurable properties from the Proxy target.
Comment 2 Mark S. Miller 2021-05-07 12:43:30 PDT
Ping. What is the status of this?
Comment 3 Alexey Shvayka 2021-06-07 17:29:59 PDT
Created attachment 430793 [details]
Patch
Comment 4 Alexey Shvayka 2021-06-07 17:41:08 PDT
(In reply to Alexey Shvayka from comment #3)
> Created attachment 430793 [details]
> Patch

                                    r278563                   patch

reflect-own-keys-function       45.4040+-0.8465     ^     21.7507+-0.2064        ^ definitely 2.0875x faster
function-prototype-get          39.7061+-0.9041     ^     35.6181+-0.3754        ^ definitely 1.1148x faster

<geometric>                     42.4357+-0.6210     ^     27.8294+-0.1872        ^ definitely 1.5248x faster
Comment 5 Alexey Shvayka 2021-06-08 12:32:43 PDT
Created attachment 430875 [details]
Patch

Adjust LayoutTests.
Comment 6 Alexey Shvayka 2021-07-03 10:57:13 PDT
Created attachment 432853 [details]
Patch

Adjust put-to-proto-chain-overrides-put.js stress test.
Comment 7 Yusuke Suzuki 2021-07-22 04:49:26 PDT
Comment on attachment 432853 [details]
Patch

r=me
Comment 8 Alexey Shvayka 2021-07-25 15:05:40 PDT
Comment on attachment 432853 [details]
Patch

I appreciate the review!
Comment 9 EWS 2021-07-25 15:32:31 PDT
Committed r280289 (239947@main): <https://commits.webkit.org/239947@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 432853 [details].
Comment 10 Radar WebKit Bug Importer 2021-07-25 15:33:19 PDT
<rdar://problem/81083194>