Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump WebKit and re-enable IPInt #16227

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/tools/SetupWebKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")

if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION e1a802a2287edfe7f4046a9dd8307c8b59f5d816)
set(WEBKIT_VERSION 5ebbd7b2e6661972c40f816321863eb14b837feb)
endif()

if(WEBKIT_LOCAL)
Expand Down
11 changes: 9 additions & 2 deletions scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async function runTests() {
failure ||= result;
flaky ||= true;

if (attempt >= maxAttempts) {
if (attempt >= maxAttempts || isAlwaysFailure(error)) {
flaky = false;
failedResults.push(failure);
}
Expand Down Expand Up @@ -862,7 +862,7 @@ function isJavaScriptTest(path) {
* @returns {boolean}
*/
function isNodeParallelTest(testPath) {
return testPath.replaceAll(sep, "/").includes("js/node/test/parallel/")
return testPath.replaceAll(sep, "/").includes("js/node/test/parallel/");
}

/**
Expand Down Expand Up @@ -1541,6 +1541,13 @@ function getExitCode(outcome) {
return 1;
}

// A flaky segfault, sigtrap, or sigill must never be ignored.
// If it happens in CI, it will happen to our users.
function isAlwaysFailure(error) {
error = ((error || "") + "").toLowerCase().trim();
return error.includes("segmentation fault") || error.includes("sigill") || error.includes("sigtrap");
}

/**
* @param {string} signal
*/
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/bindings/BunDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BunInspectorConnection;

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

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

inspectorConnections->add(globalObject->scriptExecutionContext()->identifier(), Vector<BunInspectorConnection*, 8>());
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/BunPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace JSC;

class BunPlugin {
public:
using VirtualModuleMap = WTF::HashMap<String, JSC::Strong<JSC::JSObject>>;
using VirtualModuleMap = WTF::UncheckedKeyHashMap<String, JSC::Strong<JSC::JSObject>>;

// This is a list of pairs of regexps and functions to match against
class Group {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/DOMWrapperWorld-class.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {

private:
JSC::VM& m_vm;
HashSet<WindowProxy*> m_jsWindowProxies;
UncheckedKeyHashSet<WindowProxy*> m_jsWindowProxies;
DOMObjectWrapperMap m_wrappers;

String m_name;
Expand Down
3 changes: 3 additions & 0 deletions src/bun.js/bindings/InspectorLifecycleAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#include <JavaScriptCore/JSGlobalObjectDebuggable.h>
#include <JavaScriptCore/JSGlobalObjectInspectorController.h>
#include "ConsoleObject.h"
#include <wtf/TZoneMallocInlines.h>

namespace Inspector {

WTF_MAKE_TZONE_ALLOCATED_IMPL(InspectorLifecycleAgent);

// Zig bindings implementation
extern "C" {

Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/InspectorLifecycleAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class DisconnectReason;

class InspectorLifecycleAgent final : public InspectorAgentBase, public Inspector::LifecycleReporterBackendDispatcherHandler {
WTF_MAKE_NONCOPYABLE(InspectorLifecycleAgent);
WTF_MAKE_TZONE_ALLOCATED(InspectorLifecycleAgent);

public:
InspectorLifecycleAgent(JSC::JSGlobalObject&);
Expand Down
3 changes: 3 additions & 0 deletions src/bun.js/bindings/InspectorTestReporterAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#include "ZigGlobalObject.h"

#include "ModuleLoader.h"
#include <wtf/TZoneMallocInlines.h>

namespace Inspector {

WTF_MAKE_TZONE_ALLOCATED_IMPL(InspectorTestReporterAgent);

// Zig bindings implementation
extern "C" {

Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/InspectorTestReporterAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class DisconnectReason;

class InspectorTestReporterAgent final : public InspectorAgentBase, public Inspector::TestReporterBackendDispatcherHandler {
WTF_MAKE_NONCOPYABLE(InspectorTestReporterAgent);
WTF_MAKE_TZONE_ALLOCATED(InspectorTestReporterAgent);

public:
InspectorTestReporterAgent(JSC::JSGlobalObject&);
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/bindings/JSCTaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class JSCTaskScheduler {

public:
Lock m_lock;
HashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsKeepingEventLoopAlive;
HashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsOther;
UncheckedKeyHashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsKeepingEventLoopAlive;
UncheckedKeyHashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsOther;
};

}
78 changes: 67 additions & 11 deletions src/bun.js/bindings/ScriptExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,61 @@
#include "_libusockets.h"
#include "BunClientData.h"
#include "EventLoopTask.h"

#include "BunBroadcastChannelRegistry.h"
#include <wtf/LazyRef.h>
extern "C" void Bun__startLoop(us_loop_t* loop);

namespace WebCore {
static constexpr ScriptExecutionContextIdentifier INITIAL_IDENTIFIER_INTERNAL = 1;

static std::atomic<unsigned> lastUniqueIdentifier = 0;
static std::atomic<unsigned> lastUniqueIdentifier = INITIAL_IDENTIFIER_INTERNAL;

#if ASSERT_ENABLED
static ScriptExecutionContextIdentifier initialIdentifier()
{
static bool hasCalledInitialIdentifier = false;
ASSERT_WITH_MESSAGE(!hasCalledInitialIdentifier, "ScriptExecutionContext::initialIdentifier() cannot be called more than once. Use generateIdentifier() instead.");
hasCalledInitialIdentifier = true;
return INITIAL_IDENTIFIER_INTERNAL;
}
#else
static ScriptExecutionContextIdentifier initialIdentifier()
{
return INITIAL_IDENTIFIER_INTERNAL;
}
#endif

DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ScriptExecutionContext);

ScriptExecutionContext::ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject)
: m_vm(vm)
, m_globalObject(globalObject)
, m_identifier(initialIdentifier())
, m_broadcastChannelRegistry([](auto& owner, auto& lazyRef) {
lazyRef.set(BunBroadcastChannelRegistry::create());
})
{
relaxAdoptionRequirement();
addToContextsMap();
}

ScriptExecutionContext::ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject, ScriptExecutionContextIdentifier identifier)
: m_vm(vm)
, m_globalObject(globalObject)
, m_identifier(identifier == std::numeric_limits<int32_t>::max() ? ++lastUniqueIdentifier : identifier)
, m_broadcastChannelRegistry([](auto& owner, auto& lazyRef) {
lazyRef.set(BunBroadcastChannelRegistry::create());
})
{
relaxAdoptionRequirement();
addToContextsMap();
}

WTF_MAKE_ISO_ALLOCATED_IMPL(EventLoopTask);

#if !ENABLE(MALLOC_BREAKDOWN)
WTF_MAKE_ISO_ALLOCATED_IMPL(ScriptExecutionContext);
#endif

static Lock allScriptExecutionContextsMapLock;
static HashMap<ScriptExecutionContextIdentifier, ScriptExecutionContext*>& allScriptExecutionContextsMap() WTF_REQUIRES_LOCK(allScriptExecutionContextsMapLock)
Expand Down Expand Up @@ -84,17 +130,24 @@ ScriptExecutionContext::~ScriptExecutionContext()
{
checkConsistency();

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

auto postMessageCompletionHandlers = WTFMove(m_processMessageWithMessagePortsSoonHandlers);
for (auto& completionHandler : postMessageCompletionHandlers)
completionHandler();

while (auto* destructionObserver = m_destructionObservers.takeAny())
destructionObserver->contextDestroyed();

#if ASSERT_ENABLED
m_inScriptExecutionContextDestructor = false;
#endif // ASSERT_ENABLED
}

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

void ScriptExecutionContext::didCreateDestructionObserver(ContextDestructionObserver& observer)
{
// ASSERT(!m_inScriptExecutionContextDestructor);
#if ASSERT_ENABLED
ASSERT(!m_inScriptExecutionContextDestructor);
#endif // ASSERT_ENABLED
m_destructionObservers.add(&observer);
}

void ScriptExecutionContext::willDestroyDestructionObserver(ContextDestructionObserver& observer)
{
#if ASSERT_ENABLED
ASSERT(!m_inScriptExecutionContextDestructor);
#endif // ASSERT_ENABLED
m_destructionObservers.remove(&observer);
}

Expand Down Expand Up @@ -212,16 +270,14 @@ void ScriptExecutionContext::dispatchMessagePortEvents()

void ScriptExecutionContext::checkConsistency() const
{
// for (auto* messagePort : m_messagePorts)
// ASSERT(messagePort->scriptExecutionContext() == this);
#if ASSERT_ENABLED
for (auto* messagePort : m_messagePorts)
ASSERT(messagePort->scriptExecutionContext() == this);

// for (auto* destructionObserver : m_destructionObservers)
// ASSERT(destructionObserver->scriptExecutionContext() == this);
for (auto* destructionObserver : m_destructionObservers)
ASSERT(destructionObserver->scriptExecutionContext() == this);

// for (auto* activeDOMObject : m_activeDOMObjects) {
// ASSERT(activeDOMObject->scriptExecutionContext() == this);
// activeDOMObject->assertSuspendIfNeededWasCalled();
// }
#endif // ASSERT_ENABLED
}

void ScriptExecutionContext::createdMessagePort(MessagePort& messagePort)
Expand Down
44 changes: 21 additions & 23 deletions src/bun.js/bindings/ScriptExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "root.h"
#include "ActiveDOMObject.h"
#include "ContextDestructionObserver.h"
#include "BunBroadcastChannelRegistry.h"
#include <wtf/CrossThreadTask.h>
#include <wtf/Function.h>
#include <wtf/HashSet.h>
Expand All @@ -12,7 +11,9 @@
#include <wtf/text/WTFString.h>
#include <wtf/CompletionHandler.h>
#include "CachedScript.h"
#include "wtf/ThreadSafeWeakPtr.h"
#include <wtf/URL.h>
#include <wtf/LazyRef.h>

namespace uWS {
template<bool isServer, bool isClient, typename UserData>
Expand All @@ -26,34 +27,25 @@ struct us_loop_t;
namespace WebCore {

class WebSocket;
class BunBroadcastChannelRegistry;
class MessagePort;

class ScriptExecutionContext;
class EventLoopTask;

using ScriptExecutionContextIdentifier = uint32_t;
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ScriptExecutionContext);

class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext>, public RefCounted<ScriptExecutionContext> {
#if ENABLE(MALLOC_BREAKDOWN)
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ScriptExecutionContext);
#else
WTF_MAKE_ISO_ALLOCATED(ScriptExecutionContext);
#endif

public:
ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject)
: m_vm(vm)
, m_globalObject(globalObject)
, m_identifier(0)
, m_broadcastChannelRegistry(BunBroadcastChannelRegistry::create())
{
regenerateIdentifier();
}

ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject, ScriptExecutionContextIdentifier identifier)
: m_vm(vm)
, m_globalObject(globalObject)
, m_identifier(identifier)
, m_broadcastChannelRegistry(BunBroadcastChannelRegistry::create())
{
addToContextsMap();
}
ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject);
ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject, ScriptExecutionContextIdentifier identifier);

~ScriptExecutionContext();

Expand All @@ -77,6 +69,8 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
static ScriptExecutionContext* getScriptExecutionContext(ScriptExecutionContextIdentifier identifier);
void refEventLoop();
void unrefEventLoop();
using RefCounted::deref;
using RefCounted::ref;

const WTF::URL& url() const
{
Expand Down Expand Up @@ -156,7 +150,7 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
m_vm = &globalObject->vm();
}

BunBroadcastChannelRegistry& broadcastChannelRegistry() { return m_broadcastChannelRegistry; }
BunBroadcastChannelRegistry& broadcastChannelRegistry() { return m_broadcastChannelRegistry.get(*this); }

static ScriptExecutionContext* getMainThreadScriptExecutionContext();

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

HashSet<MessagePort*> m_messagePorts;
HashSet<ContextDestructionObserver*> m_destructionObservers;
UncheckedKeyHashSet<MessagePort*> m_messagePorts;
UncheckedKeyHashSet<ContextDestructionObserver*> m_destructionObservers;
Vector<CompletionHandler<void()>> m_processMessageWithMessagePortsSoonHandlers;
Ref<BunBroadcastChannelRegistry> m_broadcastChannelRegistry;
LazyRef<ScriptExecutionContext, BunBroadcastChannelRegistry> m_broadcastChannelRegistry;

bool m_willProcessMessageWithMessagePortsSoon { false };

Expand Down Expand Up @@ -202,6 +196,10 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
return m_connected_client_websockets_ctx;
}
}

#if ASSERT_ENABLED
bool m_inScriptExecutionContextDestructor = false;
#endif
};

ScriptExecutionContext* executionContext(JSC::JSGlobalObject*);
Expand Down
Loading
Loading