aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/BunDetectLibcModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/bindings/BunDetectLibcModule.cpp')
-rw-r--r--src/bun.js/bindings/BunDetectLibcModule.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/bun.js/bindings/BunDetectLibcModule.cpp b/src/bun.js/bindings/BunDetectLibcModule.cpp
new file mode 100644
index 000000000..f7e2c1945
--- /dev/null
+++ b/src/bun.js/bindings/BunDetectLibcModule.cpp
@@ -0,0 +1,34 @@
+#include "root.h"
+
+#include "JavaScriptCore/JavaScript.h"
+#include "wtf/text/WTFString.h"
+#include "JavaScriptCore/ObjectConstructor.h"
+
+#if defined(__LINUX__)
+#include <gnu/libc-version.h>
+#endif
+
+using namespace JSC;
+using namespace WTF;
+
+JSC::JSObject* createDetectLibcModule(JSC::JSGlobalObject* globalObject)
+{
+ VM& vm = globalObject->vm();
+ JSC::JSObject* object = nullptr;
+
+ {
+ JSC::ObjectInitializationScope initializationScope(vm);
+ object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 2);
+ #if defined(__LINUX__)
+ auto version = JSC::jsString(vm, makeAtomString(gnu_get_libc_version()));
+ auto family = JSC::jsString(vm, makeAtomString("glibc"));
+ #else
+ auto version = JSC::jsNull();
+ auto family = JSC::jsNull();
+ #endif
+ object->putDirect(vm, JSC::Identifier::fromString(vm, "version"_s), version, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0);
+ object->putDirect(vm, JSC::Identifier::fromString(vm, "family"_s), family, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0);
+ }
+
+ return object;
+}