Title: [158489] trunk/Source/WebKit2
Revision
158489
Author
m...@apple.com
Date
2013-11-02 09:42:47 -0700 (Sat, 02 Nov 2013)

Log Message

[Cocoa] Add WKNSDictionary
https://bugs.webkit.org/show_bug.cgi?id=123660

Reviewed by Anders Carlsson.

* Shared/Cocoa/APIObject.mm:
(WebKit::APIObject::newObject): Allocate a WKNSDictionary if the APIObject is a dictionary.
* Shared/Cocoa/WKNSDictionary.h: Added.
(WebKit::wrapper):  Added. Returns an ImmutableDictionary’s wrapper as an NSDictionary.
* Shared/Cocoa/WKNSDictionary.mm: Added.
(-[WKNSDictionary dealloc]): Calls the ImmutableDictionary destructor.
(-[WKNSDictionary count]): Added.
(-[WKNSDictionary objectForKey:]): Added.
(-[WKNSDictionary keyEnumerator]): Added.
(-[WKNSDictionary copyWithZone:]): Retains self.
(-[WKNSDictionary _apiObject]): Returns the wrapped ImmutableDictionary.
* WebKit2.xcodeproj/project.pbxproj: Added references to new files.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (158488 => 158489)


--- trunk/Source/WebKit2/ChangeLog	2013-11-02 16:04:45 UTC (rev 158488)
+++ trunk/Source/WebKit2/ChangeLog	2013-11-02 16:42:47 UTC (rev 158489)
@@ -1,3 +1,23 @@
+2013-11-02  Dan Bernstein  <m...@apple.com>
+
+        [Cocoa] Add WKNSDictionary
+        https://bugs.webkit.org/show_bug.cgi?id=123660
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/Cocoa/APIObject.mm:
+        (WebKit::APIObject::newObject): Allocate a WKNSDictionary if the APIObject is a dictionary.
+        * Shared/Cocoa/WKNSDictionary.h: Added.
+        (WebKit::wrapper):  Added. Returns an ImmutableDictionary’s wrapper as an NSDictionary.
+        * Shared/Cocoa/WKNSDictionary.mm: Added.
+        (-[WKNSDictionary dealloc]): Calls the ImmutableDictionary destructor.
+        (-[WKNSDictionary count]): Added.
+        (-[WKNSDictionary objectForKey:]): Added.
+        (-[WKNSDictionary keyEnumerator]): Added.
+        (-[WKNSDictionary copyWithZone:]): Retains self.
+        (-[WKNSDictionary _apiObject]): Returns the wrapped ImmutableDictionary.
+        * WebKit2.xcodeproj/project.pbxproj: Added references to new files.
+
 2013-11-02  Tim Horton  <timothy_hor...@apple.com>
 
         Address some review comments noted in r158463

Modified: trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm (158488 => 158489)


--- trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm	2013-11-02 16:04:45 UTC (rev 158488)
+++ trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm	2013-11-02 16:42:47 UTC (rev 158489)
@@ -31,6 +31,7 @@
 #import "WKBackForwardListInternal.h"
 #import "WKBackForwardListItemInternal.h"
 #import "WKNSArray.h"
+#import "WKNSDictionary.h"
 #import "WKNSString.h"
 #import "WKNSURL.h"
 
@@ -67,6 +68,10 @@
         wrapper = [WKBackForwardListItem alloc];
         break;
 
+    case TypeDictionary:
+        wrapper = [WKNSDictionary alloc];
+        break;
+
     case TypeString:
         wrapper = NSAllocateObject([WKNSString class], size, nullptr);
         break;

Added: trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.h (0 => 158489)


--- trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.h	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.h	2013-11-02 16:42:47 UTC (rev 158489)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WKFoundation.h"
+
+#if WK_API_ENABLED
+
+#import "ImmutableDictionary.h"
+#import "WKObject.h"
+
+namespace WebKit {
+inline NSDictionary *wrapper(ImmutableDictionary& dictionary) { ASSERT([dictionary.wrapper() isKindOfClass:[NSDictionary class]]); return (NSDictionary *)dictionary.wrapper(); }
+}
+
+@interface WKNSDictionary : NSDictionary <WKObject>
+@end
+
+#endif // WK_API_ENABLED

Added: trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.mm (0 => 158489)


--- trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.mm	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/Cocoa/WKNSDictionary.mm	2013-11-02 16:42:47 UTC (rev 158489)
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKNSDictionary.h"
+
+#if WK_API_ENABLED
+
+#import "WKNSArray.h"
+
+using namespace WebKit;
+
+@implementation WKNSDictionary {
+    std::aligned_storage<sizeof(ImmutableDictionary), std::alignment_of<ImmutableDictionary>::value>::type _dictionary;
+}
+
+- (void)dealloc
+{
+    reinterpret_cast<ImmutableDictionary*>(&_dictionary)->~ImmutableDictionary();
+
+    [super dealloc];
+}
+
+#pragma mark NSDictionary primitive methods
+
+- (instancetype)initWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)count
+{
+    ASSERT_NOT_REACHED();
+    [super initWithObjects:objects forKeys:keys count:count];
+}
+
+- (NSUInteger)count
+{
+    return reinterpret_cast<ImmutableDictionary*>(&_dictionary)->size();
+}
+
+- (id)objectForKey:(id)key
+{
+    if (![key isKindOfClass:[NSString class]])
+        return nil;
+
+    if (APIObject* value = reinterpret_cast<ImmutableDictionary*>(&_dictionary)->get((NSString *)key))
+        return value->wrapper();
+
+    return nil;
+}
+
+- (NSEnumerator *)keyEnumerator
+{
+    return [wrapper(*reinterpret_cast<ImmutableDictionary*>(&_dictionary)->keys()) objectEnumerator];
+}
+
+#pragma mark NSCopying protocol implementation
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    return [self retain];
+}
+
+#pragma mark WKObject protocol implementation
+
+- (APIObject&)_apiObject
+{
+    return *reinterpret_cast<APIObject*>(&_dictionary);
+}
+
+@end
+
+#endif // WK_API_ENABLED

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (158488 => 158489)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-11-02 16:04:45 UTC (rev 158488)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-11-02 16:42:47 UTC (rev 158489)
@@ -398,6 +398,8 @@
 		33D3A3CA1339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33D3A3C61339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp */; };
 		33D3A3CB1339617900709BE4 /* WebMediaCacheManagerProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 33D3A3C71339617900709BE4 /* WebMediaCacheManagerProxyMessages.h */; };
 		33F9D5B91312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */; };
+		371A19411824D29300F32A5E /* WKNSDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 371A193F1824D29300F32A5E /* WKNSDictionary.mm */; };
+		371A19421824D29300F32A5E /* WKNSDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 371A19401824D29300F32A5E /* WKNSDictionary.h */; };
 		374436881820E7240049579F /* WKObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374436871820E7240049579F /* WKObject.mm */; };
 		3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3760881C150413E900FC82C7 /* WebRenderObject.cpp */; };
 		3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 3760881D150413E900FC82C7 /* WebRenderObject.h */; };
@@ -1891,6 +1893,8 @@
 		33D3A3C71339617900709BE4 /* WebMediaCacheManagerProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebMediaCacheManagerProxyMessages.h; sourceTree = "<group>"; };
 		33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = WebResourceCacheManagerCFNet.cpp; path = ResourceCache/cf/WebResourceCacheManagerCFNet.cpp; sourceTree = "<group>"; };
 		3574B37F1665932C00859BB7 /* PDFAnnotationTextWidgetDetails.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PDFAnnotationTextWidgetDetails.h; path = PDF/PDFAnnotationTextWidgetDetails.h; sourceTree = "<group>"; };
+		371A193F1824D29300F32A5E /* WKNSDictionary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSDictionary.mm; sourceTree = "<group>"; };
+		371A19401824D29300F32A5E /* WKNSDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSDictionary.h; sourceTree = "<group>"; };
 		374436871820E7240049579F /* WKObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKObject.mm; sourceTree = "<group>"; };
 		3760881C150413E900FC82C7 /* WebRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebRenderObject.cpp; sourceTree = "<group>"; };
 		3760881D150413E900FC82C7 /* WebRenderObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebRenderObject.h; sourceTree = "<group>"; };
@@ -3687,6 +3691,8 @@
 				378E1A3B181ED6FF0031007A /* APIObject.mm */,
 				37C4C0921814B3AF003688B9 /* WKNSArray.h */,
 				37C4C0911814B3AF003688B9 /* WKNSArray.mm */,
+				371A19401824D29300F32A5E /* WKNSDictionary.h */,
+				371A193F1824D29300F32A5E /* WKNSDictionary.mm */,
 				378E1A4818208CD60031007A /* WKNSString.h */,
 				378E1A4718208CD60031007A /* WKNSString.mm */,
 				378E1A4C18208D700031007A /* WKNSURL.h */,
@@ -5758,6 +5764,7 @@
 				33D3A3C2133960B000709BE4 /* WebMediaCacheManager.h in Headers */,
 				33D3A3C91339617900709BE4 /* WebMediaCacheManagerMessages.h in Headers */,
 				37C4C08D1814AC5C003688B9 /* WKBackForwardList.h in Headers */,
+				371A19421824D29300F32A5E /* WKNSDictionary.h in Headers */,
 				33D3A3BB1339606200709BE4 /* WebMediaCacheManagerProxy.h in Headers */,
 				33D3A3CB1339617900709BE4 /* WebMediaCacheManagerProxyMessages.h in Headers */,
 				909854ED12BC4E18000AD080 /* WebMemorySampler.h in Headers */,
@@ -6916,6 +6923,7 @@
 				1A2D92211281DC1B001EB962 /* PluginProxyMac.mm in Sources */,
 				755422C418062BF90046F6A8 /* WebOriginDataManagerProxy.cpp in Sources */,
 				1A8EFA701252B84100F7067F /* PluginProxyMessageReceiver.cpp in Sources */,
+				371A19411824D29300F32A5E /* WKNSDictionary.mm in Sources */,
 				7CD622771739D863005BD7FF /* PluginSandboxProfile.mm in Sources */,
 				BC82844D16B5081C00A278FE /* PluginServiceEntryPoint.mm in Sources */,
 				1A6FB7AE11E64B6800DB1371 /* PluginView.cpp in Sources */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to