Bug 207297 - [JSC] Computed function properties compute their keys twice
Summary: [JSC] Computed function properties compute their keys twice
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ross Kirsling
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-02-05 14:43 PST by Ross Kirsling
Modified: 2020-02-18 12:02 PST (History)
10 users (show)

See Also:


Attachments
Patch (8.19 KB, patch)
2020-02-08 16:10 PST, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (13.87 KB, patch)
2020-02-10 13:53 PST, Ross Kirsling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Kirsling 2020-02-05 14:43:25 PST
Basic repro:

    ```
    let count1 = 0;
    let key1 = { toString() { count1++; return 'foo'; } };
    ({ [key1]: 'bar' });

    let count2 = 0;
    let key2 = { toString() { count2++; return 'foo'; } };
    ({ [key2]() { return 'bar'; } });

    print(count1, count2);
    ```

    λ eshost -s test.js
    #### ch, sm, v8, xs
    1 1

    #### jsc
    1 2

Notes:

- This also reproes if:
  - we write the function property as `[key]: function () { return 'bar'; }` or `[key]: () => 'bar'` instead
  - we set toString to null and use valueOf instead

- Relevant test262 failures:
  https://github.com/tc39/test262/blob/master/test/language/computed-property-names/to-name-side-effects/class.js
  https://github.com/tc39/test262/blob/master/test/language/computed-property-names/to-name-side-effects/numbers-class.js
  https://github.com/tc39/test262/blob/master/test/language/computed-property-names/to-name-side-effects/object.js

- Bug 170934 seems related but separate.
Comment 1 Ross Kirsling 2020-02-08 16:10:42 PST
Created attachment 390185 [details]
Patch
Comment 2 Ross Kirsling 2020-02-10 11:33:15 PST
Comment on attachment 390185 [details]
Patch

The current approach is very simple but incurs a ToPropertyKey instruction even for non-function computed properties.

I suppose it would be better to split emitSetFunctionNameIfNeeded into needsSetFunctionName and emitSetFunctionName so that this can be avoided.
Comment 3 Ross Kirsling 2020-02-10 13:53:24 PST
Created attachment 390291 [details]
Patch
Comment 4 Ross Kirsling 2020-02-18 10:28:54 PST
Ping?
Comment 5 Keith Miller 2020-02-18 11:11:11 PST
Comment on attachment 390291 [details]
Patch

r=me.
Comment 6 WebKit Commit Bot 2020-02-18 12:01:26 PST
Comment on attachment 390291 [details]
Patch

Clearing flags on attachment: 390291

Committed r256846: <https://trac.webkit.org/changeset/256846>
Comment 7 WebKit Commit Bot 2020-02-18 12:01:27 PST
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2020-02-18 12:02:21 PST
<rdar://problem/59559881>