#include "BunClientData.h" #include "root.h" #include #include #include #pragma mark - Node.js Path namespace Zig { static JSC::JSObject* createPath(JSC::JSGlobalObject* globalThis, bool isWindows); using JSGlobalObject = JSC::JSGlobalObject; using Exception = JSC::Exception; using JSValue = JSC::JSValue; using JSString = JSC::JSString; using JSModuleLoader = JSC::JSModuleLoader; using JSModuleRecord = JSC::JSModuleRecord; using Identifier = JSC::Identifier; using SourceOrigin = JSC::SourceOrigin; using JSObject = JSC::JSObject; using JSNonFinalObject = JSC::JSNonFinalObject; namespace JSCastingHelpers = JSC::JSCastingHelpers; // clang-format off #define DEFINE_CALLBACK_FUNCTION_BODY(ZigFunction) JSC::VM& vm = globalObject->vm(); \ auto* thisObject = JSC::jsDynamicCast(vm, callFrame->thisValue()); \ auto scope = DECLARE_THROW_SCOPE(vm); \ if (!thisObject) \ return throwVMTypeError(globalObject, scope); \ auto argCount = static_cast(callFrame->argumentCount()); \ WTF::Vector arguments; \ arguments.reserveInitialCapacity(argCount); \ if (argCount) { \ for (uint16_t i = 0; i < argCount; ++i) { \ arguments.uncheckedAppend(JSC::JSValue::encode(callFrame->uncheckedArgument(i))); \ } \ } \ auto clientData = Bun::clientData(vm); \ auto isWindows = thisObject->get(globalObject, clientData->builtinNames().isWindowsPrivateName()); \ JSC::JSValue result = JSC::JSValue::decode( \ ZigFunction(globalObject, isWindows.asBoolean(), reinterpret_cast(arguments.data()), argCount) \ ); \ JSC::JSObject *obj = result.getObject(); \ if (UNLIKELY(obj != nullptr && obj->isErrorInstance())) { \ scope.throwException(globalObject, obj); \ return JSC::JSValue::encode(JSC::jsUndefined()); \ } \ if (UNLIKELY(scope.exception())) \ return JSC::JSValue::encode(JSC::jsUndefined()); \ return JSC::JSValue::encode(result); // clang-format on static JSC_DECLARE_HOST_FUNCTION(Path_functionBasename); static JSC_DEFINE_HOST_FUNCTION(Path_functionBasename, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__basename); } static JSC_DECLARE_HOST_FUNCTION(Path_functionDirname); static JSC_DEFINE_HOST_FUNCTION(Path_functionDirname, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__dirname); } static JSC_DECLARE_HOST_FUNCTION(Path_functionExtname); static JSC_DEFINE_HOST_FUNCTION(Path_functionExtname, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__extname); } static JSC_DECLARE_HOST_FUNCTION(Path_functionFormat); static JSC_DEFINE_HOST_FUNCTION(Path_functionFormat, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__format); } static JSC_DECLARE_HOST_FUNCTION(Path_functionIsAbsolute); static JSC_DEFINE_HOST_FUNCTION(Path_functionIsAbsolute, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__isAbsolute); } static JSC_DECLARE_HOST_FUNCTION(Path_functionJoin); static JSC_DEFINE_HOST_FUNCTION(Path_functionJoin, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__join); } static JSC_DECLARE_HOST_FUNCTION(Path_functionNormalize); static JSC_DEFINE_HOST_FUNCTION(Path_functionNormalize, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__normalize); } static JSC_DECLARE_HOST_FUNCTION(Path_functionParse); static JSC_DEFINE_HOST_FUNCTION(Path_functionParse, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__parse); } static JSC_DECLARE_HOST_FUNCTION(Path_functionRelative); static JSC_DEFINE_HOST_FUNCTION(Path_functionRelative, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__relative); } static JSC_DECLARE_HOST_FUNCTION(Path_functionResolve); static JSC_DEFINE_HOST_FUNCTION(Path_functionResolve, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__resolve); } static JSC_DECLARE_HOST_FUNCTION(Path_functionToNamespacedPath); static JSC_DEFINE_HOST_FUNCTION(Path_functionToNamespacedPath, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { auto argCount = static_cast(callFrame->argumentCount()); // TODO: return JSC::JSValue::encode(callFrame->argument(0)); } static JSC::JSObject* createPath(JSGlobalObject* globalThis, bool isWindows) { JSC::VM& vm = globalThis->vm(); JSC::Structure* plainObjectStructure = JSC::JSFinalObject::createStructure(vm, globalThis, globalThis->objectPrototype(), 0); JSC::JSObject* path = JSC::JSFinalObject::create(vm, plainObjectStructure); auto clientData = Bun::clientData(vm); path->putDirect(vm, clientData->builtinNames().isWindowsPrivateName(), JSC::jsBoolean(isWindows), 0); path->putDirect(vm, clientData->builtinNames().basenamePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("basename"), Path_functionBasename), 0); path->putDirect(vm, clientData->builtinNames().dirnamePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("dirname"), Path_functionDirname), 0); path->putDirect(vm, clientData->builtinNames().extnamePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("extname"), Path_functionExtname), 0); path->putDirect(vm, clientData->builtinNames().formatPublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("format"), Path_functionFormat), 0); path->putDirect(vm, clientData->builtinNames().isAbsolutePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("isAbsolute"), Path_functionIsAbsolute), 0); path->putDirect(vm, clientData->builtinNames().joinPublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("join"), Path_functionJoin), 0); path->putDirect(vm, clientData->builtinNames().normalizePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("normalize"), Path_functionNormalize), 0); path->putDirect(vm, clientData->builtinNames().parsePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("parse"), Path_functionParse), 0); path->putDirect(vm, clientData->builtinNames().relativePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("relative"), Path_functionRelative), 0); path->putDirect(vm, clientData->builtinNames().resolvePublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("resolve"), Path_functionResolve), 0); path->putDirect(vm, clientData->builtinNames().toNamespacedPathPublicName(), JSC::JSFunction::create(vm, JSC::jsCast(globalThis), 0, WTF::String("toNamespacedPath"), Path_functionToNamespacedPath), 0); if (isWindows) { path->putDirect(vm, clientData->builtinNames().sepPublicName(), JSC::jsString(vm, WTF::String("\\"_s)), 0); path->putDirect(vm, clientData->builtinNames().delimiterPublicName(), JSC::jsString(vm, WTF::String(";"_s)), 0); } else { path->putDirect(vm, clientData->builtinNames().sepPublicName(), JSC::jsString(vm, WTF::String("/"_s)), 0); path->putDirect(vm, clientData->builtinNames().delimiterPublicName(), JSC::jsString(vm, WTF::String(":"_s)), 0); } return path; } } // namespace Zig extern JSC__JSValue Bun__Path__create(JSC::JSGlobalObject* globalObject, bool isWindows) { JSC::VM& vm = globalObject->vm(); return JSC::JSValue::encode(JSC::JSValue(Zig::createPath( globalObject, isWindows))); }>jarred/mdx-thrwawy Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-07-05Fix incorrect signaturesGravatar Ashcon Partovi 3-21/+21
2023-07-05Fix detect-libcGravatar Ashcon Partovi 16-98/+116
2023-07-05Update websocket_http_client.zigGravatar Dylan Conway 1-0/+2
2023-07-05Fixes #3512 (#3526)Gravatar Jarred Sumner 9-38/+168
* Fixes #3512 * Fix `clearTimeout` and `clearInterval` not cancelling jobs same-tick --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-07-05Fixes #3515 (#3523)Gravatar Jarred Sumner 4-190/+182
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-07-05Fixes #3520 (#3522)Gravatar Jarred Sumner 3-23/+37
* Fixes #3520 * Update html_rewriter.zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-07-05add envs on tests (#3518)Gravatar Ciro Spaciari 4-0/+20
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2023-07-04Update build-idGravatar Jarred Sumner 1-1/+1
2023-07-04Fix build determinism issue (thanks to @alexlamsl)Gravatar Jarred Sumner 1-2/+2
cc @dylan-conway this was the cause
2023-07-04boopGravatar Jarred Sumner 10-55/+55
2023-07-04use sengrid account on nodemailer test (#3517)bun-v0.6.13Gravatar Ciro Spaciari 2-14/+15
2023-07-04[tls] fix servername (#3513)Gravatar Ciro Spaciari 4-8/+109
* fix servername * add postgres tls tests * update test packages * add basic CRUD test
2023-07-04Add alias for readBigUInt64BE ... (#3514)Gravatar Ai Hoshino 2-4/+58
* Add alias for `readBigUInt64BE` ... Close: https://github.com/oven-sh/bun/issues/3338 * add some tests for `readBigUint64BE` alias * format code
2023-07-04reduce countGravatar Jarred Sumner 1-2/+2
2023-07-04bumpGravatar Jarred Sumner 3-2/+2
2023-07-04Fix crashGravatar Jarred Sumner 1-5/+8