From 802803686574eb6fc9846650c301b583e8e4f74d Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 23 Dec 2015 10:41:40 -0800 Subject: [PATCH] Provide useful-ish error messages from eval calls. --- Error.cpp | 4 ++++ Error.hpp | 1 + Execute.cpp | 10 +++++++++- Library.cpp | 8 ++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Error.cpp b/Error.cpp index 38d49fc..be2b4a0 100644 --- a/Error.cpp +++ b/Error.cpp @@ -30,6 +30,10 @@ CYPoolError::CYPoolError(const CYPoolError &rhs) : { } +CYPoolError::CYPoolError(const char *message) { + message_ = pool_.strdup(message); +} + CYPoolError::CYPoolError(const char *format, ...) { va_list args; va_start(args, format); diff --git a/Error.hpp b/Error.hpp index 9fc6e85..5b948eb 100644 --- a/Error.hpp +++ b/Error.hpp @@ -53,6 +53,7 @@ struct _visible CYPoolError : CYPoolError(const CYPoolError &rhs); + CYPoolError(const char *message); CYPoolError(const char *format, ...); CYPoolError(const char *format, va_list args); diff --git a/Execute.cpp b/Execute.cpp index d09c31a..1c83e26 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1206,7 +1206,15 @@ static JSValueRef All_getProperty(JSContextRef context, JSObjectRef object, JSSt const char *code; unsigned flags; if (CYBridgeHash(pool, CYPoolUTF8String(pool, context, property), code, flags)) { - JSValueRef result(_jsccall(JSEvaluateScript, context, CYJSString(CYPoolCode(pool, code)), NULL, NULL, 0)); + CYUTF8String parsed; + + try { + parsed = CYPoolCode(pool, code); + } catch (const CYException &error) { + CYThrow("%s", pool.strcat("error caching ", CYPoolCString(pool, context, property), ": ", error.PoolCString(pool), NULL)); + } + + JSValueRef result(_jsccall(JSEvaluateScript, context, CYJSString(parsed), NULL, NULL, 0)); if (flags == 0) { JSObjectRef cache(CYGetCachedObject(context, CYJSString("cache"))); diff --git a/Library.cpp b/Library.cpp index 47da272..942ae8e 100644 --- a/Library.cpp +++ b/Library.cpp @@ -128,8 +128,12 @@ _visible bool CYStartsWith(const CYUTF8String &haystack, const CYUTF8String &nee CYUTF8String CYPoolCode(CYPool &pool, std::streambuf &stream) { CYLocalPool local; CYDriver driver(local, stream); - _assert(!driver.Parse()); - _assert(driver.errors_.empty()); + + if (driver.Parse()) { + if (!driver.errors_.empty()) + CYThrow("%s", driver.errors_.front().message_.c_str()); + CYThrow("syntax error"); + } CYOptions options; CYContext context(options); -- 2.45.2