@@ -2480,7 +2480,47 @@ void FileSystemLoadFrom(const FunctionCallbackInfo<Value>& args) {
24802480 args.GetReturnValue ().Set (fsObj);
24812481}
24822482
2483- void DefineConstants (Isolate* isolate, Local<FunctionTemplate> func) {
2483+ void MacroISDIR (const FunctionCallbackInfo<Value>& args) {
2484+ args.GetReturnValue ().Set (FS_S_ISDIR (Val<uint64_t >(args[0 ])));
2485+ }
2486+
2487+ void MacroISREG (const FunctionCallbackInfo<Value>& args) {
2488+ args.GetReturnValue ().Set (FS_S_ISREG (Val<uint64_t >(args[0 ])));
2489+ }
2490+
2491+ void MacroISLNK (const FunctionCallbackInfo<Value>& args) {
2492+ args.GetReturnValue ().Set (FS_S_ISLNK (Val<uint64_t >(args[0 ])));
2493+ }
2494+
2495+ void MacroIFTODT (const FunctionCallbackInfo<Value>& args) {
2496+ args.GetReturnValue ().Set (BigInt::NewFromUnsigned (args.GetIsolate (), Val<uint64_t >(args[0 ])));
2497+ }
2498+
2499+ template <typename T, size_t N>
2500+ void DefineFunction (
2501+ Isolate* isolate,
2502+ Local<T> obj,
2503+ const char (&prop)[N],
2504+ FunctionCallback fn,
2505+ int argc,
2506+ PropertyAttribute attr = PropertyAttribute::DontEnum
2507+ ) {
2508+ obj->Set (
2509+ String::NewFromUtf8Literal (isolate, prop, NewStringType::kInternalized ),
2510+ FunctionTemplate::New (
2511+ isolate,
2512+ fn,
2513+ Local<Value>(),
2514+ Local<Signature>(),
2515+ argc,
2516+ ConstructorBehavior::kThrow ,
2517+ SideEffectType::kHasSideEffect
2518+ ),
2519+ attr
2520+ );
2521+ }
2522+
2523+ void DefineMacros (Isolate* isolate, Local<FunctionTemplate> func) {
24842524#define DefineFlag (v ) \
24852525 do { \
24862526 func->Set ( \
@@ -2541,18 +2581,10 @@ void DefineConstants(Isolate* isolate, Local<FunctionTemplate> func) {
25412581 DefineFlag (S_IFLNK);
25422582 DefineFlag (S_IFMT);
25432583 DefineFlag (S_IFREG);
2544- DefineFlag (S_IRUSR);
2545- DefineFlag (S_IRGRP);
2546- DefineFlag (S_IROTH);
2547- DefineFlag (S_IWUSR);
2548- DefineFlag (S_IWGRP);
2549- DefineFlag (S_IWOTH);
2550- DefineFlag (S_IXUSR);
2551- DefineFlag (S_IXGRP);
2552- DefineFlag (S_IXOTH);
2553- DefineFlag (S_IRWXU);
2554- DefineFlag (S_IRWXG);
2555- DefineFlag (S_IRWXO);
2584+ DefineFunction (isolate, func, " S_IFTODT" , MacroIFTODT, 1 , PropertyAttribute::None);
2585+ DefineFunction (isolate, func, " S_ISDIR" , MacroISDIR, 1 , PropertyAttribute::None);
2586+ DefineFunction (isolate, func, " S_ISLNK" , MacroISLNK, 1 , PropertyAttribute::None);
2587+ DefineFunction (isolate, func, " S_ISREG" , MacroISREG, 1 , PropertyAttribute::None);
25562588 DefineFlag (UTIME_NOW);
25572589 DefineFlag (UTIME_OMIT);
25582590 DefineFlag (XATTR_CREATE);
@@ -2583,29 +2615,6 @@ void DefineConstants(Isolate* isolate, Local<FunctionTemplate> func) {
25832615#undef DefineFlag
25842616}
25852617
2586- template <typename T, size_t N>
2587- void DefineFunction (
2588- Isolate* isolate,
2589- Local<T> obj,
2590- const char (&prop)[N],
2591- FunctionCallback fn,
2592- int argc,
2593- PropertyAttribute attr = PropertyAttribute::DontEnum
2594- ) {
2595- obj->Set (
2596- String::NewFromUtf8Literal (isolate, prop, NewStringType::kInternalized ),
2597- FunctionTemplate::New (
2598- isolate,
2599- fn,
2600- Local<Value>(),
2601- Local<Signature>(),
2602- argc,
2603- ConstructorBehavior::kThrow ,
2604- SideEffectType::kHasSideEffect
2605- ),
2606- attr
2607- );
2608- }
26092618void DefineTemplateFunctions (Isolate* isolate, Local<ObjectTemplate> tmpl) {
26102619 DefineFunction (isolate, tmpl, " faccessat2" , FileSystemFAccessAt2, 4 );
26112620 DefineFunction (isolate, tmpl, " faccessat" , FileSystemFAccessAt, 3 );
@@ -2680,7 +2689,7 @@ NODE_MODULE_INIT() {
26802689 isolate,
26812690 FileSystemConstructor
26822691 );
2683- DefineConstants (isolate, FSTmpl);
2692+ DefineMacros (isolate, FSTmpl);
26842693 DefineFunction (isolate, FSTmpl, " loadFrom" , FileSystemLoadFrom, 1 , PropertyAttribute::None);
26852694 FSConstructorTmpl.Reset (isolate, FSTmpl);
26862695 Local<ObjectTemplate> instTmpl = FSTmpl->InstanceTemplate ();
0 commit comments