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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart

Issue 12330135: Make instance methods whose names collide with intercepted methods have the interceptor calling con… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 if (!requiresNativeIsCheck(element)) continue; 477 if (!requiresNativeIsCheck(element)) continue;
478 if (element.isObject(compiler)) continue; 478 if (element.isObject(compiler)) continue;
479 String name = backend.namer.operatorIs(element); 479 String name = backend.namer.operatorIs(element);
480 addProperty(name, 480 addProperty(name,
481 js.fun([], js.return_(js['false']))); 481 js.fun([], js.return_(js['false'])));
482 } 482 }
483 } 483 }
484 emitIsChecks(); 484 emitIsChecks();
485 485
486 jsAst.Expression makeCallOnThis(String functionName) { 486 jsAst.Expression makeCallOnThis(String functionName) {
487 return js.fun([], js.return_(js['$functionName(this)'])); 487 // Because we know the function is intercepted, we need an extra
488 // parameter.
489 return js.fun(['_'], js.return_(js['$functionName(this)']));
488 } 490 }
489 491
490 // In order to have the toString method on every native class, 492 // In order to have the toString method on every native class,
491 // we must patch the JS Object prototype with a helper method. 493 // we must patch the JS Object prototype with a helper method.
492 String toStringName = backend.namer.publicInstanceMethodNameByArity( 494 String toStringName = backend.namer.publicInstanceMethodNameByArity(
493 const SourceString('toString'), 0); 495 const SourceString('toString'), 0);
494 addProperty(toStringName, makeCallOnThis(toStringHelperName)); 496 addProperty(toStringName, makeCallOnThis(toStringHelperName));
495 497
496 // Same as above, but for hashCode. 498 // Same as above, but for hashCode.
497 String hashCodeName = 499 String hashCodeName =
498 backend.namer.publicGetterName(const SourceString('hashCode')); 500 backend.namer.publicGetterName(const SourceString('hashCode'));
499 addProperty(hashCodeName, makeCallOnThis(hashCodeHelperName)); 501 addProperty(hashCodeName, makeCallOnThis(hashCodeHelperName));
500 502
501 // Same as above, but for operator==. 503 // Same as above, but for operator==.
502 String equalsName = backend.namer.publicInstanceMethodNameByArity( 504 String equalsName = backend.namer.publicInstanceMethodNameByArity(
503 const SourceString('=='), 1); 505 const SourceString('=='), 1);
504 addProperty(equalsName, js.fun(['a'], 506 // Because we know the function is intercepted, we need an extra
507 // parameter.
508 addProperty(equalsName, js.fun(['_', 'a'],
505 js.return_(js['this === a']))); 509 js.return_(js['this === a'])));
506 510
507 // If the native emitter has been asked to take care of the 511 // If the native emitter has been asked to take care of the
508 // noSuchMethod handlers, we do that now. 512 // noSuchMethod handlers, we do that now.
509 if (handleNoSuchMethod) { 513 if (handleNoSuchMethod) {
510 emitter.emitNoSuchMethodHandlers(addProperty); 514 emitter.emitNoSuchMethodHandlers(addProperty);
511 } 515 }
512 516
513 // If we have any properties to add to Object.prototype, we run 517 // If we have any properties to add to Object.prototype, we run
514 // through them and add them using defineProperty. 518 // through them and add them using defineProperty.
(...skipping 13 matching lines...) Expand all
528 if (emitter.compiler.enableMinification) targetBuffer.add(';'); 532 if (emitter.compiler.enableMinification) targetBuffer.add(';');
529 targetBuffer.add(jsAst.prettyPrint( 533 targetBuffer.add(jsAst.prettyPrint(
530 new jsAst.ExpressionStatement(init), compiler)); 534 new jsAst.ExpressionStatement(init), compiler));
531 targetBuffer.add('\n'); 535 targetBuffer.add('\n');
532 } 536 }
533 537
534 targetBuffer.add(nativeBuffer); 538 targetBuffer.add(nativeBuffer);
535 targetBuffer.add('\n'); 539 targetBuffer.add('\n');
536 } 540 }
537 } 541 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698