X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/19e13c2de7065201c9a5a54e9a1a5409ed4a4cdc..2fad14e52c8cde8c45003a2ebb6907a57ca380e4:/libcycript.cy diff --git a/libcycript.cy b/libcycript.cy index 79a1735..4014fd6 100644 --- a/libcycript.cy +++ b/libcycript.cy @@ -25,6 +25,10 @@ var process = { (function() { +this.typeid = function(object) { + return object.$cyt; +}; + let $cy_set = function(object, properties) { for (const name in properties) Object.defineProperty(object, name, { @@ -35,6 +39,12 @@ let $cy_set = function(object, properties) { }); }; +$cy_set(Boolean.prototype, { + toCYON: function() { + return `new Boolean(${this.toString()})`; + }, +}); + $cy_set(Date.prototype, { toCYON: function() { return `new ${this.constructor.name}(${this.toUTCString().toCYON()})`; @@ -43,12 +53,33 @@ $cy_set(Date.prototype, { $cy_set(Error.prototype, { toCYON: function() { - let stack = this.stack.split('\n'); - if (stack.slice(-1)[0] == "global code") - stack = stack.slice(0, -1); - for (let i = 0; i != stack.length; ++i) - stack[i] = '\n ' + stack[i]; - return `new ${this.constructor.name}(${this.message.toCYON()}) /*${stack.join('')} */`; + let stack = this.stack; + if (typeof stack == 'undefined') + stack = ''; + else { + stack = stack.split('\n'); + if (stack.slice(-1)[0] == "global code") + stack = stack.slice(0, -1); + for (let i = 0; i != stack.length; ++i) + stack[i] = '\n ' + stack[i]; + stack = stack.join(''); + stack = ` /*${stack} */`; + } + return `new ${this.constructor.name}(${this.message.toCYON()})${stack}`; + }, +}); + +$cy_set(Number.prototype, { + toCYON: function() { + if ("$cyt" in this) + return `${this.$cyt.toCYON()}(${this.toString()})`; + return `new Number(${this.toString()})`; + }, +}); + +$cy_set(RegExp.prototype, { + toCYON: function() { + return this.toString(); }, });