diff options
author | 2023-06-14 03:24:39 -0700 | |
---|---|---|
committer | 2023-06-14 03:24:39 -0700 | |
commit | 333b3f6bebda76a16bf5faf689677d175d0a4425 (patch) | |
tree | 9cd8ab051920b4d37d845ef3d87f5506677d5f7e | |
parent | b7ff3b0745a8ca9eec4c3c2590fb10203d7a2348 (diff) | |
download | bun-333b3f6bebda76a16bf5faf689677d175d0a4425.tar.gz bun-333b3f6bebda76a16bf5faf689677d175d0a4425.tar.zst bun-333b3f6bebda76a16bf5faf689677d175d0a4425.zip |
Prepare to support webkit debug build assertions
-rw-r--r-- | src/bun.js/bindings/BunPlugin.cpp | 4 | ||||
-rw-r--r-- | src/bun.js/bindings/CallSitePrototype.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/ErrorStackTrace.h | 1 | ||||
-rw-r--r-- | src/bun.js/bindings/ExceptionOr.h | 6 | ||||
-rw-r--r-- | src/bun.js/bindings/JSBundlerPlugin.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/EventEmitter.cpp | 1 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/EventTarget.cpp | 1 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/Node.h | 31 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/WebSocket.cpp | 36 |
9 files changed, 26 insertions, 58 deletions
diff --git a/src/bun.js/bindings/BunPlugin.cpp b/src/bun.js/bindings/BunPlugin.cpp index ad4039336..066cf82fd 100644 --- a/src/bun.js/bindings/BunPlugin.cpp +++ b/src/bun.js/bindings/BunPlugin.cpp @@ -49,7 +49,7 @@ static EncodedJSValue jsFunctionAppendOnLoadPluginBody(JSC::JSGlobalObject* glob auto clientData = WebCore::clientData(vm); auto& builtinNames = clientData->builtinNames(); JSC::RegExpObject* filter = nullptr; - if (JSValue filterValue = filterObject->getIfPropertyExists(globalObject, builtinNames.filterPublicName())) { + if (JSValue filterValue = filterObject->getIfPropertyExists(globalObject, Identifier::fromString(vm, "filter"_s))) { if (filterValue.isCell() && filterValue.asCell()->inherits<JSC::RegExpObject>()) filter = jsCast<JSC::RegExpObject*>(filterValue); } @@ -101,7 +101,7 @@ static EncodedJSValue jsFunctionAppendOnResolvePluginBody(JSC::JSGlobalObject* g auto clientData = WebCore::clientData(vm); auto& builtinNames = clientData->builtinNames(); JSC::RegExpObject* filter = nullptr; - if (JSValue filterValue = filterObject->getIfPropertyExists(globalObject, builtinNames.filterPublicName())) { + if (JSValue filterValue = filterObject->getIfPropertyExists(globalObject, Identifier::fromString(vm, "filter"_s))) { if (filterValue.isCell() && filterValue.asCell()->inherits<JSC::RegExpObject>()) filter = jsCast<JSC::RegExpObject*>(filterValue); } diff --git a/src/bun.js/bindings/CallSitePrototype.cpp b/src/bun.js/bindings/CallSitePrototype.cpp index faaf571e2..f3e365cb0 100644 --- a/src/bun.js/bindings/CallSitePrototype.cpp +++ b/src/bun.js/bindings/CallSitePrototype.cpp @@ -89,7 +89,7 @@ const JSC::ClassInfo CallSitePrototype::s_info = { "CallSite"_s, &Base::s_info, void CallSitePrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); - ASSERT(inherits(vm, info())); + ASSERT(inherits(info())); reifyStaticProperties(vm, CallSite::info(), CallSitePrototypeTableValues, *this); JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); diff --git a/src/bun.js/bindings/ErrorStackTrace.h b/src/bun.js/bindings/ErrorStackTrace.h index a8a6a192f..1284376a4 100644 --- a/src/bun.js/bindings/ErrorStackTrace.h +++ b/src/bun.js/bindings/ErrorStackTrace.h @@ -94,7 +94,6 @@ public: bool hasBytecodeIndex() const { return (m_bytecodeIndex.offset() != UINT_MAX) && !m_isWasmFrame; } JSC::BytecodeIndex bytecodeIndex() const { - ASSERT(hasBytecodeOffset()); return m_bytecodeIndex; } diff --git a/src/bun.js/bindings/ExceptionOr.h b/src/bun.js/bindings/ExceptionOr.h index f3378466e..3bbc641a1 100644 --- a/src/bun.js/bindings/ExceptionOr.h +++ b/src/bun.js/bindings/ExceptionOr.h @@ -116,25 +116,21 @@ template<typename ReturnType> inline bool ExceptionOr<ReturnType>::hasException( template<typename ReturnType> inline const Exception& ExceptionOr<ReturnType>::exception() const { - ASSERT(!m_wasReleased); return m_value.error(); } template<typename ReturnType> inline Exception ExceptionOr<ReturnType>::releaseException() { - ASSERT(!std::exchange(m_wasReleased, true)); return WTFMove(m_value.error()); } template<typename ReturnType> inline const ReturnType& ExceptionOr<ReturnType>::returnValue() const { - ASSERT(!m_wasReleased); return m_value.value(); } template<typename ReturnType> inline ReturnType ExceptionOr<ReturnType>::releaseReturnValue() { - ASSERT(!std::exchange(m_wasReleased, true)); return WTFMove(m_value.value()); } @@ -185,13 +181,11 @@ inline bool ExceptionOr<void>::hasException() const inline const Exception& ExceptionOr<void>::exception() const { - ASSERT(!m_wasReleased); return m_value.error(); } inline Exception ExceptionOr<void>::releaseException() { - ASSERT(!std::exchange(m_wasReleased, true)); return WTFMove(m_value.error()); } diff --git a/src/bun.js/bindings/JSBundlerPlugin.cpp b/src/bun.js/bindings/JSBundlerPlugin.cpp index e93556963..cae6a4b22 100644 --- a/src/bun.js/bindings/JSBundlerPlugin.cpp +++ b/src/bun.js/bindings/JSBundlerPlugin.cpp @@ -239,7 +239,7 @@ JSC_DEFINE_HOST_FUNCTION(jsBundlerPluginFunction_onResolveAsync, (JSC::JSGlobalO void JSBundlerPlugin::finishCreation(JSC::VM& vm) { Base::finishCreation(vm); - ASSERT(inherits(vm, info())); + ASSERT(inherits(info())); this->onLoadFunction.initLater( [](const JSC::LazyProperty<JSBundlerPlugin, JSC::JSFunction>::Initializer& init) { auto& vm = init.vm; diff --git a/src/bun.js/bindings/webcore/EventEmitter.cpp b/src/bun.js/bindings/webcore/EventEmitter.cpp index 4ea10587e..0650d624c 100644 --- a/src/bun.js/bindings/webcore/EventEmitter.cpp +++ b/src/bun.js/bindings/webcore/EventEmitter.cpp @@ -171,7 +171,6 @@ Vector<JSObject*> EventEmitter::getListeners(const Identifier& eventType) // https://dom.spec.whatwg.org/#concept-event-listener-invoke void EventEmitter::fireEventListeners(const Identifier& eventType, const MarkedArgumentBuffer& arguments) { - ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::isEventAllowedInMainThread()); auto* data = eventTargetData(); if (!data) diff --git a/src/bun.js/bindings/webcore/EventTarget.cpp b/src/bun.js/bindings/webcore/EventTarget.cpp index cc2113ec9..9fb875595 100644 --- a/src/bun.js/bindings/webcore/EventTarget.cpp +++ b/src/bun.js/bindings/webcore/EventTarget.cpp @@ -261,7 +261,6 @@ static const AtomString& legacyType(const Event& event) // https://dom.spec.whatwg.org/#concept-event-listener-invoke void EventTarget::fireEventListeners(Event& event, EventInvokePhase phase) { - ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::isEventAllowedInMainThread()); ASSERT(event.isInitialized()); auto* data = eventTargetData(); diff --git a/src/bun.js/bindings/webcore/Node.h b/src/bun.js/bindings/webcore/Node.h index df9917a25..509e04192 100644 --- a/src/bun.js/bindings/webcore/Node.h +++ b/src/bun.js/bindings/webcore/Node.h @@ -75,42 +75,20 @@ public: // mutable OptionSet<NodeFlag> m_nodeFlags; }; -#if ASSERT_ENABLED - -inline void adopted(Node* node) -{ - if (!node) - return; - ASSERT(!node->m_deletionHasBegun); - ASSERT(!node->m_inRemovedLastRefFunction); - node->m_adoptionIsRequired = false; -} - -#endif // ASSERT_ENABLED - ALWAYS_INLINE void Node::ref() const { - ASSERT(isMainThread()); - ASSERT(!m_deletionHasBegun); - ASSERT(!m_inRemovedLastRefFunction); - ASSERT(!m_adoptionIsRequired); + m_refCountAndParentBit += s_refCountIncrement; } ALWAYS_INLINE void Node::deref() const { - ASSERT(isMainThread()); - ASSERT(refCount()); - ASSERT(!m_deletionHasBegun); - ASSERT(!m_inRemovedLastRefFunction); - ASSERT(!m_adoptionIsRequired); + auto updatedRefCount = m_refCountAndParentBit - s_refCountIncrement; if (!updatedRefCount) { // Don't update m_refCountAndParentBit to avoid double destruction through use of Ref<T>/RefPtr<T>. // (This is a security mitigation in case of programmer error. It will ASSERT in debug builds.) -#if ASSERT_ENABLED - m_inRemovedLastRefFunction = true; -#endif + const_cast<Node&>(*this).removedLastRef(); return; } @@ -119,8 +97,7 @@ ALWAYS_INLINE void Node::deref() const ALWAYS_INLINE bool Node::hasOneRef() const { - ASSERT(!m_deletionHasBegun); - ASSERT(!m_inRemovedLastRefFunction); + return refCount() == 1; } diff --git a/src/bun.js/bindings/webcore/WebSocket.cpp b/src/bun.js/bindings/webcore/WebSocket.cpp index e19145fc7..a346175df 100644 --- a/src/bun.js/bindings/webcore/WebSocket.cpp +++ b/src/bun.js/bindings/webcore/WebSocket.cpp @@ -267,7 +267,7 @@ static String resourceName(const URL& url) static String hostName(const URL& url, bool secure) { - ASSERT(url.protocolIs("wss") == secure); + // ASSERT(url.protocolIs("wss"_s) == secure); if (url.port() && ((!secure && url.port().value() != 80) || (secure && url.port().value() != 443))) return makeString(asASCIILowercase(url.host()), ':', url.port().value()); return url.host().convertToASCIILowercase(); @@ -280,7 +280,7 @@ ExceptionOr<void> WebSocket::connect(const String& url, const Vector<String>& pr ExceptionOr<void> WebSocket::connect(const String& url, const Vector<String>& protocols, std::optional<FetchHeaders::Init>&& headersInit) { - LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data()); + // LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data()); m_url = URL { url }; ASSERT(scriptExecutionContext()); @@ -446,7 +446,7 @@ ExceptionOr<void> WebSocket::connect(const String& url, const Vector<String>& pr ExceptionOr<void> WebSocket::send(const String& message) { - LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.utf8().data()); + // LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.utf8().data()); if (m_state == CONNECTING) return Exception { InvalidStateError }; // No exception is raised if the connection was once established but has subsequently been closed. @@ -466,7 +466,7 @@ ExceptionOr<void> WebSocket::send(const String& message) ExceptionOr<void> WebSocket::send(ArrayBuffer& binaryData) { - LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, &binaryData); + // LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, &binaryData); if (m_state == CONNECTING) return Exception { InvalidStateError }; if (m_state == CLOSING || m_state == CLOSED) { @@ -484,7 +484,7 @@ ExceptionOr<void> WebSocket::send(ArrayBuffer& binaryData) ExceptionOr<void> WebSocket::send(ArrayBufferView& arrayBufferView) { - LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, &arrayBufferView); + // LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, &arrayBufferView); if (m_state == CONNECTING) return Exception { InvalidStateError }; @@ -506,7 +506,7 @@ ExceptionOr<void> WebSocket::send(ArrayBufferView& arrayBufferView) // ExceptionOr<void> WebSocket::send(Blob& binaryData) // { -// LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData.url().stringCenterEllipsizedToLength().utf8().data()); +// LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData.url().stringCenterEllipsizedToLength().utf8().data()); // if (m_state == CONNECTING) // return Exception { InvalidStateError }; // if (m_state == CLOSING || m_state == CLOSED) { @@ -587,10 +587,10 @@ void WebSocket::sendWebSocketString(const String& message) ExceptionOr<void> WebSocket::close(std::optional<unsigned short> optionalCode, const String& reason) { int code = optionalCode ? optionalCode.value() : static_cast<int>(0); - if (code == 0) - LOG(Network, "WebSocket %p close() without code and reason", this); - else { - LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code, reason.utf8().data()); + if (code == 0) { + // LOG(Network, "WebSocket %p close() without code and reason", this); + } else { + // LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code, reason.utf8().data()); // if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocketChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel::CloseEventCodeMaximumUserDefined))) // return Exception { InvalidAccessError }; if (reason.length() > maxReasonSizeInBytes) { @@ -718,7 +718,7 @@ ScriptExecutionContext* WebSocket::scriptExecutionContext() const // void WebSocket::contextDestroyed() // { -// LOG(Network, "WebSocket %p contextDestroyed()", this); +// LOG(Network, "WebSocket %p contextDestroyed()", this); // ASSERT(!m_channel); // ASSERT(m_state == CLOSED); // // ActiveDOMObject::contextDestroyed(); @@ -763,7 +763,7 @@ void WebSocket::didConnect() { // from new WebSocket() -> connect() - LOG(Network, "WebSocket %p didConnect()", this); + // LOG(Network, "WebSocket %p didConnect()", this); // queueTaskKeepingObjectAlive(*this, TaskSource::WebSocket, [this] { if (m_state == CLOSED) return; @@ -797,7 +797,7 @@ void WebSocket::didConnect() void WebSocket::didReceiveMessage(String&& message) { - LOG(Network, "WebSocket %p didReceiveMessage() Text message '%s'", this, message.utf8().data()); + // LOG(Network, "WebSocket %p didReceiveMessage() Text message '%s'", this, message.utf8().data()); // queueTaskKeepingObjectAlive(*this, TaskSource::WebSocket, [this, message = WTFMove(message)]() mutable { if (m_state != OPEN) return; @@ -831,7 +831,7 @@ void WebSocket::didReceiveMessage(String&& message) void WebSocket::didReceiveBinaryData(Vector<uint8_t>&& binaryData) { - LOG(Network, "WebSocket %p didReceiveBinaryData() %u byte binary message", this, static_cast<unsigned>(binaryData.size())); + // LOG(Network, "WebSocket %p didReceiveBinaryData() %u byte binary message", this, static_cast<unsigned>(binaryData.size())); // queueTaskKeepingObjectAlive(*this, TaskSource::WebSocket, [this, binaryData = WTFMove(binaryData)]() mutable { if (m_state != OPEN) return; @@ -916,7 +916,7 @@ void WebSocket::didReceiveBinaryData(Vector<uint8_t>&& binaryData) void WebSocket::didReceiveMessageError(unsigned short code, WTF::String reason) { - LOG(Network, "WebSocket %p didReceiveErrorMessage()", this); + // LOG(Network, "WebSocket %p didReceiveErrorMessage()", this); // queueTaskKeepingObjectAlive(*this, TaskSource::WebSocket, [this, reason = WTFMove(reason)] { if (m_state == CLOSED) return; @@ -931,7 +931,7 @@ void WebSocket::didReceiveMessageError(unsigned short code, WTF::String reason) void WebSocket::didUpdateBufferedAmount(unsigned bufferedAmount) { - LOG(Network, "WebSocket %p didUpdateBufferedAmount() New bufferedAmount is %u", this, bufferedAmount); + // LOG(Network, "WebSocket %p didUpdateBufferedAmount() New bufferedAmount is %u", this, bufferedAmount); if (m_state == CLOSED) return; m_bufferedAmount = bufferedAmount; @@ -939,7 +939,7 @@ void WebSocket::didUpdateBufferedAmount(unsigned bufferedAmount) void WebSocket::didStartClosingHandshake() { - LOG(Network, "WebSocket %p didStartClosingHandshake()", this); + // LOG(Network, "WebSocket %p didStartClosingHandshake()", this); // queueTaskKeepingObjectAlive(*this, TaskSource::WebSocket, [this] { if (m_state == CLOSED) return; @@ -950,7 +950,7 @@ void WebSocket::didStartClosingHandshake() void WebSocket::didClose(unsigned unhandledBufferedAmount, unsigned short code, const String& reason) { - LOG(Network, "WebSocket %p didClose()", this); + // LOG(Network, "WebSocket %p didClose()", this); if (this->m_connectedWebSocketKind == ConnectedWebSocketKind::None) return; |