mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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
|
||||
|
||||
@@ -144,6 +144,10 @@ static NSMutableArray *gPathWatchers;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)watchedPaths {
|
||||
return [_callbacksByPath allKeys];
|
||||
}
|
||||
|
||||
- (bool)createKeventForPath:(NSString *)path {
|
||||
path = [path stringByStandardizingPath];
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user