| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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("../../../lib/compiler/implementation/leg.dart"); | 5 #import("../../../lib/compiler/implementation/leg.dart"); |
| 6 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 6 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
| 7 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 7 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 8 #import("../../../lib/compiler/implementation/util/util.dart"); | 8 #import("../../../lib/compiler/implementation/util/util.dart"); |
| 9 #import("mock_compiler.dart"); | 9 #import("mock_compiler.dart"); |
| 10 #import("parser_helper.dart"); | 10 #import("parser_helper.dart"); |
| 11 #import("dart:uri"); | 11 #import("dart:uri"); |
| 12 | 12 |
| 13 Compiler applyPatch(String script, String patch) { | 13 Compiler applyPatch(String script, String patch) { |
| 14 String core = "$DEFAULT_CORELIB\n$script"; | 14 String core = "$DEFAULT_CORELIB\n$script"; |
| 15 MockCompiler compiler = new MockCompiler(coreSource: core); | 15 MockCompiler compiler = new MockCompiler(coreSource: core); |
| 16 var uri = new Uri("core.dartp"); | 16 var uri = new Uri("core.dartp"); |
| 17 compiler.sourceFiles[uri.toString()] = new MockFile(patch); | 17 compiler.sourceFiles[uri.toString()] = new MockFile(patch); |
| 18 compiler.patchParser.patchLibrary(uri, compiler.coreLibrary); | 18 compiler.patchParser.patchLibrary(uri, compiler.coreLibrary); |
| 19 compiler.applyClassPatches(compiler.coreLibrary); | |
| 20 return compiler; | 19 return compiler; |
| 21 } | 20 } |
| 22 | 21 |
| 23 Element ensure(compiler, | 22 Element ensure(compiler, |
| 24 String name, | 23 String name, |
| 25 Element lookup(name), | 24 Element lookup(name), |
| 26 [bool isPatched = true, | 25 [bool isPatched = true, |
| 27 bool hasBody = false, | 26 bool hasBody = false, |
| 28 bool isGetter = false]) { | 27 bool isGetter = false]) { |
| 29 var element = lookup(buildSourceString(name)); | 28 var element = lookup(buildSourceString(name)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 59 class Class { | 58 class Class { |
| 60 external String toString(); | 59 external String toString(); |
| 61 } | 60 } |
| 62 """, | 61 """, |
| 63 """ | 62 """ |
| 64 patch class Class { | 63 patch class Class { |
| 65 patch String toString() => 'string'; | 64 patch String toString() => 'string'; |
| 66 } | 65 } |
| 67 """); | 66 """); |
| 68 var container = ensure(compiler, "Class", compiler.coreLibrary.find); | 67 var container = ensure(compiler, "Class", compiler.coreLibrary.find); |
| 68 container.parseNode(compiler); |
| 69 ensure(compiler, "toString", container.lookupLocalMember, hasBody:true); | 69 ensure(compiler, "toString", container.lookupLocalMember, hasBody:true); |
| 70 } | 70 } |
| 71 | 71 |
| 72 testPatchGetter() { | 72 testPatchGetter() { |
| 73 var compiler = applyPatch( | 73 var compiler = applyPatch( |
| 74 """ | 74 """ |
| 75 class Class { | 75 class Class { |
| 76 external int get field(); | 76 external int get field(); |
| 77 } | 77 } |
| 78 """, | 78 """, |
| 79 """ | 79 """ |
| 80 patch class Class { | 80 patch class Class { |
| 81 patch int get field() => 5; | 81 patch int get field() => 5; |
| 82 } | 82 } |
| 83 """); | 83 """); |
| 84 var container = ensure(compiler, "Class", compiler.coreLibrary.find); | 84 var container = ensure(compiler, "Class", compiler.coreLibrary.find); |
| 85 container.parseNode(compiler); |
| 85 ensure(compiler, | 86 ensure(compiler, |
| 86 "field", | 87 "field", |
| 87 container.lookupLocalMember, | 88 container.lookupLocalMember, |
| 88 isGetter: true, | 89 isGetter: true, |
| 89 hasBody: true); | 90 hasBody: true); |
| 90 } | 91 } |
| 91 | 92 |
| 92 testInjectFunction() { | 93 testInjectFunction() { |
| 93 var compiler = applyPatch( | 94 var compiler = applyPatch( |
| 94 "", | 95 "", |
| 95 "int _function() => 5;"); | 96 "int _function() => 5;"); |
| 96 ensure(compiler, | 97 ensure(compiler, |
| 97 "_function", | 98 "_function", |
| 98 compiler.coreLibrary.find, | 99 compiler.coreLibrary.find, |
| 99 hasBody: true, | 100 hasBody: true, |
| 100 isPatched: false); | 101 isPatched: false); |
| 101 } | 102 } |
| 102 | 103 |
| 103 main() { | 104 main() { |
| 104 testPatchFunction(); | 105 testPatchFunction(); |
| 105 testPatchMember(); | 106 testPatchMember(); |
| 106 testPatchGetter(); | 107 testPatchGetter(); |
| 107 testInjectFunction(); | 108 testInjectFunction(); |
| 108 } | 109 } |
| OLD | NEW |