Implement more NSCoder methods
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Nov 2013 20:56:57 +0000 (20:56 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Nov 2013 20:56:57 +0000 (20:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123815

Reviewed by Dan Bernstein.

Source/WebKit2:

* Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(encodeObject):
Assert that object is not nil.

(createEncodedObject):
Handle nil objects.

(-[WKRemoteObjectEncoder encodeValueOfObjCType:at:]):
Call the right object stream encoding function based on the object type.

(-[WKRemoteObjectEncoder encodeBool:forKey:]):
(-[WKRemoteObjectEncoder encodeInt64:forKey:]):
(-[WKRemoteObjectEncoder encodeDouble:forKey:]):
Create APIObjects and add them to the current dictionary.

Tools:

Add a method that takes an NSArray, an NSDictionary and an NSURLRequest.

* TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/mac/WKRemoteObjectRegistry_Bundle.mm:
(-[BundleObject testMethodWithArray:dictionary:request:]):
* TestWebKitAPI/Tests/mac/WKRemoteObjectRegistry_Shared.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm
Tools/TestWebKitAPI/Tests/mac/WKRemoteObjectRegistry_Bundle.mm
Tools/TestWebKitAPI/Tests/mac/WKRemoteObjectRegistry_Shared.h

index f5969c9..76e97c7 100644 (file)
@@ -1,5 +1,27 @@
 2013-11-05  Anders Carlsson  <andersca@apple.com>
 
+        Implement more NSCoder methods
+        https://bugs.webkit.org/show_bug.cgi?id=123815
+
+        Reviewed by Dan Bernstein.
+
+        * Shared/API/Cocoa/WKRemoteObjectCoder.mm:
+        (encodeObject):
+        Assert that object is not nil.
+
+        (createEncodedObject):
+        Handle nil objects.
+
+        (-[WKRemoteObjectEncoder encodeValueOfObjCType:at:]):
+        Call the right object stream encoding function based on the object type.
+
+        (-[WKRemoteObjectEncoder encodeBool:forKey:]):
+        (-[WKRemoteObjectEncoder encodeInt64:forKey:]):
+        (-[WKRemoteObjectEncoder encodeDouble:forKey:]):
+        Create APIObjects and add them to the current dictionary.
+
+2013-11-05  Anders Carlsson  <andersca@apple.com>
+
         Encode the class name
         https://bugs.webkit.org/show_bug.cgi?id=123813
 
index d9fde72..b9fe97f 100644 (file)
@@ -162,6 +162,8 @@ static void encodeInvocation(WKRemoteObjectEncoder *encoder, NSInvocation *invoc
 
 static void encodeObject(WKRemoteObjectEncoder *encoder, id object)
 {
+    ASSERT(object);
+    
     if ([object isKindOfClass:[NSInvocation class]]) {
         // We have to special case NSInvocation since we don't want to encode the target.
         encodeInvocation(encoder, object);
@@ -184,6 +186,9 @@ static void encodeObject(WKRemoteObjectEncoder *encoder, id object)
 
 static PassRefPtr<ImmutableDictionary> createEncodedObject(WKRemoteObjectEncoder *encoder, id object)
 {
+    if (!object)
+        return nil;
+
     RefPtr<MutableDictionary> dictionary = MutableDictionary::create();
     TemporaryChange<MutableDictionary*> dictionaryChange(encoder->_currentDictionary, dictionary.get());
 
@@ -192,6 +197,24 @@ static PassRefPtr<ImmutableDictionary> createEncodedObject(WKRemoteObjectEncoder
     return dictionary;
 }
 
+- (void)encodeValueOfObjCType:(const char *)type at:(const void *)address
+{
+    switch (*type) {
+    // int
+    case 'i':
+        encodeToObjectStream(self, *static_cast<const int*>(address));
+        break;
+
+    // Objective-C object.
+    case '@':
+        encodeToObjectStream(self, *static_cast<const id*>(address));
+        break;
+
+    default:
+        [NSException raise:NSInvalidArgumentException format:@"Unsupported type '%s'", type];
+    }
+}
+
 - (BOOL)allowsKeyedCoding
 {
     return YES;
@@ -215,6 +238,21 @@ static NSString *escapeKey(NSString *key)
     _currentDictionary->set(escapeKey(key), WebData::create(bytes, length));
 }
 
+- (void)encodeBool:(BOOL)value forKey:(NSString *)key
+{
+    _currentDictionary->set(escapeKey(key), WebBoolean::create(value));
+}
+
+- (void)encodeInt64:(int64_t)value forKey:(NSString *)key
+{
+    _currentDictionary->set(escapeKey(key), WebUInt64::create(value));
+}
+
+- (void)encodeDouble:(double)value forKey:(NSString *)key
+{
+    _currentDictionary->set(escapeKey(key), WebDouble::create(value));
+}
+
 @end
 
 #endif // WK_API_ENABLED
index dd701bd..e608fbd 100644 (file)
@@ -1,3 +1,18 @@
+2013-11-05  Anders Carlsson  <andersca@apple.com>
+
+        Implement more NSCoder methods
+        https://bugs.webkit.org/show_bug.cgi?id=123815
+
+        Reviewed by Dan Bernstein.
+
+        Add a method that takes an NSArray, an NSDictionary and an NSURLRequest.
+
+        * TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/mac/WKRemoteObjectRegistry_Bundle.mm:
+        (-[BundleObject testMethodWithArray:dictionary:request:]):
+        * TestWebKitAPI/Tests/mac/WKRemoteObjectRegistry_Shared.h:
+
 2013-11-05  Filip Pizlo  <fpizlo@apple.com>
 
         Update ReducedFTL
index 322b0ec..45be22b 100644 (file)
@@ -101,6 +101,10 @@ TEST(WebKit2, WKRemoteObjectRegistryTest)
     [remoteObjectProxy sayHello];
     [remoteObjectProxy testMethodWithString:@"Hello" double:123.456 integer:789];
 
+    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.webkit.org/" relativeToURL:[NSURL URLWithString:@"http://www.webkit.org/"]] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:123.456];
+
+    [remoteObjectProxy testMethodWithArray:@[ @1, @2, @3 ] dictionary:@{ @"Key" : @"Value", @123 : @456 } request:request];
+
     // FIXME: Set this once the test actually is finished.
     testFinished = true;
 
index c1a1b59..78136d6 100644 (file)
     // FIXME: Implement.
 }
 
+- (void)testMethodWithArray:(NSArray *)array dictionary:(NSDictionary *)dictinoary request:(NSURLRequest *)request
+{
+    // FIXME: Implement.
+}
+
 @end
 
 namespace TestWebKitAPI {
index ebe4546..e166653 100644 (file)
@@ -27,5 +27,6 @@
 
 - (void)sayHello;
 - (void)testMethodWithString:(NSString *)string double:(double)d integer:(int)i;
+- (void)testMethodWithArray:(NSArray *)array dictionary:(NSDictionary *)dictinoary request:(NSURLRequest *)request;
 
 @end