Title: [158553] trunk/Source/WebKit2
Revision
158553
Author
m...@apple.com
Date
2013-11-03 19:01:01 -0800 (Sun, 03 Nov 2013)

Log Message

[Cocoa] Wrappers' -copyWithZone: should copy if the collection is mutable
https://bugs.webkit.org/show_bug.cgi?id=123707

Reviewed by Geoff Garen and Anders Carlsson.

* Shared/Cocoa/WKNSArray.mm:
(-[WKNSArray copyWithZone:]): If the array is mutable, make a copy.
* Shared/Cocoa/WKNSDictionary.mm:
(-[WKNSDictionary copyWithZone:]): If the dictionary is mutable, make a copy.
* Shared/ImmutableArray.h:
(WebKit::ImmutableArray::entries): Added this accessor.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (158552 => 158553)


--- trunk/Source/WebKit2/ChangeLog	2013-11-04 02:57:56 UTC (rev 158552)
+++ trunk/Source/WebKit2/ChangeLog	2013-11-04 03:01:01 UTC (rev 158553)
@@ -1,5 +1,19 @@
 2013-11-03  Dan Bernstein  <m...@apple.com>
 
+        [Cocoa] Wrappers' -copyWithZone: should copy if the collection is mutable
+        https://bugs.webkit.org/show_bug.cgi?id=123707
+
+        Reviewed by Geoff Garen and Anders Carlsson.
+
+        * Shared/Cocoa/WKNSArray.mm:
+        (-[WKNSArray copyWithZone:]): If the array is mutable, make a copy.
+        * Shared/Cocoa/WKNSDictionary.mm:
+        (-[WKNSDictionary copyWithZone:]): If the dictionary is mutable, make a copy.
+        * Shared/ImmutableArray.h:
+        (WebKit::ImmutableArray::entries): Added this accessor.
+
+2013-11-03  Dan Bernstein  <m...@apple.com>
+
         Reverted r158538.
 
         * Shared/Cocoa/WKNSArray.mm:

Modified: trunk/Source/WebKit2/Shared/Cocoa/WKNSArray.mm (158552 => 158553)


--- trunk/Source/WebKit2/Shared/Cocoa/WKNSArray.mm	2013-11-04 02:57:56 UTC (rev 158552)
+++ trunk/Source/WebKit2/Shared/Cocoa/WKNSArray.mm	2013-11-04 03:01:01 UTC (rev 158553)
@@ -58,7 +58,11 @@
 
 - (id)copyWithZone:(NSZone *)zone
 {
-    return [self retain];
+    if (!reinterpret_cast<ImmutableArray*>(&_array)->isMutable())
+        return [self retain];
+
+    auto entries = reinterpret_cast<ImmutableArray*>(&_array)->entries();
+    return ImmutableArray::adopt(entries).leakRef()->wrapper();
 }
 
 #pragma mark WKObject protocol implementation

Modified: trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.mm (158552 => 158553)


--- trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.mm	2013-11-04 02:57:56 UTC (rev 158552)
+++ trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.mm	2013-11-04 03:01:01 UTC (rev 158553)
@@ -78,7 +78,11 @@
 
 - (id)copyWithZone:(NSZone *)zone
 {
-    return [self retain];
+    if (!reinterpret_cast<ImmutableDictionary*>(&_dictionary)->isMutable())
+        return [self retain];
+
+    auto map = reinterpret_cast<ImmutableDictionary*>(&_dictionary)->map();
+    return ImmutableDictionary::adopt(map).leakRef()->wrapper();
 }
 
 #pragma mark WKObject protocol implementation

Modified: trunk/Source/WebKit2/Shared/ImmutableArray.h (158552 => 158553)


--- trunk/Source/WebKit2/Shared/ImmutableArray.h	2013-11-04 02:57:56 UTC (rev 158552)
+++ trunk/Source/WebKit2/Shared/ImmutableArray.h	2013-11-04 03:01:01 UTC (rev 158553)
@@ -65,6 +65,8 @@
 
     virtual bool isMutable() { return false; }
 
+    const Vector<RefPtr<APIObject>>& entries() { return m_entries; }
+
 protected:
     ImmutableArray();
     ImmutableArray(AdoptTag, APIObject** entries, size_t);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to