OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:path/path.dart' as p; | 8 import 'package:path/path.dart' as p; |
9 | 9 |
10 import '../../util/exit_codes.dart' as exit_codes; | 10 import '../../util/exit_codes.dart' as exit_codes; |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 /// A class for running an instance of PhantomJS. | 34 /// A class for running an instance of PhantomJS. |
35 /// | 35 /// |
36 /// Any errors starting or running the process are reported through [onExit]. | 36 /// Any errors starting or running the process are reported through [onExit]. |
37 class PhantomJS extends Browser { | 37 class PhantomJS extends Browser { |
38 final name = "PhantomJS"; | 38 final name = "PhantomJS"; |
39 | 39 |
40 final Future<Uri> remoteDebuggerUrl; | 40 final Future<Uri> remoteDebuggerUrl; |
41 | 41 |
42 factory PhantomJS(url, {String executable, bool debug: false}) { | 42 factory PhantomJS(url, {String executable, bool debug: false}) { |
43 var remoteDebuggerCompleter = new Completer.sync(); | 43 var remoteDebuggerCompleter = new Completer<Uri>.sync(); |
44 return new PhantomJS._(() async { | 44 return new PhantomJS._(() async { |
45 if (executable == null) { | 45 if (executable == null) { |
46 executable = Platform.isWindows ? "phantomjs.exe" : "phantomjs"; | 46 executable = Platform.isWindows ? "phantomjs.exe" : "phantomjs"; |
47 } | 47 } |
48 | 48 |
49 var dir = createTempDir(); | 49 var dir = createTempDir(); |
50 var script = p.join(dir, "script.js"); | 50 var script = p.join(dir, "script.js"); |
51 new File(script).writeAsStringSync(_script); | 51 new File(script).writeAsStringSync(_script); |
52 | 52 |
53 var port = debug ? await getUnsafeUnusedPort() : null; | 53 var port = debug ? await getUnsafeUnusedPort() : null; |
54 | 54 |
55 var args = []; | 55 var args = <String>[]; |
56 if (debug) { | 56 if (debug) { |
57 args.addAll([ | 57 args.addAll([ |
58 "--remote-debugger-port=$port", | 58 "--remote-debugger-port=$port", |
59 "--remote-debugger-autorun=yes" | 59 "--remote-debugger-autorun=yes" |
60 ]); | 60 ]); |
61 } | 61 } |
62 args.addAll([script, url.toString()]); | 62 args.addAll([script, url.toString()]); |
63 var process = await Process.start(executable, args); | 63 var process = await Process.start(executable, args); |
64 | 64 |
65 // PhantomJS synchronously emits standard output, which means that if we | 65 // PhantomJS synchronously emits standard output, which means that if we |
(...skipping 16 matching lines...) Expand all Loading... |
82 remoteDebuggerCompleter.complete(null); | 82 remoteDebuggerCompleter.complete(null); |
83 } | 83 } |
84 | 84 |
85 return process; | 85 return process; |
86 }, remoteDebuggerCompleter.future); | 86 }, remoteDebuggerCompleter.future); |
87 } | 87 } |
88 | 88 |
89 PhantomJS._(Future<Process> startBrowser(), this.remoteDebuggerUrl) | 89 PhantomJS._(Future<Process> startBrowser(), this.remoteDebuggerUrl) |
90 : super(startBrowser); | 90 : super(startBrowser); |
91 } | 91 } |
OLD | NEW |