X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/8b898c07529e9b3338430715caf64c915a03a550..925360811f44b121001797130ca89fc777072ae7:/libcycript.cy diff --git a/libcycript.cy b/libcycript.cy index 510bbc2..8240a44 100644 --- a/libcycript.cy +++ b/libcycript.cy @@ -19,10 +19,6 @@ **/ /* }}} */ -var process = { - env: {}, -}; - (function() { this.typeid = function(object) { @@ -62,8 +58,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}`; }, @@ -184,6 +184,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}`; + }, + }); }); } @@ -424,6 +444,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];