]> git.saurik.com Git - cycript.git/commitdiff
Implement synchronous lstat: node.js binding demo.
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 23 Dec 2015 16:23:12 +0000 (08:23 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 23 Dec 2015 16:23:12 +0000 (08:23 -0800)
Execute.cpp
libcycript.cy

index 523dccae98732e6a9c6562435e460c9e7ac69e38..7b3f2f2b84d6adcdc74dbfb726686f68bcd7d931 100644 (file)
@@ -2198,13 +2198,13 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) {
     CYSetProperty(context, cache, CYJSString("float"), CYMakeType(context, "f"), kJSPropertyAttributeDontEnum);
     CYSetProperty(context, cache, CYJSString("double"), CYMakeType(context, "d"), kJSPropertyAttributeDontEnum);
 
     CYSetProperty(context, cache, CYJSString("float"), CYMakeType(context, "f"), kJSPropertyAttributeDontEnum);
     CYSetProperty(context, cache, CYJSString("double"), CYMakeType(context, "d"), kJSPropertyAttributeDontEnum);
 
-    CYRunScript(context, "libcycript.cy");
-
     for (CYHook *hook : GetHooks())
         if (hook->SetupContext != NULL)
             (*hook->SetupContext)(context);
 
     CYArrayPush(context, alls, cycript);
     for (CYHook *hook : GetHooks())
         if (hook->SetupContext != NULL)
             (*hook->SetupContext)(context);
 
     CYArrayPush(context, alls, cycript);
+
+    CYRunScript(context, "libcycript.cy");
 }
 
 static JSGlobalContextRef context_;
 }
 
 static JSGlobalContextRef context_;
index 20a101710b7cfff1b12eb1a4a66085396f386205..a0793833f50fc70adec725c545ca802a149c3056 100644 (file)
@@ -157,6 +157,31 @@ require.resolve = function(name) {
     throw new Error("Cannot find module '" + name + "'");
 };
 
     throw new Error("Cannot find module '" + name + "'");
 };
 
+var _syscall = function(value) {
+    if (value == -1)
+        throw new Error("system call failed");
+};
+
+var info = *new (struct stat);
+if (false) {
+} else if ("st_atim" in info) {
+    var st_atime = "st_atim";
+    var st_mtime = "st_mtim";
+    var st_ctime = "st_ctim";
+} else if ("st_atimespec" in info) {
+    var st_atime = "st_atimespec";
+    var st_mtime = "st_mtimespec";
+    var st_ctime = "st_ctimespec";
+} else {
+    var st_atime = "st_atime";
+    var st_mtime = "st_mtime";
+    var st_ctime = "st_ctime";
+}
+
+var toDate = function(timespec) {
+    return new Date(timespec.tv_sec * 1000 + timespec.tv_nsec / 1000);
+};
+
 var bindings = {};
 
 process.binding = function(name) {
 var bindings = {};
 
 process.binding = function(name) {
@@ -180,8 +205,30 @@ process.binding = function(name) {
             FSInitialize() {
             },
 
             FSInitialize() {
             },
 
-            lstat() {
-                throw new Error("stat(" + arguments[0] + ")");
+            lstat(path) {
+                var info = new (struct stat);
+                _syscall(lstat(path, info));
+
+                return {
+                    dev: info->st_dev,
+                    mode: info->st_mode,
+                    nlink: info->st_nlink,
+                    uid: info->st_uid,
+                    gid: info->st_gid,
+                    rdev: info->st_rdev,
+                    blksize: info->st_blksize,
+                    ino: info->st_ino,
+                    size: info->st_size,
+                    blocks: info->st_blocks,
+
+                    atime: toDate(info->[st_atime]),
+                    mtime: toDate(info->[st_mtime]),
+                    ctime: toDate(info->[st_ctime]),
+
+                    isSymbolicLink() {
+                        return S_ISLNK(this.mode);
+                    },
+                };
             },
         }; break;
 
             },
         }; break;