Diff
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (179159 => 179160)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-01-27 01:14:14 UTC (rev 179159)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-01-27 02:39:42 UTC (rev 179160)
@@ -577,26 +577,27 @@
if (!handler)
return;
- auto completionHandler = (void (^)(id, NSError *))handler.get();
-
if (errorCode != WebKit::ScriptValueCallback::Error::None) {
auto error = createNSError(callbackErrorCode(errorCode));
if (errorCode == WebKit::ScriptValueCallback::Error::OwnerWasInvalidated) {
// The OwnerWasInvalidated callback is synchronous. We don't want to call the block from within it
// because that can trigger re-entrancy bugs in WebKit.
// FIXME: It would be even better if GenericCallback did this for us.
- dispatch_async(dispatch_get_main_queue(), [completionHandler, error] {
- completionHandler(nil, error.get());
+ dispatch_async(dispatch_get_main_queue(), [handler, error] {
+ auto rawHandler = (void (^)(id, NSError *))handler.get();
+ rawHandler(nil, error.get());
});
return;
}
- completionHandler(nil, error.get());
+ auto rawHandler = (void (^)(id, NSError *))handler.get();
+ rawHandler(nil, error.get());
return;
}
+ auto rawHandler = (void (^)(id, NSError *))handler.get();
if (!serializedScriptValue) {
- completionHandler(nil, createNSError(WKErrorJavaScriptExceptionOccurred).get());
+ rawHandler(nil, createNSError(WKErrorJavaScriptExceptionOccurred).get());
return;
}
@@ -604,7 +605,7 @@
JSValueRef valueRef = serializedScriptValue->deserialize([context JSGlobalContextRef], 0);
JSValue *value = [JSValue valueWithJSValueRef:valueRef inContext:context.get()];
- completionHandler([value toObject], nil);
+ rawHandler([value toObject], nil);
});
}
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (179159 => 179160)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2015-01-27 01:14:14 UTC (rev 179159)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2015-01-27 02:39:42 UTC (rev 179160)
@@ -10,6 +10,7 @@
0F139E771A423A5B00F590F5 /* WeakObjCPtr.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */; };
0F139E781A423A6B00F590F5 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
0F139E791A42457000F590F5 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
+ 0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */; };
1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
1A50AA201A2A51FC00F4C345 /* close-from-within-create-page.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A50AA1F1A2A4EA500F4C345 /* close-from-within-create-page.html */; };
1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93D3D19B17B1A7B000C7C415 /* all-content-in-one-iframe.html */; };
@@ -386,6 +387,7 @@
0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PlatformUtilitiesCocoa.mm; path = cocoa/PlatformUtilitiesCocoa.mm; sourceTree = "<group>"; };
0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WeakObjCPtr.mm; path = cocoa/WeakObjCPtr.mm; sourceTree = "<group>"; };
0F17BBD415AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreStatisticsWithNoWebProcess.cpp; sourceTree = "<group>"; };
+ 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEvaluateJavaScript.mm; sourceTree = "<group>"; };
0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RedBlackTree.cpp; sourceTree = "<group>"; };
0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MetaAllocator.cpp; sourceTree = "<group>"; };
14464012167A8305000BD218 /* LayoutUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutUnit.cpp; sourceTree = "<group>"; };
@@ -790,6 +792,7 @@
CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */,
C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
+ 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
);
name = "WebKit2 Cocoa";
path = WebKit2Cocoa;
@@ -1356,6 +1359,7 @@
7CCE7EE81A411AE600447C4C /* CookieManager.cpp in Sources */,
7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */,
7CCE7EDB1A411A9200447C4C /* CSSParser.cpp in Sources */,
+ 0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */,
7CCE7F321A411B8E00447C4C /* CString.cpp in Sources */,
7CCE7F291A411B1000447C4C /* CustomProtocolsInvalidScheme.mm in Sources */,
7CCE7F2A1A411B1000447C4C /* CustomProtocolsSyncXHRTest.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm (0 => 179160)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm 2015-01-27 02:39:42 UTC (rev 179160)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2014 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 <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import <WebKit/WKWebView.h>
+#import <wtf/RetainPtr.h>
+
+static bool isDone;
+
+TEST(WKWebView, EvaluateJavaScriptBlockCrash)
+{
+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ [webView loadRequest:request];
+
+ [webView evaluateJavaScript:@"" completionHandler:^(id result, NSError *error) {
+ // NOTE: By referencing the request here, we convert the block into a stack block rather than a global block and thus allow the copying of the block
+ // in evaluateJavaScript to be meaningful.
+ (void)request;
+
+ EXPECT_NULL(result);
+ EXPECT_NOT_NULL(error);
+
+ isDone = true;
+ }];
+
+ // Force the WKWebView to be destroyed to allow evaluateJavaScript's completion handler to be called with an error.
+ webView = nullptr;
+
+ isDone = false;
+ TestWebKitAPI::Util::run(&isDone);
+}
+
+#endif