Skip to content

Commit c1218b2

Browse files
190nJarred-Sumnerheimskr
authored
Bump WebKit and re-enable IPInt (#16227)
Co-authored-by: Jarred Sumner <[email protected]> Co-authored-by: Kai Tamkun <[email protected]>
1 parent 77a5906 commit c1218b2

32 files changed

+312
-191
lines changed

Diff for: cmake/tools/SetupWebKit.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
22
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
33

44
if(NOT WEBKIT_VERSION)
5-
set(WEBKIT_VERSION e1a802a2287edfe7f4046a9dd8307c8b59f5d816)
5+
set(WEBKIT_VERSION 9e3b60e4a6438d20ee6f8aa5bec6b71d2b7d213f)
66
endif()
77

88
string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX)

Diff for: scripts/runner.node.mjs

+8-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async function runTests() {
199199
failure ||= result;
200200
flaky ||= true;
201201

202-
if (attempt >= maxAttempts) {
202+
if (attempt >= maxAttempts || isAlwaysFailure(error)) {
203203
flaky = false;
204204
failedResults.push(failure);
205205
}
@@ -1552,6 +1552,13 @@ function getExitCode(outcome) {
15521552
return 1;
15531553
}
15541554

1555+
// A flaky segfault, sigtrap, or sigill must never be ignored.
1556+
// If it happens in CI, it will happen to our users.
1557+
function isAlwaysFailure(error) {
1558+
error = ((error || "") + "").toLowerCase().trim();
1559+
return error.includes("segmentation fault") || error.includes("sigill") || error.includes("sigtrap");
1560+
}
1561+
15551562
/**
15561563
* @param {string} signal
15571564
*/

Diff for: src/bun.js/bindings/BunDebugger.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BunInspectorConnection;
2626

2727
static WebCore::ScriptExecutionContext* debuggerScriptExecutionContext = nullptr;
2828
static WTF::Lock inspectorConnectionsLock = WTF::Lock();
29-
static WTF::HashMap<ScriptExecutionContextIdentifier, Vector<BunInspectorConnection*, 8>>* inspectorConnections = nullptr;
29+
static WTF::UncheckedKeyHashMap<ScriptExecutionContextIdentifier, Vector<BunInspectorConnection*, 8>>* inspectorConnections = nullptr;
3030

3131
static bool waitingForConnection = false;
3232
extern "C" void Debugger__didConnect();
@@ -487,7 +487,7 @@ extern "C" unsigned int Bun__createJSDebugger(Zig::GlobalObject* globalObject)
487487
{
488488
Locker<Lock> locker(inspectorConnectionsLock);
489489
if (inspectorConnections == nullptr) {
490-
inspectorConnections = new WTF::HashMap<ScriptExecutionContextIdentifier, Vector<BunInspectorConnection*, 8>>();
490+
inspectorConnections = new WTF::UncheckedKeyHashMap<ScriptExecutionContextIdentifier, Vector<BunInspectorConnection*, 8>>();
491491
}
492492

493493
inspectorConnections->add(globalObject->scriptExecutionContext()->identifier(), Vector<BunInspectorConnection*, 8>());

Diff for: src/bun.js/bindings/BunPlugin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace JSC;
1515

1616
class BunPlugin {
1717
public:
18-
using VirtualModuleMap = WTF::HashMap<String, JSC::Strong<JSC::JSObject>>;
18+
using VirtualModuleMap = WTF::UncheckedKeyHashMap<String, JSC::Strong<JSC::JSObject>>;
1919

2020
// This is a list of pairs of regexps and functions to match against
2121
class Group {

Diff for: src/bun.js/bindings/DOMWrapperWorld-class.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
5050

5151
private:
5252
JSC::VM& m_vm;
53-
HashSet<WindowProxy*> m_jsWindowProxies;
53+
UncheckedKeyHashSet<WindowProxy*> m_jsWindowProxies;
5454
DOMObjectWrapperMap m_wrappers;
5555

5656
String m_name;

Diff for: src/bun.js/bindings/InspectorLifecycleAgent.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
#include <JavaScriptCore/JSGlobalObjectDebuggable.h>
1212
#include <JavaScriptCore/JSGlobalObjectInspectorController.h>
1313
#include "ConsoleObject.h"
14+
#include <wtf/TZoneMallocInlines.h>
1415

1516
namespace Inspector {
1617

18+
WTF_MAKE_TZONE_ALLOCATED_IMPL(InspectorLifecycleAgent);
19+
1720
// Zig bindings implementation
1821
extern "C" {
1922

Diff for: src/bun.js/bindings/InspectorLifecycleAgent.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum class DisconnectReason;
1818

1919
class InspectorLifecycleAgent final : public InspectorAgentBase, public Inspector::LifecycleReporterBackendDispatcherHandler {
2020
WTF_MAKE_NONCOPYABLE(InspectorLifecycleAgent);
21+
WTF_MAKE_TZONE_ALLOCATED(InspectorLifecycleAgent);
2122

2223
public:
2324
InspectorLifecycleAgent(JSC::JSGlobalObject&);

Diff for: src/bun.js/bindings/InspectorTestReporterAgent.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
#include "ZigGlobalObject.h"
1212

1313
#include "ModuleLoader.h"
14+
#include <wtf/TZoneMallocInlines.h>
1415

1516
namespace Inspector {
1617

18+
WTF_MAKE_TZONE_ALLOCATED_IMPL(InspectorTestReporterAgent);
19+
1720
// Zig bindings implementation
1821
extern "C" {
1922

Diff for: src/bun.js/bindings/InspectorTestReporterAgent.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum class DisconnectReason;
1818

1919
class InspectorTestReporterAgent final : public InspectorAgentBase, public Inspector::TestReporterBackendDispatcherHandler {
2020
WTF_MAKE_NONCOPYABLE(InspectorTestReporterAgent);
21+
WTF_MAKE_TZONE_ALLOCATED(InspectorTestReporterAgent);
2122

2223
public:
2324
InspectorTestReporterAgent(JSC::JSGlobalObject&);

Diff for: src/bun.js/bindings/JSCTaskScheduler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class JSCTaskScheduler {
2222

2323
public:
2424
Lock m_lock;
25-
HashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsKeepingEventLoopAlive;
26-
HashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsOther;
25+
UncheckedKeyHashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsKeepingEventLoopAlive;
26+
UncheckedKeyHashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsOther;
2727
};
2828

2929
}

Diff for: src/bun.js/bindings/ScriptExecutionContext.cpp

+67-11
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,61 @@
77
#include "_libusockets.h"
88
#include "BunClientData.h"
99
#include "EventLoopTask.h"
10-
10+
#include "BunBroadcastChannelRegistry.h"
11+
#include <wtf/LazyRef.h>
1112
extern "C" void Bun__startLoop(us_loop_t* loop);
1213

1314
namespace WebCore {
15+
static constexpr ScriptExecutionContextIdentifier INITIAL_IDENTIFIER_INTERNAL = 1;
1416

15-
static std::atomic<unsigned> lastUniqueIdentifier = 0;
17+
static std::atomic<unsigned> lastUniqueIdentifier = INITIAL_IDENTIFIER_INTERNAL;
18+
19+
#if ASSERT_ENABLED
20+
static ScriptExecutionContextIdentifier initialIdentifier()
21+
{
22+
static bool hasCalledInitialIdentifier = false;
23+
ASSERT_WITH_MESSAGE(!hasCalledInitialIdentifier, "ScriptExecutionContext::initialIdentifier() cannot be called more than once. Use generateIdentifier() instead.");
24+
hasCalledInitialIdentifier = true;
25+
return INITIAL_IDENTIFIER_INTERNAL;
26+
}
27+
#else
28+
static ScriptExecutionContextIdentifier initialIdentifier()
29+
{
30+
return INITIAL_IDENTIFIER_INTERNAL;
31+
}
32+
#endif
33+
34+
DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ScriptExecutionContext);
35+
36+
ScriptExecutionContext::ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject)
37+
: m_vm(vm)
38+
, m_globalObject(globalObject)
39+
, m_identifier(initialIdentifier())
40+
, m_broadcastChannelRegistry([](auto& owner, auto& lazyRef) {
41+
lazyRef.set(BunBroadcastChannelRegistry::create());
42+
})
43+
{
44+
relaxAdoptionRequirement();
45+
addToContextsMap();
46+
}
47+
48+
ScriptExecutionContext::ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject, ScriptExecutionContextIdentifier identifier)
49+
: m_vm(vm)
50+
, m_globalObject(globalObject)
51+
, m_identifier(identifier == std::numeric_limits<int32_t>::max() ? ++lastUniqueIdentifier : identifier)
52+
, m_broadcastChannelRegistry([](auto& owner, auto& lazyRef) {
53+
lazyRef.set(BunBroadcastChannelRegistry::create());
54+
})
55+
{
56+
relaxAdoptionRequirement();
57+
addToContextsMap();
58+
}
1659

1760
WTF_MAKE_ISO_ALLOCATED_IMPL(EventLoopTask);
61+
62+
#if !ENABLE(MALLOC_BREAKDOWN)
1863
WTF_MAKE_ISO_ALLOCATED_IMPL(ScriptExecutionContext);
64+
#endif
1965

2066
static Lock allScriptExecutionContextsMapLock;
2167
static HashMap<ScriptExecutionContextIdentifier, ScriptExecutionContext*>& allScriptExecutionContextsMap() WTF_REQUIRES_LOCK(allScriptExecutionContextsMapLock)
@@ -84,17 +130,24 @@ ScriptExecutionContext::~ScriptExecutionContext()
84130
{
85131
checkConsistency();
86132

133+
#if ASSERT_ENABLED
87134
{
88135
Locker locker { allScriptExecutionContextsMapLock };
89136
ASSERT_WITH_MESSAGE(!allScriptExecutionContextsMap().contains(m_identifier), "A ScriptExecutionContext subclass instance implementing postTask should have already removed itself from the map");
90137
}
138+
m_inScriptExecutionContextDestructor = true;
139+
#endif // ASSERT_ENABLED
91140

92141
auto postMessageCompletionHandlers = WTFMove(m_processMessageWithMessagePortsSoonHandlers);
93142
for (auto& completionHandler : postMessageCompletionHandlers)
94143
completionHandler();
95144

96145
while (auto* destructionObserver = m_destructionObservers.takeAny())
97146
destructionObserver->contextDestroyed();
147+
148+
#if ASSERT_ENABLED
149+
m_inScriptExecutionContextDestructor = false;
150+
#endif // ASSERT_ENABLED
98151
}
99152

100153
bool ScriptExecutionContext::postTaskTo(ScriptExecutionContextIdentifier identifier, Function<void(ScriptExecutionContext&)>&& task)
@@ -111,12 +164,17 @@ bool ScriptExecutionContext::postTaskTo(ScriptExecutionContextIdentifier identif
111164

112165
void ScriptExecutionContext::didCreateDestructionObserver(ContextDestructionObserver& observer)
113166
{
114-
// ASSERT(!m_inScriptExecutionContextDestructor);
167+
#if ASSERT_ENABLED
168+
ASSERT(!m_inScriptExecutionContextDestructor);
169+
#endif // ASSERT_ENABLED
115170
m_destructionObservers.add(&observer);
116171
}
117172

118173
void ScriptExecutionContext::willDestroyDestructionObserver(ContextDestructionObserver& observer)
119174
{
175+
#if ASSERT_ENABLED
176+
ASSERT(!m_inScriptExecutionContextDestructor);
177+
#endif // ASSERT_ENABLED
120178
m_destructionObservers.remove(&observer);
121179
}
122180

@@ -212,16 +270,14 @@ void ScriptExecutionContext::dispatchMessagePortEvents()
212270

213271
void ScriptExecutionContext::checkConsistency() const
214272
{
215-
// for (auto* messagePort : m_messagePorts)
216-
// ASSERT(messagePort->scriptExecutionContext() == this);
273+
#if ASSERT_ENABLED
274+
for (auto* messagePort : m_messagePorts)
275+
ASSERT(messagePort->scriptExecutionContext() == this);
217276

218-
// for (auto* destructionObserver : m_destructionObservers)
219-
// ASSERT(destructionObserver->scriptExecutionContext() == this);
277+
for (auto* destructionObserver : m_destructionObservers)
278+
ASSERT(destructionObserver->scriptExecutionContext() == this);
220279

221-
// for (auto* activeDOMObject : m_activeDOMObjects) {
222-
// ASSERT(activeDOMObject->scriptExecutionContext() == this);
223-
// activeDOMObject->assertSuspendIfNeededWasCalled();
224-
// }
280+
#endif // ASSERT_ENABLED
225281
}
226282

227283
void ScriptExecutionContext::createdMessagePort(MessagePort& messagePort)

Diff for: src/bun.js/bindings/ScriptExecutionContext.h

+21-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "root.h"
44
#include "ActiveDOMObject.h"
55
#include "ContextDestructionObserver.h"
6-
#include "BunBroadcastChannelRegistry.h"
76
#include <wtf/CrossThreadTask.h>
87
#include <wtf/Function.h>
98
#include <wtf/HashSet.h>
@@ -12,7 +11,9 @@
1211
#include <wtf/text/WTFString.h>
1312
#include <wtf/CompletionHandler.h>
1413
#include "CachedScript.h"
14+
#include "wtf/ThreadSafeWeakPtr.h"
1515
#include <wtf/URL.h>
16+
#include <wtf/LazyRef.h>
1617

1718
namespace uWS {
1819
template<bool isServer, bool isClient, typename UserData>
@@ -26,34 +27,25 @@ struct us_loop_t;
2627
namespace WebCore {
2728

2829
class WebSocket;
30+
class BunBroadcastChannelRegistry;
2931
class MessagePort;
3032

3133
class ScriptExecutionContext;
3234
class EventLoopTask;
3335

3436
using ScriptExecutionContextIdentifier = uint32_t;
37+
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ScriptExecutionContext);
3538

36-
class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
39+
class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext>, public RefCounted<ScriptExecutionContext> {
40+
#if ENABLE(MALLOC_BREAKDOWN)
41+
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ScriptExecutionContext);
42+
#else
3743
WTF_MAKE_ISO_ALLOCATED(ScriptExecutionContext);
44+
#endif
3845

3946
public:
40-
ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject)
41-
: m_vm(vm)
42-
, m_globalObject(globalObject)
43-
, m_identifier(0)
44-
, m_broadcastChannelRegistry(BunBroadcastChannelRegistry::create())
45-
{
46-
regenerateIdentifier();
47-
}
48-
49-
ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject, ScriptExecutionContextIdentifier identifier)
50-
: m_vm(vm)
51-
, m_globalObject(globalObject)
52-
, m_identifier(identifier)
53-
, m_broadcastChannelRegistry(BunBroadcastChannelRegistry::create())
54-
{
55-
addToContextsMap();
56-
}
47+
ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject);
48+
ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject, ScriptExecutionContextIdentifier identifier);
5749

5850
~ScriptExecutionContext();
5951

@@ -77,6 +69,8 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
7769
static ScriptExecutionContext* getScriptExecutionContext(ScriptExecutionContextIdentifier identifier);
7870
void refEventLoop();
7971
void unrefEventLoop();
72+
using RefCounted::deref;
73+
using RefCounted::ref;
8074

8175
const WTF::URL& url() const
8276
{
@@ -156,7 +150,7 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
156150
m_vm = &globalObject->vm();
157151
}
158152

159-
BunBroadcastChannelRegistry& broadcastChannelRegistry() { return m_broadcastChannelRegistry; }
153+
BunBroadcastChannelRegistry& broadcastChannelRegistry() { return m_broadcastChannelRegistry.get(*this); }
160154

161155
static ScriptExecutionContext* getMainThreadScriptExecutionContext();
162156

@@ -166,10 +160,10 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
166160
WTF::URL m_url = WTF::URL();
167161
ScriptExecutionContextIdentifier m_identifier;
168162

169-
HashSet<MessagePort*> m_messagePorts;
170-
HashSet<ContextDestructionObserver*> m_destructionObservers;
163+
UncheckedKeyHashSet<MessagePort*> m_messagePorts;
164+
UncheckedKeyHashSet<ContextDestructionObserver*> m_destructionObservers;
171165
Vector<CompletionHandler<void()>> m_processMessageWithMessagePortsSoonHandlers;
172-
Ref<BunBroadcastChannelRegistry> m_broadcastChannelRegistry;
166+
LazyRef<ScriptExecutionContext, BunBroadcastChannelRegistry> m_broadcastChannelRegistry;
173167

174168
bool m_willProcessMessageWithMessagePortsSoon { false };
175169

@@ -202,6 +196,10 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
202196
return m_connected_client_websockets_ctx;
203197
}
204198
}
199+
200+
#if ASSERT_ENABLED
201+
bool m_inScriptExecutionContextDestructor = false;
202+
#endif
205203
};
206204

207205
ScriptExecutionContext* executionContext(JSC::JSGlobalObject*);

0 commit comments

Comments
 (0)