<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[199834] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/199834">199834</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2016-04-21 14:00:02 -0700 (Thu, 21 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebScriptObject description swizzler should work in a multi-threaded world
https://bugs.webkit.org/show_bug.cgi?id=156808

Source/WebCore:

Reviewed by Geoffrey Garen.

A WebKit legacy API user might be running Objective-C code on another thread.
Since we don't want to corrupt other thread's NSObject description method
we use TLS to record if we are in the stringValue function. As an attempt to
preserve any user swizzling we update the non-stringValue NSObject description
method on each call to stringValue if it has changed. Additionally, the TLS
needs to be a int because the user might call into stringValue, back into JS,
then back into stringValue. If the TLS was a boolean then it would be unset
at that point so when we return into the first stringValue call we would call
the original NSObject description method rather than our override.

Test added to API tests: WebKit1.WebScriptObjectDescription

* bridge/objc/objc_instance.mm:
(-[NSObject _web_description]):
(ObjcInstance::stringValue):
(swizzleNSObjectDescription): Deleted.

Tools:

Add a test for our NSObject swizzling TLS implementation. The test runs on
two threads. One in JS and another in Objective-C. We expect the JS thread
to use our NSObject description override and the Objective-C thread to act
as though it was using the original NSObject description method.

Reviewed by Geoffrey Garen.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/WebScriptObjectDescription.html: Added.
* TestWebKitAPI/Tests/mac/WebScriptObjectDescription.mm: Added.
(nsObjectDescriptionTest):
(-[WebScriptDescriptionTest webView:didFinishLoadForFrame:]):
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebridgeobjcobjc_instancemm">trunk/Source/WebCore/bridge/objc/objc_instance.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsmacWebScriptObjectDescriptionhtml">trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.html</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsmacWebScriptObjectDescriptionmm">trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (199833 => 199834)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-04-21 20:23:28 UTC (rev 199833)
+++ trunk/Source/WebCore/ChangeLog        2016-04-21 21:00:02 UTC (rev 199834)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-04-21  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        WebScriptObject description swizzler should work in a multi-threaded world
+        https://bugs.webkit.org/show_bug.cgi?id=156808
+
+        Reviewed by Geoffrey Garen.
+
+        A WebKit legacy API user might be running Objective-C code on another thread.
+        Since we don't want to corrupt other thread's NSObject description method
+        we use TLS to record if we are in the stringValue function. As an attempt to
+        preserve any user swizzling we update the non-stringValue NSObject description
+        method on each call to stringValue if it has changed. Additionally, the TLS
+        needs to be a int because the user might call into stringValue, back into JS,
+        then back into stringValue. If the TLS was a boolean then it would be unset
+        at that point so when we return into the first stringValue call we would call
+        the original NSObject description method rather than our override.
+
+        Test added to API tests: WebKit1.WebScriptObjectDescription
+
+        * bridge/objc/objc_instance.mm:
+        (-[NSObject _web_description]):
+        (ObjcInstance::stringValue):
+        (swizzleNSObjectDescription): Deleted.
+
</ins><span class="cx"> 2016-04-21  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Build fix.
</span></span></pre></div>
<a id="trunkSourceWebCorebridgeobjcobjc_instancemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bridge/objc/objc_instance.mm (199833 => 199834)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bridge/objc/objc_instance.mm        2016-04-21 20:23:28 UTC (rev 199833)
+++ trunk/Source/WebCore/bridge/objc/objc_instance.mm        2016-04-21 21:00:02 UTC (rev 199834)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2004, 2008, 2009, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2004, 2008, 2009, 2013, 2016 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -37,7 +37,9 @@
</span><span class="cx"> #import &lt;runtime/ObjectPrototype.h&gt;
</span><span class="cx"> #import &lt;wtf/Assertions.h&gt;
</span><span class="cx"> #import &lt;wtf/HashMap.h&gt;
</span><ins>+#import &lt;wtf/MainThread.h&gt;
</ins><span class="cx"> #import &lt;wtf/NeverDestroyed.h&gt;
</span><ins>+#import &lt;wtf/ThreadSpecific.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #ifdef NDEBUG
</span><span class="cx"> #define OBJC_LOG(formatAndArgs...) ((void)0)
</span><span class="lines">@@ -459,17 +461,42 @@
</span><span class="cx">     return valueOf(exec);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static NSString* swizzleNSObjectDescription(id self, SEL)
</del><ins>+static WTF::ThreadSpecific&lt;uint32_t&gt;* s_descriptionDepth;
+
+@interface NSObject (WebDescriptionCategory)
+- (NSString *)_web_description;
+@end
+
+@implementation NSObject (WebDescriptionCategory)
+
+- (NSString *)_web_description
</ins><span class="cx"> {
</span><del>-    return [NSString stringWithFormat:@&quot;%@%@%@&quot;, @&quot;&lt;&quot;, NSStringFromClass([self class]), @&quot;&gt;&quot;];
</del><ins>+    ASSERT(s_descriptionDepth);
+    if (s_descriptionDepth-&gt;isSet() &amp;&amp; **s_descriptionDepth)
+        return [NSString stringWithFormat:@&quot;&lt;%@&gt;&quot;, NSStringFromClass([self class])];
+    // We call _web_description here since this method should only be called
+    // once we have already swizzled this method with the one on NSObject.
+    // Thus, _web_description is actually the original description method.
+    return [self _web_description];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+@end
+
</ins><span class="cx"> JSC::JSValue ObjcInstance::stringValue(ExecState* exec) const
</span><span class="cx"> {
</span><del>-    auto method = class_getInstanceMethod([NSObject class], @selector(description));
-    IMP originalNSObjectDescription = method_setImplementation(method, (IMP)swizzleNSObjectDescription);
</del><ins>+    static std::once_flag initializeDescriptionDepthOnceFlag;
+    std::call_once(initializeDescriptionDepthOnceFlag, [] {
+        s_descriptionDepth = new WTF::ThreadSpecific&lt;uint32_t&gt;();
+        **s_descriptionDepth = 0;
+
+        auto descriptionMethod = class_getInstanceMethod([NSObject class], @selector(description));
+        auto webDescriptionMethod = class_getInstanceMethod([NSObject class], @selector(_web_description));
+        method_exchangeImplementations(descriptionMethod, webDescriptionMethod);
+    });
+
+    (**s_descriptionDepth)++;
</ins><span class="cx">     JSC::JSValue result = convertNSStringToString(exec, [getObject() description]);
</span><del>-    method_setImplementation(method, originalNSObjectDescription);
</del><ins>+    (**s_descriptionDepth)--;
</ins><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (199833 => 199834)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-04-21 20:23:28 UTC (rev 199833)
+++ trunk/Tools/ChangeLog        2016-04-21 21:00:02 UTC (rev 199834)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-04-21  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        WebScriptObject description swizzler should work in a multi-threaded world
+        https://bugs.webkit.org/show_bug.cgi?id=156808
+
+        Add a test for our NSObject swizzling TLS implementation. The test runs on
+        two threads. One in JS and another in Objective-C. We expect the JS thread
+        to use our NSObject description override and the Objective-C thread to act
+        as though it was using the original NSObject description method.
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/WebScriptObjectDescription.html: Added.
+        * TestWebKitAPI/Tests/mac/WebScriptObjectDescription.mm: Added.
+        (nsObjectDescriptionTest):
+        (-[WebScriptDescriptionTest webView:didFinishLoadForFrame:]):
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2016-04-21  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] WebKitWebView should claim the contents size as its natural size
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (199833 => 199834)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-04-21 20:23:28 UTC (rev 199833)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-04-21 21:00:02 UTC (rev 199834)
</span><span class="lines">@@ -88,6 +88,8 @@
</span><span class="cx">                 52B8CF9815868D9100281053 /* SetDocumentURI.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 52B8CF9415868CF000281053 /* SetDocumentURI.html */; };
</span><span class="cx">                 52D673EE1AFB127300FA19FE /* WKPageCopySessionStateWithFiltering.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52D673EC1AFB126800FA19FE /* WKPageCopySessionStateWithFiltering.cpp */; };
</span><span class="cx">                 52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */; };
</span><ins>+                536770341CC8022800D425B1 /* WebScriptObjectDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = 536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */; };
+                536770361CC81B6100D425B1 /* WebScriptObjectDescription.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 536770351CC812F900D425B1 /* WebScriptObjectDescription.html */; };
</ins><span class="cx">                 5714ECB91CA8B5B000051AC8 /* DownloadRequestOriginalURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */; };
</span><span class="cx">                 5714ECBB1CA8BFE400051AC8 /* DownloadRequestOriginalURLFrame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */; };
</span><span class="cx">                 5714ECBD1CA8C22A00051AC8 /* DownloadRequestOriginalURL2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECBC1CA8C21800051AC8 /* DownloadRequestOriginalURL2.html */; };
</span><span class="lines">@@ -415,6 +417,7 @@
</span><span class="cx">                         dstPath = TestWebKitAPI.resources;
</span><span class="cx">                         dstSubfolderSpec = 7;
</span><span class="cx">                         files = (
</span><ins>+                                536770361CC81B6100D425B1 /* WebScriptObjectDescription.html in Copy Resources */,
</ins><span class="cx">                                 57901FB11CAF142D00ED64F9 /* LoadInvalidURLRequest.html in Copy Resources */,
</span><span class="cx">                                 5714ECBD1CA8C22A00051AC8 /* DownloadRequestOriginalURL2.html in Copy Resources */,
</span><span class="cx">                                 5714ECBB1CA8BFE400051AC8 /* DownloadRequestOriginalURLFrame.html in Copy Resources */,
</span><span class="lines">@@ -658,6 +661,8 @@
</span><span class="cx">                 52D673EC1AFB126800FA19FE /* WKPageCopySessionStateWithFiltering.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKPageCopySessionStateWithFiltering.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame_Bundle.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptObjectDescription.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
+                536770351CC812F900D425B1 /* WebScriptObjectDescription.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WebScriptObjectDescription.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURL.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURLFrame.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5714ECBC1CA8C21800051AC8 /* DownloadRequestOriginalURL2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURL2.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1502,6 +1507,7 @@
</span><span class="cx">                                 1A7BFC0A171A0BDB00BC5F64 /* WillSendSubmitEvent.mm */,
</span><span class="cx">                                 A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */,
</span><span class="cx">                                 764322D51B61CCA40024F801 /* WordBoundaryTypingAttributes.mm */,
</span><ins>+                                536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = mac;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -1535,6 +1541,7 @@
</span><span class="cx">                                 C540F783152E5A7800A40C8C /* verboseMarkup.html */,
</span><span class="cx">                                 CE14F1A2181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html */,
</span><span class="cx">                                 A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */,
</span><ins>+                                536770351CC812F900D425B1 /* WebScriptObjectDescription.html */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = Resources;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -1804,6 +1811,7 @@
</span><span class="cx">                                 7CCE7EE11A411A9A00447C4C /* GetBackingScaleFactor.mm in Sources */,
</span><span class="cx">                                 CDBFCC451A9FF45300A7B691 /* FullscreenZoomInitialFrame.mm in Sources */,
</span><span class="cx">                                 7CCE7EF91A411AE600447C4C /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */,
</span><ins>+                                536770341CC8022800D425B1 /* WebScriptObjectDescription.mm in Sources */,
</ins><span class="cx">                                 7CCE7EE21A411A9A00447C4C /* GetPIDAfterAbortedProcessLaunch.cpp in Sources */,
</span><span class="cx">                                 7CCE7F351A411B8E00447C4C /* HashMap.cpp in Sources */,
</span><span class="cx">                                 7CCE7F361A411B8E00447C4C /* HashSet.cpp in Sources */,
</span><span class="lines">@@ -1955,7 +1963,7 @@
</span><span class="cx">                         isa = PBXSourcesBuildPhase;
</span><span class="cx">                         buildActionMask = 2147483647;
</span><span class="cx">                         files = (
</span><del>-                                0766DD201A5AD5200023E3BB /* PendingAPIRequestURL.cpp in Sources */,
</del><ins>+                                0766DD201A5AD5200023E3BB /* PendingAPIRequestURL.cpp in Sources */,
</ins><span class="cx">                                 2D9A53AF1B31FA8D0074D5AA /* ShrinkToFit.mm in Sources */,
</span><span class="cx">                                 51B454EC1B4E236B0085EAA6 /* WebViewCloseInsideDidFinishLoadForFrame.mm in Sources */,
</span><span class="cx">                                 57901FAD1CAF12C200ED64F9 /* LoadInvalidURLRequest.mm in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsmacWebScriptObjectDescriptionhtml"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.html (0 => 199834)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.html                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.html        2016-04-21 21:00:02 UTC (rev 199834)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;body&gt;
+  &lt;script&gt;
+    function foo(base) {
+        for (let i = 0; i &lt; 100000; i++) {
+            if (base + &quot;&quot; !== &quot;&lt;NSObject&gt;&quot;)
+                return false;
+        }
+        return true;
+    }
+  &lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsmacWebScriptObjectDescriptionmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.mm (0 => 199834)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/WebScriptObjectDescription.mm        2016-04-21 21:00:02 UTC (rev 199834)
</span><span class="lines">@@ -0,0 +1,86 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include &quot;config.h&quot;
+
+#import &quot;PlatformUtilities.h&quot;
+#import &quot;PlatformWebView.h&quot;
+#import &lt;atomic&gt;
+#import &lt;thread&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+@interface WebScriptDescriptionTest : NSObject &lt;WebFrameLoadDelegate&gt;
+@end
+
+static bool didFinishLoad;
+static bool failedObjCDescription { false };
+
+void nsObjectDescriptionTest(NSObject *object)
+{
+    NSError *error = nullptr;
+    NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@&quot;&lt;NSObject: 0x[0-9|a-f]+&gt;&quot; options:0 error:&amp;error];
+    for (unsigned i = 0; i &lt; 100000; ++i) {
+        NSString *description = [object description];
+        if ([regexp numberOfMatchesInString:description options:0 range:NSMakeRange(0, [description length])] != 1)
+            failedObjCDescription = true;
+    }
+}
+
+@implementation WebScriptDescriptionTest
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKit1, WebScriptObjectDescription)
+{
+    RetainPtr&lt;WebView&gt; webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+    RetainPtr&lt;WebScriptDescriptionTest&gt; testController = adoptNS([WebScriptDescriptionTest new]);
+    NSObject *object = [[NSObject alloc] init];
+
+    webView.get().frameLoadDelegate = testController.get();
+    [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle]
+        URLForResource:@&quot;WebScriptObjectDescription&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]]];
+
+    Util::run(&amp;didFinishLoad);
+    didFinishLoad = false;
+    failedObjCDescription = false;
+
+    std::thread thread1(nsObjectDescriptionTest, object);
+
+    CFBooleanRef result = (CFBooleanRef)([[webView.get() windowScriptObject] callWebScriptMethod:@&quot;foo&quot; withArguments:@[ object ]]);
+    EXPECT_EQ(CFBooleanGetValue(result), true);
+
+    thread1.join();
+    EXPECT_EQ(failedObjCDescription, false);
+    [object release];
+}
+
+} // namespace TestWebKitAPI
+
</ins></span></pre>
</div>
</div>

</body>
</html>