diff options
author | 2022-12-03 08:25:15 -0800 | |
---|---|---|
committer | 2022-12-03 08:26:53 -0800 | |
commit | bdc43c1696f0d759d28cfb63a2eb1aed5273d55f (patch) | |
tree | 604b87032f77ae1902c76a149b98ad7d40b1a2b1 | |
parent | bc028168a815977830460983f28aefa4f7605c5e (diff) | |
download | bun-bdc43c1696f0d759d28cfb63a2eb1aed5273d55f.tar.gz bun-bdc43c1696f0d759d28cfb63a2eb1aed5273d55f.tar.zst bun-bdc43c1696f0d759d28cfb63a2eb1aed5273d55f.zip |
`process.stdout` and `process.stderr`
Diffstat (limited to '')
-rw-r--r-- | src/bun.js/bindings/Process.cpp | 83 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 6 | ||||
-rw-r--r-- | src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp | 8 | ||||
-rw-r--r-- | src/bun.js/builtins/WebCoreJSBuiltins.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp | 63 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/ProcessObjectBuiltins.h | 120 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp | 655 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.h | 175 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h | 3 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/WebCoreJSBuiltins.h | 9 | ||||
-rw-r--r-- | src/bun.js/builtins/js/ProcessObject.js | 24 | ||||
-rw-r--r-- | src/bun.js/builtins/js/ProcessObjectInternals.js | 600 | ||||
-rw-r--r-- | src/bun.js/event_loop.zig | 9 | ||||
-rw-r--r-- | src/bun.js/process-stdio-polyfill.js | 342 | ||||
-rw-r--r-- | src/bun_js.zig | 2 |
15 files changed, 1537 insertions, 564 deletions
diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp index 07aabf343..baac2c587 100644 --- a/src/bun.js/bindings/Process.cpp +++ b/src/bun.js/bindings/Process.cpp @@ -6,7 +6,7 @@ #include "ZigGlobalObject.h" #include "headers.h" #include "JSEnvironmentVariableMap.h" - +#include "ImportMetaObject.h" #pragma mark - Node.js Process namespace Zig { @@ -39,6 +39,78 @@ static JSC_DECLARE_CUSTOM_GETTER(Process_getPPID); static JSC_DECLARE_HOST_FUNCTION(Process_functionCwd); +static JSValue constructStdioWriteStream(JSC::JSGlobalObject* globalObject, int fd) +{ + auto& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + auto* thisObject = reinterpret_cast<Zig::GlobalObject*>(globalObject); + JSC::JSFunction* getStdioWriteStream = JSC::JSFunction::create(vm, processObjectInternalsGetStdioWriteStreamCodeGenerator(vm), globalObject); + JSC::MarkedArgumentBuffer args; + WTF::String process = WTF::String("node:process"_s); + JSC::JSValue requireFunction = Zig::ImportMetaObject::createRequireFunction( + vm, + globalObject, + process); + + args.append(JSC::jsNumber(fd)); + args.append(requireFunction); + + auto clientData = WebCore::clientData(vm); + JSC::CallData callData = JSC::getCallData(getStdioWriteStream); + + NakedPtr<JSC::Exception> returnedException = nullptr; + auto result = JSC::call(globalObject, getStdioWriteStream, callData, globalObject->globalThis(), args, returnedException); + RETURN_IF_EXCEPTION(scope, {}); + + if (returnedException) { + throwException(globalObject, scope, returnedException.get()); + return {}; + } + + return result; +} + +JSC_DEFINE_CUSTOM_GETTER( + Process_lazyStdinGetter, + (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName property)) +{ +} + +JSC_DEFINE_CUSTOM_GETTER( + Process_lazyStdoutGetter, + (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName property)) +{ + JSValue value = JSValue::decode(thisValue); + auto& vm = globalObject->vm(); + JSC::JSObject* thisObject = value.toObject(globalObject); + JSC::JSValue stream = constructStdioWriteStream(globalObject, 1); + thisObject->putDirect(vm, property, stream, 0); + return JSValue::encode(stream); +} + +JSC_DEFINE_CUSTOM_GETTER( + Process_lazyStderrGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName property)) +{ + JSValue value = JSValue::decode(thisValue); + auto& vm = globalObject->vm(); + JSC::JSObject* thisObject = value.toObject(globalObject); + JSC::JSValue stream = constructStdioWriteStream(globalObject, 2); + thisObject->putDirect(vm, property, stream, 0); + return JSValue::encode(stream); +} + +JSC_DEFINE_CUSTOM_SETTER(Process_defaultSetter, + (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, + JSC::EncodedJSValue value, JSC::PropertyName propertyName)) +{ + JSC::VM& vm = globalObject->vm(); + + JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(JSValue::decode(thisValue)); + thisObject->putDirect(vm, propertyName, JSValue::decode(value), 0); + + return true; +} + JSC_DECLARE_HOST_FUNCTION(Process_functionNextTick); JSC_DEFINE_HOST_FUNCTION(Process_functionNextTick, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) @@ -241,7 +313,6 @@ static JSC_DECLARE_HOST_FUNCTION(Process_functionChdir); static JSC_DEFINE_HOST_FUNCTION(Process_functionChdir, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); ZigString str = ZigString { nullptr, 0 }; @@ -389,6 +460,12 @@ void Process::finishCreation(JSC::VM& vm) this->putDirectCustomAccessor(vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "release"_s)), JSC::CustomGetterSetter::create(vm, Process_getterRelease, Process_setterRelease), 0); + + this->putDirectCustomAccessor(vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "stdout"_s)), + JSC::CustomGetterSetter::create(vm, Process_lazyStdoutGetter, Process_defaultSetter), 0); + + this->putDirectCustomAccessor(vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "stderr"_s)), + JSC::CustomGetterSetter::create(vm, Process_lazyStderrGetter, Process_defaultSetter), 0); } const JSC::ClassInfo Process::s_info = { "Process"_s, &Base::s_info, nullptr, nullptr, @@ -522,7 +599,6 @@ JSC_DEFINE_CUSTOM_SETTER(Process_setVersionsLazy, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue value, JSC::PropertyName)) { - JSC::VM& vm = globalObject->vm(); auto clientData = WebCore::clientData(vm); @@ -540,7 +616,6 @@ JSC_DEFINE_CUSTOM_SETTER(Process_setVersionsLazy, static JSC_DEFINE_HOST_FUNCTION(Process_functionCwd, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); JSC::JSValue result = JSC::JSValue::decode(Bun__Process__getCwd(globalObject)); JSC::JSObject* obj = result.getObject(); diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 775382d82..a86590c60 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -2923,7 +2923,6 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.whenSignalAbortedPrivateName(), JSFunction::create(vm, this, 2, String(), whenSignalAborted, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.cloneArrayBufferPrivateName(), JSFunction::create(vm, this, 3, String(), cloneArrayBuffer, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.structuredCloneForStreamPrivateName(), JSFunction::create(vm, this, 1, String(), structuredCloneForStream, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); - extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(vm.propertyNames->builtinNames().ArrayBufferPrivateName(), arrayBufferConstructor(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.streamClosedPrivateName(), jsNumber(1), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::ConstantInteger)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.streamClosingPrivateName(), jsNumber(2), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::ConstantInteger)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.streamErroredPrivateName(), jsNumber(3), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::ConstantInteger)); @@ -2942,7 +2941,6 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) extraStaticGlobals.releaseBuffer(); putDirectBuiltinFunction(vm, this, builtinNames.createFIFOPrivateName(), streamInternalsCreateFIFOCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); - putDirectBuiltinFunction(vm, this, builtinNames.createNativeReadableStreamPrivateName(), readableStreamCreateNativeReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); putDirectBuiltinFunction(vm, this, builtinNames.createEmptyReadableStreamPrivateName(), readableStreamCreateEmptyReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); putDirectBuiltinFunction(vm, this, builtinNames.consumeReadableStreamPrivateName(), readableStreamConsumeReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); @@ -2952,7 +2950,6 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) putDirectBuiltinFunction(vm, this, builtinNames.requireESMPrivateName(), importMetaObjectRequireESMCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); putDirectBuiltinFunction(vm, this, builtinNames.requirePrivateName(), importMetaObjectRequireCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); putDirectBuiltinFunction(vm, this, builtinNames.loadCJS2ESMPrivateName(), importMetaObjectLoadCJS2ESMCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); - putDirectNativeFunction(vm, this, builtinNames.createUninitializedArrayBufferPrivateName(), 1, functionCreateUninitializedArrayBuffer, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function); putDirectNativeFunction(vm, this, builtinNames.resolveSyncPrivateName(), 1, functionImportMeta__resolveSync, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function); @@ -3034,7 +3031,6 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().WritableStreamDefaultControllerPrivateName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_WritableStreamDefaultControllerConstructor, nullptr), attributesForStructure(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly)); putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().WritableStreamDefaultWriterPrivateName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_WritableStreamDefaultWriterConstructor, nullptr), attributesForStructure(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly)); putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().AbortSignalPrivateName(), CustomGetterSetter::create(vm, JSDOMAbortSignal_getter, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); - putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().TransformStreamDefaultControllerPublicName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_TransformStreamDefaultControllerConstructor, nullptr), static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DontEnum)); putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().ReadableByteStreamControllerPublicName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_ReadableByteStreamControllerConstructor, nullptr), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().ReadableStreamPublicName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_ReadableStreamConstructor, nullptr), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); @@ -3045,9 +3041,9 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().WritableStreamPublicName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_WritableStreamConstructor, nullptr), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().WritableStreamDefaultControllerPublicName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_WritableStreamDefaultControllerConstructor, nullptr), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().WritableStreamDefaultWriterPublicName(), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_WritableStreamDefaultWriterConstructor, nullptr), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "ByteLengthQueuingStrategy"_s), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_ByteLengthQueuingStrategyConstructor, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "CountQueuingStrategy"_s), CustomGetterSetter::create(vm, jsServiceWorkerGlobalScope_CountQueuingStrategyConstructor, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); - putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "SubtleCrypto"_s), JSC::CustomGetterSetter::create(vm, getterSubtleCryptoConstructor, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "CryptoKey"_s), JSC::CustomGetterSetter::create(vm, getterCryptoKeyConstructor, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); } diff --git a/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp index 93e13369a..697f6b5ee 100644 --- a/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp +++ b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp @@ -52,6 +52,7 @@ namespace WebCore { JSBuiltinInternalFunctions::JSBuiltinInternalFunctions(JSC::VM& vm) : m_vm(vm) + , m_processObjectInternals(m_vm) , m_readableByteStreamInternals(m_vm) , m_readableStreamInternals(m_vm) , m_streamInternals(m_vm) @@ -64,6 +65,7 @@ JSBuiltinInternalFunctions::JSBuiltinInternalFunctions(JSC::VM& vm) template<typename Visitor> void JSBuiltinInternalFunctions::visit(Visitor& visitor) { + m_processObjectInternals.visit(visitor); m_readableByteStreamInternals.visit(visitor); m_readableStreamInternals.visit(visitor); m_streamInternals.visit(visitor); @@ -78,6 +80,7 @@ template void JSBuiltinInternalFunctions::visit(SlotVisitor&); SUPPRESS_ASAN void JSBuiltinInternalFunctions::initialize(JSDOMGlobalObject& globalObject) { UNUSED_PARAM(globalObject); + m_processObjectInternals.init(globalObject); m_readableByteStreamInternals.init(globalObject); m_readableStreamInternals.init(globalObject); m_streamInternals.init(globalObject); @@ -88,6 +91,11 @@ SUPPRESS_ASAN void JSBuiltinInternalFunctions::initialize(JSDOMGlobalObject& glo JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = { #define DECLARE_GLOBAL_STATIC(name) \ JSDOMGlobalObject::GlobalPropertyInfo( \ + clientData.builtinFunctions().processObjectInternalsBuiltins().name##PrivateName(), processObjectInternals().m_##name##Function.get() , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly), + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_GLOBAL_STATIC) +#undef DECLARE_GLOBAL_STATIC +#define DECLARE_GLOBAL_STATIC(name) \ + JSDOMGlobalObject::GlobalPropertyInfo( \ clientData.builtinFunctions().readableByteStreamInternalsBuiltins().name##PrivateName(), readableByteStreamInternals().m_##name##Function.get() , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly), WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_GLOBAL_STATIC) #undef DECLARE_GLOBAL_STATIC diff --git a/src/bun.js/builtins/WebCoreJSBuiltins.cpp b/src/bun.js/builtins/WebCoreJSBuiltins.cpp index eedab6754..f98915cb0 100644 --- a/src/bun.js/builtins/WebCoreJSBuiltins.cpp +++ b/src/bun.js/builtins/WebCoreJSBuiltins.cpp @@ -40,7 +40,7 @@ #include "JSBufferConstructorBuiltins.cpp" #include "JSBufferPrototypeBuiltins.cpp" #include "OnigurumaRegExpPrototypeBuiltins.cpp" -#include "ProcessObjectBuiltins.cpp" +#include "ProcessObjectInternalsBuiltins.cpp" #include "ReadableByteStreamControllerBuiltins.cpp" #include "ReadableByteStreamInternalsBuiltins.cpp" #include "ReadableStreamBYOBReaderBuiltins.cpp" diff --git a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp b/src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp deleted file mode 100644 index 0a0389ca3..000000000 --- a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2015 Igalia - * Copyright (c) 2015 Igalia S.L. - * Copyright (c) 2015 Igalia. - * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. - * Copyright (c) 2015, 2016, 2017 Canon Inc. - * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. - * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. - * Copyright (c) 2022 Codeblog Corp. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for -// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py - -#include "config.h" -#include "ProcessObjectBuiltins.h" - -#include "WebCoreJSClientData.h" -#include <JavaScriptCore/HeapInlines.h> -#include <JavaScriptCore/IdentifierInlines.h> -#include <JavaScriptCore/ImplementationVisibility.h> -#include <JavaScriptCore/Intrinsic.h> -#include <JavaScriptCore/JSCJSValueInlines.h> -#include <JavaScriptCore/JSCellInlines.h> -#include <JavaScriptCore/StructureInlines.h> -#include <JavaScriptCore/VM.h> - -namespace WebCore { - - -#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ -JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ -{\ - JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ - return clientData->builtinFunctions().processObjectBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().processObjectBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \ -} -WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) -#undef DEFINE_BUILTIN_GENERATOR - - -} // namespace WebCore diff --git a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.h b/src/bun.js/builtins/cpp/ProcessObjectBuiltins.h deleted file mode 100644 index b48359479..000000000 --- a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2015 Igalia - * Copyright (c) 2015 Igalia S.L. - * Copyright (c) 2015 Igalia. - * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. - * Copyright (c) 2015, 2016, 2017 Canon Inc. - * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. - * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. - * Copyright (c) 2022 Codeblog Corp. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for -// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py - -#pragma once - -#include <JavaScriptCore/BuiltinUtils.h> -#include <JavaScriptCore/Identifier.h> -#include <JavaScriptCore/JSFunction.h> -#include <JavaScriptCore/UnlinkedFunctionExecutable.h> - -namespace JSC { -class FunctionExecutable; -} - -namespace WebCore { - -/* ProcessObject */ - -#define WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_DATA(macro) \ - - -#define WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_CODE(macro) \ - -#define WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_FUNCTION_NAME(macro) \ - -#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ - JSC::FunctionExecutable* codeName##Generator(JSC::VM&); - -WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) -#undef DECLARE_BUILTIN_GENERATOR - -class ProcessObjectBuiltinsWrapper : private JSC::WeakHandleOwner { -public: - explicit ProcessObjectBuiltinsWrapper(JSC::VM& vm) - : m_vm(vm) - WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) -#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { })) - WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) -#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS - { - } - -#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ - JSC::UnlinkedFunctionExecutable* name##Executable(); \ - const JSC::SourceCode& name##Source() const { return m_##name##Source; } - WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) -#undef EXPOSE_BUILTIN_EXECUTABLES - - WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) - - void exportNames(); - -private: - JSC::VM& m_vm; - - WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) - -#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \ - JSC::SourceCode m_##name##Source;\ - JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable; - WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) -#undef DECLARE_BUILTIN_SOURCE_MEMBERS - -}; - -#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ -inline JSC::UnlinkedFunctionExecutable* ProcessObjectBuiltinsWrapper::name##Executable() \ -{\ - if (!m_##name##Executable) {\ - JSC::Identifier executableName = functionName##PublicName();\ - if (overriddenName)\ - executableName = JSC::Identifier::fromString(m_vm, overriddenName);\ - m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ImplementationVisibility, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\ - }\ - return m_##name##Executable.get();\ -} -WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) -#undef DEFINE_BUILTIN_EXECUTABLES - -inline void ProcessObjectBuiltinsWrapper::exportNames() -{ -#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); - WEBCORE_FOREACH_PROCESSOBJECT_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) -#undef EXPORT_FUNCTION_NAME -} - -} // namespace WebCore diff --git a/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp new file mode 100644 index 000000000..ed5ea553e --- /dev/null +++ b/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp @@ -0,0 +1,655 @@ +/* + * Copyright (c) 2015 Igalia + * Copyright (c) 2015 Igalia S.L. + * Copyright (c) 2015 Igalia. + * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. + * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. + * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. + * Copyright (c) 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#include "config.h" +#include "ProcessObjectInternalsBuiltins.h" + +#include "WebCoreJSClientData.h" +#include <JavaScriptCore/HeapInlines.h> +#include <JavaScriptCore/IdentifierInlines.h> +#include <JavaScriptCore/ImplementationVisibility.h> +#include <JavaScriptCore/Intrinsic.h> +#include <JavaScriptCore/JSCJSValueInlines.h> +#include <JavaScriptCore/JSCellInlines.h> +#include <JavaScriptCore/StructureInlines.h> +#include <JavaScriptCore/VM.h> + +namespace WebCore { + +const JSC::ConstructAbility s_processObjectInternalsGetStdioWriteStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_processObjectInternalsGetStdioWriteStreamCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_processObjectInternalsGetStdioWriteStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_processObjectInternalsGetStdioWriteStreamCodeLength = 9885; +static const JSC::Intrinsic s_processObjectInternalsGetStdioWriteStreamCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_processObjectInternalsGetStdioWriteStreamCode = + "(function (fd_, rawRequire) {\n" \ + " var module = { path: \"node:process\", require: rawRequire };\n" \ + " var require = (path) => module.require(path);\n" \ + "\n" \ + " function createStdioWriteStream(fd_) {\n" \ + " var { Duplex, eos, destroy } = require(\"node:stream\");\n" \ + " var StdioWriteStream = class StdioWriteStream extends Duplex {\n" \ + " #writeStream;\n" \ + " #readStream;\n" \ + "\n" \ + " #readable = true;\n" \ + " #writable = true;\n" \ + " #fdPath;\n" \ + "\n" \ + " #onClose;\n" \ + " #onDrain;\n" \ + " #onFinish;\n" \ + " #onReadable;\n" \ + " #isTTY;\n" \ + "\n" \ + " get isTTY() {\n" \ + " return (this.#isTTY ??= require(\"node:tty\").isatty(fd_));\n" \ + " }\n" \ + "\n" \ + " get fd() {\n" \ + " return fd_;\n" \ + " }\n" \ + "\n" \ + " constructor(fd) {\n" \ + " super({ readable: true, writable: true });\n" \ + " this.#fdPath = `/dev/fd/${fd}`;\n" \ + " }\n" \ + "\n" \ + " #onFinished(err) {\n" \ + " const cb = this.#onClose;\n" \ + " this.#onClose = null;\n" \ + "\n" \ + " if (cb) {\n" \ + " cb(err);\n" \ + " } else if (err) {\n" \ + " this.destroy(err);\n" \ + " } else if (!this.#readable && !this.#writable) {\n" \ + " this.destroy();\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " _destroy(err, callback) {\n" \ + " if (!err && this.#onClose !== null) {\n" \ + " var AbortError = class AbortError extends Error {\n" \ + " constructor(\n" \ + " message = \"The operation was aborted\",\n" \ + " options = void 0,\n" \ + " ) {\n" \ + " if (options !== void 0 && typeof options !== \"object\") {\n" \ + " throw new Error(\n" \ + " `Invalid AbortError options:\\n" \ + "\\n" \ + "${JSON.stringify(\n" \ + " options,\n" \ + " null,\n" \ + " 2,\n" \ + " )}`,\n" \ + " );\n" \ + " }\n" \ + " super(message, options);\n" \ + " this.code = \"ABORT_ERR\";\n" \ + " this.name = \"AbortError\";\n" \ + " }\n" \ + " };\n" \ + " err = new AbortError();\n" \ + " }\n" \ + "\n" \ + " this.#onDrain = null;\n" \ + " this.#onFinish = null;\n" \ + " if (this.#onClose === null) {\n" \ + " callback(err);\n" \ + " } else {\n" \ + " this.#onClose = callback;\n" \ + " if (this.#writeStream) destroy(this.#writeStream, err);\n" \ + " if (this.#readStream) destroy(this.#readStream, err);\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " _write(chunk, encoding, callback) {\n" \ + " if (!this.#writeStream) {\n" \ + " var { createWriteStream } = require(\"node:fs\");\n" \ + " var stream = (this.#writeStream = createWriteStream(this.#fdPath));\n" \ + "\n" \ + " stream.on(\"finish\", () => {\n" \ + " if (this.#onFinish) {\n" \ + " const cb = this.#onFinish;\n" \ + " this.#onFinish = null;\n" \ + " cb();\n" \ + " }\n" \ + " });\n" \ + "\n" \ + " stream.on(\"drain\", () => {\n" \ + " if (this.#onDrain) {\n" \ + " const cb = this.#onDrain;\n" \ + " this.#onDrain = null;\n" \ + " cb();\n" \ + " }\n" \ + " });\n" \ + "\n" \ + " eos(stream, (err) => {\n" \ + " this.#writable = false;\n" \ + " if (err) {\n" \ + " destroy(stream, err);\n" \ + " }\n" \ + " this.#onFinished(err);\n" \ + " });\n" \ + " }\n" \ + " if (stream.write(chunk, encoding)) {\n" \ + " callback();\n" \ + " } else {\n" \ + " this.#onDrain = callback;\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " _final(callback) {\n" \ + " this.#writeStream && this.#writeStream.end();\n" \ + " this.#onFinish = callback;\n" \ + " }\n" \ + "\n" \ + " #loadReadStream() {\n" \ + " var { createReadStream } = require(\"node:fs\");\n" \ + "\n" \ + " var readStream = (this.#readStream = createReadStream(this.#fdPath));\n" \ + "\n" \ + " readStream.on(\"readable\", () => {\n" \ + " if (this.#onReadable) {\n" \ + " const cb = this.#onReadable;\n" \ + " this.#onReadable = null;\n" \ + " cb();\n" \ + " } else {\n" \ + " this.read();\n" \ + " }\n" \ + " });\n" \ + "\n" \ + " readStream.on(\"end\", () => {\n" \ + " this.push(null);\n" \ + " });\n" \ + "\n" \ + " eos(readStream, (err) => {\n" \ + " this.#readable = false;\n" \ + " if (err) {\n" \ + " destroy(readStream, err);\n" \ + " }\n" \ + " this.#onFinished(err);\n" \ + " });\n" \ + " return readStream;\n" \ + " }\n" \ + "\n" \ + " _read() {\n" \ + " var stream = this.#readStream;\n" \ + " if (!stream) {\n" \ + " stream = this.#loadReadStream();\n" \ + " }\n" \ + "\n" \ + " while (true) {\n" \ + " const buf = stream.read();\n" \ + " if (buf === null || !this.push(buf)) {\n" \ + " return;\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + " };\n" \ + " return new StdioWriteStream(fd_);\n" \ + " }\n" \ + "\n" \ + " var { EventEmitter } = require(\"node:events\");\n" \ + "\n" \ + " function isFastEncoding(encoding) {\n" \ + " if (!encoding) return true;\n" \ + "\n" \ + " var normalied = encoding.toLowerCase();\n" \ + " return (\n" \ + " normalied === \"utf8\" ||\n" \ + " normalied === \"utf-8\" ||\n" \ + " normalied === \"buffer\" ||\n" \ + " normalied === \"binary\" ||\n" \ + " normalized === \"\"\n" \ + " );\n" \ + " }\n" \ + " var FastStdioWriteStream = class StdioWriteStream extends EventEmitter {\n" \ + " #fd;\n" \ + " #innerStream;\n" \ + " #writer;\n" \ + " #isTTY;\n" \ + "\n" \ + " bytesWritten = 0;\n" \ + "\n" \ + " setDefaultEncoding(encoding) {\n" \ + " if (this.#innerStream || !isFastEncoding(encoding)) {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream.setDefaultEncoding(encoding);\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " #createWriter() {\n" \ + " switch (this.#fd) {\n" \ + " case 1: {\n" \ + " var writer = Bun.stdout.writer({ highWaterMark: 0 });\n" \ + " writer.unref();\n" \ + " return writer;\n" \ + " }\n" \ + "\n" \ + " case 2: {\n" \ + " var writer = Bun.stderr.writer({ highWaterMark: 0 });\n" \ + " writer.unref();\n" \ + " return writer;\n" \ + " }\n" \ + " default: {\n" \ + " throw new Error(\"Unsupported writer\");\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " #getWriter() {\n" \ + " return (this.#writer ??= this.#createWriter());\n" \ + " }\n" \ + "\n" \ + " constructor(fd_) {\n" \ + " super();\n" \ + " this.#fd = fd_;\n" \ + " }\n" \ + "\n" \ + " get fd() {\n" \ + " return this.#fd;\n" \ + " }\n" \ + "\n" \ + " get isTTY() {\n" \ + " return (this.#isTTY ??= require(\"node:tty\").isatty(this.#fd));\n" \ + " }\n" \ + "\n" \ + " on(event, listener) {\n" \ + " if (event === \"close\" || event === \"finish\") {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream.on(event, listener);\n" \ + " }\n" \ + "\n" \ + " if (event === \"drain\") {\n" \ + " return super.on(\"drain\", listener);\n" \ + " }\n" \ + "\n" \ + " if (event === \"error\") {\n" \ + " return super.on(\"error\", listener);\n" \ + " }\n" \ + "\n" \ + " return super.on(event, listener);\n" \ + " }\n" \ + "\n" \ + " get _writableState() {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream._writableState;\n" \ + " }\n" \ + "\n" \ + " get _readableState() {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream._readableState;\n" \ + " }\n" \ + "\n" \ + " pipe(destination) {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream.pipe(destination);\n" \ + " }\n" \ + "\n" \ + " unpipe(destination) {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream.unpipe(destination);\n" \ + " }\n" \ + "\n" \ + " #ensureInnerStream() {\n" \ + " if (this.#innerStream) return;\n" \ + " this.#innerStream = createStdioWriteStream(this.#fd);\n" \ + " const events = this.eventNames();\n" \ + " for (const event of events) {\n" \ + " this.#innerStream.on(event, (...args) => {\n" \ + " this.emit(event, ...args);\n" \ + " });\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " #write1(chunk) {\n" \ + " var writer = this.#getWriter();\n" \ + " const writeResult = writer.write(chunk);\n" \ + " this.bytesWritten += writeResult;\n" \ + " const flushResult = writer.flush();\n" \ + " return !!(writeResult || flushResult);\n" \ + " }\n" \ + "\n" \ + " #writeWithEncoding(chunk, encoding) {\n" \ + " if (!isFastEncoding(encoding)) {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream.write(chunk, encoding);\n" \ + " }\n" \ + "\n" \ + " return this.#write1(chunk);\n" \ + " }\n" \ + "\n" \ + " #performCallback(cb, err) {\n" \ + " if (err) {\n" \ + " this.emit(\"error\", err);\n" \ + " }\n" \ + "\n" \ + " try {\n" \ + " cb(err ? err : null);\n" \ + " } catch (err2) {\n" \ + " this.emit(\"error\", err2);\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " #writeWithCallbackAndEncoding(chunk, encoding, callback) {\n" \ + " if (!isFastEncoding(encoding)) {\n" \ + " this.#ensureInnerStream();\n" \ + " return this.#innerStream.write(chunk, encoding, callback);\n" \ + " }\n" \ + "\n" \ + " var writer = this.#getWriter();\n" \ + " const writeResult = writer.write(chunk);\n" \ + " const flushResult = writer.flush(true);\n" \ + " if (flushResult?.then) {\n" \ + " flushResult.then(\n" \ + " () => {\n" \ + " this.#performCallback(callback);\n" \ + " this.emit(\"drain\");\n" \ + " },\n" \ + " (err) => this.#performCallback(callback, err),\n" \ + " );\n" \ + " return false;\n" \ + " }\n" \ + "\n" \ + " queueMicrotask(() => {\n" \ + " this.#performCallback(callback);\n" \ + " });\n" \ + "\n" \ + " return !!(writeResult || flushResult);\n" \ + " }\n" \ + "\n" \ + " write(chunk, encoding, callback) {\n" \ + " const result = this._write(chunk, encoding, callback);\n" \ + "\n" \ + " if (result) {\n" \ + " this.emit(\"drain\");\n" \ + " }\n" \ + "\n" \ + " return result;\n" \ + " }\n" \ + "\n" \ + " get hasColors() {\n" \ + " return Bun.tty[this.#fd].hasColors;\n" \ + " }\n" \ + "\n" \ + " _write(chunk, encoding, callback) {\n" \ + " var inner = this.#innerStream;\n" \ + " if (inner) {\n" \ + " return inner.write(chunk, encoding, callback);\n" \ + " }\n" \ + "\n" \ + " switch (arguments.length) {\n" \ + " case 0: {\n" \ + " var error = new Error(\"Invalid arguments\");\n" \ + " error.code = \"ERR_INVALID_ARG_TYPE\";\n" \ + " throw error;\n" \ + " }\n" \ + " case 1: {\n" \ + " return this.#write1(chunk);\n" \ + " }\n" \ + " case 2: {\n" \ + " if (typeof encoding === \"function\") {\n" \ + " return this.#writeWithCallbackAndEncoding(chunk, \"\", encoding);\n" \ + " } else if (typeof encoding === \"string\") {\n" \ + " return this.#writeWithEncoding(chunk, encoding);\n" \ + " }\n" \ + " }\n" \ + " default: {\n" \ + " if (\n" \ + " (typeof encoding !== \"undefined\" && typeof encoding !== \"string\") ||\n" \ + " (typeof callback !== \"undefined\" && typeof callback !== \"function\")\n" \ + " ) {\n" \ + " var error = new Error(\"Invalid arguments\");\n" \ + " error.code = \"ERR_INVALID_ARG_TYPE\";\n" \ + " throw error;\n" \ + " }\n" \ + "\n" \ + " if (typeof callback === \"undefined\") {\n" \ + " return this.#writeWithEncoding(chunk, encoding);\n" \ + " }\n" \ + "\n" \ + " return this.#writeWithCallbackAndEncoding(chunk, encoding, callback);\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " destroy() {\n" \ + " return this;\n" \ + " }\n" \ + "\n" \ + " end() {\n" \ + " return this;\n" \ + " }\n" \ + " };\n" \ + "\n" \ + " return new FastStdioWriteStream(fd_);\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_processObjectInternalsGetStdinStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_processObjectInternalsGetStdinStreamCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_processObjectInternalsGetStdinStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_processObjectInternalsGetStdinStreamCodeLength = 3915; +static const JSC::Intrinsic s_processObjectInternalsGetStdinStreamCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_processObjectInternalsGetStdinStreamCode = + "(function (fd, rawRequire, Bun) {\n" \ + " var module = { path: \"node:process\", require: rawRequire };\n" \ + " var require = (path) => module.require(path);\n" \ + "\n" \ + " var { Readable, Duplex, eos, destroy } = require(\"node:stream\");\n" \ + "\n" \ + " var StdinStream = class StdinStream extends Duplex {\n" \ + " #readStream;\n" \ + " #writeStream;\n" \ + "\n" \ + " #readable = true;\n" \ + " #writable = true;\n" \ + "\n" \ + " #onFinish;\n" \ + " #onClose;\n" \ + " #onDrain;\n" \ + " #onReadable;\n" \ + "\n" \ + " get isTTY() {\n" \ + " return require(\"tty\").isatty(fd);\n" \ + " }\n" \ + "\n" \ + " get fd() {\n" \ + " return fd_;\n" \ + " }\n" \ + "\n" \ + " constructor() {\n" \ + " super({ readable: true, writable: true });\n" \ + "\n" \ + " this.#onReadable = this._read.bind(this);\n" \ + " }\n" \ + "\n" \ + " #onFinished(err) {\n" \ + " const cb = this.#onClose;\n" \ + " this.#onClose = null;\n" \ + "\n" \ + " if (cb) {\n" \ + " cb(err);\n" \ + " } else if (err) {\n" \ + " this.destroy(err);\n" \ + " } else if (!this.#readable && !this.#writable) {\n" \ + " this.destroy();\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " _destroy(err, callback) {\n" \ + " if (!err && this.#onClose !== null) {\n" \ + " var AbortError = class AbortError extends Error {\n" \ + " constructor(message = \"The operation was aborted\", options = void 0) {\n" \ + " if (options !== void 0 && typeof options !== \"object\") {\n" \ + " throw new Error(\n" \ + " `Invalid AbortError options:\\n" \ + "\\n" \ + "${JSON.stringify(\n" \ + " options,\n" \ + " null,\n" \ + " 2,\n" \ + " )}`,\n" \ + " );\n" \ + " }\n" \ + " super(message, options);\n" \ + " this.code = \"ABORT_ERR\";\n" \ + " this.name = \"AbortError\";\n" \ + " }\n" \ + " };\n" \ + " err = new AbortError();\n" \ + " }\n" \ + "\n" \ + " if (this.#onClose === null) {\n" \ + " callback(err);\n" \ + " } else {\n" \ + " this.#onClose = callback;\n" \ + " if (this.#readStream) destroy(this.#readStream, err);\n" \ + " if (this.#writeStream) destroy(this.#writeStream, err);\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " on(ev, cb) {\n" \ + " super.on(ev, cb);\n" \ + " if (!this.#readStream && (ev === \"readable\" || ev === \"data\")) {\n" \ + " this.#loadReadStream();\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " #loadReadStream() {\n" \ + " var readStream = (this.#readStream = Readable.fromWeb(\n" \ + " Bun.stdin.stream(),\n" \ + " ));\n" \ + "\n" \ + " readStream.on(\"readable\", () => {\n" \ + " const cb = this.#onReadable;\n" \ + " this.#onReadable = null;\n" \ + " cb();\n" \ + " });\n" \ + "\n" \ + " readStream.on(\"end\", () => {\n" \ + " this.push(null);\n" \ + " });\n" \ + "\n" \ + " eos(readStream, (err) => {\n" \ + " this.#readable = false;\n" \ + " if (err) {\n" \ + " destroy(readStream, err);\n" \ + " }\n" \ + " this.#onFinished(err);\n" \ + " });\n" \ + " }\n" \ + "\n" \ + " _read() {\n" \ + " var readStream = this.#readStream;\n" \ + " while (true) {\n" \ + " const buf = readStream.read();\n" \ + " if (buf === null || !this.push(buf)) {\n" \ + " this.#onReadable = this._read.bind(this);\n" \ + " return;\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " #constructWriteStream() {\n" \ + " var { createWriteStream } = require(\"node:fs\");\n" \ + " var writeStream = (this.#writeStream = createWriteStream(\"/dev/fd/0\"));\n" \ + "\n" \ + " writeStream.on(\"finish\", () => {\n" \ + " if (this.#onFinish) {\n" \ + " const cb = this.#onFinish;\n" \ + " this.#onFinish = null;\n" \ + " cb();\n" \ + " }\n" \ + " });\n" \ + "\n" \ + " writeStream.on(\"drain\", () => {\n" \ + " if (this.#onDrain) {\n" \ + " const cb = this.#onDrain;\n" \ + " this.#onDrain = null;\n" \ + " cb();\n" \ + " }\n" \ + " });\n" \ + "\n" \ + " eos(writeStream, (err) => {\n" \ + " this.#writable = false;\n" \ + " if (err) {\n" \ + " destroy(writeStream, err);\n" \ + " }\n" \ + " this.#onFinished(err);\n" \ + " });\n" \ + "\n" \ + " return writeStream;\n" \ + " }\n" \ + "\n" \ + " _write(chunk, encoding, callback) {\n" \ + " var writeStream = this.#writeStream;\n" \ + " if (!writeStream) {\n" \ + " writeStream = this.#constructWriteStream();\n" \ + " }\n" \ + "\n" \ + " if (writeStream.write(chunk, encoding)) {\n" \ + " callback();\n" \ + " } else {\n" \ + " this.#onDrain = callback;\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " _final(callback) {\n" \ + " this.#writeStream.end();\n" \ + " this.#onFinish = callback.bind(this);\n" \ + " }\n" \ + " };\n" \ + "\n" \ + " return new StdinStream();\n" \ + "})\n" \ +; + + +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ +{\ + JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ + return clientData->builtinFunctions().processObjectInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().processObjectInternalsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \ +} +WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR + + +} // namespace WebCore diff --git a/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.h b/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.h new file mode 100644 index 000000000..cce9c1564 --- /dev/null +++ b/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2015 Igalia + * Copyright (c) 2015 Igalia S.L. + * Copyright (c) 2015 Igalia. + * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. + * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. + * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. + * Copyright (c) 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#pragma once + +#include <JavaScriptCore/BuiltinUtils.h> +#include <JavaScriptCore/Identifier.h> +#include <JavaScriptCore/JSFunction.h> +#include <JavaScriptCore/UnlinkedFunctionExecutable.h> + +namespace JSC { +class FunctionExecutable; +} + +namespace WebCore { + +/* ProcessObjectInternals */ +extern const char* const s_processObjectInternalsGetStdioWriteStreamCode; +extern const int s_processObjectInternalsGetStdioWriteStreamCodeLength; +extern const JSC::ConstructAbility s_processObjectInternalsGetStdioWriteStreamCodeConstructAbility; +extern const JSC::ConstructorKind s_processObjectInternalsGetStdioWriteStreamCodeConstructorKind; +extern const JSC::ImplementationVisibility s_processObjectInternalsGetStdioWriteStreamCodeImplementationVisibility; +extern const char* const s_processObjectInternalsGetStdinStreamCode; +extern const int s_processObjectInternalsGetStdinStreamCodeLength; +extern const JSC::ConstructAbility s_processObjectInternalsGetStdinStreamCodeConstructAbility; +extern const JSC::ConstructorKind s_processObjectInternalsGetStdinStreamCodeConstructorKind; +extern const JSC::ImplementationVisibility s_processObjectInternalsGetStdinStreamCodeImplementationVisibility; + +#define WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_DATA(macro) \ + macro(getStdioWriteStream, processObjectInternalsGetStdioWriteStream, 2) \ + macro(getStdinStream, processObjectInternalsGetStdinStream, 3) \ + +#define WEBCORE_BUILTIN_PROCESSOBJECTINTERNALS_GETSTDIOWRITESTREAM 1 +#define WEBCORE_BUILTIN_PROCESSOBJECTINTERNALS_GETSTDINSTREAM 1 + +#define WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(macro) \ + macro(processObjectInternalsGetStdioWriteStreamCode, getStdioWriteStream, ASCIILiteral(), s_processObjectInternalsGetStdioWriteStreamCodeLength) \ + macro(processObjectInternalsGetStdinStreamCode, getStdinStream, ASCIILiteral(), s_processObjectInternalsGetStdinStreamCodeLength) \ + +#define WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(macro) \ + macro(getStdinStream) \ + macro(getStdioWriteStream) \ + +#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ + JSC::FunctionExecutable* codeName##Generator(JSC::VM&); + +WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) +#undef DECLARE_BUILTIN_GENERATOR + +class ProcessObjectInternalsBuiltinsWrapper : private JSC::WeakHandleOwner { +public: + explicit ProcessObjectInternalsBuiltinsWrapper(JSC::VM& vm) + : m_vm(vm) + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) +#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { })) + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) +#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS + { + } + +#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ + JSC::UnlinkedFunctionExecutable* name##Executable(); \ + const JSC::SourceCode& name##Source() const { return m_##name##Source; } + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) +#undef EXPOSE_BUILTIN_EXECUTABLES + + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) + + void exportNames(); + +private: + JSC::VM& m_vm; + + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) + +#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \ + JSC::SourceCode m_##name##Source;\ + JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable; + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) +#undef DECLARE_BUILTIN_SOURCE_MEMBERS + +}; + +#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ +inline JSC::UnlinkedFunctionExecutable* ProcessObjectInternalsBuiltinsWrapper::name##Executable() \ +{\ + if (!m_##name##Executable) {\ + JSC::Identifier executableName = functionName##PublicName();\ + if (overriddenName)\ + executableName = JSC::Identifier::fromString(m_vm, overriddenName);\ + m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ImplementationVisibility, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\ + }\ + return m_##name##Executable.get();\ +} +WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) +#undef DEFINE_BUILTIN_EXECUTABLES + +inline void ProcessObjectInternalsBuiltinsWrapper::exportNames() +{ +#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) +#undef EXPORT_FUNCTION_NAME +} + +class ProcessObjectInternalsBuiltinFunctions { +public: + explicit ProcessObjectInternalsBuiltinFunctions(JSC::VM& vm) : m_vm(vm) { } + + void init(JSC::JSGlobalObject&); + template<typename Visitor> void visit(Visitor&); + +public: + JSC::VM& m_vm; + +#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \ + JSC::WriteBarrier<JSC::JSFunction> m_##functionName##Function; + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS) +#undef DECLARE_BUILTIN_SOURCE_MEMBERS +}; + +inline void ProcessObjectInternalsBuiltinFunctions::init(JSC::JSGlobalObject& globalObject) +{ +#define EXPORT_FUNCTION(codeName, functionName, overriddenName, length)\ + m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject)); + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(EXPORT_FUNCTION) +#undef EXPORT_FUNCTION +} + +template<typename Visitor> +inline void ProcessObjectInternalsBuiltinFunctions::visit(Visitor& visitor) +{ +#define VISIT_FUNCTION(name) visitor.append(m_##name##Function); + WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION) +#undef VISIT_FUNCTION +} + +template void ProcessObjectInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&); +template void ProcessObjectInternalsBuiltinFunctions::visit(JSC::SlotVisitor&); + + + +} // namespace WebCore diff --git a/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h b/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h index e843b7136..ef76cb146 100644 --- a/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h +++ b/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h @@ -40,6 +40,7 @@ namespace Zig { class GlobalObject; } #pragma once +#include "ProcessObjectInternalsBuiltins.h" #include "ReadableByteStreamInternalsBuiltins.h" #include "ReadableStreamInternalsBuiltins.h" #include "StreamInternalsBuiltins.h" @@ -59,6 +60,7 @@ public: template<typename Visitor> void visit(Visitor&); void initialize(JSDOMGlobalObject&); + ProcessObjectInternalsBuiltinFunctions& processObjectInternals() { return m_processObjectInternals; } ReadableByteStreamInternalsBuiltinFunctions& readableByteStreamInternals() { return m_readableByteStreamInternals; } ReadableStreamInternalsBuiltinFunctions& readableStreamInternals() { return m_readableStreamInternals; } StreamInternalsBuiltinFunctions& streamInternals() { return m_streamInternals; } @@ -67,6 +69,7 @@ public: private: JSC::VM& m_vm; + ProcessObjectInternalsBuiltinFunctions m_processObjectInternals; ReadableByteStreamInternalsBuiltinFunctions m_readableByteStreamInternals; ReadableStreamInternalsBuiltinFunctions m_readableStreamInternals; StreamInternalsBuiltinFunctions m_streamInternals; diff --git a/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h b/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h index 714be8e4f..22aa58ced 100644 --- a/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h +++ b/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h @@ -42,7 +42,7 @@ #include "JSBufferConstructorBuiltins.h" #include "JSBufferPrototypeBuiltins.h" #include "OnigurumaRegExpPrototypeBuiltins.h" -#include "ProcessObjectBuiltins.h" +#include "ProcessObjectInternalsBuiltins.h" #include "ReadableByteStreamControllerBuiltins.h" #include "ReadableByteStreamInternalsBuiltins.h" #include "ReadableStreamBYOBReaderBuiltins.h" @@ -72,7 +72,7 @@ public: , m_jsBufferConstructorBuiltins(m_vm) , m_jsBufferPrototypeBuiltins(m_vm) , m_onigurumaRegExpPrototypeBuiltins(m_vm) - , m_processObjectBuiltins(m_vm) + , m_processObjectInternalsBuiltins(m_vm) , m_readableByteStreamControllerBuiltins(m_vm) , m_readableByteStreamInternalsBuiltins(m_vm) , m_readableStreamBuiltins(m_vm) @@ -89,6 +89,7 @@ public: , m_writableStreamDefaultWriterBuiltins(m_vm) , m_writableStreamInternalsBuiltins(m_vm) { + m_processObjectInternalsBuiltins.exportNames(); m_readableByteStreamInternalsBuiltins.exportNames(); m_readableStreamInternalsBuiltins.exportNames(); m_streamInternalsBuiltins.exportNames(); @@ -102,7 +103,7 @@ public: JSBufferConstructorBuiltinsWrapper& jsBufferConstructorBuiltins() { return m_jsBufferConstructorBuiltins; } JSBufferPrototypeBuiltinsWrapper& jsBufferPrototypeBuiltins() { return m_jsBufferPrototypeBuiltins; } OnigurumaRegExpPrototypeBuiltinsWrapper& onigurumaRegExpPrototypeBuiltins() { return m_onigurumaRegExpPrototypeBuiltins; } - ProcessObjectBuiltinsWrapper& processObjectBuiltins() { return m_processObjectBuiltins; } + ProcessObjectInternalsBuiltinsWrapper& processObjectInternalsBuiltins() { return m_processObjectInternalsBuiltins; } ReadableByteStreamControllerBuiltinsWrapper& readableByteStreamControllerBuiltins() { return m_readableByteStreamControllerBuiltins; } ReadableByteStreamInternalsBuiltinsWrapper& readableByteStreamInternalsBuiltins() { return m_readableByteStreamInternalsBuiltins; } ReadableStreamBuiltinsWrapper& readableStreamBuiltins() { return m_readableStreamBuiltins; } @@ -127,7 +128,7 @@ private: JSBufferConstructorBuiltinsWrapper m_jsBufferConstructorBuiltins; JSBufferPrototypeBuiltinsWrapper m_jsBufferPrototypeBuiltins; OnigurumaRegExpPrototypeBuiltinsWrapper m_onigurumaRegExpPrototypeBuiltins; - ProcessObjectBuiltinsWrapper m_processObjectBuiltins; + ProcessObjectInternalsBuiltinsWrapper m_processObjectInternalsBuiltins; ReadableByteStreamControllerBuiltinsWrapper m_readableByteStreamControllerBuiltins; ReadableByteStreamInternalsBuiltinsWrapper m_readableByteStreamInternalsBuiltins; ReadableStreamBuiltinsWrapper m_readableStreamBuiltins; diff --git a/src/bun.js/builtins/js/ProcessObject.js b/src/bun.js/builtins/js/ProcessObject.js deleted file mode 100644 index beaa4aa7a..000000000 --- a/src/bun.js/builtins/js/ProcessObject.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2022 Codeblog Corp. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ diff --git a/src/bun.js/builtins/js/ProcessObjectInternals.js b/src/bun.js/builtins/js/ProcessObjectInternals.js new file mode 100644 index 000000000..580152678 --- /dev/null +++ b/src/bun.js/builtins/js/ProcessObjectInternals.js @@ -0,0 +1,600 @@ +/* + * Copyright 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// @internal + +function getStdioWriteStream(fd_, rawRequire) { + var module = { path: "node:process", require: rawRequire }; + var require = (path) => module.require(path); + + function createStdioWriteStream(fd_) { + var { Duplex, eos, destroy } = require("node:stream"); + var StdioWriteStream = class StdioWriteStream extends Duplex { + #writeStream; + #readStream; + + #readable = true; + #writable = true; + #fdPath; + + #onClose; + #onDrain; + #onFinish; + #onReadable; + #isTTY; + + get isTTY() { + return (this.#isTTY ??= require("node:tty").isatty(fd_)); + } + + get fd() { + return fd_; + } + + constructor(fd) { + super({ readable: true, writable: true }); + this.#fdPath = `/dev/fd/${fd}`; + } + + #onFinished(err) { + const cb = this.#onClose; + this.#onClose = null; + + if (cb) { + cb(err); + } else if (err) { + this.destroy(err); + } else if (!this.#readable && !this.#writable) { + this.destroy(); + } + } + + _destroy(err, callback) { + if (!err && this.#onClose !== null) { + var AbortError = class AbortError extends Error { + constructor( + message = "The operation was aborted", + options = void 0, + ) { + if (options !== void 0 && typeof options !== "object") { + throw new Error( + `Invalid AbortError options:\n\n${JSON.stringify( + options, + null, + 2, + )}`, + ); + } + super(message, options); + this.code = "ABORT_ERR"; + this.name = "AbortError"; + } + }; + err = new AbortError(); + } + + this.#onDrain = null; + this.#onFinish = null; + if (this.#onClose === null) { + callback(err); + } else { + this.#onClose = callback; + if (this.#writeStream) destroy(this.#writeStream, err); + if (this.#readStream) destroy(this.#readStream, err); + } + } + + _write(chunk, encoding, callback) { + if (!this.#writeStream) { + var { createWriteStream } = require("node:fs"); + var stream = (this.#writeStream = createWriteStream(this.#fdPath)); + + stream.on("finish", () => { + if (this.#onFinish) { + const cb = this.#onFinish; + this.#onFinish = null; + cb(); + } + }); + + stream.on("drain", () => { + if (this.#onDrain) { + const cb = this.#onDrain; + this.#onDrain = null; + cb(); + } + }); + + eos(stream, (err) => { + this.#writable = false; + if (err) { + destroy(stream, err); + } + this.#onFinished(err); + }); + } + if (stream.write(chunk, encoding)) { + callback(); + } else { + this.#onDrain = callback; + } + } + + _final(callback) { + this.#writeStream && this.#writeStream.end(); + this.#onFinish = callback; + } + + #loadReadStream() { + var { createReadStream } = require("node:fs"); + + var readStream = (this.#readStream = createReadStream(this.#fdPath)); + + readStream.on("readable", () => { + if (this.#onReadable) { + const cb = this.#onReadable; + this.#onReadable = null; + cb(); + } else { + this.read(); + } + }); + + readStream.on("end", () => { + this.push(null); + }); + + eos(readStream, (err) => { + this.#readable = false; + if (err) { + destroy(readStream, err); + } + this.#onFinished(err); + }); + return readStream; + } + + _read() { + var stream = this.#readStream; + if (!stream) { + stream = this.#loadReadStream(); + } + + while (true) { + const buf = stream.read(); + if (buf === null || !this.push(buf)) { + return; + } + } + } + }; + return new StdioWriteStream(fd_); + } + + var { EventEmitter } = require("node:events"); + + function isFastEncoding(encoding) { + if (!encoding) return true; + + var normalied = encoding.toLowerCase(); + return ( + normalied === "utf8" || + normalied === "utf-8" || + normalied === "buffer" || + normalied === "binary" || + normalized === "" + ); + } + var FastStdioWriteStream = class StdioWriteStream extends EventEmitter { + #fd; + #innerStream; + #writer; + #isTTY; + + bytesWritten = 0; + + setDefaultEncoding(encoding) { + if (this.#innerStream || !isFastEncoding(encoding)) { + this.#ensureInnerStream(); + return this.#innerStream.setDefaultEncoding(encoding); + } + } + + #createWriter() { + switch (this.#fd) { + case 1: { + var writer = Bun.stdout.writer({ highWaterMark: 0 }); + writer.unref(); + return writer; + } + + case 2: { + var writer = Bun.stderr.writer({ highWaterMark: 0 }); + writer.unref(); + return writer; + } + default: { + throw new Error("Unsupported writer"); + } + } + } + + #getWriter() { + return (this.#writer ??= this.#createWriter()); + } + + constructor(fd_) { + super(); + this.#fd = fd_; + } + + get fd() { + return this.#fd; + } + + get isTTY() { + return (this.#isTTY ??= require("node:tty").isatty(this.#fd)); + } + + on(event, listener) { + if (event === "close" || event === "finish") { + this.#ensureInnerStream(); + return this.#innerStream.on(event, listener); + } + + if (event === "drain") { + return super.on("drain", listener); + } + + if (event === "error") { + return super.on("error", listener); + } + + return super.on(event, listener); + } + + get _writableState() { + this.#ensureInnerStream(); + return this.#innerStream._writableState; + } + + get _readableState() { + this.#ensureInnerStream(); + return this.#innerStream._readableState; + } + + pipe(destination) { + this.#ensureInnerStream(); + return this.#innerStream.pipe(destination); + } + + unpipe(destination) { + this.#ensureInnerStream(); + return this.#innerStream.unpipe(destination); + } + + #ensureInnerStream() { + if (this.#innerStream) return; + this.#innerStream = createStdioWriteStream(this.#fd); + const events = this.eventNames(); + for (const event of events) { + this.#innerStream.on(event, (...args) => { + this.emit(event, ...args); + }); + } + } + + #write1(chunk) { + var writer = this.#getWriter(); + const writeResult = writer.write(chunk); + this.bytesWritten += writeResult; + const flushResult = writer.flush(); + return !!(writeResult || flushResult); + } + + #writeWithEncoding(chunk, encoding) { + if (!isFastEncoding(encoding)) { + this.#ensureInnerStream(); + return this.#innerStream.write(chunk, encoding); + } + + return this.#write1(chunk); + } + + #performCallback(cb, err) { + if (err) { + this.emit("error", err); + } + + try { + cb(err ? err : null); + } catch (err2) { + this.emit("error", err2); + } + } + + #writeWithCallbackAndEncoding(chunk, encoding, callback) { + if (!isFastEncoding(encoding)) { + this.#ensureInnerStream(); + return this.#innerStream.write(chunk, encoding, callback); + } + + var writer = this.#getWriter(); + const writeResult = writer.write(chunk); + const flushResult = writer.flush(true); + if (flushResult?.then) { + flushResult.then( + () => { + this.#performCallback(callback); + this.emit("drain"); + }, + (err) => this.#performCallback(callback, err), + ); + return false; + } + + queueMicrotask(() => { + this.#performCallback(callback); + }); + + return !!(writeResult || flushResult); + } + + write(chunk, encoding, callback) { + const result = this._write(chunk, encoding, callback); + + if (result) { + this.emit("drain"); + } + + return result; + } + + get hasColors() { + return Bun.tty[this.#fd].hasColors; + } + + _write(chunk, encoding, callback) { + var inner = this.#innerStream; + if (inner) { + return inner.write(chunk, encoding, callback); + } + + switch (arguments.length) { + case 0: { + var error = new Error("Invalid arguments"); + error.code = "ERR_INVALID_ARG_TYPE"; + throw error; + } + case 1: { + return this.#write1(chunk); + } + case 2: { + if (typeof encoding === "function") { + return this.#writeWithCallbackAndEncoding(chunk, "", encoding); + } else if (typeof encoding === "string") { + return this.#writeWithEncoding(chunk, encoding); + } + } + default: { + if ( + (typeof encoding !== "undefined" && typeof encoding !== "string") || + (typeof callback !== "undefined" && typeof callback !== "function") + ) { + var error = new Error("Invalid arguments"); + error.code = "ERR_INVALID_ARG_TYPE"; + throw error; + } + + if (typeof callback === "undefined") { + return this.#writeWithEncoding(chunk, encoding); + } + + return this.#writeWithCallbackAndEncoding(chunk, encoding, callback); + } + } + } + + destroy() { + return this; + } + + end() { + return this; + } + }; + + return new FastStdioWriteStream(fd_); +} + +function getStdinStream(fd, rawRequire, Bun) { + var module = { path: "node:process", require: rawRequire }; + var require = (path) => module.require(path); + + var { Readable, Duplex, eos, destroy } = require("node:stream"); + + var StdinStream = class StdinStream extends Duplex { + #readStream; + #writeStream; + + #readable = true; + #writable = true; + + #onFinish; + #onClose; + #onDrain; + #onReadable; + + get isTTY() { + return require("tty").isatty(fd); + } + + get fd() { + return fd_; + } + + constructor() { + super({ readable: true, writable: true }); + + this.#onReadable = this._read.bind(this); + } + + #onFinished(err) { + const cb = this.#onClose; + this.#onClose = null; + + if (cb) { + cb(err); + } else if (err) { + this.destroy(err); + } else if (!this.#readable && !this.#writable) { + this.destroy(); + } + } + + _destroy(err, callback) { + if (!err && this.#onClose !== null) { + var AbortError = class AbortError extends Error { + constructor(message = "The operation was aborted", options = void 0) { + if (options !== void 0 && typeof options !== "object") { + throw new Error( + `Invalid AbortError options:\n\n${JSON.stringify( + options, + null, + 2, + )}`, + ); + } + super(message, options); + this.code = "ABORT_ERR"; + this.name = "AbortError"; + } + }; + err = new AbortError(); + } + + if (this.#onClose === null) { + callback(err); + } else { + this.#onClose = callback; + if (this.#readStream) destroy(this.#readStream, err); + if (this.#writeStream) destroy(this.#writeStream, err); + } + } + + on(ev, cb) { + super.on(ev, cb); + if (!this.#readStream && (ev === "readable" || ev === "data")) { + this.#loadReadStream(); + } + } + + #loadReadStream() { + var readStream = (this.#readStream = Readable.fromWeb( + Bun.stdin.stream(), + )); + + readStream.on("readable", () => { + const cb = this.#onReadable; + this.#onReadable = null; + cb(); + }); + + readStream.on("end", () => { + this.push(null); + }); + + eos(readStream, (err) => { + this.#readable = false; + if (err) { + destroy(readStream, err); + } + this.#onFinished(err); + }); + } + + _read() { + var readStream = this.#readStream; + while (true) { + const buf = readStream.read(); + if (buf === null || !this.push(buf)) { + this.#onReadable = this._read.bind(this); + return; + } + } + } + + #constructWriteStream() { + var { createWriteStream } = require("node:fs"); + var writeStream = (this.#writeStream = createWriteStream("/dev/fd/0")); + + writeStream.on("finish", () => { + if (this.#onFinish) { + const cb = this.#onFinish; + this.#onFinish = null; + cb(); + } + }); + + writeStream.on("drain", () => { + if (this.#onDrain) { + const cb = this.#onDrain; + this.#onDrain = null; + cb(); + } + }); + + eos(writeStream, (err) => { + this.#writable = false; + if (err) { + destroy(writeStream, err); + } + this.#onFinished(err); + }); + + return writeStream; + } + + _write(chunk, encoding, callback) { + var writeStream = this.#writeStream; + if (!writeStream) { + writeStream = this.#constructWriteStream(); + } + + if (writeStream.write(chunk, encoding)) { + callback(); + } else { + this.#onDrain = callback; + } + } + + _final(callback) { + this.#writeStream.end(); + this.#onFinish = callback.bind(this); + } + }; + + return new StdinStream(); +} diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 6f7f18f0a..b770fe3e4 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -467,6 +467,15 @@ pub const EventLoop = struct { } } + pub fn autoTickActive(this: *EventLoop) void { + var loop = this.virtual_machine.uws_event_loop.?; + if (loop.active > 0) { + loop.tick(); + this.processGCTimer(); + // this.afterUSocketsTick(); + } + } + pub fn processGCTimer(this: *EventLoop) void { this.virtual_machine.gc_controller.processGCTimer(); } diff --git a/src/bun.js/process-stdio-polyfill.js b/src/bun.js/process-stdio-polyfill.js index b19a8076f..e69de29bb 100644 --- a/src/bun.js/process-stdio-polyfill.js +++ b/src/bun.js/process-stdio-polyfill.js @@ -1,342 +0,0 @@ -var createReadStream; -var createWriteStream; - -var StdioWriteStream; -var StdinStream; - -var AbortError = class extends Error { - constructor(message = "The operation was aborted", options = void 0) { - if (options !== void 0 && typeof options !== "object") { - throw new Error( - `Invalid AbortError options:\n\n${JSON.stringify(options, null, 2)}`, - ); - } - super(message, options); - this.code = "ABORT_ERR"; - this.name = "AbortError"; - } -}; - -function lazyLoadDeps({ require }) { - var { - createWriteStream: _createWriteStream, - createReadStream: _createReadStream, - } = require("node:fs", "node:process"); - createWriteStream = _createWriteStream; - createReadStream = _createReadStream; -} - -function getStdioWriteStream({ require }) { - if (!StdioWriteStream) { - var { Duplex, eos, destroy } = require("node:stream", "node:process"); - if (!createWriteStream) { - lazyLoadDeps({ require }); - } - - StdioWriteStream = class StdioWriteStream extends Duplex { - #writeStream; - #readStream; - - #readable = true; - #writable = true; - #fdPath; - - #onClose; - #onDrain; - #onFinish; - #onReadable; - - fd = 1; - get isTTY() { - return require("tty").isatty(this.fd); - } - - constructor(fd) { - super({ readable: true, writable: true }); - this.#fdPath = `/dev/fd/${fd}`; - - Object.defineProperty(this, "fd", { - value: fd, - writable: false, - configurable: false, - }); - } - - #onFinished(err) { - const cb = this.#onClose; - this.#onClose = null; - - if (cb) { - cb(err); - } else if (err) { - this.destroy(err); - } else if (!this.#readable && !this.#writable) { - this.destroy(); - } - } - - _destroy(err, callback) { - if (!err && this.#onClose !== null) { - err = new AbortError(); - } - this.#onDrain = null; - this.#onFinish = null; - if (this.#onClose === null) { - callback(err); - } else { - this.#onClose = callback; - if (this.#writeStream) destroy(this.#writeStream, err); - if (this.#readStream) destroy(this.#readStream, err); - } - } - - _write(chunk, encoding, callback) { - if (!this.#writeStream) { - this.#writeStream = createWriteStream(this.#fdPath); - - this.#writeStream.on("finish", () => { - if (this.#onFinish) { - const cb = this.#onFinish; - this.#onFinish = null; - cb(); - } - }); - - this.#writeStream.on("drain", () => { - if (this.#onDrain) { - const cb = this.#onDrain; - this.#onDrain = null; - cb(); - } - }); - - eos(this.#writeStream, (err) => { - this.#writable = false; - if (err) { - destroy(this.#writeStream, err); - } - this.#onFinished(err); - }); - } - if (this.#writeStream.write(chunk, encoding)) { - callback(); - } else { - this.#onDrain = callback; - } - } - - _final(callback) { - this.#writeStream.end(); - this.#onFinish = callback; - } - - _read() { - if (!this.#readStream) { - this.#readStream = createReadStream(this.#fdPath); - - this.#readStream.on("readable", () => { - if (this.#onReadable) { - const cb = this.#onReadable; - this.#onReadable = null; - cb(); - } else { - this.read(); - } - }); - - this.#readStream.on("end", () => { - this.push(null); - }); - - eos(this.#readStream, (err) => { - this.#readable = false; - if (err) { - destroy(this.#readStream, err); - } - this.#onFinished(err); - }); - } - while (true) { - const buf = this.#readStream.read(); - if (buf === null || !this.push(buf)) { - return; - } - } - } - }; - } - return StdioWriteStream; -} - -function getStdinStream({ require }) { - if (!StdinStream) { - var { - Readable, - Duplex, - eos, - destroy, - } = require("node:stream", "node:process"); - if (!createWriteStream) { - lazyLoadDeps({ require }); - } - - StdinStream = class StdinStream extends Duplex { - #readStream; - #writeStream; - - #readable = true; - #writable = true; - - #onFinish; - #onClose; - #onDrain; - #onReadable; - - fd = 0; - get isTTY() { - return require("tty").isatty(this.fd); - } - - constructor() { - super({ readable: true, writable: true }); - - Object.defineProperty(this, "fd", { - value: 0, - writable: false, - configurable: false, - }); - - this.#onReadable = this._read.bind(this); - } - - #onFinished(err) { - const cb = this.#onClose; - this.#onClose = null; - - if (cb) { - cb(err); - } else if (err) { - this.destroy(err); - } else if (!this.#readable && !this.#writable) { - this.destroy(); - } - } - - _destroy(err, callback) { - if (!err && this.#onClose !== null) { - err = new AbortError(); - } - if (this.#onClose === null) { - callback(err); - } else { - this.#onClose = callback; - if (this.#readStream) destroy(this.#readStream, err); - if (this.#writeStream) destroy(this.#writeStream, err); - } - } - - on(ev, cb) { - super.on(ev, cb); - if (!this.#readStream && (ev === "readable" || ev === "data")) { - this.#readStream = Readable.fromWeb(Bun.stdin.stream()); - - this.#readStream.on("readable", () => { - const cb = this.#onReadable; - this.#onReadable = null; - cb(); - }); - - this.#readStream.on("end", () => { - this.push(null); - }); - - eos(this.#readStream, (err) => { - this.#readable = false; - if (err) { - destroy(this.#readStream, err); - } - this.#onFinished(err); - }); - } - } - - _read() { - while (true) { - const buf = this.#readStream.read(); - if (buf === null || !this.push(buf)) { - this.#onReadable = this._read.bind(this); - return; - } - } - } - - _write(chunk, encoding, callback) { - if (!this.#writeStream) { - this.#writeStream = createWriteStream("/dev/fd/0"); - - this.#writeStream.on("finish", () => { - if (this.#onFinish) { - const cb = this.#onFinish; - this.#onFinish = null; - cb(); - } - }); - - this.#writeStream.on("drain", () => { - if (this.#onDrain) { - const cb = this.#onDrain; - this.#onDrain = null; - cb(); - } - }); - - eos(this.#writeStream, (err) => { - this.#writable = false; - if (err) { - destroy(this.#writeStream, err); - } - this.#onFinished(err); - }); - } - - if (this.#writeStream.write(chunk, encoding)) { - callback(); - } else { - this.#onDrain = callback; - } - } - - _final(callback) { - this.#writeStream.end(); - this.#onFinish = callback.bind(this); - } - }; - } - return StdinStream; -} - -export function stdin({ require }) { - var StdinStream = getStdinStream({ require }); - var stream = new StdinStream(); - return stream; -} - -export function stdout({ require }) { - var StdioWriteStream = getStdioWriteStream({ require }); - var stream = new StdioWriteStream(1); - return stream; -} - -export function stderr({ require }) { - var StdioWriteStream = getStdioWriteStream({ require }); - var stream = new StdioWriteStream(2); - return stream; -} - -export default { - stdin, - stdout, - stderr, - - [Symbol.for("CommonJS")]: 0, -}; diff --git a/src/bun_js.zig b/src/bun_js.zig index d3d59a662..e9926f800 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -165,7 +165,7 @@ pub const Run = struct { { while (this.vm.eventLoop().tasks.count > 0 or this.vm.active_tasks > 0 or this.vm.uws_event_loop.?.active > 0) { this.vm.tick(); - this.vm.eventLoop().autoTick(); + this.vm.eventLoop().autoTickActive(); } if (this.vm.log.msgs.items.len > 0) { |