JavaScriptCore:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2006 16:39:00 +0000 (16:39 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2006 16:39:00 +0000 (16:39 +0000)
        Reviewed by John.

        - fix iteration of properties of string objects (found because of a warning
          emitted by the MSVC compiler)

        * kjs/string_object.cpp: (StringInstance::getPropertyNames): Change code that
        wants to format a number as a string to use UString::from. Before it was using
        the UString constructor that makes a string from a character!

        * kjs/ustring.h:
        * kjs/ustring.cpp: Remove the dangerous and not all that helpful UString(char)
        constructor.

        * kjs/grammar.y: Change code to not depend on the UString(char) constructor.
        This is potentially more efficient anyway because we could overload the + operator
        some day to handle char* directly instead of creating a UString.

        * kjs/nodes2string.cpp: (SourceStream::operator<<): Change code to not depend on
        the UString(char) constructor.

LayoutTests:

        Reviewed by John.

        - add a test for iteration of properties of string objects

        * fast/js/resources/string-property-iteration.js: Added.
        * fast/js/string-property-iteration-expected.txt: Added.
        * fast/js/string-property-iteration.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17306 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/nodes2string.cpp
JavaScriptCore/kjs/string_object.cpp
JavaScriptCore/kjs/ustring.cpp
JavaScriptCore/kjs/ustring.h
LayoutTests/ChangeLog
LayoutTests/fast/js/resources/string-property-iteration.js [new file with mode: 0644]
LayoutTests/fast/js/string-property-iteration-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/string-property-iteration.html [new file with mode: 0644]

index ef61ca307beb9371c78aa95c5a2e9e6e226ccc35..cc625ee634faf8bcf97169163b70a804cc307ef0 100644 (file)
@@ -1,3 +1,25 @@
+2006-10-26  Darin Adler  <darin@apple.com>
+
+        Reviewed by John.
+
+        - fix iteration of properties of string objects (found because of a warning
+          emitted by the MSVC compiler)
+
+        * kjs/string_object.cpp: (StringInstance::getPropertyNames): Change code that
+        wants to format a number as a string to use UString::from. Before it was using
+        the UString constructor that makes a string from a character!
+
+        * kjs/ustring.h:
+        * kjs/ustring.cpp: Remove the dangerous and not all that helpful UString(char)
+        constructor.
+
+        * kjs/grammar.y: Change code to not depend on the UString(char) constructor.
+        This is potentially more efficient anyway because we could overload the + operator
+        some day to handle char* directly instead of creating a UString.
+
+        * kjs/nodes2string.cpp: (SourceStream::operator<<): Change code to not depend on
+        the UString(char) constructor.
+
 2006-10-25  Kevin McCullough  <KMcCullough@apple.com>
 
         Reviewed by Steve (rubber stamp).
index 8775d8a93af8ce76cee04d65fe649fa301dfac96..f420f6583606fb804cc4f7f4d80e1eb42f108f97 100644 (file)
                9322A00306C341D3009067BB /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = /usr/lib/libicucore.dylib; sourceTree = "<absolute>"; };
                932F5BD80822A1C700736975 /* Info.plist */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; tabWidth = 8; };
                932F5BD90822A1C700736975 /* JavaScriptCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JavaScriptCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
-               932F5BE10822A1C700736975 /* testkjs */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = testkjs; sourceTree = BUILT_PRODUCTS_DIR; };
+               932F5BE10822A1C700736975 /* testkjs */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testkjs; sourceTree = BUILT_PRODUCTS_DIR; };
                933A3499038AE7C6008635CE /* grammar.y */ = {isa = PBXFileReference; explicitFileType = sourcecode.yacc; fileEncoding = 4; indentWidth = 4; path = grammar.y; sourceTree = "<group>"; tabWidth = 8; };
                933A349A038AE7C6008635CE /* identifier.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = identifier.h; sourceTree = "<group>"; tabWidth = 8; };
                933A349D038AE80F008635CE /* identifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = identifier.cpp; sourceTree = "<group>"; tabWidth = 8; };
index 6748c05adc011a39df7df43757a5adda1169f54c..95b89ab153f4d45711da3652957b3e8e597dde0a 100644 (file)
@@ -203,7 +203,7 @@ Literal:
   | DIVEQUAL /* regexp with /= */       {
                                             Lexer *l = Lexer::curr();
                                             if (!l->scanRegExp()) YYABORT;
-                                            $$ = new RegExpNode(UString('=') + l->pattern, l->flags);
+                                            $$ = new RegExpNode("=" + l->pattern, l->flags);
                                         }
 ;
 
index 90c02a26b88db40ba63d0066983fb1c0a0afd356..1acd97663b826dbf80dbef6edb38bb7b23be251b 100644 (file)
@@ -52,7 +52,8 @@ using namespace KJS;
 
 SourceStream& SourceStream::operator<<(char c)
 {
-  str += UString(c);
+  UChar ch(c);
+  str += UString(&ch, 1);
   return *this;
 }
 
index 31ec6808fa4a0999356d3f37997cda51b2321ba8..ca63756a3fd0458b290effaf264ecd20493cc3d2 100644 (file)
@@ -99,7 +99,7 @@ void StringInstance::getPropertyNames(ExecState* exec, PropertyNameArray& proper
 {
   int size = internalValue()->getString().size();
   for (int i = 0; i < size; i++)
-    propertyNames.add(Identifier(UString(i)));
+    propertyNames.add(Identifier(UString::from(i)));
   return JSObject::getPropertyNames(exec, propertyNames);
 }
 
index 5d939181bc1d00697e9fd85ceafd71d3359bbbf7..e2a4a10eb6e46b0846c316c8135f11a170c03532 100644 (file)
@@ -374,14 +374,6 @@ void UString::expandPreCapacity(int requiredPreCap)
   }
 }
 
-
-UString::UString(char c)
-{
-    UChar *d = static_cast<UChar *>(fastMalloc(sizeof(UChar)));
-    d[0] = c;
-    m_rep = Rep::create(d, 1);
-}
-
 UString::UString(const char *c)
 {
   if (!c) {
index 287da61d6198b0ac4789a203feba490ad4501d83..2a1627c32427ee36be1bc3261adc7c3805664f10 100644 (file)
@@ -220,11 +220,7 @@ namespace KJS {
      */
     UString();
     /**
-     * Constructs a string from the single character c.
-     */
-    explicit UString(char c);
-    /**
-     * Constructs a string from a classical zero determined char string.
+     * Constructs a string from a classical zero-terminated char string.
      */
     UString(const char *c);
     /**
index ff8fb0290070372b71b59402155395863e4fb020..68095b51f04afd691c1c949919e1f29e361ae09a 100644 (file)
@@ -1,3 +1,13 @@
+2006-10-26  Darin Adler  <darin@apple.com>
+
+        Reviewed by John.
+
+        - add a test for iteration of properties of string objects
+
+        * fast/js/resources/string-property-iteration.js: Added.
+        * fast/js/string-property-iteration-expected.txt: Added.
+        * fast/js/string-property-iteration.html: Added.
+
 2006-10-24  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Oliver.
diff --git a/LayoutTests/fast/js/resources/string-property-iteration.js b/LayoutTests/fast/js/resources/string-property-iteration.js
new file mode 100644 (file)
index 0000000..481cc95
--- /dev/null
@@ -0,0 +1,16 @@
+description("This page tests iteration of properties on a string object.");
+
+var stringProperties = new Array();
+var i = 0;
+for (var property in "abcde") {
+    stringProperties[i++] = property;
+}
+
+shouldBe('stringProperties.length', '5');
+shouldBe('stringProperties[0]', '"0"');
+shouldBe('stringProperties[1]', '"1"');
+shouldBe('stringProperties[2]', '"2"');
+shouldBe('stringProperties[3]', '"3"');
+shouldBe('stringProperties[4]', '"4"');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/js/string-property-iteration-expected.txt b/LayoutTests/fast/js/string-property-iteration-expected.txt
new file mode 100644 (file)
index 0000000..6f481e4
--- /dev/null
@@ -0,0 +1,23 @@
+This page tests iteration of properties on the string object.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+WARN: shouldBe() expects string arguments
+FAIL 0 should be 5 (of type number). Was 0 (of type number).
+WARN: shouldBe() expects string arguments
+FAIL undefined should be 0 (of type number). Was undefined (of type undefined).
+WARN: shouldBe() expects string arguments
+FAIL undefined should be 1 (of type number). Was undefined (of type undefined).
+WARN: shouldBe() expects string arguments
+FAIL undefined should be 2 (of type number). Was undefined (of type undefined).
+WARN: shouldBe() expects string arguments
+FAIL undefined should be 3 (of type number). Was undefined (of type undefined).
+WARN: shouldBe() expects string arguments
+FAIL undefined should be 4 (of type number). Was undefined (of type undefined).
+WARN: shouldBe() expects string arguments
+FAIL undefined should be 5 (of type number). Was undefined (of type undefined).
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/string-property-iteration.html b/LayoutTests/fast/js/string-property-iteration.html
new file mode 100644 (file)
index 0000000..ddfdc37
--- /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/string-property-iteration.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>