From dc5d7cf41a141ba83d66f97957bd7742a8adbc4f Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 2 Jan 2014 04:52:42 -0800 Subject: [PATCH] When CYONifying fields, @error encode exceptions. --- Cycript.l.in | 2 ++ Cycript.yy.in | 2 ++ Execute.cpp | 18 ++++++++++++------ Highlight.cpp | 2 +- Highlight.hpp | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Cycript.l.in b/Cycript.l.in index 87a46af..cb422cc 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -251,6 +251,8 @@ XMLName {XMLNameStart}{XMLNamePart}* "[" L C F(tk::OpenBracket, hi::Structure); "]" L C F(tk::CloseBracket, hi::Structure); +"@error" L C F(tk::AtError, hi::Error); + @begin Java "@class" L C F(tk::AtClass, hi::Meta); @end diff --git a/Cycript.yy.in b/Cycript.yy.in index 14f6aad..53673a2 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -224,6 +224,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %token OpenBracket "[" %token CloseBracket "]" +%token AtError "@error" + @begin Java %token AtClass "@class" @end diff --git a/Execute.cpp b/Execute.cpp index 5df5f60..ca678ae 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -443,27 +443,33 @@ const char *CYPoolCCYON(CYPool &pool, JSContextRef context, JSObjectRef object) bool comma(false); for (size_t index(0), count(JSPropertyNameArrayGetCount(names)); index != count; ++index) { - JSStringRef name(JSPropertyNameArrayGetNameAtIndex(names, index)); - JSValueRef value(CYGetProperty(context, object, name)); - if (comma) str << ','; else comma = true; + JSStringRef name(JSPropertyNameArrayGetNameAtIndex(names, index)); CYUTF8String string(CYPoolUTF8String(pool, context, name)); + if (CYIsKey(string)) str << string.data; else CYStringify(str, string.data, string.size); - str << ':' << CYPoolCCYON(pool, context, value); - } + str << ':'; - str << '}'; + try { + JSValueRef value(CYGetProperty(context, object, name)); + str << CYPoolCCYON(pool, context, value); + } catch (const CYException &error) { + str << "@error"; + } + } JSPropertyNameArrayRelease(names); + str << '}'; + std::string string(str.str()); return pool.strmemdup(string.c_str(), string.size()); } diff --git a/Highlight.cpp b/Highlight.cpp index 4b7d669..0a077a8 100644 --- a/Highlight.cpp +++ b/Highlight.cpp @@ -74,7 +74,7 @@ void CYLexerHighlight(const char *data, size_t size, std::ostream &output, bool case hi::Comment: color = CYColor(true, 30); break; case hi::Constant: color = CYColor(false, 31); break; case hi::Control: color = CYColor(false, 33); break; - case hi::Escape: color = CYColor(true, 31); break; + case hi::Error: color = CYColor(true, 31); break; case hi::Identifier: color = CYColor(false, 0); break; case hi::Meta: color = CYColor(false, 32); break; case hi::Nothing: color = CYColor(false, 0); break; diff --git a/Highlight.hpp b/Highlight.hpp index 1feca0c..278ff07 100644 --- a/Highlight.hpp +++ b/Highlight.hpp @@ -28,7 +28,7 @@ namespace hi { enum Value { Comment, Constant, Control, - Escape, + Error, Identifier, Meta, Nothing, -- 2.47.2