]> git.saurik.com Git - cycript.git/blobdiff - libcycript.cy
Link readline to provide Kevin his 64-bit console.
[cycript.git] / libcycript.cy
index da34baa127d021427b01cf1676c8d5e1f1665d28..7690a299f7eadf6aa43074ecf5433c17c1dbf797 100644 (file)
 **/
 /* }}} */
 
-var process = {
-    env: {},
-};
-
 (function() {
 
+Number.prototype.__defineGetter__('$cyt', function() {
+    if (this.$cyt_)
+        return this.$cyt_;
+    if ((this|0) == this)
+        return int;
+});
+
 this.typeid = function(object) {
     return object.$cyt;
 };
 
 let $cy_set = function(object, properties) {
     for (const name in properties)
+        if ("defineProperty" in Object)
         Object.defineProperty(object, name, {
             configurable: true,
             enumerable: false,
             writable: true,
             value: properties[name],
-        });
+        }); else object[name] = properties[name];
 };
 
 $cy_set(Boolean.prototype, {
@@ -62,8 +66,12 @@ $cy_set(Error.prototype, {
                 stack = stack.slice(0, -1);
             for (let i = 0; i != stack.length; ++i)
                 stack[i] = '\n    ' + stack[i];
-            stack = stack.join('');
-            stack = ` /*${stack} */`;
+            if (stack.length == 0)
+                stack = '';
+            else {
+                stack = stack.join('');
+                stack = ` /*${stack} */`;
+            }
         }
         return `new ${this.constructor.name}(${this.message.toCYON()})${stack}`;
     },
@@ -72,7 +80,8 @@ $cy_set(Error.prototype, {
 $cy_set(Number.prototype, {
     toCYON: function() {
         if ("$cyt" in this)
-            return `${this.$cyt.toCYON()}(${this.toString()})`;
+            //return `${this.$cyt.toCYON()}(${this.toString()})`;
+            return this.toString();
         return `new Number(${this.toString()})`;
     },
 });
@@ -118,7 +127,6 @@ Java.emit = function(event) {
 };
 
 Java.on('setup', function() {
-    system.print("JVM\n");
     $cy_set(java.lang.Boolean.prototype, {
         toCYON: function() {
             return `new java.lang.Boolean(${this->value})`;
@@ -185,6 +193,26 @@ Java.on('setup', function() {
                 this.put(key, value);
         },
     });
+
+    $cy_set(java.lang.Throwable.prototype, {
+        toCYON: function() {
+            var message = this.getMessage();
+            if (message == null)
+                message = '';
+            else
+                message = message.toCYON();
+
+            let stack = this.getStackTrace();
+            if (stack.length == 0)
+                stack = '';
+            else {
+                stack = stack.join('\n    ');
+                stack = ` /*\n    ${stack} */`;
+            }
+
+            return `new ${this.constructor.class.getName()}(${message})${stack}`;
+        },
+    });
 });
 
 }
@@ -290,7 +318,7 @@ require.resolve = function(name) {
         if (path != null)
             return path;
     } else {
-        let cwd = new (typedef char[1024]);
+        let cwd = *new (typedef char[1024]);
         cwd = getcwd(cwd, cwd.length).toString();
         cwd = cwd.split('/');
 
@@ -425,6 +453,8 @@ process.binding = function(name) {
     return binding;
 };
 
+process.env = {};
+
 let environ = *(typedef char ***)(dlsym(RTLD_DEFAULT, "environ"));
 for (let i = 0; environ[i] != null; ++i) {
     let assign = environ[i];