-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015 Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016 Jay Freeman (saurik)
*/
/* GNU Affero General Public License, Version 3 {{{ */
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}`;
},
},
});
+// XXX: Java should just always be available
if ("Java" in Cycript) {
+
+// XXX: this is a half-assed EventEmitter
+// XXX: this doesn't even have the same semantics
+
+Java.handlers_ = {};
+
+Java.on = function(event, handler) {
+ var handlers;
+ if (event in this.handlers_)
+ handlers = this.handlers_[event];
+ else {
+ handlers = [];
+ this.handlers_[event] = handlers;
+ }
+
+ if (this.handlers_ == null)
+ handler();
+ else
+ handlers.push(handler);
+};
+
+Java.emit = function(event) {
+ if (event in this.handlers_) {
+ var handlers = this.handlers_[event];
+ if (handlers != null)
+ for (var handler of handlers)
+ handler();
+ }
+
+ this.handlers_[event] = null;
+};
+
+Java.on('setup', function() {
$cy_set(java.lang.Boolean.prototype, {
toCYON: function() {
- return `new java.lang.Boolean(${this.value})`;
+ return `new java.lang.Boolean(${this->value})`;
},
});
$cy_set(java.lang.Byte.prototype, {
toCYON: function() {
- return `new java.lang.Byte(${this.value})`;
+ return `new java.lang.Byte(${this->value})`;
},
});
$cy_set(java.lang.Character.prototype, {
toCYON: function() {
- return `new java.lang.Character(${this.value})`;
+ return `new java.lang.Character(${this->value})`;
},
});
$cy_set(java.lang.Short.prototype, {
toCYON: function() {
- return `new java.lang.Short(${this.value})`;
+ return `new java.lang.Short(${this->value})`;
},
});
$cy_set(java.lang.Integer.prototype, {
toCYON: function() {
- return `new java.lang.Integer(${this.value})`;
+ return `new java.lang.Integer(${this->value})`;
},
});
$cy_set(java.lang.Long.prototype, {
toCYON: function() {
- return `new java.lang.Long(${this.value})`;
+ return `new java.lang.Long(${this->value})`;
},
});
$cy_set(java.lang.Float.prototype, {
toCYON: function() {
- return `new java.lang.Float(${this.value})`;
+ return `new java.lang.Float(${this->value})`;
},
});
$cy_set(java.lang.Double.prototype, {
toCYON: function() {
- return `new java.lang.Double(${this.value})`;
+ return `new java.lang.Double(${this->value})`;
+ },
+ });
+
+ $cy_set(java.lang.Object.prototype, {
+ toCYON: function(key) {
+ return "#" + this.toString().toCYON();
+ },
+
+ // XXX: due to lack of interface prototypes :(
+ $cyg: function(key) {
+ return this.get(key);
+ },
+
+ // XXX: due to lack of interface prototypes :(
+ $cys: function(key, value) {
+ if ("set" in this)
+ this.set(key, value);
+ else
+ this.put(key, value);
+ },
+ });
+});
+
+}
+
+if ("ObjectiveC" in Cycript) {
+ $cy_set(NSArray.prototype, {
+ $cyg: function(key) {
+ return objc_msgSend(this, "objectAtIndex:", key);
+ },
+
+ $cys: function(key, value) {
+ return objc_msgSend(this, "setObject:atIndex:", value, key);
+ },
+ });
+
+ $cy_set(NSDictionary.prototype, {
+ $cyg: function(key) {
+ return objc_msgSend(this, "objectForKey:", key);
+ },
+
+ $cys: function(key, value) {
+ return objc_msgSend(this, "setObject:forKey:", value, key);
},
});
}
process.env[name.toString()] = value;
}
+process.cwd = function() {
+ let cwd = new (typedef char[1024]);
+ return getcwd(cwd, cwd.length).toString();
+};
+
process.pid = getpid();
})();