| 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 class NativeEmitter { | 5 class NativeEmitter { |
| 6 | 6 |
| 7 Compiler compiler; | 7 Compiler compiler; |
| 8 StringBuffer buffer; | 8 StringBuffer buffer; |
| 9 | 9 |
| 10 // Classes that participate in dynamic dispatch. These are the | 10 // Classes that participate in dynamic dispatch. These are the |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 void emitIsChecks(StringBuffer buffer) { | 325 void emitIsChecks(StringBuffer buffer) { |
| 326 for (Element type in compiler.universe.isChecks) { | 326 for (Element type in compiler.universe.isChecks) { |
| 327 if (!requiresNativeIsCheck(type)) continue; | 327 if (!requiresNativeIsCheck(type)) continue; |
| 328 String name = compiler.namer.operatorIs(type); | 328 String name = compiler.namer.operatorIs(type); |
| 329 buffer.add("$defPropName(Object.prototype, '$name', "); | 329 buffer.add("$defPropName(Object.prototype, '$name', "); |
| 330 buffer.add('function() { return false; });\n'); | 330 buffer.add('function() { return false; });\n'); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 void assembleCode(StringBuffer other) { | 334 void assembleCode(StringBuffer targetBuffer) { |
| 335 if (nativeClasses.isEmpty()) return; | 335 if (nativeClasses.isEmpty()) return; |
| 336 | 336 |
| 337 // Because of native classes, we have to generate some is checks | 337 // Because of native classes, we have to generate some is checks |
| 338 // by calling a method, instead of accessing a property. So we | 338 // by calling a method, instead of accessing a property. So we |
| 339 // attach to the JS Object prototype these methods that return | 339 // attach to the JS Object prototype these methods that return |
| 340 // false, and will be overridden by subclasses when they have to | 340 // false, and will be overridden by subclasses when they have to |
| 341 // return true. | 341 // return true. |
| 342 StringBuffer objectProperties = new StringBuffer(); | 342 StringBuffer objectProperties = new StringBuffer(); |
| 343 emitIsChecks(objectProperties); | 343 emitIsChecks(objectProperties); |
| 344 | 344 |
| 345 // In order to have the toString method on every native class, | 345 // In order to have the toString method on every native class, |
| 346 // we must patch the JS Object prototype with a helper method. | 346 // we must patch the JS Object prototype with a helper method. |
| 347 String toStringName = compiler.namer.instanceMethodName( | 347 String toStringName = compiler.namer.instanceMethodName( |
| 348 null, const SourceString('toString'), 0); | 348 null, const SourceString('toString'), 0); |
| 349 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); | 349 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); |
| 350 objectProperties.add( | 350 objectProperties.add( |
| 351 'function() { return $toStringHelperName(this); });\n'); | 351 'function() { return $toStringHelperName(this); });\n'); |
| 352 | 352 |
| 353 // Finally, emit the code in the main buffer. | 353 // Finally, emit the code in the main buffer. |
| 354 other.add('(function() {\n$objectProperties$buffer\n})();\n'); | 354 targetBuffer.add('(function() {\n$objectProperties$buffer\n})();\n'); |
| 355 } | 355 } |
| 356 } | 356 } |
| OLD | NEW |