OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #import "ios/web/alloc_with_zone_interceptor.h" | |
6 | |
7 #import <objc/runtime.h> | |
8 | |
9 #include "base/logging.h" | |
10 | |
11 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
12 #error "This file requires ARC support." | |
13 #endif | |
14 | |
15 namespace web { | |
16 | |
17 void AddAllocWithZoneMethod(Class target, id (^impl_block)(Class, NSZone*)) { | |
18 // Make sure |allocWithZone:| is not already implemented in the target class. | |
19 Class meta_class = object_getClass(target); | |
20 DCHECK_EQ( | |
21 class_getMethodImplementation(meta_class, @selector(allocWithZone:)), | |
22 class_getMethodImplementation(object_getClass([NSObject class]), | |
23 @selector(allocWithZone:))); | |
24 | |
25 IMP new_impl = imp_implementationWithBlock(^(id self, NSZone* zone) { | |
26 return impl_block(self, zone); | |
27 }); | |
28 class_addMethod(meta_class, @selector(allocWithZone:), new_impl, "v@:@"); | |
29 } | |
30 | |
31 } // namespace web | |
OLD | NEW |