Skip to content

Commit

Permalink
[iOS Sim Debug] ASSERTION FAILED The atomic string comes from an othe…
Browse files Browse the repository at this point in the history
…r thread! Layout Test imported/w3c/web-platform-tests/workers/WorkerNavigator_appName.htm is a flaky crash

https://bugs.webkit.org/show_bug.cgi?id=197530
<rdar://problem/50448285>

Reviewed by Geoffrey Garen.

The issue is that NavigatorBase::platform() was not thread safe but was called by both Navigator on
the main thread and WorkerNavigator on worker threads.

No new tests, covered by existing tests.

* page/Navigator.cpp:
(WebCore::Navigator::platform const):
* page/Navigator.h:

* page/NavigatorBase.cpp:
(WebCore::NavigatorBase::platform const):
* page/NavigatorBase.h:
Make NavigatorBase::platform() thread safe.

* platform/ios/Device.cpp:
(WebCore::deviceName):
* platform/ios/Device.h:
Make WebCore::deviceName() thread safe.

* platform/ios/UserAgentIOS.mm:
(WebCore::deviceNameForUserAgent):
Cache value returned by WebCore::deviceName() for performance.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@244927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez@apple.com committed May 3, 2019
1 parent f998a7e commit 878faaa
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 36 deletions.
31 changes: 31 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
2019-05-03 Chris Dumez <cdumez@apple.com>

[iOS Sim Debug] ASSERTION FAILED The atomic string comes from an other thread! Layout Test imported/w3c/web-platform-tests/workers/WorkerNavigator_appName.htm is a flaky crash
https://bugs.webkit.org/show_bug.cgi?id=197530
<rdar://problem/50448285>

Reviewed by Geoffrey Garen.

The issue is that NavigatorBase::platform() was not thread safe but was called by both Navigator on
the main thread and WorkerNavigator on worker threads.

No new tests, covered by existing tests.

* page/Navigator.cpp:
(WebCore::Navigator::platform const):
* page/Navigator.h:

* page/NavigatorBase.cpp:
(WebCore::NavigatorBase::platform const):
* page/NavigatorBase.h:
Make NavigatorBase::platform() thread safe.

* platform/ios/Device.cpp:
(WebCore::deviceName):
* platform/ios/Device.h:
Make WebCore::deviceName() thread safe.

* platform/ios/UserAgentIOS.mm:
(WebCore::deviceNameForUserAgent):
Cache value returned by WebCore::deviceName() for performance.

2019-05-03 Chris Dumez <cdumez@apple.com>

Use WeakPtr for JSLazyEventListener::m_originalNode for safety
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const String& Navigator::userAgent() const
return m_userAgent;
}

const String& Navigator::platform() const
String Navigator::platform() const
{
auto* frame = this->frame();
if (!frame || !frame->page())
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/Navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Navigator final : public NavigatorBase, public ScriptWrappable, public DOM
bool cookieEnabled() const;
bool javaEnabled() const;
const String& userAgent() const final;
const String& platform() const final;
String platform() const final;
void userAgentChanged();
bool onLine() const final;
void share(ScriptExecutionContext&, ShareData, Ref<DeferredPromise>&&);
Expand Down
39 changes: 17 additions & 22 deletions Source/WebCore/page/NavigatorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@
#include "Device.h"
#endif

#ifndef WEBCORE_NAVIGATOR_PLATFORM
#if PLATFORM(IOS_FAMILY)
#define WEBCORE_NAVIGATOR_PLATFORM deviceName()
#elif OS(MAC_OS_X) && (CPU(PPC) || CPU(PPC64))
#define WEBCORE_NAVIGATOR_PLATFORM "MacPPC"_s
#elif OS(MAC_OS_X) && (CPU(X86) || CPU(X86_64))
#define WEBCORE_NAVIGATOR_PLATFORM "MacIntel"_s
#elif OS(WINDOWS)
#define WEBCORE_NAVIGATOR_PLATFORM "Win32"_s
#else
#define WEBCORE_NAVIGATOR_PLATFORM emptyString()
#endif
#endif // ifndef WEBCORE_NAVIGATOR_PLATFORM

#ifndef WEBCORE_NAVIGATOR_PRODUCT
#define WEBCORE_NAVIGATOR_PRODUCT "Gecko"_s
#endif // ifndef WEBCORE_NAVIGATOR_PRODUCT
Expand Down Expand Up @@ -96,17 +82,26 @@ String NavigatorBase::appVersion() const
return agent.substring(agent.find('/') + 1);
}

const String& NavigatorBase::platform() const
String NavigatorBase::platform() const
{
static NeverDestroyed<String> defaultPlatform = WEBCORE_NAVIGATOR_PLATFORM;
#if OS(LINUX)
if (!String(WEBCORE_NAVIGATOR_PLATFORM).isEmpty())
return defaultPlatform;
struct utsname osname;
static NeverDestroyed<String> platformName(uname(&osname) >= 0 ? String(osname.sysname) + " "_str + String(osname.machine) : emptyString());
return platformName;
static LazyNeverDestroyed<String> platformName;
static std::once_flag onceKey;
std::call_once(onceKey, [] {
struct utsname osname;
platformName.construct(uname(&osname) >= 0 ? String(osname.sysname) + " "_str + String(osname.machine) : String(""_s));
});
return platformName->isolatedCopy();
#elif PLATFORM(IOS_FAMILY)
return deviceName();
#elif OS(MAC_OS_X) && (CPU(PPC) || CPU(PPC64))
return "MacPPC"_s;
#elif OS(MAC_OS_X) && (CPU(X86) || CPU(X86_64))
return "MacIntel"_s;
#elif OS(WINDOWS)
return "Win32"_s;
#else
return defaultPlatform;
return ""_s;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/NavigatorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NavigatorBase : public RefCounted<NavigatorBase>, public ContextDestructio
static String appName();
String appVersion() const;
virtual const String& userAgent() const = 0;
virtual const String& platform() const;
virtual String platform() const;

static String appCodeName();
static String product();
Expand Down
12 changes: 8 additions & 4 deletions Source/WebCore/platform/ios/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ MGDeviceClass deviceClass()
return deviceClass;
}

const String& deviceName()
String deviceName()
{
#if TARGET_OS_IOS
static const NeverDestroyed<String> deviceName = adoptCF(static_cast<CFStringRef>(MGCopyAnswer(kMGQDeviceName, nullptr))).get();
static CFStringRef deviceName;
static std::once_flag onceKey;
std::call_once(onceKey, [] {
deviceName = static_cast<CFStringRef>(MGCopyAnswer(kMGQDeviceName, nullptr));
});
return deviceName;
#else
static const NeverDestroyed<String> deviceName { "iPhone"_s };
return "iPhone"_s;
#endif
return deviceName;
}

bool deviceHasIPadCapability()
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/ios/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
namespace WebCore {

WEBCORE_EXPORT MGDeviceClass deviceClass();
const WTF::String& deviceName();
String deviceName(); // Thread-safe.

// FIXME: Isn't this the same as deviceClass() == MGDeviceClassiPad?
bool deviceHasIPadCapability();
Expand Down
15 changes: 9 additions & 6 deletions Source/WebCore/platform/ios/UserAgentIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ static inline String deviceNameForUserAgent()
{
if (isClassic()) {
if (isClassicPad())
return "iPad";
return "iPhone";
return "iPad"_s;
return "iPhone"_s;
}

String name = deviceName();
static NeverDestroyed<String> name = [] {
auto name = deviceName();
#if PLATFORM(IOS_FAMILY_SIMULATOR)
size_t location = name.find(" Simulator");
if (location != notFound)
return name.substring(0, location);
size_t location = name.find(" Simulator");
if (location != notFound)
return name.substring(0, location);
#endif
return name;
}();
return name;
}

Expand Down

0 comments on commit 878faaa

Please sign in to comment.