From 29b22175bf6fc726d0b028c7bf5619ab89fca09a Mon Sep 17 00:00:00 2001 From: dave caruso Date: Fri, 15 Sep 2023 11:22:06 -0400 Subject: feat(runtime): add `process.binding` `uv`/`natives`/`config` + make global object properties lazy (#5355) * binding uv * we did that * some more bindings * fix doc * fix uv * yo * static hash table nonsense <3 * huge refactor to the global object i am not ready for merge conflicts * it works part 3 * lose --------- Co-authored-by: Jarred Sumner --- .../ZigGeneratedClasses+lazyStructureHeader.h | 302 +++++++-------------- 1 file changed, 101 insertions(+), 201 deletions(-) (limited to 'src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h') diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h index 2c075a508..386e1ea80 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h @@ -1,300 +1,200 @@ JSC::Structure* JSAttributeIteratorStructure() { return m_JSAttributeIterator.getInitializedOnMainThread(this); } - JSC::JSObject* JSAttributeIteratorConstructor() { return m_JSAttributeIterator.constructorInitializedOnMainThread(this); } - JSC::JSValue JSAttributeIteratorPrototype() { return m_JSAttributeIterator.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSAttributeIteratorConstructor() { return m_JSAttributeIterator.constructorInitializedOnMainThread(this); } + JSC::JSValue JSAttributeIteratorPrototype() { return m_JSAttributeIterator.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSAttributeIterator; - bool hasJSAttributeIteratorSetterValue { false }; - mutable JSC::WriteBarrier m_JSAttributeIteratorSetterValue; JSC::Structure* JSBigIntStatsStructure() { return m_JSBigIntStats.getInitializedOnMainThread(this); } - JSC::JSObject* JSBigIntStatsConstructor() { return m_JSBigIntStats.constructorInitializedOnMainThread(this); } - JSC::JSValue JSBigIntStatsPrototype() { return m_JSBigIntStats.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSBigIntStatsConstructor() { return m_JSBigIntStats.constructorInitializedOnMainThread(this); } + JSC::JSValue JSBigIntStatsPrototype() { return m_JSBigIntStats.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSBigIntStats; - bool hasJSBigIntStatsSetterValue { false }; - mutable JSC::WriteBarrier m_JSBigIntStatsSetterValue; JSC::Structure* JSBlobStructure() { return m_JSBlob.getInitializedOnMainThread(this); } - JSC::JSObject* JSBlobConstructor() { return m_JSBlob.constructorInitializedOnMainThread(this); } - JSC::JSValue JSBlobPrototype() { return m_JSBlob.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSBlobConstructor() { return m_JSBlob.constructorInitializedOnMainThread(this); } + JSC::JSValue JSBlobPrototype() { return m_JSBlob.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSBlob; - bool hasJSBlobSetterValue { false }; - mutable JSC::WriteBarrier m_JSBlobSetterValue; JSC::Structure* JSBuildArtifactStructure() { return m_JSBuildArtifact.getInitializedOnMainThread(this); } - JSC::JSObject* JSBuildArtifactConstructor() { return m_JSBuildArtifact.constructorInitializedOnMainThread(this); } - JSC::JSValue JSBuildArtifactPrototype() { return m_JSBuildArtifact.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSBuildArtifactConstructor() { return m_JSBuildArtifact.constructorInitializedOnMainThread(this); } + JSC::JSValue JSBuildArtifactPrototype() { return m_JSBuildArtifact.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSBuildArtifact; - bool hasJSBuildArtifactSetterValue { false }; - mutable JSC::WriteBarrier m_JSBuildArtifactSetterValue; JSC::Structure* JSBuildMessageStructure() { return m_JSBuildMessage.getInitializedOnMainThread(this); } - JSC::JSObject* JSBuildMessageConstructor() { return m_JSBuildMessage.constructorInitializedOnMainThread(this); } - JSC::JSValue JSBuildMessagePrototype() { return m_JSBuildMessage.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSBuildMessageConstructor() { return m_JSBuildMessage.constructorInitializedOnMainThread(this); } + JSC::JSValue JSBuildMessagePrototype() { return m_JSBuildMessage.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSBuildMessage; - bool hasJSBuildMessageSetterValue { false }; - mutable JSC::WriteBarrier m_JSBuildMessageSetterValue; JSC::Structure* JSCommentStructure() { return m_JSComment.getInitializedOnMainThread(this); } - JSC::JSObject* JSCommentConstructor() { return m_JSComment.constructorInitializedOnMainThread(this); } - JSC::JSValue JSCommentPrototype() { return m_JSComment.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSCommentConstructor() { return m_JSComment.constructorInitializedOnMainThread(this); } + JSC::JSValue JSCommentPrototype() { return m_JSComment.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSComment; - bool hasJSCommentSetterValue { false }; - mutable JSC::WriteBarrier m_JSCommentSetterValue; JSC::Structure* JSCryptoStructure() { return m_JSCrypto.getInitializedOnMainThread(this); } - JSC::JSObject* JSCryptoConstructor() { return m_JSCrypto.constructorInitializedOnMainThread(this); } - JSC::JSValue JSCryptoPrototype() { return m_JSCrypto.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSCryptoConstructor() { return m_JSCrypto.constructorInitializedOnMainThread(this); } + JSC::JSValue JSCryptoPrototype() { return m_JSCrypto.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSCrypto; - bool hasJSCryptoSetterValue { false }; - mutable JSC::WriteBarrier m_JSCryptoSetterValue; JSC::Structure* JSCryptoHasherStructure() { return m_JSCryptoHasher.getInitializedOnMainThread(this); } - JSC::JSObject* JSCryptoHasherConstructor() { return m_JSCryptoHasher.constructorInitializedOnMainThread(this); } - JSC::JSValue JSCryptoHasherPrototype() { return m_JSCryptoHasher.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSCryptoHasherConstructor() { return m_JSCryptoHasher.constructorInitializedOnMainThread(this); } + JSC::JSValue JSCryptoHasherPrototype() { return m_JSCryptoHasher.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSCryptoHasher; - bool hasJSCryptoHasherSetterValue { false }; - mutable JSC::WriteBarrier m_JSCryptoHasherSetterValue; JSC::Structure* JSDebugHTTPSServerStructure() { return m_JSDebugHTTPSServer.getInitializedOnMainThread(this); } - JSC::JSObject* JSDebugHTTPSServerConstructor() { return m_JSDebugHTTPSServer.constructorInitializedOnMainThread(this); } - JSC::JSValue JSDebugHTTPSServerPrototype() { return m_JSDebugHTTPSServer.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSDebugHTTPSServerConstructor() { return m_JSDebugHTTPSServer.constructorInitializedOnMainThread(this); } + JSC::JSValue JSDebugHTTPSServerPrototype() { return m_JSDebugHTTPSServer.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSDebugHTTPSServer; - bool hasJSDebugHTTPSServerSetterValue { false }; - mutable JSC::WriteBarrier m_JSDebugHTTPSServerSetterValue; JSC::Structure* JSDebugHTTPServerStructure() { return m_JSDebugHTTPServer.getInitializedOnMainThread(this); } - JSC::JSObject* JSDebugHTTPServerConstructor() { return m_JSDebugHTTPServer.constructorInitializedOnMainThread(this); } - JSC::JSValue JSDebugHTTPServerPrototype() { return m_JSDebugHTTPServer.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSDebugHTTPServerConstructor() { return m_JSDebugHTTPServer.constructorInitializedOnMainThread(this); } + JSC::JSValue JSDebugHTTPServerPrototype() { return m_JSDebugHTTPServer.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSDebugHTTPServer; - bool hasJSDebugHTTPServerSetterValue { false }; - mutable JSC::WriteBarrier m_JSDebugHTTPServerSetterValue; JSC::Structure* JSDirentStructure() { return m_JSDirent.getInitializedOnMainThread(this); } - JSC::JSObject* JSDirentConstructor() { return m_JSDirent.constructorInitializedOnMainThread(this); } - JSC::JSValue JSDirentPrototype() { return m_JSDirent.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSDirentConstructor() { return m_JSDirent.constructorInitializedOnMainThread(this); } + JSC::JSValue JSDirentPrototype() { return m_JSDirent.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSDirent; - bool hasJSDirentSetterValue { false }; - mutable JSC::WriteBarrier m_JSDirentSetterValue; JSC::Structure* JSDocEndStructure() { return m_JSDocEnd.getInitializedOnMainThread(this); } - JSC::JSObject* JSDocEndConstructor() { return m_JSDocEnd.constructorInitializedOnMainThread(this); } - JSC::JSValue JSDocEndPrototype() { return m_JSDocEnd.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSDocEndConstructor() { return m_JSDocEnd.constructorInitializedOnMainThread(this); } + JSC::JSValue JSDocEndPrototype() { return m_JSDocEnd.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSDocEnd; - bool hasJSDocEndSetterValue { false }; - mutable JSC::WriteBarrier m_JSDocEndSetterValue; JSC::Structure* JSDocTypeStructure() { return m_JSDocType.getInitializedOnMainThread(this); } - JSC::JSObject* JSDocTypeConstructor() { return m_JSDocType.constructorInitializedOnMainThread(this); } - JSC::JSValue JSDocTypePrototype() { return m_JSDocType.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSDocTypeConstructor() { return m_JSDocType.constructorInitializedOnMainThread(this); } + JSC::JSValue JSDocTypePrototype() { return m_JSDocType.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSDocType; - bool hasJSDocTypeSetterValue { false }; - mutable JSC::WriteBarrier m_JSDocTypeSetterValue; JSC::Structure* JSElementStructure() { return m_JSElement.getInitializedOnMainThread(this); } - JSC::JSObject* JSElementConstructor() { return m_JSElement.constructorInitializedOnMainThread(this); } - JSC::JSValue JSElementPrototype() { return m_JSElement.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSElementConstructor() { return m_JSElement.constructorInitializedOnMainThread(this); } + JSC::JSValue JSElementPrototype() { return m_JSElement.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSElement; - bool hasJSElementSetterValue { false }; - mutable JSC::WriteBarrier m_JSElementSetterValue; JSC::Structure* JSEndTagStructure() { return m_JSEndTag.getInitializedOnMainThread(this); } - JSC::JSObject* JSEndTagConstructor() { return m_JSEndTag.constructorInitializedOnMainThread(this); } - JSC::JSValue JSEndTagPrototype() { return m_JSEndTag.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSEndTagConstructor() { return m_JSEndTag.constructorInitializedOnMainThread(this); } + JSC::JSValue JSEndTagPrototype() { return m_JSEndTag.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSEndTag; - bool hasJSEndTagSetterValue { false }; - mutable JSC::WriteBarrier m_JSEndTagSetterValue; JSC::Structure* JSExpectStructure() { return m_JSExpect.getInitializedOnMainThread(this); } - JSC::JSObject* JSExpectConstructor() { return m_JSExpect.constructorInitializedOnMainThread(this); } - JSC::JSValue JSExpectPrototype() { return m_JSExpect.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSExpectConstructor() { return m_JSExpect.constructorInitializedOnMainThread(this); } + JSC::JSValue JSExpectPrototype() { return m_JSExpect.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSExpect; - bool hasJSExpectSetterValue { false }; - mutable JSC::WriteBarrier m_JSExpectSetterValue; JSC::Structure* JSExpectAnyStructure() { return m_JSExpectAny.getInitializedOnMainThread(this); } - JSC::JSObject* JSExpectAnyConstructor() { return m_JSExpectAny.constructorInitializedOnMainThread(this); } - JSC::JSValue JSExpectAnyPrototype() { return m_JSExpectAny.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSExpectAnyConstructor() { return m_JSExpectAny.constructorInitializedOnMainThread(this); } + JSC::JSValue JSExpectAnyPrototype() { return m_JSExpectAny.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSExpectAny; - bool hasJSExpectAnySetterValue { false }; - mutable JSC::WriteBarrier m_JSExpectAnySetterValue; JSC::Structure* JSExpectAnythingStructure() { return m_JSExpectAnything.getInitializedOnMainThread(this); } - JSC::JSObject* JSExpectAnythingConstructor() { return m_JSExpectAnything.constructorInitializedOnMainThread(this); } - JSC::JSValue JSExpectAnythingPrototype() { return m_JSExpectAnything.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSExpectAnythingConstructor() { return m_JSExpectAnything.constructorInitializedOnMainThread(this); } + JSC::JSValue JSExpectAnythingPrototype() { return m_JSExpectAnything.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSExpectAnything; - bool hasJSExpectAnythingSetterValue { false }; - mutable JSC::WriteBarrier m_JSExpectAnythingSetterValue; JSC::Structure* JSExpectStringContainingStructure() { return m_JSExpectStringContaining.getInitializedOnMainThread(this); } - JSC::JSObject* JSExpectStringContainingConstructor() { return m_JSExpectStringContaining.constructorInitializedOnMainThread(this); } - JSC::JSValue JSExpectStringContainingPrototype() { return m_JSExpectStringContaining.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSExpectStringContainingConstructor() { return m_JSExpectStringContaining.constructorInitializedOnMainThread(this); } + JSC::JSValue JSExpectStringContainingPrototype() { return m_JSExpectStringContaining.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSExpectStringContaining; - bool hasJSExpectStringContainingSetterValue { false }; - mutable JSC::WriteBarrier m_JSExpectStringContainingSetterValue; JSC::Structure* JSExpectStringMatchingStructure() { return m_JSExpectStringMatching.getInitializedOnMainThread(this); } - JSC::JSObject* JSExpectStringMatchingConstructor() { return m_JSExpectStringMatching.constructorInitializedOnMainThread(this); } - JSC::JSValue JSExpectStringMatchingPrototype() { return m_JSExpectStringMatching.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSExpectStringMatchingConstructor() { return m_JSExpectStringMatching.constructorInitializedOnMainThread(this); } + JSC::JSValue JSExpectStringMatchingPrototype() { return m_JSExpectStringMatching.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSExpectStringMatching; - bool hasJSExpectStringMatchingSetterValue { false }; - mutable JSC::WriteBarrier m_JSExpectStringMatchingSetterValue; JSC::Structure* JSFFIStructure() { return m_JSFFI.getInitializedOnMainThread(this); } - JSC::JSObject* JSFFIConstructor() { return m_JSFFI.constructorInitializedOnMainThread(this); } - JSC::JSValue JSFFIPrototype() { return m_JSFFI.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSFFIConstructor() { return m_JSFFI.constructorInitializedOnMainThread(this); } + JSC::JSValue JSFFIPrototype() { return m_JSFFI.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSFFI; - bool hasJSFFISetterValue { false }; - mutable JSC::WriteBarrier m_JSFFISetterValue; JSC::Structure* JSFSWatcherStructure() { return m_JSFSWatcher.getInitializedOnMainThread(this); } - JSC::JSObject* JSFSWatcherConstructor() { return m_JSFSWatcher.constructorInitializedOnMainThread(this); } - JSC::JSValue JSFSWatcherPrototype() { return m_JSFSWatcher.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSFSWatcherConstructor() { return m_JSFSWatcher.constructorInitializedOnMainThread(this); } + JSC::JSValue JSFSWatcherPrototype() { return m_JSFSWatcher.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSFSWatcher; - bool hasJSFSWatcherSetterValue { false }; - mutable JSC::WriteBarrier m_JSFSWatcherSetterValue; JSC::Structure* JSFileSystemRouterStructure() { return m_JSFileSystemRouter.getInitializedOnMainThread(this); } - JSC::JSObject* JSFileSystemRouterConstructor() { return m_JSFileSystemRouter.constructorInitializedOnMainThread(this); } - JSC::JSValue JSFileSystemRouterPrototype() { return m_JSFileSystemRouter.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSFileSystemRouterConstructor() { return m_JSFileSystemRouter.constructorInitializedOnMainThread(this); } + JSC::JSValue JSFileSystemRouterPrototype() { return m_JSFileSystemRouter.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSFileSystemRouter; - bool hasJSFileSystemRouterSetterValue { false }; - mutable JSC::WriteBarrier m_JSFileSystemRouterSetterValue; JSC::Structure* JSHTMLRewriterStructure() { return m_JSHTMLRewriter.getInitializedOnMainThread(this); } - JSC::JSObject* JSHTMLRewriterConstructor() { return m_JSHTMLRewriter.constructorInitializedOnMainThread(this); } - JSC::JSValue JSHTMLRewriterPrototype() { return m_JSHTMLRewriter.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSHTMLRewriterConstructor() { return m_JSHTMLRewriter.constructorInitializedOnMainThread(this); } + JSC::JSValue JSHTMLRewriterPrototype() { return m_JSHTMLRewriter.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSHTMLRewriter; - bool hasJSHTMLRewriterSetterValue { false }; - mutable JSC::WriteBarrier m_JSHTMLRewriterSetterValue; JSC::Structure* JSHTTPSServerStructure() { return m_JSHTTPSServer.getInitializedOnMainThread(this); } - JSC::JSObject* JSHTTPSServerConstructor() { return m_JSHTTPSServer.constructorInitializedOnMainThread(this); } - JSC::JSValue JSHTTPSServerPrototype() { return m_JSHTTPSServer.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSHTTPSServerConstructor() { return m_JSHTTPSServer.constructorInitializedOnMainThread(this); } + JSC::JSValue JSHTTPSServerPrototype() { return m_JSHTTPSServer.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSHTTPSServer; - bool hasJSHTTPSServerSetterValue { false }; - mutable JSC::WriteBarrier m_JSHTTPSServerSetterValue; JSC::Structure* JSHTTPServerStructure() { return m_JSHTTPServer.getInitializedOnMainThread(this); } - JSC::JSObject* JSHTTPServerConstructor() { return m_JSHTTPServer.constructorInitializedOnMainThread(this); } - JSC::JSValue JSHTTPServerPrototype() { return m_JSHTTPServer.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSHTTPServerConstructor() { return m_JSHTTPServer.constructorInitializedOnMainThread(this); } + JSC::JSValue JSHTTPServerPrototype() { return m_JSHTTPServer.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSHTTPServer; - bool hasJSHTTPServerSetterValue { false }; - mutable JSC::WriteBarrier m_JSHTTPServerSetterValue; JSC::Structure* JSListenerStructure() { return m_JSListener.getInitializedOnMainThread(this); } - JSC::JSObject* JSListenerConstructor() { return m_JSListener.constructorInitializedOnMainThread(this); } - JSC::JSValue JSListenerPrototype() { return m_JSListener.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSListenerConstructor() { return m_JSListener.constructorInitializedOnMainThread(this); } + JSC::JSValue JSListenerPrototype() { return m_JSListener.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSListener; - bool hasJSListenerSetterValue { false }; - mutable JSC::WriteBarrier m_JSListenerSetterValue; JSC::Structure* JSMD4Structure() { return m_JSMD4.getInitializedOnMainThread(this); } - JSC::JSObject* JSMD4Constructor() { return m_JSMD4.constructorInitializedOnMainThread(this); } - JSC::JSValue JSMD4Prototype() { return m_JSMD4.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSMD4Constructor() { return m_JSMD4.constructorInitializedOnMainThread(this); } + JSC::JSValue JSMD4Prototype() { return m_JSMD4.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSMD4; - bool hasJSMD4SetterValue { false }; - mutable JSC::WriteBarrier m_JSMD4SetterValue; JSC::Structure* JSMD5Structure() { return m_JSMD5.getInitializedOnMainThread(this); } - JSC::JSObject* JSMD5Constructor() { return m_JSMD5.constructorInitializedOnMainThread(this); } - JSC::JSValue JSMD5Prototype() { return m_JSMD5.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSMD5Constructor() { return m_JSMD5.constructorInitializedOnMainThread(this); } + JSC::JSValue JSMD5Prototype() { return m_JSMD5.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSMD5; - bool hasJSMD5SetterValue { false }; - mutable JSC::WriteBarrier m_JSMD5SetterValue; JSC::Structure* JSMatchedRouteStructure() { return m_JSMatchedRoute.getInitializedOnMainThread(this); } - JSC::JSObject* JSMatchedRouteConstructor() { return m_JSMatchedRoute.constructorInitializedOnMainThread(this); } - JSC::JSValue JSMatchedRoutePrototype() { return m_JSMatchedRoute.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSMatchedRouteConstructor() { return m_JSMatchedRoute.constructorInitializedOnMainThread(this); } + JSC::JSValue JSMatchedRoutePrototype() { return m_JSMatchedRoute.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSMatchedRoute; - bool hasJSMatchedRouteSetterValue { false }; - mutable JSC::WriteBarrier m_JSMatchedRouteSetterValue; JSC::Structure* JSNodeJSFSStructure() { return m_JSNodeJSFS.getInitializedOnMainThread(this); } - JSC::JSObject* JSNodeJSFSConstructor() { return m_JSNodeJSFS.constructorInitializedOnMainThread(this); } - JSC::JSValue JSNodeJSFSPrototype() { return m_JSNodeJSFS.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSNodeJSFSConstructor() { return m_JSNodeJSFS.constructorInitializedOnMainThread(this); } + JSC::JSValue JSNodeJSFSPrototype() { return m_JSNodeJSFS.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSNodeJSFS; - bool hasJSNodeJSFSSetterValue { false }; - mutable JSC::WriteBarrier m_JSNodeJSFSSetterValue; JSC::Structure* JSRequestStructure() { return m_JSRequest.getInitializedOnMainThread(this); } - JSC::JSObject* JSRequestConstructor() { return m_JSRequest.constructorInitializedOnMainThread(this); } - JSC::JSValue JSRequestPrototype() { return m_JSRequest.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSRequestConstructor() { return m_JSRequest.constructorInitializedOnMainThread(this); } + JSC::JSValue JSRequestPrototype() { return m_JSRequest.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSRequest; - bool hasJSRequestSetterValue { false }; - mutable JSC::WriteBarrier m_JSRequestSetterValue; JSC::Structure* JSResolveMessageStructure() { return m_JSResolveMessage.getInitializedOnMainThread(this); } - JSC::JSObject* JSResolveMessageConstructor() { return m_JSResolveMessage.constructorInitializedOnMainThread(this); } - JSC::JSValue JSResolveMessagePrototype() { return m_JSResolveMessage.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSResolveMessageConstructor() { return m_JSResolveMessage.constructorInitializedOnMainThread(this); } + JSC::JSValue JSResolveMessagePrototype() { return m_JSResolveMessage.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSResolveMessage; - bool hasJSResolveMessageSetterValue { false }; - mutable JSC::WriteBarrier m_JSResolveMessageSetterValue; JSC::Structure* JSResponseStructure() { return m_JSResponse.getInitializedOnMainThread(this); } - JSC::JSObject* JSResponseConstructor() { return m_JSResponse.constructorInitializedOnMainThread(this); } - JSC::JSValue JSResponsePrototype() { return m_JSResponse.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSResponseConstructor() { return m_JSResponse.constructorInitializedOnMainThread(this); } + JSC::JSValue JSResponsePrototype() { return m_JSResponse.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSResponse; - bool hasJSResponseSetterValue { false }; - mutable JSC::WriteBarrier m_JSResponseSetterValue; JSC::Structure* JSSHA1Structure() { return m_JSSHA1.getInitializedOnMainThread(this); } - JSC::JSObject* JSSHA1Constructor() { return m_JSSHA1.constructorInitializedOnMainThread(this); } - JSC::JSValue JSSHA1Prototype() { return m_JSSHA1.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSSHA1Constructor() { return m_JSSHA1.constructorInitializedOnMainThread(this); } + JSC::JSValue JSSHA1Prototype() { return m_JSSHA1.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSSHA1; - bool hasJSSHA1SetterValue { false }; - mutable JSC::WriteBarrier m_JSSHA1SetterValue; JSC::Structure* JSSHA224Structure() { return m_JSSHA224.getInitializedOnMainThread(this); } - JSC::JSObject* JSSHA224Constructor() { return m_JSSHA224.constructorInitializedOnMainThread(this); } - JSC::JSValue JSSHA224Prototype() { return m_JSSHA224.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSSHA224Constructor() { return m_JSSHA224.constructorInitializedOnMainThread(this); } + JSC::JSValue JSSHA224Prototype() { return m_JSSHA224.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSSHA224; - bool hasJSSHA224SetterValue { false }; - mutable JSC::WriteBarrier m_JSSHA224SetterValue; JSC::Structure* JSSHA256Structure() { return m_JSSHA256.getInitializedOnMainThread(this); } - JSC::JSObject* JSSHA256Constructor() { return m_JSSHA256.constructorInitializedOnMainThread(this); } - JSC::JSValue JSSHA256Prototype() { return m_JSSHA256.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSSHA256Constructor() { return m_JSSHA256.constructorInitializedOnMainThread(this); } + JSC::JSValue JSSHA256Prototype() { return m_JSSHA256.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSSHA256; - bool hasJSSHA256SetterValue { false }; - mutable JSC::WriteBarrier m_JSSHA256SetterValue; JSC::Structure* JSSHA384Structure() { return m_JSSHA384.getInitializedOnMainThread(this); } - JSC::JSObject* JSSHA384Constructor() { return m_JSSHA384.constructorInitializedOnMainThread(this); } - JSC::JSValue JSSHA384Prototype() { return m_JSSHA384.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSSHA384Constructor() { return m_JSSHA384.constructorInitializedOnMainThread(this); } + JSC::JSValue JSSHA384Prototype() { return m_JSSHA384.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSSHA384; - bool hasJSSHA384SetterValue { false }; - mutable JSC::WriteBarrier m_JSSHA384SetterValue; JSC::Structure* JSSHA512Structure() { return m_JSSHA512.getInitializedOnMainThread(this); } - JSC::JSObject* JSSHA512Constructor() { return m_JSSHA512.constructorInitializedOnMainThread(this); } - JSC::JSValue JSSHA512Prototype() { return m_JSSHA512.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSSHA512Constructor() { return m_JSSHA512.constructorInitializedOnMainThread(this); } + JSC::JSValue JSSHA512Prototype() { return m_JSSHA512.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSSHA512; - bool hasJSSHA512SetterValue { false }; - mutable JSC::WriteBarrier m_JSSHA512SetterValue; JSC::Structure* JSSHA512_256Structure() { return m_JSSHA512_256.getInitializedOnMainThread(this); } - JSC::JSObject* JSSHA512_256Constructor() { return m_JSSHA512_256.constructorInitializedOnMainThread(this); } - JSC::JSValue JSSHA512_256Prototype() { return m_JSSHA512_256.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSSHA512_256Constructor() { return m_JSSHA512_256.constructorInitializedOnMainThread(this); } + JSC::JSValue JSSHA512_256Prototype() { return m_JSSHA512_256.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSSHA512_256; - bool hasJSSHA512_256SetterValue { false }; - mutable JSC::WriteBarrier m_JSSHA512_256SetterValue; JSC::Structure* JSServerWebSocketStructure() { return m_JSServerWebSocket.getInitializedOnMainThread(this); } - JSC::JSObject* JSServerWebSocketConstructor() { return m_JSServerWebSocket.constructorInitializedOnMainThread(this); } - JSC::JSValue JSServerWebSocketPrototype() { return m_JSServerWebSocket.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSServerWebSocketConstructor() { return m_JSServerWebSocket.constructorInitializedOnMainThread(this); } + JSC::JSValue JSServerWebSocketPrototype() { return m_JSServerWebSocket.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSServerWebSocket; - bool hasJSServerWebSocketSetterValue { false }; - mutable JSC::WriteBarrier m_JSServerWebSocketSetterValue; JSC::Structure* JSStatWatcherStructure() { return m_JSStatWatcher.getInitializedOnMainThread(this); } - JSC::JSObject* JSStatWatcherConstructor() { return m_JSStatWatcher.constructorInitializedOnMainThread(this); } - JSC::JSValue JSStatWatcherPrototype() { return m_JSStatWatcher.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSStatWatcherConstructor() { return m_JSStatWatcher.constructorInitializedOnMainThread(this); } + JSC::JSValue JSStatWatcherPrototype() { return m_JSStatWatcher.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSStatWatcher; - bool hasJSStatWatcherSetterValue { false }; - mutable JSC::WriteBarrier m_JSStatWatcherSetterValue; JSC::Structure* JSStatsStructure() { return m_JSStats.getInitializedOnMainThread(this); } - JSC::JSObject* JSStatsConstructor() { return m_JSStats.constructorInitializedOnMainThread(this); } - JSC::JSValue JSStatsPrototype() { return m_JSStats.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSStatsConstructor() { return m_JSStats.constructorInitializedOnMainThread(this); } + JSC::JSValue JSStatsPrototype() { return m_JSStats.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSStats; - bool hasJSStatsSetterValue { false }; - mutable JSC::WriteBarrier m_JSStatsSetterValue; JSC::Structure* JSSubprocessStructure() { return m_JSSubprocess.getInitializedOnMainThread(this); } - JSC::JSObject* JSSubprocessConstructor() { return m_JSSubprocess.constructorInitializedOnMainThread(this); } - JSC::JSValue JSSubprocessPrototype() { return m_JSSubprocess.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSSubprocessConstructor() { return m_JSSubprocess.constructorInitializedOnMainThread(this); } + JSC::JSValue JSSubprocessPrototype() { return m_JSSubprocess.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSSubprocess; - bool hasJSSubprocessSetterValue { false }; - mutable JSC::WriteBarrier m_JSSubprocessSetterValue; JSC::Structure* JSTCPSocketStructure() { return m_JSTCPSocket.getInitializedOnMainThread(this); } - JSC::JSObject* JSTCPSocketConstructor() { return m_JSTCPSocket.constructorInitializedOnMainThread(this); } - JSC::JSValue JSTCPSocketPrototype() { return m_JSTCPSocket.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSTCPSocketConstructor() { return m_JSTCPSocket.constructorInitializedOnMainThread(this); } + JSC::JSValue JSTCPSocketPrototype() { return m_JSTCPSocket.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSTCPSocket; - bool hasJSTCPSocketSetterValue { false }; - mutable JSC::WriteBarrier m_JSTCPSocketSetterValue; JSC::Structure* JSTLSSocketStructure() { return m_JSTLSSocket.getInitializedOnMainThread(this); } - JSC::JSObject* JSTLSSocketConstructor() { return m_JSTLSSocket.constructorInitializedOnMainThread(this); } - JSC::JSValue JSTLSSocketPrototype() { return m_JSTLSSocket.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSTLSSocketConstructor() { return m_JSTLSSocket.constructorInitializedOnMainThread(this); } + JSC::JSValue JSTLSSocketPrototype() { return m_JSTLSSocket.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSTLSSocket; - bool hasJSTLSSocketSetterValue { false }; - mutable JSC::WriteBarrier m_JSTLSSocketSetterValue; JSC::Structure* JSTextChunkStructure() { return m_JSTextChunk.getInitializedOnMainThread(this); } - JSC::JSObject* JSTextChunkConstructor() { return m_JSTextChunk.constructorInitializedOnMainThread(this); } - JSC::JSValue JSTextChunkPrototype() { return m_JSTextChunk.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSTextChunkConstructor() { return m_JSTextChunk.constructorInitializedOnMainThread(this); } + JSC::JSValue JSTextChunkPrototype() { return m_JSTextChunk.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSTextChunk; - bool hasJSTextChunkSetterValue { false }; - mutable JSC::WriteBarrier m_JSTextChunkSetterValue; JSC::Structure* JSTextDecoderStructure() { return m_JSTextDecoder.getInitializedOnMainThread(this); } - JSC::JSObject* JSTextDecoderConstructor() { return m_JSTextDecoder.constructorInitializedOnMainThread(this); } - JSC::JSValue JSTextDecoderPrototype() { return m_JSTextDecoder.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSTextDecoderConstructor() { return m_JSTextDecoder.constructorInitializedOnMainThread(this); } + JSC::JSValue JSTextDecoderPrototype() { return m_JSTextDecoder.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSTextDecoder; - bool hasJSTextDecoderSetterValue { false }; - mutable JSC::WriteBarrier m_JSTextDecoderSetterValue; JSC::Structure* JSTimeoutStructure() { return m_JSTimeout.getInitializedOnMainThread(this); } - JSC::JSObject* JSTimeoutConstructor() { return m_JSTimeout.constructorInitializedOnMainThread(this); } - JSC::JSValue JSTimeoutPrototype() { return m_JSTimeout.prototypeInitializedOnMainThread(this); } + JSC::JSObject* JSTimeoutConstructor() { return m_JSTimeout.constructorInitializedOnMainThread(this); } + JSC::JSValue JSTimeoutPrototype() { return m_JSTimeout.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSTimeout; - bool hasJSTimeoutSetterValue { false }; - mutable JSC::WriteBarrier m_JSTimeoutSetterValue; JSC::Structure* JSTranspilerStructure() { return m_JSTranspiler.getInitializedOnMainThread(this); } - JSC::JSObject* JSTranspilerConstructor() { return m_JSTranspiler.constructorInitializedOnMainThread(this); } - JSC::JSValue JSTranspilerPrototype() { return m_JSTranspiler.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSTranspiler; - bool hasJSTranspilerSetterValue { false }; - mutable JSC::WriteBarrier m_JSTranspilerSetterValue; \ No newline at end of file + JSC::JSObject* JSTranspilerConstructor() { return m_JSTranspiler.constructorInitializedOnMainThread(this); } + JSC::JSValue JSTranspilerPrototype() { return m_JSTranspiler.prototypeInitializedOnMainThread(this); } + JSC::LazyClassStructure m_JSTranspiler; \ No newline at end of file -- cgit v1.2.3 From c7de270bbba05e0fc850290b27d617bda1df2206 Mon Sep 17 00:00:00 2001 From: WingLim Date: Mon, 18 Sep 2023 17:59:09 +0800 Subject: feat(test): Implement `arrayContaining` (#5572) * feat(test): implement `arrayContaining` * feat: early return when expectedArray is empty * feat: add test for toEqual * chore: use `JSC::isArray` * chore: use getIndex for performance * fix: use deepEqual --------- Co-authored-by: Jarred Sumner --- .../ZigGeneratedClasses+DOMClientIsoSubspaces.h | 1 + .../bindings/ZigGeneratedClasses+DOMIsoSubspaces.h | 1 + .../ZigGeneratedClasses+lazyStructureHeader.h | 4 + .../ZigGeneratedClasses+lazyStructureImpl.h | 9 +- src/bun.js/bindings/ZigGeneratedClasses.cpp | 168 +++++++++++++++++++++ src/bun.js/bindings/ZigGeneratedClasses.h | 56 +++++++ src/bun.js/bindings/bindings.cpp | 43 +++++- src/bun.js/bindings/generated_classes.zig | 82 ++++++++++ src/bun.js/bindings/generated_classes_list.zig | 1 + src/bun.js/test/expect.zig | 42 +++++- src/bun.js/test/jest.classes.ts | 12 ++ test/js/bun/test/expect.test.js | 16 ++ 12 files changed, 432 insertions(+), 3 deletions(-) (limited to 'src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h') diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h index a364c0a48..cef5c512a 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h @@ -16,6 +16,7 @@ std::unique_ptr m_clientSubspaceForEndTag; std::unique_ptr m_clientSubspaceForExpect; std::unique_ptr m_clientSubspaceForExpectConstructor;std::unique_ptr m_clientSubspaceForExpectAny; std::unique_ptr m_clientSubspaceForExpectAnything; +std::unique_ptr m_clientSubspaceForExpectArrayContaining; std::unique_ptr m_clientSubspaceForExpectStringContaining; std::unique_ptr m_clientSubspaceForExpectStringMatching; std::unique_ptr m_clientSubspaceForFFI; diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h index e98ea16c3..d06451eda 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h @@ -16,6 +16,7 @@ std::unique_ptr m_subspaceForEndTag; std::unique_ptr m_subspaceForExpect; std::unique_ptr m_subspaceForExpectConstructor;std::unique_ptr m_subspaceForExpectAny; std::unique_ptr m_subspaceForExpectAnything; +std::unique_ptr m_subspaceForExpectArrayContaining; std::unique_ptr m_subspaceForExpectStringContaining; std::unique_ptr m_subspaceForExpectStringMatching; std::unique_ptr m_subspaceForFFI; diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h index 386e1ea80..381378262 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h @@ -70,6 +70,10 @@ JSC::Structure* JSExpectAnythingStructure() { return m_JSExpectAnything.getIniti JSC::JSObject* JSExpectAnythingConstructor() { return m_JSExpectAnything.constructorInitializedOnMainThread(this); } JSC::JSValue JSExpectAnythingPrototype() { return m_JSExpectAnything.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSExpectAnything; +JSC::Structure* JSExpectArrayContainingStructure() { return m_JSExpectArrayContaining.getInitializedOnMainThread(this); } + JSC::JSObject* JSExpectArrayContainingConstructor() { return m_JSExpectArrayContaining.constructorInitializedOnMainThread(this); } + JSC::JSValue JSExpectArrayContainingPrototype() { return m_JSExpectArrayContaining.prototypeInitializedOnMainThread(this); } + JSC::LazyClassStructure m_JSExpectArrayContaining; JSC::Structure* JSExpectStringContainingStructure() { return m_JSExpectStringContaining.getInitializedOnMainThread(this); } JSC::JSObject* JSExpectStringContainingConstructor() { return m_JSExpectStringContaining.constructorInitializedOnMainThread(this); } JSC::JSValue JSExpectStringContainingPrototype() { return m_JSExpectStringContaining.prototypeInitializedOnMainThread(this); } diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h index b51752180..84d3df7a0 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h @@ -1,4 +1,4 @@ -void GlobalObject::initGeneratedLazyClasses() { +ALWAYS_INLINE void GlobalObject::initGeneratedLazyClasses() { m_JSAttributeIterator.initLater( [](LazyClassStructure::Initializer& init) { init.setPrototype(WebCore::JSAttributeIterator::createPrototype(init.vm, reinterpret_cast(init.global))); @@ -106,6 +106,12 @@ void GlobalObject::initGeneratedLazyClasses() { init.setPrototype(WebCore::JSExpectAnything::createPrototype(init.vm, reinterpret_cast(init.global))); init.setStructure(WebCore::JSExpectAnything::createStructure(init.vm, init.global, init.prototype)); + }); + m_JSExpectArrayContaining.initLater( + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSExpectArrayContaining::createPrototype(init.vm, reinterpret_cast(init.global))); + init.setStructure(WebCore::JSExpectArrayContaining::createStructure(init.vm, init.global, init.prototype)); + }); m_JSExpectStringContaining.initLater( [](LazyClassStructure::Initializer& init) { @@ -321,6 +327,7 @@ void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& thisObject->m_JSExpect.visit(visitor); thisObject->m_JSExpectAny.visit(visitor); thisObject->m_JSExpectAnything.visit(visitor); + thisObject->m_JSExpectArrayContaining.visit(visitor); thisObject->m_JSExpectStringContaining.visit(visitor); thisObject->m_JSExpectStringMatching.visit(visitor); thisObject->m_JSFFI.visit(visitor); diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index ec2add296..b84c1cd16 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -9712,6 +9712,174 @@ extern "C" EncodedJSValue ExpectAnything__create(Zig::GlobalObject* globalObject return JSValue::encode(instance); } +class JSExpectArrayContainingPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + + static JSExpectArrayContainingPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) + { + JSExpectArrayContainingPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSExpectArrayContainingPrototype(vm, globalObject, structure); + ptr->finishCreation(vm, globalObject); + return ptr; + } + + DECLARE_INFO; + template + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + JSExpectArrayContainingPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + : Base(vm, structure) + { + } + + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; + +extern "C" void ExpectArrayContainingClass__finalize(void*); +extern "C" JSC_DECLARE_HOST_FUNCTION(ExpectArrayContainingClass__call); + +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSExpectArrayContainingPrototype, JSExpectArrayContainingPrototype::Base); + +static const HashTableValue JSExpectArrayContainingPrototypeTableValues[] = {}; + +const ClassInfo JSExpectArrayContainingPrototype::s_info = { "ExpectArrayContaining"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSExpectArrayContainingPrototype) }; + +extern "C" void ExpectArrayContainingPrototype__arrayValueSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + auto& vm = globalObject->vm(); + auto* thisObject = jsCast(JSValue::decode(thisValue)); + thisObject->m_arrayValue.set(vm, thisObject, JSValue::decode(value)); +} + +extern "C" EncodedJSValue ExpectArrayContainingPrototype__arrayValueGetCachedValue(JSC::EncodedJSValue thisValue) +{ + auto* thisObject = jsCast(JSValue::decode(thisValue)); + return JSValue::encode(thisObject->m_arrayValue.get()); +} + +void JSExpectArrayContainingPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) +{ + Base::finishCreation(vm); + + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +JSExpectArrayContaining::~JSExpectArrayContaining() +{ + if (m_ctx) { + ExpectArrayContainingClass__finalize(m_ctx); + } +} +void JSExpectArrayContaining::destroy(JSCell* cell) +{ + static_cast(cell)->JSExpectArrayContaining::~JSExpectArrayContaining(); +} + +const ClassInfo JSExpectArrayContaining::s_info = { "ExpectArrayContaining"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSExpectArrayContaining) }; + +void JSExpectArrayContaining::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(info())); +} + +JSExpectArrayContaining* JSExpectArrayContaining::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) +{ + JSExpectArrayContaining* ptr = new (NotNull, JSC::allocateCell(vm)) JSExpectArrayContaining(vm, structure, ctx); + ptr->finishCreation(vm); + return ptr; +} + +extern "C" void* ExpectArrayContaining__fromJS(JSC::EncodedJSValue value) +{ + JSC::JSValue decodedValue = JSC::JSValue::decode(value); + if (decodedValue.isEmpty() || !decodedValue.isCell()) + return nullptr; + + JSC::JSCell* cell = decodedValue.asCell(); + JSExpectArrayContaining* object = JSC::jsDynamicCast(cell); + + if (!object) + return nullptr; + + return object->wrapped(); +} + +extern "C" bool ExpectArrayContaining__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) +{ + JSExpectArrayContaining* object = JSC::jsDynamicCast(JSValue::decode(value)); + if (!object) + return false; + + object->m_ctx = ptr; + return true; +} + +extern "C" const size_t ExpectArrayContaining__ptrOffset = JSExpectArrayContaining::offsetOfWrapped(); + +void JSExpectArrayContaining::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast(cell); + if (void* wrapped = thisObject->wrapped()) { + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + } + Base::analyzeHeap(cell, analyzer); +} + +JSObject* JSExpectArrayContaining::createPrototype(VM& vm, JSDOMGlobalObject* globalObject) +{ + return JSExpectArrayContainingPrototype::create(vm, globalObject, JSExpectArrayContainingPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); +} + +extern "C" EncodedJSValue ExpectArrayContaining__create(Zig::GlobalObject* globalObject, void* ptr) +{ + auto& vm = globalObject->vm(); + JSC::Structure* structure = globalObject->JSExpectArrayContainingStructure(); + JSExpectArrayContaining* instance = JSExpectArrayContaining::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} + +template +void JSExpectArrayContaining::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ + JSExpectArrayContaining* thisObject = jsCast(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); + + thisObject->visitAdditionalChildren(visitor); +} + +DEFINE_VISIT_CHILDREN(JSExpectArrayContaining); + +template +void JSExpectArrayContaining::visitAdditionalChildren(Visitor& visitor) +{ + JSExpectArrayContaining* thisObject = this; + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + visitor.append(thisObject->m_arrayValue); +} + +DEFINE_VISIT_ADDITIONAL_CHILDREN(JSExpectArrayContaining); + +template +void JSExpectArrayContaining::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor) +{ + JSExpectArrayContaining* thisObject = jsCast(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + thisObject->visitAdditionalChildren(visitor); +} + +DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSExpectArrayContaining); class JSExpectStringContainingPrototype final : public JSC::JSNonFinalObject { public: using Base = JSC::JSNonFinalObject; diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index 142a96746..33aa58487 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -1004,6 +1004,62 @@ public: void finishCreation(JSC::VM&); }; +class JSExpectArrayContaining final : public JSC::JSDestructibleObject { +public: + using Base = JSC::JSDestructibleObject; + static JSExpectArrayContaining* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); + + DECLARE_EXPORT_INFO; + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForExpectArrayContaining.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForExpectArrayContaining = std::forward(space); }, + [](auto& spaces) { return spaces.m_subspaceForExpectArrayContaining.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForExpectArrayContaining = std::forward(space); }); + } + + static void destroy(JSC::JSCell*); + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast(0b11101110), StructureFlags), info()); + } + + static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); + ; + + ~JSExpectArrayContaining(); + + void* wrapped() const { return m_ctx; } + + void detach() + { + m_ctx = nullptr; + } + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSExpectArrayContaining, m_ctx); } + + void* m_ctx { nullptr }; + + JSExpectArrayContaining(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) + : Base(vm, structure) + { + m_ctx = sinkPtr; + } + + void finishCreation(JSC::VM&); + + DECLARE_VISIT_CHILDREN; + template void visitAdditionalChildren(Visitor&); + DECLARE_VISIT_OUTPUT_CONSTRAINTS; + + mutable JSC::WriteBarrier m_arrayValue; +}; + class JSExpectStringContaining final : public JSC::JSDestructibleObject { public: using Base = JSC::JSDestructibleObject; diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 173a454a1..47ef36aea 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -229,6 +229,47 @@ AsymmetricMatcherResult matchAsymmetricMatcher(JSGlobalObject* globalObject, JSC } } + return AsymmetricMatcherResult::FAIL; + } else if (auto* expectArrayContaining = jsDynamicCast(matcherPropCell)) { + JSValue expectedArrayValue = expectArrayContaining->m_arrayValue.get(); + + if (JSC::isArray(globalObject, otherProp)) { + if (JSC::isArray(globalObject, expectedArrayValue)) { + JSArray* expectedArray = jsDynamicCast(expectedArrayValue); + JSArray* otherArray = jsDynamicCast(otherProp); + + unsigned expectedLength = expectedArray->length(); + unsigned otherLength = otherArray->length(); + + // A empty array is all array's subset + if (expectedLength == 0) { + return AsymmetricMatcherResult::PASS; + } + + // O(m*n) but works for now + for (unsigned m = 0; m < expectedLength; m++) { + JSValue expectedValue = expectedArray->getIndex(globalObject, m); + bool found = false; + + for (unsigned n = 0; n < otherLength; n++) { + JSValue otherValue = otherArray->getIndex(globalObject, n); + ThrowScope scope = DECLARE_THROW_SCOPE(globalObject->vm()); + Vector, 16> stack; + if (Bun__deepEquals(globalObject, expectedValue, otherValue, stack, &scope, true)) { + found = true; + break; + } + } + + if (!found) { + return AsymmetricMatcherResult::FAIL; + } + } + + return AsymmetricMatcherResult::PASS; + } + } + return AsymmetricMatcherResult::FAIL; } @@ -4702,4 +4743,4 @@ CPP_DECL void JSC__VM__setControlFlowProfiler(JSC__VM* vm, bool isEnabled) } else { vm->disableControlFlowProfiler(); } -} \ No newline at end of file +} diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 329506718..581d4a5f3 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -2507,6 +2507,87 @@ pub const JSExpectAnything = struct { } } }; +pub const JSExpectArrayContaining = struct { + const ExpectArrayContaining = Classes.ExpectArrayContaining; + const GetterType = fn (*ExpectArrayContaining, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const GetterTypeWithThisValue = fn (*ExpectArrayContaining, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const SetterType = fn (*ExpectArrayContaining, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const SetterTypeWithThisValue = fn (*ExpectArrayContaining, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const CallbackType = fn (*ExpectArrayContaining, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue; + + /// Return the pointer to the wrapped object. + /// If the object does not match the type, return null. + pub fn fromJS(value: JSC.JSValue) ?*ExpectArrayContaining { + JSC.markBinding(@src()); + return ExpectArrayContaining__fromJS(value); + } + + extern fn ExpectArrayContainingPrototype__arrayValueSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void; + + extern fn ExpectArrayContainingPrototype__arrayValueGetCachedValue(JSC.JSValue) JSC.JSValue; + + /// `ExpectArrayContaining.arrayValue` setter + /// This value will be visited by the garbage collector. + pub fn arrayValueSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { + JSC.markBinding(@src()); + ExpectArrayContainingPrototype__arrayValueSetCachedValue(thisValue, globalObject, value); + } + + /// `ExpectArrayContaining.arrayValue` getter + /// This value will be visited by the garbage collector. + pub fn arrayValueGetCached(thisValue: JSC.JSValue) ?JSC.JSValue { + JSC.markBinding(@src()); + const result = ExpectArrayContainingPrototype__arrayValueGetCachedValue(thisValue); + if (result == .zero) + return null; + + return result; + } + + /// Create a new instance of ExpectArrayContaining + pub fn toJS(this: *ExpectArrayContaining, globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + if (comptime Environment.allow_assert) { + const value__ = ExpectArrayContaining__create(globalObject, this); + std.debug.assert(value__.as(ExpectArrayContaining).? == this); // If this fails, likely a C ABI issue. + return value__; + } else { + return ExpectArrayContaining__create(globalObject, this); + } + } + + /// Modify the internal ptr to point to a new instance of ExpectArrayContaining. + pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*ExpectArrayContaining) bool { + JSC.markBinding(@src()); + return ExpectArrayContaining__dangerouslySetPtr(value, ptr); + } + + /// Detach the ptr from the thisValue + pub fn detachPtr(_: *ExpectArrayContaining, value: JSC.JSValue) void { + JSC.markBinding(@src()); + std.debug.assert(ExpectArrayContaining__dangerouslySetPtr(value, null)); + } + + extern fn ExpectArrayContaining__fromJS(JSC.JSValue) ?*ExpectArrayContaining; + extern fn ExpectArrayContaining__getConstructor(*JSC.JSGlobalObject) JSC.JSValue; + + extern fn ExpectArrayContaining__create(globalObject: *JSC.JSGlobalObject, ptr: ?*ExpectArrayContaining) JSC.JSValue; + + extern fn ExpectArrayContaining__dangerouslySetPtr(JSC.JSValue, ?*ExpectArrayContaining) bool; + + comptime { + if (@TypeOf(ExpectArrayContaining.finalize) != (fn (*ExpectArrayContaining) callconv(.C) void)) { + @compileLog("ExpectArrayContaining.finalize is not a finalizer"); + } + + if (@TypeOf(ExpectArrayContaining.call) != StaticCallbackType) + @compileLog("Expected ExpectArrayContaining.call to be a static callback"); + if (!JSC.is_bindgen) { + @export(ExpectArrayContaining.call, .{ .name = "ExpectArrayContainingClass__call" }); + @export(ExpectArrayContaining.finalize, .{ .name = "ExpectArrayContainingClass__finalize" }); + } + } +}; pub const JSExpectStringContaining = struct { const ExpectStringContaining = Classes.ExpectStringContaining; const GetterType = fn (*ExpectStringContaining, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; @@ -7006,6 +7087,7 @@ comptime { _ = JSExpect; _ = JSExpectAny; _ = JSExpectAnything; + _ = JSExpectArrayContaining; _ = JSExpectStringContaining; _ = JSExpectStringMatching; _ = JSFFI; diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig index a86f74dd3..3b45f33b8 100644 --- a/src/bun.js/bindings/generated_classes_list.zig +++ b/src/bun.js/bindings/generated_classes_list.zig @@ -17,6 +17,7 @@ pub const Classes = struct { pub const ExpectAnything = JSC.Expect.ExpectAnything; pub const ExpectStringContaining = JSC.Expect.ExpectStringContaining; pub const ExpectStringMatching = JSC.Expect.ExpectStringMatching; + pub const ExpectArrayContaining = JSC.Expect.ExpectArrayContaining; pub const FileSystemRouter = JSC.API.FileSystemRouter; pub const Bundler = JSC.API.JSBundler; pub const JSBundler = Bundler; diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 0d3ff663e..6434e3702 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -3437,8 +3437,11 @@ pub const Expect = struct { return ExpectStringMatching.call(globalObject, callFrame); } + pub fn arrayContaining(globalObject: *JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) JSValue { + return ExpectArrayContaining.call(globalObject, callFrame); + } + pub const extend = notImplementedStaticFn; - pub const arrayContaining = notImplementedStaticFn; pub const assertions = notImplementedStaticFn; pub const hasAssertions = notImplementedStaticFn; pub const objectContaining = notImplementedStaticFn; @@ -3621,6 +3624,43 @@ pub const ExpectAny = struct { } }; +pub const ExpectArrayContaining = struct { + pub usingnamespace JSC.Codegen.JSExpectArrayContaining; + + pub fn finalize( + this: *ExpectArrayContaining, + ) callconv(.C) void { + VirtualMachine.get().allocator.destroy(this); + } + + pub fn call(globalObject: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) JSValue { + const args = callFrame.arguments(1).slice(); + + if (args.len == 0 or !args[0].jsType().isArray()) { + const fmt = "expect.arrayContaining(array)\n\nExpected a array\n"; + globalObject.throwPretty(fmt, .{}); + return .zero; + } + + const array_value = args[0]; + const array_containing = globalObject.bunVM().allocator.create(ExpectArrayContaining) catch unreachable; + + if (Jest.runner.?.pending_test == null) { + const err = globalObject.createErrorInstance("expect.arrayContaining() must be called in a test", .{}); + err.put(globalObject, ZigString.static("name"), ZigString.init("TestNotRunningError").toValueGC(globalObject)); + globalObject.throwValue(err); + return .zero; + } + + const array_containing_js_value = array_containing.toJS(globalObject); + ExpectArrayContaining.arrayValueSetCached(array_containing_js_value, globalObject, array_value); + + var vm = globalObject.bunVM(); + vm.autoGarbageCollect(); + return array_containing_js_value; + } +}; + /// JSValue.zero is used to indicate it was not a JSMockFunction /// If there were no calls, it returns an empty JSArray* extern fn JSMockFunction__getCalls(JSValue) JSValue; diff --git a/src/bun.js/test/jest.classes.ts b/src/bun.js/test/jest.classes.ts index d40acbf07..186c8f9a8 100644 --- a/src/bun.js/test/jest.classes.ts +++ b/src/bun.js/test/jest.classes.ts @@ -48,6 +48,18 @@ export default [ klass: {}, proto: {}, }), + define({ + name: "ExpectArrayContaining", + construct: false, + noConstructor: true, + call: true, + finalize: true, + JSType: "0b11101110", + values: ["arrayValue"], + configurable: false, + klass: {}, + proto: {}, + }), define({ name: "Expect", construct: true, diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js index 804a5339f..4b9e5ec22 100644 --- a/test/js/bun/test/expect.test.js +++ b/test/js/bun/test/expect.test.js @@ -1298,6 +1298,16 @@ describe("expect()", () => { a = { a: 1, b: 2, c: 3 }; b = { a: 1, b: 2 }; expect(a).not.toEqual(b); + + array1 = [1, 2, 3]; + expect(array1).toEqual(expect.arrayContaining([])); + expect(array1).toEqual(expect.arrayContaining([1, 2])); + expect(array1).not.toEqual(expect.arrayContaining([1, 2, 4])); + + array2 = [{ a: 1, b: 2 }, { a: { a: 1 } }]; + expect(array2).toEqual(expect.arrayContaining([{ a: 1, b: 2 }])); + expect(array2).toEqual(expect.arrayContaining([{ a: { a: 1 } }])); + expect(array2).not.toEqual(expect.arrayContaining([{ a: 2, b: 3 }])); }); test("symbol based keys in arrays are processed correctly", () => { @@ -2624,6 +2634,12 @@ describe("expect()", () => { expect({ a: [1, 2, 3] }).toMatchObject({ a: [1, 2, 3] }); expect({ a: [1, 2, 4] }).not.toMatchObject({ a: [1, 2, 3] }); + expect({ a: [1, 2, 3] }).toMatchObject({ a: expect.arrayContaining([1, 2]) }); + expect({ a: [1, 2, 3] }).not.toMatchObject({ a: expect.arrayContaining([4]) }); + expect({ a: ['hello', 'world'] }).toMatchObject({ a: expect.arrayContaining([]) }); + expect({ a: ['hello', 'world'] }).toMatchObject({ a: expect.arrayContaining(['world']) }); + expect({ a: ['hello', 'world'] }).not.toMatchObject({ a: expect.arrayContaining(['hello', 'mars']) }); + expect([]).toMatchObject([]); expect([]).toMatchObject({}); expect({}).not.toMatchObject([]); -- cgit v1.2.3