From f348c89090d46cd58f44ca15623dcc044454f874 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 23 Dec 2015 11:39:06 -0800 Subject: [PATCH] Error instances that weren't thrown have no stack. --- libcycript.cy | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libcycript.cy b/libcycript.cy index dd7e2ac..8640a74 100644 --- a/libcycript.cy +++ b/libcycript.cy @@ -49,12 +49,19 @@ $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}`; }, }); -- 2.47.2