JavaScriptCore:
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jul 2006 17:32:15 +0000 (17:32 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jul 2006 17:32:15 +0000 (17:32 +0000)
2006-07-19  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Darin.

        <rdar://problem/4620655> 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  <acarlsson@apple.com>

        Reviewed by Darin.

        <rdar://problem/4620655> 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
JavaScriptCore/kjs/function.cpp
JavaScriptCore/kjs/function.h
JavaScriptCore/kjs/nodes2string.cpp
JavaScriptCore/wtf/unicode/icu/UnicodeIcu.h
LayoutTests/ChangeLog
LayoutTests/fast/js/pretty-print-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/pretty-print.html [new file with mode: 0644]
LayoutTests/fast/js/resources/pretty-print.js [new file with mode: 0644]

index 15db7571b6ae6ee34113d89acde37b8eb2abc341..cf18872e183947aaf9a489476a9fe8f428586472 100644 (file)
@@ -1,3 +1,25 @@
+2006-07-19  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Darin.
+
+        <rdar://problem/4620655> 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  <mjs@apple.com>
index 294c2376b8aa0ab2d9adadc353346ec6a7ddc348..ffd611c53e9f6270deb5f23af7f19f437a32ab77 100644 (file)
@@ -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
index e9b205e5b96326136c200217aa8e851f4ba514d3..79cd44bd322eab02e2369f5f377f11b4fb877d22 100644 (file)
@@ -161,7 +161,7 @@ namespace KJS {
     int id;
   };
 
-
+UString escapeStringForPrettyPrinting(const UString& s);
 
 } // namespace
 
index caff9f19aa8ebc75dde1679d0261b111a8893a65..90c02a26b88db40ba63d0066983fb1c0a0afd356 100644 (file)
@@ -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"; }
 
index 16ae478449cddf440e113d5963678621fc33736e..668874f3560711d600bc8e942aca8bcf8a6e1cea 100644 (file)
@@ -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)) {
index cc6cd8312f0b20e635dcb6582c63e9b432e0ae8a..6f84436d926831027d8e312d06b91998e1187f29 100644 (file)
@@ -1,3 +1,13 @@
+2006-07-19  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Darin.
+
+        <rdar://problem/4620655> 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  <harrison@apple.com>
 
         <rdar://problem/4629307> -[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 (file)
index 0000000..43e5eee
--- /dev/null
@@ -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 (file)
index 0000000..6df2d0d
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/pretty-print.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/resources/pretty-print.js b/LayoutTests/fast/js/resources/pretty-print.js
new file mode 100644 (file)
index 0000000..bc0a464
--- /dev/null
@@ -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;