Bug 148705

Summary: [ES6] Implement ModuleNamespaceObject
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: saam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 148053    
Bug Blocks: 147340, 148689    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch ggaren: review+

Description Yusuke Suzuki 2015-09-01 23:29:37 PDT
Implement ModuleNamespaceObject.
Comment 1 Yusuke Suzuki 2015-09-02 13:16:41 PDT
Created attachment 260431 [details]
Patch
Comment 2 Yusuke Suzuki 2015-09-02 13:21:52 PDT
Comment on attachment 260431 [details]
Patch

This patch is based on the https://bugs.webkit.org/show_bug.cgi?id=148053
Comment 3 Yusuke Suzuki 2015-09-02 14:17:11 PDT
Created attachment 260437 [details]
Patch
Comment 4 Yusuke Suzuki 2015-09-03 21:30:21 PDT
Let's rebase it.
Comment 5 Yusuke Suzuki 2015-09-03 21:51:38 PDT
Created attachment 260562 [details]
Patch
Comment 6 Yusuke Suzuki 2015-09-03 22:00:29 PDT
Created attachment 260564 [details]
Patch
Comment 7 Yusuke Suzuki 2015-09-03 22:00:53 PDT
Slightly clean up the comment. Now patch is ready for review.
Comment 8 Geoffrey Garen 2015-09-04 14:19:41 PDT
Comment on attachment 260564 [details]
Patch

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

> Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp:64
> +{
> +    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects
> +    // Quoted from the spec:
> +    //     A List containing the String values of the exported names exposed as own properties of this object.
> +    //     The list is ordered as if an Array of those String values had been sorted using Array.prototype.sort using SortCompare as comparefn.
> +    //
> +    // Sort the exported names by the code point order.
> +    Vector<UniquedStringImpl*> temporaryVector(exports.size(), nullptr);
> +    std::transform(exports.begin(), exports.end(), temporaryVector.begin(), [](const RefPtr<WTF::UniquedStringImpl>& ref) {
> +        return ref.get();
> +    });
> +    std::sort(temporaryVector.begin(), temporaryVector.end(), [] (UniquedStringImpl* lhs, UniquedStringImpl* rhs) {
> +        return codePointCompare(lhs, rhs) < 0;
> +    });
> +    for (auto* identifier : temporaryVector)
> +        m_exports.add(identifier);

This stuff should move into finishCreation. A JS object constructor should only do the bare minimum to default initialize fields in order to avoid crashing during GC. We do all meaningful work inside finishCreation in order to avoid problems that we might cause by triggering GC during a constructor. (I can see by reading this code that it doesn't cause GC, but it is preferable style to favor finishCreation so we don't have to do that reading.)

> Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp:114
> +    // If the value is filled with TDZ value, throw the reference error.

the => a
Comment 9 Yusuke Suzuki 2015-09-04 14:55:02 PDT
Comment on attachment 260564 [details]
Patch

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

Thank you for your review! I'll revise the patch based on your review and land it :D

>> Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp:64
>> +        m_exports.add(identifier);
> 
> This stuff should move into finishCreation. A JS object constructor should only do the bare minimum to default initialize fields in order to avoid crashing during GC. We do all meaningful work inside finishCreation in order to avoid problems that we might cause by triggering GC during a constructor. (I can see by reading this code that it doesn't cause GC, but it is preferable style to favor finishCreation so we don't have to do that reading.)

Make sense. Moving the above code to the finishCreation.

>> Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp:114
>> +    // If the value is filled with TDZ value, throw the reference error.
> 
> the => a

Thank you! Fixed.
Comment 10 Yusuke Suzuki 2015-09-05 00:23:05 PDT
Committed r189429: <http://trac.webkit.org/changeset/189429>