Title: [198022] trunk/Source/_javascript_Core
Revision
198022
Author
[email protected]
Date
2016-03-11 08:57:20 -0800 (Fri, 11 Mar 2016)

Log Message

Web Inspector: generated initWithPayload: protocol object initializers should recursively decode array and object members
https://bugs.webkit.org/show_bug.cgi?id=155337
<rdar://problem/25098357>

Reviewed by Timothy Hatcher.

In cases where an object member is itself an object or array, we were
not calling initWithPayload: on the object member itself. So, this caused
a runtime error when constructing the outer object because the generated
code casted the NSDictionary/NSArray into the member's protocol object type.

* inspector/scripts/codegen/objc_generator.py:
(ObjCGenerator.payload_to_objc_expression_for_member):
Do a straightforward call to initWithPayload: for objects. For arrays,
call a templated helper function which does the same thing. The helper
is used to make this array decoding fit into a single generated _expression_.

Rebaseline relevant test results.

* inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result:
* inspector/scripts/tests/expected/type-declaration-object-type.json-result:
* inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (198021 => 198022)


--- trunk/Source/_javascript_Core/ChangeLog	2016-03-11 16:20:25 UTC (rev 198021)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-03-11 16:57:20 UTC (rev 198022)
@@ -1,3 +1,28 @@
+2016-03-10  Brian Burg  <[email protected]>
+
+        Web Inspector: generated initWithPayload: protocol object initializers should recursively decode array and object members
+        https://bugs.webkit.org/show_bug.cgi?id=155337
+        <rdar://problem/25098357>
+
+        Reviewed by Timothy Hatcher.
+
+        In cases where an object member is itself an object or array, we were
+        not calling initWithPayload: on the object member itself. So, this caused
+        a runtime error when constructing the outer object because the generated
+        code casted the NSDictionary/NSArray into the member's protocol object type.
+
+        * inspector/scripts/codegen/objc_generator.py:
+        (ObjCGenerator.payload_to_objc_expression_for_member):
+        Do a straightforward call to initWithPayload: for objects. For arrays,
+        call a templated helper function which does the same thing. The helper
+        is used to make this array decoding fit into a single generated _expression_.
+
+        Rebaseline relevant test results.
+
+        * inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result:
+        * inspector/scripts/tests/expected/type-declaration-object-type.json-result:
+        * inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result:
+
 2016-03-10  Keith Miller  <[email protected]>
 
         Unreviewed, fix Changelog. git merged poorly.

Modified: trunk/Source/_javascript_Core/inspector/scripts/codegen/objc_generator.py (198021 => 198022)


--- trunk/Source/_javascript_Core/inspector/scripts/codegen/objc_generator.py	2016-03-11 16:20:25 UTC (rev 198021)
+++ trunk/Source/_javascript_Core/inspector/scripts/codegen/objc_generator.py	2016-03-11 16:57:20 UTC (rev 198022)
@@ -479,8 +479,12 @@
                 return 'fromProtocolString<%s>(%s)' % (self.objc_enum_name_for_anonymous_enum_member(declaration, member), sub_expression)
             else:
                 return 'fromProtocolString<%s>(%s)' % (self.objc_enum_name_for_non_anonymous_enum(member.type), sub_expression)
-        if isinstance(_type, (ObjectType, ArrayType)):
-            return 'payload[@"%s"]' % member.member_name
+        if isinstance(_type, ObjectType):
+            objc_class = self.objc_class_for_type(member.type)
+            return '[[%s alloc] initWithPayload:payload[@"%s"]]' % (objc_class, member.member_name)
+        if isinstance(_type, ArrayType):
+            objc_class = self.objc_class_for_type(member.type.element_type)
+            return 'objcArrayFromPayload<%s>(payload[@"%s"])' % (objc_class, member.member_name)
 
     # JSON object setter/getter selectors for types.
 

Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result (198021 => 198022)


--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result	2016-03-11 16:20:25 UTC (rev 198021)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result	2016-03-11 16:57:20 UTC (rev 198022)
@@ -1009,7 +1009,7 @@
 
     self.string = payload[@"string"];
 
-    self.array = payload[@"array"];
+    self.array = objcArrayFromPayload<NSString>(payload[@"array"]);
 
     return self;
 }

Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-object-type.json-result (198021 => 198022)


--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-object-type.json-result	2016-03-11 16:20:25 UTC (rev 198021)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-object-type.json-result	2016-03-11 16:57:20 UTC (rev 198022)
@@ -1522,7 +1522,7 @@
     if (!(self = [super init]))
         return nil;
 
-    self.columnNames = payload[@"columnNames"];
+    self.columnNames = objcArrayFromPayload<NSString>(payload[@"columnNames"]);
 
     self.notes = payload[@"notes"];
 
@@ -1532,9 +1532,9 @@
 
     self.payload = payload[@"payload"];
 
-    self.error = payload[@"error"];
+    self.error = [[TestProtocolDatabaseError alloc] initWithPayload:payload[@"error"]];
 
-    self.errorList = payload[@"errorList"];
+    self.errorList = objcArrayFromPayload<TestProtocolDatabaseError>(payload[@"errorList"]);
 
     return self;
 }
@@ -1620,7 +1620,7 @@
         return nil;
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"columnNames"], @"columnNames");
-    self.columnNames = payload[@"columnNames"];
+    self.columnNames = objcArrayFromPayload<NSString>(payload[@"columnNames"]);
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"notes"], @"notes");
     self.notes = payload[@"notes"];
@@ -1635,10 +1635,10 @@
     self.payload = payload[@"payload"];
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"error"], @"error");
-    self.error = payload[@"error"];
+    self.error = [[TestProtocolDatabaseError alloc] initWithPayload:payload[@"error"]];
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"errorList"], @"errorList");
-    self.errorList = payload[@"errorList"];
+    self.errorList = objcArrayFromPayload<TestProtocolDatabaseError>(payload[@"errorList"]);
 
     return self;
 }
@@ -1860,7 +1860,7 @@
         return nil;
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"columnNames"], @"columnNames");
-    self.columnNames = payload[@"columnNames"];
+    self.columnNames = objcArrayFromPayload<NSString>(payload[@"columnNames"]);
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"notes"], @"notes");
     self.notes = payload[@"notes"];
@@ -1875,7 +1875,7 @@
     self.payload = payload[@"payload"];
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"error"], @"error");
-    self.error = payload[@"error"];
+    self.error = [[TestProtocolDatabaseError alloc] initWithPayload:payload[@"error"]];
 
     return self;
 }

Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result (198021 => 198022)


--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result	2016-03-11 16:20:25 UTC (rev 198021)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result	2016-03-11 16:57:20 UTC (rev 198022)
@@ -1394,7 +1394,7 @@
     self.identifier = [payload[@"id"] integerValue];
 
     THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"tree"], @"tree");
-    self.tree = payload[@"tree"];
+    self.tree = [[TestProtocolTestRecursiveObject1 alloc] initWithPayload:payload[@"tree"]];
 
     return self;
 }
@@ -1476,7 +1476,7 @@
     if (!(self = [super init]))
         return nil;
 
-    self.obj = payload[@"obj"];
+    self.obj = [[TestProtocolTestRecursiveObject2 alloc] initWithPayload:payload[@"obj"]];
 
     return self;
 }
@@ -1500,7 +1500,7 @@
     if (!(self = [super init]))
         return nil;
 
-    self.obj = payload[@"obj"];
+    self.obj = [[TestProtocolTestRecursiveObject1 alloc] initWithPayload:payload[@"obj"]];
 
     return self;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to