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

Side by Side Diff: dart/sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 734323003: Use Object.create instead of a tmp-function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 _js_helper; 5 library _js_helper;
6 6
7 import 'shared/embedded_names.dart' show 7 import 'shared/embedded_names.dart' show
8 ALL_CLASSES, 8 ALL_CLASSES,
9 GET_ISOLATE_TAG, 9 GET_ISOLATE_TAG,
10 INTERCEPTED_NAMES, 10 INTERCEPTED_NAMES,
(...skipping 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 // BoundClosure. For this, we need to create an object whose prototype is 1963 // BoundClosure. For this, we need to create an object whose prototype is
1964 // the prototype is either TearOffClosure.prototype or 1964 // the prototype is either TearOffClosure.prototype or
1965 // BoundClosure.prototype, respectively in pseudo JavaScript code. The 1965 // BoundClosure.prototype, respectively in pseudo JavaScript code. The
1966 // simplest way to access the JavaScript construction function of a Dart 1966 // simplest way to access the JavaScript construction function of a Dart
1967 // class is to create an instance and access its constructor property. The 1967 // class is to create an instance and access its constructor property. The
1968 // newly created instance could in theory be used directly as the 1968 // newly created instance could in theory be used directly as the
1969 // prototype, but it might include additional fields that we don't need. 1969 // prototype, but it might include additional fields that we don't need.
1970 // So we only use the new instance to access the constructor property and 1970 // So we only use the new instance to access the constructor property and
1971 // use Object.create to create the desired prototype. 1971 // use Object.create to create the desired prototype.
1972 var prototype = isStatic 1972 var prototype = isStatic
1973 // TODO(ahe): Safe to use Object.create?
1974 ? JS('TearOffClosure', 'Object.create(#.constructor.prototype)', 1973 ? JS('TearOffClosure', 'Object.create(#.constructor.prototype)',
1975 new TearOffClosure()) 1974 new TearOffClosure())
1976 : JS('BoundClosure', 'Object.create(#.constructor.prototype)', 1975 : JS('BoundClosure', 'Object.create(#.constructor.prototype)',
1977 new BoundClosure(null, null, null, null)); 1976 new BoundClosure(null, null, null, null));
1978 1977
1979 JS('', '#.\$initialize = #', prototype, JS('', '#.constructor', prototype)); 1978 JS('', '#.\$initialize = #', prototype, JS('', '#.constructor', prototype));
1980 var constructor = isStatic 1979 var constructor = isStatic
1981 ? JS('', 'function(){this.\$initialize()}') 1980 ? JS('', 'function(){this.\$initialize()}')
1982 : isCsp 1981 : isCsp
1983 ? JS('', 'function(a,b,c,d) {this.\$initialize(a,b,c,d)}') 1982 ? JS('', 'function(a,b,c,d) {this.\$initialize(a,b,c,d)}')
1984 : JS('', 1983 : JS('',
1985 'new Function("a","b","c","d",' 1984 'new Function("a","b","c","d",'
1986 '"this.\$initialize(a,b,c,d);"+#)', 1985 '"this.\$initialize(a,b,c,d);"+#)',
1987 functionCounter++); 1986 functionCounter++);
1988 1987
1989 // TODO(ahe): Is it necessary to set the constructor property? 1988 // It is necessary to set the constructor property, otherwise it will be
1989 // "Object".
1990 JS('', '#.constructor = #', prototype, constructor); 1990 JS('', '#.constructor = #', prototype, constructor);
1991 1991
1992 JS('', '#.prototype = #', constructor, prototype); 1992 JS('', '#.prototype = #', constructor, prototype);
1993 1993
1994 // Create a closure and "monkey" patch it with call stubs. 1994 // Create a closure and "monkey" patch it with call stubs.
1995 var trampoline = function; 1995 var trampoline = function;
1996 var isIntercepted = false; 1996 var isIntercepted = false;
1997 if (!isStatic) { 1997 if (!isStatic) {
1998 if (JS('bool', '#.length == 1', jsArguments)) { 1998 if (JS('bool', '#.length == 1', jsArguments)) {
1999 // Intercepted call. 1999 // Intercepted call.
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3402 throw new MainError("No top-level function named 'main'."); 3402 throw new MainError("No top-level function named 'main'.");
3403 } 3403 }
3404 3404
3405 void badMain() { 3405 void badMain() {
3406 throw new MainError("'main' is not a function."); 3406 throw new MainError("'main' is not a function.");
3407 } 3407 }
3408 3408
3409 void mainHasTooManyParameters() { 3409 void mainHasTooManyParameters() {
3410 throw new MainError("'main' expects too many parameters."); 3410 throw new MainError("'main' expects too many parameters.");
3411 } 3411 }
OLDNEW
« no previous file with comments | « dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698