OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/alloc_with_zone_interceptor.h" | 5 #import "ios/web/alloc_with_zone_interceptor.h" |
6 | 6 |
7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
11 namespace web { | 15 namespace web { |
12 | 16 |
13 void AddAllocWithZoneMethod(Class target, id (^impl_block)(Class, NSZone*)) { | 17 void AddAllocWithZoneMethod(Class target, id (^impl_block)(Class, NSZone*)) { |
14 // Make sure |allocWithZone:| is not already implemented in the target class. | 18 // Make sure |allocWithZone:| is not already implemented in the target class. |
15 Class meta_class = object_getClass(target); | 19 Class meta_class = object_getClass(target); |
16 DCHECK_EQ( | 20 DCHECK_EQ( |
17 class_getMethodImplementation(meta_class, @selector(allocWithZone:)), | 21 class_getMethodImplementation(meta_class, @selector(allocWithZone:)), |
18 class_getMethodImplementation(object_getClass([NSObject class]), | 22 class_getMethodImplementation(object_getClass([NSObject class]), |
19 @selector(allocWithZone:))); | 23 @selector(allocWithZone:))); |
20 | 24 |
21 IMP new_impl = imp_implementationWithBlock(^(id self, NSZone* zone) { | 25 IMP new_impl = imp_implementationWithBlock(^(id self, NSZone* zone) { |
22 return impl_block(self, zone); | 26 return impl_block(self, zone); |
23 }); | 27 }); |
24 class_addMethod(meta_class, @selector(allocWithZone:), new_impl, "v@:@"); | 28 class_addMethod(meta_class, @selector(allocWithZone:), new_impl, "v@:@"); |
25 } | 29 } |
26 | 30 |
27 } // namespace web | 31 } // namespace web |
OLD | NEW |