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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2587203002: Correct handling of cross-frame functions in ddc. (Closed)
Patch Set: Created 3 years, 12 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 /// The dart:_interceptors JSArray element. 119 /// The dart:_interceptors JSArray element.
120 final ClassElement _jsArray; 120 final ClassElement _jsArray;
121 121
122 final ClassElement boolClass; 122 final ClassElement boolClass;
123 final ClassElement intClass; 123 final ClassElement intClass;
124 final ClassElement interceptorClass; 124 final ClassElement interceptorClass;
125 final ClassElement nullClass; 125 final ClassElement nullClass;
126 final ClassElement numClass; 126 final ClassElement numClass;
127 final ClassElement objectClass; 127 final ClassElement objectClass;
128 final ClassElement stringClass; 128 final ClassElement stringClass;
129 final ClassElement functionClass;
129 final ClassElement symbolClass; 130 final ClassElement symbolClass;
130 131
131 ConstFieldVisitor _constants; 132 ConstFieldVisitor _constants;
132 133
133 /// The current function body being compiled. 134 /// The current function body being compiled.
134 FunctionBody _currentFunction; 135 FunctionBody _currentFunction;
135 136
136 /// Helper class for emitting elements in the proper order to allow 137 /// Helper class for emitting elements in the proper order to allow
137 /// JS to load the module. 138 /// JS to load the module.
138 ElementLoader _loader; 139 ElementLoader _loader;
(...skipping 25 matching lines...) Expand all
164 _jsArray = _getLibrary(c, 'dart:_interceptors').getType('JSArray'), 165 _jsArray = _getLibrary(c, 'dart:_interceptors').getType('JSArray'),
165 interceptorClass = 166 interceptorClass =
166 _getLibrary(c, 'dart:_interceptors').getType('Interceptor'), 167 _getLibrary(c, 'dart:_interceptors').getType('Interceptor'),
167 dartCoreLibrary = _getLibrary(c, 'dart:core'), 168 dartCoreLibrary = _getLibrary(c, 'dart:core'),
168 boolClass = _getLibrary(c, 'dart:core').getType('bool'), 169 boolClass = _getLibrary(c, 'dart:core').getType('bool'),
169 intClass = _getLibrary(c, 'dart:core').getType('int'), 170 intClass = _getLibrary(c, 'dart:core').getType('int'),
170 numClass = _getLibrary(c, 'dart:core').getType('num'), 171 numClass = _getLibrary(c, 'dart:core').getType('num'),
171 nullClass = _getLibrary(c, 'dart:core').getType('Null'), 172 nullClass = _getLibrary(c, 'dart:core').getType('Null'),
172 objectClass = _getLibrary(c, 'dart:core').getType('Object'), 173 objectClass = _getLibrary(c, 'dart:core').getType('Object'),
173 stringClass = _getLibrary(c, 'dart:core').getType('String'), 174 stringClass = _getLibrary(c, 'dart:core').getType('String'),
175 functionClass = _getLibrary(c, 'dart:core').getType('Function'),
174 symbolClass = _getLibrary(c, 'dart:_internal').getType('Symbol'), 176 symbolClass = _getLibrary(c, 'dart:_internal').getType('Symbol'),
175 dartJSLibrary = _getLibrary(c, 'dart:js'); 177 dartJSLibrary = _getLibrary(c, 'dart:js');
176 178
177 LibraryElement get currentLibrary => _loader.currentElement.library; 179 LibraryElement get currentLibrary => _loader.currentElement.library;
178 180
179 /// The main entry point to JavaScript code generation. 181 /// The main entry point to JavaScript code generation.
180 /// 182 ///
181 /// Takes the metadata for the build unit, as well as resolved trees and 183 /// Takes the metadata for the build unit, as well as resolved trees and
182 /// errors, and computes the output module code and optionally the source map. 184 /// errors, and computes the output module code and optionally the source map.
183 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, 185 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits,
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 '}', 925 '}',
924 [className, _runtimeModule, className])); 926 [className, _runtimeModule, className]));
925 body.add(js.statement( 927 body.add(js.statement(
926 '#._check = function check_String(o) {' 928 '#._check = function check_String(o) {'
927 ' if (typeof o == "string" || o == null) return o;' 929 ' if (typeof o == "string" || o == null) return o;'
928 ' return #.check(o, #);' 930 ' return #.check(o, #);'
929 '}', 931 '}',
930 [className, _runtimeModule, className])); 932 [className, _runtimeModule, className]));
931 return; 933 return;
932 } 934 }
935 if (classElem == functionClass) {
936 body.add(js.statement(
937 '#.is = function is_Function(o) { return typeof o == "function"; }',
Leaf 2016/12/19 22:42:56 Does this do the right thing for classes with call
Jacob 2016/12/19 22:53:33 Yes because classes with call methods have to be i
938 className));
939 body.add(js.statement(
940 '#.as = function as_Function(o) {'
941 ' if (typeof o == "function" || o == null) return o;'
942 ' return #.as(o, #);'
943 '}',
944 [className, _runtimeModule, className]));
945 body.add(js.statement(
946 '#._check = function check_String(o) {'
947 ' if (typeof o == "function" || o == null) return o;'
948 ' return #.check(o, #);'
949 '}',
950 [className, _runtimeModule, className]));
951 return;
952 }
953
933 if (classElem == intClass) { 954 if (classElem == intClass) {
934 body.add(js.statement( 955 body.add(js.statement(
935 '#.is = function is_int(o) {' 956 '#.is = function is_int(o) {'
936 ' return typeof o == "number" && Math.floor(o) == o;' 957 ' return typeof o == "number" && Math.floor(o) == o;'
937 '}', 958 '}',
938 className)); 959 className));
939 body.add(js.statement( 960 body.add(js.statement(
940 '#.as = function as_int(o) {' 961 '#.as = function as_int(o) {'
941 ' if ((typeof o == "number" && Math.floor(o) == o) || o == null)' 962 ' if ((typeof o == "number" && Math.floor(o) == o) || o == null)'
942 ' return o;' 963 ' return o;'
(...skipping 4850 matching lines...) Expand 10 before | Expand all | Expand 10 after
5793 if (targetIdentifier.staticElement is! PrefixElement) return false; 5814 if (targetIdentifier.staticElement is! PrefixElement) return false;
5794 var prefix = targetIdentifier.staticElement as PrefixElement; 5815 var prefix = targetIdentifier.staticElement as PrefixElement;
5795 5816
5796 // The library the prefix is referring to must come from a deferred import. 5817 // The library the prefix is referring to must come from a deferred import.
5797 var containingLibrary = resolutionMap 5818 var containingLibrary = resolutionMap
5798 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5819 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5799 .library; 5820 .library;
5800 var imports = containingLibrary.getImportsWithPrefix(prefix); 5821 var imports = containingLibrary.getImportsWithPrefix(prefix);
5801 return imports.length == 1 && imports[0].isDeferred; 5822 return imports.length == 1 && imports[0].isDeferred;
5802 } 5823 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698