Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Side by Side Diff: lib/compiler/implementation/native_emitter.dart

Issue 9921010: Address review comments from: https://chromiumcodereview.appspot.com/9750003. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698