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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 class NativeEmitter { | 7 class NativeEmitter { |
8 | 8 |
9 CodeEmitterTask emitter; | 9 CodeEmitterTask emitter; |
10 CodeBuffer nativeBuffer; | 10 CodeBuffer nativeBuffer; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 String name = backend.namer.operatorIs(element); | 489 String name = backend.namer.operatorIs(element); |
490 addProperty(name, | 490 addProperty(name, |
491 js.fun([], js.return_(js('false')))); | 491 js.fun([], js.return_(js('false')))); |
492 // Add a function for the (trivial) substitution. | 492 // Add a function for the (trivial) substitution. |
493 addProperty(backend.namer.substitutionName(element), | 493 addProperty(backend.namer.substitutionName(element), |
494 js.fun([], js.return_(js('null')))); | 494 js.fun([], js.return_(js('null')))); |
495 } | 495 } |
496 } | 496 } |
497 emitIsChecks(); | 497 emitIsChecks(); |
498 | 498 |
499 jsAst.Expression makeCallOnThis(String functionName) { | |
500 // Because we know the function is intercepted, we need an extra | |
501 // parameter. | |
502 return js.fun(['_'], js.return_(js('$functionName(this)'))); | |
503 } | |
504 | |
505 if (!nativeClasses.isEmpty) { | 499 if (!nativeClasses.isEmpty) { |
506 emitDynamicDispatchMetadata(); | 500 emitDynamicDispatchMetadata(); |
507 | 501 |
508 // In order to have the toString method on every native class, | |
509 // we must patch the JS Object prototype with a helper method. | |
510 String toStringName = backend.namer.publicInstanceMethodNameByArity( | |
511 const SourceString('toString'), 0); | |
512 addProperty(toStringName, makeCallOnThis(toStringHelperName)); | |
513 | |
514 // Same as above, but for hashCode. | |
515 String hashCodeName = | |
516 backend.namer.publicGetterName(const SourceString('hashCode')); | |
517 addProperty(hashCodeName, makeCallOnThis(hashCodeHelperName)); | |
518 | |
519 // Same as above, but for operator==. | |
520 String equalsName = backend.namer.publicInstanceMethodNameByArity( | |
521 const SourceString('=='), 1); | |
522 // Because we know the function is intercepted, we need an extra | |
523 // parameter. | |
524 addProperty(equalsName, js.fun(['_', 'a'], | |
525 js.return_(js('this === a')))); | |
526 | |
527 // If the native emitter has been asked to take care of the | 502 // If the native emitter has been asked to take care of the |
528 // noSuchMethod handlers, we do that now. | 503 // noSuchMethod handlers, we do that now. |
529 if (handleNoSuchMethod) { | 504 if (handleNoSuchMethod) { |
530 emitter.emitNoSuchMethodHandlers(addProperty); | 505 emitter.emitNoSuchMethodHandlers(addProperty); |
531 } | 506 } |
532 } | 507 } |
533 | 508 |
534 // If we have any properties to add to Object.prototype, we run | 509 // If we have any properties to add to Object.prototype, we run |
535 // through them and add them using defineProperty. | 510 // through them and add them using defineProperty. |
536 if (!objectProperties.isEmpty) { | 511 if (!objectProperties.isEmpty) { |
(...skipping 12 matching lines...) Expand all Loading... |
549 if (emitter.compiler.enableMinification) targetBuffer.add(';'); | 524 if (emitter.compiler.enableMinification) targetBuffer.add(';'); |
550 targetBuffer.add(jsAst.prettyPrint( | 525 targetBuffer.add(jsAst.prettyPrint( |
551 new jsAst.ExpressionStatement(init), compiler)); | 526 new jsAst.ExpressionStatement(init), compiler)); |
552 targetBuffer.add('\n'); | 527 targetBuffer.add('\n'); |
553 } | 528 } |
554 | 529 |
555 targetBuffer.add(nativeBuffer); | 530 targetBuffer.add(nativeBuffer); |
556 targetBuffer.add('\n'); | 531 targetBuffer.add('\n'); |
557 } | 532 } |
558 } | 533 } |
OLD | NEW |