diff options
author | 2022-11-07 20:43:34 -0800 | |
---|---|---|
committer | 2022-11-07 20:43:34 -0800 | |
commit | b4abb0f33705018d93aae86a04c3a669ba7dfb31 (patch) | |
tree | d2a8513be37ce34a05097a7e2bee47c84742d792 | |
parent | 41c983b3868a32257873795dd6248c91d87b27fe (diff) | |
download | bun-b4abb0f33705018d93aae86a04c3a669ba7dfb31.tar.gz bun-b4abb0f33705018d93aae86a04c3a669ba7dfb31.tar.zst bun-b4abb0f33705018d93aae86a04c3a669ba7dfb31.zip |
Visit all the fields
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 104 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.h | 86 |
2 files changed, 111 insertions, 79 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 4d05c8ace..1056ec445 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -2037,29 +2037,27 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotask, (JSGlobalObject * globalObj JSValue result; WTF::NakedPtr<JSC::Exception> exceptionPtr; - switch (callframe->argumentCount()) { - case 1: - JSC::call(globalObject, job, callData, jsUndefined(), arguments, exceptionPtr); - break; - case 2: - arguments.append(callframe->argument(1)); - JSC::call(globalObject, job, callData, jsUndefined(), arguments, exceptionPtr); - break; - case 3: - arguments.append(callframe->argument(1)); - arguments.append(callframe->argument(2)); - JSC::call(globalObject, job, callData, jsUndefined(), arguments, exceptionPtr); - break; - case 4: - arguments.append(callframe->argument(1)); - arguments.append(callframe->argument(2)); - arguments.append(callframe->argument(3)); - JSC::call(globalObject, job, callData, jsUndefined(), arguments, exceptionPtr); - break; - default: - RELEASE_ASSERT_NOT_REACHED(); + size_t argCount = callframe->argumentCount(); + if (argCount > 1) { + if (JSValue arg0 = callframe->argument(1)) { + arguments.append(arg0); + } + + if (argCount > 2) { + if (JSValue arg1 = callframe->argument(2)) { + arguments.append(arg1); + } + + if (argCount > 3) { + if (JSValue arg2 = callframe->argument(3)) { + arguments.append(arg2); + } + } + } } + JSC::call(globalObject, job, callData, jsUndefined(), arguments, exceptionPtr); + if (auto* exception = exceptionPtr.get()) { Bun__reportUnhandledError(globalObject, JSValue::encode(exception)); } @@ -2992,33 +2990,52 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) visitor.append(constructor); thisObject->m_builtinInternalFunctions.visit(visitor); - thisObject->m_JSFFIFunctionStructure.visit(visitor); + + visitor.append(thisObject->m_assignToStream); + visitor.append(thisObject->m_readableStreamToArrayBuffer); + visitor.append(thisObject->m_readableStreamToArrayBufferResolve); + visitor.append(thisObject->m_readableStreamToBlob); + visitor.append(thisObject->m_readableStreamToJSON); + visitor.append(thisObject->m_readableStreamToText); + + visitor.append(thisObject->m_JSTextDecoderSetterValue); + visitor.append(thisObject->m_JSResponseSetterValue); + visitor.append(thisObject->m_JSRequestSetterValue); + visitor.append(thisObject->m_JSBlobSetterValue); + visitor.append(thisObject->m_JSMessageEventSetterValue); + visitor.append(thisObject->m_JSBufferSetterValue); + visitor.append(thisObject->m_JSWebSocketSetterValue); + visitor.append(thisObject->m_JSFetchHeadersSetterValue); + visitor.append(thisObject->m_JSTextEncoderSetterValue); + visitor.append(thisObject->m_JSURLSearchParamsSetterValue); + thisObject->m_JSArrayBufferSinkClassStructure.visit(visitor); - thisObject->m_JSArrayBufferControllerPrototype.visit(visitor); thisObject->m_JSBufferListClassStructure.visit(visitor); - thisObject->m_JSStringDecoderClassStructure.visit(visitor); + thisObject->m_JSFFIFunctionStructure.visit(visitor); + thisObject->m_JSFileSinkClassStructure.visit(visitor); + thisObject->m_JSHTTPResponseSinkClassStructure.visit(visitor); + thisObject->m_JSHTTPSResponseSinkClassStructure.visit(visitor); thisObject->m_JSReadableStateClassStructure.visit(visitor); + thisObject->m_JSStringDecoderClassStructure.visit(visitor); + thisObject->m_NapiClassStructure.visit(visitor); + thisObject->m_OnigurumaRegExpClassStructure.visit(visitor); + + thisObject->m_pendingVirtualModuleResultStructure.visit(visitor); + thisObject->m_performMicrotaskFunction.visit(visitor); + thisObject->m_performMicrotaskVariadicFunction.visit(visitor); thisObject->m_lazyReadableStreamPrototypeMap.visit(visitor); thisObject->m_requireMap.visit(visitor); + thisObject->m_encodeIntoObjectPrototype.visit(visitor); + thisObject->m_JSArrayBufferControllerPrototype.visit(visitor); + thisObject->m_JSFileSinkControllerPrototype.visit(visitor); + thisObject->m_JSHTTPSResponseControllerPrototype.visit(visitor); + thisObject->m_navigatorObject.visit(visitor); + thisObject->m_performanceObject.visit(visitor); + thisObject->m_primordialsObject.visit(visitor); thisObject->m_processEnvObject.visit(visitor); thisObject->m_processObject.visit(visitor); - thisObject->m_performanceObject.visit(visitor); - thisObject->m_navigatorObject.visit(visitor); thisObject->m_subtleCryptoObject.visit(visitor); - thisObject->m_primordialsObject.visit(visitor); - - thisObject->m_JSHTTPResponseSinkClassStructure.visit(visitor); - thisObject->m_JSHTTPSResponseSinkClassStructure.visit(visitor); - thisObject->m_JSFileSinkClassStructure.visit(visitor); - thisObject->m_OnigurumaRegExpClassStructure.visit(visitor); - - visitor.append(thisObject->m_JSBufferSetterValue); - visitor.append(thisObject->m_JSTextEncoderSetterValue); - visitor.append(thisObject->m_JSMessageEventSetterValue); - visitor.append(thisObject->m_JSWebSocketSetterValue); - visitor.append(thisObject->m_JSFetchHeadersSetterValue); - visitor.append(thisObject->m_JSTextEncoderSetterValue); - visitor.append(thisObject->m_JSURLSearchParamsSetterValue); + thisObject->m_JSHTTPResponseController.visit(visitor); for (auto& barrier : thisObject->m_thenables) { visitor.append(barrier); @@ -3026,13 +3043,6 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) thisObject->visitGeneratedLazyClasses<Visitor>(thisObject, visitor); - visitor.append(thisObject->m_readableStreamToArrayBufferResolve); - visitor.append(thisObject->m_readableStreamToText); - visitor.append(thisObject->m_readableStreamToJSON); - visitor.append(thisObject->m_readableStreamToBlob); - visitor.append(thisObject->m_readableStreamToArrayBuffer); - visitor.append(thisObject->m_assignToStream); - ScriptExecutionContext* context = thisObject->scriptExecutionContext(); visitor.addOpaqueRoot(context); } diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h index 06be6b17c..8613bc912 100644 --- a/src/bun.js/bindings/ZigGlobalObject.h +++ b/src/bun.js/bindings/ZigGlobalObject.h @@ -348,20 +348,30 @@ public: return func; } + /** + * WARNING: You must update visitChildrenImpl() if you add a new field. + * + * That informs the garbage collector that these fields exist. If you don't + * do that, the garbage collector will not know about these fields and will + * not trace them. This will lead to crashes and very strange behavior at runtime. + * + * For example, if you don't add the queueMicrotask functions to visitChildrenImpl(), + * those callbacks will eventually never be called anymore. But it'll work the first time! + */ + mutable WriteBarrier<JSFunction> m_assignToStream; + mutable WriteBarrier<JSFunction> m_readableStreamToArrayBuffer; mutable WriteBarrier<JSFunction> m_readableStreamToArrayBufferResolve; - mutable WriteBarrier<JSFunction> m_readableStreamToText; mutable WriteBarrier<JSFunction> m_readableStreamToBlob; mutable WriteBarrier<JSFunction> m_readableStreamToJSON; - mutable WriteBarrier<JSFunction> m_readableStreamToArrayBuffer; - mutable WriteBarrier<JSFunction> m_assignToStream; - mutable WriteBarrier<JSFunction> m_thenables[promiseFunctionsSize + 1]; - + mutable WriteBarrier<JSFunction> m_readableStreamToText; mutable WriteBarrier<Unknown> m_JSBufferSetterValue; - mutable WriteBarrier<Unknown> m_JSTextEncoderSetterValue; - mutable WriteBarrier<Unknown> m_JSMessageEventSetterValue; - mutable WriteBarrier<Unknown> m_JSWebSocketSetterValue; mutable WriteBarrier<Unknown> m_JSFetchHeadersSetterValue; + mutable WriteBarrier<Unknown> m_JSMessageEventSetterValue; + mutable WriteBarrier<Unknown> m_JSTextEncoderSetterValue; mutable WriteBarrier<Unknown> m_JSURLSearchParamsSetterValue; + mutable WriteBarrier<Unknown> m_JSWebSocketSetterValue; + + mutable WriteBarrier<JSFunction> m_thenables[promiseFunctionsSize + 1]; JSObject* navigatorObject(); @@ -410,42 +420,54 @@ private: Lock m_gcLock; WebCore::ScriptExecutionContext* m_scriptExecutionContext; Ref<WebCore::DOMWrapperWorld> m_world; - LazyClassStructure m_JSFFIFunctionStructure; - LazyClassStructure m_NapiClassStructure; + + /** + * WARNING: You must update visitChildrenImpl() if you add a new field. + * + * That informs the garbage collector that these fields exist. If you don't + * do that, the garbage collector will not know about these fields and will + * not trace them. This will lead to crashes and very strange behavior at runtime. + * + * For example, if you don't add the queueMicrotask functions to visitChildrenImpl(), + * those callbacks will eventually never be called anymore. But it'll work the first time! + */ LazyClassStructure m_JSArrayBufferSinkClassStructure; + LazyClassStructure m_JSBufferListClassStructure; + LazyClassStructure m_JSFFIFunctionStructure; + LazyClassStructure m_JSFileSinkClassStructure; LazyClassStructure m_JSHTTPResponseSinkClassStructure; LazyClassStructure m_JSHTTPSResponseSinkClassStructure; - LazyClassStructure m_JSFileSinkClassStructure; - LazyClassStructure m_JSBufferListClassStructure; - LazyClassStructure m_JSStringDecoderClassStructure; LazyClassStructure m_JSReadableStateClassStructure; + LazyClassStructure m_JSStringDecoderClassStructure; + LazyClassStructure m_NapiClassStructure; LazyClassStructure m_OnigurumaRegExpClassStructure; - LazyProperty<JSGlobalObject, JSObject> m_primordialsObject; - - LazyProperty<JSGlobalObject, JSObject> m_navigatorObject; - - LazyProperty<JSGlobalObject, JSObject> m_JSArrayBufferControllerPrototype; - LazyProperty<JSGlobalObject, JSObject> m_JSHTTPSResponseControllerPrototype; - LazyProperty<JSGlobalObject, JSObject> m_JSFileSinkControllerPrototype; - - LazyProperty<JSGlobalObject, Structure> m_JSHTTPResponseController; + /** + * WARNING: You must update visitChildrenImpl() if you add a new field. + * + * That informs the garbage collector that these fields exist. If you don't + * do that, the garbage collector will not know about these fields and will + * not trace them. This will lead to crashes and very strange behavior at runtime. + * + * For example, if you don't add the queueMicrotask functions to visitChildrenImpl(), + * those callbacks will eventually never be called anymore. But it'll work the first time! + */ + LazyProperty<JSGlobalObject, JSC::Structure> m_pendingVirtualModuleResultStructure; LazyProperty<JSGlobalObject, JSFunction> m_performMicrotaskFunction; LazyProperty<JSGlobalObject, JSFunction> m_performMicrotaskVariadicFunction; - - LazyProperty<JSGlobalObject, JSObject> m_processObject; - LazyProperty<JSGlobalObject, JSObject> m_processEnvObject; LazyProperty<JSGlobalObject, JSMap> m_lazyReadableStreamPrototypeMap; LazyProperty<JSGlobalObject, JSMap> m_requireMap; + LazyProperty<JSGlobalObject, JSObject> m_encodeIntoObjectPrototype; + LazyProperty<JSGlobalObject, JSObject> m_JSArrayBufferControllerPrototype; + LazyProperty<JSGlobalObject, JSObject> m_JSFileSinkControllerPrototype; + LazyProperty<JSGlobalObject, JSObject> m_JSHTTPSResponseControllerPrototype; + LazyProperty<JSGlobalObject, JSObject> m_navigatorObject; LazyProperty<JSGlobalObject, JSObject> m_performanceObject; - + LazyProperty<JSGlobalObject, JSObject> m_primordialsObject; + LazyProperty<JSGlobalObject, JSObject> m_processEnvObject; + LazyProperty<JSGlobalObject, JSObject> m_processObject; LazyProperty<JSGlobalObject, JSObject> m_subtleCryptoObject; - - LazyProperty<JSGlobalObject, JSC::Structure> m_pendingVirtualModuleResultStructure; - - LazyProperty<JSGlobalObject, JSObject> m_encodeIntoObjectPrototype; - - // LazyProperty<JSGlobalObject, WebCore::JSEventTarget> m_eventTarget; + LazyProperty<JSGlobalObject, Structure> m_JSHTTPResponseController; JSClassRef m_dotEnvClassRef; |