| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.js_emitter.full_emitter.nsm_emitter; | 5 library dart2js.js_emitter.full_emitter.nsm_emitter; |
| 6 | 6 |
| 7 import '../../elements/entities.dart'; | 7 import '../../elements/entities.dart'; |
| 8 import '../../js/js.dart' as jsAst; | 8 import '../../js/js.dart' as jsAst; |
| 9 import '../../js/js.dart' show js; | 9 import '../../js/js.dart' show js; |
| 10 import '../../js_backend/js_backend.dart' show GetterName, SetterName; | 10 import '../../js_backend/js_backend.dart' show GetterName, SetterName; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 // If we need fewer than this many noSuchMethod handlers we can save space by | 29 // If we need fewer than this many noSuchMethod handlers we can save space by |
| 30 // just emitting them in JS, rather than emitting the JS needed to generate | 30 // just emitting them in JS, rather than emitting the JS needed to generate |
| 31 // them at run time. | 31 // them at run time. |
| 32 static const VERY_FEW_NO_SUCH_METHOD_HANDLERS = 10; | 32 static const VERY_FEW_NO_SUCH_METHOD_HANDLERS = 10; |
| 33 | 33 |
| 34 static const MAX_MINIFIED_LENGTH_FOR_DIFF_ENCODING = 4; | 34 static const MAX_MINIFIED_LENGTH_FOR_DIFF_ENCODING = 4; |
| 35 | 35 |
| 36 void emitNoSuchMethodHandlers(AddPropertyFunction addProperty) { | 36 void emitNoSuchMethodHandlers(AddPropertyFunction addProperty) { |
| 37 ClassStubGenerator generator = new ClassStubGenerator(task.emitter, | 37 ClassStubGenerator generator = new ClassStubGenerator(task.emitter, |
| 38 compiler.commonElements, namer, codegenWorldBuilder, closedWorld, | 38 closedWorld.commonElements, namer, codegenWorldBuilder, closedWorld, |
| 39 enableMinification: compiler.options.enableMinification); | 39 enableMinification: compiler.options.enableMinification); |
| 40 | 40 |
| 41 // Keep track of the JavaScript names we've already added so we | 41 // Keep track of the JavaScript names we've already added so we |
| 42 // do not introduce duplicates (bad for code size). | 42 // do not introduce duplicates (bad for code size). |
| 43 Map<jsAst.Name, Selector> addedJsNames = | 43 Map<jsAst.Name, Selector> addedJsNames = |
| 44 generator.computeSelectorsForNsmHandlers(); | 44 generator.computeSelectorsForNsmHandlers(); |
| 45 | 45 |
| 46 // Set flag used by generateMethod helper below. If we have very few | 46 // Set flag used by generateMethod helper below. If we have very few |
| 47 // handlers we use addProperty for them all, rather than try to generate | 47 // handlers we use addProperty for them all, rather than try to generate |
| 48 // them at runtime. | 48 // them at runtime. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 js.stringPart(",")), | 167 js.stringPart(",")), |
| 168 addQuotes: true); | 168 addQuotes: true); |
| 169 | 169 |
| 170 if (!minify) { | 170 if (!minify) { |
| 171 sortedLongs = | 171 sortedLongs = |
| 172 sorted.map((selector) => selector.invocationMirrorMemberName); | 172 sorted.map((selector) => selector.invocationMirrorMemberName); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 // Startup code that loops over the method names and puts handlers on the | 175 // Startup code that loops over the method names and puts handlers on the |
| 176 // Object class to catch noSuchMethod invocations. | 176 // Object class to catch noSuchMethod invocations. |
| 177 ClassEntity objectClass = compiler.commonElements.objectClass; | 177 ClassEntity objectClass = closedWorld.commonElements.objectClass; |
| 178 jsAst.Expression createInvocationMirror = backend.emitter | 178 jsAst.Expression createInvocationMirror = backend.emitter |
| 179 .staticFunctionAccess(compiler.commonElements.createInvocationMirror); | 179 .staticFunctionAccess( |
| 180 closedWorld.commonElements.createInvocationMirror); |
| 180 if (useDiffEncoding) { | 181 if (useDiffEncoding) { |
| 181 statements.add(js.statement( | 182 statements.add(js.statement( |
| 182 '''{ | 183 '''{ |
| 183 var objectClassObject = processedClasses.collected[#objectClass], | 184 var objectClassObject = processedClasses.collected[#objectClass], |
| 184 nameSequences = #diffEncoding.split("."), | 185 nameSequences = #diffEncoding.split("."), |
| 185 shortNames = []; | 186 shortNames = []; |
| 186 if (objectClassObject instanceof Array) | 187 if (objectClassObject instanceof Array) |
| 187 objectClassObject = objectClassObject[1]; | 188 objectClassObject = objectClassObject[1]; |
| 188 for (var j = 0; j < nameSequences.length; ++j) { | 189 for (var j = 0; j < nameSequences.length; ++j) { |
| 189 var sequence = nameSequences[j].split(","), | 190 var sequence = nameSequences[j].split(","), |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 404 } |
| 404 | 405 |
| 405 String get value { | 406 String get value { |
| 406 if (_cachedValue == null) { | 407 if (_cachedValue == null) { |
| 407 _cachedValue = _computeDiffEncoding(); | 408 _cachedValue = _computeDiffEncoding(); |
| 408 } | 409 } |
| 409 | 410 |
| 410 return _cachedValue; | 411 return _cachedValue; |
| 411 } | 412 } |
| 412 } | 413 } |
| OLD | NEW |