forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial implementation of ReplayFileSystem (#28)
This implements all the plumbing for `ReplayFileSystem` except for the resurrectors for `FileSystemEntity`, `File`, `Directory`, and `Link`. Those will land in a follow-on PR. Part of flutter#11
- Loading branch information
Showing
18 changed files
with
880 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'common.dart'; | ||
import 'encoding.dart'; | ||
|
||
/// Error thrown during replay when there is no matching invocation in the | ||
/// recording. | ||
class NoMatchingInvocationError extends Error { | ||
/// The invocation that was unable to be replayed. | ||
final Invocation invocation; | ||
|
||
/// Creates a new `NoMatchingInvocationError` caused by the failure to replay | ||
/// the specified [invocation]. | ||
NoMatchingInvocationError(this.invocation); | ||
|
||
@override | ||
String toString() { | ||
StringBuffer buf = new StringBuffer(); | ||
buf.write('No matching invocation found: '); | ||
buf.write(getSymbolName(invocation.memberName)); | ||
if (invocation.isMethod) { | ||
buf.write('('); | ||
int i = 0; | ||
for (dynamic arg in invocation.positionalArguments) { | ||
buf.write(Error.safeToString(encode(arg))); | ||
if (i++ > 0) { | ||
buf.write(', '); | ||
} | ||
} | ||
invocation.namedArguments.forEach((Symbol name, dynamic value) { | ||
if (i++ > 0) { | ||
buf.write(', '); | ||
} | ||
buf.write('${getSymbolName(name)}: ${encode(value)}'); | ||
}); | ||
buf.write(')'); | ||
} else if (invocation.isSetter) { | ||
buf.write(Error.safeToString(encode(invocation.positionalArguments[0]))); | ||
} | ||
return buf.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// An object that uses [noSuchMethod] to dynamically handle invocations | ||
/// (property getters, property setters, and method invocations). | ||
abstract class ProxyObject {} | ||
|
||
/// A function reference that, when invoked, will forward the invocation back | ||
/// to a [ProxyObject]. | ||
/// | ||
/// This is used when a caller accesses a method on a [ProxyObject] via the | ||
/// method's getter. In these cases, the caller will receive a [MethodProxy] | ||
/// that allows delayed invocation of the method. | ||
class MethodProxy extends Object implements Function { | ||
/// The object on which the method was retrieved. | ||
/// | ||
/// This will be the target object when this method proxy is invoked. | ||
final ProxyObject _proxyObject; | ||
|
||
/// The name of the method in question. | ||
final Symbol _methodName; | ||
|
||
/// Creates a new [MethodProxy] that, when invoked, will invoke the method | ||
/// identified by [methodName] on the specified target [object]. | ||
MethodProxy(ProxyObject object, Symbol methodName) | ||
: _proxyObject = object, | ||
_methodName = methodName; | ||
|
||
@override | ||
dynamic noSuchMethod(Invocation invocation) { | ||
if (invocation.isMethod && invocation.memberName == #call) { | ||
// The method is being invoked. Capture the arguments, and invoke the | ||
// method on the proxy object. We have to synthesize an invocation, since | ||
// our current `invocation` object represents the invocation of `call()`. | ||
return _proxyObject.noSuchMethod(new _MethodInvocationProxy( | ||
_methodName, | ||
invocation.positionalArguments, | ||
invocation.namedArguments, | ||
)); | ||
} | ||
return super.noSuchMethod(invocation); | ||
} | ||
} | ||
|
||
class _MethodInvocationProxy extends Invocation { | ||
_MethodInvocationProxy( | ||
this.memberName, | ||
this.positionalArguments, | ||
this.namedArguments, | ||
); | ||
|
||
@override | ||
final Symbol memberName; | ||
|
||
@override | ||
final List<dynamic> positionalArguments; | ||
|
||
@override | ||
final Map<Symbol, dynamic> namedArguments; | ||
|
||
@override | ||
final bool isMethod = true; | ||
|
||
@override | ||
final bool isGetter = false; | ||
|
||
@override | ||
final bool isSetter = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:file/file.dart'; | ||
|
||
import 'replay_file_system.dart'; | ||
import 'replay_file_system_entity.dart'; | ||
import 'resurrectors.dart'; | ||
|
||
/// [Directory] implementation that replays all invocation activity from a | ||
/// prior recording. | ||
class ReplayDirectory extends ReplayFileSystemEntity implements Directory { | ||
/// Creates a new `ReplayDirectory`. | ||
ReplayDirectory(ReplayFileSystemImpl fileSystem, String identifier) | ||
: super(fileSystem, identifier) { | ||
// TODO(tvolkert): fill in resurrectors | ||
methods.addAll(<Symbol, Resurrector>{ | ||
#create: null, | ||
#createSync: null, | ||
#createTemp: null, | ||
#createTempSync: null, | ||
#list: null, | ||
#listSync: null, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:file/file.dart'; | ||
|
||
import 'replay_file_system.dart'; | ||
import 'replay_file_system_entity.dart'; | ||
import 'resurrectors.dart'; | ||
|
||
/// [File] implementation that replays all invocation activity from a prior | ||
/// recording. | ||
class ReplayFile extends ReplayFileSystemEntity implements File { | ||
/// Creates a new `ReplayFile`. | ||
ReplayFile(ReplayFileSystemImpl fileSystem, String identifier) | ||
: super(fileSystem, identifier) { | ||
// TODO(tvolkert): fill in resurrectors | ||
methods.addAll(<Symbol, Resurrector>{ | ||
#create: null, | ||
#createSync: null, | ||
#copy: null, | ||
#copySync: null, | ||
#length: null, | ||
#lengthSync: null, | ||
#lastModified: null, | ||
#lastModifiedSync: null, | ||
#open: null, | ||
#openSync: null, | ||
#openRead: null, | ||
#openWrite: null, | ||
#readAsBytes: null, | ||
#readAsBytesSync: null, | ||
#readAsString: null, | ||
#readAsStringSync: null, | ||
#readAsLines: null, | ||
#readAsLinesSync: null, | ||
#writeAsBytes: null, | ||
#writeAsBytesSync: null, | ||
#writeAsString: null, | ||
#writeAsStringSync: null, | ||
}); | ||
} | ||
} |
Oops, something went wrong.