- Revision
- 284226
- Author
- [email protected]
- Date
- 2021-10-14 19:02:14 -0700 (Thu, 14 Oct 2021)
Log Message
Service workers running on the main thread should use the main VM
https://bugs.webkit.org/show_bug.cgi?id=231753
Reviewed by Geoffrey Garen.
Source/WebCore:
ervice workers running on the main thread should use the main VM. This makes life easier for injected
bundle clients and there is no strong reason to use a separate VM since VMs are mainly used for thread
safety / isolation.
No new tests, extended existing API test.
* workers/WorkerOrWorkletGlobalScope.cpp:
(WebCore::WorkerOrWorkletGlobalScope::isContextThread const):
WorkerOrWorkletThread::thread() returns null when the service worker is running on the main thread.
Update WorkerOrWorkletGlobalScope::isContextThread() to deal with that and properly treats the
main thread as the context thread in this case.
* workers/WorkerOrWorkletScriptController.cpp:
(WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController):
(WebCore::WorkerOrWorkletScriptController::scheduleExecutionTermination):
Tools:
Extend API test coverage.
* TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerPagePlugIn.mm:
(-[ServiceWorkerPagePlugIn webProcessPlugInBrowserContextController:serviceWorkerGlobalObjectIsAvailableForFrame:inScriptWorld:]):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (284225 => 284226)
--- trunk/Source/WebCore/ChangeLog 2021-10-15 01:58:24 UTC (rev 284225)
+++ trunk/Source/WebCore/ChangeLog 2021-10-15 02:02:14 UTC (rev 284226)
@@ -1,3 +1,26 @@
+2021-10-14 Chris Dumez <[email protected]>
+
+ Service workers running on the main thread should use the main VM
+ https://bugs.webkit.org/show_bug.cgi?id=231753
+
+ Reviewed by Geoffrey Garen.
+
+ ervice workers running on the main thread should use the main VM. This makes life easier for injected
+ bundle clients and there is no strong reason to use a separate VM since VMs are mainly used for thread
+ safety / isolation.
+
+ No new tests, extended existing API test.
+
+ * workers/WorkerOrWorkletGlobalScope.cpp:
+ (WebCore::WorkerOrWorkletGlobalScope::isContextThread const):
+ WorkerOrWorkletThread::thread() returns null when the service worker is running on the main thread.
+ Update WorkerOrWorkletGlobalScope::isContextThread() to deal with that and properly treats the
+ main thread as the context thread in this case.
+
+ * workers/WorkerOrWorkletScriptController.cpp:
+ (WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController):
+ (WebCore::WorkerOrWorkletScriptController::scheduleExecutionTermination):
+
2021-10-14 Aditya Keerthi <[email protected]>
[iOS] Paint <datalist> indicator in RenderTheme
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (284225 => 284226)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2021-10-15 01:58:24 UTC (rev 284225)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2021-10-15 02:02:14 UTC (rev 284226)
@@ -31,6 +31,7 @@
#include "CSSFontSelector.h"
#include "CSSValueList.h"
#include "CSSValuePool.h"
+#include "CommonVM.h"
#include "ContentSecurityPolicy.h"
#include "Crypto.h"
#include "FontCache.h"
@@ -79,7 +80,7 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(WorkerGlobalScope);
WorkerGlobalScope::WorkerGlobalScope(WorkerThreadType type, const WorkerParameters& params, Ref<SecurityOrigin>&& origin, WorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider)
- : WorkerOrWorkletGlobalScope(type, JSC::VM::create(), &thread)
+ : WorkerOrWorkletGlobalScope(type, isMainThread() ? Ref { commonVM() } : JSC::VM::create(), &thread)
, m_url(params.scriptURL)
, m_identifier(params.identifier)
, m_userAgent(params.userAgent)
Modified: trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp (284225 => 284226)
--- trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp 2021-10-15 01:58:24 UTC (rev 284225)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp 2021-10-15 02:02:14 UTC (rev 284226)
@@ -111,7 +111,7 @@
bool WorkerOrWorkletGlobalScope::isContextThread() const
{
auto* thread = workerOrWorkletThread();
- return thread ? thread->thread() == &Thread::current() : isMainThread();
+ return thread && thread->thread() ? thread->thread() == &Thread::current() : isMainThread();
}
void WorkerOrWorkletGlobalScope::postTask(Task&& task)
Modified: trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp (284225 => 284226)
--- trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp 2021-10-15 01:58:24 UTC (rev 284225)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp 2021-10-15 02:02:14 UTC (rev 284226)
@@ -27,6 +27,7 @@
#include "config.h"
#include "WorkerOrWorkletScriptController.h"
+#include "CommonVM.h"
#include "DedicatedWorkerGlobalScope.h"
#include "EventLoop.h"
#include "JSAudioWorkletGlobalScope.h"
@@ -68,13 +69,15 @@
, m_globalScope(globalScope)
, m_globalScopeWrapper(*m_vm)
{
- m_vm->heap.acquireAccess(); // It's not clear that we have good discipline for heap access, so turn it on permanently.
- {
- JSLockHolder lock(m_vm.get());
- m_vm->ensureTerminationException();
+ if (!isMainThread() || m_vm != &commonVM()) {
+ m_vm->heap.acquireAccess(); // It's not clear that we have good discipline for heap access, so turn it on permanently.
+ {
+ JSLockHolder lock(m_vm.get());
+ m_vm->ensureTerminationException();
+ }
+
+ JSVMClientData::initNormalWorld(m_vm.get(), type);
}
-
- JSVMClientData::initNormalWorld(m_vm.get(), type);
}
WorkerOrWorkletScriptController::WorkerOrWorkletScriptController(WorkerThreadType type, WorkerOrWorkletGlobalScope* globalScope)
@@ -129,7 +132,8 @@
m_isTerminatingExecution = true;
}
- m_vm->notifyNeedTermination();
+ if (m_vm != &commonVM())
+ m_vm->notifyNeedTermination();
}
bool WorkerOrWorkletScriptController::isTerminatingExecution() const
Modified: trunk/Tools/ChangeLog (284225 => 284226)
--- trunk/Tools/ChangeLog 2021-10-15 01:58:24 UTC (rev 284225)
+++ trunk/Tools/ChangeLog 2021-10-15 02:02:14 UTC (rev 284226)
@@ -1,3 +1,15 @@
+2021-10-14 Chris Dumez <[email protected]>
+
+ Service workers running on the main thread should use the main VM
+ https://bugs.webkit.org/show_bug.cgi?id=231753
+
+ Reviewed by Geoffrey Garen.
+
+ Extend API test coverage.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerPagePlugIn.mm:
+ (-[ServiceWorkerPagePlugIn webProcessPlugInBrowserContextController:serviceWorkerGlobalObjectIsAvailableForFrame:inScriptWorld:]):
+
2021-10-14 Wenson Hsieh <[email protected]>
[JS IPC] Implement a way to synchronously wait for an incoming IPC message
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerPagePlugIn.mm (284225 => 284226)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerPagePlugIn.mm 2021-10-15 01:58:24 UTC (rev 284225)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerPagePlugIn.mm 2021-10-15 02:02:14 UTC (rev 284226)
@@ -26,6 +26,7 @@
#import "config.h"
#import "ServiceWorkerPageProtocol.h"
+#import <_javascript_Core/JSContextRef.h>
#import <WebKit/WKBundlePage.h>
#import <WebKit/WKWebProcessPlugIn.h>
#import <WebKit/WKWebProcessPlugInBrowserContextControllerPrivate.h>
@@ -32,6 +33,7 @@
#import <WebKit/WKWebProcessPlugInFrame.h>
#import <WebKit/WKWebProcessPlugInFramePrivate.h>
#import <WebKit/WKWebProcessPlugInLoadDelegate.h>
+#import <WebKit/WKWebProcessPlugInScriptWorld.h>
#import <WebKit/_WKRemoteObjectInterface.h>
#import <WebKit/_WKRemoteObjectRegistry.h>
#import <wtf/RunLoop.h>
@@ -47,11 +49,20 @@
{
RELEASE_ASSERT(RunLoop::isMain());
RELEASE_ASSERT(frame);
- JSContext *jsContext = [frame jsContextForServiceWorkerWorld:scriptWorld];
- RELEASE_ASSERT(jsContext);
- RELEASE_ASSERT([WKWebProcessPlugInFrame lookUpFrameFromJSContext:jsContext] == frame);
+ JSContext *serviceWorkerJSContext = [frame jsContextForServiceWorkerWorld:scriptWorld];
+ RELEASE_ASSERT(serviceWorkerJSContext);
+ RELEASE_ASSERT([WKWebProcessPlugInFrame lookUpFrameFromJSContext:serviceWorkerJSContext] == frame);
- JSValue *globalIsServiceWorkerGlobalScope = [jsContext evaluateScript:@"self.__proto__ === ServiceWorkerGlobalScope.prototype"];
+ JSContext *mainFrameJSContext = [frame jsContextForWorld:[WKWebProcessPlugInScriptWorld normalWorld]];
+ RELEASE_ASSERT(mainFrameJSContext);
+
+ // The main frame and the service worker should have different JSContexts but should use the same VM.
+ RELEASE_ASSERT(mainFrameJSContext != serviceWorkerJSContext);
+ RELEASE_ASSERT(JSContextGetGroup(mainFrameJSContext.JSGlobalContextRef) == JSContextGetGroup(serviceWorkerJSContext.JSGlobalContextRef));
+
+ RELEASE_ASSERT(scriptWorld == [WKWebProcessPlugInScriptWorld normalWorld]);
+
+ JSValue *globalIsServiceWorkerGlobalScope = [serviceWorkerJSContext evaluateScript:@"self.__proto__ === ServiceWorkerGlobalScope.prototype"];
RELEASE_ASSERT(!!globalIsServiceWorkerGlobalScope);
RELEASE_ASSERT([globalIsServiceWorkerGlobalScope toBool]);