From 21438860e82d7b718bae32d7d9ab5257eeb572c8 Mon Sep 17 00:00:00 2001 From: andersca Date: Wed, 19 Jul 2006 17:32:15 +0000 Subject: [PATCH] JavaScriptCore: 2006-07-19 Anders Carlsson Reviewed by Darin. REGRESSION(10.4.7-10.5): preview button for a blogger.com post doesn't work * kjs/nodes2string.cpp: (StringNode::streamTo): Return the escaped string. (RegExpNode::streamTo): Use the correct syntax. * kjs/function.cpp: (KJS::escapeStringForPrettyPrinting): * kjs/function.h: Add escape function which escapes a string for pretty-printing so it can be parsed again. * wtf/unicode/icu/UnicodeIcu.h: (WTF::Unicode::isPrintableChar): New function. LayoutTests: 2006-07-19 Anders Carlsson Reviewed by Darin. REGRESSION(10.4.7-10.5): preview button for a blogger.com post doesn't work * fast/js/pretty-print-expected.txt: Added. * fast/js/pretty-print.html: Added. * fast/js/resources/pretty-print.js: Added. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15526 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- JavaScriptCore/ChangeLog | 22 +++++++++++ JavaScriptCore/kjs/function.cpp | 39 +++++++++++++++++++ JavaScriptCore/kjs/function.h | 2 +- JavaScriptCore/kjs/nodes2string.cpp | 8 +++- JavaScriptCore/wtf/unicode/icu/UnicodeIcu.h | 5 +++ LayoutTests/ChangeLog | 10 +++++ LayoutTests/fast/js/pretty-print-expected.txt | 4 ++ LayoutTests/fast/js/pretty-print.html | 13 +++++++ LayoutTests/fast/js/resources/pretty-print.js | 12 ++++++ 9 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 LayoutTests/fast/js/pretty-print-expected.txt create mode 100644 LayoutTests/fast/js/pretty-print.html create mode 100644 LayoutTests/fast/js/resources/pretty-print.js diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog index 15db7571b6ae..cf18872e1839 100644 --- a/JavaScriptCore/ChangeLog +++ b/JavaScriptCore/ChangeLog @@ -1,3 +1,25 @@ +2006-07-19 Anders Carlsson + + Reviewed by Darin. + + REGRESSION(10.4.7-10.5): preview button for a blogger.com post doesn't work + + * kjs/nodes2string.cpp: + (StringNode::streamTo): + Return the escaped string. + + (RegExpNode::streamTo): + Use the correct syntax. + + * kjs/function.cpp: + (KJS::escapeStringForPrettyPrinting): + * kjs/function.h: + Add escape function which escapes a string for pretty-printing so it can be parsed again. + + * wtf/unicode/icu/UnicodeIcu.h: + (WTF::Unicode::isPrintableChar): + New function. + === Safari-521.19 === 2006-07-18 Maciej Stachowiak diff --git a/JavaScriptCore/kjs/function.cpp b/JavaScriptCore/kjs/function.cpp index 294c2376b8aa..ffd611c53e9f 100644 --- a/JavaScriptCore/kjs/function.cpp +++ b/JavaScriptCore/kjs/function.cpp @@ -918,4 +918,43 @@ JSValue *GlobalFuncImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, c return res; } +UString escapeStringForPrettyPrinting(const UString& s) +{ + UString escapedString; + + for (int i = 0; i < s.size(); i++) { + unsigned short c = s.data()[i].unicode(); + + switch (c) { + case '\"': + escapedString += "\\\""; + break; + case '\n': + escapedString += "\\n"; + break; + case '\r': + escapedString += "\\r"; + break; + case '\t': + escapedString += "\\t"; + break; + case '\\': + escapedString += "\\\\"; + break; + default: + if (c < 128 && WTF::Unicode::isPrintableChar(c)) + escapedString.append(c); + else { + char hexValue[7]; + + snprintf(hexValue, 7, "\\u%04x", c); + escapedString += hexValue; + } + } + } + + return escapedString; +} + + } // namespace diff --git a/JavaScriptCore/kjs/function.h b/JavaScriptCore/kjs/function.h index e9b205e5b963..79cd44bd322e 100644 --- a/JavaScriptCore/kjs/function.h +++ b/JavaScriptCore/kjs/function.h @@ -161,7 +161,7 @@ namespace KJS { int id; }; - +UString escapeStringForPrettyPrinting(const UString& s); } // namespace diff --git a/JavaScriptCore/kjs/nodes2string.cpp b/JavaScriptCore/kjs/nodes2string.cpp index caff9f19aa8e..90c02a26b88d 100644 --- a/JavaScriptCore/kjs/nodes2string.cpp +++ b/JavaScriptCore/kjs/nodes2string.cpp @@ -22,6 +22,7 @@ #include "config.h" #include "nodes.h" +#include "function.h" namespace KJS { /** @@ -116,10 +117,13 @@ void NumberNode::streamTo(SourceStream &s) const { s << UString::from(value); } void StringNode::streamTo(SourceStream &s) const { - s << '"' << value << '"'; + s << '"' << escapeStringForPrettyPrinting(value) << '"'; } -void RegExpNode::streamTo(SourceStream &s) const { s << pattern; } +void RegExpNode::streamTo(SourceStream &s) const +{ + s << "/" << pattern << "/" << flags; +} void ThisNode::streamTo(SourceStream &s) const { s << "this"; } diff --git a/JavaScriptCore/wtf/unicode/icu/UnicodeIcu.h b/JavaScriptCore/wtf/unicode/icu/UnicodeIcu.h index 16ae478449cd..668874f35607 100644 --- a/JavaScriptCore/wtf/unicode/icu/UnicodeIcu.h +++ b/JavaScriptCore/wtf/unicode/icu/UnicodeIcu.h @@ -82,6 +82,11 @@ namespace WTF { return u_charType(c) == U_SPACE_SEPARATOR; } + inline bool isPrintableChar(int32_t c) + { + return u_isprint(c); + } + inline CharCategory category(int32_t c) { switch (u_charType(c)) { diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index cc6cd8312f0b..6f84436d9268 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,13 @@ +2006-07-19 Anders Carlsson + + Reviewed by Darin. + + REGRESSION(10.4.7-10.5): preview button for a blogger.com post doesn't work + + * fast/js/pretty-print-expected.txt: Added. + * fast/js/pretty-print.html: Added. + * fast/js/resources/pretty-print.js: Added. + 2006-07-19 David Harrison -[DOMRange markupString] does not include the initial table element if it is at the beginning of the range diff --git a/LayoutTests/fast/js/pretty-print-expected.txt b/LayoutTests/fast/js/pretty-print-expected.txt new file mode 100644 index 000000000000..43e5eeedbf1b --- /dev/null +++ b/LayoutTests/fast/js/pretty-print-expected.txt @@ -0,0 +1,4 @@ +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/js/pretty-print.html b/LayoutTests/fast/js/pretty-print.html new file mode 100644 index 000000000000..6df2d0da260c --- /dev/null +++ b/LayoutTests/fast/js/pretty-print.html @@ -0,0 +1,13 @@ + + + + + + + +

+
+ + + + diff --git a/LayoutTests/fast/js/resources/pretty-print.js b/LayoutTests/fast/js/resources/pretty-print.js new file mode 100644 index 000000000000..bc0a46415a6d --- /dev/null +++ b/LayoutTests/fast/js/resources/pretty-print.js @@ -0,0 +1,12 @@ +//description( +"This test checks that regexps and strings with are pretty-printed correctly" +//); + +function f() { + var re = /test/g; + var s = '\n\r\\'; +} + +eval(f.toString()); + +var successfullyParsed = true; -- 2.36.0