Bug 215562

Summary: Resolve with the class used to define the Custom Element
Product: WebKit Reporter: Andrea Giammarchi <andrea.giammarchi>
Component: PlatformAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, clopez, darin, esprehn+autocc, ews-watchlist, kangil.han, koivisto, rniwa, webkit-bug-importer, wenson_hsieh, youennf, ysuzuki
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=215830
Bug Depends on:    
Bug Blocks: 154907    
Attachments:
Description Flags
Implements the new behavior
none
Patch for landing none

Description Andrea Giammarchi 2020-08-17 03:00:12 PDT
Accordingly with https://github.com/whatwg/html/issues/5552, `whenDefined` should resolve with the class used to define the custom element in the registry.
Comment 1 Radar WebKit Bug Importer 2020-08-17 17:28:50 PDT
<rdar://problem/67282709>
Comment 2 Ryosuke Niwa 2020-08-20 19:47:29 PDT
Created attachment 406998 [details]
Implements the new behavior
Comment 3 EWS Watchlist 2020-08-20 19:48:32 PDT
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Comment 4 Darin Adler 2020-08-20 19:54:25 PDT
Comment on attachment 406998 [details]
Implements the new behavior

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

> Source/WebCore/bindings/js/JSDOMPromiseDeferred.h:80
> +        JSC::JSGlobalObject* lexicalGlobalObject = globalObject();

auto

> Source/WebCore/dom/CustomElementRegistry.cpp:81
>      if (auto promise = m_promiseMap.take(localName))
> -        promise.value()->resolve();
> +        return WTFMove(*promise);
> +    return nullptr;

No if statement needed:

    return m_promiseMap.take(localName);
Comment 5 Ryosuke Niwa 2020-08-20 20:17:52 PDT
(In reply to Darin Adler from comment #4)
> Comment on attachment 406998 [details]
> Implements the new behavior
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=406998&action=review
>
> > Source/WebCore/dom/CustomElementRegistry.cpp:81
> >      if (auto promise = m_promiseMap.take(localName))
> > -        promise.value()->resolve();
> > +        return WTFMove(*promise);
> > +    return nullptr;
> 
> No if statement needed:
> 
>     return m_promiseMap.take(localName);

That's what I thought but I was getting (and still getting) this error:

./dom/CustomElementRegistry.cpp:79:12: error: no viable conversion from returned value of type 'WTF::HashMap<WTF::AtomString, WTF::Ref<WebCore::DeferredPromise, WTF::DumbPtrTraits<WebCore::DeferredPromise> >, WTF::DefaultHash<WTF::AtomString>, WTF::HashTraits<WTF::AtomString>, WTF::HashTraits<WTF::Ref<WebCore::DeferredPromise, WTF::DumbPtrTraits<WebCore::DeferredPromise> > > >::MappedTakeType' (aka 'Optional<Ref<WebCore::DeferredPromise> >') to function return type 'RefPtr<WebCore::DeferredPromise>'
    return m_promiseMap.take(localName);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment 6 Darin Adler 2020-08-21 09:15:53 PDT
I see. You’ll have to write it this way for now, but we should either change RefHashTraits::TakeType to RefPtr in HashTraits.h, or add a constructor for RefPtr that takes Optional<Ref>&& in RefPtr.h, or possibly do both. Then we can come back here and re-simplify this.
Comment 7 Ryosuke Niwa 2020-08-25 13:54:22 PDT
Created attachment 407227 [details]
Patch for landing
Comment 8 Ryosuke Niwa 2020-08-25 13:54:49 PDT
(In reply to Darin Adler from comment #6)
> I see. You’ll have to write it this way for now, but we should either change
> RefHashTraits::TakeType to RefPtr in HashTraits.h, or add a constructor for
> RefPtr that takes Optional<Ref>&& in RefPtr.h, or possibly do both. Then we
> can come back here and re-simplify this.

Yeah, let me work on that next.
Comment 9 EWS 2020-08-25 14:22:17 PDT
Committed r266142: <https://trac.webkit.org/changeset/266142>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 407227 [details].