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

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

Issue 11411215: Generate parameter stubs using ASTs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 library native; 5 library native;
6 6
7 import 'dart:uri'; 7 import 'dart:uri';
8 import 'dart2jslib.dart' hide SourceString; 8 import 'dart2jslib.dart' hide SourceString;
9 import 'elements/elements.dart'; 9 import 'elements/elements.dart';
10 import 'js_backend/js_backend.dart'; 10 import 'js_backend/js_backend.dart';
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 builder.add(new HForeign( 801 builder.add(new HForeign(
802 new DartString.literal('${parameter.name.slowToString()} = #'), 802 new DartString.literal('${parameter.name.slowToString()} = #'),
803 const LiteralDartString('void'), 803 const LiteralDartString('void'),
804 <HInstruction>[jsClosure])); 804 <HInstruction>[jsClosure]));
805 } 805 }
806 }); 806 });
807 LiteralString jsCode = nativeBody.asLiteralString(); 807 LiteralString jsCode = nativeBody.asLiteralString();
808 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); 808 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[]));
809 } 809 }
810 } 810 }
811
812 void generateMethodWithPrototypeCheckForElement(Compiler compiler,
813 StringBuffer buffer,
814 FunctionElement element,
815 String code,
816 String parameters) {
817 String methodName;
818 JavaScriptBackend backend = compiler.backend;
819 Namer namer = backend.namer;
820 if (element.kind == ElementKind.FUNCTION) {
821 methodName = namer.instanceMethodName(element);
822 } else if (element.kind == ElementKind.GETTER) {
823 methodName = namer.getterName(element.getLibrary(), element.name);
824 } else if (element.kind == ElementKind.SETTER) {
825 methodName = namer.setterName(element.getLibrary(), element.name);
826 } else {
827 compiler.internalError('unexpected kind: "${element.kind}"',
828 element: element);
829 }
830
831 generateMethodWithPrototypeCheck(
832 compiler, buffer, methodName, code, parameters);
833 }
834
835
836 // If a method is overridden, we must check if the prototype of
837 // 'this' has the method available. Otherwise, we may end up
838 // calling the method from the super class. If the method is not
839 // available, we make a direct call to Object.prototype.$methodName.
840 // This method will patch the prototype of 'this' to the real method.
841 void generateMethodWithPrototypeCheck(Compiler compiler,
842 StringBuffer buffer,
843 String methodName,
844 String code,
845 String parameters) {
846 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty");
847 buffer.add("('$methodName')) {\n");
848 buffer.add(" $code");
849 buffer.add(" } else {\n");
850 buffer.add(" return Object.prototype.$methodName.call(this");
851 buffer.add(parameters == '' ? '' : ', $parameters');
852 buffer.add(");\n");
853 buffer.add(" }\n");
854 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698