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

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

Issue 23452029: Address comments from CL 23304012. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter_no_eval.dart » ('j') | 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) 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 /// Enables debugging of fast/slow objects using V8-specific primitives.
7 const DEBUG_FAST_OBJECTS = false; 8 const DEBUG_FAST_OBJECTS = false;
8 9
9 /** 10 /**
10 * A function element that represents a closure call. The signature is copied 11 * A function element that represents a closure call. The signature is copied
11 * from the given element. 12 * from the given element.
12 */ 13 */
13 class ClosureInvocationElement extends FunctionElementX { 14 class ClosureInvocationElement extends FunctionElementX {
14 ClosureInvocationElement(SourceString name, 15 ClosureInvocationElement(SourceString name,
15 FunctionElement other) 16 FunctionElement other)
16 : super.from(name, other, other.enclosingElement), 17 : super.from(name, other, other.enclosingElement),
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 697
697 List<jsAst.Node> statements = [ 698 List<jsAst.Node> statements = [
698 js('var pendingClasses = {}'), 699 js('var pendingClasses = {}'),
699 js.if_('!init.allClasses', js('init.allClasses = {}')), 700 js.if_('!init.allClasses', js('init.allClasses = {}')),
700 js('var allClasses = init.allClasses'), 701 js('var allClasses = init.allClasses'),
701 702
702 js('var hasOwnProperty = Object.prototype.hasOwnProperty'), 703 js('var hasOwnProperty = Object.prototype.hasOwnProperty'),
703 704
704 optional( 705 optional(
705 DEBUG_FAST_OBJECTS, 706 DEBUG_FAST_OBJECTS,
706 js(r'print("Number of classes: " + Object.getOwnPropertyNames($$).leng th)')), 707 js(r'print("Number of classes: "'
708 ' + Object.getOwnPropertyNames($$).length)')),
707 709
708 js.forIn('cls', 'collectedClasses', [ 710 js.forIn('cls', 'collectedClasses', [
709 js.if_('hasOwnProperty.call(collectedClasses, cls)', [ 711 js.if_('hasOwnProperty.call(collectedClasses, cls)', [
710 js('var desc = collectedClasses[cls]'), 712 js('var desc = collectedClasses[cls]'),
711 js('var globalObject = isolateProperties'), 713 js('var globalObject = isolateProperties'),
712 js.if_('desc instanceof Array', [ 714 js.if_('desc instanceof Array', [
713 js('globalObject = desc[0] || isolateProperties'), 715 js('globalObject = desc[0] || isolateProperties'),
714 js('desc = desc[1]') 716 js('desc = desc[1]')
715 ]), 717 ]),
716 718
(...skipping 3006 matching lines...) Expand 10 before | Expand all | Expand 10 after
3723 buffer.write(metadata); 3725 buffer.write(metadata);
3724 } 3726 }
3725 } else { 3727 } else {
3726 throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}'; 3728 throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}';
3727 } 3729 }
3728 buffer.write(',$n'); 3730 buffer.write(',$n');
3729 } 3731 }
3730 buffer.write('];$n'); 3732 buffer.write('];$n');
3731 } 3733 }
3732 3734
3733 void emitInstancify() { 3735 void emitInstancify() {
ahe 2013/09/13 09:36:14 Nicolas suggested renaming this method, but I'm no
ahe 2013/09/13 10:09:12 Renamed to "emitConvertToFastObjectFunction".
3734 mainBuffer.add(r''' 3736 mainBuffer.add(r'''
3735 function instancify(properties) { 3737 function instancify(properties) {
3736 function makeConstructor() { 3738 function makeConstructor() {
3737 var str = "{\n"; 3739 var str = "{\n";
3738 var hasOwnProperty = Object.prototype.hasOwnProperty; 3740 var hasOwnProperty = Object.prototype.hasOwnProperty;
3739 for (var property in properties) { 3741 for (var property in properties) {
3740 if (hasOwnProperty.call(properties, property)) { 3742 if (hasOwnProperty.call(properties, property)) {
3741 str += "this." + property + "= properties." + property + ";\n"; 3743 str += "this." + property + "= properties." + property + ";\n";
3742 } 3744 }
3743 } 3745 }
(...skipping 15 matching lines...) Expand all
3759 computeNeededClasses(); 3761 computeNeededClasses();
3760 3762
3761 mainBuffer.add(buildGeneratedBy()); 3763 mainBuffer.add(buildGeneratedBy());
3762 addComment(HOOKS_API_USAGE, mainBuffer); 3764 addComment(HOOKS_API_USAGE, mainBuffer);
3763 3765
3764 if (!areAnyElementsDeferred) { 3766 if (!areAnyElementsDeferred) {
3765 mainBuffer.add('(function(${namer.CURRENT_ISOLATE})$_{$n'); 3767 mainBuffer.add('(function(${namer.CURRENT_ISOLATE})$_{$n');
3766 } 3768 }
3767 3769
3768 for (String globalObject in Namer.reservedGlobalObjectNames) { 3770 for (String globalObject in Namer.reservedGlobalObjectNames) {
3771 // The global objects start as so-called "slow objects". For V8, this
3772 // means that it won't try to make map transitions as we add properties
3773 // to these objects. Later on, we attempt to turn these objects into
3774 // fast objects by calling "instancify".
ngeoffray 2013/09/13 10:05:54 Please add that instancify is being defined in [em
ahe 2013/09/13 10:09:12 Done.
3769 mainBuffer 3775 mainBuffer
3770 ..write('var ${globalObject}$_=$_{}$N') 3776 ..write('var ${globalObject}$_=$_{}$N')
3771 ..write('delete ${globalObject}.x$N'); 3777 ..write('delete ${globalObject}.x$N');
3772 } 3778 }
3773 3779
3774 mainBuffer.add('function ${namer.isolateName}()$_{}\n'); 3780 mainBuffer.add('function ${namer.isolateName}()$_{}\n');
3775 mainBuffer.add('init()$N$n'); 3781 mainBuffer.add('init()$N$n');
3776 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary. 3782 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary.
3777 isolateProperties = namer.CURRENT_ISOLATE; 3783 isolateProperties = namer.CURRENT_ISOLATE;
3778 mainBuffer.add( 3784 mainBuffer.add(
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
4000 } 4006 }
4001 if (DEBUG_FAST_OBJECTS) { 4007 if (DEBUG_FAST_OBJECTS) {
4002 ClassElement primitives = 4008 ClassElement primitives =
4003 compiler.findHelper(const SourceString('Primitives')); 4009 compiler.findHelper(const SourceString('Primitives'));
4004 FunctionElement printHelper = 4010 FunctionElement printHelper =
4005 compiler.lookupElementIn( 4011 compiler.lookupElementIn(
4006 primitives, const SourceString('printString')); 4012 primitives, const SourceString('printString'));
4007 String printHelperName = namer.isolateAccess(printHelper); 4013 String printHelperName = namer.isolateAccess(printHelper);
4008 4014
4009 mainBuffer.add(''' 4015 mainBuffer.add('''
4016 // The following only works on V8 when run with option "--allow-natives-syntax".
4010 if (typeof $printHelperName === "function") { 4017 if (typeof $printHelperName === "function") {
4011 $printHelperName("Size of global helper object: " 4018 $printHelperName("Size of global helper object: "
4012 + String(Object.getOwnPropertyNames(H).length) 4019 + String(Object.getOwnPropertyNames(H).length)
4013 + ", fast properties " + %HasFastProperties(H)); 4020 + ", fast properties " + %HasFastProperties(H));
4014 $printHelperName("Size of global platform object: " 4021 $printHelperName("Size of global platform object: "
4015 + String(Object.getOwnPropertyNames(P).length) 4022 + String(Object.getOwnPropertyNames(P).length)
4016 + ", fast properties " + %HasFastProperties(P)); 4023 + ", fast properties " + %HasFastProperties(P));
4017 $printHelperName("Size of global dart:html object: " 4024 $printHelperName("Size of global dart:html object: "
4018 + String(Object.getOwnPropertyNames(W).length) 4025 + String(Object.getOwnPropertyNames(W).length)
4019 + ", fast properties " + %HasFastProperties(W)); 4026 + ", fast properties " + %HasFastProperties(W));
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
4294 4301
4295 const String HOOKS_API_USAGE = """ 4302 const String HOOKS_API_USAGE = """
4296 // The code supports the following hooks: 4303 // The code supports the following hooks:
4297 // dartPrint(message) - if this function is defined it is called 4304 // dartPrint(message) - if this function is defined it is called
4298 // instead of the Dart [print] method. 4305 // instead of the Dart [print] method.
4299 // dartMainRunner(main) - if this function is defined, the Dart [main] 4306 // dartMainRunner(main) - if this function is defined, the Dart [main]
4300 // method will not be invoked directly. 4307 // method will not be invoked directly.
4301 // Instead, a closure that will invoke [main] is 4308 // Instead, a closure that will invoke [main] is
4302 // passed to [dartMainRunner]. 4309 // passed to [dartMainRunner].
4303 """; 4310 """;
OLDNEW
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter_no_eval.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698