Bug 143181 - class methods should be non-enumerable
Summary: class methods should be non-enumerable
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
: 143246 (view as bug list)
Depends on:
Blocks: 140491
  Show dependency treegraph
 
Reported: 2015-03-28 01:46 PDT by Ryosuke Niwa
Modified: 2015-04-25 15:04 PDT (History)
7 users (show)

See Also:


Attachments
WIP (17.28 KB, patch)
2015-04-01 02:49 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WIP2 (18.72 KB, patch)
2015-04-02 23:20 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixes the bug (30.85 KB, patch)
2015-04-12 03:22 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Updated for ToT (34.90 KB, patch)
2015-04-20 16:25 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed Windows build (35.36 KB, patch)
2015-04-22 14:39 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Another attempt to fix Windows build (35.32 KB, patch)
2015-04-22 21:50 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed Windows build for good; fuck off cl.exe (35.37 KB, patch)
2015-04-23 03:36 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Yet another Win build fix; fuck cl.exe (36.10 KB, patch)
2015-04-23 12:33 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed builds (36.33 KB, patch)
2015-04-23 16:59 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Another build fix (36.32 KB, patch)
2015-04-23 18:09 PDT, Ryosuke Niwa
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2015-03-28 01:46:53 PDT
Both instance and static methods defined by ES6 class syntax should not be enumerable.
Comment 1 Ryosuke Niwa 2015-03-28 01:48:56 PDT
Also see the bug 142842: The prototype internal slot of an ES6 class should be non-configurable and non-writable  See dependency tree for bug 142842.

We can either add an extra argument to op_put_by_id or add a new op code to modify the descriptor of a property.

Any preferences?
Comment 2 Radar WebKit Bug Importer 2015-03-28 01:51:53 PDT
<rdar://problem/20337023>
Comment 3 Ryosuke Niwa 2015-03-29 23:48:28 PDT
Looks like defineProperty is mostly used to define a new accessor in benchmarks (run-jsc-benchmarks):

The total number of calls to defineOwnIndexProperty: 8
The total number of calls to defineOwnNonIndexProperty: 3562
  was a new entry: 3398
  didn't change descriptor: 0
  configurable:  2224
  enumerable: 2168
  writable: 1726
  accessor: 1726
Comment 4 Ryosuke Niwa 2015-03-29 23:53:04 PDT
In Speedometer, it's mostly used to define non-enumerable and non-writable proeprties:

The total number of calls to defineOwnIndexProperty: 22
The total number of calls to defineOwnNonIndexProperty: 103034
  was a new entry: 66903 (65%)
  didn't change descriptor: 0
  configurable: 73953 (72%)
  enumerable: 2168 (2%)
  writable: 1726 (2%)
  accessor: 1726 (2%)
Comment 5 Ryosuke Niwa 2015-03-30 18:42:58 PDT
*** Bug 143246 has been marked as a duplicate of this bug. ***
Comment 6 Ryosuke Niwa 2015-03-30 18:48:38 PDT
I talked with Geoff today about this bug, and he suggested that we can just make a function call to defineProperty. We can then add an intrinsic to defineProperty so that it'll go fast in DFG.  That'll work nicely with the bug 143239.
Comment 7 Ryosuke Niwa 2015-04-01 02:49:04 PDT
Created attachment 249911 [details]
WIP

Some real craziness.
Comment 8 Ryosuke Niwa 2015-04-02 23:20:28 PDT
Created attachment 250046 [details]
WIP2
Comment 9 Ryosuke Niwa 2015-04-12 03:22:57 PDT
Created attachment 250598 [details]
Fixes the bug
Comment 10 Ryosuke Niwa 2015-04-20 16:25:08 PDT
Created attachment 251202 [details]
Updated for ToT
Comment 11 Darin Adler 2015-04-21 16:54:11 PDT
Comment on attachment 251202 [details]
Updated for ToT

View in context: https://bugs.webkit.org/attachment.cgi?id=251202&action=review

> Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h:572
> +    unsigned m_linkTimeConstants[LinkTimeConstantCount] { 0 };

Looks like Windows can’t handle this.
Comment 12 Oliver Hunt 2015-04-21 17:34:51 PDT
Comment on attachment 251202 [details]
Updated for ToT

View in context: https://bugs.webkit.org/attachment.cgi?id=251202&action=review

>> Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h:572
>> +    unsigned m_linkTimeConstants[LinkTimeConstantCount] { 0 };
> 
> Looks like Windows can’t handle this.

I'd swear we've used things like this before -- you could try making LinkTimeConstantCount static or a class member.

Also honestly i'd prefer it if you used std::array here sit has bounds checking at least in debug builds (alas not in release :-/ )
Comment 13 Ryosuke Niwa 2015-04-22 14:39:46 PDT
Created attachment 251369 [details]
Fixed Windows build
Comment 14 Ryosuke Niwa 2015-04-22 21:50:02 PDT
Created attachment 251404 [details]
Another attempt to fix Windows build
Comment 15 Ryosuke Niwa 2015-04-23 03:36:03 PDT
Created attachment 251425 [details]
Fixed Windows build for good; fuck off cl.exe
Comment 16 Ryosuke Niwa 2015-04-23 12:33:58 PDT
Created attachment 251468 [details]
Yet another Win build fix; fuck cl.exe
Comment 17 Ryosuke Niwa 2015-04-23 12:34:11 PDT
Fucking cl.exe needs to die.
Comment 18 Geoffrey Garen 2015-04-23 13:19:01 PDT
Comment on attachment 251468 [details]
Yet another Win build fix; fuck cl.exe

View in context: https://bugs.webkit.org/attachment.cgi?id=251468&action=review

Patch looks OK to me. Please address the comments below, and fix the build.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1769
> +    for (unsigned i = 0; i < LinkTimeConstantCount; i++) {
> +        LinkTimeConstant type = static_cast<LinkTimeConstant>(i);
> +        if (unsigned registerIndex = unlinkedCodeBlock->registerIndexForLinkTimeConstant(type))
> +            m_constantRegisters[registerIndex].set(*m_vm, ownerExecutable, m_globalObject->jsCellForLinkTimeConstant(type));
> +    }

Can we unify LinkTimeConstant with SpecialPointer? They implement the same feature, so it would be nice to unify them. SpecialPointer is just a LinkTimeConstant for one of two possible functions (call, apply), and LinkTimeConstant adds another (defineProperty).

> Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:152
> +    m_linkTimeConstantRegisters = { {nullptr} };

Will this syntax fill all entries or just the first? We want to fill all.
Comment 19 Ryosuke Niwa 2015-04-23 14:13:25 PDT
(In reply to comment #18)
> Comment on attachment 251468 [details]
> Yet another Win build fix; fuck cl.exe
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=251468&action=review
> 
> Patch looks OK to me. Please address the comments below, and fix the build.
> 
> > Source/JavaScriptCore/bytecode/CodeBlock.cpp:1769
> > +    for (unsigned i = 0; i < LinkTimeConstantCount; i++) {
> > +        LinkTimeConstant type = static_cast<LinkTimeConstant>(i);
> > +        if (unsigned registerIndex = unlinkedCodeBlock->registerIndexForLinkTimeConstant(type))
> > +            m_constantRegisters[registerIndex].set(*m_vm, ownerExecutable, m_globalObject->jsCellForLinkTimeConstant(type));
> > +    }
> 
> Can we unify LinkTimeConstant with SpecialPointer? They implement the same
> feature, so it would be nice to unify them. SpecialPointer is just a
> LinkTimeConstant for one of two possible functions (call, apply), and
> LinkTimeConstant adds another (defineProperty).

Yeah, that's the plan but I didn't want to do that in this patch since it's already quite massive.

> > Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:152
> > +    m_linkTimeConstantRegisters = { {nullptr} };
> 
> Will this syntax fill all entries or just the first? We want to fill all.

It should initiailize them all but I'm gonna just use loop since it doesn't seem like nothing compiles these days.
Comment 20 Ryosuke Niwa 2015-04-23 16:59:53 PDT
Created attachment 251514 [details]
Fixed builds
Comment 21 Ryosuke Niwa 2015-04-23 18:09:54 PDT
Created attachment 251521 [details]
Another build fix
Comment 22 Darin Adler 2015-04-23 19:17:17 PDT
Comment on attachment 251521 [details]
Another build fix

View in context: https://bugs.webkit.org/attachment.cgi?id=251521&action=review

> Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h:334
> +    unsigned addConstant(LinkTimeConstant type)

ASSERT it’s < LinkTimeConstantCount?

> Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h:343
> +    unsigned registerIndexForLinkTimeConstant(LinkTimeConstant type)

ASSERT it’s < LinkTimeConstantCount?

> Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:153
> +    for (unsigned i = 0; i < LinkTimeConstantCount; i++)
> +        m_linkTimeConstantRegisters[i] = nullptr;

Can this use a modern for loop instead?

> Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:186
> +    for (unsigned i = 0; i < LinkTimeConstantCount; i++)
> +        m_linkTimeConstantRegisters[i] = nullptr;

Can this use a modern for loop instead?

> Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:504
> +    for (unsigned i = 0; i < LinkTimeConstantCount; i++)
> +        m_linkTimeConstantRegisters[i] = nullptr;

Can this use a modern for loop instead?
Comment 23 Ryosuke Niwa 2015-04-23 19:25:30 PDT
(In reply to comment #22)
> Comment on attachment 251521 [details]
> Another build fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=251521&action=review
>
> > Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:153
> > +    for (unsigned i = 0; i < LinkTimeConstantCount; i++)
> > +        m_linkTimeConstantRegisters[i] = nullptr;
> 
> Can this use a modern for loop instead?

How do I do that?
Comment 24 Ryosuke Niwa 2015-04-25 14:43:47 PDT
Okay, we can just do:
for (auto& constantRegister : m_linkTimeConstantRegisters)
    constantRegister = nullptr;
Comment 25 Ryosuke Niwa 2015-04-25 14:57:15 PDT
Thanks for the review!  Will land the patch after using modern loops and adding assertions.
Comment 26 Ryosuke Niwa 2015-04-25 15:04:40 PDT
Committed r183316: <http://trac.webkit.org/changeset/183316>