Index: ios/web/public/test/js_test_util.mm |
diff --git a/ios/web/public/test/js_test_util.mm b/ios/web/public/test/js_test_util.mm |
index 9ddf9a8a06a3716954bb6e99e6b239281b0b6532..4f9c75458fbaa3d61d2d9850edb7754e62b2f632 100644 |
--- a/ios/web/public/test/js_test_util.mm |
+++ b/ios/web/public/test/js_test_util.mm |
@@ -7,22 +7,25 @@ |
#import <WebKit/WebKit.h> |
#include "base/logging.h" |
-#import "base/mac/scoped_nsobject.h" |
#include "base/strings/sys_string_conversions.h" |
#import "ios/testing/wait_util.h" |
#import "ios/web/public/web_state/js/crw_js_injection_manager.h" |
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
+#error "This file requires ARC support." |
+#endif |
+ |
namespace web { |
id ExecuteJavaScript(CRWJSInjectionManager* manager, NSString* script) { |
- __block base::scoped_nsobject<NSString> result; |
+ __block NSString* result; |
__block bool completed = false; |
[manager executeJavaScript:script |
completionHandler:^(id execution_result, NSError* error) { |
DCHECK(!error); |
- result.reset([execution_result copy]); |
+ result = [execution_result copy]; |
completed = true; |
}]; |
@@ -35,12 +38,12 @@ id ExecuteJavaScript(CRWJSInjectionManager* manager, NSString* script) { |
<< "CRWJSInjectionManager failed to complete javascript execution.\n" |
<< base::SysNSStringToUTF8( |
[[NSThread callStackSymbols] componentsJoinedByString:@"\n"]); |
- return [[result retain] autorelease]; |
+ return result; |
} |
id ExecuteJavaScript(CRWJSInjectionReceiver* receiver, NSString* script) { |
- base::scoped_nsobject<CRWJSInjectionManager> manager( |
- [[CRWJSInjectionManager alloc] initWithReceiver:receiver]); |
+ CRWJSInjectionManager* manager = |
+ [[CRWJSInjectionManager alloc] initWithReceiver:receiver]; |
return ExecuteJavaScript(manager, script); |
} |
@@ -48,14 +51,16 @@ id ExecuteJavaScript(WKWebView* web_view, NSString* script) { |
return ExecuteJavaScript(web_view, script, nullptr); |
} |
-id ExecuteJavaScript(WKWebView* web_view, NSString* script, NSError** error) { |
- __block base::scoped_nsobject<id> result; |
+id ExecuteJavaScript(WKWebView* web_view, |
+ NSString* script, |
+ NSError* __unsafe_unretained* error) { |
+ __block id result; |
__block bool completed = false; |
+ __block NSError* temp_error = nil; |
[web_view evaluateJavaScript:script |
completionHandler:^(id script_result, NSError* script_error) { |
- result.reset([script_result copy]); |
- if (error) |
- *error = [[script_error copy] autorelease]; |
+ result = [script_result copy]; |
+ temp_error = [script_error copy]; |
completed = true; |
}]; |
BOOL success = testing::WaitUntilConditionOrTimeout( |
@@ -66,7 +71,11 @@ id ExecuteJavaScript(WKWebView* web_view, NSString* script, NSError** error) { |
EXPECT_TRUE(success) << "WKWebView failed to complete javascript execution.\n" |
<< base::SysNSStringToUTF8([[NSThread callStackSymbols] |
componentsJoinedByString:@"\n"]); |
- return [[result retain] autorelease]; |
+ if (error) { |
+ NSError* __autoreleasing auto_released_error = temp_error; |
+ *error = auto_released_error; |
+ } |
+ return result; |
} |
} // namespace web |