diff --git a/src/bun.js/bindings/CommonJSModuleRecord.h b/src/bun.js/bindings/CommonJSModuleRecord.h index d3f0fde00a..f3c6c49023 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.h +++ b/src/bun.js/bindings/CommonJSModuleRecord.h @@ -5,6 +5,7 @@ #include "JavaScriptCore/JSString.h" #include "headers-handwritten.h" #include "wtf/NakedPtr.h" +#include "BunClientData.h" namespace Zig { class GlobalObject; @@ -18,6 +19,8 @@ class AbstractModuleRecord; namespace Bun { +using namespace JSC; + JSC_DECLARE_HOST_FUNCTION(jsFunctionCreateCommonJSModule); JSC_DECLARE_HOST_FUNCTION(jsFunctionLoadModule); diff --git a/src/bun.js/bindings/ProcessBindingConstants.cpp b/src/bun.js/bindings/ProcessBindingConstants.cpp index 6d2fb1a2f1..a63ef71c5e 100644 --- a/src/bun.js/bindings/ProcessBindingConstants.cpp +++ b/src/bun.js/bindings/ProcessBindingConstants.cpp @@ -17,10 +17,6 @@ #include #include -#ifndef OPENSSL_NO_ENGINE -#include -#endif - #if !defined(_MSC_VER) #include #endif @@ -769,6 +765,10 @@ static JSValue processBindingConstantsGetFs(VM& vm, JSObject* bindingObject) object->putDirect(vm, PropertyName(Identifier::fromString(vm, "COPYFILE_FICLONE"_s)), jsNumber(2)); object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_FS_COPYFILE_FICLONE_FORCE"_s)), jsNumber(4)); object->putDirect(vm, PropertyName(Identifier::fromString(vm, "COPYFILE_FICLONE_FORCE"_s)), jsNumber(4)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "EXTENSIONLESS_FORMAT_JAVASCRIPT"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "EXTENSIONLESS_FORMAT_WASM"_s)), jsNumber(1)); + return object; } @@ -784,6 +784,8 @@ static JSValue processBindingConstantsGetCrypto(VM& vm, JSObject* bindingObject) #endif #ifdef SSL_OP_ALLOW_NO_DHE_KEX object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_ALLOW_NO_DHE_KEX"_s)), jsNumber(SSL_OP_ALLOW_NO_DHE_KEX)); +#else + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_ALLOW_NO_DHE_KEX"_s)), jsNumber(0)); #endif #ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION"_s)), jsNumber(SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)); @@ -793,12 +795,18 @@ static JSValue processBindingConstantsGetCrypto(VM& vm, JSObject* bindingObject) #endif #ifdef SSL_OP_CISCO_ANYCONNECT object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_CISCO_ANYCONNECT"_s)), jsNumber(SSL_OP_CISCO_ANYCONNECT)); +#else + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_CISCO_ANYCONNECT"_s)), jsNumber(0)); #endif #ifdef SSL_OP_COOKIE_EXCHANGE object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_COOKIE_EXCHANGE"_s)), jsNumber(SSL_OP_COOKIE_EXCHANGE)); +#else + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_COOKIE_EXCHANGE"_s)), jsNumber(0)); #endif #ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_CRYPTOPRO_TLSEXT_BUG"_s)), jsNumber(SSL_OP_CRYPTOPRO_TLSEXT_BUG)); +#else + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_CRYPTOPRO_TLSEXT_BUG"_s)), jsNumber(0)); #endif #ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS"_s)), jsNumber(SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)); @@ -811,6 +819,8 @@ static JSValue processBindingConstantsGetCrypto(VM& vm, JSObject* bindingObject) #endif #ifdef SSL_OP_NO_ENCRYPT_THEN_MAC object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_ENCRYPT_THEN_MAC"_s)), jsNumber(SSL_OP_NO_ENCRYPT_THEN_MAC)); +#else + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_ENCRYPT_THEN_MAC"_s)), jsNumber(0)); #endif #ifdef SSL_OP_NO_QUERY_MTU object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_QUERY_MTU"_s)), jsNumber(SSL_OP_NO_QUERY_MTU)); @@ -844,45 +854,42 @@ static JSValue processBindingConstantsGetCrypto(VM& vm, JSObject* bindingObject) #endif #ifdef SSL_OP_PRIORITIZE_CHACHA object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_PRIORITIZE_CHACHA"_s)), jsNumber(SSL_OP_PRIORITIZE_CHACHA)); +#else + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_PRIORITIZE_CHACHA"_s)), jsNumber(0)); #endif #ifdef SSL_OP_TLS_ROLLBACK_BUG object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_TLS_ROLLBACK_BUG"_s)), jsNumber(SSL_OP_TLS_ROLLBACK_BUG)); #endif -#ifndef OPENSSL_NO_ENGINE -#ifdef ENGINE_METHOD_RSA - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_RSA"_s)), jsNumber(ENGINE_METHOD_RSA)); -#endif -#ifdef ENGINE_METHOD_DSA - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_DSA"_s)), jsNumber(ENGINE_METHOD_DSA)); -#endif -#ifdef ENGINE_METHOD_DH - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_DH"_s)), jsNumber(ENGINE_METHOD_DH)); -#endif -#ifdef ENGINE_METHOD_RAND - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_RAND"_s)), jsNumber(ENGINE_METHOD_RAND)); -#endif -#ifdef ENGINE_METHOD_EC - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_EC"_s)), jsNumber(ENGINE_METHOD_EC)); -#endif -#ifdef ENGINE_METHOD_CIPHERS - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_CIPHERS"_s)), jsNumber(ENGINE_METHOD_CIPHERS)); -#endif -#ifdef ENGINE_METHOD_DIGESTS - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_DIGESTS"_s)), jsNumber(ENGINE_METHOD_DIGESTS)); -#endif -#ifdef ENGINE_METHOD_PKEY_METHS - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_PKEY_METHS"_s)), jsNumber(ENGINE_METHOD_PKEY_METHS)); -#endif -#ifdef ENGINE_METHOD_PKEY_ASN1_METHS - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_PKEY_ASN1_METHS"_s)), jsNumber(ENGINE_METHOD_PKEY_ASN1_METHS)); -#endif -#ifdef ENGINE_METHOD_ALL - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_ALL"_s)), jsNumber(ENGINE_METHOD_ALL)); -#endif -#ifdef ENGINE_METHOD_NONE - object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_NONE"_s)), jsNumber(ENGINE_METHOD_NONE)); -#endif -#endif // !OPENSSL_NO_ENGINE + // OBSOLETE OPTIONS retained for compatibility + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_MICROSOFT_SESS_ID_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NETSCAPE_CHALLENGE_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_MSIE_SSLV2_RSA_PADDING"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_SSLEAY_080_CLIENT_DH_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_TLS_D5_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_TLS_BLOCK_PADDING_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_SINGLE_ECDH_USE"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_SINGLE_DH_USE"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_EPHEMERAL_RSA"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_SSLv2"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_PKCS1_CHECK_1"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_PKCS1_CHECK_2"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NETSCAPE_CA_DN_BUG"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG"_s)), jsNumber(0)); + // BoringSSL does not define engine constants in openssl/engine.h + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_RSA"_s)), jsNumber(0x0001)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_DSA"_s)), jsNumber(0x0002)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_DH"_s)), jsNumber(0x0004)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_RAND"_s)), jsNumber(0x0008)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_CIPHERS"_s)), jsNumber(0x0040)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_DIGESTS"_s)), jsNumber(0x0080)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_PKEY_METHS"_s)), jsNumber(0x0200)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_PKEY_ASN1_METHS"_s)), jsNumber(0x0400)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_EC"_s)), jsNumber(0x0800)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_ALL"_s)), jsNumber(0xFFFF)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ENGINE_METHOD_NONE"_s)), jsNumber(0x0000)); #ifdef DH_CHECK_P_NOT_SAFE_PRIME object->putDirect(vm, PropertyName(Identifier::fromString(vm, "DH_CHECK_P_NOT_SAFE_PRIME"_s)), jsNumber(DH_CHECK_P_NOT_SAFE_PRIME)); #endif @@ -958,18 +965,10 @@ static JSValue processBindingConstantsGetCrypto(VM& vm, JSObject* bindingObject) jsString(vm, cipherList)); object->putDirect(vm, PropertyName(Identifier::fromString(vm, "defaultCipherList"_s)), jsString(vm, cipherList)); -#ifdef TLS1_VERSION object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TLS1_VERSION"_s)), jsNumber(TLS1_VERSION)); -#endif -#ifdef TLS1_1_VERSION object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TLS1_1_VERSION"_s)), jsNumber(TLS1_1_VERSION)); -#endif -#ifdef TLS1_2_VERSION object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TLS1_2_VERSION"_s)), jsNumber(TLS1_2_VERSION)); -#endif -#ifdef TLS1_3_VERSION object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TLS1_3_VERSION"_s)), jsNumber(TLS1_3_VERSION)); -#endif object->putDirect(vm, PropertyName(Identifier::fromString(vm, "POINT_CONVERSION_COMPRESSED"_s)), jsNumber(POINT_CONVERSION_COMPRESSED)); object->putDirect(vm, PropertyName(Identifier::fromString(vm, "POINT_CONVERSION_UNCOMPRESSED"_s)), jsNumber(POINT_CONVERSION_UNCOMPRESSED)); object->putDirect(vm, PropertyName(Identifier::fromString(vm, "POINT_CONVERSION_HYBRID"_s)), jsNumber(POINT_CONVERSION_HYBRID)); diff --git a/src/bun.js/modules/NodeModuleModule.h b/src/bun.js/modules/NodeModuleModule.h index e825170848..fa2650434b 100644 --- a/src/bun.js/modules/NodeModuleModule.h +++ b/src/bun.js/modules/NodeModuleModule.h @@ -4,12 +4,14 @@ #include "CommonJSModuleRecord.h" #include "ImportMetaObject.h" #include "JavaScriptCore/ArgList.h" +#include "JavaScriptCore/JSCJSValue.h" #include "JavaScriptCore/JSGlobalObjectInlines.h" #include "_NativeModule.h" #include "isBuiltinModule.h" #include #include #include "PathInlines.h" +#include "headers.h" using namespace Zig; using namespace JSC; @@ -532,6 +534,17 @@ DEFINE_NATIVE_MODULE(NodeModule) { put(Identifier::fromString(vm, "_cache"_s), jsCast(globalObject)->lazyRequireCacheObject()); put(Identifier::fromString(vm, "globalPaths"_s), constructEmptyArray(globalObject, nullptr, 0)); + auto constants_compileCacheStatus = constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure()); + constants_compileCacheStatus->putDirect(vm, Identifier::fromString(vm, "FAILED"_s), jsNumber(0)); + constants_compileCacheStatus->putDirect(vm, Identifier::fromString(vm, "ENABLED"_s), jsNumber(1)); + constants_compileCacheStatus->putDirect(vm, Identifier::fromString(vm, "ALREADY_ENABLED"_s), jsNumber(2)); + constants_compileCacheStatus->putDirect(vm, Identifier::fromString(vm, "DISABLED"_s), jsNumber(3)); + + auto constants = constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure()); + constants->putDirect(vm, Identifier::fromString(vm, "compileCacheStatus"_s), constants_compileCacheStatus); + + put(Identifier::fromString(vm,"constants"_s), constants); + auto prototype = constructEmptyObject(globalObject, globalObject->objectPrototype(), 1); prototype->putDirectCustomAccessor( vm, WebCore::clientData(vm)->builtinNames().requirePublicName(), diff --git a/src/js/node/fs.ts b/src/js/node/fs.ts index 3b6f205101..b0b7905d7d 100644 --- a/src/js/node/fs.ts +++ b/src/js/node/fs.ts @@ -1542,7 +1542,6 @@ setName(chown, "chown"); setName(chownSync, "chownSync"); setName(close, "close"); setName(closeSync, "closeSync"); -setName(constants, "constants"); setName(copyFile, "copyFile"); setName(copyFileSync, "copyFileSync"); setName(cp, "cp"); @@ -1579,7 +1578,6 @@ setName(mkdtemp, "mkdtemp"); setName(mkdtempSync, "mkdtempSync"); setName(open, "open"); setName(openSync, "openSync"); -setName(promises, "promises"); setName(read, "read"); setName(readFile, "readFile"); setName(readFileSync, "readFileSync"); diff --git a/src/js/node/vm.ts b/src/js/node/vm.ts index 6cf4a90cf0..fd447006ef 100644 --- a/src/js/node/vm.ts +++ b/src/js/node/vm.ts @@ -3,6 +3,8 @@ const { throwNotImplemented } = require("internal/shared"); const vm = $cpp("NodeVM.cpp", "Bun::createNodeVMBinding"); +const ObjectFreeze = Object.freeze; + const { createContext, isContext, Script, runInNewContext, runInThisContext } = vm; function runInContext(code, context, options) { @@ -38,6 +40,12 @@ class SyntheticModule { } } +const constants = { + __proto__: null, + USE_MAIN_CONTEXT_DEFAULT_LOADER: Symbol("vm_dynamic_import_main_context_default"), + DONT_CONTEXTIFY: Symbol("vm_context_no_contextify"), +}; + export default { createContext, runInContext, @@ -51,4 +59,5 @@ export default { SourceTextModule, SyntheticModule, createScript, + constants: ObjectFreeze(constants), }; diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 2b64c59115..54a328e15a 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -2653,6 +2653,8 @@ it("fs.constants", () => { COPYFILE_FICLONE: 2, UV_FS_COPYFILE_FICLONE_FORCE: 4, COPYFILE_FICLONE_FORCE: 4, + EXTENSIONLESS_FORMAT_JAVASCRIPT: 0, + EXTENSIONLESS_FORMAT_WASM: 1, } as any); return; }