Ensure PathWatcher isn't watching anything at the end of each spec

This replaces the old functionality of ensuring no files or directories have subscriptions in javascript. We allow this now, but we just don't allow leaked watches at the native layer.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-11-28 17:16:15 -07:00
parent ac84a8ab0a
commit db78d6a7e5
5 changed files with 28 additions and 19 deletions

View File

@@ -19,5 +19,6 @@ typedef void (^WatchCallback)(NSString *, NSString *);
- (id)initWithContext:(CefRefPtr<CefV8Context>)context;
- (NSString *)watchPath:(NSString *)path callback:(WatchCallback)callback;
- (void)unwatchPath:(NSString *)path callbackId:(NSString *)callbackId error:(NSError **)error;
- (NSArray *)watchedPaths;
@end

View File

@@ -144,6 +144,10 @@ static NSMutableArray *gPathWatchers;
}
}
- (NSArray *)watchedPaths {
return [_callbacksByPath allKeys];
}
- (bool)createKeventForPath:(NSString *)path {
path = [path stringByStandardizingPath];

View File

@@ -43,6 +43,9 @@ var $native = {};
native function unwatchPath(path, callbackId);
$native.unwatchPath = unwatchPath;
native function getWatchedPaths();
$native.getWatchedPaths = getWatchedPaths;
native function makeDirectory(path);
$native.makeDirectory = makeDirectory;

View File

@@ -237,6 +237,21 @@ bool Native::Execute(const CefString& name,
return true;
}
else if (name == "getWatchedPaths") {
PathWatcher *pathWatcher = [PathWatcher pathWatcherForContext:CefV8Context::GetCurrentContext()];
NSArray *paths = [pathWatcher watchedPaths];
CefRefPtr<CefV8Value> pathsArray = CefV8Value::CreateArray([paths count]);
for (int i = 0; i < [paths count]; i++) {
CefRefPtr<CefV8Value> path = CefV8Value::CreateString([[paths objectAtIndex:i] UTF8String]);
pathsArray->SetValue(i, path);
}
retval = pathsArray;
return true;
}
else if (name == "makeDirectory") {
NSString *path = stringFromCefV8Value(arguments[0]);
NSFileManager *fm = [NSFileManager defaultManager];