Title: [199742] trunk
Revision
199742
Author
keith_mil...@apple.com
Date
2016-04-19 14:02:15 -0700 (Tue, 19 Apr 2016)

Log Message

ObjcInstance::stringValue should not call NSObject's description method
https://bugs.webkit.org/show_bug.cgi?id=156758

Reviewed by Geoffrey Garen.

Source/WebCore:

This patch makes it so that we no longer call NSObject's description method without first
swizzling the implementation for WebScriptObjects. We restore the incomming NSObject's
description method once we have finished generating the string.

Test: platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html

* bridge/objc/objc_instance.mm:
(swizzleNSObjectDescription):
(ObjcInstance::stringValue):

Tools:

Add new methods to ObjCController that expose two Types of WebScriptObjects. The first is
an NSObject and the second is an NSArray of NSObjects. These are used to test that we don't
call the NSObjects description method without first swizzling it.

* DumpRenderTree/mac/ObjCController.m:
(+[ObjCController isSelectorExcludedFromWebScript:]):
(+[ObjCController webScriptNameForSelector:]):
(-[ObjCController testArrayOfObjects]):
(-[ObjCController testObject]):

LayoutTests:

Test that we don't use the NSObject's description method when stringifying a WebScriptObject.

* platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject-expected.txt: Added.
* platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html: Added.
* platform/wk2/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (199741 => 199742)


--- trunk/LayoutTests/ChangeLog	2016-04-19 20:25:36 UTC (rev 199741)
+++ trunk/LayoutTests/ChangeLog	2016-04-19 21:02:15 UTC (rev 199742)
@@ -1,3 +1,16 @@
+2016-04-19  Keith Miller  <keith_mil...@apple.com>
+
+        ObjcInstance::stringValue should not call NSObject's description method
+        https://bugs.webkit.org/show_bug.cgi?id=156758
+
+        Reviewed by Geoffrey Garen.
+
+        Test that we don't use the NSObject's description method when stringifying a WebScriptObject.
+
+        * platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject-expected.txt: Added.
+        * platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html: Added.
+        * platform/wk2/TestExpectations:
+
 2016-04-19  Alex Christensen  <achristen...@webkit.org>
 
         Update ANGLE

Added: trunk/LayoutTests/platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject-expected.txt (0 => 199742)


--- trunk/LayoutTests/platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject-expected.txt	2016-04-19 21:02:15 UTC (rev 199742)
@@ -0,0 +1,4 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html (0 => 199742)


--- trunk/LayoutTests/platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html	2016-04-19 21:02:15 UTC (rev 199742)
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+var obj = objCController.testObject();
+if (/: 0x[0-9|a-f]*/.test(obj + ""))
+    throw "bad";
+
+var array = objCController.testArrayOfObjects();
+if (/: 0x[0-9|a-f]*/.test(obj + ""))
+    throw "bad";
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/platform/wk2/TestExpectations (199741 => 199742)


--- trunk/LayoutTests/platform/wk2/TestExpectations	2016-04-19 20:25:36 UTC (rev 199741)
+++ trunk/LayoutTests/platform/wk2/TestExpectations	2016-04-19 21:02:15 UTC (rev 199742)
@@ -597,6 +597,7 @@
 platform/mac/fast/objc/dom-html-select-live-pseudo-selectors.html
 platform/mac/fast/objc/longlongTest.html
 platform/mac/fast/objc/webScriptObject-hasWebScriptKey.html
+platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html
 platform/mac/plugins/bindings-array-apply-crash.html
 platform/mac/plugins/bindings-objc-long-method-name.html
 platform/mac/plugins/bindings-objc-method-name-conversion.html

Modified: trunk/Source/WebCore/ChangeLog (199741 => 199742)


--- trunk/Source/WebCore/ChangeLog	2016-04-19 20:25:36 UTC (rev 199741)
+++ trunk/Source/WebCore/ChangeLog	2016-04-19 21:02:15 UTC (rev 199742)
@@ -1,3 +1,20 @@
+2016-04-19  Keith Miller  <keith_mil...@apple.com>
+
+        ObjcInstance::stringValue should not call NSObject's description method
+        https://bugs.webkit.org/show_bug.cgi?id=156758
+
+        Reviewed by Geoffrey Garen.
+
+        This patch makes it so that we no longer call NSObject's description method without first
+        swizzling the implementation for WebScriptObjects. We restore the incomming NSObject's
+        description method once we have finished generating the string.
+
+        Test: platform/mac/fast/objc/webScriptObject-does-not-call-description-on-nsobject.html
+
+        * bridge/objc/objc_instance.mm:
+        (swizzleNSObjectDescription):
+        (ObjcInstance::stringValue):
+
 2016-04-19  Alex Christensen  <achristen...@webkit.org>
 
         Update ANGLE

Modified: trunk/Source/WebCore/bridge/objc/objc_instance.mm (199741 => 199742)


--- trunk/Source/WebCore/bridge/objc/objc_instance.mm	2016-04-19 20:25:36 UTC (rev 199741)
+++ trunk/Source/WebCore/bridge/objc/objc_instance.mm	2016-04-19 21:02:15 UTC (rev 199742)
@@ -459,9 +459,18 @@
     return valueOf(exec);
 }
 
+static NSString* swizzleNSObjectDescription(id self, SEL)
+{
+    return [NSString stringWithFormat:@"%@%@%@", @"<", NSStringFromClass([self class]), @">"];
+}
+
 JSC::JSValue ObjcInstance::stringValue(ExecState* exec) const
 {
-    return convertNSStringToString(exec, [getObject() description]);
+    auto method = class_getInstanceMethod([NSObject class], @selector(description));
+    IMP originalNSObjectDescription = method_setImplementation(method, (IMP)swizzleNSObjectDescription);
+    JSC::JSValue result = convertNSStringToString(exec, [getObject() description]);
+    method_setImplementation(method, originalNSObjectDescription);
+    return result;
 }
 
 JSC::JSValue ObjcInstance::numberValue(ExecState*) const

Modified: trunk/Tools/ChangeLog (199741 => 199742)


--- trunk/Tools/ChangeLog	2016-04-19 20:25:36 UTC (rev 199741)
+++ trunk/Tools/ChangeLog	2016-04-19 21:02:15 UTC (rev 199742)
@@ -1,3 +1,20 @@
+2016-04-19  Keith Miller  <keith_mil...@apple.com>
+
+        ObjcInstance::stringValue should not call NSObject's description method
+        https://bugs.webkit.org/show_bug.cgi?id=156758
+
+        Reviewed by Geoffrey Garen.
+
+        Add new methods to ObjCController that expose two Types of WebScriptObjects. The first is
+        an NSObject and the second is an NSArray of NSObjects. These are used to test that we don't
+        call the NSObjects description method without first swizzling it.
+
+        * DumpRenderTree/mac/ObjCController.m:
+        (+[ObjCController isSelectorExcludedFromWebScript:]):
+        (+[ObjCController webScriptNameForSelector:]):
+        (-[ObjCController testArrayOfObjects]):
+        (-[ObjCController testObject]):
+
 2016-04-18  Dan Bernstein  <m...@apple.com>
 
         Fixed building with old Xcode.

Modified: trunk/Tools/DumpRenderTree/mac/ObjCController.m (199741 => 199742)


--- trunk/Tools/DumpRenderTree/mac/ObjCController.m	2016-04-19 20:25:36 UTC (rev 199741)
+++ trunk/Tools/DumpRenderTree/mac/ObjCController.m	2016-04-19 21:02:15 UTC (rev 199742)
@@ -78,6 +78,8 @@
             || aSelector == @selector(testValueForKey)
             || aSelector == @selector(testHasWebScriptKey:)
             || aSelector == @selector(testArray)
+            || aSelector == @selector(testArrayOfObjects)
+            || aSelector == @selector(testObject)
             || aSelector == @selector(setSelectElement:selectedIndex:allowingMultiple:)
         )
         return NO;
@@ -110,6 +112,10 @@
         return @"testHasWebScriptKey";
     if (aSelector == @selector(testArray))
         return @"testArray";
+    if (aSelector == @selector(testArrayOfObjects))
+        return @"testArrayOfObjects";
+    if (aSelector == @selector(testObject))
+        return @"testObject";
     if (aSelector == @selector(setSelectElement:selectedIndex:allowingMultiple:))
         return @"setSelectElementSelectedIndexAllowingMultiple";
 
@@ -269,6 +275,16 @@
     return [NSArray array];
 }
 
+- (NSArray *)testArrayOfObjects
+{
+    return @[ [[[NSObject alloc] init] autorelease], [[[NSObject alloc] init] autorelease], [[[NSObject alloc] init] autorelease]];
+}
+
+- (NSObject *)testObject
+{
+    return [[[NSObject alloc] init] autorelease];
+}
+
 - (void)dealloc
 {
     [storedWebScriptObject release];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to