Bug 178187 - SW "Hello world"
Summary: SW "Hello world"
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brady Eidson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-10-11 14:06 PDT by Brady Eidson
Modified: 2017-12-16 17:02 PST (History)
13 users (show)

See Also:


Attachments
Patch (without changeling but otherwise review ready?) (38.24 KB, patch)
2017-10-12 17:14 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch (Changelog to come, still reviewable now) (38.28 KB, patch)
2017-10-12 20:22 PDT, Brady Eidson
aestes: review+
Details | Formatted Diff | Diff
PFL (42.19 KB, patch)
2017-10-12 22:24 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
PFL (42.17 KB, patch)
2017-10-12 22:57 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2017-10-11 14:06:08 PDT
SW "Hello world"

<rdar://problem/33225187>
Comment 1 Brady Eidson 2017-10-12 17:14:46 PDT
Created attachment 323605 [details]
Patch (without changeling but otherwise review ready?)
Comment 2 Brady Eidson 2017-10-12 17:15:13 PDT
Wow, autocorrect made "changelog" into "changeling"

Nice.
Comment 3 Tim Horton 2017-10-12 17:23:40 PDT
Comment on attachment 323605 [details]
Patch (without changeling but otherwise review ready?)

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

> Source/WebCore/workers/service/ServiceWorkerContextData.h:70
> +    if (!decoder.decode(scriptURL))
> +        return std::nullopt;

Shouldn't we have a MESSAGE_CHECK of some sort here?

> Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:35
> +ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, const URL& url, const String& identifier, const String& userAgent, ServiceWorkerThread& thread, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, PAL::SessionID sessionID)

That is a lot of arguments. Will there be more? Seems ripe for a Parameters object or something.
Comment 4 Brady Eidson 2017-10-12 20:19:51 PDT
(In reply to Tim Horton from comment #3)
> Comment on attachment 323605 [details]
> Patch (without changeling but otherwise review ready?)
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=323605&action=review
> 
> > Source/WebCore/workers/service/ServiceWorkerContextData.h:70
> > +    if (!decoder.decode(scriptURL))
> > +        return std::nullopt;
> 
> Shouldn't we have a MESSAGE_CHECK of some sort here?

WebCore has no concept of MESSAGE_CHECK, so therefore non of the WebCore encoder/decoders do.

> 
> > Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:35
> > +ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, const URL& url, const String& identifier, const String& userAgent, ServiceWorkerThread& thread, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, PAL::SessionID sessionID)
> 
> That is a lot of arguments. Will there be more? Seems ripe for a Parameters
> object or something.

This is exactly the same as WorkerGlobalScope, DedicatedWorkerGlobalScope, WorkerThread, etc etc etc.

I don't know that a parameters object makes a lot of sense. For these families of objects there's only ever going to be one caller, and making changes to the parameters is easily handled with the ::create() method being variadic.

Also a parameters object would allow for default arguments, and I think it's good for none of these arguments to be things you can ignore!
Part of it is made nicer with a variadic ::create() method.
Comment 5 Brady Eidson 2017-10-12 20:22:47 PDT
Created attachment 323625 [details]
Patch (Changelog to come, still reviewable now)
Comment 6 Andy Estes 2017-10-12 20:55:20 PDT
Comment on attachment 323625 [details]
Patch (Changelog to come, still reviewable now)

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

> Source/WebCore/bindings/js/WorkerScriptController.cpp:112
> +        Structure* contextPrototypeStructure = JSServiceWorkerGlobalScopePrototype::createStructure(*m_vm, nullptr, jsNull());
> +        Strong<JSServiceWorkerGlobalScopePrototype> contextPrototype(*m_vm, JSServiceWorkerGlobalScopePrototype::create(*m_vm, nullptr, contextPrototypeStructure));
> +        Structure* structure = JSServiceWorkerGlobalScope::createStructure(*m_vm, nullptr, contextPrototype.get());
> +        auto* proxyStructure = JSProxy::createStructure(*m_vm, nullptr, jsNull(), PureForwardingProxyType);
> +        auto* proxy = JSProxy::create(*m_vm, proxyStructure);
> +    
> +        m_workerGlobalScopeWrapper.set(*m_vm, JSServiceWorkerGlobalScope::create(*m_vm, structure, static_cast<ServiceWorkerGlobalScope&>(*m_workerGlobalScope), proxy));
> +        contextPrototypeStructure->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
> +        ASSERT(structure->globalObject() == m_workerGlobalScopeWrapper);
> +        ASSERT(m_workerGlobalScopeWrapper->structure()->globalObject() == m_workerGlobalScopeWrapper);
> +        contextPrototype->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
> +        contextPrototype->structure()->setPrototypeWithoutTransition(*m_vm, JSWorkerGlobalScope::prototype(*m_vm, *m_workerGlobalScopeWrapper.get()));
> +
> +        proxy->setTarget(*m_vm, m_workerGlobalScopeWrapper.get());
> +        proxy->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());

Since there's very little difference between this and the the code for dedicated workers above, I'd consider factoring this out into a function template that takes the prototype and global scope class names as parameters.

> Source/WebCore/workers/service/ServiceWorkerGlobalScope.h:38
> +    

whitespace

> Source/WebCore/workers/service/context/ServiceWorkerThread.cpp:76
> +static uint64_t nextUniqueContextIdentifier()
> +{
> +    ASSERT(isMainThread());
> +    static uint64_t currentUniqueContextIdentifier;
> +    return ++currentUniqueContextIdentifier;
> +}

Can ServiceWorkerThread use Identified<> instead?
Comment 7 Brady Eidson 2017-10-12 22:17:02 PDT
(In reply to Andy Estes from comment #6)
> Comment on attachment 323625 [details]
> Patch (Changelog to come, still reviewable now)
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=323625&action=review
> 
> > Source/WebCore/bindings/js/WorkerScriptController.cpp:112
> > +        Structure* contextPrototypeStructure = JSServiceWorkerGlobalScopePrototype::createStructure(*m_vm, nullptr, jsNull());
> > +        Strong<JSServiceWorkerGlobalScopePrototype> contextPrototype(*m_vm, JSServiceWorkerGlobalScopePrototype::create(*m_vm, nullptr, contextPrototypeStructure));
> > +        Structure* structure = JSServiceWorkerGlobalScope::createStructure(*m_vm, nullptr, contextPrototype.get());
> > +        auto* proxyStructure = JSProxy::createStructure(*m_vm, nullptr, jsNull(), PureForwardingProxyType);
> > +        auto* proxy = JSProxy::create(*m_vm, proxyStructure);
> > +    
> > +        m_workerGlobalScopeWrapper.set(*m_vm, JSServiceWorkerGlobalScope::create(*m_vm, structure, static_cast<ServiceWorkerGlobalScope&>(*m_workerGlobalScope), proxy));
> > +        contextPrototypeStructure->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
> > +        ASSERT(structure->globalObject() == m_workerGlobalScopeWrapper);
> > +        ASSERT(m_workerGlobalScopeWrapper->structure()->globalObject() == m_workerGlobalScopeWrapper);
> > +        contextPrototype->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
> > +        contextPrototype->structure()->setPrototypeWithoutTransition(*m_vm, JSWorkerGlobalScope::prototype(*m_vm, *m_workerGlobalScopeWrapper.get()));
> > +
> > +        proxy->setTarget(*m_vm, m_workerGlobalScopeWrapper.get());
> > +        proxy->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
> 
> Since there's very little difference between this and the the code for
> dedicated workers above, I'd consider factoring this out into a function
> template that takes the prototype and global scope class names as parameters.
> 

Not as much of a slam dunk as it seems as there's SW specific bits coming very very soon.

I'll take a quick look at it.

> > Source/WebCore/workers/service/ServiceWorkerGlobalScope.h:38
> > +    
> 
> whitespace
> 
> > Source/WebCore/workers/service/context/ServiceWorkerThread.cpp:76
> > +static uint64_t nextUniqueContextIdentifier()
> > +{
> > +    ASSERT(isMainThread());
> > +    static uint64_t currentUniqueContextIdentifier;
> > +    return ++currentUniqueContextIdentifier;
> > +}
> 
> Can ServiceWorkerThread use Identified<> instead?

(Puts on the hat of the person who added Identified<> in the first place)

Yes.
Comment 8 Brady Eidson 2017-10-12 22:24:31 PDT
Created attachment 323637 [details]
PFL
Comment 9 Brady Eidson 2017-10-12 22:57:09 PDT
Created attachment 323639 [details]
PFL
Comment 10 WebKit Commit Bot 2017-10-12 23:44:50 PDT
Comment on attachment 323639 [details]
PFL

Clearing flags on attachment: 323639

Committed r223277: <https://trac.webkit.org/changeset/223277>
Comment 11 youenn fablet 2017-10-13 09:30:23 PDT
Is it possible with this patch landed to do some HTTP/POST to a server so as to enable communication between a window and a service worker through this server?
Comment 12 Chris Dumez 2017-10-13 10:07:23 PDT
Comment on attachment 323639 [details]
PFL

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

> Source/WebCore/workers/service/context/SWContextManager.cpp:40
> +    static SWContextManager* sharedManager = new SWContextManager;

Any reason we are not using NeverDestroyed here?