diff options
Diffstat (limited to 'src/bun.js')
39 files changed, 4469 insertions, 2690 deletions
diff --git a/src/bun.js/bindings/BunJSCModule.cpp b/src/bun.js/bindings/BunJSCModule.cpp deleted file mode 100644 index 444318632..000000000 --- a/src/bun.js/bindings/BunJSCModule.cpp +++ /dev/null @@ -1,615 +0,0 @@ -#include "root.h" - -#include "JavaScriptCore/JavaScript.h" -#include "wtf/FileSystem.h" -#include "wtf/MemoryFootprint.h" -#include "wtf/text/WTFString.h" -#include "JavaScriptCore/CodeBlock.h" -#include "JavaScriptCore/JSCInlines.h" -#include "JavaScriptCore/TestRunnerUtils.h" -#include "JavaScriptCore/JIT.h" -#include "JavaScriptCore/APICast.h" -#include "JavaScriptCore/JSBasePrivate.h" -#include "JavaScriptCore/ObjectConstructor.h" -#include "JavaScriptCore/AggregateError.h" -#include "JavaScriptCore/BytecodeIndex.h" -#include "JavaScriptCore/CallFrameInlines.h" -#include "JavaScriptCore/ClassInfo.h" -#include "JavaScriptCore/CodeBlock.h" -#include "JavaScriptCore/Completion.h" -#include "JavaScriptCore/Error.h" -#include "JavaScriptCore/ErrorInstance.h" -#include "JavaScriptCore/HeapSnapshotBuilder.h" -#include "JavaScriptCore/JSONObject.h" -#include "JavaScriptCore/DeferTermination.h" -#include "JavaScriptCore/SamplingProfiler.h" -#include "JavaScriptCore/VMTrapsInlines.h" -#include "SerializedScriptValue.h" -#include "ExceptionOr.h" -#include "MessagePort.h" - -#include "Process.h" - -#if ENABLE(REMOTE_INSPECTOR) -#include "JavaScriptCore/RemoteInspectorServer.h" -#endif - -#include "mimalloc.h" -#include "JSDOMConvertBase.h" - -using namespace JSC; -using namespace WTF; -using namespace WebCore; - -JSC_DECLARE_HOST_FUNCTION(functionStartRemoteDebugger); -JSC_DEFINE_HOST_FUNCTION(functionStartRemoteDebugger, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ -#if ENABLE(REMOTE_INSPECTOR) - static const char* defaultHost = "127.0.0.1\0"; - static uint16_t defaultPort = 9230; // node + 1 - auto& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - JSC::JSValue hostValue = callFrame->argument(0); - JSC::JSValue portValue = callFrame->argument(1); - const char* host = defaultHost; - if (hostValue.isString()) { - - auto str = hostValue.toWTFString(globalObject); - if (!str.isEmpty()) - host = toCString(str).data(); - } else if (!hostValue.isUndefined()) { - throwVMError(globalObject, scope, createTypeError(globalObject, "host must be a string"_s)); - return JSC::JSValue::encode(JSC::jsUndefined()); - } - - uint16_t port = defaultPort; - if (portValue.isNumber()) { - auto port_int = portValue.toUInt32(globalObject); - if (!(port_int > 0 && port_int < 65536)) { - throwVMError(globalObject, scope, createRangeError(globalObject, "port must be between 0 and 65535"_s)); - return JSC::JSValue::encode(JSC::jsUndefined()); - } - port = port_int; - } else if (!portValue.isUndefined()) { - throwVMError(globalObject, scope, createTypeError(globalObject, "port must be a number between 0 and 65535"_s)); - return JSC::JSValue::encode(JSC::jsUndefined()); - } - - globalObject->setInspectable(true); - auto& server = Inspector::RemoteInspectorServer::singleton(); - if (!server.start(reinterpret_cast<const char*>(host), port)) { - throwVMError(globalObject, scope, createError(globalObject, "Failed to start server \""_s + host + ":"_s + port + "\". Is port already in use?"_s)); - return JSC::JSValue::encode(JSC::jsUndefined()); - } - - RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsUndefined())); -#else - auto& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - throwVMError(globalObject, scope, createTypeError(globalObject, "Remote inspector is not enabled in this build of Bun"_s)); - return JSC::JSValue::encode(JSC::jsUndefined()); -#endif -} - -JSC_DECLARE_HOST_FUNCTION(functionDescribe); -JSC_DEFINE_HOST_FUNCTION(functionDescribe, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - VM& vm = globalObject->vm(); - if (callFrame->argumentCount() < 1) - return JSValue::encode(jsUndefined()); - return JSValue::encode(jsString(vm, toString(callFrame->argument(0)))); -} - -JSC_DECLARE_HOST_FUNCTION(functionDescribeArray); -JSC_DEFINE_HOST_FUNCTION(functionDescribeArray, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - if (callFrame->argumentCount() < 1) - return JSValue::encode(jsUndefined()); - VM& vm = globalObject->vm(); - JSObject* object = jsDynamicCast<JSObject*>(callFrame->argument(0)); - if (!object) - return JSValue::encode(jsNontrivialString(vm, "<not object>"_s)); - return JSValue::encode(jsNontrivialString(vm, toString("<Butterfly: ", RawPointer(object->butterfly()), "; public length: ", object->getArrayLength(), "; vector length: ", object->getVectorLength(), ">"))); -} - -JSC_DECLARE_HOST_FUNCTION(functionGCAndSweep); -JSC_DEFINE_HOST_FUNCTION(functionGCAndSweep, (JSGlobalObject * globalObject, CallFrame*)) -{ - VM& vm = globalObject->vm(); - JSLockHolder lock(vm); - vm.heap.collectNow(Sync, CollectionScope::Full); - return JSValue::encode(jsNumber(vm.heap.sizeAfterLastFullCollection())); -} - -JSC_DECLARE_HOST_FUNCTION(functionFullGC); -JSC_DEFINE_HOST_FUNCTION(functionFullGC, (JSGlobalObject * globalObject, CallFrame*)) -{ - VM& vm = globalObject->vm(); - JSLockHolder lock(vm); - vm.heap.collectSync(CollectionScope::Full); - return JSValue::encode(jsNumber(vm.heap.sizeAfterLastFullCollection())); -} - -JSC_DECLARE_HOST_FUNCTION(functionEdenGC); -JSC_DEFINE_HOST_FUNCTION(functionEdenGC, (JSGlobalObject * globalObject, CallFrame*)) -{ - VM& vm = globalObject->vm(); - JSLockHolder lock(vm); - vm.heap.collectSync(CollectionScope::Eden); - return JSValue::encode(jsNumber(vm.heap.sizeAfterLastEdenCollection())); -} - -JSC_DECLARE_HOST_FUNCTION(functionHeapSize); -JSC_DEFINE_HOST_FUNCTION(functionHeapSize, (JSGlobalObject * globalObject, CallFrame*)) -{ - VM& vm = globalObject->vm(); - JSLockHolder lock(vm); - return JSValue::encode(jsNumber(vm.heap.size())); -} - -JSC::Structure* createMemoryFootprintStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject) -{ - - JSC::Structure* structure = globalObject->structureCache().emptyObjectStructureForPrototype(globalObject, globalObject->objectPrototype(), 5); - JSC::PropertyOffset offset; - - structure = structure->addPropertyTransition(vm, structure, Identifier::fromString(vm, "current"_s), 0, offset); - structure = structure->addPropertyTransition(vm, structure, Identifier::fromString(vm, "peak"_s), 0, offset); - structure = structure->addPropertyTransition(vm, structure, Identifier::fromString(vm, "currentCommit"_s), 0, offset); - structure = structure->addPropertyTransition(vm, structure, Identifier::fromString(vm, "peakCommit"_s), 0, offset); - structure = structure->addPropertyTransition(vm, structure, Identifier::fromString(vm, "pageFaults"_s), 0, offset); - - return structure; -} - -JSC_DECLARE_HOST_FUNCTION(functionMemoryUsageStatistics); -JSC_DEFINE_HOST_FUNCTION(functionMemoryUsageStatistics, (JSGlobalObject * globalObject, CallFrame*)) -{ - - auto& vm = globalObject->vm(); - JSC::DisallowGC disallowGC; - - // this is a C API function - auto* stats = toJS(JSGetMemoryUsageStatistics(toRef(globalObject))); - - if (JSValue heapSizeValue = stats->getDirect(vm, Identifier::fromString(vm, "heapSize"_s))) { - ASSERT(heapSizeValue.isNumber()); - if (heapSizeValue.toInt32(globalObject) == 0) { - vm.heap.collectNow(Sync, CollectionScope::Full); - stats = toJS(JSGetMemoryUsageStatistics(toRef(globalObject))); - } - } - - // This is missing from the C API - JSC::JSObject* protectedCounts = constructEmptyObject(globalObject); - auto typeCounts = *vm.heap.protectedObjectTypeCounts(); - for (auto& it : typeCounts) - protectedCounts->putDirect(vm, Identifier::fromLatin1(vm, it.key), jsNumber(it.value)); - - stats->putDirect(vm, Identifier::fromLatin1(vm, "protectedObjectTypeCounts"_s), protectedCounts); - return JSValue::encode(stats); -} - -JSC_DECLARE_HOST_FUNCTION(functionCreateMemoryFootprint); -JSC_DEFINE_HOST_FUNCTION(functionCreateMemoryFootprint, (JSGlobalObject * globalObject, CallFrame*)) -{ - - size_t elapsed_msecs = 0; - size_t user_msecs = 0; - size_t system_msecs = 0; - size_t current_rss = 0; - size_t peak_rss = 0; - size_t current_commit = 0; - size_t peak_commit = 0; - size_t page_faults = 0; - - mi_process_info(&elapsed_msecs, &user_msecs, &system_msecs, - ¤t_rss, &peak_rss, - ¤t_commit, &peak_commit, &page_faults); - - // mi_process_info produces incorrect rss size on linux. - Zig::getRSS(¤t_rss); - - VM& vm = globalObject->vm(); - JSC::JSObject* object = JSC::constructEmptyObject(vm, JSC::jsCast<Zig::GlobalObject*>(globalObject)->memoryFootprintStructure()); - - object->putDirectOffset(vm, 0, jsNumber(current_rss)); - object->putDirectOffset(vm, 1, jsNumber(peak_rss)); - object->putDirectOffset(vm, 2, jsNumber(current_commit)); - object->putDirectOffset(vm, 3, jsNumber(peak_commit)); - object->putDirectOffset(vm, 4, jsNumber(page_faults)); - - return JSValue::encode(object); -} - -JSC_DECLARE_HOST_FUNCTION(functionNeverInlineFunction); -JSC_DEFINE_HOST_FUNCTION(functionNeverInlineFunction, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - return JSValue::encode(setNeverInline(globalObject, callFrame)); -} - -extern "C" bool Bun__mkdirp(JSC::JSGlobalObject*, const char*); - -JSC_DECLARE_HOST_FUNCTION(functionStartSamplingProfiler); -JSC_DEFINE_HOST_FUNCTION(functionStartSamplingProfiler, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) -{ - JSC::VM& vm = globalObject->vm(); - JSC::SamplingProfiler& samplingProfiler = vm.ensureSamplingProfiler(WTF::Stopwatch::create()); - - JSC::JSValue directoryValue = callFrame->argument(0); - JSC::JSValue sampleValue = callFrame->argument(1); - - auto scope = DECLARE_THROW_SCOPE(vm); - if (directoryValue.isString()) { - auto path = directoryValue.toWTFString(globalObject); - if (!path.isEmpty()) { - StringPrintStream pathOut; - auto pathCString = toCString(String(path)); - if (!Bun__mkdirp(globalObject, pathCString.data())) { - throwVMError(globalObject, scope, createTypeError(globalObject, "directory couldn't be created"_s)); - return JSC::JSValue::encode(jsUndefined()); - } - - Options::samplingProfilerPath() = pathCString.data(); - samplingProfiler.registerForReportAtExit(); - } - } - if (sampleValue.isNumber()) { - unsigned sampleInterval = sampleValue.toUInt32(globalObject); - samplingProfiler.setTimingInterval(Seconds::fromMicroseconds(sampleInterval)); - } - - samplingProfiler.noticeCurrentThreadAsJSCExecutionThread(); - samplingProfiler.start(); - return JSC::JSValue::encode(jsUndefined()); -} - -JSC_DECLARE_HOST_FUNCTION(functionSamplingProfilerStackTraces); -JSC_DEFINE_HOST_FUNCTION(functionSamplingProfilerStackTraces, (JSC::JSGlobalObject * globalObject, JSC::CallFrame*)) -{ - JSC::VM& vm = globalObject->vm(); - JSC::DeferTermination deferScope(vm); - auto scope = DECLARE_THROW_SCOPE(vm); - - if (!vm.samplingProfiler()) - return JSC::JSValue::encode(throwException(globalObject, scope, createError(globalObject, "Sampling profiler was never started"_s))); - - WTF::String jsonString = vm.samplingProfiler()->stackTracesAsJSON(); - JSC::EncodedJSValue result = JSC::JSValue::encode(JSONParse(globalObject, jsonString)); - scope.releaseAssertNoException(); - return result; -} - -JSC_DECLARE_HOST_FUNCTION(functionGetRandomSeed); -JSC_DEFINE_HOST_FUNCTION(functionGetRandomSeed, (JSGlobalObject * globalObject, CallFrame*)) -{ - return JSValue::encode(jsNumber(globalObject->weakRandom().seed())); -} - -JSC_DECLARE_HOST_FUNCTION(functionSetRandomSeed); -JSC_DEFINE_HOST_FUNCTION(functionSetRandomSeed, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - VM& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - unsigned seed = callFrame->argument(0).toUInt32(globalObject); - RETURN_IF_EXCEPTION(scope, encodedJSValue()); - globalObject->weakRandom().setSeed(seed); - return JSValue::encode(jsUndefined()); -} - -JSC_DECLARE_HOST_FUNCTION(functionIsRope); -JSC_DEFINE_HOST_FUNCTION(functionIsRope, (JSGlobalObject*, CallFrame* callFrame)) -{ - JSValue argument = callFrame->argument(0); - if (!argument.isString()) - return JSValue::encode(jsBoolean(false)); - const StringImpl* impl = asString(argument)->tryGetValueImpl(); - return JSValue::encode(jsBoolean(!impl)); -} - -JSC_DECLARE_HOST_FUNCTION(functionCallerSourceOrigin); -JSC_DEFINE_HOST_FUNCTION(functionCallerSourceOrigin, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - VM& vm = globalObject->vm(); - SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); - if (sourceOrigin.url().isNull()) - return JSValue::encode(jsNull()); - return JSValue::encode(jsString(vm, sourceOrigin.string())); -} - -JSC_DECLARE_HOST_FUNCTION(functionNoFTL); -JSC_DEFINE_HOST_FUNCTION(functionNoFTL, (JSGlobalObject*, CallFrame* callFrame)) -{ - if (callFrame->argumentCount()) { - FunctionExecutable* executable = getExecutableForFunction(callFrame->argument(0)); - if (executable) - executable->setNeverFTLOptimize(true); - } - return JSValue::encode(jsUndefined()); -} - -JSC_DECLARE_HOST_FUNCTION(functionNoOSRExitFuzzing); -JSC_DEFINE_HOST_FUNCTION(functionNoOSRExitFuzzing, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - return JSValue::encode(setCannotUseOSRExitFuzzing(globalObject, callFrame)); -} - -JSC_DECLARE_HOST_FUNCTION(functionOptimizeNextInvocation); -JSC_DEFINE_HOST_FUNCTION(functionOptimizeNextInvocation, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - return JSValue::encode(optimizeNextInvocation(globalObject, callFrame)); -} - -JSC_DECLARE_HOST_FUNCTION(functionNumberOfDFGCompiles); -JSC_DEFINE_HOST_FUNCTION(functionNumberOfDFGCompiles, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - return JSValue::encode(numberOfDFGCompiles(globalObject, callFrame)); -} - -JSC_DECLARE_HOST_FUNCTION(functionReleaseWeakRefs); -JSC_DEFINE_HOST_FUNCTION(functionReleaseWeakRefs, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - globalObject->vm().finalizeSynchronousJSExecution(); - return JSValue::encode(jsUndefined()); -} - -JSC_DECLARE_HOST_FUNCTION(functionTotalCompileTime); -JSC_DEFINE_HOST_FUNCTION(functionTotalCompileTime, (JSGlobalObject*, CallFrame*)) -{ - return JSValue::encode(jsNumber(JIT::totalCompileTime().milliseconds())); -} - -JSC_DECLARE_HOST_FUNCTION(functionGetProtectedObjects); -JSC_DEFINE_HOST_FUNCTION(functionGetProtectedObjects, (JSGlobalObject * globalObject, CallFrame*)) -{ - MarkedArgumentBuffer list; - size_t result = 0; - globalObject->vm().heap.forEachProtectedCell( - [&](JSCell* cell) { - list.append(cell); - }); - RELEASE_ASSERT(!list.hasOverflowed()); - return JSC::JSValue::encode(constructArray(globalObject, static_cast<JSC::ArrayAllocationProfile*>(nullptr), list)); -} - -JSC_DECLARE_HOST_FUNCTION(functionReoptimizationRetryCount); -JSC_DEFINE_HOST_FUNCTION(functionReoptimizationRetryCount, (JSGlobalObject*, CallFrame* callFrame)) -{ - if (callFrame->argumentCount() < 1) - return JSValue::encode(jsUndefined()); - - CodeBlock* block = getSomeBaselineCodeBlockForFunction(callFrame->argument(0)); - if (!block) - return JSValue::encode(jsNumber(0)); - - return JSValue::encode(jsNumber(block->reoptimizationRetryCounter())); -} - -extern "C" void Bun__drainMicrotasks(); - -JSC_DECLARE_HOST_FUNCTION(functionDrainMicrotasks); -JSC_DEFINE_HOST_FUNCTION(functionDrainMicrotasks, (JSGlobalObject * globalObject, CallFrame*)) -{ - VM& vm = globalObject->vm(); - vm.drainMicrotasks(); - Bun__drainMicrotasks(); - return JSValue::encode(jsUndefined()); -} - -JSC_DEFINE_HOST_FUNCTION(functionSetTimeZone, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - VM& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - if (callFrame->argumentCount() < 1) { - throwTypeError(globalObject, scope, "setTimeZone requires a timezone string"_s); - return encodedJSValue(); - } - - if (!callFrame->argument(0).isString()) { - throwTypeError(globalObject, scope, "setTimeZone requires a timezone string"_s); - return encodedJSValue(); - } - - String timeZoneName = callFrame->argument(0).toWTFString(globalObject); - RETURN_IF_EXCEPTION(scope, encodedJSValue()); - - double time = callFrame->argument(1).toNumber(globalObject); - RETURN_IF_EXCEPTION(scope, encodedJSValue()); - - if (!WTF::setTimeZoneOverride(timeZoneName)) { - throwTypeError(globalObject, scope, makeString("Invalid timezone: \""_s, timeZoneName, "\""_s)); - return encodedJSValue(); - } - vm.dateCache.resetIfNecessarySlow(); - WTF::Vector<UChar, 32> buffer; - WTF::getTimeZoneOverride(buffer); - WTF::String timeZoneString(buffer.data(), buffer.size()); - return JSValue::encode(jsString(vm, timeZoneString)); -} - -JSC_DEFINE_HOST_FUNCTION(functionRunProfiler, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - JSC::VM& vm = globalObject->vm(); - JSC::SamplingProfiler& samplingProfiler = vm.ensureSamplingProfiler(WTF::Stopwatch::create()); - - JSC::JSValue callbackValue = callFrame->argument(0); - auto throwScope = DECLARE_THROW_SCOPE(vm); - if (callbackValue.isUndefinedOrNull() || !callbackValue.isCallable()) { - throwException(globalObject, throwScope, createTypeError(globalObject, "First argument must be a function."_s)); - return JSValue::encode(JSValue {}); - } - - JSC::JSFunction* function = jsCast<JSC::JSFunction*>(callbackValue); - - JSC::JSValue sampleValue = callFrame->argument(1); - if (sampleValue.isNumber()) { - unsigned sampleInterval = sampleValue.toUInt32(globalObject); - samplingProfiler.setTimingInterval(Seconds::fromMicroseconds(sampleInterval)); - } - - JSC::CallData callData = JSC::getCallData(function); - MarkedArgumentBuffer args; - - samplingProfiler.noticeCurrentThreadAsJSCExecutionThread(); - samplingProfiler.start(); - JSC::call(globalObject, function, callData, JSC::jsUndefined(), args); - samplingProfiler.pause(); - if (throwScope.exception()) { - samplingProfiler.shutdown(); - samplingProfiler.clearData(); - return JSValue::encode(JSValue {}); - } - - StringPrintStream topFunctions; - samplingProfiler.reportTopFunctions(topFunctions); - - StringPrintStream byteCodes; - samplingProfiler.reportTopBytecodes(byteCodes); - - JSValue stackTraces = JSONParse(globalObject, samplingProfiler.stackTracesAsJSON()); - - samplingProfiler.shutdown(); - samplingProfiler.clearData(); - - JSObject* result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 3); - result->putDirect(vm, Identifier::fromString(vm, "functions"_s), jsString(vm, topFunctions.toString())); - result->putDirect(vm, Identifier::fromString(vm, "bytecodes"_s), jsString(vm, byteCodes.toString())); - result->putDirect(vm, Identifier::fromString(vm, "stackTraces"_s), stackTraces); - - return JSValue::encode(result); -} - -JSC_DECLARE_HOST_FUNCTION(functionGenerateHeapSnapshotForDebugging); -JSC_DEFINE_HOST_FUNCTION(functionGenerateHeapSnapshotForDebugging, (JSGlobalObject * globalObject, CallFrame*)) -{ - VM& vm = globalObject->vm(); - JSLockHolder lock(vm); - DeferTermination deferScope(vm); - auto scope = DECLARE_THROW_SCOPE(vm); - String jsonString; - { - DeferGCForAWhile deferGC(vm); // Prevent concurrent GC from interfering with the full GC that the snapshot does. - - HeapSnapshotBuilder snapshotBuilder(vm.ensureHeapProfiler(), HeapSnapshotBuilder::SnapshotType::GCDebuggingSnapshot); - snapshotBuilder.buildSnapshot(); - - jsonString = snapshotBuilder.json(); - } - scope.releaseAssertNoException(); - - return JSValue::encode(JSONParse(globalObject, WTFMove(jsonString))); -} - -JSC_DEFINE_HOST_FUNCTION(functionSerialize, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - auto* globalObject = jsCast<JSDOMGlobalObject*>(lexicalGlobalObject); - JSC::VM& vm = globalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - - JSValue value = callFrame->argument(0); - JSValue optionsObject = callFrame->argument(1); - bool asNodeBuffer = false; - if (optionsObject.isObject()) { - JSC::JSObject* options = optionsObject.getObject(); - if (JSC::JSValue binaryTypeValue = options->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "binaryType"_s))) { - if (!binaryTypeValue.isString()) { - throwTypeError(globalObject, throwScope, "binaryType must be a string"_s); - return JSValue::encode(jsUndefined()); - } - - asNodeBuffer = binaryTypeValue.toWTFString(globalObject) == "nodebuffer"_s; - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - } - } - - Vector<JSC::Strong<JSC::JSObject>> transferList; - Vector<RefPtr<MessagePort>> dummyPorts; - ExceptionOr<Ref<SerializedScriptValue>> serialized = SerializedScriptValue::create(*globalObject, value, WTFMove(transferList), dummyPorts); - - if (serialized.hasException()) { - WebCore::propagateException(*globalObject, throwScope, serialized.releaseException()); - return JSValue::encode(jsUndefined()); - } - - auto serializedValue = serialized.releaseReturnValue(); - auto arrayBuffer = serializedValue->toArrayBuffer(); - - if (asNodeBuffer) { - size_t byteLength = arrayBuffer->byteLength(); - JSC::JSUint8Array* uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, globalObject->JSBufferSubclassStructure(), WTFMove(arrayBuffer), 0, byteLength); - return JSValue::encode(uint8Array); - } - - if (arrayBuffer->isShared()) { - return JSValue::encode(JSArrayBuffer::create(vm, globalObject->arrayBufferStructureWithSharingMode<ArrayBufferSharingMode::Shared>(), WTFMove(arrayBuffer))); - } - - return JSValue::encode(JSArrayBuffer::create(vm, globalObject->arrayBufferStructure(), WTFMove(arrayBuffer))); -} -JSC_DEFINE_HOST_FUNCTION(functionDeserialize, (JSGlobalObject * globalObject, CallFrame* callFrame)) -{ - JSC::VM& vm = globalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - JSValue value = callFrame->argument(0); - - JSValue result; - - if (auto* jsArrayBuffer = jsDynamicCast<JSArrayBuffer*>(value)) { - result = SerializedScriptValue::fromArrayBuffer(*globalObject, globalObject, jsArrayBuffer->impl(), 0, jsArrayBuffer->impl()->byteLength()); - } else if (auto* view = jsDynamicCast<JSArrayBufferView*>(value)) { - auto arrayBuffer = view->possiblySharedImpl()->possiblySharedBuffer(); - result = SerializedScriptValue::fromArrayBuffer(*globalObject, globalObject, arrayBuffer.get(), view->byteOffset(), view->byteLength()); - } else { - throwTypeError(globalObject, throwScope, "First argument must be an ArrayBuffer"_s); - return JSValue::encode(jsUndefined()); - } - - RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined())); - RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); -} - -JSC::JSObject* createJSCModule(JSC::JSGlobalObject* globalObject) -{ - VM& vm = globalObject->vm(); - JSC::JSObject* object = nullptr; - - { - JSC::ObjectInitializationScope initializationScope(vm); - object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 23); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "callerSourceOrigin"_s), 1, functionCallerSourceOrigin, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "describe"_s), 1, functionDescribe, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "describeArray"_s), 1, functionDescribeArray, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "drainMicrotasks"_s), 1, functionDrainMicrotasks, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "edenGC"_s), 1, functionEdenGC, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "fullGC"_s), 1, functionFullGC, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "gcAndSweep"_s), 1, functionGCAndSweep, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "getRandomSeed"_s), 1, functionGetRandomSeed, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "heapSize"_s), 1, functionHeapSize, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "heapStats"_s), 1, functionMemoryUsageStatistics, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "startSamplingProfiler"_s), 1, functionStartSamplingProfiler, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "samplingProfilerStackTraces"_s), 1, functionSamplingProfilerStackTraces, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "noInline"_s), 1, functionNeverInlineFunction, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "isRope"_s), 1, functionIsRope, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "memoryUsage"_s), 1, functionCreateMemoryFootprint, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "noFTL"_s), 1, functionNoFTL, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "noOSRExitFuzzing"_s), 1, functionNoOSRExitFuzzing, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "numberOfDFGCompiles"_s), 1, functionNumberOfDFGCompiles, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "optimizeNextInvocation"_s), 1, functionOptimizeNextInvocation, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "releaseWeakRefs"_s), 1, functionReleaseWeakRefs, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "reoptimizationRetryCount"_s), 1, functionReoptimizationRetryCount, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "setRandomSeed"_s), 1, functionSetRandomSeed, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "startRemoteDebugger"_s), 2, functionStartRemoteDebugger, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "totalCompileTime"_s), 1, functionTotalCompileTime, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "getProtectedObjects"_s), 1, functionGetProtectedObjects, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "generateHeapSnapshotForDebugging"_s), 0, functionGenerateHeapSnapshotForDebugging, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "profile"_s), 0, functionRunProfiler, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "setTimeZone"_s), 0, functionSetTimeZone, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "serialize"_s), 0, functionSerialize, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "deserialize"_s), 0, functionDeserialize, ImplementationVisibility::Public, NoIntrinsic, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); - } - - return object; -} diff --git a/src/bun.js/bindings/BunJSCModule.h b/src/bun.js/bindings/BunJSCModule.h deleted file mode 100644 index d2ddcf6a7..000000000 --- a/src/bun.js/bindings/BunJSCModule.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "root.h" -#include "JavaScriptCore/JSObject.h" - -JSC::JSObject* createJSCModule(JSC::JSGlobalObject* globalObject); -JSC::Structure* createMemoryFootprintStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
\ No newline at end of file diff --git a/src/bun.js/bindings/CommonJSModuleRecord.cpp b/src/bun.js/bindings/CommonJSModuleRecord.cpp index bcae04500..a1f5781d7 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.cpp +++ b/src/bun.js/bindings/CommonJSModuleRecord.cpp @@ -93,7 +93,7 @@ static bool canPerformFastEnumeration(Structure* s) return true; } -static bool evaluateCommonJSModuleOnce(JSC::VM& vm, Zig::GlobalObject* globalObject, JSCommonJSModule* moduleObject, JSString* dirname, JSString* filename, WTF::NakedPtr<Exception>& exception) +static bool evaluateCommonJSModuleOnce(JSC::VM& vm, Zig::GlobalObject* globalObject, JSCommonJSModule* moduleObject, JSString* dirname, JSValue filename, WTF::NakedPtr<Exception>& exception) { JSC::Structure* thisObjectStructure = globalObject->commonJSFunctionArgumentsStructure(); JSC::JSObject* thisObject = JSC::constructEmptyObject( @@ -395,7 +395,7 @@ public: const JSC::ClassInfo JSCommonJSModulePrototype::s_info = { "Module"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCommonJSModulePrototype) }; -void JSCommonJSModule::finishCreation(JSC::VM& vm, JSC::JSString* id, JSC::JSString* filename, JSC::JSString* dirname, JSC::JSSourceCode* sourceCode) +void JSCommonJSModule::finishCreation(JSC::VM& vm, JSC::JSString* id, JSValue filename, JSC::JSString* dirname, JSC::JSSourceCode* sourceCode) { Base::finishCreation(vm); ASSERT(inherits(vm, info())); @@ -421,7 +421,7 @@ JSCommonJSModule* JSCommonJSModule::create( JSC::VM& vm, JSC::Structure* structure, JSC::JSString* id, - JSC::JSString* filename, + JSValue filename, JSC::JSString* dirname, JSC::JSSourceCode* sourceCode) { @@ -489,60 +489,10 @@ bool JSCommonJSModule::evaluate( auto throwScope = DECLARE_THROW_SCOPE(vm); generator(globalObject, JSC::Identifier::fromString(vm, key), propertyNames, arguments); RETURN_IF_EXCEPTION(throwScope, false); - - bool needsPut = false; - auto getDefaultValue = [&]() -> JSValue { - size_t defaultValueIndex = propertyNames.find(vm.propertyNames->defaultKeyword); - auto cjsSymbol = Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s)); - - if (defaultValueIndex != notFound && propertyNames.contains(cjsSymbol)) { - JSValue current = arguments.at(defaultValueIndex); - needsPut = true; - return current; - } - - size_t count = propertyNames.size(); - JSValue existingDefaultObject = this->getIfPropertyExists(globalObject, WebCore::clientData(vm)->builtinNames().exportsPublicName()); - JSObject* defaultObject; - - if (existingDefaultObject && existingDefaultObject.isObject()) { - defaultObject = jsCast<JSObject*>(existingDefaultObject); - } else { - defaultObject = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype()); - needsPut = true; - } - - for (size_t i = 0; i < count; ++i) { - auto prop = propertyNames[i]; - unsigned attributes = 0; - - JSValue value = arguments.at(i); - - if (prop.isSymbol()) { - attributes |= JSC::PropertyAttribute::DontEnum; - } - - if (value.isCell() && value.isCallable()) { - attributes |= JSC::PropertyAttribute::Function; - } - - defaultObject->putDirect(vm, prop, value, attributes); - } - - return defaultObject; - }; - - JSValue defaultValue = getDefaultValue(); - if (needsPut) { - unsigned attributes = 0; - - if (defaultValue.isCell() && defaultValue.isCallable()) { - attributes |= JSC::PropertyAttribute::Function; - } - - this->putDirect(vm, WebCore::clientData(vm)->builtinNames().exportsPublicName(), defaultValue, attributes); - } - + // This goes off of the assumption that you only call this `evaluate` using a generator that explicity + // assigns the `default` export first. + JSValue defaultValue = arguments.at(0); + this->putDirect(vm, WebCore::clientData(vm)->builtinNames().exportsPublicName(), defaultValue, 0); this->hasEvaluated = true; RELEASE_AND_RETURN(throwScope, true); } @@ -556,10 +506,6 @@ void JSCommonJSModule::toSyntheticSource(JSC::JSGlobalObject* globalObject, auto& vm = globalObject->vm(); - // This exists to tell ImportMetaObject.ts that this is a CommonJS module. - exportNames.append(Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s))); - exportValues.append(jsNumber(0)); - // Bun's intepretation of the "__esModule" annotation: // // - If a "default" export does not exist OR the __esModule annotation is not present, then we @@ -820,10 +766,11 @@ void RequireResolveFunctionPrototype::finishCreation(JSC::VM& vm) bool JSCommonJSModule::evaluate( Zig::GlobalObject* globalObject, const WTF::String& key, - ResolvedSource source) + ResolvedSource source, + bool isBuiltIn) { auto& vm = globalObject->vm(); - auto sourceProvider = Zig::SourceProvider::create(jsCast<Zig::GlobalObject*>(globalObject), source, JSC::SourceProviderSourceType::Program); + auto sourceProvider = Zig::SourceProvider::create(jsCast<Zig::GlobalObject*>(globalObject), source, JSC::SourceProviderSourceType::Program, isBuiltIn); this->ignoreESModuleAnnotation = source.tag == ResolvedSourceTagPackageJSONTypeModule; JSC::SourceCode rawInputSource( WTFMove(sourceProvider)); @@ -854,7 +801,8 @@ bool JSCommonJSModule::evaluate( std::optional<JSC::SourceCode> createCommonJSModule( Zig::GlobalObject* globalObject, - ResolvedSource source) + ResolvedSource source, + bool isBuiltIn) { JSCommonJSModule* moduleObject; WTF::String sourceURL = toStringCopy(source.source_url); @@ -862,7 +810,7 @@ std::optional<JSC::SourceCode> createCommonJSModule( JSValue specifierValue = Bun::toJS(globalObject, source.specifier); JSValue entry = globalObject->requireMap()->get(globalObject, specifierValue); - auto sourceProvider = Zig::SourceProvider::create(jsCast<Zig::GlobalObject*>(globalObject), source, JSC::SourceProviderSourceType::Program); + auto sourceProvider = Zig::SourceProvider::create(jsCast<Zig::GlobalObject*>(globalObject), source, JSC::SourceProviderSourceType::Program, isBuiltIn); bool ignoreESModuleAnnotation = source.tag == ResolvedSourceTagPackageJSONTypeModule; SourceOrigin sourceOrigin = sourceProvider->sourceOrigin(); diff --git a/src/bun.js/bindings/CommonJSModuleRecord.h b/src/bun.js/bindings/CommonJSModuleRecord.h index 20941f454..e38d2e083 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.h +++ b/src/bun.js/bindings/CommonJSModuleRecord.h @@ -1,3 +1,4 @@ +#pragma once #include "root.h" #include "headers-handwritten.h" @@ -22,7 +23,7 @@ public: static constexpr unsigned StructureFlags = Base::StructureFlags | JSC::OverridesPut; mutable JSC::WriteBarrier<JSC::JSString> m_id; - mutable JSC::WriteBarrier<JSC::JSString> m_filename; + mutable JSC::WriteBarrier<JSC::Unknown> m_filename; mutable JSC::WriteBarrier<JSC::JSString> m_dirname; mutable JSC::WriteBarrier<Unknown> m_paths; mutable JSC::WriteBarrier<JSC::JSSourceCode> sourceCode; @@ -32,18 +33,22 @@ public: ~JSCommonJSModule(); void finishCreation(JSC::VM& vm, - JSC::JSString* id, JSC::JSString* filename, + JSC::JSString* id, JSValue filename, JSC::JSString* dirname, JSC::JSSourceCode* sourceCode); static JSC::Structure* createStructure(JSC::JSGlobalObject* globalObject); - bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& sourceURL, ResolvedSource resolvedSource); + bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& sourceURL, ResolvedSource resolvedSource, bool isBuiltIn); + inline bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& sourceURL, ResolvedSource resolvedSource) + { + return evaluate(globalObject, sourceURL, resolvedSource, false); + } bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& key, const SyntheticSourceProvider::SyntheticSourceGenerator& generator); bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& key, JSSourceCode* sourceCode); static JSCommonJSModule* create(JSC::VM& vm, JSC::Structure* structure, JSC::JSString* id, - JSC::JSString* filename, + JSValue filename, JSC::JSString* dirname, JSC::JSSourceCode* sourceCode); static JSCommonJSModule* create( @@ -96,7 +101,15 @@ JSC::Structure* createCommonJSModuleStructure( std::optional<JSC::SourceCode> createCommonJSModule( Zig::GlobalObject* globalObject, - ResolvedSource source); + ResolvedSource source, + bool isBuiltIn); + +inline std::optional<JSC::SourceCode> createCommonJSModule( + Zig::GlobalObject* globalObject, + ResolvedSource source) +{ + return createCommonJSModule(globalObject, source, false); +} class RequireResolveFunctionPrototype final : public JSC::JSNonFinalObject { public: diff --git a/src/bun.js/bindings/InternalModuleRegistry.cpp b/src/bun.js/bindings/InternalModuleRegistry.cpp new file mode 100644 index 000000000..552e9fbfe --- /dev/null +++ b/src/bun.js/bindings/InternalModuleRegistry.cpp @@ -0,0 +1,142 @@ +#include "InternalModuleRegistry.h" + +#include "ZigGlobalObject.h" +#include "JavaScriptCore/BuiltinUtils.h" +#include "JavaScriptCore/JSFunction.h" +#include "JavaScriptCore/LazyProperty.h" +#include "JavaScriptCore/LazyPropertyInlines.h" +#include "JavaScriptCore/VMTrapsInlines.h" +#include "JavaScriptCore/JSModuleLoader.h" + +#include "InternalModuleRegistryConstants.h" + +namespace Bun { + +// The `INTERNAL_MODULE_REGISTRY_GENERATE` macro handles inlining code to compile and run a +// JS builtin that acts as a module. In debug mode, we use a different implementation that reads +// from the developer's filesystem. This allows reloading code without recompiling bindings. + +#define INTERNAL_MODULE_REGISTRY_GENERATE_(globalObject, vm, SOURCE, moduleName) \ + auto throwScope = DECLARE_THROW_SCOPE(vm); \ + \ + SourceCode source = JSC::makeSource(SOURCE, SourceOrigin(WTF::URL("builtin://" #moduleName ".js"_s)), #moduleName ".js"_s); \ + \ + JSFunction* func \ + = JSFunction::create( \ + vm, \ + createBuiltinExecutable( \ + vm, source, \ + Identifier(), \ + ImplementationVisibility::Public, \ + ConstructorKind::None, \ + ConstructAbility::CannotConstruct) \ + ->link(vm, nullptr, source), \ + static_cast<JSC::JSGlobalObject*>(globalObject)); \ + \ + JSC::MarkedArgumentBuffer argList; \ + \ + JSValue result = JSC::call( \ + globalObject, \ + func, \ + JSC::getCallData(func), \ + globalObject, JSC::MarkedArgumentBuffer()); \ + \ + RETURN_IF_EXCEPTION(throwScope, {}); \ + ASSERT_INTERNAL_MODULE(result, moduleName); \ + return result; + +#if BUN_DEBUG +#include "../../src/js/out/DebugPath.h" +#define ASSERT_INTERNAL_MODULE(result, moduleName) \ + if (!result || !result.isCell() || !jsDynamicCast<JSObject*>(result)) { \ + printf("Expected \"%s\" to export a JSObject. Bun is going to crash.", moduleName.utf8().data()); \ + } +JSValue initializeInternalModuleFromDisk( + JSGlobalObject* globalObject, + VM& vm, + WTF::String moduleName, + WTF::String fileBase, + WTF::String fallback) +{ + WTF::String file = makeString(BUN_DYNAMIC_JS_LOAD_PATH, "modules_dev/"_s, fileBase); + if (auto contents = WTF::FileSystemImpl::readEntireFile(file)) { + auto string = WTF::String::fromUTF8(contents.value()); + INTERNAL_MODULE_REGISTRY_GENERATE_(globalObject, vm, string, moduleName); + } else { + printf("bun-debug failed to load bundled version of \"%s\" at \"%s\" (was it deleted?)\n" + "Please run `make js` to rebundle these builtins.\n", + moduleName.utf8().data(), file.utf8().data()); + // Fallback to embedded source + INTERNAL_MODULE_REGISTRY_GENERATE_(globalObject, vm, fallback, moduleName); + } +} +#define INTERNAL_MODULE_REGISTRY_GENERATE(globalObject, vm, moduleId, filename, SOURCE) \ + return initializeInternalModuleFromDisk(globalObject, vm, moduleId, filename, SOURCE) +#else + +#define ASSERT_INTERNAL_MODULE(result, moduleName) \ + { \ + } +#define INTERNAL_MODULE_REGISTRY_GENERATE(globalObject, vm, moduleId, filename, SOURCE) \ + INTERNAL_MODULE_REGISTRY_GENERATE_(globalObject, vm, SOURCE, moduleId) +#endif + +const ClassInfo InternalModuleRegistry::s_info = { "InternalModuleRegistry"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(InternalModuleRegistry) }; + +InternalModuleRegistry::InternalModuleRegistry(VM& vm, Structure* structure) + : Base(vm, structure) +{ +} + +template<typename Visitor> +void InternalModuleRegistry::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ + auto* thisObject = jsCast<InternalModuleRegistry*>(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); +} + +DEFINE_VISIT_CHILDREN_WITH_MODIFIER(JS_EXPORT_PRIVATE, InternalModuleRegistry); + +InternalModuleRegistry* InternalModuleRegistry::create(VM& vm, Structure* structure) +{ + InternalModuleRegistry* registry = new (NotNull, allocateCell<InternalModuleRegistry>(vm)) InternalModuleRegistry(vm, structure); + for (uint8_t i = 0; i < BUN_INTERNAL_MODULE_COUNT; i++) { + registry->internalField(static_cast<Field>(i)) + .set(vm, registry, jsUndefined()); + } + return registry; +} + +Structure* InternalModuleRegistry::createStructure(VM& vm, JSGlobalObject* globalObject) +{ + return Structure::create(vm, globalObject, jsNull(), TypeInfo(InternalFieldTupleType, StructureFlags), info(), 0, 48); +} + +JSValue InternalModuleRegistry::requireId(JSGlobalObject* globalObject, VM& vm, Field id) +{ + auto value = internalField(id).get(); + if (!value || value.isUndefined()) { + value = createInternalModuleById(globalObject, vm, id); + internalField(id).set(vm, this, value); + } + return value; +} + +#include "../../../src/js/out/InternalModuleRegistry+createInternalModuleById.h" + +// This is called like @getInternalField(@internalModuleRegistry, 1) ?? @createInternalModuleById(1) +// so we want to write it to the internal field when loaded. +JSC_DEFINE_HOST_FUNCTION(InternalModuleRegistry::jsCreateInternalModuleById, (JSGlobalObject * lexicalGlobalObject, CallFrame* callframe)) +{ + auto id = callframe->argument(0).toUInt32(lexicalGlobalObject); + auto registry = static_cast<Zig::GlobalObject*>(lexicalGlobalObject)->internalModuleRegistry(); + auto module = registry->createInternalModuleById(lexicalGlobalObject, lexicalGlobalObject->vm(), static_cast<Field>(id)); + registry->internalField(static_cast<Field>(id)).set(lexicalGlobalObject->vm(), registry, module); + return JSValue::encode(module); +} + +} // namespace Bun + +#undef INTERNAL_MODULE_REGISTRY_GENERATE_ +#undef INTERNAL_MODULE_REGISTRY_GENERATE diff --git a/src/bun.js/bindings/InternalModuleRegistry.h b/src/bun.js/bindings/InternalModuleRegistry.h new file mode 100644 index 000000000..d14625e00 --- /dev/null +++ b/src/bun.js/bindings/InternalModuleRegistry.h @@ -0,0 +1,59 @@ +#pragma once +#include "root.h" +#include "JavaScriptCore/JSInternalFieldObjectImpl.h" +#include "JavaScriptCore/JSInternalFieldObjectImplInlines.h" +#include "BunClientData.h" +#include "../../../src/js/out/InternalModuleRegistry+numberOfModules.h" + +namespace Bun { +using namespace JSC; + +// Internal module registry is an array of lazily initialized "modules". Module IDs are generated +// pre-build by `make js` and inlined into JS code and the C++ enum (InternalModuleRegistry::Field) +// This allows modules depending on each other to skip the module resolver. +// +// Modules come from two sources: +// - some are written in JS (src/js, there is a readme file that explain those files more. +// - others are native code (src/bun.js/modules), see _NativeModule.h in there. +class InternalModuleRegistry : public JSInternalFieldObjectImpl<BUN_INTERNAL_MODULE_COUNT> { +protected: + JS_EXPORT_PRIVATE InternalModuleRegistry(VM&, Structure*); + DECLARE_DEFAULT_FINISH_CREATION; + DECLARE_VISIT_CHILDREN_WITH_MODIFIER(JS_EXPORT_PRIVATE); + +public: + using Base = JSInternalFieldObjectImpl<BUN_INTERNAL_MODULE_COUNT>; + + DECLARE_EXPORT_INFO; + + enum Field : uint8_t { +#include "../../../src/js/out/InternalModuleRegistry+enum.h" + }; + const WriteBarrier<Unknown>& internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); } + WriteBarrier<Unknown>& internalField(Field field) { return Base::internalField(static_cast<uint32_t>(field)); } + + template<typename, SubspaceAccess mode> + static GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl<InternalModuleRegistry, WebCore::UseCustomHeapCellType::No>( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForInternalModuleRegistry.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForInternalModuleRegistry = std::forward<decltype(space)>(space); }, + [](auto& spaces) { return spaces.m_subspaceForInternalModuleRegistry.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForInternalModuleRegistry = std::forward<decltype(space)>(space); }); + } + + static InternalModuleRegistry* create(VM& vm, Structure* structure); + static Structure* createStructure(VM& vm, JSGlobalObject* globalObject); + + JSValue requireId(JSGlobalObject* globalObject, VM& vm, Field id); + + static JSC_DECLARE_HOST_FUNCTION(jsCreateInternalModuleById); + +protected: + JSValue createInternalModuleById(JSGlobalObject* globalObject, VM& vm, Field id); +}; + +} // namespace Bun diff --git a/src/bun.js/bindings/JSMockFunction.cpp b/src/bun.js/bindings/JSMockFunction.cpp index 4a9b936b4..a8bac7c56 100644 --- a/src/bun.js/bindings/JSMockFunction.cpp +++ b/src/bun.js/bindings/JSMockFunction.cpp @@ -1435,19 +1435,3 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionWithImplementation, (JSC::JSGlobalObject return JSC::JSValue::encode(jsUndefined()); } } // namespace Bun - -namespace JSC { - -template<unsigned passedNumberOfInternalFields> -template<typename Visitor> -void JSInternalFieldObjectImpl<passedNumberOfInternalFields>::visitChildrenImpl(JSCell* cell, Visitor& visitor) -{ - auto* thisObject = jsCast<JSInternalFieldObjectImpl*>(cell); - ASSERT_GC_OBJECT_INHERITS(thisObject, info()); - Base::visitChildren(thisObject, visitor); - visitor.appendValues(thisObject->m_internalFields, numberOfInternalFields); -} - -DEFINE_VISIT_CHILDREN_WITH_MODIFIER(template<unsigned passedNumberOfInternalFields>, JSInternalFieldObjectImpl<passedNumberOfInternalFields>); - -} // namespace JSC diff --git a/src/bun.js/bindings/JSSink+custom.h b/src/bun.js/bindings/JSSink+custom.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/bun.js/bindings/JSSink+custom.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/bun.js/bindings/ModuleLoader.cpp b/src/bun.js/bindings/ModuleLoader.cpp index 20c2be2a2..2e4dfa88e 100644 --- a/src/bun.js/bindings/ModuleLoader.cpp +++ b/src/bun.js/bindings/ModuleLoader.cpp @@ -27,15 +27,6 @@ #include "EventEmitter.h" #include "JSEventEmitter.h" -#include "../modules/BufferModule.h" -#include "../modules/EventsModule.h" -#include "../modules/ProcessModule.h" -#include "../modules/StringDecoderModule.h" -#include "../modules/ObjectModule.h" -#include "../modules/NodeModuleModule.h" -#include "../modules/TTYModule.h" -#include "../modules/ConstantsModule.h" -#include "node_util_types.h" #include "CommonJSModuleRecord.h" #include <JavaScriptCore/JSModuleLoader.h> #include <JavaScriptCore/Completion.h> @@ -43,7 +34,13 @@ #include <JavaScriptCore/JSMap.h> #include <JavaScriptCore/JSMapInlines.h> +#include "../modules/_NativeModule.h" +#include "../../js/out/NativeModuleImpl.h" + +#include "../modules/ObjectModule.h" + namespace Bun { +using namespace JSC; using namespace Zig; using namespace WebCore; @@ -67,7 +64,38 @@ static JSC::JSInternalPromise* resolvedInternalPromise(JSC::JSGlobalObject* glob return promise; } -using namespace JSC; +// Converts an object from InternalModuleRegistry into { ...obj, default: obj } +JSC::SyntheticSourceProvider::SyntheticSourceGenerator +generateInternalModuleSourceCode(JSC::JSGlobalObject* globalObject, JSC::JSObject* object) +{ + return [object](JSC::JSGlobalObject* lexicalGlobalObject, + JSC::Identifier moduleKey, + Vector<JSC::Identifier, 4>& exportNames, + JSC::MarkedArgumentBuffer& exportValues) -> void { + JSC::VM& vm = lexicalGlobalObject->vm(); + GlobalObject* globalObject = reinterpret_cast<GlobalObject*>(lexicalGlobalObject); + JSC::EnsureStillAliveScope stillAlive(object); + + auto throwScope = DECLARE_THROW_SCOPE(vm); + + PropertyNameArray properties(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude); + object->getPropertyNames(globalObject, properties, DontEnumPropertiesMode::Exclude); + + RETURN_IF_EXCEPTION(throwScope, {}); + + auto len = properties.size() + 1; + exportNames.reserveCapacity(len); + exportValues.ensureCapacity(len); + + exportNames.append(vm.propertyNames->defaultKeyword); + exportValues.append(object); + + for (auto& entry : properties) { + exportNames.append(entry); + exportValues.append(object->get(globalObject, entry)); + } + }; +} static OnLoadResult handleOnLoadObjectResult(Zig::GlobalObject* globalObject, JSC::JSObject* object) { @@ -389,45 +417,35 @@ JSValue fetchCommonJSModule( return JSValue(); } - switch (res->result.value.tag) { - case SyntheticModuleType::Module: { - target->evaluate(globalObject, Bun::toWTFString(*specifier), generateNodeModuleModule); - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, target); - } + auto tag = res->result.value.tag; + switch (tag) { +// Generated native module cases +#define CASE(str, name) \ + case SyntheticModuleType::name: { \ + target->evaluate(globalObject, Bun::toWTFString(*specifier), generateNativeModule_##name); \ + RETURN_IF_EXCEPTION(scope, {}); \ + RELEASE_AND_RETURN(scope, target); \ + } + BUN_FOREACH_NATIVE_MODULE(CASE) +#undef CASE - case SyntheticModuleType::Buffer: { - target->evaluate(globalObject, Bun::toWTFString(*specifier), generateBufferSourceCode); - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, target); - } - case SyntheticModuleType::TTY: { - target->evaluate(globalObject, Bun::toWTFString(*specifier), generateTTYSourceCode); - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, target); - } - case SyntheticModuleType::NodeUtilTypes: { - target->evaluate(globalObject, Bun::toWTFString(*specifier), Bun::generateNodeUtilTypesSourceCode); - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, target); - } - case SyntheticModuleType::Process: { - target->evaluate(globalObject, Bun::toWTFString(*specifier), generateProcessSourceCode); - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, target); - } - case SyntheticModuleType::Events: { - target->evaluate(globalObject, Bun::toWTFString(*specifier), generateEventsSourceCode); - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, target); - } - case SyntheticModuleType::StringDecoder: { - target->evaluate(globalObject, Bun::toWTFString(*specifier), generateStringDecoderSourceCode); - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, target); + case SyntheticModuleType::ESM: { + RELEASE_AND_RETURN(scope, jsNumber(-1)); } + default: { - RELEASE_AND_RETURN(scope, jsNumber(-1)); + if (tag & SyntheticModuleType::InternalModuleRegistryFlag) { + constexpr auto mask = (SyntheticModuleType::InternalModuleRegistryFlag - 1); + target->putDirect( + vm, + builtinNames.exportsPublicName(), + globalObject->internalModuleRegistry()->requireId(globalObject, vm, static_cast<InternalModuleRegistry::Field>(tag & mask)), + JSC::PropertyAttribute::ReadOnly | 0); + RETURN_IF_EXCEPTION(scope, {}); + RELEASE_AND_RETURN(scope, target); + } else { + RELEASE_AND_RETURN(scope, jsNumber(-1)); + } } } } @@ -496,7 +514,7 @@ JSValue fetchCommonJSModule( } template<bool allowPromise> -static JSValue fetchSourceCode( +static JSValue fetchESMSourceCode( Zig::GlobalObject* globalObject, ErrorableResolvedSource* res, BunString* specifier, @@ -555,67 +573,32 @@ static JSValue fetchSourceCode( auto moduleKey = Bun::toWTFString(*specifier); - switch (res->result.value.tag) { - case SyntheticModuleType::Module: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(generateNodeModuleModule, - JSC::SourceOrigin(), WTFMove(moduleKey))); - - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); - } - - case SyntheticModuleType::Buffer: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(generateBufferSourceCode, - JSC::SourceOrigin(), WTFMove(moduleKey))); - - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); - } - case SyntheticModuleType::TTY: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(generateTTYSourceCode, - JSC::SourceOrigin(), WTFMove(moduleKey))); - - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); - } - case SyntheticModuleType::NodeUtilTypes: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(Bun::generateNodeUtilTypesSourceCode, - JSC::SourceOrigin(), WTFMove(moduleKey))); - - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); - } - case SyntheticModuleType::Process: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(generateProcessSourceCode, - JSC::SourceOrigin(), WTFMove(moduleKey))); - - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); - } - case SyntheticModuleType::Events: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(generateEventsSourceCode, - JSC::SourceOrigin(), WTFMove(moduleKey))); - - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); + auto tag = res->result.value.tag; + switch (tag) { + case SyntheticModuleType::ESM: { + auto&& provider = Zig::SourceProvider::create(globalObject, res->result.value, JSC::SourceProviderSourceType::Module, true); + return rejectOrResolve(JSSourceCode::create(vm, JSC::SourceCode(provider))); } - case SyntheticModuleType::StringDecoder: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(generateStringDecoderSourceCode, - JSC::SourceOrigin(), WTFMove(moduleKey))); - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); - } - case SyntheticModuleType::Constants: { - auto source = JSC::SourceCode( - JSC::SyntheticSourceProvider::create(generateConstantsSourceCode, - JSC::SourceOrigin(), WTFMove(moduleKey))); +#define CASE(str, name) \ + case (SyntheticModuleType::name): { \ + auto source = JSC::SourceCode(JSC::SyntheticSourceProvider::create(generateNativeModule_##name, JSC::SourceOrigin(), WTFMove(moduleKey))); \ + return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); \ + } + BUN_FOREACH_NATIVE_MODULE(CASE) +#undef CASE - return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); - } + // CommonJS modules from src/js/* default: { - auto&& provider = Zig::SourceProvider::create(globalObject, res->result.value, JSC::SourceProviderSourceType::Module, true); - return rejectOrResolve(JSC::JSSourceCode::create(vm, JSC::SourceCode(provider))); + if (tag & SyntheticModuleType::InternalModuleRegistryFlag) { + constexpr auto mask = (SyntheticModuleType::InternalModuleRegistryFlag - 1); + auto* internalModule = jsCast<JSObject*>(globalObject->internalModuleRegistry()->requireId(globalObject, vm, static_cast<InternalModuleRegistry::Field>(tag & mask))); + auto source = JSC::SourceCode(JSC::SyntheticSourceProvider::create(generateInternalModuleSourceCode(globalObject, internalModule), JSC::SourceOrigin(), WTFMove(moduleKey))); + return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source))); + } else { + auto&& provider = Zig::SourceProvider::create(globalObject, res->result.value, JSC::SourceProviderSourceType::Module, true); + return rejectOrResolve(JSC::JSSourceCode::create(vm, JSC::SourceCode(provider))); + } } } } @@ -715,36 +698,21 @@ extern "C" JSC::EncodedJSValue jsFunctionOnLoadObjectResultReject(JSC::JSGlobalO return JSValue::encode(reason); } -JSValue fetchSourceCodeSync( +JSValue fetchESMSourceCodeSync( Zig::GlobalObject* globalObject, ErrorableResolvedSource* res, BunString* specifier, BunString* referrer) { - return fetchSourceCode<false>(globalObject, res, specifier, referrer); + return fetchESMSourceCode<false>(globalObject, res, specifier, referrer); } -JSValue fetchSourceCodeAsync( +JSValue fetchESMSourceCodeAsync( Zig::GlobalObject* globalObject, ErrorableResolvedSource* res, BunString* specifier, BunString* referrer) { - return fetchSourceCode<true>(globalObject, res, specifier, referrer); + return fetchESMSourceCode<true>(globalObject, res, specifier, referrer); } } -namespace JSC { - -template<unsigned passedNumberOfInternalFields> -template<typename Visitor> -void JSInternalFieldObjectImpl<passedNumberOfInternalFields>::visitChildrenImpl(JSCell* cell, Visitor& visitor) -{ - auto* thisObject = jsCast<JSInternalFieldObjectImpl*>(cell); - ASSERT_GC_OBJECT_INHERITS(thisObject, info()); - Base::visitChildren(thisObject, visitor); - visitor.appendValues(thisObject->m_internalFields, numberOfInternalFields); -} - -DEFINE_VISIT_CHILDREN_WITH_MODIFIER(template<unsigned passedNumberOfInternalFields>, JSInternalFieldObjectImpl<passedNumberOfInternalFields>); - -} // namespace JSC diff --git a/src/bun.js/bindings/ModuleLoader.h b/src/bun.js/bindings/ModuleLoader.h index 6eb04bf40..ee726ebcf 100644 --- a/src/bun.js/bindings/ModuleLoader.h +++ b/src/bun.js/bindings/ModuleLoader.h @@ -81,13 +81,13 @@ public: }; OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::JSValue objectValue); -JSValue fetchSourceCodeSync( +JSValue fetchESMSourceCodeSync( Zig::GlobalObject* globalObject, ErrorableResolvedSource* res, BunString* specifier, BunString* referrer); -JSValue fetchSourceCodeAsync( +JSValue fetchESMSourceCodeAsync( Zig::GlobalObject* globalObject, ErrorableResolvedSource* res, BunString* specifier, @@ -100,4 +100,4 @@ JSValue fetchCommonJSModule( BunString* specifier, BunString* referrer); -} // namespace Bun
\ No newline at end of file +} // namespace Bun diff --git a/src/bun.js/bindings/Process.lut.h b/src/bun.js/bindings/Process.lut.h index 3f2d9255d..aa805b6cd 100644 --- a/src/bun.js/bindings/Process.lut.h +++ b/src/bun.js/bindings/Process.lut.h @@ -146,69 +146,68 @@ static const struct CompactHashIndex processObjectTableIndex[143] = { }; static const struct HashTableValue processObjectTableValues[62] = { - { "abort"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionAbort, 1 } }, - { "allowedNodeEnvironmentFlags"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, Process_stubEmptySet } }, - { "arch"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructArch } }, - { "argv"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructArgv } }, - { "argv0"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructArgv0 } }, - { "assert"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionAssert, 1 } }, - { "binding"_s, ((static_cast<unsigned>(PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, processObjectBindingCodeGenerator, 1 } }, - { "browser"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructBrowser } }, - { "chdir"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionChdir, 1 } }, - { "config"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructProcessConfigObject } }, - { "cpuUsage"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionCpuUsage, 1 } }, - { "cwd"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionCwd, 1 } }, - { "debugPort"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processDebugPort, setProcessDebugPort } }, - { "dlopen"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionDlopen, 1 } }, - { "emitWarning"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_emitWarning, 1 } }, - { "env"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructEnv } }, - { "execArgv"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructExecArgv } }, - { "execPath"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructExecPath } }, - { "exit"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionExit, 1 } }, - { "exitCode"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processExitCode, setProcessExitCode } }, - { "features"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructFeatures } }, - { "getActiveResourcesInfo"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubFunctionReturningArray, 0 } }, - { "getegid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetegid, 0 } }, - { "geteuid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongeteuid, 0 } }, - { "getgid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetgid, 0 } }, - { "getgroups"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetgroups, 0 } }, - { "getuid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetuid, 0 } }, - { "hrtime"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructProcessHrtimeObject } }, - { "isBun"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructIsBun } }, - { "kill"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionKill, 2 } }, - { "mainModule"_s, ((static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::Builtin|PropertyAttribute::Accessor|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, processObjectMainModuleCodeGenerator, 0 } }, - { "memoryUsage"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructMemoryUsage } }, - { "moduleLoadList"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, Process_stubEmptyArray } }, - { "nextTick"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionNextTick, 1 } }, - { "openStdin"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionOpenStdin, 0 } }, - { "pid"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPid } }, - { "platform"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPlatform } }, - { "ppid"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPpid } }, - { "reallyExit"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionReallyExit, 1 } }, - { "release"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructProcessReleaseObject } }, - { "revision"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructRevision } }, - { "setSourceMapsEnabled"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 1 } }, - { "stderr"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructStderr } }, - { "stdin"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructStdin } }, - { "stdout"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructStdout } }, - { "title"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processTitle, setProcessTitle } }, - { "umask"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionUmask, 1 } }, - { "uptime"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionUptime, 1 } }, - { "version"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructVersion } }, - { "versions"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructVersions } }, - { "_debugEnd"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, - { "_debugProcess"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, - { "_fatalException"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 1 } }, - { "_getActiveRequests"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubFunctionReturningArray, 0 } }, - { "_getActiveHandles"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubFunctionReturningArray, 0 } }, - { "_linkedBinding"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, - { "_preload_modules"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, Process_stubEmptyArray } }, - { "_rawDebug"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, - { "_startProfilerIdleNotifier"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, - { "_stopProfilerIdleNotifier"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, - { "_tickCallback"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, - { "_kill"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionReallyKill, 2 } }, + { "abort"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionAbort, 1 } }, + { "allowedNodeEnvironmentFlags"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, Process_stubEmptySet } }, + { "arch"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructArch } }, + { "argv"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructArgv } }, + { "argv0"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructArgv0 } }, + { "assert"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionAssert, 1 } }, + { "binding"_s, ((static_cast<unsigned>(PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, processObjectBindingCodeGenerator, 1 } }, + { "browser"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructBrowser } }, + { "chdir"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionChdir, 1 } }, + { "config"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructProcessConfigObject } }, + { "cpuUsage"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionCpuUsage, 1 } }, + { "cwd"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionCwd, 1 } }, + { "debugPort"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processDebugPort, setProcessDebugPort } }, + { "dlopen"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionDlopen, 1 } }, + { "emitWarning"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_emitWarning, 1 } }, + { "env"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructEnv } }, + { "execArgv"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructExecArgv } }, + { "execPath"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructExecPath } }, + { "exit"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionExit, 1 } }, + { "exitCode"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processExitCode, setProcessExitCode } }, + { "features"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructFeatures } }, + { "getActiveResourcesInfo"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubFunctionReturningArray, 0 } }, + { "getegid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetegid, 0 } }, + { "geteuid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongeteuid, 0 } }, + { "getgid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetgid, 0 } }, + { "getgroups"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetgroups, 0 } }, + { "getuid"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functiongetuid, 0 } }, + { "hrtime"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructProcessHrtimeObject } }, + { "isBun"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructIsBun } }, + { "kill"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionKill, 2 } }, + { "mainModule"_s, ((static_cast<unsigned>(PropertyAttribute::ReadOnly | PropertyAttribute::Builtin | PropertyAttribute::Accessor | PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, processObjectMainModuleCodeGenerator, 0 } }, + { "memoryUsage"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructMemoryUsage } }, + { "moduleLoadList"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, Process_stubEmptyArray } }, + { "nextTick"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionNextTick, 1 } }, + { "openStdin"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionOpenStdin, 0 } }, + { "pid"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPid } }, + { "platform"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPlatform } }, + { "ppid"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPpid } }, + { "reallyExit"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionReallyExit, 1 } }, + { "release"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructProcessReleaseObject } }, + { "revision"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructRevision } }, + { "setSourceMapsEnabled"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 1 } }, + { "stderr"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructStderr } }, + { "stdin"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructStdin } }, + { "stdout"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructStdout } }, + { "title"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processTitle, setProcessTitle } }, + { "umask"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionUmask, 1 } }, + { "uptime"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionUptime, 1 } }, + { "version"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructVersion } }, + { "versions"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructVersions } }, + { "_debugEnd"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, + { "_debugProcess"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, + { "_fatalException"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 1 } }, + { "_getActiveRequests"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubFunctionReturningArray, 0 } }, + { "_getActiveHandles"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubFunctionReturningArray, 0 } }, + { "_linkedBinding"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, + { "_preload_modules"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, Process_stubEmptyArray } }, + { "_rawDebug"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, + { "_startProfilerIdleNotifier"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, + { "_stopProfilerIdleNotifier"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, + { "_tickCallback"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_stubEmptyFunction, 0 } }, + { "_kill"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionReallyKill, 2 } }, }; -static const struct HashTable processObjectTable = - { 62, 127, true, nullptr, processObjectTableValues, processObjectTableIndex }; +static const struct HashTable processObjectTable = { 62, 127, true, nullptr, processObjectTableValues, processObjectTableIndex }; diff --git a/src/bun.js/bindings/ProcessBindingConstants.cpp b/src/bun.js/bindings/ProcessBindingConstants.cpp new file mode 100644 index 000000000..36a4a7f96 --- /dev/null +++ b/src/bun.js/bindings/ProcessBindingConstants.cpp @@ -0,0 +1,1124 @@ +// Modelled off of https://github.com/nodejs/node/blob/main/src/node_constants.cc +// Note that if you change any of this code, you probably also have to change NodeConstantsModule.h +#include "ProcessBindingConstants.h" +#include "JavaScriptCore/ObjectConstructor.h" + +// These headers may not all be needed, but they are the ones node references. +// Most of the constants are defined with #if checks on existing #defines, instead of platform-checks +#include <openssl/ec.h> +#include <openssl/ssl.h> +#include <zlib.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <cerrno> +#include <csignal> +#include <limits> + +#ifndef OPENSSL_NO_ENGINE +#include <openssl/engine.h> +#endif + +#if !defined(_MSC_VER) +#include <unistd.h> +#endif + +#if defined(_WIN32) +#include <io.h> // _S_IREAD _S_IWRITE +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif // S_IRUSR +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif // S_IWUSR +#else +#include <dlfcn.h> +#endif + +namespace Bun { +using namespace JSC; + +static JSValue processBindingConstantsGetOs(VM& vm, JSObject* bindingObject) +{ + auto globalObject = bindingObject->globalObject(); + auto osObj = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 1); + auto dlopenObj = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 1); + auto errnoObj = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 1); + auto signalsObj = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 1); + auto priorityObj = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 1); + osObj->putDirect(vm, Identifier::fromString(vm, "UV_UDP_REUSEADDR"_s), jsNumber(4)); + osObj->putDirect(vm, Identifier::fromString(vm, "dlopen"_s), dlopenObj); + osObj->putDirect(vm, Identifier::fromString(vm, "errno"_s), errnoObj); + osObj->putDirect(vm, Identifier::fromString(vm, "signals"_s), signalsObj); + osObj->putDirect(vm, Identifier::fromString(vm, "priority"_s), priorityObj); +#ifdef E2BIG + errnoObj->putDirect(vm, Identifier::fromString(vm, "E2BIG"_s), jsNumber(E2BIG)); +#endif +#ifdef EACCES + errnoObj->putDirect(vm, Identifier::fromString(vm, "EACCES"_s), jsNumber(EACCES)); +#endif +#ifdef EADDRINUSE + errnoObj->putDirect(vm, Identifier::fromString(vm, "EADDRINUSE"_s), jsNumber(EADDRINUSE)); +#endif +#ifdef EADDRNOTAVAIL + errnoObj->putDirect(vm, Identifier::fromString(vm, "EADDRNOTAVAIL"_s), jsNumber(EADDRNOTAVAIL)); +#endif +#ifdef EAFNOSUPPORT + errnoObj->putDirect(vm, Identifier::fromString(vm, "EAFNOSUPPORT"_s), jsNumber(EAFNOSUPPORT)); +#endif +#ifdef EAGAIN + errnoObj->putDirect(vm, Identifier::fromString(vm, "EAGAIN"_s), jsNumber(EAGAIN)); +#endif +#ifdef EALREADY + errnoObj->putDirect(vm, Identifier::fromString(vm, "EALREADY"_s), jsNumber(EALREADY)); +#endif +#ifdef EBADF + errnoObj->putDirect(vm, Identifier::fromString(vm, "EBADF"_s), jsNumber(EBADF)); +#endif +#ifdef EBADMSG + errnoObj->putDirect(vm, Identifier::fromString(vm, "EBADMSG"_s), jsNumber(EBADMSG)); +#endif +#ifdef EBUSY + errnoObj->putDirect(vm, Identifier::fromString(vm, "EBUSY"_s), jsNumber(EBUSY)); +#endif +#ifdef ECANCELED + errnoObj->putDirect(vm, Identifier::fromString(vm, "ECANCELED"_s), jsNumber(ECANCELED)); +#endif +#ifdef ECHILD + errnoObj->putDirect(vm, Identifier::fromString(vm, "ECHILD"_s), jsNumber(ECHILD)); +#endif +#ifdef ECONNABORTED + errnoObj->putDirect(vm, Identifier::fromString(vm, "ECONNABORTED"_s), jsNumber(ECONNABORTED)); +#endif +#ifdef ECONNREFUSED + errnoObj->putDirect(vm, Identifier::fromString(vm, "ECONNREFUSED"_s), jsNumber(ECONNREFUSED)); +#endif +#ifdef ECONNRESET + errnoObj->putDirect(vm, Identifier::fromString(vm, "ECONNRESET"_s), jsNumber(ECONNRESET)); +#endif +#ifdef EDEADLK + errnoObj->putDirect(vm, Identifier::fromString(vm, "EDEADLK"_s), jsNumber(EDEADLK)); +#endif +#ifdef EDESTADDRREQ + errnoObj->putDirect(vm, Identifier::fromString(vm, "EDESTADDRREQ"_s), jsNumber(EDESTADDRREQ)); +#endif +#ifdef EDOM + errnoObj->putDirect(vm, Identifier::fromString(vm, "EDOM"_s), jsNumber(EDOM)); +#endif +#ifdef EDQUOT + errnoObj->putDirect(vm, Identifier::fromString(vm, "EDQUOT"_s), jsNumber(EDQUOT)); +#endif +#ifdef EEXIST + errnoObj->putDirect(vm, Identifier::fromString(vm, "EEXIST"_s), jsNumber(EEXIST)); +#endif +#ifdef EFAULT + errnoObj->putDirect(vm, Identifier::fromString(vm, "EFAULT"_s), jsNumber(EFAULT)); +#endif +#ifdef EFBIG + errnoObj->putDirect(vm, Identifier::fromString(vm, "EFBIG"_s), jsNumber(EFBIG)); +#endif +#ifdef EHOSTUNREACH + errnoObj->putDirect(vm, Identifier::fromString(vm, "EHOSTUNREACH"_s), jsNumber(EHOSTUNREACH)); +#endif +#ifdef EIDRM + errnoObj->putDirect(vm, Identifier::fromString(vm, "EIDRM"_s), jsNumber(EIDRM)); +#endif +#ifdef EILSEQ + errnoObj->putDirect(vm, Identifier::fromString(vm, "EILSEQ"_s), jsNumber(EILSEQ)); +#endif +#ifdef EINPROGRESS + errnoObj->putDirect(vm, Identifier::fromString(vm, "EINPROGRESS"_s), jsNumber(EINPROGRESS)); +#endif +#ifdef EINTR + errnoObj->putDirect(vm, Identifier::fromString(vm, "EINTR"_s), jsNumber(EINTR)); +#endif +#ifdef EINVAL + errnoObj->putDirect(vm, Identifier::fromString(vm, "EINVAL"_s), jsNumber(EINVAL)); +#endif +#ifdef EIO + errnoObj->putDirect(vm, Identifier::fromString(vm, "EIO"_s), jsNumber(EIO)); +#endif +#ifdef EISCONN + errnoObj->putDirect(vm, Identifier::fromString(vm, "EISCONN"_s), jsNumber(EISCONN)); +#endif +#ifdef EISDIR + errnoObj->putDirect(vm, Identifier::fromString(vm, "EISDIR"_s), jsNumber(EISDIR)); +#endif +#ifdef ELOOP + errnoObj->putDirect(vm, Identifier::fromString(vm, "ELOOP"_s), jsNumber(ELOOP)); +#endif +#ifdef EMFILE + errnoObj->putDirect(vm, Identifier::fromString(vm, "EMFILE"_s), jsNumber(EMFILE)); +#endif +#ifdef EMLINK + errnoObj->putDirect(vm, Identifier::fromString(vm, "EMLINK"_s), jsNumber(EMLINK)); +#endif +#ifdef EMSGSIZE + errnoObj->putDirect(vm, Identifier::fromString(vm, "EMSGSIZE"_s), jsNumber(EMSGSIZE)); +#endif +#ifdef EMULTIHOP + errnoObj->putDirect(vm, Identifier::fromString(vm, "EMULTIHOP"_s), jsNumber(EMULTIHOP)); +#endif +#ifdef ENAMETOOLONG + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENAMETOOLONG"_s), jsNumber(ENAMETOOLONG)); +#endif +#ifdef ENETDOWN + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENETDOWN"_s), jsNumber(ENETDOWN)); +#endif +#ifdef ENETRESET + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENETRESET"_s), jsNumber(ENETRESET)); +#endif +#ifdef ENETUNREACH + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENETUNREACH"_s), jsNumber(ENETUNREACH)); +#endif +#ifdef ENFILE + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENFILE"_s), jsNumber(ENFILE)); +#endif +#ifdef ENOBUFS + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOBUFS"_s), jsNumber(ENOBUFS)); +#endif +#ifdef ENODATA + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENODATA"_s), jsNumber(ENODATA)); +#endif +#ifdef ENODEV + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENODEV"_s), jsNumber(ENODEV)); +#endif +#ifdef ENOENT + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOENT"_s), jsNumber(ENOENT)); +#endif +#ifdef ENOEXEC + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOEXEC"_s), jsNumber(ENOEXEC)); +#endif +#ifdef ENOLCK + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOLCK"_s), jsNumber(ENOLCK)); +#endif +#ifdef ENOLINK + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOLINK"_s), jsNumber(ENOLINK)); +#endif +#ifdef ENOMEM + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOMEM"_s), jsNumber(ENOMEM)); +#endif +#ifdef ENOMSG + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOMSG"_s), jsNumber(ENOMSG)); +#endif +#ifdef ENOPROTOOPT + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOPROTOOPT"_s), jsNumber(ENOPROTOOPT)); +#endif +#ifdef ENOSPC + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOSPC"_s), jsNumber(ENOSPC)); +#endif +#ifdef ENOSR + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOSR"_s), jsNumber(ENOSR)); +#endif +#ifdef ENOSTR + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOSTR"_s), jsNumber(ENOSTR)); +#endif +#ifdef ENOSYS + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOSYS"_s), jsNumber(ENOSYS)); +#endif +#ifdef ENOTCONN + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOTCONN"_s), jsNumber(ENOTCONN)); +#endif +#ifdef ENOTDIR + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOTDIR"_s), jsNumber(ENOTDIR)); +#endif +#ifdef ENOTEMPTY + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOTEMPTY"_s), jsNumber(ENOTEMPTY)); +#endif +#ifdef ENOTSOCK + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOTSOCK"_s), jsNumber(ENOTSOCK)); +#endif +#ifdef ENOTSUP + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOTSUP"_s), jsNumber(ENOTSUP)); +#endif +#ifdef ENOTTY + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENOTTY"_s), jsNumber(ENOTTY)); +#endif +#ifdef ENXIO + errnoObj->putDirect(vm, Identifier::fromString(vm, "ENXIO"_s), jsNumber(ENXIO)); +#endif +#ifdef EOPNOTSUPP + errnoObj->putDirect(vm, Identifier::fromString(vm, "EOPNOTSUPP"_s), jsNumber(EOPNOTSUPP)); +#endif +#ifdef EOVERFLOW + errnoObj->putDirect(vm, Identifier::fromString(vm, "EOVERFLOW"_s), jsNumber(EOVERFLOW)); +#endif +#ifdef EPERM + errnoObj->putDirect(vm, Identifier::fromString(vm, "EPERM"_s), jsNumber(EPERM)); +#endif +#ifdef EPIPE + errnoObj->putDirect(vm, Identifier::fromString(vm, "EPIPE"_s), jsNumber(EPIPE)); +#endif +#ifdef EPROTO + errnoObj->putDirect(vm, Identifier::fromString(vm, "EPROTO"_s), jsNumber(EPROTO)); +#endif +#ifdef EPROTONOSUPPORT + errnoObj->putDirect(vm, Identifier::fromString(vm, "EPROTONOSUPPORT"_s), jsNumber(EPROTONOSUPPORT)); +#endif +#ifdef EPROTOTYPE + errnoObj->putDirect(vm, Identifier::fromString(vm, "EPROTOTYPE"_s), jsNumber(EPROTOTYPE)); +#endif +#ifdef ERANGE + errnoObj->putDirect(vm, Identifier::fromString(vm, "ERANGE"_s), jsNumber(ERANGE)); +#endif +#ifdef EROFS + errnoObj->putDirect(vm, Identifier::fromString(vm, "EROFS"_s), jsNumber(EROFS)); +#endif +#ifdef ESPIPE + errnoObj->putDirect(vm, Identifier::fromString(vm, "ESPIPE"_s), jsNumber(ESPIPE)); +#endif +#ifdef ESRCH + errnoObj->putDirect(vm, Identifier::fromString(vm, "ESRCH"_s), jsNumber(ESRCH)); +#endif +#ifdef ESTALE + errnoObj->putDirect(vm, Identifier::fromString(vm, "ESTALE"_s), jsNumber(ESTALE)); +#endif +#ifdef ETIME + errnoObj->putDirect(vm, Identifier::fromString(vm, "ETIME"_s), jsNumber(ETIME)); +#endif +#ifdef ETIMEDOUT + errnoObj->putDirect(vm, Identifier::fromString(vm, "ETIMEDOUT"_s), jsNumber(ETIMEDOUT)); +#endif +#ifdef ETXTBSY + errnoObj->putDirect(vm, Identifier::fromString(vm, "ETXTBSY"_s), jsNumber(ETXTBSY)); +#endif +#ifdef EWOULDBLOCK + errnoObj->putDirect(vm, Identifier::fromString(vm, "EWOULDBLOCK"_s), jsNumber(EWOULDBLOCK)); +#endif +#ifdef EXDEV + errnoObj->putDirect(vm, Identifier::fromString(vm, "EXDEV"_s), jsNumber(EXDEV)); +#endif +#ifdef WSAEINTR + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEINTR"_s), jsNumber(WSAEINTR)); +#endif +#ifdef WSAEBADF + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEBADF"_s), jsNumber(WSAEBADF)); +#endif +#ifdef WSAEACCES + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEACCES"_s), jsNumber(WSAEACCES)); +#endif +#ifdef WSAEFAULT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEFAULT"_s), jsNumber(WSAEFAULT)); +#endif +#ifdef WSAEINVAL + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEINVAL"_s), jsNumber(WSAEINVAL)); +#endif +#ifdef WSAEMFILE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEMFILE"_s), jsNumber(WSAEMFILE)); +#endif +#ifdef WSAEWOULDBLOCK + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEWOULDBLOCK"_s), jsNumber(WSAEWOULDBLOCK)); +#endif +#ifdef WSAEINPROGRESS + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEINPROGRESS"_s), jsNumber(WSAEINPROGRESS)); +#endif +#ifdef WSAEALREADY + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEALREADY"_s), jsNumber(WSAEALREADY)); +#endif +#ifdef WSAENOTSOCK + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENOTSOCK"_s), jsNumber(WSAENOTSOCK)); +#endif +#ifdef WSAEDESTADDRREQ + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEDESTADDRREQ"_s), jsNumber(WSAEDESTADDRREQ)); +#endif +#ifdef WSAEMSGSIZE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEMSGSIZE"_s), jsNumber(WSAEMSGSIZE)); +#endif +#ifdef WSAEPROTOTYPE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEPROTOTYPE"_s), jsNumber(WSAEPROTOTYPE)); +#endif +#ifdef WSAENOPROTOOPT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENOPROTOOPT"_s), jsNumber(WSAENOPROTOOPT)); +#endif +#ifdef WSAEPROTONOSUPPORT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEPROTONOSUPPORT"_s), jsNumber(WSAEPROTONOSUPPORT)); +#endif +#ifdef WSAESOCKTNOSUPPORT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAESOCKTNOSUPPORT"_s), jsNumber(WSAESOCKTNOSUPPORT)); +#endif +#ifdef WSAEOPNOTSUPP + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEOPNOTSUPP"_s), jsNumber(WSAEOPNOTSUPP)); +#endif +#ifdef WSAEPFNOSUPPORT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEPFNOSUPPORT"_s), jsNumber(WSAEPFNOSUPPORT)); +#endif +#ifdef WSAEAFNOSUPPORT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEAFNOSUPPORT"_s), jsNumber(WSAEAFNOSUPPORT)); +#endif +#ifdef WSAEADDRINUSE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEADDRINUSE"_s), jsNumber(WSAEADDRINUSE)); +#endif +#ifdef WSAEADDRNOTAVAIL + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEADDRNOTAVAIL"_s), jsNumber(WSAEADDRNOTAVAIL)); +#endif +#ifdef WSAENETDOWN + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENETDOWN"_s), jsNumber(WSAENETDOWN)); +#endif +#ifdef WSAENETUNREACH + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENETUNREACH"_s), jsNumber(WSAENETUNREACH)); +#endif +#ifdef WSAENETRESET + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENETRESET"_s), jsNumber(WSAENETRESET)); +#endif +#ifdef WSAECONNABORTED + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAECONNABORTED"_s), jsNumber(WSAECONNABORTED)); +#endif +#ifdef WSAECONNRESET + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAECONNRESET"_s), jsNumber(WSAECONNRESET)); +#endif +#ifdef WSAENOBUFS + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENOBUFS"_s), jsNumber(WSAENOBUFS)); +#endif +#ifdef WSAEISCONN + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEISCONN"_s), jsNumber(WSAEISCONN)); +#endif +#ifdef WSAENOTCONN + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENOTCONN"_s), jsNumber(WSAENOTCONN)); +#endif +#ifdef WSAESHUTDOWN + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAESHUTDOWN"_s), jsNumber(WSAESHUTDOWN)); +#endif +#ifdef WSAETOOMANYREFS + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAETOOMANYREFS"_s), jsNumber(WSAETOOMANYREFS)); +#endif +#ifdef WSAETIMEDOUT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAETIMEDOUT"_s), jsNumber(WSAETIMEDOUT)); +#endif +#ifdef WSAECONNREFUSED + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAECONNREFUSED"_s), jsNumber(WSAECONNREFUSED)); +#endif +#ifdef WSAELOOP + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAELOOP"_s), jsNumber(WSAELOOP)); +#endif +#ifdef WSAENAMETOOLONG + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENAMETOOLONG"_s), jsNumber(WSAENAMETOOLONG)); +#endif +#ifdef WSAEHOSTDOWN + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEHOSTDOWN"_s), jsNumber(WSAEHOSTDOWN)); +#endif +#ifdef WSAEHOSTUNREACH + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEHOSTUNREACH"_s), jsNumber(WSAEHOSTUNREACH)); +#endif +#ifdef WSAENOTEMPTY + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENOTEMPTY"_s), jsNumber(WSAENOTEMPTY)); +#endif +#ifdef WSAEPROCLIM + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEPROCLIM"_s), jsNumber(WSAEPROCLIM)); +#endif +#ifdef WSAEUSERS + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEUSERS"_s), jsNumber(WSAEUSERS)); +#endif +#ifdef WSAEDQUOT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEDQUOT"_s), jsNumber(WSAEDQUOT)); +#endif +#ifdef WSAESTALE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAESTALE"_s), jsNumber(WSAESTALE)); +#endif +#ifdef WSAEREMOTE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEREMOTE"_s), jsNumber(WSAEREMOTE)); +#endif +#ifdef WSASYSNOTREADY + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSASYSNOTREADY"_s), jsNumber(WSASYSNOTREADY)); +#endif +#ifdef WSAVERNOTSUPPORTED + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAVERNOTSUPPORTED"_s), jsNumber(WSAVERNOTSUPPORTED)); +#endif +#ifdef WSANOTINITIALISED + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSANOTINITIALISED"_s), jsNumber(WSANOTINITIALISED)); +#endif +#ifdef WSAEDISCON + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEDISCON"_s), jsNumber(WSAEDISCON)); +#endif +#ifdef WSAENOMORE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAENOMORE"_s), jsNumber(WSAENOMORE)); +#endif +#ifdef WSAECANCELLED + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAECANCELLED"_s), jsNumber(WSAECANCELLED)); +#endif +#ifdef WSAEINVALIDPROCTABLE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEINVALIDPROCTABLE"_s), jsNumber(WSAEINVALIDPROCTABLE)); +#endif +#ifdef WSAEINVALIDPROVIDER + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEINVALIDPROVIDER"_s), jsNumber(WSAEINVALIDPROVIDER)); +#endif +#ifdef WSAEPROVIDERFAILEDINIT + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEPROVIDERFAILEDINIT"_s), jsNumber(WSAEPROVIDERFAILEDINIT)); +#endif +#ifdef WSASYSCALLFAILURE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSASYSCALLFAILURE"_s), jsNumber(WSASYSCALLFAILURE)); +#endif +#ifdef WSASERVICE_NOT_FOUND + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSASERVICE_NOT_FOUND"_s), jsNumber(WSASERVICE_NOT_FOUND)); +#endif +#ifdef WSATYPE_NOT_FOUND + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSATYPE_NOT_FOUND"_s), jsNumber(WSATYPE_NOT_FOUND)); +#endif +#ifdef WSA_E_NO_MORE + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSA_E_NO_MORE"_s), jsNumber(WSA_E_NO_MORE)); +#endif +#ifdef WSA_E_CANCELLED + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSA_E_CANCELLED"_s), jsNumber(WSA_E_CANCELLED)); +#endif +#ifdef WSAEREFUSED + errnoObj->putDirect(vm, Identifier::fromString(vm, "WSAEREFUSED"_s), jsNumber(WSAEREFUSED)); +#endif +#ifdef SIGHUP + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGHUP"_s), jsNumber(SIGHUP)); +#endif +#ifdef SIGINT + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGINT"_s), jsNumber(SIGINT)); +#endif +#ifdef SIGQUIT + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGQUIT"_s), jsNumber(SIGQUIT)); +#endif +#ifdef SIGILL + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGILL"_s), jsNumber(SIGILL)); +#endif +#ifdef SIGTRAP + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGTRAP"_s), jsNumber(SIGTRAP)); +#endif +#ifdef SIGABRT + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGABRT"_s), jsNumber(SIGABRT)); +#endif +#ifdef SIGIOT + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGIOT"_s), jsNumber(SIGIOT)); +#endif +#ifdef SIGBUS + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGBUS"_s), jsNumber(SIGBUS)); +#endif +#ifdef SIGFPE + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGFPE"_s), jsNumber(SIGFPE)); +#endif +#ifdef SIGKILL + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGKILL"_s), jsNumber(SIGKILL)); +#endif +#ifdef SIGUSR1 + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGUSR1"_s), jsNumber(SIGUSR1)); +#endif +#ifdef SIGSEGV + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGSEGV"_s), jsNumber(SIGSEGV)); +#endif +#ifdef SIGUSR2 + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGUSR2"_s), jsNumber(SIGUSR2)); +#endif +#ifdef SIGPIPE + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGPIPE"_s), jsNumber(SIGPIPE)); +#endif +#ifdef SIGALRM + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGALRM"_s), jsNumber(SIGALRM)); +#endif +#ifdef SIGTERM + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGTERM"_s), jsNumber(SIGTERM)); +#endif +#ifdef SIGCHLD + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGCHLD"_s), jsNumber(SIGCHLD)); +#endif +#ifdef SIGSTKFLT + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGSTKFLT"_s), jsNumber(SIGSTKFLT)); +#endif +#ifdef SIGCONT + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGCONT"_s), jsNumber(SIGCONT)); +#endif +#ifdef SIGSTOP + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGSTOP"_s), jsNumber(SIGSTOP)); +#endif +#ifdef SIGTSTP + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGTSTP"_s), jsNumber(SIGTSTP)); +#endif +#ifdef SIGBREAK + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGBREAK"_s), jsNumber(SIGBREAK)); +#endif +#ifdef SIGTTIN + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGTTIN"_s), jsNumber(SIGTTIN)); +#endif +#ifdef SIGTTOU + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGTTOU"_s), jsNumber(SIGTTOU)); +#endif +#ifdef SIGURG + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGURG"_s), jsNumber(SIGURG)); +#endif +#ifdef SIGXCPU + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGXCPU"_s), jsNumber(SIGXCPU)); +#endif +#ifdef SIGXFSZ + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGXFSZ"_s), jsNumber(SIGXFSZ)); +#endif +#ifdef SIGVTALRM + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGVTALRM"_s), jsNumber(SIGVTALRM)); +#endif +#ifdef SIGPROF + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGPROF"_s), jsNumber(SIGPROF)); +#endif +#ifdef SIGWINCH + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGWINCH"_s), jsNumber(SIGWINCH)); +#endif +#ifdef SIGIO + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGIO"_s), jsNumber(SIGIO)); +#endif +#ifdef SIGPOLL + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGPOLL"_s), jsNumber(SIGPOLL)); +#endif +#ifdef SIGLOST + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGLOST"_s), jsNumber(SIGLOST)); +#endif +#ifdef SIGPWR + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGPWR"_s), jsNumber(SIGPWR)); +#endif +#ifdef SIGINFO + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGINFO"_s), jsNumber(SIGINFO)); +#endif +#ifdef SIGSYS + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGSYS"_s), jsNumber(SIGSYS)); +#endif +#ifdef SIGUNUSED + signalsObj->putDirect(vm, Identifier::fromString(vm, "SIGUNUSED"_s), jsNumber(SIGUNUSED)); +#endif + priorityObj->putDirect(vm, Identifier::fromString(vm, "PRIORITY_LOW"_s), jsNumber(19)); + priorityObj->putDirect(vm, Identifier::fromString(vm, "PRIORITY_BELOW_NORMAL"_s), jsNumber(10)); + priorityObj->putDirect(vm, Identifier::fromString(vm, "PRIORITY_NORMAL"_s), jsNumber(0)); + priorityObj->putDirect(vm, Identifier::fromString(vm, "PRIORITY_ABOVE_NORMAL"_s), jsNumber(-7)); + priorityObj->putDirect(vm, Identifier::fromString(vm, "PRIORITY_HIGH"_s), jsNumber(-14)); + priorityObj->putDirect(vm, Identifier::fromString(vm, "PRIORITY_HIGHEST"_s), jsNumber(-20)); +#ifdef RTLD_LAZY + dlopenObj->putDirect(vm, Identifier::fromString(vm, "RTLD_LAZY"_s), jsNumber(RTLD_LAZY)); +#endif +#ifdef RTLD_NOW + dlopenObj->putDirect(vm, Identifier::fromString(vm, "RTLD_NOW"_s), jsNumber(RTLD_NOW)); +#endif +#ifdef RTLD_GLOBAL + dlopenObj->putDirect(vm, Identifier::fromString(vm, "RTLD_GLOBAL"_s), jsNumber(RTLD_GLOBAL)); +#endif +#ifdef RTLD_LOCAL + dlopenObj->putDirect(vm, Identifier::fromString(vm, "RTLD_LOCAL"_s), jsNumber(RTLD_LOCAL)); +#endif +#ifdef RTLD_DEEPBIND + dlopenObj->putDirect(vm, Identifier::fromString(vm, "RTLD_DEEPBIND"_s), jsNumber(RTLD_DEEPBIND)); +#endif + return osObj; +} + +static JSValue processBindingConstantsGetTrace(VM& vm, JSObject* bindingObject) +{ + auto globalObject = bindingObject->globalObject(); + auto object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 26); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_BEGIN"_s)), jsNumber(66)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_END"_s)), jsNumber(69)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_COMPLETE"_s)), jsNumber(88)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_INSTANT"_s)), jsNumber(73)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_ASYNC_BEGIN"_s)), jsNumber(83)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_ASYNC_STEP_INTO"_s)), jsNumber(84)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_ASYNC_STEP_PAST"_s)), jsNumber(112)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_ASYNC_END"_s)), jsNumber(70)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN"_s)), jsNumber(98)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_NESTABLE_ASYNC_END"_s)), jsNumber(101)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT"_s)), jsNumber(110)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_FLOW_BEGIN"_s)), jsNumber(115)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_FLOW_STEP"_s)), jsNumber(116)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_FLOW_END"_s)), jsNumber(102)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_METADATA"_s)), jsNumber(77)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_COUNTER"_s)), jsNumber(67)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_SAMPLE"_s)), jsNumber(80)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_CREATE_OBJECT"_s)), jsNumber(78)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_SNAPSHOT_OBJECT"_s)), jsNumber(79)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_DELETE_OBJECT"_s)), jsNumber(68)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_MEMORY_DUMP"_s)), jsNumber(118)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_MARK"_s)), jsNumber(82)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_CLOCK_SYNC"_s)), jsNumber(99)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_ENTER_CONTEXT"_s)), jsNumber(40)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_LEAVE_CONTEXT"_s)), jsNumber(41)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "TRACE_EVENT_PHASE_LINK_IDS"_s)), jsNumber(61)); + return object; +} + +static JSValue processBindingConstantsGetFs(VM& vm, JSObject* bindingObject) +{ + auto globalObject = bindingObject->globalObject(); + auto object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 26); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_FS_SYMLINK_DIR"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_FS_SYMLINK_JUNCTION"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_RDONLY"_s)), jsNumber(O_RDONLY)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_WRONLY"_s)), jsNumber(O_WRONLY)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_RDWR"_s)), jsNumber(O_RDWR)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_UNKNOWN"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_FILE"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_DIR"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_LINK"_s)), jsNumber(3)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_FIFO"_s)), jsNumber(4)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_SOCKET"_s)), jsNumber(5)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_CHAR"_s)), jsNumber(6)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_DIRENT_BLOCK"_s)), jsNumber(7)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFMT"_s)), jsNumber(S_IFMT)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFREG"_s)), jsNumber(S_IFREG)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFDIR"_s)), jsNumber(S_IFDIR)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFCHR"_s)), jsNumber(S_IFCHR)); +#ifdef S_IFBLK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFBLK"_s)), jsNumber(S_IFBLK)); +#endif +#ifdef S_IFIFO + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFIFO"_s)), jsNumber(S_IFIFO)); +#endif +#ifdef S_IFLNK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFLNK"_s)), jsNumber(S_IFLNK)); +#endif +#ifdef S_IFSOCK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IFSOCK"_s)), jsNumber(S_IFSOCK)); +#endif +#ifdef O_CREAT + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_CREAT"_s)), jsNumber(O_CREAT)); +#endif +#ifdef O_EXCL + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_EXCL"_s)), jsNumber(O_EXCL)); +#endif + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_FS_O_FILEMAP"_s)), jsNumber(0)); + +#ifdef O_NOCTTY + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_NOCTTY"_s)), jsNumber(O_NOCTTY)); +#endif +#ifdef O_TRUNC + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_TRUNC"_s)), jsNumber(O_TRUNC)); +#endif +#ifdef O_APPEND + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_APPEND"_s)), jsNumber(O_APPEND)); +#endif +#ifdef O_DIRECTORY + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_DIRECTORY"_s)), jsNumber(O_DIRECTORY)); +#endif +#ifdef O_EXCL + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_EXCL"_s)), jsNumber(O_EXCL)); +#endif +#ifdef O_NOATIME + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_NOATIME"_s)), jsNumber(O_NOATIME)); +#endif +#ifdef O_NOFOLLOW + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_NOFOLLOW"_s)), jsNumber(O_NOFOLLOW)); +#endif +#ifdef O_SYNC + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_SYNC"_s)), jsNumber(O_SYNC)); +#endif +#ifdef O_DSYNC + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_DSYNC"_s)), jsNumber(O_DSYNC)); +#endif +#ifdef O_SYMLINK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_SYMLINK"_s)), jsNumber(O_SYMLINK)); +#endif +#ifdef O_DIRECT + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_DIRECT"_s)), jsNumber(O_DIRECT)); +#endif +#ifdef O_NONBLOCK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "O_NONBLOCK"_s)), jsNumber(O_NONBLOCK)); +#endif +#ifdef S_IRWXU + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IRWXU"_s)), jsNumber(S_IRWXU)); +#endif +#ifdef S_IRUSR + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IRUSR"_s)), jsNumber(S_IRUSR)); +#endif +#ifdef S_IWUSR + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IWUSR"_s)), jsNumber(S_IWUSR)); +#endif +#ifdef S_IXUSR + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IXUSR"_s)), jsNumber(S_IXUSR)); +#endif +#ifdef S_IRWXG + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IRWXG"_s)), jsNumber(S_IRWXG)); +#endif +#ifdef S_IRGRP + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IRGRP"_s)), jsNumber(S_IRGRP)); +#endif +#ifdef S_IWGRP + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IWGRP"_s)), jsNumber(S_IWGRP)); +#endif +#ifdef S_IXGRP + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IXGRP"_s)), jsNumber(S_IXGRP)); +#endif +#ifdef S_IRWXO + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IRWXO"_s)), jsNumber(S_IRWXO)); +#endif +#ifdef S_IROTH + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IROTH"_s)), jsNumber(S_IROTH)); +#endif +#ifdef S_IWOTH + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IWOTH"_s)), jsNumber(S_IWOTH)); +#endif +#ifdef S_IXOTH + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "S_IXOTH"_s)), jsNumber(S_IXOTH)); +#endif +#ifdef F_OK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "F_OK"_s)), jsNumber(F_OK)); +#endif +#ifdef R_OK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "R_OK"_s)), jsNumber(R_OK)); +#endif +#ifdef W_OK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "W_OK"_s)), jsNumber(W_OK)); +#endif +#ifdef X_OK + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "X_OK"_s)), jsNumber(X_OK)); +#endif + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_FS_COPYFILE_EXCL"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "COPYFILE_EXCL"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UV_FS_COPYFILE_FICLONE"_s)), jsNumber(2)); + 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)); + return object; +} + +static JSValue processBindingConstantsGetCrypto(VM& vm, JSObject* bindingObject) +{ + auto globalObject = bindingObject->globalObject(); + auto object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype()); +#ifdef OPENSSL_VERSION_NUMBER + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "OPENSSL_VERSION_NUMBER"_s)), jsNumber(OPENSSL_VERSION_NUMBER)); +#endif +#ifdef SSL_OP_ALL + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_ALL"_s)), jsNumber(SSL_OP_ALL)); +#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)); +#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)); +#endif +#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_CIPHER_SERVER_PREFERENCE"_s)), jsNumber(SSL_OP_CIPHER_SERVER_PREFERENCE)); +#endif +#ifdef SSL_OP_CISCO_ANYCONNECT + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_CISCO_ANYCONNECT"_s)), jsNumber(SSL_OP_CISCO_ANYCONNECT)); +#endif +#ifdef SSL_OP_COOKIE_EXCHANGE + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_COOKIE_EXCHANGE"_s)), jsNumber(SSL_OP_COOKIE_EXCHANGE)); +#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)); +#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)); +#endif +#ifdef SSL_OP_LEGACY_SERVER_CONNECT + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_LEGACY_SERVER_CONNECT"_s)), jsNumber(SSL_OP_LEGACY_SERVER_CONNECT)); +#endif +#ifdef SSL_OP_NO_COMPRESSION + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_COMPRESSION"_s)), jsNumber(SSL_OP_NO_COMPRESSION)); +#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)); +#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)); +#endif +#ifdef SSL_OP_NO_RENEGOTIATION + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_RENEGOTIATION"_s)), jsNumber(SSL_OP_NO_RENEGOTIATION)); +#endif +#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION"_s)), jsNumber(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)); +#endif +#ifdef SSL_OP_NO_SSLv2 + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_SSLv2"_s)), jsNumber(SSL_OP_NO_SSLv2)); +#endif +#ifdef SSL_OP_NO_SSLv3 + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_SSLv3"_s)), jsNumber(SSL_OP_NO_SSLv3)); +#endif +#ifdef SSL_OP_NO_TICKET + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_TICKET"_s)), jsNumber(SSL_OP_NO_TICKET)); +#endif +#ifdef SSL_OP_NO_TLSv1 + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_TLSv1"_s)), jsNumber(SSL_OP_NO_TLSv1)); +#endif +#ifdef SSL_OP_NO_TLSv1_1 + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_TLSv1_1"_s)), jsNumber(SSL_OP_NO_TLSv1_1)); +#endif +#ifdef SSL_OP_NO_TLSv1_2 + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_TLSv1_2"_s)), jsNumber(SSL_OP_NO_TLSv1_2)); +#endif +#ifdef SSL_OP_NO_TLSv1_3 + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_NO_TLSv1_3"_s)), jsNumber(SSL_OP_NO_TLSv1_3)); +#endif +#ifdef SSL_OP_PRIORITIZE_CHACHA + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "SSL_OP_PRIORITIZE_CHACHA"_s)), jsNumber(SSL_OP_PRIORITIZE_CHACHA)); +#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 +#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 +#ifdef DH_CHECK_P_NOT_PRIME + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "DH_CHECK_P_NOT_PRIME"_s)), jsNumber(DH_CHECK_P_NOT_PRIME)); +#endif +#ifdef DH_UNABLE_TO_CHECK_GENERATOR + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "DH_UNABLE_TO_CHECK_GENERATOR"_s)), jsNumber(DH_UNABLE_TO_CHECK_GENERATOR)); +#endif +#ifdef DH_NOT_SUITABLE_GENERATOR + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "DH_NOT_SUITABLE_GENERATOR"_s)), jsNumber(DH_NOT_SUITABLE_GENERATOR)); +#endif +#ifdef RSA_PKCS1_PADDING + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_PKCS1_PADDING"_s)), jsNumber(RSA_PKCS1_PADDING)); +#endif +#ifdef RSA_SSLV23_PADDING + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_SSLV23_PADDING"_s)), jsNumber(RSA_SSLV23_PADDING)); +#endif +#ifdef RSA_NO_PADDING + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_NO_PADDING"_s)), jsNumber(RSA_NO_PADDING)); +#endif +#ifdef RSA_PKCS1_OAEP_PADDING + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_PKCS1_OAEP_PADDING"_s)), jsNumber(RSA_PKCS1_OAEP_PADDING)); +#endif +#ifdef RSA_X931_PADDING + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_X931_PADDING"_s)), jsNumber(RSA_X931_PADDING)); +#endif +#ifdef RSA_PKCS1_PSS_PADDING + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_PKCS1_PSS_PADDING"_s)), jsNumber(RSA_PKCS1_PSS_PADDING)); +#endif +#ifdef RSA_PSS_SALTLEN_DIGEST + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_PSS_SALTLEN_DIGEST"_s)), jsNumber(RSA_PSS_SALTLEN_DIGEST)); +#endif +#ifdef RSA_PSS_SALTLEN_MAX_SIGN + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_PSS_SALTLEN_MAX_SIGN"_s)), jsNumber(RSA_PSS_SALTLEN_MAX_SIGN)); +#endif +#ifdef RSA_PSS_SALTLEN_AUTO + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "RSA_PSS_SALTLEN_AUTO"_s)), jsNumber(RSA_PSS_SALTLEN_AUTO)); +#endif + auto cipherList = String("TLS_AES_256_GCM_SHA384:" + "TLS_CHACHA20_POLY1305_SHA256:" + "TLS_AES_128_GCM_SHA256:" + "ECDHE-RSA-AES128-GCM-SHA256:" + "ECDHE-ECDSA-AES128-GCM-SHA256:" + "ECDHE-RSA-AES256-GCM-SHA384:" + "ECDHE-ECDSA-AES256-GCM-SHA384:" + "DHE-RSA-AES128-GCM-SHA256:" + "ECDHE-RSA-AES128-SHA256:" + "DHE-RSA-AES128-SHA256:" + "ECDHE-RSA-AES256-SHA384:" + "DHE-RSA-AES256-SHA384:" + "ECDHE-RSA-AES256-SHA256:" + "DHE-RSA-AES256-SHA256:" + "HIGH:" + "!aNULL:" + "!eNULL:" + "!EXPORT:" + "!DES:" + "!RC4:" + "!MD5:" + "!PSK:" + "!SRP:" + "!CAMELLIA"_s); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "defaultCoreCipherList"_s)), + 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)); + return object; +} + +static JSValue processBindingConstantsGetZlib(VM& vm, JSObject* bindingObject) +{ + auto globalObject = bindingObject->globalObject(); + auto object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype()); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_NO_FLUSH"_s)), jsNumber(Z_NO_FLUSH)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_PARTIAL_FLUSH"_s)), jsNumber(Z_PARTIAL_FLUSH)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_SYNC_FLUSH"_s)), jsNumber(Z_SYNC_FLUSH)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_FULL_FLUSH"_s)), jsNumber(Z_FULL_FLUSH)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_FINISH"_s)), jsNumber(Z_FINISH)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_BLOCK"_s)), jsNumber(Z_BLOCK)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_OK"_s)), jsNumber(Z_OK)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_STREAM_END"_s)), jsNumber(Z_STREAM_END)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_NEED_DICT"_s)), jsNumber(Z_NEED_DICT)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_ERRNO"_s)), jsNumber(Z_ERRNO)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_STREAM_ERROR"_s)), jsNumber(Z_STREAM_ERROR)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_DATA_ERROR"_s)), jsNumber(Z_DATA_ERROR)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MEM_ERROR"_s)), jsNumber(Z_MEM_ERROR)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_BUF_ERROR"_s)), jsNumber(Z_BUF_ERROR)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_VERSION_ERROR"_s)), jsNumber(Z_VERSION_ERROR)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_NO_COMPRESSION"_s)), jsNumber(Z_NO_COMPRESSION)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_BEST_SPEED"_s)), jsNumber(Z_BEST_SPEED)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_BEST_COMPRESSION"_s)), jsNumber(Z_BEST_COMPRESSION)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_DEFAULT_COMPRESSION"_s)), jsNumber(Z_DEFAULT_COMPRESSION)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_FILTERED"_s)), jsNumber(Z_FILTERED)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_HUFFMAN_ONLY"_s)), jsNumber(Z_HUFFMAN_ONLY)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_RLE"_s)), jsNumber(Z_RLE)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_FIXED"_s)), jsNumber(Z_FIXED)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_DEFAULT_STRATEGY"_s)), jsNumber(Z_DEFAULT_STRATEGY)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "ZLIB_VERNUM"_s)), jsNumber(ZLIB_VERNUM)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "DEFLATE"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "INFLATE"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "GZIP"_s)), jsNumber(3)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "GUNZIP"_s)), jsNumber(4)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "DEFLATERAW"_s)), jsNumber(5)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "INFLATERAW"_s)), jsNumber(6)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "UNZIP"_s)), jsNumber(7)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODE"_s)), jsNumber(8)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_ENCODE"_s)), jsNumber(9)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MIN_WINDOWBITS"_s)), jsNumber(8)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MAX_WINDOWBITS"_s)), jsNumber(15)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_DEFAULT_WINDOWBITS"_s)), jsNumber(15)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MIN_CHUNK"_s)), jsNumber(64)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MAX_CHUNK"_s)), jsNumber(INFINITY)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_DEFAULT_CHUNK"_s)), jsNumber(16384)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MIN_MEMLEVEL"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MAX_MEMLEVEL"_s)), jsNumber(9)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_DEFAULT_MEMLEVEL"_s)), jsNumber(8)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MIN_LEVEL"_s)), jsNumber(-1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_MAX_LEVEL"_s)), jsNumber(9)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "Z_DEFAULT_LEVEL"_s)), jsNumber(-1)); + + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_OPERATION_PROCESS"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_OPERATION_FLUSH"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_OPERATION_FINISH"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_OPERATION_EMIT_METADATA"_s)), jsNumber(3)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_MODE"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MODE_GENERIC"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MODE_TEXT"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MODE_FONT"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DEFAULT_MODE"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_QUALITY"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MIN_QUALITY"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MAX_QUALITY"_s)), jsNumber(11)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DEFAULT_QUALITY"_s)), jsNumber(11)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_LGWIN"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MIN_WINDOW_BITS"_s)), jsNumber(10)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MAX_WINDOW_BITS"_s)), jsNumber(24)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_LARGE_MAX_WINDOW_BITS"_s)), jsNumber(30)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DEFAULT_WINDOW"_s)), jsNumber(22)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_LGBLOCK"_s)), jsNumber(3)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MIN_INPUT_BLOCK_BITS"_s)), jsNumber(16)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_MAX_INPUT_BLOCK_BITS"_s)), jsNumber(24)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING"_s)), jsNumber(4)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_SIZE_HINT"_s)), jsNumber(5)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_LARGE_WINDOW"_s)), jsNumber(6)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_NPOSTFIX"_s)), jsNumber(7)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_PARAM_NDIRECT"_s)), jsNumber(8)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_RESULT_ERROR"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_RESULT_SUCCESS"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT"_s)), jsNumber(3)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_PARAM_LARGE_WINDOW"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_NO_ERROR"_s)), jsNumber(0)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_SUCCESS"_s)), jsNumber(1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_NEEDS_MORE_INPUT"_s)), jsNumber(2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_NEEDS_MORE_OUTPUT"_s)), jsNumber(3)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE"_s)), jsNumber(-1)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_RESERVED"_s)), jsNumber(-2)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE"_s)), jsNumber(-3)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET"_s)), jsNumber(-4)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME"_s)), jsNumber(-5)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_CL_SPACE"_s)), jsNumber(-6)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE"_s)), jsNumber(-7)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT"_s)), jsNumber(-8)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1"_s)), jsNumber(-9)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2"_s)), jsNumber(-10)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_TRANSFORM"_s)), jsNumber(-11)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_DICTIONARY"_s)), jsNumber(-12)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS"_s)), jsNumber(-13)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_PADDING_1"_s)), jsNumber(-14)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_PADDING_2"_s)), jsNumber(-15)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_FORMAT_DISTANCE"_s)), jsNumber(-16)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET"_s)), jsNumber(-19)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_INVALID_ARGUMENTS"_s)), jsNumber(-20)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES"_s)), jsNumber(-21)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS"_s)), jsNumber(-22)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP"_s)), jsNumber(-25)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1"_s)), jsNumber(-26)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2"_s)), jsNumber(-27)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES"_s)), jsNumber(-30)); + object->putDirect(vm, PropertyName(Identifier::fromString(vm, "BROTLI_DECODER_ERROR_UNREACHABLE"_s)), jsNumber(-31)); + + return object; +} + +static const HashTableValue ProcessBindingConstantsValues[] = { + { "os"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, processBindingConstantsGetOs } }, + { "fs"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, processBindingConstantsGetFs } }, + { "crypto"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, processBindingConstantsGetCrypto } }, + { "zlib"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, processBindingConstantsGetZlib } }, + { "trace"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, processBindingConstantsGetTrace } }, +}; + +const ClassInfo ProcessBindingConstants::s_info = { "ProcessBindingConstants"_s, Base::info(), nullptr, nullptr, CREATE_METHOD_TABLE(ProcessBindingConstants) }; + +ProcessBindingConstants* ProcessBindingConstants::create(VM& vm, Structure* structure) +{ + ProcessBindingConstants* obj = new (NotNull, allocateCell<ProcessBindingConstants>(vm)) ProcessBindingConstants(vm, structure); + obj->finishCreation(vm); + return obj; +} + +Structure* ProcessBindingConstants::createStructure(VM& vm, JSGlobalObject* globalObject) +{ + return Structure::create(vm, globalObject, jsNull(), TypeInfo(ObjectType, StructureFlags), ProcessBindingConstants::info()); +} + +void ProcessBindingConstants::finishCreation(JSC::VM& vm) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, ProcessBindingConstants::info(), ProcessBindingConstantsValues, *this); + ASSERT(inherits(vm, info())); +} + +template<typename Visitor> +void ProcessBindingConstants::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ + ProcessBindingConstants* thisObject = jsCast<ProcessBindingConstants*>(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); +} + +DEFINE_VISIT_CHILDREN(ProcessBindingConstants); + +} // namespace Bun diff --git a/src/bun.js/bindings/ProcessBindingConstants.h b/src/bun.js/bindings/ProcessBindingConstants.h new file mode 100644 index 000000000..5a9be7ce7 --- /dev/null +++ b/src/bun.js/bindings/ProcessBindingConstants.h @@ -0,0 +1,32 @@ +#include "root.h" + +namespace Bun { +using namespace JSC; + +// The object returned from process.binding('constants') +class ProcessBindingConstants final : public JSC::JSNonFinalObject { +public: + DECLARE_INFO; + DECLARE_VISIT_CHILDREN; + + using Base = JSC::JSNonFinalObject; + + static ProcessBindingConstants* create(JSC::VM& vm, JSC::Structure* structure); + static Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject); + + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + +private: + void finishCreation(JSC::VM& vm); + + ProcessBindingConstants(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure) + { + } +}; + +} // namespace Bun diff --git a/src/bun.js/bindings/ZigGeneratedCode.cpp b/src/bun.js/bindings/ZigGeneratedCode.cpp index 29f92bab0..6a57e43ea 100644 --- a/src/bun.js/bindings/ZigGeneratedCode.cpp +++ b/src/bun.js/bindings/ZigGeneratedCode.cpp @@ -1,703 +1,670 @@ - #include "root.h" - #include "headers.h" - - #include <JavaScriptCore/DOMJITAbstractHeap.h> - #include "DOMJITIDLConvert.h" - #include "DOMJITIDLType.h" - #include "DOMJITIDLTypeFilter.h" - #include "DOMJITHelpers.h" - #include <JavaScriptCore/DFGAbstractHeap.h> - - #include "JSDOMConvertBufferSource.h" - - using namespace JSC; - using namespace WebCore; - - - /* -- BEGIN DOMCall DEFINITIONS -- */ - +#include "root.h" +#include "headers.h" -extern "C" JSC_DECLARE_HOST_FUNCTION(FFI__ptr__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*)); +#include <JavaScriptCore/DOMJITAbstractHeap.h> +#include "DOMJITIDLConvert.h" +#include "DOMJITIDLType.h" +#include "DOMJITIDLTypeFilter.h" +#include "DOMJITHelpers.h" +#include <JavaScriptCore/DFGAbstractHeap.h> -JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1); -} -JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +#include "JSDOMConvertBufferSource.h" + +using namespace JSC; +using namespace WebCore; + +/* -- BEGIN DOMCall DEFINITIONS -- */ + +extern "C" JSC_DECLARE_HOST_FUNCTION(FFI__ptr__slowpathWrapper); +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*)); + +JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1); +} +JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return FFI__ptr__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void FFI__ptr__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_ptr_signature( - FFI__ptr__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecDoubleReal, - JSC::SpecUint8Array - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 1, - String("ptr"_s), - FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper, - &DOMJIT_ptr_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "ptr"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void FFI__ptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_ptr_signature( + FFI__ptr__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecDoubleReal, + JSC::SpecUint8Array); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 1, + String("ptr"_s), + FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper, + &DOMJIT_ptr_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "ptr"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__u8__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__u8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__u8__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__u8__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__u8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__u8__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__u8__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__u8__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__u8__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_u8_signature( - Reader__u8__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt32Only, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("u8"_s), - Reader__u8__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u8__slowpathWrapper, - &DOMJIT_u8_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "u8"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__u8__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_u8_signature( + Reader__u8__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt32Only, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("u8"_s), + Reader__u8__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u8__slowpathWrapper, + &DOMJIT_u8_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "u8"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__u16__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__u16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__u16__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__u16__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__u16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__u16__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__u16__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__u16__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__u16__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_u16_signature( - Reader__u16__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt32Only, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("u16"_s), - Reader__u16__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u16__slowpathWrapper, - &DOMJIT_u16_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "u16"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__u16__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_u16_signature( + Reader__u16__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt32Only, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("u16"_s), + Reader__u16__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u16__slowpathWrapper, + &DOMJIT_u16_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "u16"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__u32__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__u32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__u32__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__u32__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__u32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__u32__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__u32__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__u32__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__u32__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_u32_signature( - Reader__u32__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt32Only, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("u32"_s), - Reader__u32__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u32__slowpathWrapper, - &DOMJIT_u32_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "u32"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__u32__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_u32_signature( + Reader__u32__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt32Only, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("u32"_s), + Reader__u32__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u32__slowpathWrapper, + &DOMJIT_u32_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "u32"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__ptr__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__ptr__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__ptr__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__ptr__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__ptr__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__ptr__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__ptr__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_ptr_signature( - Reader__ptr__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt52Any, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("ptr"_s), - Reader__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__ptr__slowpathWrapper, - &DOMJIT_ptr_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "ptr"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__ptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_ptr_signature( + Reader__ptr__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt52Any, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("ptr"_s), + Reader__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__ptr__slowpathWrapper, + &DOMJIT_ptr_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "ptr"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__i8__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__i8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__i8__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__i8__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__i8__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__i8__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__i8__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__i8__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__i8__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_i8_signature( - Reader__i8__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt32Only, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("i8"_s), - Reader__i8__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i8__slowpathWrapper, - &DOMJIT_i8_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "i8"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__i8__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_i8_signature( + Reader__i8__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt32Only, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("i8"_s), + Reader__i8__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i8__slowpathWrapper, + &DOMJIT_i8_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "i8"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__i16__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__i16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__i16__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__i16__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__i16__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__i16__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__i16__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__i16__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__i16__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_i16_signature( - Reader__i16__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt32Only, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("i16"_s), - Reader__i16__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i16__slowpathWrapper, - &DOMJIT_i16_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "i16"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__i16__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_i16_signature( + Reader__i16__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt32Only, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("i16"_s), + Reader__i16__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i16__slowpathWrapper, + &DOMJIT_i16_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "i16"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__i32__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__i32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__i32__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__i32__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__i32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__i32__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__i32__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__i32__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__i32__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_i32_signature( - Reader__i32__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt32Only, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("i32"_s), - Reader__i32__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i32__slowpathWrapper, - &DOMJIT_i32_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "i32"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__i32__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_i32_signature( + Reader__i32__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt32Only, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("i32"_s), + Reader__i32__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i32__slowpathWrapper, + &DOMJIT_i32_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "i32"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__i64__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__i64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__i64__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__i64__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__i64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__i64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__i64__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__i64__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__i64__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__i64__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_i64_signature( - Reader__i64__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecHeapTop, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("i64"_s), - Reader__i64__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i64__slowpathWrapper, - &DOMJIT_i64_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "i64"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__i64__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_i64_signature( + Reader__i64__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecHeapTop, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("i64"_s), + Reader__i64__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__i64__slowpathWrapper, + &DOMJIT_i64_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "i64"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__u64__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__u64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__u64__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__u64__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__u64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__u64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__u64__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__u64__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__u64__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__u64__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_u64_signature( - Reader__u64__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecHeapTop, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("u64"_s), - Reader__u64__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u64__slowpathWrapper, - &DOMJIT_u64_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "u64"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__u64__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_u64_signature( + Reader__u64__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecHeapTop, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("u64"_s), + Reader__u64__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__u64__slowpathWrapper, + &DOMJIT_u64_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "u64"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__intptr__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__intptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__intptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__intptr__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__intptr__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__intptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__intptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__intptr__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__intptr__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__intptr__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__intptr__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_intptr_signature( - Reader__intptr__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecInt52Any, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("intptr"_s), - Reader__intptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__intptr__slowpathWrapper, - &DOMJIT_intptr_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "intptr"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__intptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_intptr_signature( + Reader__intptr__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecInt52Any, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("intptr"_s), + Reader__intptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__intptr__slowpathWrapper, + &DOMJIT_intptr_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "intptr"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__f32__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__f32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__f32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__f32__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__f32__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__f32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__f32__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__f32__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__f32__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__f32__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__f32__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_f32_signature( - Reader__f32__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecDoubleReal, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("f32"_s), - Reader__f32__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__f32__slowpathWrapper, - &DOMJIT_f32_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "f32"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__f32__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_f32_signature( + Reader__f32__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecDoubleReal, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("f32"_s), + Reader__f32__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__f32__slowpathWrapper, + &DOMJIT_f32_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "f32"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Reader__f64__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__f64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t, int32_t)); - -JSC_DEFINE_JIT_OPERATION(Reader__f64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Reader__f64__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Reader__f64__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Reader__f64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t, int32_t)); + +JSC_DEFINE_JIT_OPERATION(Reader__f64__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, int64_t arg1, int32_t arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Reader__f64__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Reader__f64__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Reader__f64__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Reader__f64__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_f64_signature( - Reader__f64__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecDoubleReal, - JSC::SpecInt52Any, - JSC::SpecInt32Only - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("f64"_s), - Reader__f64__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__f64__slowpathWrapper, - &DOMJIT_f64_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "f64"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Reader__f64__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_f64_signature( + Reader__f64__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecDoubleReal, + JSC::SpecInt52Any, + JSC::SpecInt32Only); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("f64"_s), + Reader__f64__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Reader__f64__slowpathWrapper, + &DOMJIT_f64_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "f64"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Crypto__getRandomValues__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Crypto__getRandomValues__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*)); - -JSC_DEFINE_JIT_OPERATION(Crypto__getRandomValues__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Crypto__getRandomValues__fastpath(lexicalGlobalObject, thisValue, arg1); -} -JSC_DEFINE_HOST_FUNCTION(Crypto__getRandomValues__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Crypto__getRandomValues__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*)); + +JSC_DEFINE_JIT_OPERATION(Crypto__getRandomValues__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Crypto__getRandomValues__fastpath(lexicalGlobalObject, thisValue, arg1); +} +JSC_DEFINE_HOST_FUNCTION(Crypto__getRandomValues__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Crypto__getRandomValues__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Crypto__getRandomValues__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_getRandomValues_signature( - Crypto__getRandomValues__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecHeapTop, - JSC::SpecUint8Array - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 1, - String("getRandomValues"_s), - Crypto__getRandomValues__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Crypto__getRandomValues__slowpathWrapper, - &DOMJIT_getRandomValues_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "getRandomValues"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Crypto__getRandomValues__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_getRandomValues_signature( + Crypto__getRandomValues__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecHeapTop, + JSC::SpecUint8Array); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 1, + String("getRandomValues"_s), + Crypto__getRandomValues__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Crypto__getRandomValues__slowpathWrapper, + &DOMJIT_getRandomValues_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "getRandomValues"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Crypto__randomUUID__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Crypto__randomUUID__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue)); - -JSC_DEFINE_JIT_OPERATION(Crypto__randomUUID__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Crypto__randomUUID__fastpath(lexicalGlobalObject, thisValue); -} -JSC_DEFINE_HOST_FUNCTION(Crypto__randomUUID__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Crypto__randomUUID__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); + +JSC_DEFINE_JIT_OPERATION(Crypto__randomUUID__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Crypto__randomUUID__fastpath(lexicalGlobalObject, thisValue); +} +JSC_DEFINE_HOST_FUNCTION(Crypto__randomUUID__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Crypto__randomUUID__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Crypto__randomUUID__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_randomUUID_signature( - Crypto__randomUUID__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecString); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 0, - String("randomUUID"_s), - Crypto__randomUUID__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Crypto__randomUUID__slowpathWrapper, - &DOMJIT_randomUUID_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "randomUUID"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); +extern "C" void Crypto__randomUUID__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_randomUUID_signature( + Crypto__randomUUID__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecString); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 0, + String("randomUUID"_s), + Crypto__randomUUID__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Crypto__randomUUID__slowpathWrapper, + &DOMJIT_randomUUID_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "randomUUID"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); } - - extern "C" JSC_DECLARE_HOST_FUNCTION(Crypto__timingSafeEqual__slowpathWrapper); -extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Crypto__timingSafeEqual__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*, JSC::JSUint8Array*)); - -JSC_DEFINE_JIT_OPERATION(Crypto__timingSafeEqual__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1, JSC::JSUint8Array* arg2)) { -VM& vm = JSC::getVM(lexicalGlobalObject); -IGNORE_WARNINGS_BEGIN("frame-address") -CallFrame* callFrame = DECLARE_CALL_FRAME(vm); -IGNORE_WARNINGS_END -JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); -return Crypto__timingSafeEqual__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); -} -JSC_DEFINE_HOST_FUNCTION(Crypto__timingSafeEqual__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) { +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(Crypto__timingSafeEqual__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*, JSC::JSUint8Array*)); + +JSC_DEFINE_JIT_OPERATION(Crypto__timingSafeEqual__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1, JSC::JSUint8Array* arg2)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return Crypto__timingSafeEqual__fastpath(lexicalGlobalObject, thisValue, arg1, arg2); +} +JSC_DEFINE_HOST_FUNCTION(Crypto__timingSafeEqual__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame)) +{ return Crypto__timingSafeEqual__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount()); } -extern "C" void Crypto__timingSafeEqual__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) { - JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value)); - static const JSC::DOMJIT::Signature DOMJIT_timingSafeEqual_signature( - Crypto__timingSafeEqual__fastpathWrapper, - thisObject->classInfo(), -JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), - JSC::SpecHeapTop, - JSC::SpecUint8Array, - JSC::SpecUint8Array - ); - JSFunction* function = JSFunction::create( - globalObject->vm(), - globalObject, - 2, - String("timingSafeEqual"_s), - Crypto__timingSafeEqual__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Crypto__timingSafeEqual__slowpathWrapper, - &DOMJIT_timingSafeEqual_signature - ); - thisObject->putDirect( - globalObject->vm(), - Identifier::fromString(globalObject->vm(), "timingSafeEqual"_s), - function, - JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0 - ); -} - - - /* -- END DOMCall DEFINITIONS-- */ - +extern "C" void Crypto__timingSafeEqual__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value)); + static const JSC::DOMJIT::Signature DOMJIT_timingSafeEqual_signature( + Crypto__timingSafeEqual__fastpathWrapper, + thisObject->classInfo(), + JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()), + JSC::SpecHeapTop, + JSC::SpecUint8Array, + JSC::SpecUint8Array); + JSFunction* function = JSFunction::create( + globalObject->vm(), + globalObject, + 2, + String("timingSafeEqual"_s), + Crypto__timingSafeEqual__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, Crypto__timingSafeEqual__slowpathWrapper, + &DOMJIT_timingSafeEqual_signature); + thisObject->putDirect( + globalObject->vm(), + Identifier::fromString(globalObject->vm(), "timingSafeEqual"_s), + function, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0); +} + +/* -- END DOMCall DEFINITIONS-- */ diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 7c1181921..849cee27b 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -105,7 +105,6 @@ #include "JavaScriptCore/FunctionPrototype.h" #include "napi.h" #include "JSSQLStatement.h" -#include "BunJSCModule.h" #include "ModuleLoader.h" #include "NodeVMScript.h" #include "ProcessIdentifier.h" @@ -219,6 +218,8 @@ constexpr size_t DEFAULT_ERROR_STACK_TRACE_LIMIT = 10; // #include <iostream> static bool has_loaded_jsc = false; +Structure* createMemoryFootprintStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject); + namespace WebCore { class Base64Utilities { public: @@ -491,7 +492,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFulfillModuleSync, res.result.err.code = 0; res.result.err.ptr = nullptr; - JSValue result = Bun::fetchSourceCodeSync( + JSValue result = Bun::fetchESMSourceCodeSync( reinterpret_cast<Zig::GlobalObject*>(globalObject), &res, &specifier, @@ -1586,6 +1587,7 @@ JSC_DEFINE_HOST_FUNCTION(functionCallNotImplemented, } // we're trying out a new way to do this lazy loading +// this is $lazy() in js code static JSC_DEFINE_HOST_FUNCTION(functionLazyLoad, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) { @@ -1642,10 +1644,6 @@ JSC: return JSC::JSValue::encode(JSSQLStatementConstructor::create(vm, globalObject, JSSQLStatementConstructor::createStructure(vm, globalObject, globalObject->m_functionPrototype.get()))); } - if (string == "bun:jsc"_s) { - return JSC::JSValue::encode(createJSCModule(globalObject)); - } - if (string == "pathToFileURL"_s) { return JSValue::encode( JSFunction::create(vm, globalObject, 1, pathToFileURLString, functionPathToFileURL, ImplementationVisibility::Public, NoIntrinsic)); @@ -1674,23 +1672,20 @@ JSC: JSC::JSFunction::create(vm, globalObject, 0, "onEofChunk"_s, jsReadable_onEofChunk, ImplementationVisibility::Public), 0); return JSValue::encode(obj); } - - if (string == "createImportMeta"_s) { - Zig::ImportMetaObject* obj = Zig::ImportMetaObject::create(globalObject, callFrame->argument(1)); - return JSValue::encode(obj); + if (string == "events"_s) { + return JSValue::encode(WebCore::JSEventEmitter::getConstructor(vm, globalObject)); } - if (string == "internal/tls"_s) { auto* obj = constructEmptyObject(globalObject); auto sourceOrigin = callFrame->callerSourceOrigin(vm).url(); -// expose for tests in debug mode only -#ifndef BUN_DEBUG - bool isBuiltin = sourceOrigin.protocolIs("builtin"_s); - if (!isBuiltin) { - return JSC::JSValue::encode(JSC::jsUndefined()); - } -#endif + // expose for tests in debug mode only + // #ifndef BUN_DEBUG + // bool isBuiltin = sourceOrigin.protocolIs("builtin"_s); + // if (!isBuiltin) { + // return JSC::JSValue::encode(JSC::jsUndefined()); + // } + // #endif struct us_cert_string_t* out; auto size = us_raw_root_certs(&out); if (size < 0) { @@ -1735,26 +1730,9 @@ JSC: return JSValue::encode(obj); } - if (string == "primordials"_s) { - auto sourceOrigin = callFrame->callerSourceOrigin(vm).url(); - bool isBuiltin = sourceOrigin.protocolIs("builtin"_s); - if (!isBuiltin) { - return JSC::JSValue::encode(JSC::jsUndefined()); - } - - auto* obj = globalObject->primordialsObject(); - return JSValue::encode(obj); - } - if (string == "async_hooks"_s) { auto* obj = constructEmptyObject(globalObject); obj->putDirect( - vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "get"_s)), - JSC::JSFunction::create(vm, asyncContextGetAsyncContextCodeGenerator(vm), globalObject), 0); - obj->putDirect( - vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "set"_s)), - JSC::JSFunction::create(vm, asyncContextSetAsyncContextCodeGenerator(vm), globalObject), 0); - obj->putDirect( vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "cleanupLater"_s)), JSC::JSFunction::create(vm, globalObject, 0, "cleanupLater"_s, asyncHooksCleanupLater, ImplementationVisibility::Public), 0); return JSValue::encode(obj); @@ -2762,81 +2740,6 @@ JSC_DEFINE_HOST_FUNCTION(functionReadableStreamToArrayBuffer, (JSGlobalObject * return ZigGlobalObject__readableStreamToArrayBufferBody(reinterpret_cast<Zig::GlobalObject*>(globalObject), JSValue::encode(readableStreamValue)); } -class BunPrimordialsObject final : public JSNonFinalObject { -public: - using Base = JSC::JSNonFinalObject; - static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | GetOwnPropertySlotMayBeWrongAboutDontEnum; - static BunPrimordialsObject* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) - { - BunPrimordialsObject* ptr = new (NotNull, JSC::allocateCell<BunPrimordialsObject>(vm)) BunPrimordialsObject(vm, globalObject, structure); - ptr->finishCreation(vm); - return ptr; - } - - template<typename CellType, JSC::SubspaceAccess> - static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(BunPrimordialsObject, Base); - return &vm.plainObjectSpace(); - } - - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) - { - return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); - } - - static bool getOwnPropertySlot(JSObject* object, JSGlobalObject* globalObject, PropertyName propertyName, PropertySlot& slot) - { - JSC::VM& vm = globalObject->vm(); - - auto str = String(propertyName.publicName()); - SymbolImpl* symbol = vm.propertyNames->builtinNames().lookUpPrivateName(str); - if (!symbol) { - return false; - } - - auto identifier = JSC::Identifier::fromUid(vm, symbol); - if (auto value = globalObject->getIfPropertyExists(globalObject, identifier)) { - slot.setValue(globalObject, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly, value); - return true; - } else if (auto value = vm.bytecodeIntrinsicRegistry().lookup(identifier)) { - auto name = identifier.string(); - String functionText; - bool isFunction = false; - // this is...terrible code - if (name.characters8()[0] >= 'A' && name.characters8()[0] <= 'Z') { - functionText = makeString("(function () { return @"_s, name, ";\n})\n"_s); - } else if (name.characters8()[0] == 'p' || name.characters8()[0] == 't' || name.characters8()[0] == 'g') { - isFunction = true; - functionText = makeString("(function (arg1, arg2) { return @"_s, name, "(arg1, arg2);\n})\n"_s); - } else { - isFunction = true; - functionText = makeString("(function (arg1) { return @"_s, name, "(arg1);\n})\n"_s); - } - - SourceCode source = makeSource(WTFMove(functionText), {}); - JSFunction* func = JSFunction::create(vm, createBuiltinExecutable(vm, source, Identifier::fromString(vm, name), ImplementationVisibility::Public, ConstructorKind::None, ConstructAbility::CannotConstruct)->link(vm, nullptr, source), globalObject); - - slot.setValue( - globalObject, - PropertyAttribute::ReadOnly | PropertyAttribute::DontDelete | 0, - isFunction ? JSValue(func) : JSC::call(globalObject, func, JSC::getCallData(func), globalObject, JSC::MarkedArgumentBuffer())); - - return true; - } - return false; - } - - DECLARE_INFO - - BunPrimordialsObject(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) - : JSC::JSNonFinalObject(vm, structure) - { - } -}; - -const ClassInfo BunPrimordialsObject::s_info = { "Primordials"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BunPrimordialsObject) }; - JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotask, (JSGlobalObject * globalObject, CallFrame* callframe)) { auto& vm = globalObject->vm(); @@ -3303,10 +3206,6 @@ void GlobalObject::finishCreation(VM& vm) [](const Initializer<JSWeakMap>& init) { init.set(JSWeakMap::create(init.vm, init.owner->weakMapStructure())); }); - // m_asyncHooksContext.initLater( - // [](const Initializer<JSC::JSMap>& init) { - // init.set(JSC::JSMap::create(init.vm, init.owner->mapStructure())); - // }); m_JSBufferSubclassStructure.initLater( [](const Initializer<Structure>& init) { @@ -3399,14 +3298,6 @@ void GlobalObject::finishCreation(VM& vm) toJS<IDLInterface<SubtleCrypto>>(*init.owner, global, global.crypto).getObject()); }); - m_primordialsObject.initLater( - [](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::JSObject>::Initializer& init) { - auto& global = *reinterpret_cast<Zig::GlobalObject*>(init.owner); - BunPrimordialsObject* object = BunPrimordialsObject::create(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.owner), - BunPrimordialsObject::createStructure(init.vm, init.owner, init.owner->objectPrototype())); - init.set(object); - }); - m_NapiClassStructure.initLater( [](LazyClassStructure::Initializer& init) { init.setStructure(Zig::NapiClass::createStructure(init.vm, init.global, init.global->functionPrototype())); @@ -3493,6 +3384,7 @@ void GlobalObject::finishCreation(VM& vm) init.owner->globalScope(), JSFunction::createStructure(init.vm, init.owner, RequireFunctionPrototype::create(init.owner)))); }); + m_requireResolveFunctionUnbound.initLater( [](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::JSObject>::Initializer& init) { init.set( @@ -3503,6 +3395,22 @@ void GlobalObject::finishCreation(VM& vm) JSFunction::createStructure(init.vm, init.owner, RequireResolveFunctionPrototype::create(init.owner)))); }); + m_internalModuleRegistry.initLater( + [](const JSC::LazyProperty<JSC::JSGlobalObject, Bun::InternalModuleRegistry>::Initializer& init) { + init.set( + InternalModuleRegistry::create( + init.vm, + InternalModuleRegistry::createStructure(init.vm, init.owner))); + }); + + m_processBindingConstants.initLater( + [](const JSC::LazyProperty<JSC::JSGlobalObject, Bun::ProcessBindingConstants>::Initializer& init) { + init.set( + ProcessBindingConstants::create( + init.vm, + ProcessBindingConstants::createStructure(init.vm, init.owner))); + }); + m_importMetaObjectStructure.initLater( [](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::Structure>::Initializer& init) { init.set(Zig::ImportMetaObject::createStructure(init.vm, init.owner)); @@ -4107,7 +4015,6 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0 }); static NeverDestroyed<const String> BunLazyString(MAKE_STATIC_STRING_IMPL("Bun.lazy")); - static NeverDestroyed<const String> CommonJSSymbolKey(MAKE_STATIC_STRING_IMPL("CommonJS")); JSC::Identifier BunLazyIdentifier = JSC::Identifier::fromUid(vm.symbolRegistry().symbolForKey(BunLazyString)); JSC::JSFunction* lazyLoadFunction = JSC::JSFunction::create(vm, this, 0, BunLazyString, functionLazyLoad, ImplementationVisibility::Public); @@ -4137,7 +4044,6 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.getInternalWritableStreamPrivateName(), JSFunction::create(vm, this, 1, String(), getInternalWritableStream, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.createWritableStreamFromInternalPrivateName(), JSFunction::create(vm, this, 1, String(), createWritableStreamFromInternal, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.fulfillModuleSyncPrivateName(), JSFunction::create(vm, this, 1, String(), functionFulfillModuleSync, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function)); - extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.commonJSSymbolPrivateName(), JSC::Symbol::create(vm, vm.symbolRegistry().symbolForKey(CommonJSSymbolKey)), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(builtinNames.directPrivateName(), JSFunction::create(vm, this, 1, String(), functionGetDirectStreamDetails, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function)); extraStaticGlobals.uncheckedAppend(GlobalPropertyInfo(vm.propertyNames->builtinNames().ArrayBufferPrivateName(), arrayBufferConstructor(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly)); @@ -4155,8 +4061,12 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) putDirectBuiltinFunction(vm, this, builtinNames.requireESMPrivateName(), importMetaObjectRequireESMCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); putDirectBuiltinFunction(vm, this, builtinNames.loadCJS2ESMPrivateName(), importMetaObjectLoadCJS2ESMCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); putDirectBuiltinFunction(vm, this, builtinNames.internalRequirePrivateName(), importMetaObjectInternalRequireCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); + putDirectBuiltinFunction(vm, this, builtinNames.requireNativeModulePrivateName(), moduleRequireNativeModuleCodeGenerator(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__resolveSyncPrivate, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function); + putDirectNativeFunction(vm, this, builtinNames.createInternalModuleByIdPrivateName(), 1, InternalModuleRegistry::jsCreateInternalModuleById, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function); + putDirect(vm, builtinNames.internalModuleRegistryPrivateName(), this->internalModuleRegistry(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); + putDirect(vm, builtinNames.processBindingConstantsPrivateName(), this->processBindingConstants(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "process"_s), JSC::CustomGetterSetter::create(vm, property_lazyProcessGetter, property_lazyProcessSetter), JSC::PropertyAttribute::CustomAccessor | 0); @@ -4674,7 +4584,6 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) thisObject->m_navigatorObject.visit(visitor); thisObject->m_nativeMicrotaskTrampoline.visit(visitor); thisObject->m_performanceObject.visit(visitor); - thisObject->m_primordialsObject.visit(visitor); thisObject->m_processEnvObject.visit(visitor); thisObject->m_processObject.visit(visitor); thisObject->m_subtleCryptoObject.visit(visitor); @@ -4685,8 +4594,10 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) thisObject->m_requireFunctionUnbound.visit(visitor); thisObject->m_requireResolveFunctionUnbound.visit(visitor); + thisObject->m_processBindingConstants.visit(visitor); thisObject->m_importMetaObjectStructure.visit(visitor); thisObject->m_asyncBoundFunctionStructure.visit(visitor); + thisObject->m_internalModuleRegistry.visit(visitor); thisObject->m_dnsObject.visit(visitor); thisObject->m_lazyRequireCacheObject.visit(visitor); @@ -4963,7 +4874,7 @@ JSC::JSInternalPromise* GlobalObject::moduleLoaderFetch(JSGlobalObject* globalOb res.result.err.code = 0; res.result.err.ptr = nullptr; - JSValue result = Bun::fetchSourceCodeAsync( + JSValue result = Bun::fetchESMSourceCodeAsync( reinterpret_cast<Zig::GlobalObject*>(globalObject), &res, &moduleKeyBun, diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h index 12f5d9d32..c5281db6e 100644 --- a/src/bun.js/bindings/ZigGlobalObject.h +++ b/src/bun.js/bindings/ZigGlobalObject.h @@ -42,6 +42,8 @@ class DOMWrapperWorld; #include "DOMConstructors.h" #include "BunPlugin.h" #include "JSMockFunction.h" +#include "InternalModuleRegistry.h" +#include "ProcessBindingConstants.h" namespace WebCore { class GlobalScope; @@ -252,7 +254,6 @@ public: JSC::Structure* callSiteStructure() const { return m_callSiteStructure.getInitializedOnMainThread(this); } JSC::JSObject* performanceObject() { return m_performanceObject.getInitializedOnMainThread(this); } - JSC::JSObject* primordialsObject() { return m_primordialsObject.getInitializedOnMainThread(this); } JSC::JSFunction* performMicrotaskFunction() { return m_performMicrotaskFunction.getInitializedOnMainThread(this); } JSC::JSFunction* performMicrotaskVariadicFunction() { return m_performMicrotaskVariadicFunction.getInitializedOnMainThread(this); } @@ -261,6 +262,8 @@ public: JSObject* requireFunctionUnbound() { return m_requireFunctionUnbound.getInitializedOnMainThread(this); } JSObject* requireResolveFunctionUnbound() { return m_requireResolveFunctionUnbound.getInitializedOnMainThread(this); } + Bun::InternalModuleRegistry* internalModuleRegistry() { return m_internalModuleRegistry.getInitializedOnMainThread(this); } + Bun::ProcessBindingConstants* processBindingConstants() { return m_processBindingConstants.getInitializedOnMainThread(this); } JSObject* lazyRequireCacheObject() { return m_lazyRequireCacheObject.getInitializedOnMainThread(this); } @@ -509,7 +512,6 @@ private: LazyProperty<JSGlobalObject, JSObject> m_JSHTTPSResponseControllerPrototype; LazyProperty<JSGlobalObject, JSObject> m_navigatorObject; LazyProperty<JSGlobalObject, JSObject> m_performanceObject; - LazyProperty<JSGlobalObject, JSObject> m_primordialsObject; LazyProperty<JSGlobalObject, JSObject> m_processEnvObject; LazyProperty<JSGlobalObject, JSObject> m_processObject; LazyProperty<JSGlobalObject, JSObject> m_subtleCryptoObject; @@ -531,6 +533,8 @@ private: LazyProperty<JSGlobalObject, JSC::JSObject> m_requireFunctionUnbound; LazyProperty<JSGlobalObject, JSC::JSObject> m_requireResolveFunctionUnbound; + LazyProperty<JSGlobalObject, Bun::InternalModuleRegistry> m_internalModuleRegistry; + LazyProperty<JSGlobalObject, Bun::ProcessBindingConstants> m_processBindingConstants; LazyProperty<JSGlobalObject, JSC::Structure> m_importMetaObjectStructure; LazyProperty<JSGlobalObject, JSC::Structure> m_asyncBoundFunctionStructure; diff --git a/src/bun.js/bindings/ZigSourceProvider.cpp b/src/bun.js/bindings/ZigSourceProvider.cpp index a71e946de..2c448b5a6 100644 --- a/src/bun.js/bindings/ZigSourceProvider.cpp +++ b/src/bun.js/bindings/ZigSourceProvider.cpp @@ -198,4 +198,4 @@ int SourceProvider::readCache(JSC::VM& vm, const JSC::SourceCode& sourceCode) // return 0; // } } -}; // namespace Zig
\ No newline at end of file +}; // namespace Zig diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index 20c110d52..6d57798fd 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -221,22 +221,7 @@ pub const ResolvedSource = extern struct { tag: Tag = Tag.javascript, - pub const Tag = enum(u64) { - javascript = 0, - package_json_type_module = 1, - wasm = 2, - object = 3, - file = 4, - - @"node:buffer" = 1024, - @"node:process" = 1025, - @"bun:events_native" = 1026, // native version of EventEmitter used for streams - @"node:string_decoder" = 1027, - @"node:module" = 1028, - @"node:tty" = 1029, - @"node:util/types" = 1030, - @"node:constants" = 1031, - }; + pub const Tag = @import("../../js/out/ResolvedSourceTag.zig").ResolvedSourceTag; }; const Mimalloc = @import("../../allocators/mimalloc.zig"); diff --git a/src/bun.js/bindings/headers-handwritten.h b/src/bun.js/bindings/headers-handwritten.h index df1bec554..e19be7abe 100644 --- a/src/bun.js/bindings/headers-handwritten.h +++ b/src/bun.js/bindings/headers-handwritten.h @@ -70,9 +70,9 @@ typedef struct ResolvedSource { uint32_t commonJSExportsLen; uint32_t hash; void* allocator; - uint64_t tag; + uint32_t tag; } ResolvedSource; -static const uint64_t ResolvedSourceTagPackageJSONTypeModule = 1; +static const uint32_t ResolvedSourceTagPackageJSONTypeModule = 1; typedef union ErrorableResolvedSourceResult { ResolvedSource value; ZigErrorType err; @@ -264,18 +264,7 @@ typedef struct { bool shared; } Bun__ArrayBuffer; -enum SyntheticModuleType : uint64_t { - ObjectModule = 2, - - Buffer = 1024, - Process = 1025, - Events = 1026, - StringDecoder = 1027, - Module = 1028, - TTY = 1029, - NodeUtilTypes = 1030, - Constants = 1031, -}; +#include "../../../js/out/SyntheticModuleType.h" extern "C" const char* Bun__userAgent; diff --git a/src/bun.js/bindings/node_util_types.h b/src/bun.js/bindings/node_util_types.h deleted file mode 100644 index adf0cd0ea..000000000 --- a/src/bun.js/bindings/node_util_types.h +++ /dev/null @@ -1,11 +0,0 @@ -#include "JavaScriptCore/JSGlobalObject.h" -#include "ZigGlobalObject.h" - -namespace Bun { -using namespace WebCore; - -void generateNodeUtilTypesSourceCode(JSC::JSGlobalObject* lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4>& exportNames, - JSC::MarkedArgumentBuffer& exportValues); -} diff --git a/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h b/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h index 391060426..a81b84577 100644 --- a/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h +++ b/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h @@ -40,6 +40,7 @@ public: std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForAsyncContextFrame; std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForMockWithImplementationCleanupData; std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForProcessObject; + std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForInternalModuleRegistry; #include "ZigGeneratedClasses+DOMClientIsoSubspaces.h" /* --- bun --- */ diff --git a/src/bun.js/bindings/webcore/DOMIsoSubspaces.h b/src/bun.js/bindings/webcore/DOMIsoSubspaces.h index 01f202a81..c67112388 100644 --- a/src/bun.js/bindings/webcore/DOMIsoSubspaces.h +++ b/src/bun.js/bindings/webcore/DOMIsoSubspaces.h @@ -40,6 +40,7 @@ public: std::unique_ptr<IsoSubspace> m_subspaceForAsyncContextFrame; std::unique_ptr<IsoSubspace> m_subspaceForMockWithImplementationCleanupData; std::unique_ptr<IsoSubspace> m_subspaceForProcessObject; + std::unique_ptr<IsoSubspace> m_subspaceForInternalModuleRegistry; #include "ZigGeneratedClasses+DOMIsoSubspaces.h" /*-- BUN --*/ diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 65f9bbf26..eaf97bb60 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -492,12 +492,6 @@ pub const RuntimeTranspilerStore = struct { continue; } - if (JSC.DisabledModule.has(import_record.path.text)) { - import_record.path.is_disabled = true; - import_record.do_commonjs_transform_in_printer = true; - continue; - } - if (bundler.options.rewrite_jest_for_tests) { if (strings.eqlComptime( import_record.path.text, @@ -1376,7 +1370,8 @@ pub const ModuleLoader = struct { } } - var allocator = arena.allocator(); + // var allocator = arena.allocator(); + var allocator = bun.default_allocator; var fd: ?StoredFileDescriptorType = null; var package_json: ?*PackageJSON = null; @@ -1634,7 +1629,7 @@ pub const ModuleLoader = struct { if (has_bun_plugin) { return ResolvedSource{ .allocator = null, - .source_code = String.static("// auto-generated plugin stub\nexport default undefined\n"), + .source_code = String.static("module.exports=undefined"), .specifier = input_specifier, .source_url = ZigString.init(path.text), // // TODO: change hash to a bitfield @@ -1781,16 +1776,10 @@ pub const ModuleLoader = struct { } return ResolvedSource{ .allocator = null, - .source_code = bun.String.static( - strings.append3( - bun.default_allocator, - JSC.Node.fs.constants_string, - @as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "node/wasi.js")), - @as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "bun/wasi-runner.js")), - ) catch unreachable, - ), + .source_code = bun.String.static(@embedFile("../js/wasi-runner.js")), .specifier = input_specifier, .source_url = ZigString.init(path.text), + .tag = .esm, .hash = 0, }; } @@ -2190,88 +2179,74 @@ pub const ModuleLoader = struct { .specifier = specifier, .source_url = ZigString.init(bun.asByteSlice(JSC.VirtualMachine.main_file_name)), .hash = 0, + .tag = .esm, }; }, + + // Native modules .@"node:buffer" => return jsSyntheticModule(.@"node:buffer", specifier), .@"node:string_decoder" => return jsSyntheticModule(.@"node:string_decoder", specifier), .@"node:module" => return jsSyntheticModule(.@"node:module", specifier), .@"node:process" => return jsSyntheticModule(.@"node:process", specifier), .@"node:tty" => return jsSyntheticModule(.@"node:tty", specifier), .@"node:util/types" => return jsSyntheticModule(.@"node:util/types", specifier), - .@"bun:events_native" => return jsSyntheticModule(.@"bun:events_native", specifier), .@"node:constants" => return jsSyntheticModule(.@"node:constants", specifier), - .@"node:fs/promises" => { - return ResolvedSource{ - .allocator = null, - .source_code = bun.String.static(comptime JSC.Node.fs.constants_string ++ @embedFile("../js/out/modules/node/fs.promises.js")), - .specifier = specifier, - .source_url = ZigString.init("node:fs/promises"), - .hash = 0, - }; - }, - .@"bun:ffi" => { - const shared_library_suffix = if (Environment.isMac) "dylib" else if (Environment.isLinux) "so" else if (Environment.isWindows) "dll" else ""; - return ResolvedSource{ - .allocator = null, - .source_code = bun.String.static( - comptime "export const FFIType=" ++ - JSC.FFI.ABIType.map_to_js_object ++ - ";export const suffix='" ++ shared_library_suffix ++ "';" ++ - @embedFile("../js/out/modules/bun/ffi.js"), - ), - .specifier = specifier, - .source_url = ZigString.init("bun:ffi"), - .hash = 0, - }; - }, - - .@"bun:jsc" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"bun:jsc", "bun/jsc.js", specifier), - .@"bun:sqlite" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"bun:sqlite", "bun/sqlite.js", specifier), - - .@"node:assert" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:assert", "node/assert.js", specifier), - .@"node:assert/strict" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:assert/strict", "node/assert.strict.js", specifier), - .@"node:async_hooks" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:async_hooks", "node/async_hooks.js", specifier), - .@"node:child_process" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:child_process", "node/child_process.js", specifier), - .@"node:crypto" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:crypto", "node/crypto.js", specifier), - .@"node:dns" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:dns", "node/dns.js", specifier), - .@"node:dns/promises" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:dns/promises", "node/dns.promises.js", specifier), - .@"node:events" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:child_process", "node/events.js", specifier), - .@"node:fs" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:fs", "node/fs.js", specifier), - .@"node:http" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:http", "node/http.js", specifier), - .@"node:https" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:https", "node/https.js", specifier), - .@"node:net" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:net", "node/net.js", specifier), - .@"node:os" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:os", "node/os.js", specifier), - .@"node:path" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:path", "node/path.js", specifier), - .@"node:path/posix" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:path/posix", "node/path.posix.js", specifier), - .@"node:path/win32" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:path/win32", "node/path.win32.js", specifier), - .@"node:perf_hooks" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:perf_hooks", "node/perf_hooks.js", specifier), - .@"node:readline" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:readline", "node/readline.js", specifier), - .@"node:readline/promises" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:readline/promises", "node/readline.promises.js", specifier), - .@"node:stream" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:stream", "node/stream.js", specifier), - .@"node:stream/consumers" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:stream/consumers", "node/stream.consumers.js", specifier), - .@"node:stream/promises" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:stream/promises", "node/stream.promises.js", specifier), - .@"node:stream/web" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:stream/web", "node/stream.web.js", specifier), - .@"node:timers" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:timers", "node/timers.js", specifier), - .@"node:timers/promises" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:timers/promises", "node/timers.promises.js", specifier), - .@"node:tls" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:tls", "node/tls.js", specifier), - .@"node:url" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:url", "node/url.js", specifier), - .@"node:util" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:util", "node/util.js", specifier), - .@"node:vm" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:vm", "node/vm.js", specifier), - .@"node:wasi" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:wasi", "node/wasi.js", specifier), - .@"node:zlib" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:zlib", "node/zlib.js", specifier), - - .@"detect-libc" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"detect-libc", if (Environment.isLinux) "thirdparty/detect-libc.linux.js" else "thirdparty/detect-libc.js", specifier), - .undici => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .undici, "thirdparty/undici.js", specifier), - .ws => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .ws, "thirdparty/ws.js", specifier), - - .@"node:cluster" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:cluster", "node/cluster.js", specifier), - .@"node:dgram" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:dgram", "node/dgram.js", specifier), - .@"node:diagnostics_channel" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:diagnostics_channel", "node/diagnostics_channel.js", specifier), - .@"node:http2" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:http2", "node/http2.js", specifier), - .@"node:inspector" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:inspector", "node/inspector.js", specifier), - .@"node:repl" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:repl", "node/repl.js", specifier), - .@"node:trace_events" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:trace_events", "node/trace_events.js", specifier), - .@"node:v8" => return jsResolvedSource(jsc_vm, jsc_vm.load_builtins_from_path, .@"node:v8", "node/v8.js", specifier), + .@"bun:jsc" => return jsSyntheticModule(.@"bun:jsc", specifier), + + // These are defined in src/js/* + .@"bun:ffi" => return jsSyntheticModule(.@"bun:ffi", specifier), + .@"bun:sqlite" => return jsSyntheticModule(.@"bun:sqlite", specifier), + .@"detect-libc" => return jsSyntheticModule(if (Environment.isLinux) .@"detect-libc/linux" else .@"detect-libc", specifier), + .@"node:assert" => return jsSyntheticModule(.@"node:assert", specifier), + .@"node:assert/strict" => return jsSyntheticModule(.@"node:assert/strict", specifier), + .@"node:async_hooks" => return jsSyntheticModule(.@"node:async_hooks", specifier), + .@"node:child_process" => return jsSyntheticModule(.@"node:child_process", specifier), + .@"node:cluster" => return jsSyntheticModule(.@"node:cluster", specifier), + .@"node:console" => return jsSyntheticModule(.@"node:console", specifier), + .@"node:crypto" => return jsSyntheticModule(.@"node:crypto", specifier), + .@"node:dgram" => return jsSyntheticModule(.@"node:dgram", specifier), + .@"node:diagnostics_channel" => return jsSyntheticModule(.@"node:diagnostics_channel", specifier), + .@"node:dns" => return jsSyntheticModule(.@"node:dns", specifier), + .@"node:dns/promises" => return jsSyntheticModule(.@"node:dns/promises", specifier), + .@"node:domain" => return jsSyntheticModule(.@"node:domain", specifier), + .@"node:events" => return jsSyntheticModule(.@"node:events", specifier), + .@"node:fs" => return jsSyntheticModule(.@"node:fs", specifier), + .@"node:fs/promises" => return jsSyntheticModule(.@"node:fs/promises", specifier), + .@"node:http" => return jsSyntheticModule(.@"node:http", specifier), + .@"node:http2" => return jsSyntheticModule(.@"node:http2", specifier), + .@"node:https" => return jsSyntheticModule(.@"node:https", specifier), + .@"node:inspector" => return jsSyntheticModule(.@"node:inspector", specifier), + .@"node:net" => return jsSyntheticModule(.@"node:net", specifier), + .@"node:os" => return jsSyntheticModule(.@"node:os", specifier), + .@"node:path" => return jsSyntheticModule(.@"node:path", specifier), + .@"node:path/posix" => return jsSyntheticModule(.@"node:path/posix", specifier), + .@"node:path/win32" => return jsSyntheticModule(.@"node:path/win32", specifier), + .@"node:punycode" => return jsSyntheticModule(.@"node:punycode", specifier), + .@"node:perf_hooks" => return jsSyntheticModule(.@"node:perf_hooks", specifier), + .@"node:querystring" => return jsSyntheticModule(.@"node:querystring", specifier), + .@"node:readline" => return jsSyntheticModule(.@"node:readline", specifier), + .@"node:readline/promises" => return jsSyntheticModule(.@"node:readline/promises", specifier), + .@"node:repl" => return jsSyntheticModule(.@"node:repl", specifier), + .@"node:stream" => return jsSyntheticModule(.@"node:stream", specifier), + .@"node:stream/consumers" => return jsSyntheticModule(.@"node:stream/consumers", specifier), + .@"node:stream/promises" => return jsSyntheticModule(.@"node:stream/promises", specifier), + .@"node:stream/web" => return jsSyntheticModule(.@"node:stream/web", specifier), + .@"node:timers" => return jsSyntheticModule(.@"node:timers", specifier), + .@"node:timers/promises" => return jsSyntheticModule(.@"node:timers/promises", specifier), + .@"node:tls" => return jsSyntheticModule(.@"node:tls", specifier), + .@"node:trace_events" => return jsSyntheticModule(.@"node:trace_events", specifier), + .@"node:url" => return jsSyntheticModule(.@"node:url", specifier), + .@"node:util" => return jsSyntheticModule(.@"node:util", specifier), + .@"node:v8" => return jsSyntheticModule(.@"node:v8", specifier), + .@"node:vm" => return jsSyntheticModule(.@"node:vm", specifier), + .@"node:wasi" => return jsSyntheticModule(.@"node:wasi", specifier), + .@"node:worker_threads" => return jsSyntheticModule(.@"node:worker_threads", specifier), + .@"node:zlib" => return jsSyntheticModule(.@"node:zlib", specifier), + .@"isomorphic-fetch" => return jsSyntheticModule(.@"isomorphic-fetch", specifier), + .@"node-fetch" => return jsSyntheticModule(.@"node-fetch", specifier), + .@"@vercel/fetch" => return jsSyntheticModule(.vercel_fetch, specifier), + .undici => return jsSyntheticModule(.undici, specifier), + .ws => return jsSyntheticModule(.ws, specifier), } } else if (specifier.hasPrefixComptime(js_ast.Macro.namespaceWithColon)) { const spec = specifier.toUTF8(bun.default_allocator); @@ -2285,20 +2260,6 @@ pub const ModuleLoader = struct { .hash = 0, }; } - } else if (DisabledModule.getWithEql(specifier, bun.String.eqlComptime) != null) { - return ResolvedSource{ - .allocator = null, - .source_code = bun.String.static( - \\var masqueradesAsUndefined=globalThis[Symbol.for("Bun.lazy")]("masqueradesAsUndefined"); - \\masqueradesAsUndefined[Symbol.for("CommonJS")]=0; - \\masqueradesAsUndefined.default=masqueradesAsUndefined; - \\export default masqueradesAsUndefined; - \\ - ), - .specifier = specifier, - .source_url = specifier.toZigString(), - .hash = 0, - }; } else if (jsc_vm.standalone_module_graph) |graph| { const specifier_utf8 = specifier.toUTF8(bun.default_allocator); defer specifier_utf8.deinit(); @@ -2405,17 +2366,18 @@ pub const HardcodedModule = enum { @"bun:jsc", @"bun:main", @"bun:sqlite", - @"bun:events_native", @"detect-libc", @"node:assert", @"node:assert/strict", @"node:async_hooks", @"node:buffer", @"node:child_process", - @"node:crypto", + @"node:console", @"node:constants", + @"node:crypto", @"node:dns", @"node:dns/promises", + @"node:domain", @"node:events", @"node:fs", @"node:fs/promises", @@ -2429,6 +2391,7 @@ pub const HardcodedModule = enum { @"node:path/win32", @"node:perf_hooks", @"node:process", + @"node:querystring", @"node:readline", @"node:readline/promises", @"node:stream", @@ -2445,9 +2408,14 @@ pub const HardcodedModule = enum { @"node:util/types", @"node:vm", @"node:wasi", + @"node:worker_threads", @"node:zlib", + @"node:punycode", undici, ws, + @"isomorphic-fetch", + @"node-fetch", + @"@vercel/fetch", // These are all not implemented yet, but are stubbed @"node:v8", @"node:trace_events", @@ -2470,7 +2438,6 @@ pub const HardcodedModule = enum { .{ "bun:jsc", HardcodedModule.@"bun:jsc" }, .{ "bun:main", HardcodedModule.@"bun:main" }, .{ "bun:sqlite", HardcodedModule.@"bun:sqlite" }, - .{ "bun:events_native", HardcodedModule.@"bun:events_native" }, .{ "detect-libc", HardcodedModule.@"detect-libc" }, .{ "node:assert", HardcodedModule.@"node:assert" }, .{ "node:assert/strict", HardcodedModule.@"node:assert/strict" }, @@ -2478,12 +2445,14 @@ pub const HardcodedModule = enum { .{ "node:buffer", HardcodedModule.@"node:buffer" }, .{ "node:child_process", HardcodedModule.@"node:child_process" }, .{ "node:cluster", HardcodedModule.@"node:cluster" }, - .{ "node:crypto", HardcodedModule.@"node:crypto" }, + .{ "node:console", HardcodedModule.@"node:console" }, .{ "node:constants", HardcodedModule.@"node:constants" }, + .{ "node:crypto", HardcodedModule.@"node:crypto" }, .{ "node:dgram", HardcodedModule.@"node:dgram" }, .{ "node:diagnostics_channel", HardcodedModule.@"node:diagnostics_channel" }, .{ "node:dns", HardcodedModule.@"node:dns" }, .{ "node:dns/promises", HardcodedModule.@"node:dns/promises" }, + .{ "node:domain", HardcodedModule.@"node:domain" }, .{ "node:events", HardcodedModule.@"node:events" }, .{ "node:fs", HardcodedModule.@"node:fs" }, .{ "node:fs/promises", HardcodedModule.@"node:fs/promises" }, @@ -2497,8 +2466,12 @@ pub const HardcodedModule = enum { .{ "node:path", HardcodedModule.@"node:path" }, .{ "node:path/posix", HardcodedModule.@"node:path/posix" }, .{ "node:path/win32", HardcodedModule.@"node:path/win32" }, + .{ "node:punycode", HardcodedModule.@"node:punycode" }, .{ "node:perf_hooks", HardcodedModule.@"node:perf_hooks" }, .{ "node:process", HardcodedModule.@"node:process" }, + .{ "node:querystring", HardcodedModule.@"node:querystring" }, + .{ "node-fetch", HardcodedModule.@"node-fetch" }, + .{ "isomorphic-fetch", HardcodedModule.@"isomorphic-fetch" }, .{ "node:readline", HardcodedModule.@"node:readline" }, .{ "node:readline/promises", HardcodedModule.@"node:readline/promises" }, .{ "node:repl", HardcodedModule.@"node:repl" }, @@ -2518,9 +2491,11 @@ pub const HardcodedModule = enum { .{ "node:v8", HardcodedModule.@"node:v8" }, .{ "node:vm", HardcodedModule.@"node:vm" }, .{ "node:wasi", HardcodedModule.@"node:wasi" }, + .{ "node:worker_threads", HardcodedModule.@"node:worker_threads" }, .{ "node:zlib", HardcodedModule.@"node:zlib" }, .{ "undici", HardcodedModule.undici }, .{ "ws", HardcodedModule.ws }, + .{ "@vercel/fetch", HardcodedModule.@"@vercel/fetch" }, }, ); pub const Alias = struct { @@ -2535,7 +2510,6 @@ pub const HardcodedModule = enum { .{ "async_hooks", .{ .path = "node:async_hooks" } }, .{ "buffer", .{ .path = "node:buffer" } }, .{ "bun", .{ .path = "bun", .tag = .bun } }, - .{ "bun:events_native", .{ .path = "bun:events_native" } }, .{ "bun:ffi", .{ .path = "bun:ffi" } }, .{ "bun:jsc", .{ .path = "bun:jsc" } }, .{ "bun:sqlite", .{ .path = "bun:sqlite" } }, @@ -2561,6 +2535,14 @@ pub const HardcodedModule = enum { .{ "node:buffer", .{ .path = "node:buffer" } }, .{ "node:child_process", .{ .path = "node:child_process" } }, .{ "node:constants", .{ .path = "node:constants" } }, + .{ "node:console", .{ .path = "node:console" } }, + .{ "node:querystring", .{ .path = "node:querystring" } }, + .{ "querystring", .{ .path = "node:querystring" } }, + .{ "node:domain", .{ .path = "node:domain" } }, + .{ "domain", .{ .path = "node:domain" } }, + .{ "@vercel/fetch", .{ .path = "@vercel/fetch" } }, + .{ "node:punycode", .{ .path = "node:punycode" } }, + .{ "punycode", .{ .path = "node:punycode" } }, .{ "node:crypto", .{ .path = "node:crypto" } }, .{ "node:dns", .{ .path = "node:dns" } }, .{ "node:dns/promises", .{ .path = "node:dns/promises" } }, @@ -2667,29 +2649,13 @@ pub const HardcodedModule = enum { .{ "node:trace_events", .{ .path = "node:trace_events" } }, .{ "node:v8", .{ .path = "node:v8" } }, .{ "node:vm", .{ .path = "node:vm" } }, + + .{ "node:sys", .{ .path = "node:util" } }, + .{ "sys", .{ .path = "node:util" } }, + + .{ "node-fetch", .{ .path = "node-fetch" } }, + .{ "isomorphic-fetch", .{ .path = "isomorphic-fetch" } }, + .{ "@vercel/fetch", .{ .path = "@vercel/fetch" } }, }, ); }; - -pub const DisabledModule = bun.ComptimeStringMap( - void, - .{ - // Stubbing out worker_threads will break esbuild. - .{"worker_threads"}, - .{"node:worker_threads"}, - }, -); - -fn jsResolvedSource(vm: *JSC.VirtualMachine, builtins: []const u8, comptime module: HardcodedModule, comptime input: []const u8, specifier: bun.String) ResolvedSource { - // We use RefCountedResolvedSource because we want a stable StringImpl* - // pointer so that the SourceProviderCache has the maximum hit rate - return vm.refCountedResolvedSource( - jsModuleFromFile(builtins, input), - specifier, - @tagName(module), - null, - - // we never want to free these - true, - ); -} diff --git a/src/bun.js/modules/BunJSCModule.h b/src/bun.js/modules/BunJSCModule.h new file mode 100644 index 000000000..c5350fcd7 --- /dev/null +++ b/src/bun.js/modules/BunJSCModule.h @@ -0,0 +1,731 @@ +#include "_NativeModule.h" + +#include "ExceptionOr.h" +#include "JavaScriptCore/APICast.h" +#include "JavaScriptCore/AggregateError.h" +#include "JavaScriptCore/BytecodeIndex.h" +#include "JavaScriptCore/CallFrameInlines.h" +#include "JavaScriptCore/ClassInfo.h" +#include "JavaScriptCore/CodeBlock.h" +#include "JavaScriptCore/Completion.h" +#include "JavaScriptCore/DeferTermination.h" +#include "JavaScriptCore/Error.h" +#include "JavaScriptCore/ErrorInstance.h" +#include "JavaScriptCore/HeapSnapshotBuilder.h" +#include "JavaScriptCore/JIT.h" +#include "JavaScriptCore/JSBasePrivate.h" +#include "JavaScriptCore/JSCInlines.h" +#include "JavaScriptCore/JSONObject.h" +#include "JavaScriptCore/JavaScript.h" +#include "JavaScriptCore/ObjectConstructor.h" +#include "JavaScriptCore/SamplingProfiler.h" +#include "JavaScriptCore/TestRunnerUtils.h" +#include "JavaScriptCore/VMTrapsInlines.h" +#include "MessagePort.h" +#include "SerializedScriptValue.h" +#include "wtf/FileSystem.h" +#include "wtf/MemoryFootprint.h" +#include "wtf/text/WTFString.h" + +#include "Process.h" + +#if ENABLE(REMOTE_INSPECTOR) +#include "JavaScriptCore/RemoteInspectorServer.h" +#endif + +#include "JSDOMConvertBase.h" +#include "mimalloc.h" + +using namespace JSC; +using namespace WTF; +using namespace WebCore; + +JSC_DECLARE_HOST_FUNCTION(functionStartRemoteDebugger); +JSC_DEFINE_HOST_FUNCTION(functionStartRemoteDebugger, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { +#if ENABLE(REMOTE_INSPECTOR) + static const char *defaultHost = "127.0.0.1\0"; + static uint16_t defaultPort = 9230; // node + 1 + auto &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + JSC::JSValue hostValue = callFrame->argument(0); + JSC::JSValue portValue = callFrame->argument(1); + const char *host = defaultHost; + if (hostValue.isString()) { + + auto str = hostValue.toWTFString(globalObject); + if (!str.isEmpty()) + host = toCString(str).data(); + } else if (!hostValue.isUndefined()) { + throwVMError(globalObject, scope, + createTypeError(globalObject, "host must be a string"_s)); + return JSC::JSValue::encode(JSC::jsUndefined()); + } + + uint16_t port = defaultPort; + if (portValue.isNumber()) { + auto port_int = portValue.toUInt32(globalObject); + if (!(port_int > 0 && port_int < 65536)) { + throwVMError( + globalObject, scope, + createRangeError(globalObject, "port must be between 0 and 65535"_s)); + return JSC::JSValue::encode(JSC::jsUndefined()); + } + port = port_int; + } else if (!portValue.isUndefined()) { + throwVMError( + globalObject, scope, + createTypeError(globalObject, + "port must be a number between 0 and 65535"_s)); + return JSC::JSValue::encode(JSC::jsUndefined()); + } + + globalObject->setInspectable(true); + auto &server = Inspector::RemoteInspectorServer::singleton(); + if (!server.start(reinterpret_cast<const char *>(host), port)) { + throwVMError( + globalObject, scope, + createError(globalObject, "Failed to start server \""_s + host + ":"_s + + port + "\". Is port already in use?"_s)); + return JSC::JSValue::encode(JSC::jsUndefined()); + } + + RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsUndefined())); +#else + auto &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + throwVMError(globalObject, scope, + createTypeError( + globalObject, + "Remote inspector is not enabled in this build of Bun"_s)); + return JSC::JSValue::encode(JSC::jsUndefined()); +#endif +} + +JSC_DECLARE_HOST_FUNCTION(functionDescribe); +JSC_DEFINE_HOST_FUNCTION(functionDescribe, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + if (callFrame->argumentCount() < 1) + return JSValue::encode(jsUndefined()); + return JSValue::encode(jsString(vm, toString(callFrame->argument(0)))); +} + +JSC_DECLARE_HOST_FUNCTION(functionDescribeArray); +JSC_DEFINE_HOST_FUNCTION(functionDescribeArray, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + if (callFrame->argumentCount() < 1) + return JSValue::encode(jsUndefined()); + VM &vm = globalObject->vm(); + JSObject *object = jsDynamicCast<JSObject *>(callFrame->argument(0)); + if (!object) + return JSValue::encode(jsNontrivialString(vm, "<not object>"_s)); + return JSValue::encode(jsNontrivialString( + vm, toString("<Butterfly: ", RawPointer(object->butterfly()), + "; public length: ", object->getArrayLength(), + "; vector length: ", object->getVectorLength(), ">"))); +} + +JSC_DECLARE_HOST_FUNCTION(functionGCAndSweep); +JSC_DEFINE_HOST_FUNCTION(functionGCAndSweep, + (JSGlobalObject * globalObject, CallFrame *)) { + VM &vm = globalObject->vm(); + JSLockHolder lock(vm); + vm.heap.collectNow(Sync, CollectionScope::Full); + return JSValue::encode(jsNumber(vm.heap.sizeAfterLastFullCollection())); +} + +JSC_DECLARE_HOST_FUNCTION(functionFullGC); +JSC_DEFINE_HOST_FUNCTION(functionFullGC, + (JSGlobalObject * globalObject, CallFrame *)) { + VM &vm = globalObject->vm(); + JSLockHolder lock(vm); + vm.heap.collectSync(CollectionScope::Full); + return JSValue::encode(jsNumber(vm.heap.sizeAfterLastFullCollection())); +} + +JSC_DECLARE_HOST_FUNCTION(functionEdenGC); +JSC_DEFINE_HOST_FUNCTION(functionEdenGC, + (JSGlobalObject * globalObject, CallFrame *)) { + VM &vm = globalObject->vm(); + JSLockHolder lock(vm); + vm.heap.collectSync(CollectionScope::Eden); + return JSValue::encode(jsNumber(vm.heap.sizeAfterLastEdenCollection())); +} + +JSC_DECLARE_HOST_FUNCTION(functionHeapSize); +JSC_DEFINE_HOST_FUNCTION(functionHeapSize, + (JSGlobalObject * globalObject, CallFrame *)) { + VM &vm = globalObject->vm(); + JSLockHolder lock(vm); + return JSValue::encode(jsNumber(vm.heap.size())); +} + +JSC::Structure * +createMemoryFootprintStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject) { + + JSC::Structure *structure = + globalObject->structureCache().emptyObjectStructureForPrototype( + globalObject, globalObject->objectPrototype(), 5); + JSC::PropertyOffset offset; + + structure = structure->addPropertyTransition( + vm, structure, Identifier::fromString(vm, "current"_s), 0, offset); + structure = structure->addPropertyTransition( + vm, structure, Identifier::fromString(vm, "peak"_s), 0, offset); + structure = structure->addPropertyTransition( + vm, structure, Identifier::fromString(vm, "currentCommit"_s), 0, offset); + structure = structure->addPropertyTransition( + vm, structure, Identifier::fromString(vm, "peakCommit"_s), 0, offset); + structure = structure->addPropertyTransition( + vm, structure, Identifier::fromString(vm, "pageFaults"_s), 0, offset); + + return structure; +} + +JSC_DECLARE_HOST_FUNCTION(functionMemoryUsageStatistics); +JSC_DEFINE_HOST_FUNCTION(functionMemoryUsageStatistics, + (JSGlobalObject * globalObject, CallFrame *)) { + + auto &vm = globalObject->vm(); + JSC::DisallowGC disallowGC; + + // this is a C API function + auto *stats = toJS(JSGetMemoryUsageStatistics(toRef(globalObject))); + + if (JSValue heapSizeValue = + stats->getDirect(vm, Identifier::fromString(vm, "heapSize"_s))) { + ASSERT(heapSizeValue.isNumber()); + if (heapSizeValue.toInt32(globalObject) == 0) { + vm.heap.collectNow(Sync, CollectionScope::Full); + stats = toJS(JSGetMemoryUsageStatistics(toRef(globalObject))); + } + } + + // This is missing from the C API + JSC::JSObject *protectedCounts = constructEmptyObject(globalObject); + auto typeCounts = *vm.heap.protectedObjectTypeCounts(); + for (auto &it : typeCounts) + protectedCounts->putDirect(vm, Identifier::fromLatin1(vm, it.key), + jsNumber(it.value)); + + stats->putDirect(vm, + Identifier::fromLatin1(vm, "protectedObjectTypeCounts"_s), + protectedCounts); + return JSValue::encode(stats); +} + +JSC_DECLARE_HOST_FUNCTION(functionCreateMemoryFootprint); +JSC_DEFINE_HOST_FUNCTION(functionCreateMemoryFootprint, + (JSGlobalObject * globalObject, CallFrame *)) { + + size_t elapsed_msecs = 0; + size_t user_msecs = 0; + size_t system_msecs = 0; + size_t current_rss = 0; + size_t peak_rss = 0; + size_t current_commit = 0; + size_t peak_commit = 0; + size_t page_faults = 0; + + mi_process_info(&elapsed_msecs, &user_msecs, &system_msecs, ¤t_rss, + &peak_rss, ¤t_commit, &peak_commit, &page_faults); + + // mi_process_info produces incorrect rss size on linux. + Zig::getRSS(¤t_rss); + + VM &vm = globalObject->vm(); + JSC::JSObject *object = JSC::constructEmptyObject( + vm, JSC::jsCast<Zig::GlobalObject *>(globalObject) + ->memoryFootprintStructure()); + + object->putDirectOffset(vm, 0, jsNumber(current_rss)); + object->putDirectOffset(vm, 1, jsNumber(peak_rss)); + object->putDirectOffset(vm, 2, jsNumber(current_commit)); + object->putDirectOffset(vm, 3, jsNumber(peak_commit)); + object->putDirectOffset(vm, 4, jsNumber(page_faults)); + + return JSValue::encode(object); +} + +JSC_DECLARE_HOST_FUNCTION(functionNeverInlineFunction); +JSC_DEFINE_HOST_FUNCTION(functionNeverInlineFunction, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + return JSValue::encode(setNeverInline(globalObject, callFrame)); +} + +extern "C" bool Bun__mkdirp(JSC::JSGlobalObject *, const char *); + +JSC_DECLARE_HOST_FUNCTION(functionStartSamplingProfiler); +JSC_DEFINE_HOST_FUNCTION(functionStartSamplingProfiler, + (JSC::JSGlobalObject * globalObject, + JSC::CallFrame *callFrame)) { + JSC::VM &vm = globalObject->vm(); + JSC::SamplingProfiler &samplingProfiler = + vm.ensureSamplingProfiler(WTF::Stopwatch::create()); + + JSC::JSValue directoryValue = callFrame->argument(0); + JSC::JSValue sampleValue = callFrame->argument(1); + + auto scope = DECLARE_THROW_SCOPE(vm); + if (directoryValue.isString()) { + auto path = directoryValue.toWTFString(globalObject); + if (!path.isEmpty()) { + StringPrintStream pathOut; + auto pathCString = toCString(String(path)); + if (!Bun__mkdirp(globalObject, pathCString.data())) { + throwVMError( + globalObject, scope, + createTypeError(globalObject, "directory couldn't be created"_s)); + return JSC::JSValue::encode(jsUndefined()); + } + + Options::samplingProfilerPath() = pathCString.data(); + samplingProfiler.registerForReportAtExit(); + } + } + if (sampleValue.isNumber()) { + unsigned sampleInterval = sampleValue.toUInt32(globalObject); + samplingProfiler.setTimingInterval( + Seconds::fromMicroseconds(sampleInterval)); + } + + samplingProfiler.noticeCurrentThreadAsJSCExecutionThread(); + samplingProfiler.start(); + return JSC::JSValue::encode(jsUndefined()); +} + +JSC_DECLARE_HOST_FUNCTION(functionSamplingProfilerStackTraces); +JSC_DEFINE_HOST_FUNCTION(functionSamplingProfilerStackTraces, + (JSC::JSGlobalObject * globalObject, + JSC::CallFrame *)) { + JSC::VM &vm = globalObject->vm(); + JSC::DeferTermination deferScope(vm); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!vm.samplingProfiler()) + return JSC::JSValue::encode(throwException( + globalObject, scope, + createError(globalObject, "Sampling profiler was never started"_s))); + + WTF::String jsonString = vm.samplingProfiler()->stackTracesAsJSON(); + JSC::EncodedJSValue result = + JSC::JSValue::encode(JSONParse(globalObject, jsonString)); + scope.releaseAssertNoException(); + return result; +} + +JSC_DECLARE_HOST_FUNCTION(functionGetRandomSeed); +JSC_DEFINE_HOST_FUNCTION(functionGetRandomSeed, + (JSGlobalObject * globalObject, CallFrame *)) { + return JSValue::encode(jsNumber(globalObject->weakRandom().seed())); +} + +JSC_DECLARE_HOST_FUNCTION(functionSetRandomSeed); +JSC_DEFINE_HOST_FUNCTION(functionSetRandomSeed, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + unsigned seed = callFrame->argument(0).toUInt32(globalObject); + RETURN_IF_EXCEPTION(scope, encodedJSValue()); + globalObject->weakRandom().setSeed(seed); + return JSValue::encode(jsUndefined()); +} + +JSC_DECLARE_HOST_FUNCTION(functionIsRope); +JSC_DEFINE_HOST_FUNCTION(functionIsRope, + (JSGlobalObject *, CallFrame *callFrame)) { + JSValue argument = callFrame->argument(0); + if (!argument.isString()) + return JSValue::encode(jsBoolean(false)); + const StringImpl *impl = asString(argument)->tryGetValueImpl(); + return JSValue::encode(jsBoolean(!impl)); +} + +JSC_DECLARE_HOST_FUNCTION(functionCallerSourceOrigin); +JSC_DEFINE_HOST_FUNCTION(functionCallerSourceOrigin, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + if (sourceOrigin.url().isNull()) + return JSValue::encode(jsNull()); + return JSValue::encode(jsString(vm, sourceOrigin.string())); +} + +JSC_DECLARE_HOST_FUNCTION(functionNoFTL); +JSC_DEFINE_HOST_FUNCTION(functionNoFTL, + (JSGlobalObject *, CallFrame *callFrame)) { + if (callFrame->argumentCount()) { + FunctionExecutable *executable = + getExecutableForFunction(callFrame->argument(0)); + if (executable) + executable->setNeverFTLOptimize(true); + } + return JSValue::encode(jsUndefined()); +} + +JSC_DECLARE_HOST_FUNCTION(functionNoOSRExitFuzzing); +JSC_DEFINE_HOST_FUNCTION(functionNoOSRExitFuzzing, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + return JSValue::encode(setCannotUseOSRExitFuzzing(globalObject, callFrame)); +} + +JSC_DECLARE_HOST_FUNCTION(functionOptimizeNextInvocation); +JSC_DEFINE_HOST_FUNCTION(functionOptimizeNextInvocation, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + return JSValue::encode(optimizeNextInvocation(globalObject, callFrame)); +} + +JSC_DECLARE_HOST_FUNCTION(functionNumberOfDFGCompiles); +JSC_DEFINE_HOST_FUNCTION(functionNumberOfDFGCompiles, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + return JSValue::encode(numberOfDFGCompiles(globalObject, callFrame)); +} + +JSC_DECLARE_HOST_FUNCTION(functionReleaseWeakRefs); +JSC_DEFINE_HOST_FUNCTION(functionReleaseWeakRefs, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + globalObject->vm().finalizeSynchronousJSExecution(); + return JSValue::encode(jsUndefined()); +} + +JSC_DECLARE_HOST_FUNCTION(functionTotalCompileTime); +JSC_DEFINE_HOST_FUNCTION(functionTotalCompileTime, + (JSGlobalObject *, CallFrame *)) { + return JSValue::encode(jsNumber(JIT::totalCompileTime().milliseconds())); +} + +JSC_DECLARE_HOST_FUNCTION(functionGetProtectedObjects); +JSC_DEFINE_HOST_FUNCTION(functionGetProtectedObjects, + (JSGlobalObject * globalObject, CallFrame *)) { + MarkedArgumentBuffer list; + size_t result = 0; + globalObject->vm().heap.forEachProtectedCell( + [&](JSCell *cell) { list.append(cell); }); + RELEASE_ASSERT(!list.hasOverflowed()); + return JSC::JSValue::encode(constructArray( + globalObject, static_cast<JSC::ArrayAllocationProfile *>(nullptr), list)); +} + +JSC_DECLARE_HOST_FUNCTION(functionReoptimizationRetryCount); +JSC_DEFINE_HOST_FUNCTION(functionReoptimizationRetryCount, + (JSGlobalObject *, CallFrame *callFrame)) { + if (callFrame->argumentCount() < 1) + return JSValue::encode(jsUndefined()); + + CodeBlock *block = + getSomeBaselineCodeBlockForFunction(callFrame->argument(0)); + if (!block) + return JSValue::encode(jsNumber(0)); + + return JSValue::encode(jsNumber(block->reoptimizationRetryCounter())); +} + +extern "C" void Bun__drainMicrotasks(); + +JSC_DECLARE_HOST_FUNCTION(functionDrainMicrotasks); +JSC_DEFINE_HOST_FUNCTION(functionDrainMicrotasks, + (JSGlobalObject * globalObject, CallFrame *)) { + VM &vm = globalObject->vm(); + vm.drainMicrotasks(); + Bun__drainMicrotasks(); + return JSValue::encode(jsUndefined()); +} + +JSC_DEFINE_HOST_FUNCTION(functionSetTimeZone, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (callFrame->argumentCount() < 1) { + throwTypeError(globalObject, scope, + "setTimeZone requires a timezone string"_s); + return encodedJSValue(); + } + + if (!callFrame->argument(0).isString()) { + throwTypeError(globalObject, scope, + "setTimeZone requires a timezone string"_s); + return encodedJSValue(); + } + + String timeZoneName = callFrame->argument(0).toWTFString(globalObject); + RETURN_IF_EXCEPTION(scope, encodedJSValue()); + + double time = callFrame->argument(1).toNumber(globalObject); + RETURN_IF_EXCEPTION(scope, encodedJSValue()); + + if (!WTF::setTimeZoneOverride(timeZoneName)) { + throwTypeError(globalObject, scope, + makeString("Invalid timezone: \""_s, timeZoneName, "\""_s)); + return encodedJSValue(); + } + vm.dateCache.resetIfNecessarySlow(); + WTF::Vector<UChar, 32> buffer; + WTF::getTimeZoneOverride(buffer); + WTF::String timeZoneString(buffer.data(), buffer.size()); + return JSValue::encode(jsString(vm, timeZoneString)); +} + +JSC_DEFINE_HOST_FUNCTION(functionRunProfiler, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + JSC::VM &vm = globalObject->vm(); + JSC::SamplingProfiler &samplingProfiler = + vm.ensureSamplingProfiler(WTF::Stopwatch::create()); + + JSC::JSValue callbackValue = callFrame->argument(0); + auto throwScope = DECLARE_THROW_SCOPE(vm); + if (callbackValue.isUndefinedOrNull() || !callbackValue.isCallable()) { + throwException( + globalObject, throwScope, + createTypeError(globalObject, "First argument must be a function."_s)); + return JSValue::encode(JSValue{}); + } + + JSC::JSFunction *function = jsCast<JSC::JSFunction *>(callbackValue); + + JSC::JSValue sampleValue = callFrame->argument(1); + if (sampleValue.isNumber()) { + unsigned sampleInterval = sampleValue.toUInt32(globalObject); + samplingProfiler.setTimingInterval( + Seconds::fromMicroseconds(sampleInterval)); + } + + JSC::CallData callData = JSC::getCallData(function); + MarkedArgumentBuffer args; + + samplingProfiler.noticeCurrentThreadAsJSCExecutionThread(); + samplingProfiler.start(); + JSC::call(globalObject, function, callData, JSC::jsUndefined(), args); + samplingProfiler.pause(); + if (throwScope.exception()) { + samplingProfiler.shutdown(); + samplingProfiler.clearData(); + return JSValue::encode(JSValue{}); + } + + StringPrintStream topFunctions; + samplingProfiler.reportTopFunctions(topFunctions); + + StringPrintStream byteCodes; + samplingProfiler.reportTopBytecodes(byteCodes); + + JSValue stackTraces = + JSONParse(globalObject, samplingProfiler.stackTracesAsJSON()); + + samplingProfiler.shutdown(); + samplingProfiler.clearData(); + + JSObject *result = + constructEmptyObject(globalObject, globalObject->objectPrototype(), 3); + result->putDirect(vm, Identifier::fromString(vm, "functions"_s), + jsString(vm, topFunctions.toString())); + result->putDirect(vm, Identifier::fromString(vm, "bytecodes"_s), + jsString(vm, byteCodes.toString())); + result->putDirect(vm, Identifier::fromString(vm, "stackTraces"_s), + stackTraces); + + return JSValue::encode(result); +} + +JSC_DECLARE_HOST_FUNCTION(functionGenerateHeapSnapshotForDebugging); +JSC_DEFINE_HOST_FUNCTION(functionGenerateHeapSnapshotForDebugging, + (JSGlobalObject * globalObject, CallFrame *)) { + VM &vm = globalObject->vm(); + JSLockHolder lock(vm); + DeferTermination deferScope(vm); + auto scope = DECLARE_THROW_SCOPE(vm); + String jsonString; + { + DeferGCForAWhile deferGC(vm); // Prevent concurrent GC from interfering with + // the full GC that the snapshot does. + + HeapSnapshotBuilder snapshotBuilder( + vm.ensureHeapProfiler(), + HeapSnapshotBuilder::SnapshotType::GCDebuggingSnapshot); + snapshotBuilder.buildSnapshot(); + + jsonString = snapshotBuilder.json(); + } + scope.releaseAssertNoException(); + + return JSValue::encode(JSONParse(globalObject, WTFMove(jsonString))); +} + +JSC_DEFINE_HOST_FUNCTION(functionSerialize, + (JSGlobalObject * lexicalGlobalObject, + CallFrame *callFrame)) { + auto *globalObject = jsCast<JSDOMGlobalObject *>(lexicalGlobalObject); + JSC::VM &vm = globalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + + JSValue value = callFrame->argument(0); + JSValue optionsObject = callFrame->argument(1); + bool asNodeBuffer = false; + if (optionsObject.isObject()) { + JSC::JSObject *options = optionsObject.getObject(); + if (JSC::JSValue binaryTypeValue = options->getIfPropertyExists( + globalObject, JSC::Identifier::fromString(vm, "binaryType"_s))) { + if (!binaryTypeValue.isString()) { + throwTypeError(globalObject, throwScope, + "binaryType must be a string"_s); + return JSValue::encode(jsUndefined()); + } + + asNodeBuffer = + binaryTypeValue.toWTFString(globalObject) == "nodebuffer"_s; + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + } + } + + Vector<JSC::Strong<JSC::JSObject>> transferList; + Vector<RefPtr<MessagePort>> dummyPorts; + ExceptionOr<Ref<SerializedScriptValue>> serialized = + SerializedScriptValue::create(*globalObject, value, WTFMove(transferList), + dummyPorts); + + if (serialized.hasException()) { + WebCore::propagateException(*globalObject, throwScope, + serialized.releaseException()); + return JSValue::encode(jsUndefined()); + } + + auto serializedValue = serialized.releaseReturnValue(); + auto arrayBuffer = serializedValue->toArrayBuffer(); + + if (asNodeBuffer) { + size_t byteLength = arrayBuffer->byteLength(); + JSC::JSUint8Array *uint8Array = JSC::JSUint8Array::create( + lexicalGlobalObject, globalObject->JSBufferSubclassStructure(), + WTFMove(arrayBuffer), 0, byteLength); + return JSValue::encode(uint8Array); + } + + if (arrayBuffer->isShared()) { + return JSValue::encode( + JSArrayBuffer::create(vm, + globalObject->arrayBufferStructureWithSharingMode< + ArrayBufferSharingMode::Shared>(), + WTFMove(arrayBuffer))); + } + + return JSValue::encode(JSArrayBuffer::create( + vm, globalObject->arrayBufferStructure(), WTFMove(arrayBuffer))); +} +JSC_DEFINE_HOST_FUNCTION(functionDeserialize, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + JSC::VM &vm = globalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSValue value = callFrame->argument(0); + + JSValue result; + + if (auto *jsArrayBuffer = jsDynamicCast<JSArrayBuffer *>(value)) { + result = SerializedScriptValue::fromArrayBuffer( + *globalObject, globalObject, jsArrayBuffer->impl(), 0, + jsArrayBuffer->impl()->byteLength()); + } else if (auto *view = jsDynamicCast<JSArrayBufferView *>(value)) { + auto arrayBuffer = view->possiblySharedImpl()->possiblySharedBuffer(); + result = SerializedScriptValue::fromArrayBuffer( + *globalObject, globalObject, arrayBuffer.get(), view->byteOffset(), + view->byteLength()); + } else { + throwTypeError(globalObject, throwScope, + "First argument must be an ArrayBuffer"_s); + return JSValue::encode(jsUndefined()); + } + + RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined())); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + +// clang-format off +/* Source for BunJSCModuleTable.lut.h +@begin BunJSCModuleTable + callerSourceOrigin functionCallerSourceOrigin Function 0 + jscDescribe functionDescribe Function 0 + jscDescribeArray functionDescribeArray Function 0 + drainMicrotasks functionDrainMicrotasks Function 0 + edenGC functionEdenGC Function 0 + fullGC functionFullGC Function 0 + gcAndSweep functionGCAndSweep Function 0 + getRandomSeed functionGetRandomSeed Function 0 + heapSize functionHeapSize Function 0 + heapStats functionMemoryUsageStatistics Function 0 + startSamplingProfiler functionStartSamplingProfiler Function 0 + samplingProfilerStackTraces functionSamplingProfilerStackTraces Function 0 + noInline functionNeverInlineFunction Function 0 + isRope functionIsRope Function 0 + memoryUsage functionCreateMemoryFootprint Function 0 + noFTL functionNoFTL Function 0 + noOSRExitFuzzing functionNoOSRExitFuzzing Function 0 + numberOfDFGCompiles functionNumberOfDFGCompiles Function 0 + optimizeNextInvocation functionOptimizeNextInvocation Function 0 + releaseWeakRefs functionReleaseWeakRefs Function 0 + reoptimizationRetryCount functionReoptimizationRetryCount Function 0 + setRandomSeed functionSetRandomSeed Function 0 + startRemoteDebugger functionStartRemoteDebugger Function 0 + totalCompileTime functionTotalCompileTime Function 0 + getProtectedObjects functionGetProtectedObjects Function 0 + generateHeapSnapshotForDebugging functionGenerateHeapSnapshotForDebugging Function 0 + profile functionRunProfiler Function 0 + setTimeZone functionSetTimeZone Function 0 + serialize functionSerialize Function 0 + deserialize functionDeserialize Function 0 +@end +*/ + +namespace Zig { +DEFINE_NATIVE_MODULE(BunJSC) +{ + INIT_NATIVE_MODULE(33); + + putNativeFn(Identifier::fromString(vm, "callerSourceOrigin"_s), functionCallerSourceOrigin); + putNativeFn(Identifier::fromString(vm, "jscDescribe"_s), functionDescribe); + putNativeFn(Identifier::fromString(vm, "jscDescribeArray"_s), functionDescribeArray); + putNativeFn(Identifier::fromString(vm, "drainMicrotasks"_s), functionDrainMicrotasks); + putNativeFn(Identifier::fromString(vm, "edenGC"_s), functionEdenGC); + putNativeFn(Identifier::fromString(vm, "fullGC"_s), functionFullGC); + putNativeFn(Identifier::fromString(vm, "gcAndSweep"_s), functionGCAndSweep); + putNativeFn(Identifier::fromString(vm, "getRandomSeed"_s), functionGetRandomSeed); + putNativeFn(Identifier::fromString(vm, "heapSize"_s), functionHeapSize); + putNativeFn(Identifier::fromString(vm, "heapStats"_s), functionMemoryUsageStatistics); + putNativeFn(Identifier::fromString(vm, "startSamplingProfiler"_s), functionStartSamplingProfiler); + putNativeFn(Identifier::fromString(vm, "samplingProfilerStackTraces"_s), functionSamplingProfilerStackTraces); + putNativeFn(Identifier::fromString(vm, "noInline"_s), functionNeverInlineFunction); + putNativeFn(Identifier::fromString(vm, "isRope"_s), functionIsRope); + putNativeFn(Identifier::fromString(vm, "memoryUsage"_s), functionCreateMemoryFootprint); + putNativeFn(Identifier::fromString(vm, "noFTL"_s), functionNoFTL); + putNativeFn(Identifier::fromString(vm, "noOSRExitFuzzing"_s), functionNoOSRExitFuzzing); + putNativeFn(Identifier::fromString(vm, "numberOfDFGCompiles"_s), functionNumberOfDFGCompiles); + putNativeFn(Identifier::fromString(vm, "optimizeNextInvocation"_s), functionOptimizeNextInvocation); + putNativeFn(Identifier::fromString(vm, "releaseWeakRefs"_s), functionReleaseWeakRefs); + putNativeFn(Identifier::fromString(vm, "reoptimizationRetryCount"_s), functionReoptimizationRetryCount); + putNativeFn(Identifier::fromString(vm, "setRandomSeed"_s), functionSetRandomSeed); + putNativeFn(Identifier::fromString(vm, "startRemoteDebugger"_s), functionStartRemoteDebugger); + putNativeFn(Identifier::fromString(vm, "totalCompileTime"_s), functionTotalCompileTime); + putNativeFn(Identifier::fromString(vm, "getProtectedObjects"_s), functionGetProtectedObjects); + putNativeFn(Identifier::fromString(vm, "generateHeapSnapshotForDebugging"_s), functionGenerateHeapSnapshotForDebugging); + putNativeFn(Identifier::fromString(vm, "profile"_s), functionRunProfiler); + putNativeFn(Identifier::fromString(vm, "setTimeZone"_s), functionSetTimeZone); + putNativeFn(Identifier::fromString(vm, "serialize"_s), functionSerialize); + putNativeFn(Identifier::fromString(vm, "deserialize"_s), functionDeserialize); + + // Deprecated + putNativeFn(Identifier::fromString(vm, "describe"_s), functionDescribe); + putNativeFn(Identifier::fromString(vm, "describeArray"_s), functionDescribeArray); + putNativeFn(Identifier::fromString(vm, "setTimezone"_s), functionSetTimeZone); + + RETURN_NATIVE_MODULE(); +} + +} // namespace Zig diff --git a/src/bun.js/modules/ConstantsModule.h b/src/bun.js/modules/ConstantsModule.h deleted file mode 100644 index 8d7c1602b..000000000 --- a/src/bun.js/modules/ConstantsModule.h +++ /dev/null @@ -1,262 +0,0 @@ -#include "JavaScriptCore/JSGlobalObject.h" -#include "ZigGlobalObject.h" - -namespace Zig { -using namespace WebCore; - -inline void generateConstantsSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues) { - JSC::VM &vm = lexicalGlobalObject->vm(); - GlobalObject *globalObject = reinterpret_cast<GlobalObject *>(lexicalGlobalObject); - - auto* defaultObject = JSC::constructEmptyObject(globalObject); - - - auto exportProperty = [&](JSC::Identifier name, JSC::JSValue value) { - exportNames.append(name); - exportValues.append(value); - defaultObject->putDirect(vm, name, value, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | 0); - }; - - exportProperty(JSC::Identifier::fromString(vm, "RTLD_LAZY"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "RTLD_NOW"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "RTLD_GLOBAL"_s), JSC::jsNumber(256)); - exportProperty(JSC::Identifier::fromString(vm, "RTLD_LOCAL"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "RTLD_DEEPBIND"_s), JSC::jsNumber(8)); - exportProperty(JSC::Identifier::fromString(vm, "E2BIG"_s), JSC::jsNumber(7)); - exportProperty(JSC::Identifier::fromString(vm, "EACCES"_s), JSC::jsNumber(13)); - exportProperty(JSC::Identifier::fromString(vm, "EADDRINUSE"_s), JSC::jsNumber(98)); - exportProperty(JSC::Identifier::fromString(vm, "EADDRNOTAVAIL"_s), JSC::jsNumber(99)); - exportProperty(JSC::Identifier::fromString(vm, "EAFNOSUPPORT"_s), JSC::jsNumber(97)); - exportProperty(JSC::Identifier::fromString(vm, "EAGAIN"_s), JSC::jsNumber(11)); - exportProperty(JSC::Identifier::fromString(vm, "EALREADY"_s), JSC::jsNumber(114)); - exportProperty(JSC::Identifier::fromString(vm, "EBADF"_s), JSC::jsNumber(9)); - exportProperty(JSC::Identifier::fromString(vm, "EBADMSG"_s), JSC::jsNumber(74)); - exportProperty(JSC::Identifier::fromString(vm, "EBUSY"_s), JSC::jsNumber(16)); - exportProperty(JSC::Identifier::fromString(vm, "ECANCELED"_s), JSC::jsNumber(125)); - exportProperty(JSC::Identifier::fromString(vm, "ECHILD"_s), JSC::jsNumber(10)); - exportProperty(JSC::Identifier::fromString(vm, "ECONNABORTED"_s), JSC::jsNumber(103)); - exportProperty(JSC::Identifier::fromString(vm, "ECONNREFUSED"_s), JSC::jsNumber(111)); - exportProperty(JSC::Identifier::fromString(vm, "ECONNRESET"_s), JSC::jsNumber(104)); - exportProperty(JSC::Identifier::fromString(vm, "EDEADLK"_s), JSC::jsNumber(35)); - exportProperty(JSC::Identifier::fromString(vm, "EDESTADDRREQ"_s), JSC::jsNumber(89)); - exportProperty(JSC::Identifier::fromString(vm, "EDOM"_s), JSC::jsNumber(33)); - exportProperty(JSC::Identifier::fromString(vm, "EDQUOT"_s), JSC::jsNumber(122)); - exportProperty(JSC::Identifier::fromString(vm, "EEXIST"_s), JSC::jsNumber(17)); - exportProperty(JSC::Identifier::fromString(vm, "EFAULT"_s), JSC::jsNumber(14)); - exportProperty(JSC::Identifier::fromString(vm, "EFBIG"_s), JSC::jsNumber(27)); - exportProperty(JSC::Identifier::fromString(vm, "EHOSTUNREACH"_s), JSC::jsNumber(113)); - exportProperty(JSC::Identifier::fromString(vm, "EIDRM"_s), JSC::jsNumber(43)); - exportProperty(JSC::Identifier::fromString(vm, "EILSEQ"_s), JSC::jsNumber(84)); - exportProperty(JSC::Identifier::fromString(vm, "EINPROGRESS"_s), JSC::jsNumber(115)); - exportProperty(JSC::Identifier::fromString(vm, "EINTR"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "EINVAL"_s), JSC::jsNumber(22)); - exportProperty(JSC::Identifier::fromString(vm, "EIO"_s), JSC::jsNumber(5)); - exportProperty(JSC::Identifier::fromString(vm, "EISCONN"_s), JSC::jsNumber(106)); - exportProperty(JSC::Identifier::fromString(vm, "EISDIR"_s), JSC::jsNumber(21)); - exportProperty(JSC::Identifier::fromString(vm, "ELOOP"_s), JSC::jsNumber(40)); - exportProperty(JSC::Identifier::fromString(vm, "EMFILE"_s), JSC::jsNumber(24)); - exportProperty(JSC::Identifier::fromString(vm, "EMLINK"_s), JSC::jsNumber(31)); - exportProperty(JSC::Identifier::fromString(vm, "EMSGSIZE"_s), JSC::jsNumber(90)); - exportProperty(JSC::Identifier::fromString(vm, "EMULTIHOP"_s), JSC::jsNumber(72)); - exportProperty(JSC::Identifier::fromString(vm, "ENAMETOOLONG"_s), JSC::jsNumber(36)); - exportProperty(JSC::Identifier::fromString(vm, "ENETDOWN"_s), JSC::jsNumber(100)); - exportProperty(JSC::Identifier::fromString(vm, "ENETRESET"_s), JSC::jsNumber(102)); - exportProperty(JSC::Identifier::fromString(vm, "ENETUNREACH"_s), JSC::jsNumber(101)); - exportProperty(JSC::Identifier::fromString(vm, "ENFILE"_s), JSC::jsNumber(23)); - exportProperty(JSC::Identifier::fromString(vm, "ENOBUFS"_s), JSC::jsNumber(105)); - exportProperty(JSC::Identifier::fromString(vm, "ENODATA"_s), JSC::jsNumber(61)); - exportProperty(JSC::Identifier::fromString(vm, "ENODEV"_s), JSC::jsNumber(19)); - exportProperty(JSC::Identifier::fromString(vm, "ENOENT"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "ENOEXEC"_s), JSC::jsNumber(8)); - exportProperty(JSC::Identifier::fromString(vm, "ENOLCK"_s), JSC::jsNumber(37)); - exportProperty(JSC::Identifier::fromString(vm, "ENOLINK"_s), JSC::jsNumber(67)); - exportProperty(JSC::Identifier::fromString(vm, "ENOMEM"_s), JSC::jsNumber(12)); - exportProperty(JSC::Identifier::fromString(vm, "ENOMSG"_s), JSC::jsNumber(42)); - exportProperty(JSC::Identifier::fromString(vm, "ENOPROTOOPT"_s), JSC::jsNumber(92)); - exportProperty(JSC::Identifier::fromString(vm, "ENOSPC"_s), JSC::jsNumber(28)); - exportProperty(JSC::Identifier::fromString(vm, "ENOSR"_s), JSC::jsNumber(63)); - exportProperty(JSC::Identifier::fromString(vm, "ENOSTR"_s), JSC::jsNumber(60)); - exportProperty(JSC::Identifier::fromString(vm, "ENOSYS"_s), JSC::jsNumber(38)); - exportProperty(JSC::Identifier::fromString(vm, "ENOTCONN"_s), JSC::jsNumber(107)); - exportProperty(JSC::Identifier::fromString(vm, "ENOTDIR"_s), JSC::jsNumber(20)); - exportProperty(JSC::Identifier::fromString(vm, "ENOTEMPTY"_s), JSC::jsNumber(39)); - exportProperty(JSC::Identifier::fromString(vm, "ENOTSOCK"_s), JSC::jsNumber(88)); - exportProperty(JSC::Identifier::fromString(vm, "ENOTSUP"_s), JSC::jsNumber(95)); - exportProperty(JSC::Identifier::fromString(vm, "ENOTTY"_s), JSC::jsNumber(25)); - exportProperty(JSC::Identifier::fromString(vm, "ENXIO"_s), JSC::jsNumber(6)); - exportProperty(JSC::Identifier::fromString(vm, "EOPNOTSUPP"_s), JSC::jsNumber(95)); - exportProperty(JSC::Identifier::fromString(vm, "EOVERFLOW"_s), JSC::jsNumber(75)); - exportProperty(JSC::Identifier::fromString(vm, "EPERM"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "EPIPE"_s), JSC::jsNumber(32)); - exportProperty(JSC::Identifier::fromString(vm, "EPROTO"_s), JSC::jsNumber(71)); - exportProperty(JSC::Identifier::fromString(vm, "EPROTONOSUPPORT"_s), JSC::jsNumber(93)); - exportProperty(JSC::Identifier::fromString(vm, "EPROTOTYPE"_s), JSC::jsNumber(91)); - exportProperty(JSC::Identifier::fromString(vm, "ERANGE"_s), JSC::jsNumber(34)); - exportProperty(JSC::Identifier::fromString(vm, "EROFS"_s), JSC::jsNumber(30)); - exportProperty(JSC::Identifier::fromString(vm, "ESPIPE"_s), JSC::jsNumber(29)); - exportProperty(JSC::Identifier::fromString(vm, "ESRCH"_s), JSC::jsNumber(3)); - exportProperty(JSC::Identifier::fromString(vm, "ESTALE"_s), JSC::jsNumber(116)); - exportProperty(JSC::Identifier::fromString(vm, "ETIME"_s), JSC::jsNumber(62)); - exportProperty(JSC::Identifier::fromString(vm, "ETIMEDOUT"_s), JSC::jsNumber(110)); - exportProperty(JSC::Identifier::fromString(vm, "ETXTBSY"_s), JSC::jsNumber(26)); - exportProperty(JSC::Identifier::fromString(vm, "EWOULDBLOCK"_s), JSC::jsNumber(11)); - exportProperty(JSC::Identifier::fromString(vm, "EXDEV"_s), JSC::jsNumber(18)); - exportProperty(JSC::Identifier::fromString(vm, "PRIORITY_LOW"_s), JSC::jsNumber(19)); - exportProperty(JSC::Identifier::fromString(vm, "PRIORITY_BELOW_NORMAL"_s), JSC::jsNumber(10)); - exportProperty(JSC::Identifier::fromString(vm, "PRIORITY_NORMAL"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "PRIORITY_ABOVE_NORMAL"_s), JSC::jsNumber(-7)); - exportProperty(JSC::Identifier::fromString(vm, "PRIORITY_HIGH"_s), JSC::jsNumber(-14)); - exportProperty(JSC::Identifier::fromString(vm, "PRIORITY_HIGHEST"_s), JSC::jsNumber(-20)); - exportProperty(JSC::Identifier::fromString(vm, "SIGHUP"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "SIGINT"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "SIGQUIT"_s), JSC::jsNumber(3)); - exportProperty(JSC::Identifier::fromString(vm, "SIGILL"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "SIGTRAP"_s), JSC::jsNumber(5)); - exportProperty(JSC::Identifier::fromString(vm, "SIGABRT"_s), JSC::jsNumber(6)); - exportProperty(JSC::Identifier::fromString(vm, "SIGIOT"_s), JSC::jsNumber(6)); - exportProperty(JSC::Identifier::fromString(vm, "SIGBUS"_s), JSC::jsNumber(7)); - exportProperty(JSC::Identifier::fromString(vm, "SIGFPE"_s), JSC::jsNumber(8)); - exportProperty(JSC::Identifier::fromString(vm, "SIGKILL"_s), JSC::jsNumber(9)); - exportProperty(JSC::Identifier::fromString(vm, "SIGUSR1"_s), JSC::jsNumber(10)); - exportProperty(JSC::Identifier::fromString(vm, "SIGSEGV"_s), JSC::jsNumber(11)); - exportProperty(JSC::Identifier::fromString(vm, "SIGUSR2"_s), JSC::jsNumber(12)); - exportProperty(JSC::Identifier::fromString(vm, "SIGPIPE"_s), JSC::jsNumber(13)); - exportProperty(JSC::Identifier::fromString(vm, "SIGALRM"_s), JSC::jsNumber(14)); - exportProperty(JSC::Identifier::fromString(vm, "SIGTERM"_s), JSC::jsNumber(15)); - exportProperty(JSC::Identifier::fromString(vm, "SIGCHLD"_s), JSC::jsNumber(17)); - exportProperty(JSC::Identifier::fromString(vm, "SIGSTKFLT"_s), JSC::jsNumber(16)); - exportProperty(JSC::Identifier::fromString(vm, "SIGCONT"_s), JSC::jsNumber(18)); - exportProperty(JSC::Identifier::fromString(vm, "SIGSTOP"_s), JSC::jsNumber(19)); - exportProperty(JSC::Identifier::fromString(vm, "SIGTSTP"_s), JSC::jsNumber(20)); - exportProperty(JSC::Identifier::fromString(vm, "SIGTTIN"_s), JSC::jsNumber(21)); - exportProperty(JSC::Identifier::fromString(vm, "SIGTTOU"_s), JSC::jsNumber(22)); - exportProperty(JSC::Identifier::fromString(vm, "SIGURG"_s), JSC::jsNumber(23)); - exportProperty(JSC::Identifier::fromString(vm, "SIGXCPU"_s), JSC::jsNumber(24)); - exportProperty(JSC::Identifier::fromString(vm, "SIGXFSZ"_s), JSC::jsNumber(25)); - exportProperty(JSC::Identifier::fromString(vm, "SIGVTALRM"_s), JSC::jsNumber(26)); - exportProperty(JSC::Identifier::fromString(vm, "SIGPROF"_s), JSC::jsNumber(27)); - exportProperty(JSC::Identifier::fromString(vm, "SIGWINCH"_s), JSC::jsNumber(28)); - exportProperty(JSC::Identifier::fromString(vm, "SIGIO"_s), JSC::jsNumber(29)); - exportProperty(JSC::Identifier::fromString(vm, "SIGPOLL"_s), JSC::jsNumber(29)); - exportProperty(JSC::Identifier::fromString(vm, "SIGPWR"_s), JSC::jsNumber(30)); - exportProperty(JSC::Identifier::fromString(vm, "SIGSYS"_s), JSC::jsNumber(31)); - exportProperty(JSC::Identifier::fromString(vm, "UV_FS_SYMLINK_DIR"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "UV_FS_SYMLINK_JUNCTION"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "O_RDONLY"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "O_WRONLY"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "O_RDWR"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_UNKNOWN"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_FILE"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_DIR"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_LINK"_s), JSC::jsNumber(3)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_FIFO"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_SOCKET"_s), JSC::jsNumber(5)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_CHAR"_s), JSC::jsNumber(6)); - exportProperty(JSC::Identifier::fromString(vm, "UV_DIRENT_BLOCK"_s), JSC::jsNumber(7)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFMT"_s), JSC::jsNumber(61440)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFREG"_s), JSC::jsNumber(32768)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFDIR"_s), JSC::jsNumber(16384)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFCHR"_s), JSC::jsNumber(8192)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFBLK"_s), JSC::jsNumber(24576)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFIFO"_s), JSC::jsNumber(4096)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFLNK"_s), JSC::jsNumber(40960)); - exportProperty(JSC::Identifier::fromString(vm, "S_IFSOCK"_s), JSC::jsNumber(49152)); - exportProperty(JSC::Identifier::fromString(vm, "O_CREAT"_s), JSC::jsNumber(64)); - exportProperty(JSC::Identifier::fromString(vm, "O_EXCL"_s), JSC::jsNumber(128)); - exportProperty(JSC::Identifier::fromString(vm, "UV_FS_O_FILEMAP"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "O_NOCTTY"_s), JSC::jsNumber(256)); - exportProperty(JSC::Identifier::fromString(vm, "O_TRUNC"_s), JSC::jsNumber(512)); - exportProperty(JSC::Identifier::fromString(vm, "O_APPEND"_s), JSC::jsNumber(1024)); - exportProperty(JSC::Identifier::fromString(vm, "O_DIRECTORY"_s), JSC::jsNumber(65536)); - exportProperty(JSC::Identifier::fromString(vm, "O_NOATIME"_s), JSC::jsNumber(262144)); - exportProperty(JSC::Identifier::fromString(vm, "O_NOFOLLOW"_s), JSC::jsNumber(131072)); - exportProperty(JSC::Identifier::fromString(vm, "O_SYNC"_s), JSC::jsNumber(1052672)); - exportProperty(JSC::Identifier::fromString(vm, "O_DSYNC"_s), JSC::jsNumber(4096)); - exportProperty(JSC::Identifier::fromString(vm, "O_DIRECT"_s), JSC::jsNumber(16384)); - exportProperty(JSC::Identifier::fromString(vm, "O_NONBLOCK"_s), JSC::jsNumber(2048)); - exportProperty(JSC::Identifier::fromString(vm, "S_IRWXU"_s), JSC::jsNumber(448)); - exportProperty(JSC::Identifier::fromString(vm, "S_IRUSR"_s), JSC::jsNumber(256)); - exportProperty(JSC::Identifier::fromString(vm, "S_IWUSR"_s), JSC::jsNumber(128)); - exportProperty(JSC::Identifier::fromString(vm, "S_IXUSR"_s), JSC::jsNumber(64)); - exportProperty(JSC::Identifier::fromString(vm, "S_IRWXG"_s), JSC::jsNumber(56)); - exportProperty(JSC::Identifier::fromString(vm, "S_IRGRP"_s), JSC::jsNumber(32)); - exportProperty(JSC::Identifier::fromString(vm, "S_IWGRP"_s), JSC::jsNumber(16)); - exportProperty(JSC::Identifier::fromString(vm, "S_IXGRP"_s), JSC::jsNumber(8)); - exportProperty(JSC::Identifier::fromString(vm, "S_IRWXO"_s), JSC::jsNumber(7)); - exportProperty(JSC::Identifier::fromString(vm, "S_IROTH"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "S_IWOTH"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "S_IXOTH"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "F_OK"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "R_OK"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "W_OK"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "X_OK"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "UV_FS_COPYFILE_EXCL"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "COPYFILE_EXCL"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "UV_FS_COPYFILE_FICLONE"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "COPYFILE_FICLONE"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "UV_FS_COPYFILE_FICLONE_FORCE"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "COPYFILE_FICLONE_FORCE"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "OPENSSL_VERSION_NUMBER"_s), JSC::jsNumber(805306496)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_ALL"_s), JSC::jsNumber(2147485776)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_ALLOW_NO_DHE_KEX"_s), JSC::jsNumber(1024)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION"_s), JSC::jsNumber(262144)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_CIPHER_SERVER_PREFERENCE"_s), JSC::jsNumber(4194304)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_CISCO_ANYCONNECT"_s), JSC::jsNumber(32768)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_COOKIE_EXCHANGE"_s), JSC::jsNumber(8192)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_CRYPTOPRO_TLSEXT_BUG"_s), JSC::jsNumber(2147483648)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS"_s), JSC::jsNumber(2048)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_LEGACY_SERVER_CONNECT"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_COMPRESSION"_s), JSC::jsNumber(131072)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_ENCRYPT_THEN_MAC"_s), JSC::jsNumber(524288)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_QUERY_MTU"_s), JSC::jsNumber(4096)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_RENEGOTIATION"_s), JSC::jsNumber(1073741824)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION"_s), JSC::jsNumber(65536)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_SSLv2"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_SSLv3"_s), JSC::jsNumber(33554432)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_TICKET"_s), JSC::jsNumber(16384)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_TLSv1"_s), JSC::jsNumber(67108864)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_TLSv1_1"_s), JSC::jsNumber(268435456)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_TLSv1_2"_s), JSC::jsNumber(134217728)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_NO_TLSv1_3"_s), JSC::jsNumber(536870912)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_PRIORITIZE_CHACHA"_s), JSC::jsNumber(2097152)); - exportProperty(JSC::Identifier::fromString(vm, "SSL_OP_TLS_ROLLBACK_BUG"_s), JSC::jsNumber(8388608)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_RSA"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_DSA"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_DH"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_RAND"_s), JSC::jsNumber(8)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_EC"_s), JSC::jsNumber(2048)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_CIPHERS"_s), JSC::jsNumber(64)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_DIGESTS"_s), JSC::jsNumber(128)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_PKEY_METHS"_s), JSC::jsNumber(512)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_PKEY_ASN1_METHS"_s), JSC::jsNumber(1024)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_ALL"_s), JSC::jsNumber(65535)); - exportProperty(JSC::Identifier::fromString(vm, "ENGINE_METHOD_NONE"_s), JSC::jsNumber(0)); - exportProperty(JSC::Identifier::fromString(vm, "DH_CHECK_P_NOT_SAFE_PRIME"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "DH_CHECK_P_NOT_PRIME"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "DH_UNABLE_TO_CHECK_GENERATOR"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "DH_NOT_SUITABLE_GENERATOR"_s), JSC::jsNumber(8)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_PKCS1_PADDING"_s), JSC::jsNumber(1)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_NO_PADDING"_s), JSC::jsNumber(3)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_PKCS1_OAEP_PADDING"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_X931_PADDING"_s), JSC::jsNumber(5)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_PKCS1_PSS_PADDING"_s), JSC::jsNumber(6)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_PSS_SALTLEN_DIGEST"_s), JSC::jsNumber(-1)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_PSS_SALTLEN_MAX_SIGN"_s), JSC::jsNumber(-2)); - exportProperty(JSC::Identifier::fromString(vm, "RSA_PSS_SALTLEN_AUTO"_s), JSC::jsNumber(-2)); - exportProperty(JSC::Identifier::fromString(vm, "defaultCoreCipherList"_s), JSC::jsString(vm, WTF::String::fromUTF8("DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256"))); - exportProperty(JSC::Identifier::fromString(vm, "TLS1_VERSION"_s), JSC::jsNumber(769)); - exportProperty(JSC::Identifier::fromString(vm, "TLS1_1_VERSION"_s), JSC::jsNumber(770)); - exportProperty(JSC::Identifier::fromString(vm, "TLS1_2_VERSION"_s), JSC::jsNumber(771)); - exportProperty(JSC::Identifier::fromString(vm, "TLS1_3_VERSION"_s), JSC::jsNumber(772)); - exportProperty(JSC::Identifier::fromString(vm, "POINT_CONVERSION_COMPRESSED"_s), JSC::jsNumber(2)); - exportProperty(JSC::Identifier::fromString(vm, "POINT_CONVERSION_UNCOMPRESSED"_s), JSC::jsNumber(4)); - exportProperty(JSC::Identifier::fromString(vm, "POINT_CONVERSION_HYBRID"_s), JSC::jsNumber(6)); - - exportNames.append(vm.propertyNames->defaultKeyword); - exportValues.append(defaultObject); -} - -} // namespace Zig diff --git a/src/bun.js/modules/EventsModule.h b/src/bun.js/modules/EventsModule.h deleted file mode 100644 index 7d53ff838..000000000 --- a/src/bun.js/modules/EventsModule.h +++ /dev/null @@ -1,58 +0,0 @@ -#include "JavaScriptCore/JSGlobalObject.h" -#include "ZigGlobalObject.h" - -namespace Zig { -using namespace WebCore; - -inline void generateEventsSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues) { - JSC::VM &vm = lexicalGlobalObject->vm(); - GlobalObject *globalObject = - reinterpret_cast<GlobalObject *>(lexicalGlobalObject); - - exportNames.append(JSC::Identifier::fromString(vm, "EventEmitter"_s)); - exportValues.append( - WebCore::JSEventEmitter::getConstructor(vm, globalObject)); - - exportNames.append(JSC::Identifier::fromString(vm, "getEventListeners"_s)); - exportValues.append(JSC::JSFunction::create( - vm, lexicalGlobalObject, 0, MAKE_STATIC_STRING_IMPL("getEventListeners"), - Events_functionGetEventListeners, ImplementationVisibility::Public)); - exportNames.append(JSC::Identifier::fromString(vm, "listenerCount"_s)); - exportValues.append(JSC::JSFunction::create( - vm, lexicalGlobalObject, 0, MAKE_STATIC_STRING_IMPL("listenerCount"), - Events_functionListenerCount, ImplementationVisibility::Public)); - exportNames.append(JSC::Identifier::fromString(vm, "once"_s)); - exportValues.append(JSC::JSFunction::create( - vm, lexicalGlobalObject, 0, MAKE_STATIC_STRING_IMPL("once"), - Events_functionOnce, ImplementationVisibility::Public)); - exportNames.append(JSC::Identifier::fromString(vm, "on"_s)); - exportValues.append(JSC::JSFunction::create( - vm, lexicalGlobalObject, 0, MAKE_STATIC_STRING_IMPL("on"), - Events_functionOn, ImplementationVisibility::Public)); - exportNames.append( - JSC::Identifier::fromString(vm, "captureRejectionSymbol"_s)); - exportValues.append(Symbol::create( - vm, vm.symbolRegistry().symbolForKey("nodejs.rejection"_s))); - - JSFunction *eventEmitterModuleCJS = - jsCast<JSFunction *>(WebCore::JSEventEmitter::getConstructor( - vm, reinterpret_cast<Zig::GlobalObject *>(globalObject))); - - eventEmitterModuleCJS->putDirect( - vm, - PropertyName( - Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s))), - jsNumber(0), 0); - - for (size_t i = 0; i < exportNames.size(); i++) { - eventEmitterModuleCJS->putDirect(vm, exportNames[i], exportValues.at(i), 0); - } - - exportNames.append(JSC::Identifier::fromString(vm, "default"_s)); - exportValues.append(eventEmitterModuleCJS); -} - -} // namespace Zig diff --git a/src/bun.js/modules/BufferModule.h b/src/bun.js/modules/NodeBufferModule.h index 6e6e39e9c..5c6acd48e 100644 --- a/src/bun.js/modules/BufferModule.h +++ b/src/bun.js/modules/NodeBufferModule.h @@ -1,7 +1,5 @@ #include "../bindings/JSBuffer.h" -#include "../bindings/ZigGlobalObject.h" -#include "JavaScriptCore/JSGlobalObject.h" -#include "JavaScriptCore/ObjectConstructor.h" +#include "_NativeModule.h" #include "simdutf.h" namespace Zig { @@ -134,33 +132,11 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionNotImplemented, return JSValue::encode(jsUndefined()); } -inline void generateBufferSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues) { - JSC::VM &vm = lexicalGlobalObject->vm(); - GlobalObject *globalObject = - reinterpret_cast<GlobalObject *>(lexicalGlobalObject); +DEFINE_NATIVE_MODULE(NodeBuffer) { + INIT_NATIVE_MODULE(12); - JSC::JSObject *defaultObject = JSC::constructEmptyObject( - globalObject, globalObject->objectPrototype(), 12); - - auto CommonJS = - Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s)); - - defaultObject->putDirect(vm, PropertyName(CommonJS), jsNumber(0), 0); - - exportNames.append(CommonJS); - exportValues.append(jsNumber(0)); - - auto exportProperty = [&](JSC::Identifier name, JSC::JSValue value) { - exportNames.append(name); - exportValues.append(value); - defaultObject->putDirect(vm, name, value, 0); - }; - - exportProperty(JSC::Identifier::fromString(vm, "Buffer"_s), - globalObject->JSBufferConstructor()); + put(JSC::Identifier::fromString(vm, "Buffer"_s), + globalObject->JSBufferConstructor()); auto *slowBuffer = JSC::JSFunction::create( vm, globalObject, 0, "SlowBuffer"_s, WebCore::constructSlowBuffer, @@ -170,24 +146,24 @@ inline void generateBufferSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, vm, vm.propertyNames->prototype, globalObject->JSBufferPrototype(), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); - exportProperty(JSC::Identifier::fromString(vm, "SlowBuffer"_s), slowBuffer); + put(JSC::Identifier::fromString(vm, "SlowBuffer"_s), slowBuffer); auto blobIdent = JSC::Identifier::fromString(vm, "Blob"_s); JSValue blobValue = lexicalGlobalObject->get(globalObject, PropertyName(blobIdent)); - exportProperty(blobIdent, blobValue); + put(blobIdent, blobValue); // TODO: implement File - exportProperty(JSC::Identifier::fromString(vm, "File"_s), blobValue); + put(JSC::Identifier::fromString(vm, "File"_s), blobValue); - exportProperty(JSC::Identifier::fromString(vm, "INSPECT_MAX_BYTES"_s), - JSC::jsNumber(50)); + put(JSC::Identifier::fromString(vm, "INSPECT_MAX_BYTES"_s), + JSC::jsNumber(50)); - exportProperty(JSC::Identifier::fromString(vm, "kMaxLength"_s), - JSC::jsNumber(4294967296LL)); + put(JSC::Identifier::fromString(vm, "kMaxLength"_s), + JSC::jsNumber(4294967296LL)); - exportProperty(JSC::Identifier::fromString(vm, "kStringMaxLength"_s), - JSC::jsNumber(536870888)); + put(JSC::Identifier::fromString(vm, "kStringMaxLength"_s), + JSC::jsNumber(536870888)); JSC::JSObject *constants = JSC::constructEmptyObject( lexicalGlobalObject, globalObject->objectPrototype(), 2); @@ -197,7 +173,7 @@ inline void generateBufferSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, JSC::Identifier::fromString(vm, "MAX_STRING_LENGTH"_s), JSC::jsNumber(536870888)); - exportProperty(JSC::Identifier::fromString(vm, "constants"_s), constants); + put(JSC::Identifier::fromString(vm, "constants"_s), constants); JSC::Identifier atobI = JSC::Identifier::fromString(vm, "atob"_s); JSC::JSValue atobV = @@ -207,37 +183,31 @@ inline void generateBufferSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, JSC::JSValue btoaV = lexicalGlobalObject->get(globalObject, PropertyName(btoaI)); - exportProperty(atobI, atobV); - exportProperty(btoaI, btoaV); + put(atobI, atobV); + put(btoaI, btoaV); auto *transcode = InternalFunction::createFunctionThatMasqueradesAsUndefined( vm, globalObject, 1, "transcode"_s, jsFunctionNotImplemented); - exportProperty(JSC::Identifier::fromString(vm, "transcode"_s), transcode); + put(JSC::Identifier::fromString(vm, "transcode"_s), transcode); auto *resolveObjectURL = InternalFunction::createFunctionThatMasqueradesAsUndefined( vm, globalObject, 1, "resolveObjectURL"_s, jsFunctionNotImplemented); - exportProperty(JSC::Identifier::fromString(vm, "resolveObjectURL"_s), - resolveObjectURL); - - exportProperty(JSC::Identifier::fromString(vm, "isAscii"_s), - JSC::JSFunction::create(vm, globalObject, 1, "isAscii"_s, - jsBufferConstructorFunction_isAscii, - ImplementationVisibility::Public, - NoIntrinsic, - jsBufferConstructorFunction_isUtf8)); - - exportProperty(JSC::Identifier::fromString(vm, "isUtf8"_s), - JSC::JSFunction::create(vm, globalObject, 1, "isUtf8"_s, - jsBufferConstructorFunction_isUtf8, - ImplementationVisibility::Public, - NoIntrinsic, - jsBufferConstructorFunction_isUtf8)); - - exportNames.append(vm.propertyNames->defaultKeyword); - exportValues.append(defaultObject); + put(JSC::Identifier::fromString(vm, "resolveObjectURL"_s), resolveObjectURL); + + put(JSC::Identifier::fromString(vm, "isAscii"_s), + JSC::JSFunction::create(vm, globalObject, 1, "isAscii"_s, + jsBufferConstructorFunction_isAscii, + ImplementationVisibility::Public, NoIntrinsic, + jsBufferConstructorFunction_isUtf8)); + + put(JSC::Identifier::fromString(vm, "isUtf8"_s), + JSC::JSFunction::create(vm, globalObject, 1, "isUtf8"_s, + jsBufferConstructorFunction_isUtf8, + ImplementationVisibility::Public, NoIntrinsic, + jsBufferConstructorFunction_isUtf8)); } } // namespace Zig diff --git a/src/bun.js/modules/NodeConstantsModule.h b/src/bun.js/modules/NodeConstantsModule.h new file mode 100644 index 000000000..c1e324b0a --- /dev/null +++ b/src/bun.js/modules/NodeConstantsModule.h @@ -0,0 +1,916 @@ +#include "_NativeModule.h" +// Modelled off of https://github.com/nodejs/node/blob/main/src/node_constants.cc +// Note that if you change any of this code, you probably also have to change ProcessBindingConstants.cpp + +// require('constants') is implemented in node as a spread of: +// - constants.os.dlopen +// - constants.os.errno +// - constants.os.priority +// - constants.os.signals +// - constants.fs +// - constants.crypto +// Instead of loading $processBindingConstants, we just inline it + +// These headers may not all be needed, but they are the ones node references. +// Most of the constants are defined with #if checks on existing #defines, instead of platform-checks +#include <openssl/ec.h> +#include <openssl/ssl.h> +#include <zlib.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <cerrno> +#include <csignal> +#include <limits> + +#ifndef OPENSSL_NO_ENGINE +#include <openssl/engine.h> +#endif + +#if !defined(_MSC_VER) +#include <unistd.h> +#endif + +#if defined(_WIN32) +#include <io.h> // _S_IREAD _S_IWRITE +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif // S_IRUSR +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif // S_IWUSR +#else +#include <dlfcn.h> +#endif + +namespace Zig { +using namespace WebCore; + +DEFINE_NATIVE_MODULE(NodeConstants) { + INIT_NATIVE_MODULE(63); + +#ifdef RTLD_LAZY + put(Identifier::fromString(vm, "RTLD_LAZY"_s), jsNumber(RTLD_LAZY)); +#endif +#ifdef RTLD_NOW + put(Identifier::fromString(vm, "RTLD_NOW"_s), jsNumber(RTLD_NOW)); +#endif +#ifdef RTLD_GLOBAL + put(Identifier::fromString(vm, "RTLD_GLOBAL"_s), jsNumber(RTLD_GLOBAL)); +#endif +#ifdef RTLD_LOCAL + put(Identifier::fromString(vm, "RTLD_LOCAL"_s), jsNumber(RTLD_LOCAL)); +#endif +#ifdef RTLD_DEEPBIND + put(Identifier::fromString(vm, "RTLD_DEEPBIND"_s), jsNumber(RTLD_DEEPBIND)); +#endif +#ifdef E2BIG + put(Identifier::fromString(vm, "E2BIG"_s), jsNumber(E2BIG)); +#endif +#ifdef EACCES + put(Identifier::fromString(vm, "EACCES"_s), jsNumber(EACCES)); +#endif +#ifdef EADDRINUSE + put(Identifier::fromString(vm, "EADDRINUSE"_s), jsNumber(EADDRINUSE)); +#endif +#ifdef EADDRNOTAVAIL + put(Identifier::fromString(vm, "EADDRNOTAVAIL"_s), jsNumber(EADDRNOTAVAIL)); +#endif +#ifdef EAFNOSUPPORT + put(Identifier::fromString(vm, "EAFNOSUPPORT"_s), jsNumber(EAFNOSUPPORT)); +#endif +#ifdef EAGAIN + put(Identifier::fromString(vm, "EAGAIN"_s), jsNumber(EAGAIN)); +#endif +#ifdef EALREADY + put(Identifier::fromString(vm, "EALREADY"_s), jsNumber(EALREADY)); +#endif +#ifdef EBADF + put(Identifier::fromString(vm, "EBADF"_s), jsNumber(EBADF)); +#endif +#ifdef EBADMSG + put(Identifier::fromString(vm, "EBADMSG"_s), jsNumber(EBADMSG)); +#endif +#ifdef EBUSY + put(Identifier::fromString(vm, "EBUSY"_s), jsNumber(EBUSY)); +#endif +#ifdef ECANCELED + put(Identifier::fromString(vm, "ECANCELED"_s), jsNumber(ECANCELED)); +#endif +#ifdef ECHILD + put(Identifier::fromString(vm, "ECHILD"_s), jsNumber(ECHILD)); +#endif +#ifdef ECONNABORTED + put(Identifier::fromString(vm, "ECONNABORTED"_s), jsNumber(ECONNABORTED)); +#endif +#ifdef ECONNREFUSED + put(Identifier::fromString(vm, "ECONNREFUSED"_s), jsNumber(ECONNREFUSED)); +#endif +#ifdef ECONNRESET + put(Identifier::fromString(vm, "ECONNRESET"_s), jsNumber(ECONNRESET)); +#endif +#ifdef EDEADLK + put(Identifier::fromString(vm, "EDEADLK"_s), jsNumber(EDEADLK)); +#endif +#ifdef EDESTADDRREQ + put(Identifier::fromString(vm, "EDESTADDRREQ"_s), jsNumber(EDESTADDRREQ)); +#endif +#ifdef EDOM + put(Identifier::fromString(vm, "EDOM"_s), jsNumber(EDOM)); +#endif +#ifdef EDQUOT + put(Identifier::fromString(vm, "EDQUOT"_s), jsNumber(EDQUOT)); +#endif +#ifdef EEXIST + put(Identifier::fromString(vm, "EEXIST"_s), jsNumber(EEXIST)); +#endif +#ifdef EFAULT + put(Identifier::fromString(vm, "EFAULT"_s), jsNumber(EFAULT)); +#endif +#ifdef EFBIG + put(Identifier::fromString(vm, "EFBIG"_s), jsNumber(EFBIG)); +#endif +#ifdef EHOSTUNREACH + put(Identifier::fromString(vm, "EHOSTUNREACH"_s), jsNumber(EHOSTUNREACH)); +#endif +#ifdef EIDRM + put(Identifier::fromString(vm, "EIDRM"_s), jsNumber(EIDRM)); +#endif +#ifdef EILSEQ + put(Identifier::fromString(vm, "EILSEQ"_s), jsNumber(EILSEQ)); +#endif +#ifdef EINPROGRESS + put(Identifier::fromString(vm, "EINPROGRESS"_s), jsNumber(EINPROGRESS)); +#endif +#ifdef EINTR + put(Identifier::fromString(vm, "EINTR"_s), jsNumber(EINTR)); +#endif +#ifdef EINVAL + put(Identifier::fromString(vm, "EINVAL"_s), jsNumber(EINVAL)); +#endif +#ifdef EIO + put(Identifier::fromString(vm, "EIO"_s), jsNumber(EIO)); +#endif +#ifdef EISCONN + put(Identifier::fromString(vm, "EISCONN"_s), jsNumber(EISCONN)); +#endif +#ifdef EISDIR + put(Identifier::fromString(vm, "EISDIR"_s), jsNumber(EISDIR)); +#endif +#ifdef ELOOP + put(Identifier::fromString(vm, "ELOOP"_s), jsNumber(ELOOP)); +#endif +#ifdef EMFILE + put(Identifier::fromString(vm, "EMFILE"_s), jsNumber(EMFILE)); +#endif +#ifdef EMLINK + put(Identifier::fromString(vm, "EMLINK"_s), jsNumber(EMLINK)); +#endif +#ifdef EMSGSIZE + put(Identifier::fromString(vm, "EMSGSIZE"_s), jsNumber(EMSGSIZE)); +#endif +#ifdef EMULTIHOP + put(Identifier::fromString(vm, "EMULTIHOP"_s), jsNumber(EMULTIHOP)); +#endif +#ifdef ENAMETOOLONG + put(Identifier::fromString(vm, "ENAMETOOLONG"_s), jsNumber(ENAMETOOLONG)); +#endif +#ifdef ENETDOWN + put(Identifier::fromString(vm, "ENETDOWN"_s), jsNumber(ENETDOWN)); +#endif +#ifdef ENETRESET + put(Identifier::fromString(vm, "ENETRESET"_s), jsNumber(ENETRESET)); +#endif +#ifdef ENETUNREACH + put(Identifier::fromString(vm, "ENETUNREACH"_s), jsNumber(ENETUNREACH)); +#endif +#ifdef ENFILE + put(Identifier::fromString(vm, "ENFILE"_s), jsNumber(ENFILE)); +#endif +#ifdef ENOBUFS + put(Identifier::fromString(vm, "ENOBUFS"_s), jsNumber(ENOBUFS)); +#endif +#ifdef ENODATA + put(Identifier::fromString(vm, "ENODATA"_s), jsNumber(ENODATA)); +#endif +#ifdef ENODEV + put(Identifier::fromString(vm, "ENODEV"_s), jsNumber(ENODEV)); +#endif +#ifdef ENOENT + put(Identifier::fromString(vm, "ENOENT"_s), jsNumber(ENOENT)); +#endif +#ifdef ENOEXEC + put(Identifier::fromString(vm, "ENOEXEC"_s), jsNumber(ENOEXEC)); +#endif +#ifdef ENOLCK + put(Identifier::fromString(vm, "ENOLCK"_s), jsNumber(ENOLCK)); +#endif +#ifdef ENOLINK + put(Identifier::fromString(vm, "ENOLINK"_s), jsNumber(ENOLINK)); +#endif +#ifdef ENOMEM + put(Identifier::fromString(vm, "ENOMEM"_s), jsNumber(ENOMEM)); +#endif +#ifdef ENOMSG + put(Identifier::fromString(vm, "ENOMSG"_s), jsNumber(ENOMSG)); +#endif +#ifdef ENOPROTOOPT + put(Identifier::fromString(vm, "ENOPROTOOPT"_s), jsNumber(ENOPROTOOPT)); +#endif +#ifdef ENOSPC + put(Identifier::fromString(vm, "ENOSPC"_s), jsNumber(ENOSPC)); +#endif +#ifdef ENOSR + put(Identifier::fromString(vm, "ENOSR"_s), jsNumber(ENOSR)); +#endif +#ifdef ENOSTR + put(Identifier::fromString(vm, "ENOSTR"_s), jsNumber(ENOSTR)); +#endif +#ifdef ENOSYS + put(Identifier::fromString(vm, "ENOSYS"_s), jsNumber(ENOSYS)); +#endif +#ifdef ENOTCONN + put(Identifier::fromString(vm, "ENOTCONN"_s), jsNumber(ENOTCONN)); +#endif +#ifdef ENOTDIR + put(Identifier::fromString(vm, "ENOTDIR"_s), jsNumber(ENOTDIR)); +#endif +#ifdef ENOTEMPTY + put(Identifier::fromString(vm, "ENOTEMPTY"_s), jsNumber(ENOTEMPTY)); +#endif +#ifdef ENOTSOCK + put(Identifier::fromString(vm, "ENOTSOCK"_s), jsNumber(ENOTSOCK)); +#endif +#ifdef ENOTSUP + put(Identifier::fromString(vm, "ENOTSUP"_s), jsNumber(ENOTSUP)); +#endif +#ifdef ENOTTY + put(Identifier::fromString(vm, "ENOTTY"_s), jsNumber(ENOTTY)); +#endif +#ifdef ENXIO + put(Identifier::fromString(vm, "ENXIO"_s), jsNumber(ENXIO)); +#endif +#ifdef EOPNOTSUPP + put(Identifier::fromString(vm, "EOPNOTSUPP"_s), jsNumber(EOPNOTSUPP)); +#endif +#ifdef EOVERFLOW + put(Identifier::fromString(vm, "EOVERFLOW"_s), jsNumber(EOVERFLOW)); +#endif +#ifdef EPERM + put(Identifier::fromString(vm, "EPERM"_s), jsNumber(EPERM)); +#endif +#ifdef EPIPE + put(Identifier::fromString(vm, "EPIPE"_s), jsNumber(EPIPE)); +#endif +#ifdef EPROTO + put(Identifier::fromString(vm, "EPROTO"_s), jsNumber(EPROTO)); +#endif +#ifdef EPROTONOSUPPORT + put(Identifier::fromString(vm, "EPROTONOSUPPORT"_s), jsNumber(EPROTONOSUPPORT)); +#endif +#ifdef EPROTOTYPE + put(Identifier::fromString(vm, "EPROTOTYPE"_s), jsNumber(EPROTOTYPE)); +#endif +#ifdef ERANGE + put(Identifier::fromString(vm, "ERANGE"_s), jsNumber(ERANGE)); +#endif +#ifdef EROFS + put(Identifier::fromString(vm, "EROFS"_s), jsNumber(EROFS)); +#endif +#ifdef ESPIPE + put(Identifier::fromString(vm, "ESPIPE"_s), jsNumber(ESPIPE)); +#endif +#ifdef ESRCH + put(Identifier::fromString(vm, "ESRCH"_s), jsNumber(ESRCH)); +#endif +#ifdef ESTALE + put(Identifier::fromString(vm, "ESTALE"_s), jsNumber(ESTALE)); +#endif +#ifdef ETIME + put(Identifier::fromString(vm, "ETIME"_s), jsNumber(ETIME)); +#endif +#ifdef ETIMEDOUT + put(Identifier::fromString(vm, "ETIMEDOUT"_s), jsNumber(ETIMEDOUT)); +#endif +#ifdef ETXTBSY + put(Identifier::fromString(vm, "ETXTBSY"_s), jsNumber(ETXTBSY)); +#endif +#ifdef EWOULDBLOCK + put(Identifier::fromString(vm, "EWOULDBLOCK"_s), jsNumber(EWOULDBLOCK)); +#endif +#ifdef EXDEV + put(Identifier::fromString(vm, "EXDEV"_s), jsNumber(EXDEV)); +#endif +#ifdef WSAEINTR + put(Identifier::fromString(vm, "WSAEINTR"_s), jsNumber(WSAEINTR)); +#endif +#ifdef WSAEBADF + put(Identifier::fromString(vm, "WSAEBADF"_s), jsNumber(WSAEBADF)); +#endif +#ifdef WSAEACCES + put(Identifier::fromString(vm, "WSAEACCES"_s), jsNumber(WSAEACCES)); +#endif +#ifdef WSAEFAULT + put(Identifier::fromString(vm, "WSAEFAULT"_s), jsNumber(WSAEFAULT)); +#endif +#ifdef WSAEINVAL + put(Identifier::fromString(vm, "WSAEINVAL"_s), jsNumber(WSAEINVAL)); +#endif +#ifdef WSAEMFILE + put(Identifier::fromString(vm, "WSAEMFILE"_s), jsNumber(WSAEMFILE)); +#endif +#ifdef WSAEWOULDBLOCK + put(Identifier::fromString(vm, "WSAEWOULDBLOCK"_s), jsNumber(WSAEWOULDBLOCK)); +#endif +#ifdef WSAEINPROGRESS + put(Identifier::fromString(vm, "WSAEINPROGRESS"_s), jsNumber(WSAEINPROGRESS)); +#endif +#ifdef WSAEALREADY + put(Identifier::fromString(vm, "WSAEALREADY"_s), jsNumber(WSAEALREADY)); +#endif +#ifdef WSAENOTSOCK + put(Identifier::fromString(vm, "WSAENOTSOCK"_s), jsNumber(WSAENOTSOCK)); +#endif +#ifdef WSAEDESTADDRREQ + put(Identifier::fromString(vm, "WSAEDESTADDRREQ"_s), jsNumber(WSAEDESTADDRREQ)); +#endif +#ifdef WSAEMSGSIZE + put(Identifier::fromString(vm, "WSAEMSGSIZE"_s), jsNumber(WSAEMSGSIZE)); +#endif +#ifdef WSAEPROTOTYPE + put(Identifier::fromString(vm, "WSAEPROTOTYPE"_s), jsNumber(WSAEPROTOTYPE)); +#endif +#ifdef WSAENOPROTOOPT + put(Identifier::fromString(vm, "WSAENOPROTOOPT"_s), jsNumber(WSAENOPROTOOPT)); +#endif +#ifdef WSAEPROTONOSUPPORT + put(Identifier::fromString(vm, "WSAEPROTONOSUPPORT"_s), jsNumber(WSAEPROTONOSUPPORT)); +#endif +#ifdef WSAESOCKTNOSUPPORT + put(Identifier::fromString(vm, "WSAESOCKTNOSUPPORT"_s), jsNumber(WSAESOCKTNOSUPPORT)); +#endif +#ifdef WSAEOPNOTSUPP + put(Identifier::fromString(vm, "WSAEOPNOTSUPP"_s), jsNumber(WSAEOPNOTSUPP)); +#endif +#ifdef WSAEPFNOSUPPORT + put(Identifier::fromString(vm, "WSAEPFNOSUPPORT"_s), jsNumber(WSAEPFNOSUPPORT)); +#endif +#ifdef WSAEAFNOSUPPORT + put(Identifier::fromString(vm, "WSAEAFNOSUPPORT"_s), jsNumber(WSAEAFNOSUPPORT)); +#endif +#ifdef WSAEADDRINUSE + put(Identifier::fromString(vm, "WSAEADDRINUSE"_s), jsNumber(WSAEADDRINUSE)); +#endif +#ifdef WSAEADDRNOTAVAIL + put(Identifier::fromString(vm, "WSAEADDRNOTAVAIL"_s), jsNumber(WSAEADDRNOTAVAIL)); +#endif +#ifdef WSAENETDOWN + put(Identifier::fromString(vm, "WSAENETDOWN"_s), jsNumber(WSAENETDOWN)); +#endif +#ifdef WSAENETUNREACH + put(Identifier::fromString(vm, "WSAENETUNREACH"_s), jsNumber(WSAENETUNREACH)); +#endif +#ifdef WSAENETRESET + put(Identifier::fromString(vm, "WSAENETRESET"_s), jsNumber(WSAENETRESET)); +#endif +#ifdef WSAECONNABORTED + put(Identifier::fromString(vm, "WSAECONNABORTED"_s), jsNumber(WSAECONNABORTED)); +#endif +#ifdef WSAECONNRESET + put(Identifier::fromString(vm, "WSAECONNRESET"_s), jsNumber(WSAECONNRESET)); +#endif +#ifdef WSAENOBUFS + put(Identifier::fromString(vm, "WSAENOBUFS"_s), jsNumber(WSAENOBUFS)); +#endif +#ifdef WSAEISCONN + put(Identifier::fromString(vm, "WSAEISCONN"_s), jsNumber(WSAEISCONN)); +#endif +#ifdef WSAENOTCONN + put(Identifier::fromString(vm, "WSAENOTCONN"_s), jsNumber(WSAENOTCONN)); +#endif +#ifdef WSAESHUTDOWN + put(Identifier::fromString(vm, "WSAESHUTDOWN"_s), jsNumber(WSAESHUTDOWN)); +#endif +#ifdef WSAETOOMANYREFS + put(Identifier::fromString(vm, "WSAETOOMANYREFS"_s), jsNumber(WSAETOOMANYREFS)); +#endif +#ifdef WSAETIMEDOUT + put(Identifier::fromString(vm, "WSAETIMEDOUT"_s), jsNumber(WSAETIMEDOUT)); +#endif +#ifdef WSAECONNREFUSED + put(Identifier::fromString(vm, "WSAECONNREFUSED"_s), jsNumber(WSAECONNREFUSED)); +#endif +#ifdef WSAELOOP + put(Identifier::fromString(vm, "WSAELOOP"_s), jsNumber(WSAELOOP)); +#endif +#ifdef WSAENAMETOOLONG + put(Identifier::fromString(vm, "WSAENAMETOOLONG"_s), jsNumber(WSAENAMETOOLONG)); +#endif +#ifdef WSAEHOSTDOWN + put(Identifier::fromString(vm, "WSAEHOSTDOWN"_s), jsNumber(WSAEHOSTDOWN)); +#endif +#ifdef WSAEHOSTUNREACH + put(Identifier::fromString(vm, "WSAEHOSTUNREACH"_s), jsNumber(WSAEHOSTUNREACH)); +#endif +#ifdef WSAENOTEMPTY + put(Identifier::fromString(vm, "WSAENOTEMPTY"_s), jsNumber(WSAENOTEMPTY)); +#endif +#ifdef WSAEPROCLIM + put(Identifier::fromString(vm, "WSAEPROCLIM"_s), jsNumber(WSAEPROCLIM)); +#endif +#ifdef WSAEUSERS + put(Identifier::fromString(vm, "WSAEUSERS"_s), jsNumber(WSAEUSERS)); +#endif +#ifdef WSAEDQUOT + put(Identifier::fromString(vm, "WSAEDQUOT"_s), jsNumber(WSAEDQUOT)); +#endif +#ifdef WSAESTALE + put(Identifier::fromString(vm, "WSAESTALE"_s), jsNumber(WSAESTALE)); +#endif +#ifdef WSAEREMOTE + put(Identifier::fromString(vm, "WSAEREMOTE"_s), jsNumber(WSAEREMOTE)); +#endif +#ifdef WSASYSNOTREADY + put(Identifier::fromString(vm, "WSASYSNOTREADY"_s), jsNumber(WSASYSNOTREADY)); +#endif +#ifdef WSAVERNOTSUPPORTED + put(Identifier::fromString(vm, "WSAVERNOTSUPPORTED"_s), jsNumber(WSAVERNOTSUPPORTED)); +#endif +#ifdef WSANOTINITIALISED + put(Identifier::fromString(vm, "WSANOTINITIALISED"_s), jsNumber(WSANOTINITIALISED)); +#endif +#ifdef WSAEDISCON + put(Identifier::fromString(vm, "WSAEDISCON"_s), jsNumber(WSAEDISCON)); +#endif +#ifdef WSAENOMORE + put(Identifier::fromString(vm, "WSAENOMORE"_s), jsNumber(WSAENOMORE)); +#endif +#ifdef WSAECANCELLED + put(Identifier::fromString(vm, "WSAECANCELLED"_s), jsNumber(WSAECANCELLED)); +#endif +#ifdef WSAEINVALIDPROCTABLE + put(Identifier::fromString(vm, "WSAEINVALIDPROCTABLE"_s), jsNumber(WSAEINVALIDPROCTABLE)); +#endif +#ifdef WSAEINVALIDPROVIDER + put(Identifier::fromString(vm, "WSAEINVALIDPROVIDER"_s), jsNumber(WSAEINVALIDPROVIDER)); +#endif +#ifdef WSAEPROVIDERFAILEDINIT + put(Identifier::fromString(vm, "WSAEPROVIDERFAILEDINIT"_s), jsNumber(WSAEPROVIDERFAILEDINIT)); +#endif +#ifdef WSASYSCALLFAILURE + put(Identifier::fromString(vm, "WSASYSCALLFAILURE"_s), jsNumber(WSASYSCALLFAILURE)); +#endif +#ifdef WSASERVICE_NOT_FOUND + put(Identifier::fromString(vm, "WSASERVICE_NOT_FOUND"_s), jsNumber(WSASERVICE_NOT_FOUND)); +#endif +#ifdef WSATYPE_NOT_FOUND + put(Identifier::fromString(vm, "WSATYPE_NOT_FOUND"_s), jsNumber(WSATYPE_NOT_FOUND)); +#endif +#ifdef WSA_E_NO_MORE + put(Identifier::fromString(vm, "WSA_E_NO_MORE"_s), jsNumber(WSA_E_NO_MORE)); +#endif +#ifdef WSA_E_CANCELLED + put(Identifier::fromString(vm, "WSA_E_CANCELLED"_s), jsNumber(WSA_E_CANCELLED)); +#endif +#ifdef WSAEREFUSED + put(Identifier::fromString(vm, "WSAEREFUSED"_s), jsNumber(WSAEREFUSED)); +#endif + put(Identifier::fromString(vm, "PRIORITY_LOW"_s), jsNumber(19)); + put(Identifier::fromString(vm, "PRIORITY_BELOW_NORMAL"_s), jsNumber(10)); + put(Identifier::fromString(vm, "PRIORITY_NORMAL"_s), jsNumber(0)); + put(Identifier::fromString(vm, "PRIORITY_ABOVE_NORMAL"_s), jsNumber(-7)); + put(Identifier::fromString(vm, "PRIORITY_HIGH"_s), jsNumber(-14)); + put(Identifier::fromString(vm, "PRIORITY_HIGHEST"_s), jsNumber(-20)); +#ifdef SIGHUP + put(Identifier::fromString(vm, "SIGHUP"_s), jsNumber(SIGHUP)); +#endif +#ifdef SIGINT + put(Identifier::fromString(vm, "SIGINT"_s), jsNumber(SIGINT)); +#endif +#ifdef SIGQUIT + put(Identifier::fromString(vm, "SIGQUIT"_s), jsNumber(SIGQUIT)); +#endif +#ifdef SIGILL + put(Identifier::fromString(vm, "SIGILL"_s), jsNumber(SIGILL)); +#endif +#ifdef SIGTRAP + put(Identifier::fromString(vm, "SIGTRAP"_s), jsNumber(SIGTRAP)); +#endif +#ifdef SIGABRT + put(Identifier::fromString(vm, "SIGABRT"_s), jsNumber(SIGABRT)); +#endif +#ifdef SIGIOT + put(Identifier::fromString(vm, "SIGIOT"_s), jsNumber(SIGIOT)); +#endif +#ifdef SIGBUS + put(Identifier::fromString(vm, "SIGBUS"_s), jsNumber(SIGBUS)); +#endif +#ifdef SIGFPE + put(Identifier::fromString(vm, "SIGFPE"_s), jsNumber(SIGFPE)); +#endif +#ifdef SIGKILL + put(Identifier::fromString(vm, "SIGKILL"_s), jsNumber(SIGKILL)); +#endif +#ifdef SIGUSR1 + put(Identifier::fromString(vm, "SIGUSR1"_s), jsNumber(SIGUSR1)); +#endif +#ifdef SIGSEGV + put(Identifier::fromString(vm, "SIGSEGV"_s), jsNumber(SIGSEGV)); +#endif +#ifdef SIGUSR2 + put(Identifier::fromString(vm, "SIGUSR2"_s), jsNumber(SIGUSR2)); +#endif +#ifdef SIGPIPE + put(Identifier::fromString(vm, "SIGPIPE"_s), jsNumber(SIGPIPE)); +#endif +#ifdef SIGALRM + put(Identifier::fromString(vm, "SIGALRM"_s), jsNumber(SIGALRM)); +#endif +#ifdef SIGTERM + put(Identifier::fromString(vm, "SIGTERM"_s), jsNumber(SIGTERM)); +#endif +#ifdef SIGCHLD + put(Identifier::fromString(vm, "SIGCHLD"_s), jsNumber(SIGCHLD)); +#endif +#ifdef SIGSTKFLT + put(Identifier::fromString(vm, "SIGSTKFLT"_s), jsNumber(SIGSTKFLT)); +#endif +#ifdef SIGCONT + put(Identifier::fromString(vm, "SIGCONT"_s), jsNumber(SIGCONT)); +#endif +#ifdef SIGSTOP + put(Identifier::fromString(vm, "SIGSTOP"_s), jsNumber(SIGSTOP)); +#endif +#ifdef SIGTSTP + put(Identifier::fromString(vm, "SIGTSTP"_s), jsNumber(SIGTSTP)); +#endif +#ifdef SIGBREAK + put(Identifier::fromString(vm, "SIGBREAK"_s), jsNumber(SIGBREAK)); +#endif +#ifdef SIGTTIN + put(Identifier::fromString(vm, "SIGTTIN"_s), jsNumber(SIGTTIN)); +#endif +#ifdef SIGTTOU + put(Identifier::fromString(vm, "SIGTTOU"_s), jsNumber(SIGTTOU)); +#endif +#ifdef SIGURG + put(Identifier::fromString(vm, "SIGURG"_s), jsNumber(SIGURG)); +#endif +#ifdef SIGXCPU + put(Identifier::fromString(vm, "SIGXCPU"_s), jsNumber(SIGXCPU)); +#endif +#ifdef SIGXFSZ + put(Identifier::fromString(vm, "SIGXFSZ"_s), jsNumber(SIGXFSZ)); +#endif +#ifdef SIGVTALRM + put(Identifier::fromString(vm, "SIGVTALRM"_s), jsNumber(SIGVTALRM)); +#endif +#ifdef SIGPROF + put(Identifier::fromString(vm, "SIGPROF"_s), jsNumber(SIGPROF)); +#endif +#ifdef SIGWINCH + put(Identifier::fromString(vm, "SIGWINCH"_s), jsNumber(SIGWINCH)); +#endif +#ifdef SIGIO + put(Identifier::fromString(vm, "SIGIO"_s), jsNumber(SIGIO)); +#endif +#ifdef SIGPOLL + put(Identifier::fromString(vm, "SIGPOLL"_s), jsNumber(SIGPOLL)); +#endif +#ifdef SIGLOST + put(Identifier::fromString(vm, "SIGLOST"_s), jsNumber(SIGLOST)); +#endif +#ifdef SIGPWR + put(Identifier::fromString(vm, "SIGPWR"_s), jsNumber(SIGPWR)); +#endif +#ifdef SIGINFO + put(Identifier::fromString(vm, "SIGINFO"_s), jsNumber(SIGINFO)); +#endif +#ifdef SIGSYS + put(Identifier::fromString(vm, "SIGSYS"_s), jsNumber(SIGSYS)); +#endif +#ifdef SIGUNUSED + put(Identifier::fromString(vm, "SIGUNUSED"_s), jsNumber(SIGUNUSED)); +#endif + put(Identifier::fromString(vm, "UV_FS_SYMLINK_DIR"_s), jsNumber(1)); + put(Identifier::fromString(vm, "UV_FS_SYMLINK_JUNCTION"_s), jsNumber(2)); + put(Identifier::fromString(vm, "O_RDONLY"_s), jsNumber(O_RDONLY)); + put(Identifier::fromString(vm, "O_WRONLY"_s), jsNumber(O_WRONLY)); + put(Identifier::fromString(vm, "O_RDWR"_s), jsNumber(O_RDWR)); + + put(Identifier::fromString(vm, "UV_DIRENT_UNKNOWN"_s), jsNumber(0)); + put(Identifier::fromString(vm, "UV_DIRENT_FILE"_s), jsNumber(1)); + put(Identifier::fromString(vm, "UV_DIRENT_DIR"_s), jsNumber(2)); + put(Identifier::fromString(vm, "UV_DIRENT_LINK"_s), jsNumber(3)); + put(Identifier::fromString(vm, "UV_DIRENT_FIFO"_s), jsNumber(4)); + put(Identifier::fromString(vm, "UV_DIRENT_SOCKET"_s), jsNumber(5)); + put(Identifier::fromString(vm, "UV_DIRENT_CHAR"_s), jsNumber(6)); + put(Identifier::fromString(vm, "UV_DIRENT_BLOCK"_s), jsNumber(7)); + + put(Identifier::fromString(vm, "S_IFMT"_s), jsNumber(S_IFMT)); + put(Identifier::fromString(vm, "S_IFREG"_s), jsNumber(S_IFREG)); + put(Identifier::fromString(vm, "S_IFDIR"_s), jsNumber(S_IFDIR)); + put(Identifier::fromString(vm, "S_IFCHR"_s), jsNumber(S_IFCHR)); +#ifdef S_IFBLK + put(Identifier::fromString(vm, "S_IFBLK"_s), jsNumber(S_IFBLK)); +#endif +#ifdef S_IFIFO + put(Identifier::fromString(vm, "S_IFIFO"_s), jsNumber(S_IFIFO)); +#endif +#ifdef S_IFLNK + put(Identifier::fromString(vm, "S_IFLNK"_s), jsNumber(S_IFLNK)); +#endif +#ifdef S_IFSOCK + put(Identifier::fromString(vm, "S_IFSOCK"_s), jsNumber(S_IFSOCK)); +#endif +#ifdef O_CREAT + put(Identifier::fromString(vm, "O_CREAT"_s), jsNumber(O_CREAT)); +#endif +#ifdef O_EXCL + put(Identifier::fromString(vm, "O_EXCL"_s), jsNumber(O_EXCL)); +#endif + put(Identifier::fromString(vm, "UV_FS_O_FILEMAP"_s), jsNumber(0)); + +#ifdef O_NOCTTY + put(Identifier::fromString(vm, "O_NOCTTY"_s), jsNumber(O_NOCTTY)); +#endif +#ifdef O_TRUNC + put(Identifier::fromString(vm, "O_TRUNC"_s), jsNumber(O_TRUNC)); +#endif +#ifdef O_APPEND + put(Identifier::fromString(vm, "O_APPEND"_s), jsNumber(O_APPEND)); +#endif +#ifdef O_DIRECTORY + put(Identifier::fromString(vm, "O_DIRECTORY"_s), jsNumber(O_DIRECTORY)); +#endif +#ifdef O_EXCL + put(Identifier::fromString(vm, "O_EXCL"_s), jsNumber(O_EXCL)); +#endif +#ifdef O_NOATIME + put(Identifier::fromString(vm, "O_NOATIME"_s), jsNumber(O_NOATIME)); +#endif +#ifdef O_NOFOLLOW + put(Identifier::fromString(vm, "O_NOFOLLOW"_s), jsNumber(O_NOFOLLOW)); +#endif +#ifdef O_SYNC + put(Identifier::fromString(vm, "O_SYNC"_s), jsNumber(O_SYNC)); +#endif +#ifdef O_DSYNC + put(Identifier::fromString(vm, "O_DSYNC"_s), jsNumber(O_DSYNC)); +#endif +#ifdef O_SYMLINK + put(Identifier::fromString(vm, "O_SYMLINK"_s), jsNumber(O_SYMLINK)); +#endif +#ifdef O_DIRECT + put(Identifier::fromString(vm, "O_DIRECT"_s), jsNumber(O_DIRECT)); +#endif +#ifdef O_NONBLOCK + put(Identifier::fromString(vm, "O_NONBLOCK"_s), jsNumber(O_NONBLOCK)); +#endif +#ifdef S_IRWXU + put(Identifier::fromString(vm, "S_IRWXU"_s), jsNumber(S_IRWXU)); +#endif +#ifdef S_IRUSR + put(Identifier::fromString(vm, "S_IRUSR"_s), jsNumber(S_IRUSR)); +#endif +#ifdef S_IWUSR + put(Identifier::fromString(vm, "S_IWUSR"_s), jsNumber(S_IWUSR)); +#endif +#ifdef S_IXUSR + put(Identifier::fromString(vm, "S_IXUSR"_s), jsNumber(S_IXUSR)); +#endif +#ifdef S_IRWXG + put(Identifier::fromString(vm, "S_IRWXG"_s), jsNumber(S_IRWXG)); +#endif +#ifdef S_IRGRP + put(Identifier::fromString(vm, "S_IRGRP"_s), jsNumber(S_IRGRP)); +#endif +#ifdef S_IWGRP + put(Identifier::fromString(vm, "S_IWGRP"_s), jsNumber(S_IWGRP)); +#endif +#ifdef S_IXGRP + put(Identifier::fromString(vm, "S_IXGRP"_s), jsNumber(S_IXGRP)); +#endif +#ifdef S_IRWXO + put(Identifier::fromString(vm, "S_IRWXO"_s), jsNumber(S_IRWXO)); +#endif +#ifdef S_IROTH + put(Identifier::fromString(vm, "S_IROTH"_s), jsNumber(S_IROTH)); +#endif +#ifdef S_IWOTH + put(Identifier::fromString(vm, "S_IWOTH"_s), jsNumber(S_IWOTH)); +#endif +#ifdef S_IXOTH + put(Identifier::fromString(vm, "S_IXOTH"_s), jsNumber(S_IXOTH)); +#endif +#ifdef F_OK + put(Identifier::fromString(vm, "F_OK"_s), jsNumber(F_OK)); +#endif +#ifdef R_OK + put(Identifier::fromString(vm, "R_OK"_s), jsNumber(R_OK)); +#endif +#ifdef W_OK + put(Identifier::fromString(vm, "W_OK"_s), jsNumber(W_OK)); +#endif +#ifdef X_OK + put(Identifier::fromString(vm, "X_OK"_s), jsNumber(X_OK)); +#endif + put(Identifier::fromString(vm, "UV_FS_COPYFILE_EXCL"_s), jsNumber(1)); + put(Identifier::fromString(vm, "COPYFILE_EXCL"_s), jsNumber(1)); + put(Identifier::fromString(vm, "UV_FS_COPYFILE_FICLONE"_s), jsNumber(2)); + put(Identifier::fromString(vm, "COPYFILE_FICLONE"_s), jsNumber(2)); + put(Identifier::fromString(vm, "UV_FS_COPYFILE_FICLONE_FORCE"_s), jsNumber(4)); + put(Identifier::fromString(vm, "COPYFILE_FICLONE_FORCE"_s), jsNumber(4)); +#ifdef OPENSSL_VERSION_NUMBER + put(Identifier::fromString(vm, "OPENSSL_VERSION_NUMBER"_s), jsNumber(OPENSSL_VERSION_NUMBER)); +#endif +#ifdef SSL_OP_ALL + put(Identifier::fromString(vm, "SSL_OP_ALL"_s), jsNumber(SSL_OP_ALL)); +#endif +#ifdef SSL_OP_ALLOW_NO_DHE_KEX + put(Identifier::fromString(vm, "SSL_OP_ALLOW_NO_DHE_KEX"_s), jsNumber(SSL_OP_ALLOW_NO_DHE_KEX)); +#endif +#ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION + put(Identifier::fromString(vm, "SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION"_s), jsNumber(SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)); +#endif +#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE + put(Identifier::fromString(vm, "SSL_OP_CIPHER_SERVER_PREFERENCE"_s), jsNumber(SSL_OP_CIPHER_SERVER_PREFERENCE)); +#endif +#ifdef SSL_OP_CISCO_ANYCONNECT + put(Identifier::fromString(vm, "SSL_OP_CISCO_ANYCONNECT"_s), jsNumber(SSL_OP_CISCO_ANYCONNECT)); +#endif +#ifdef SSL_OP_COOKIE_EXCHANGE + put(Identifier::fromString(vm, "SSL_OP_COOKIE_EXCHANGE"_s), jsNumber(SSL_OP_COOKIE_EXCHANGE)); +#endif +#ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG + put(Identifier::fromString(vm, "SSL_OP_CRYPTOPRO_TLSEXT_BUG"_s), jsNumber(SSL_OP_CRYPTOPRO_TLSEXT_BUG)); +#endif +#ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS + put(Identifier::fromString(vm, "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS"_s), jsNumber(SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)); +#endif +#ifdef SSL_OP_LEGACY_SERVER_CONNECT + put(Identifier::fromString(vm, "SSL_OP_LEGACY_SERVER_CONNECT"_s), jsNumber(SSL_OP_LEGACY_SERVER_CONNECT)); +#endif +#ifdef SSL_OP_NO_COMPRESSION + put(Identifier::fromString(vm, "SSL_OP_NO_COMPRESSION"_s), jsNumber(SSL_OP_NO_COMPRESSION)); +#endif +#ifdef SSL_OP_NO_ENCRYPT_THEN_MAC + put(Identifier::fromString(vm, "SSL_OP_NO_ENCRYPT_THEN_MAC"_s), jsNumber(SSL_OP_NO_ENCRYPT_THEN_MAC)); +#endif +#ifdef SSL_OP_NO_QUERY_MTU + put(Identifier::fromString(vm, "SSL_OP_NO_QUERY_MTU"_s), jsNumber(SSL_OP_NO_QUERY_MTU)); +#endif +#ifdef SSL_OP_NO_RENEGOTIATION + put(Identifier::fromString(vm, "SSL_OP_NO_RENEGOTIATION"_s), jsNumber(SSL_OP_NO_RENEGOTIATION)); +#endif +#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION + put(Identifier::fromString(vm, "SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION"_s), jsNumber(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)); +#endif +#ifdef SSL_OP_NO_SSLv2 + put(Identifier::fromString(vm, "SSL_OP_NO_SSLv2"_s), jsNumber(SSL_OP_NO_SSLv2)); +#endif +#ifdef SSL_OP_NO_SSLv3 + put(Identifier::fromString(vm, "SSL_OP_NO_SSLv3"_s), jsNumber(SSL_OP_NO_SSLv3)); +#endif +#ifdef SSL_OP_NO_TICKET + put(Identifier::fromString(vm, "SSL_OP_NO_TICKET"_s), jsNumber(SSL_OP_NO_TICKET)); +#endif +#ifdef SSL_OP_NO_TLSv1 + put(Identifier::fromString(vm, "SSL_OP_NO_TLSv1"_s), jsNumber(SSL_OP_NO_TLSv1)); +#endif +#ifdef SSL_OP_NO_TLSv1_1 + put(Identifier::fromString(vm, "SSL_OP_NO_TLSv1_1"_s), jsNumber(SSL_OP_NO_TLSv1_1)); +#endif +#ifdef SSL_OP_NO_TLSv1_2 + put(Identifier::fromString(vm, "SSL_OP_NO_TLSv1_2"_s), jsNumber(SSL_OP_NO_TLSv1_2)); +#endif +#ifdef SSL_OP_NO_TLSv1_3 + put(Identifier::fromString(vm, "SSL_OP_NO_TLSv1_3"_s), jsNumber(SSL_OP_NO_TLSv1_3)); +#endif +#ifdef SSL_OP_PRIORITIZE_CHACHA + put(Identifier::fromString(vm, "SSL_OP_PRIORITIZE_CHACHA"_s), jsNumber(SSL_OP_PRIORITIZE_CHACHA)); +#endif +#ifdef SSL_OP_TLS_ROLLBACK_BUG + put(Identifier::fromString(vm, "SSL_OP_TLS_ROLLBACK_BUG"_s), jsNumber(SSL_OP_TLS_ROLLBACK_BUG)); +#endif +#ifndef OPENSSL_NO_ENGINE +#ifdef ENGINE_METHOD_RSA + put(Identifier::fromString(vm, "ENGINE_METHOD_RSA"_s), jsNumber(ENGINE_METHOD_RSA)); +#endif +#ifdef ENGINE_METHOD_DSA + put(Identifier::fromString(vm, "ENGINE_METHOD_DSA"_s), jsNumber(ENGINE_METHOD_DSA)); +#endif +#ifdef ENGINE_METHOD_DH + put(Identifier::fromString(vm, "ENGINE_METHOD_DH"_s), jsNumber(ENGINE_METHOD_DH)); +#endif +#ifdef ENGINE_METHOD_RAND + put(Identifier::fromString(vm, "ENGINE_METHOD_RAND"_s), jsNumber(ENGINE_METHOD_RAND)); +#endif +#ifdef ENGINE_METHOD_EC + put(Identifier::fromString(vm, "ENGINE_METHOD_EC"_s), jsNumber(ENGINE_METHOD_EC)); +#endif +#ifdef ENGINE_METHOD_CIPHERS + put(Identifier::fromString(vm, "ENGINE_METHOD_CIPHERS"_s), jsNumber(ENGINE_METHOD_CIPHERS)); +#endif +#ifdef ENGINE_METHOD_DIGESTS + put(Identifier::fromString(vm, "ENGINE_METHOD_DIGESTS"_s), jsNumber(ENGINE_METHOD_DIGESTS)); +#endif +#ifdef ENGINE_METHOD_PKEY_METHS + put(Identifier::fromString(vm, "ENGINE_METHOD_PKEY_METHS"_s), jsNumber(ENGINE_METHOD_PKEY_METHS)); +#endif +#ifdef ENGINE_METHOD_PKEY_ASN1_METHS + put(Identifier::fromString(vm, "ENGINE_METHOD_PKEY_ASN1_METHS"_s), jsNumber(ENGINE_METHOD_PKEY_ASN1_METHS)); +#endif +#ifdef ENGINE_METHOD_ALL + put(Identifier::fromString(vm, "ENGINE_METHOD_ALL"_s), jsNumber(ENGINE_METHOD_ALL)); +#endif +#ifdef ENGINE_METHOD_NONE + put(Identifier::fromString(vm, "ENGINE_METHOD_NONE"_s), jsNumber(ENGINE_METHOD_NONE)); +#endif +#endif // !OPENSSL_NO_ENGINE +#ifdef DH_CHECK_P_NOT_SAFE_PRIME + put(Identifier::fromString(vm, "DH_CHECK_P_NOT_SAFE_PRIME"_s), jsNumber(DH_CHECK_P_NOT_SAFE_PRIME)); +#endif +#ifdef DH_CHECK_P_NOT_PRIME + put(Identifier::fromString(vm, "DH_CHECK_P_NOT_PRIME"_s), jsNumber(DH_CHECK_P_NOT_PRIME)); +#endif +#ifdef DH_UNABLE_TO_CHECK_GENERATOR + put(Identifier::fromString(vm, "DH_UNABLE_TO_CHECK_GENERATOR"_s), jsNumber(DH_UNABLE_TO_CHECK_GENERATOR)); +#endif +#ifdef DH_NOT_SUITABLE_GENERATOR + put(Identifier::fromString(vm, "DH_NOT_SUITABLE_GENERATOR"_s), jsNumber(DH_NOT_SUITABLE_GENERATOR)); +#endif +#ifdef RSA_PKCS1_PADDING + put(Identifier::fromString(vm, "RSA_PKCS1_PADDING"_s), jsNumber(RSA_PKCS1_PADDING)); +#endif +#ifdef RSA_SSLV23_PADDING + put(Identifier::fromString(vm, "RSA_SSLV23_PADDING"_s), jsNumber(RSA_SSLV23_PADDING)); +#endif +#ifdef RSA_NO_PADDING + put(Identifier::fromString(vm, "RSA_NO_PADDING"_s), jsNumber(RSA_NO_PADDING)); +#endif +#ifdef RSA_PKCS1_OAEP_PADDING + put(Identifier::fromString(vm, "RSA_PKCS1_OAEP_PADDING"_s), jsNumber(RSA_PKCS1_OAEP_PADDING)); +#endif +#ifdef RSA_X931_PADDING + put(Identifier::fromString(vm, "RSA_X931_PADDING"_s), jsNumber(RSA_X931_PADDING)); +#endif +#ifdef RSA_PKCS1_PSS_PADDING + put(Identifier::fromString(vm, "RSA_PKCS1_PSS_PADDING"_s), jsNumber(RSA_PKCS1_PSS_PADDING)); +#endif +#ifdef RSA_PSS_SALTLEN_DIGEST + put(Identifier::fromString(vm, "RSA_PSS_SALTLEN_DIGEST"_s), jsNumber(RSA_PSS_SALTLEN_DIGEST)); +#endif +#ifdef RSA_PSS_SALTLEN_MAX_SIGN + put(Identifier::fromString(vm, "RSA_PSS_SALTLEN_MAX_SIGN"_s), jsNumber(RSA_PSS_SALTLEN_MAX_SIGN)); +#endif +#ifdef RSA_PSS_SALTLEN_AUTO + put(Identifier::fromString(vm, "RSA_PSS_SALTLEN_AUTO"_s), jsNumber(RSA_PSS_SALTLEN_AUTO)); +#endif + auto cipherList = String("TLS_AES_256_GCM_SHA384:" + "TLS_CHACHA20_POLY1305_SHA256:" + "TLS_AES_128_GCM_SHA256:" + "ECDHE-RSA-AES128-GCM-SHA256:" + "ECDHE-ECDSA-AES128-GCM-SHA256:" + "ECDHE-RSA-AES256-GCM-SHA384:" + "ECDHE-ECDSA-AES256-GCM-SHA384:" + "DHE-RSA-AES128-GCM-SHA256:" + "ECDHE-RSA-AES128-SHA256:" + "DHE-RSA-AES128-SHA256:" + "ECDHE-RSA-AES256-SHA384:" + "DHE-RSA-AES256-SHA384:" + "ECDHE-RSA-AES256-SHA256:" + "DHE-RSA-AES256-SHA256:" + "HIGH:" + "!aNULL:" + "!eNULL:" + "!EXPORT:" + "!DES:" + "!RC4:" + "!MD5:" + "!PSK:" + "!SRP:" + "!CAMELLIA"_s); + put(Identifier::fromString(vm, "defaultCoreCipherList"_s), + jsString(vm, cipherList)); + put(Identifier::fromString(vm, "defaultCipherList"_s), + jsString(vm, cipherList)); +#ifdef TLS1_VERSION + put(Identifier::fromString(vm, "TLS1_VERSION"_s), jsNumber(TLS1_VERSION)); +#endif +#ifdef TLS1_1_VERSION + put(Identifier::fromString(vm, "TLS1_1_VERSION"_s), jsNumber(TLS1_1_VERSION)); +#endif +#ifdef TLS1_2_VERSION + put(Identifier::fromString(vm, "TLS1_2_VERSION"_s), jsNumber(TLS1_2_VERSION)); +#endif +#ifdef TLS1_3_VERSION + put(Identifier::fromString(vm, "TLS1_3_VERSION"_s), jsNumber(TLS1_3_VERSION)); +#endif + put(Identifier::fromString(vm, "POINT_CONVERSION_COMPRESSED"_s), jsNumber(POINT_CONVERSION_COMPRESSED)); + put(Identifier::fromString(vm, "POINT_CONVERSION_UNCOMPRESSED"_s), jsNumber(POINT_CONVERSION_UNCOMPRESSED)); + put(Identifier::fromString(vm, "POINT_CONVERSION_HYBRID"_s), jsNumber(POINT_CONVERSION_HYBRID)); + RETURN_NATIVE_MODULE(); +} + +} // namespace Zig diff --git a/src/bun.js/modules/NodeModuleModule.cpp b/src/bun.js/modules/NodeModuleModule.cpp deleted file mode 100644 index 476ee95dc..000000000 --- a/src/bun.js/modules/NodeModuleModule.cpp +++ /dev/null @@ -1,297 +0,0 @@ -#include "root.h" - -#include "./NodeModuleModule.h" - -#include "CommonJSModuleRecord.h" -#include "ImportMetaObject.h" -#include "JavaScriptCore/JSBoundFunction.h" -#include "JavaScriptCore/ObjectConstructor.h" -using namespace Zig; -using namespace JSC; - -// This is a mix of bun's builtin module names and also the ones reported by -// node v20.4.0 -static constexpr ASCIILiteral builtinModuleNames[] = { - "_http_agent"_s, - "_http_client"_s, - "_http_common"_s, - "_http_incoming"_s, - "_http_outgoing"_s, - "_http_server"_s, - "_stream_duplex"_s, - "_stream_passthrough"_s, - "_stream_readable"_s, - "_stream_transform"_s, - "_stream_wrap"_s, - "_stream_writable"_s, - "_tls_common"_s, - "_tls_wrap"_s, - "assert"_s, - "assert/strict"_s, - "async_hooks"_s, - "buffer"_s, - "bun"_s, - "bun:events_native"_s, - "bun:ffi"_s, - "bun:jsc"_s, - "bun:sqlite"_s, - "bun:wrap"_s, - "child_process"_s, - "cluster"_s, - "console"_s, - "constants"_s, - "crypto"_s, - "detect-libc"_s, - "dgram"_s, - "diagnostics_channel"_s, - "dns"_s, - "dns/promises"_s, - "domain"_s, - "events"_s, - "fs"_s, - "fs/promises"_s, - "http"_s, - "http2"_s, - "https"_s, - "inspector"_s, - "inspector/promises"_s, - "module"_s, - "net"_s, - "os"_s, - "path"_s, - "path/posix"_s, - "path/win32"_s, - "perf_hooks"_s, - "process"_s, - "punycode"_s, - "querystring"_s, - "readline"_s, - "readline/promises"_s, - "repl"_s, - "stream"_s, - "stream/consumers"_s, - "stream/promises"_s, - "stream/web"_s, - "string_decoder"_s, - "sys"_s, - "timers"_s, - "timers/promises"_s, - "tls"_s, - "trace_events"_s, - "tty"_s, - "undici"_s, - "url"_s, - "util"_s, - "util/types"_s, - "v8"_s, - "vm"_s, - "wasi"_s, - "worker_threads"_s, - "ws"_s, - "zlib"_s, -}; - -static bool isBuiltinModule(const String &namePossiblyWithNodePrefix) { - String name = namePossiblyWithNodePrefix; - if (name.startsWith("node:"_s)) - name = name.substringSharingImpl(5); - - for (auto &builtinModule : builtinModuleNames) { - if (name == builtinModule) - return true; - } - return false; -} - -JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBuiltinModule, - (JSC::JSGlobalObject * globalObject, - JSC::CallFrame *callFrame)) { - JSC::VM &vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - JSValue moduleName = callFrame->argument(0); - if (!moduleName.isString()) { - return JSValue::encode(jsBoolean(false)); - } - - auto moduleStr = moduleName.toWTFString(globalObject); - RETURN_IF_EXCEPTION(scope, JSValue::encode(jsBoolean(false))); - - return JSValue::encode(jsBoolean(isBuiltinModule(moduleStr))); -} - -JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeModuleCreateRequire, - (JSC::JSGlobalObject * globalObject, - JSC::CallFrame *callFrame)) { - JSC::VM &vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - if (callFrame->argumentCount() < 1) { - throwTypeError(globalObject, scope, - "createRequire() requires at least one argument"_s); - RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsUndefined())); - } - - auto val = callFrame->uncheckedArgument(0).toWTFString(globalObject); - RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(JSC::jsUndefined())); - RELEASE_AND_RETURN( - scope, JSValue::encode(Bun::JSCommonJSModule::createBoundRequireFunction( - vm, globalObject, val))); -} -extern "C" EncodedJSValue Resolver__nodeModulePathsForJS(JSGlobalObject *, - CallFrame *); - -JSC_DEFINE_HOST_FUNCTION(jsFunctionFindSourceMap, - (JSGlobalObject * globalObject, - CallFrame *callFrame)) { - auto &vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - throwException(globalObject, scope, - createError(globalObject, "Not implemented"_s)); - return JSValue::encode(jsUndefined()); -} - -JSC_DEFINE_HOST_FUNCTION(jsFunctionSyncBuiltinExports, - (JSGlobalObject * globalObject, - CallFrame *callFrame)) { - return JSValue::encode(jsUndefined()); -} - -JSC_DEFINE_HOST_FUNCTION(jsFunctionSourceMap, (JSGlobalObject * globalObject, - CallFrame *callFrame)) { - auto &vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - throwException(globalObject, scope, - createError(globalObject, "Not implemented"_s)); - return JSValue::encode(jsUndefined()); -} - -JSC_DEFINE_HOST_FUNCTION(jsFunctionResolveFileName, - (JSC::JSGlobalObject * globalObject, - JSC::CallFrame *callFrame)) { - JSC::VM &vm = globalObject->vm(); - - switch (callFrame->argumentCount()) { - case 0: { - auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); - // not "requires" because "require" could be confusing - JSC::throwTypeError( - globalObject, scope, - "Module._resolveFileName needs 2+ arguments (a string)"_s); - scope.release(); - return JSC::JSValue::encode(JSC::JSValue{}); - } - default: { - JSC::JSValue moduleName = callFrame->argument(0); - - if (moduleName.isUndefinedOrNull()) { - auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); - JSC::throwTypeError(globalObject, scope, - "Module._resolveFileName expects a string"_s); - scope.release(); - return JSC::JSValue::encode(JSC::JSValue{}); - } - - auto result = - Bun__resolveSync(globalObject, JSC::JSValue::encode(moduleName), - JSValue::encode(callFrame->argument(1)), false); - auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); - - if (!JSC::JSValue::decode(result).isString()) { - JSC::throwException(globalObject, scope, JSC::JSValue::decode(result)); - return JSC::JSValue::encode(JSC::JSValue{}); - } - - scope.release(); - return result; - } - } -} -template <std::size_t N, class T> consteval std::size_t countof(T (&)[N]) { - return N; -} - -namespace Zig { -void generateNodeModuleModule(JSC::JSGlobalObject *globalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues) { - JSC::VM &vm = globalObject->vm(); - - JSObject *defaultObject = JSC::constructEmptyObject( - vm, globalObject->nullPrototypeObjectStructure()); - auto append = [&](Identifier name, JSValue value) { - defaultObject->putDirect(vm, name, value); - exportNames.append(name); - exportValues.append(value); - }; - - append(Identifier::fromString(vm, "createRequire"_s), - JSFunction::create(vm, globalObject, 1, String("createRequire"_s), - jsFunctionNodeModuleCreateRequire, - ImplementationVisibility::Public)); - - append(Identifier::fromString(vm, "paths"_s), - JSFunction::create(vm, globalObject, 1, String("paths"_s), - Resolver__nodeModulePathsForJS, - ImplementationVisibility::Public)); - - append(Identifier::fromString(vm, "findSourceMap"_s), - JSFunction::create(vm, globalObject, 1, String("findSourceMap"_s), - jsFunctionFindSourceMap, - ImplementationVisibility::Public)); - append(Identifier::fromString(vm, "syncBuiltinExports"_s), - JSFunction::create(vm, globalObject, 0, String("syncBuiltinExports"_s), - jsFunctionSyncBuiltinExports, - ImplementationVisibility::Public)); - append(Identifier::fromString(vm, "SourceMap"_s), - JSFunction::create(vm, globalObject, 1, String("SourceMap"_s), - jsFunctionSourceMap, - ImplementationVisibility::Public, NoIntrinsic, - jsFunctionSourceMap, nullptr)); - - append(Identifier::fromString(vm, "isBuiltin"_s), - JSFunction::create(vm, globalObject, 1, String("isBuiltin"_s), - jsFunctionIsBuiltinModule, - ImplementationVisibility::Public, NoIntrinsic, - jsFunctionIsBuiltinModule, nullptr)); - - append(JSC::Identifier::fromString(vm, "_resolveFilename"_s), - JSFunction::create(vm, globalObject, 3, String("_resolveFilename"_s), - jsFunctionResolveFileName, - ImplementationVisibility::Public)); - - append(JSC::Identifier::fromString(vm, "_nodeModulePaths"_s), - JSFunction::create(vm, globalObject, 0, String("_nodeModulePaths"_s), - Resolver__nodeModulePathsForJS, - ImplementationVisibility::Public)); - - append(JSC::Identifier::fromString(vm, "_cache"_s), - jsCast<Zig::GlobalObject *>(globalObject)->lazyRequireCacheObject()); - - append(JSC::Identifier::fromString(vm, "globalPaths"_s), - JSC::constructEmptyArray(globalObject, nullptr, 0)); - - append(JSC::Identifier::fromString(vm, "prototype"_s), - JSC::constructEmptyObject(globalObject)); - - JSC::JSArray *builtinModules = JSC::JSArray::create( - vm, - globalObject->arrayStructureForIndexingTypeDuringAllocation( - ArrayWithContiguous), - countof(builtinModuleNames)); - - for (unsigned i = 0; i < countof(builtinModuleNames); ++i) { - builtinModules->putDirectIndex( - globalObject, i, JSC::jsString(vm, String(builtinModuleNames[i]))); - } - - append(JSC::Identifier::fromString(vm, "builtinModules"_s), builtinModules); - - defaultObject->putDirect(vm, - JSC::PropertyName(Identifier::fromUid( - vm.symbolRegistry().symbolForKey("CommonJS"_s))), - jsNumber(0), 0); - - exportNames.append(vm.propertyNames->defaultKeyword); - exportValues.append(defaultObject); -} -} // namespace Zig diff --git a/src/bun.js/modules/NodeModuleModule.h b/src/bun.js/modules/NodeModuleModule.h index 0aefdef12..e51f2ac86 100644 --- a/src/bun.js/modules/NodeModuleModule.h +++ b/src/bun.js/modules/NodeModuleModule.h @@ -1,12 +1,320 @@ -#include "../bindings/ZigGlobalObject.h" -#include "JavaScriptCore/JSGlobalObject.h" +#include "CommonJSModuleRecord.h" +#include "ImportMetaObject.h" +#include "JavaScriptCore/JSBoundFunction.h" +#include "JavaScriptCore/ObjectConstructor.h" +#include "_NativeModule.h" + +using namespace Zig; +using namespace JSC; + +// This is a mix of bun's builtin module names and also the ones reported by +// node v20.4.0 +static constexpr ASCIILiteral builtinModuleNames[] = { + "_http_agent"_s, + "_http_client"_s, + "_http_common"_s, + "_http_incoming"_s, + "_http_outgoing"_s, + "_http_server"_s, + "_stream_duplex"_s, + "_stream_passthrough"_s, + "_stream_readable"_s, + "_stream_transform"_s, + "_stream_wrap"_s, + "_stream_writable"_s, + "_tls_common"_s, + "_tls_wrap"_s, + "assert"_s, + "assert/strict"_s, + "async_hooks"_s, + "buffer"_s, + "bun"_s, + "bun:ffi"_s, + "bun:jsc"_s, + "bun:sqlite"_s, + "bun:wrap"_s, + "child_process"_s, + "cluster"_s, + "console"_s, + "constants"_s, + "crypto"_s, + "detect-libc"_s, + "dgram"_s, + "diagnostics_channel"_s, + "dns"_s, + "dns/promises"_s, + "domain"_s, + "events"_s, + "fs"_s, + "fs/promises"_s, + "http"_s, + "http2"_s, + "https"_s, + "inspector"_s, + "inspector/promises"_s, + "module"_s, + "net"_s, + "os"_s, + "path"_s, + "path/posix"_s, + "path/win32"_s, + "perf_hooks"_s, + "process"_s, + "punycode"_s, + "querystring"_s, + "readline"_s, + "readline/promises"_s, + "repl"_s, + "stream"_s, + "stream/consumers"_s, + "stream/promises"_s, + "stream/web"_s, + "string_decoder"_s, + "sys"_s, + "timers"_s, + "timers/promises"_s, + "tls"_s, + "trace_events"_s, + "tty"_s, + "undici"_s, + "url"_s, + "util"_s, + "util/types"_s, + "v8"_s, + "vm"_s, + "wasi"_s, + "worker_threads"_s, + "ws"_s, + "zlib"_s, +}; + +static bool isBuiltinModule(const String &namePossiblyWithNodePrefix) { + String name = namePossiblyWithNodePrefix; + if (name.startsWith("node:"_s)) + name = name.substringSharingImpl(5); + + for (auto &builtinModule : builtinModuleNames) { + if (name == builtinModule) + return true; + } + return false; +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeModuleModuleConstructor, + (JSC::JSGlobalObject * globalObject, + JSC::CallFrame *callFrame)) { + // In node, this is supposed to be the actual CommonJSModule constructor. + // We are cutting a huge corner by not doing all that work. + // This code is only to support babel. + JSC::VM &vm = globalObject->vm(); + JSString *idString = JSC::jsString(vm, WTF::String("."_s)); + + JSString *dirname = jsEmptyString(vm); + + // TODO: handle when JSGlobalObject !== Zig::GlobalObject, such as in node:vm + Structure *structure = static_cast<Zig::GlobalObject *>(globalObject) + ->CommonJSModuleObjectStructure(); + + // TODO: handle ShadowRealm, node:vm, new.target, subclasses + JSValue idValue = callFrame->argument(0); + JSValue parentValue = callFrame->argument(1); + + auto scope = DECLARE_THROW_SCOPE(vm); + if (idValue.isString()) { + idString = idValue.toString(globalObject); + RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(JSC::jsUndefined())); + + auto index = idString->tryGetValue().reverseFind('/', idString->length()); + + if (index != WTF::notFound) { + dirname = JSC::jsSubstring(globalObject, idString, 0, index); + } + } + + auto *out = Bun::JSCommonJSModule::create(vm, structure, idString, jsNull(), + dirname, nullptr); + + if (!parentValue.isUndefined()) + out->putDirect(vm, JSC::Identifier::fromString(vm, "parent"_s), parentValue, + 0); + + return JSValue::encode(out); +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBuiltinModule, + (JSC::JSGlobalObject * globalObject, + JSC::CallFrame *callFrame)) { + JSC::VM &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + JSValue moduleName = callFrame->argument(0); + if (!moduleName.isString()) { + return JSValue::encode(jsBoolean(false)); + } + + auto moduleStr = moduleName.toWTFString(globalObject); + RETURN_IF_EXCEPTION(scope, JSValue::encode(jsBoolean(false))); + + return JSValue::encode(jsBoolean(isBuiltinModule(moduleStr))); +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeModuleCreateRequire, + (JSC::JSGlobalObject * globalObject, + JSC::CallFrame *callFrame)) { + JSC::VM &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + if (callFrame->argumentCount() < 1) { + throwTypeError(globalObject, scope, + "createRequire() requires at least one argument"_s); + RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsUndefined())); + } + + auto val = callFrame->uncheckedArgument(0).toWTFString(globalObject); + RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(JSC::jsUndefined())); + RELEASE_AND_RETURN( + scope, JSValue::encode(Bun::JSCommonJSModule::createBoundRequireFunction( + vm, globalObject, val))); +} +extern "C" EncodedJSValue Resolver__nodeModulePathsForJS(JSGlobalObject *, + CallFrame *); + +JSC_DEFINE_HOST_FUNCTION(jsFunctionFindSourceMap, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + auto &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + throwException(globalObject, scope, + createError(globalObject, "Not implemented"_s)); + return JSValue::encode(jsUndefined()); +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionSyncBuiltinExports, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + return JSValue::encode(jsUndefined()); +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionSourceMap, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + auto &vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + throwException(globalObject, scope, + createError(globalObject, "Not implemented"_s)); + return JSValue::encode(jsUndefined()); +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionResolveFileName, + (JSC::JSGlobalObject * globalObject, + JSC::CallFrame *callFrame)) { + JSC::VM &vm = globalObject->vm(); + + switch (callFrame->argumentCount()) { + case 0: { + auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); + // not "requires" because "require" could be confusing + JSC::throwTypeError( + globalObject, scope, + "Module._resolveFileName needs 2+ arguments (a string)"_s); + scope.release(); + return JSC::JSValue::encode(JSC::JSValue{}); + } + default: { + JSC::JSValue moduleName = callFrame->argument(0); + + if (moduleName.isUndefinedOrNull()) { + auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); + JSC::throwTypeError(globalObject, scope, + "Module._resolveFileName expects a string"_s); + scope.release(); + return JSC::JSValue::encode(JSC::JSValue{}); + } + + auto result = + Bun__resolveSync(globalObject, JSC::JSValue::encode(moduleName), + JSValue::encode(callFrame->argument(1)), false); + auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); + + if (!JSC::JSValue::decode(result).isString()) { + JSC::throwException(globalObject, scope, JSC::JSValue::decode(result)); + return JSC::JSValue::encode(JSC::JSValue{}); + } + + scope.release(); + return result; + } + } +} +template <std::size_t N, class T> consteval std::size_t countof(T (&)[N]) { + return N; +} namespace Zig { -// node:module -void generateNodeModuleModule(JSC::JSGlobalObject *globalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues); +DEFINE_NATIVE_MODULE(NodeModule) { + // the default object here is a function, so we cant use the INIT_NATIVE_MODULE helper + + Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject *>(lexicalGlobalObject); + JSC::VM &vm = globalObject->vm(); + JSC::JSObject *defaultObject = JSC::JSFunction::create( + vm, globalObject, 0, "Module"_s, jsFunctionNodeModuleModuleConstructor, + JSC::ImplementationVisibility::Public, JSC::NoIntrinsic, + jsFunctionNodeModuleModuleConstructor); + auto put = [&](JSC::Identifier name, JSC::JSValue value) { + defaultObject->putDirect(vm, name, value); + exportNames.append(name); + exportValues.append(value); + }; + auto putNativeFn = [&](JSC::Identifier name, JSC::NativeFunction ptr) { + JSC::JSFunction *value = JSC::JSFunction::create( + vm, globalObject, 1, name.string(), ptr, + JSC::ImplementationVisibility::Public, JSC::NoIntrinsic, ptr); + defaultObject->putDirect(vm, name, value); + exportNames.append(name); + exportValues.append(value); + }; + exportNames.reserveCapacity(13); + exportValues.ensureCapacity(13); + exportNames.append(vm.propertyNames->defaultKeyword); + exportValues.append(defaultObject); + + putNativeFn(Identifier::fromString(vm, "createRequire"_s), + jsFunctionNodeModuleCreateRequire); + putNativeFn(Identifier::fromString(vm, "paths"_s), + Resolver__nodeModulePathsForJS); + putNativeFn(Identifier::fromString(vm, "findSourceMap"_s), + jsFunctionFindSourceMap); + putNativeFn(Identifier::fromString(vm, "syncBuiltinExports"_s), + jsFunctionSyncBuiltinExports); + putNativeFn(Identifier::fromString(vm, "SourceMap"_s), jsFunctionSourceMap); + putNativeFn(Identifier::fromString(vm, "isBuiltin"_s), + jsFunctionIsBuiltinModule); + putNativeFn(Identifier::fromString(vm, "_resolveFilename"_s), + jsFunctionResolveFileName); + putNativeFn(Identifier::fromString(vm, "_nodeModulePaths"_s), + Resolver__nodeModulePathsForJS); + + put(Identifier::fromString(vm, "_cache"_s), + jsCast<Zig::GlobalObject *>(globalObject)->lazyRequireCacheObject()); + + put(Identifier::fromString(vm, "globalPaths"_s), + constructEmptyArray(globalObject, nullptr, 0)); + + put(Identifier::fromString(vm, "prototype"_s), + constructEmptyObject(globalObject)); + + JSC::JSArray *builtinModules = JSC::JSArray::create( + vm, + globalObject->arrayStructureForIndexingTypeDuringAllocation( + ArrayWithContiguous), + countof(builtinModuleNames)); + + for (unsigned i = 0; i < countof(builtinModuleNames); ++i) { + builtinModules->putDirectIndex( + globalObject, i, JSC::jsString(vm, String(builtinModuleNames[i]))); + } + + put(JSC::Identifier::fromString(vm, "builtinModules"_s), builtinModules); + + RETURN_NATIVE_MODULE(); +} -} // namespace Zig
\ No newline at end of file +} // namespace Zig diff --git a/src/bun.js/modules/ProcessModule.h b/src/bun.js/modules/NodeProcessModule.h index fab0298ae..6c3db0731 100644 --- a/src/bun.js/modules/ProcessModule.h +++ b/src/bun.js/modules/NodeProcessModule.h @@ -1,6 +1,7 @@ #include "../bindings/ZigGlobalObject.h" #include "JavaScriptCore/CustomGetterSetter.h" #include "JavaScriptCore/JSGlobalObject.h" +#include "_NativeModule.h" namespace Zig { @@ -35,10 +36,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsFunctionProcessModuleCommonJSSetter, ->putDirect(vm, propertyName, JSValue::decode(encodedValue), 0); } -inline void generateProcessSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues) { +DEFINE_NATIVE_MODULE(NodeProcess) { JSC::VM &vm = lexicalGlobalObject->vm(); GlobalObject *globalObject = reinterpret_cast<GlobalObject *>(lexicalGlobalObject); @@ -61,10 +59,6 @@ inline void generateProcessSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, exportNames.append(vm.propertyNames->defaultKeyword); exportValues.append(process); - exportNames.append( - Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s))); - exportValues.append(jsNumber(0)); - for (auto &entry : properties) { exportNames.append(entry); auto catchScope = DECLARE_CATCH_SCOPE(vm); diff --git a/src/bun.js/modules/NodeStringDecoderModule.h b/src/bun.js/modules/NodeStringDecoderModule.h new file mode 100644 index 000000000..3f5258cc1 --- /dev/null +++ b/src/bun.js/modules/NodeStringDecoderModule.h @@ -0,0 +1,16 @@ +#include "../bindings/JSStringDecoder.h" +#include "../bindings/ZigGlobalObject.h" +#include "JavaScriptCore/JSGlobalObject.h" + +namespace Zig { + +DEFINE_NATIVE_MODULE(NodeStringDecoder) { + INIT_NATIVE_MODULE(1); + + put(JSC::Identifier::fromString(vm, "StringDecoder"_s), + globalObject->JSStringDecoder()); + + RETURN_NATIVE_MODULE(); +} + +} // namespace Zig diff --git a/src/bun.js/modules/NodeTTYModule.h b/src/bun.js/modules/NodeTTYModule.h new file mode 100644 index 000000000..18a8f59a9 --- /dev/null +++ b/src/bun.js/modules/NodeTTYModule.h @@ -0,0 +1,50 @@ +#include "JSBuffer.h" +#include "_NativeModule.h" + +namespace Zig { +using namespace WebCore; + +JSC_DEFINE_HOST_FUNCTION(jsFunctionTty_isatty, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + if (callFrame->argumentCount() < 1) { + return JSValue::encode(jsBoolean(false)); + } + + auto scope = DECLARE_CATCH_SCOPE(vm); + int fd = callFrame->argument(0).toInt32(globalObject); + RETURN_IF_EXCEPTION(scope, encodedJSValue()); + + return JSValue::encode(jsBoolean(isatty(fd))); +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionNotImplementedYet, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + throwException(globalObject, throwScope, + createError(globalObject, "Not implemented yet"_s)); + return JSValue::encode(jsUndefined()); +} + +DEFINE_NATIVE_MODULE(NodeTTY) { + INIT_NATIVE_MODULE(3); + + auto *isattyFunction = + JSFunction::create(vm, globalObject, 1, "isatty"_s, jsFunctionTty_isatty, + ImplementationVisibility::Public); + + auto *notimpl = JSFunction::create(vm, globalObject, 0, "notimpl"_s, + jsFunctionNotImplementedYet, + ImplementationVisibility::Public, + NoIntrinsic, jsFunctionNotImplementedYet); + + putNativeFn(Identifier::fromString(vm, "isatty"_s), jsFunctionTty_isatty); + put(Identifier::fromString(vm, "ReadStream"_s), notimpl); + put(Identifier::fromString(vm, "WriteStream"_s), notimpl); + + RETURN_NATIVE_MODULE(); +} + +} // namespace Zig diff --git a/src/bun.js/bindings/node_util_types.cpp b/src/bun.js/modules/NodeUtilTypesModule.h index f7ae3949e..586743fea 100644 --- a/src/bun.js/bindings/node_util_types.cpp +++ b/src/bun.js/modules/NodeUtilTypesModule.h @@ -1,5 +1,4 @@ -#include "root.h" -#include "node_util_types.h" +#include "_NativeModule.h" #include "webcrypto/JSCryptoKey.h" #include "napi_external.h" @@ -312,72 +311,54 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionIsCryptoKey, (JSC::JSGlobalObject * globalObj return JSValue::encode(jsBoolean(cell->inherits<WebCore::JSCryptoKey>())); } -namespace Bun { -void generateNodeUtilTypesSourceCode(JSC::JSGlobalObject* lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4>& exportNames, - JSC::MarkedArgumentBuffer& exportValues) +namespace Zig { +DEFINE_NATIVE_MODULE(NodeUtilTypes) { - Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + INIT_NATIVE_MODULE(42); - JSC::VM& vm = globalObject->vm(); + putNativeFn(Identifier::fromString(vm, "isExternal"_s), jsFunctionIsExternal); + putNativeFn(Identifier::fromString(vm, "isDate"_s), jsFunctionIsDate); + putNativeFn(Identifier::fromString(vm, "isArgumentsObject"_s), jsFunctionIsArgumentsObject); + putNativeFn(Identifier::fromString(vm, "isBigIntObject"_s), jsFunctionIsBigIntObject); + putNativeFn(Identifier::fromString(vm, "isBooleanObject"_s), jsFunctionIsBooleanObject); + putNativeFn(Identifier::fromString(vm, "isNumberObject"_s), jsFunctionIsNumberObject); + putNativeFn(Identifier::fromString(vm, "isStringObject"_s), jsFunctionIsStringObject); + putNativeFn(Identifier::fromString(vm, "isSymbolObject"_s), jsFunctionIsSymbolObject); + putNativeFn(Identifier::fromString(vm, "isNativeError"_s), jsFunctionIsNativeError); + putNativeFn(Identifier::fromString(vm, "isRegExp"_s), jsFunctionIsRegExp); + putNativeFn(Identifier::fromString(vm, "isAsyncFunction"_s), jsFunctionIsAsyncFunction); + putNativeFn(Identifier::fromString(vm, "isGeneratorFunction"_s), jsFunctionIsGeneratorFunction); + putNativeFn(Identifier::fromString(vm, "isGeneratorObject"_s), jsFunctionIsGeneratorObject); + putNativeFn(Identifier::fromString(vm, "isPromise"_s), jsFunctionIsPromise); + putNativeFn(Identifier::fromString(vm, "isMap"_s), jsFunctionIsMap); + putNativeFn(Identifier::fromString(vm, "isSet"_s), jsFunctionIsSet); + putNativeFn(Identifier::fromString(vm, "isMapIterator"_s), jsFunctionIsMapIterator); + putNativeFn(Identifier::fromString(vm, "isSetIterator"_s), jsFunctionIsSetIterator); + putNativeFn(Identifier::fromString(vm, "isWeakMap"_s), jsFunctionIsWeakMap); + putNativeFn(Identifier::fromString(vm, "isWeakSet"_s), jsFunctionIsWeakSet); + putNativeFn(Identifier::fromString(vm, "isArrayBuffer"_s), jsFunctionIsArrayBuffer); + putNativeFn(Identifier::fromString(vm, "isDataView"_s), jsFunctionIsDataView); + putNativeFn(Identifier::fromString(vm, "isSharedArrayBuffer"_s), jsFunctionIsSharedArrayBuffer); + putNativeFn(Identifier::fromString(vm, "isProxy"_s), jsFunctionIsProxy); + putNativeFn(Identifier::fromString(vm, "isModuleNamespaceObject"_s), jsFunctionIsModuleNamespaceObject); + putNativeFn(Identifier::fromString(vm, "isAnyArrayBuffer"_s), jsFunctionIsAnyArrayBuffer); + putNativeFn(Identifier::fromString(vm, "isBoxedPrimitive"_s), jsFunctionIsBoxedPrimitive); + putNativeFn(Identifier::fromString(vm, "isArrayBufferView"_s), jsFunctionIsArrayBufferView); + putNativeFn(Identifier::fromString(vm, "isTypedArray"_s), jsFunctionIsTypedArray); + putNativeFn(Identifier::fromString(vm, "isUint8Array"_s), jsFunctionIsUint8Array); + putNativeFn(Identifier::fromString(vm, "isUint8ClampedArray"_s), jsFunctionIsUint8ClampedArray); + putNativeFn(Identifier::fromString(vm, "isUint16Array"_s), jsFunctionIsUint16Array); + putNativeFn(Identifier::fromString(vm, "isUint32Array"_s), jsFunctionIsUint32Array); + putNativeFn(Identifier::fromString(vm, "isInt8Array"_s), jsFunctionIsInt8Array); + putNativeFn(Identifier::fromString(vm, "isInt16Array"_s), jsFunctionIsInt16Array); + putNativeFn(Identifier::fromString(vm, "isInt32Array"_s), jsFunctionIsInt32Array); + putNativeFn(Identifier::fromString(vm, "isFloat32Array"_s), jsFunctionIsFloat32Array); + putNativeFn(Identifier::fromString(vm, "isFloat64Array"_s), jsFunctionIsFloat64Array); + putNativeFn(Identifier::fromString(vm, "isBigInt64Array"_s), jsFunctionIsBigInt64Array); + putNativeFn(Identifier::fromString(vm, "isBigUint64Array"_s), jsFunctionIsBigUint64Array); + putNativeFn(Identifier::fromString(vm, "isKeyObject"_s), jsFunctionIsKeyObject); + putNativeFn(Identifier::fromString(vm, "isCryptoKey"_s), jsFunctionIsCryptoKey); - JSC::JSObject* defaultObject = constructEmptyObject(globalObject, globalObject->objectPrototype(), 42); - exportNames.reserveCapacity(43); - exportValues.ensureCapacity(43); - - auto putBoth = [&](JSC::Identifier identifier, NativeFunction functionPtr) { - JSC::JSFunction* function = JSC::JSFunction::create(vm, globalObject, 1, identifier.string(), functionPtr, ImplementationVisibility::Public, NoIntrinsic, functionPtr); - defaultObject->putDirect(vm, identifier, function, 0); - exportNames.append(identifier); - exportValues.append(function); - }; - - putBoth(Identifier::fromString(vm, "isExternal"_s), jsFunctionIsExternal); - putBoth(Identifier::fromString(vm, "isDate"_s), jsFunctionIsDate); - putBoth(Identifier::fromString(vm, "isArgumentsObject"_s), jsFunctionIsArgumentsObject); - putBoth(Identifier::fromString(vm, "isBigIntObject"_s), jsFunctionIsBigIntObject); - putBoth(Identifier::fromString(vm, "isBooleanObject"_s), jsFunctionIsBooleanObject); - putBoth(Identifier::fromString(vm, "isNumberObject"_s), jsFunctionIsNumberObject); - putBoth(Identifier::fromString(vm, "isStringObject"_s), jsFunctionIsStringObject); - putBoth(Identifier::fromString(vm, "isSymbolObject"_s), jsFunctionIsSymbolObject); - putBoth(Identifier::fromString(vm, "isNativeError"_s), jsFunctionIsNativeError); - putBoth(Identifier::fromString(vm, "isRegExp"_s), jsFunctionIsRegExp); - putBoth(Identifier::fromString(vm, "isAsyncFunction"_s), jsFunctionIsAsyncFunction); - putBoth(Identifier::fromString(vm, "isGeneratorFunction"_s), jsFunctionIsGeneratorFunction); - putBoth(Identifier::fromString(vm, "isGeneratorObject"_s), jsFunctionIsGeneratorObject); - putBoth(Identifier::fromString(vm, "isPromise"_s), jsFunctionIsPromise); - putBoth(Identifier::fromString(vm, "isMap"_s), jsFunctionIsMap); - putBoth(Identifier::fromString(vm, "isSet"_s), jsFunctionIsSet); - putBoth(Identifier::fromString(vm, "isMapIterator"_s), jsFunctionIsMapIterator); - putBoth(Identifier::fromString(vm, "isSetIterator"_s), jsFunctionIsSetIterator); - putBoth(Identifier::fromString(vm, "isWeakMap"_s), jsFunctionIsWeakMap); - putBoth(Identifier::fromString(vm, "isWeakSet"_s), jsFunctionIsWeakSet); - putBoth(Identifier::fromString(vm, "isArrayBuffer"_s), jsFunctionIsArrayBuffer); - putBoth(Identifier::fromString(vm, "isDataView"_s), jsFunctionIsDataView); - putBoth(Identifier::fromString(vm, "isSharedArrayBuffer"_s), jsFunctionIsSharedArrayBuffer); - putBoth(Identifier::fromString(vm, "isProxy"_s), jsFunctionIsProxy); - putBoth(Identifier::fromString(vm, "isModuleNamespaceObject"_s), jsFunctionIsModuleNamespaceObject); - putBoth(Identifier::fromString(vm, "isAnyArrayBuffer"_s), jsFunctionIsAnyArrayBuffer); - putBoth(Identifier::fromString(vm, "isBoxedPrimitive"_s), jsFunctionIsBoxedPrimitive); - putBoth(Identifier::fromString(vm, "isArrayBufferView"_s), jsFunctionIsArrayBufferView); - putBoth(Identifier::fromString(vm, "isTypedArray"_s), jsFunctionIsTypedArray); - putBoth(Identifier::fromString(vm, "isUint8Array"_s), jsFunctionIsUint8Array); - putBoth(Identifier::fromString(vm, "isUint8ClampedArray"_s), jsFunctionIsUint8ClampedArray); - putBoth(Identifier::fromString(vm, "isUint16Array"_s), jsFunctionIsUint16Array); - putBoth(Identifier::fromString(vm, "isUint32Array"_s), jsFunctionIsUint32Array); - putBoth(Identifier::fromString(vm, "isInt8Array"_s), jsFunctionIsInt8Array); - putBoth(Identifier::fromString(vm, "isInt16Array"_s), jsFunctionIsInt16Array); - putBoth(Identifier::fromString(vm, "isInt32Array"_s), jsFunctionIsInt32Array); - putBoth(Identifier::fromString(vm, "isFloat32Array"_s), jsFunctionIsFloat32Array); - putBoth(Identifier::fromString(vm, "isFloat64Array"_s), jsFunctionIsFloat64Array); - putBoth(Identifier::fromString(vm, "isBigInt64Array"_s), jsFunctionIsBigInt64Array); - putBoth(Identifier::fromString(vm, "isBigUint64Array"_s), jsFunctionIsBigUint64Array); - putBoth(Identifier::fromString(vm, "isKeyObject"_s), jsFunctionIsKeyObject); - putBoth(Identifier::fromString(vm, "isCryptoKey"_s), jsFunctionIsCryptoKey); - defaultObject->putDirect(vm, JSC::PropertyName(Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s))), jsNumber(0), 0); - - exportNames.append(JSC::Identifier::fromString(vm, "default"_s)); - exportValues.append(defaultObject); -} + RETURN_NATIVE_MODULE(); } +} // namespace Zig diff --git a/src/bun.js/modules/StringDecoderModule.h b/src/bun.js/modules/StringDecoderModule.h deleted file mode 100644 index 1dbf5ef8e..000000000 --- a/src/bun.js/modules/StringDecoderModule.h +++ /dev/null @@ -1,36 +0,0 @@ -#include "../bindings/JSStringDecoder.h" -#include "../bindings/ZigGlobalObject.h" -#include "JavaScriptCore/JSGlobalObject.h" - -namespace Zig { - -inline void -generateStringDecoderSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues) { - JSC::VM &vm = lexicalGlobalObject->vm(); - GlobalObject *globalObject = - reinterpret_cast<GlobalObject *>(lexicalGlobalObject); - - exportNames.append(JSC::Identifier::fromString(vm, "StringDecoder"_s)); - exportValues.append(globalObject->JSStringDecoder()); - - auto CommonJS = - Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s)); - - JSC::JSObject *defaultObject = constructEmptyObject(globalObject); - defaultObject->putDirect(vm, PropertyName(CommonJS), jsNumber(0), 0); - - for (size_t i = 0; i < exportNames.size(); i++) { - defaultObject->putDirect(vm, exportNames[i], exportValues.at(i), 0); - } - - exportNames.append(vm.propertyNames->defaultKeyword); - exportValues.append(defaultObject); - - exportNames.append(CommonJS); - exportValues.append(jsNumber(0)); -} - -} // namespace Zig diff --git a/src/bun.js/modules/TTYModule.h b/src/bun.js/modules/TTYModule.h deleted file mode 100644 index 79bc8c871..000000000 --- a/src/bun.js/modules/TTYModule.h +++ /dev/null @@ -1,81 +0,0 @@ -#include "../bindings/JSBuffer.h" -#include "../bindings/ZigGlobalObject.h" -#include "JavaScriptCore/JSGlobalObject.h" - -#include "JavaScriptCore/ObjectConstructor.h" - -namespace Zig { -using namespace WebCore; - -JSC_DEFINE_HOST_FUNCTION(jsFunctionTty_isatty, (JSGlobalObject * globalObject, - CallFrame *callFrame)) { - VM &vm = globalObject->vm(); - if (callFrame->argumentCount() < 1) { - return JSValue::encode(jsBoolean(false)); - } - - auto scope = DECLARE_CATCH_SCOPE(vm); - int fd = callFrame->argument(0).toInt32(globalObject); - RETURN_IF_EXCEPTION(scope, encodedJSValue()); - - return JSValue::encode(jsBoolean(isatty(fd))); -} - -JSC_DEFINE_HOST_FUNCTION(jsFunctionNotImplementedYet, - (JSGlobalObject * globalObject, - CallFrame *callFrame)) { - VM &vm = globalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - throwException(globalObject, throwScope, - createError(globalObject, "Not implemented yet"_s)); - return JSValue::encode(jsUndefined()); -} - -inline void generateTTYSourceCode(JSC::JSGlobalObject *lexicalGlobalObject, - JSC::Identifier moduleKey, - Vector<JSC::Identifier, 4> &exportNames, - JSC::MarkedArgumentBuffer &exportValues) { - JSC::VM &vm = lexicalGlobalObject->vm(); - GlobalObject *globalObject = - reinterpret_cast<GlobalObject *>(lexicalGlobalObject); - - auto *tty = JSC::constructEmptyObject(globalObject, - globalObject->objectPrototype(), 3); - - auto *isattyFunction = - JSFunction::create(vm, globalObject, 1, "isatty"_s, jsFunctionTty_isatty, - ImplementationVisibility::Public); - - auto *notimpl = JSFunction::create(vm, globalObject, 0, "notimpl"_s, - jsFunctionNotImplementedYet, - ImplementationVisibility::Public, - NoIntrinsic, jsFunctionNotImplementedYet); - - exportNames.append(JSC::Identifier::fromString(vm, "isatty"_s)); - exportValues.append(isattyFunction); - - exportNames.append(JSC::Identifier::fromString(vm, "ReadStream"_s)); - tty->putDirect(vm, JSC::Identifier::fromString(vm, "ReadStream"_s), notimpl); - exportValues.append(notimpl); - - exportNames.append(JSC::Identifier::fromString(vm, "WriteStream"_s)); - tty->putDirect(vm, JSC::Identifier::fromString(vm, "WriteStream"_s), notimpl); - exportValues.append(notimpl); - - for (size_t i = 0; i < exportNames.size(); i++) { - tty->putDirect(vm, exportNames[i], exportValues.at(i), 0); - } - - exportNames.append(vm.propertyNames->defaultKeyword); - exportValues.append(tty); - - auto CommonJS = - Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s)); - - exportNames.append(CommonJS); - exportValues.append(jsNumber(0)); - - tty->putDirect(vm, PropertyName(CommonJS), jsNumber(0), 0); -} - -} // namespace Zig diff --git a/src/bun.js/modules/_NativeModule.h b/src/bun.js/modules/_NativeModule.h new file mode 100644 index 000000000..01a112d0b --- /dev/null +++ b/src/bun.js/modules/_NativeModule.h @@ -0,0 +1,90 @@ +// clang-format off +#pragma once +#include "JSBuffer.h" +#include "JavaScriptCore/JSGlobalObject.h" +#include "JavaScriptCore/ObjectConstructor.h" +#include "ZigGlobalObject.h" + +// These modules are implemented in native code as a function which writes ESM +// export key+value pairs. The following macros help simplify the implementation +// of these functions. + +// To add a new native module +// 1. Add a new line to `BUN_FOREACH_NATIVE_MODULE` +// 2. Add a case to `module_loader.zig` that resolves the import. +// 3. Add a new file in this folder named after the module, camelcase and suffixed with Module, +// like "NodeBufferModule.h" or "BunJSCModule.h". It should call DEFINE_NATIVE_MODULE(name). +// +// The native module function is called to create the module object: +// - INIT_NATIVE_MODULE(n) is called with the number of exports +// - put(id, jsvalue) adds an export +// - putNativeFn(id, nativefn) lets you quickly add from `JSC_DEFINE_HOST_FUNCTION` +// - NATIVE_MODULE_FINISH() do asserts and finalize everything. +// If you decide to not use INIT_NATIVE_MODULE. make sure the first property +// given is the default export + +#define BUN_FOREACH_NATIVE_MODULE(macro) \ + macro("bun:jsc"_s, BunJSC) \ + macro("node:buffer"_s, NodeBuffer) \ + macro("node:constants"_s, NodeConstants) \ + macro("node:module"_s, NodeModule) \ + macro("node:process"_s, NodeProcess) \ + macro("node:string_decoder"_s, NodeStringDecoder) \ + macro("node:tty"_s, NodeTTY) \ + macro("node:util/types"_s, NodeUtilTypes) \ + +#if ASSERT_ENABLED + +// This function is a lie. It doesnt return, but rather it performs an assertion +// that what you passed to INIT_NATIVE_MODULE is indeed correct. +#define RETURN_NATIVE_MODULE() \ + ASSERT_WITH_MESSAGE(numberOfActualExportNames == passedNumberOfExportNames, \ + "NATIVE_MODULE_START() was given the incorrect value."); + +#define __NATIVE_MODULE_ASSERT_DECL \ + int numberOfActualExportNames = 0; \ + int passedNumberOfExportNames = numberOfExportNames; \ +#define __NATIVE_MODULE_ASSERT_INCR numberOfActualExportNames++; + +#else + +#define RETURN_NATIVE_MODULE() ; +#define __NATIVE_MODULE_ASSERT_INCR ; +#define __NATIVE_MODULE_ASSERT_DECL ; + +#endif + +#define DEFINE_NATIVE_MODULE(name) \ + inline void generateNativeModule_##name( \ + JSC::JSGlobalObject *lexicalGlobalObject, JSC::Identifier moduleKey, \ + Vector<JSC::Identifier, 4> &exportNames, \ + JSC::MarkedArgumentBuffer &exportValues) + +#define INIT_NATIVE_MODULE(numberOfExportNames) \ + Zig::GlobalObject *globalObject = \ + reinterpret_cast<Zig::GlobalObject *>(lexicalGlobalObject); \ + JSC::VM &vm = globalObject->vm(); \ + JSC::JSObject *defaultObject = JSC::constructEmptyObject( \ + globalObject, globalObject->objectPrototype(), numberOfExportNames); \ + __NATIVE_MODULE_ASSERT_DECL \ + auto put = [&](JSC::Identifier name, JSC::JSValue value) { \ + defaultObject->putDirect(vm, name, value); \ + exportNames.append(name); \ + exportValues.append(value); \ + __NATIVE_MODULE_ASSERT_INCR \ + }; \ + auto putNativeFn = [&](JSC::Identifier name, JSC::NativeFunction ptr) { \ + JSC::JSFunction *value = JSC::JSFunction::create( \ + vm, globalObject, 1, name.string(), ptr, \ + JSC::ImplementationVisibility::Public, JSC::NoIntrinsic, ptr); \ + defaultObject->putDirect(vm, name, value); \ + exportNames.append(name); \ + exportValues.append(value); \ + __NATIVE_MODULE_ASSERT_INCR \ + }; \ + exportNames.reserveCapacity(numberOfExportNames + 1); \ + exportValues.ensureCapacity(numberOfExportNames + 1); \ + exportNames.append(vm.propertyNames->defaultKeyword); \ + exportValues.append(defaultObject); \ + while (0) { \ + } diff --git a/src/bun.js/node/node_fs_constant.zig b/src/bun.js/node/node_fs_constant.zig index 8e642ebad..0d8ec66c5 100644 --- a/src/bun.js/node/node_fs_constant.zig +++ b/src/bun.js/node/node_fs_constant.zig @@ -146,8 +146,7 @@ pub const Constants = struct { // Due to zig's format support max 32 arguments, we need to split // here. const constants_string_format1 = - \\ - \\export var constants = {{ + \\var constants = {{ \\ F_OK: {d}, \\ R_OK: {d}, \\ W_OK: {d}, diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig index bd9844db0..a4efe4454 100644 --- a/src/bun.js/node/node_os.zig +++ b/src/bun.js/node/node_os.zig @@ -9,7 +9,6 @@ const Environment = bun.Environment; const Global = bun.Global; const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false; const heap_allocator = bun.default_allocator; -const constants = @import("./os/constants.zig"); pub const Os = struct { pub const name = "Bun__Os"; @@ -41,7 +40,7 @@ pub const Os = struct { module.put(globalObject, JSC.ZigString.static("devNull"), JSC.ZigString.init(devNull).withEncoding().toValue(globalObject)); module.put(globalObject, JSC.ZigString.static("EOL"), JSC.ZigString.init(EOL).withEncoding().toValue(globalObject)); - module.put(globalObject, JSC.ZigString.static("constants"), constants.create(globalObject)); + // module.put(globalObject, JSC.ZigString.static("constants"), constants.create(globalObject)); return module; } |