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

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

Issue 929313002: Use an enum in embedded_names as input to JS_GET_NAME. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase + comments Created 5 years, 10 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) 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 'dart:_async_await_error_codes' as async_error_codes; 7 import 'dart:_async_await_error_codes' as async_error_codes;
8 8
9 import 'dart:_js_embedded_names' show 9 import 'dart:_js_embedded_names' show
10 JsGetName,
10 GET_TYPE_FROM_NAME, 11 GET_TYPE_FROM_NAME,
11 GET_ISOLATE_TAG, 12 GET_ISOLATE_TAG,
12 INTERCEPTED_NAMES, 13 INTERCEPTED_NAMES,
13 INTERCEPTORS_BY_TAG, 14 INTERCEPTORS_BY_TAG,
14 LEAF_TAGS, 15 LEAF_TAGS,
15 METADATA, 16 METADATA,
16 DEFERRED_LIBRARY_URIS, 17 DEFERRED_LIBRARY_URIS,
17 DEFERRED_LIBRARY_HASHES, 18 DEFERRED_LIBRARY_HASHES,
18 INITIALIZE_LOADED_HUNK, 19 INITIALIZE_LOADED_HUNK,
19 IS_HUNK_LOADED, 20 IS_HUNK_LOADED,
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 if (namedArguments != null && !namedArguments.isEmpty) { 1028 if (namedArguments != null && !namedArguments.isEmpty) {
1028 namedArguments.forEach((String name, argument) { 1029 namedArguments.forEach((String name, argument) {
1029 names = '$names\$$name'; 1030 names = '$names\$$name';
1030 namedArgumentList.add(name); 1031 namedArgumentList.add(name);
1031 arguments.add(argument); 1032 arguments.add(argument);
1032 argumentCount++; 1033 argumentCount++;
1033 }); 1034 });
1034 } 1035 }
1035 1036
1036 String selectorName = 1037 String selectorName =
1037 '${JS_GET_NAME("CALL_PREFIX")}\$$argumentCount$names'; 1038 '${JS_GET_NAME(JsGetName.CALL_PREFIX)}\$$argumentCount$names';
1038 1039
1039 return function.noSuchMethod( 1040 return function.noSuchMethod(
1040 createUnmangledInvocationMirror( 1041 createUnmangledInvocationMirror(
1041 #call, 1042 #call,
1042 selectorName, 1043 selectorName,
1043 JSInvocationMirror.METHOD, 1044 JSInvocationMirror.METHOD,
1044 arguments, 1045 arguments,
1045 namedArgumentList)); 1046 namedArgumentList));
1046 } 1047 }
1047 1048
1048 static applyFunctionNewEmitter(Function function, 1049 static applyFunctionNewEmitter(Function function,
1049 List positionalArguments, 1050 List positionalArguments,
1050 Map<String, dynamic> namedArguments) { 1051 Map<String, dynamic> namedArguments) {
1051 if (namedArguments == null) { 1052 if (namedArguments == null) {
1052 int requiredParameterCount = JS('int', r'#[#]', function, 1053 int requiredParameterCount = JS('int', r'#[#]', function,
1053 JS_GET_NAME("REQUIRED_PARAMETER_PROPERTY")); 1054 JS_GET_NAME(JsGetName.REQUIRED_PARAMETER_PROPERTY));
1054 int argumentCount = positionalArguments.length; 1055 int argumentCount = positionalArguments.length;
1055 if (argumentCount < requiredParameterCount) { 1056 if (argumentCount < requiredParameterCount) {
1056 return functionNoSuchMethod(function, positionalArguments, null); 1057 return functionNoSuchMethod(function, positionalArguments, null);
1057 } 1058 }
1058 String selectorName = '${JS_GET_NAME("CALL_PREFIX")}\$$argumentCount'; 1059 String selectorName =
1060 '${JS_GET_NAME(JsGetName.CALL_PREFIX)}\$$argumentCount';
1059 var jsStub = JS('var', r'#[#]', function, selectorName); 1061 var jsStub = JS('var', r'#[#]', function, selectorName);
1060 if (jsStub == null) { 1062 if (jsStub == null) {
1061 // Do a dynamic call. 1063 // Do a dynamic call.
1062 var interceptor = getInterceptor(function); 1064 var interceptor = getInterceptor(function);
1063 var jsFunction = JS('', '#[#]', interceptor, 1065 var jsFunction = JS('', '#[#]', interceptor,
1064 JS_GET_NAME('CALL_CATCH_ALL')); 1066 JS_GET_NAME(JsGetName.CALL_CATCH_ALL));
1065 var defaultValues = JS('var', r'#[#]', function, 1067 var defaultValues = JS('var', r'#[#]', function,
1066 JS_GET_NAME("DEFAULT_VALUES_PROPERTY")); 1068 JS_GET_NAME(JsGetName.DEFAULT_VALUES_PROPERTY));
1067 if (!JS('bool', '# instanceof Array', defaultValues)) { 1069 if (!JS('bool', '# instanceof Array', defaultValues)) {
1068 // The function expects named arguments! 1070 // The function expects named arguments!
1069 return functionNoSuchMethod(function, positionalArguments, null); 1071 return functionNoSuchMethod(function, positionalArguments, null);
1070 } 1072 }
1071 int defaultsLength = JS('int', "#.length", defaultValues); 1073 int defaultsLength = JS('int', "#.length", defaultValues);
1072 int maxArguments = requiredParameterCount + defaultsLength; 1074 int maxArguments = requiredParameterCount + defaultsLength;
1073 if (argumentCount > maxArguments) { 1075 if (argumentCount > maxArguments) {
1074 // The function expects less arguments! 1076 // The function expects less arguments!
1075 return functionNoSuchMethod(function, positionalArguments, null); 1077 return functionNoSuchMethod(function, positionalArguments, null);
1076 } 1078 }
1077 List arguments = new List.from(positionalArguments); 1079 List arguments = new List.from(positionalArguments);
1078 List missingDefaults = JS('JSArray', '#.slice(#)', defaultValues, 1080 List missingDefaults = JS('JSArray', '#.slice(#)', defaultValues,
1079 argumentCount - requiredParameterCount); 1081 argumentCount - requiredParameterCount);
1080 arguments.addAll(missingDefaults); 1082 arguments.addAll(missingDefaults);
1081 return JS('var', '#.apply(#, #)', jsFunction, function, arguments); 1083 return JS('var', '#.apply(#, #)', jsFunction, function, arguments);
1082 } 1084 }
1083 return JS('var', '#.apply(#, #)', jsStub, function, positionalArguments); 1085 return JS('var', '#.apply(#, #)', jsStub, function, positionalArguments);
1084 } else { 1086 } else {
1085 var interceptor = getInterceptor(function); 1087 var interceptor = getInterceptor(function);
1086 var jsFunction = JS('', '#[#]', interceptor, 1088 var jsFunction = JS('', '#[#]', interceptor,
1087 JS_GET_NAME('CALL_CATCH_ALL')); 1089 JS_GET_NAME(JsGetName.CALL_CATCH_ALL));
1088 var defaultValues = JS('JSArray', r'#[#]', function, 1090 var defaultValues = JS('JSArray', r'#[#]', function,
1089 JS_GET_NAME("DEFAULT_VALUES_PROPERTY")); 1091 JS_GET_NAME(JsGetName.DEFAULT_VALUES_PROPERTY));
1090 List keys = JS('JSArray', r'Object.keys(#)', defaultValues); 1092 List keys = JS('JSArray', r'Object.keys(#)', defaultValues);
1091 List arguments = new List.from(positionalArguments); 1093 List arguments = new List.from(positionalArguments);
1092 int used = 0; 1094 int used = 0;
1093 for (String key in keys) { 1095 for (String key in keys) {
1094 var value = namedArguments[key]; 1096 var value = namedArguments[key];
1095 if (value != null) { 1097 if (value != null) {
1096 used++; 1098 used++;
1097 arguments.add(value); 1099 arguments.add(value);
1098 } else { 1100 } else {
1099 arguments.add(JS('var', r'#[#]', defaultValues, key)); 1101 arguments.add(JS('var', r'#[#]', defaultValues, key));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 if (JS('bool', '# instanceof Array', positionalArguments)) { 1133 if (JS('bool', '# instanceof Array', positionalArguments)) {
1132 arguments = positionalArguments; 1134 arguments = positionalArguments;
1133 } else { 1135 } else {
1134 arguments = new List.from(positionalArguments); 1136 arguments = new List.from(positionalArguments);
1135 } 1137 }
1136 argumentCount = JS('int', '#.length', arguments); 1138 argumentCount = JS('int', '#.length', arguments);
1137 } else { 1139 } else {
1138 arguments = []; 1140 arguments = [];
1139 } 1141 }
1140 1142
1141 String selectorName = '${JS_GET_NAME("CALL_PREFIX")}\$$argumentCount'; 1143 String selectorName =
1144 '${JS_GET_NAME(JsGetName.CALL_PREFIX)}\$$argumentCount';
1142 var jsFunction = JS('var', '#[#]', function, selectorName); 1145 var jsFunction = JS('var', '#[#]', function, selectorName);
1143 if (jsFunction == null) { 1146 if (jsFunction == null) {
1144 var interceptor = getInterceptor(function); 1147 var interceptor = getInterceptor(function);
1145 jsFunction = JS('', '#["call*"]', interceptor); 1148 jsFunction = JS('', '#["call*"]', interceptor);
1146 1149
1147 if (jsFunction == null) { 1150 if (jsFunction == null) {
1148 return functionNoSuchMethod(function, positionalArguments, null); 1151 return functionNoSuchMethod(function, positionalArguments, null);
1149 } 1152 }
1150 ReflectionInfo info = new ReflectionInfo(jsFunction); 1153 ReflectionInfo info = new ReflectionInfo(jsFunction);
1151 int maxArgumentCount = info.requiredParameterCount + 1154 int maxArgumentCount = info.requiredParameterCount +
(...skipping 15 matching lines...) Expand all
1167 static applyFunctionWithNamedArguments(Function function, 1170 static applyFunctionWithNamedArguments(Function function,
1168 List positionalArguments, 1171 List positionalArguments,
1169 Map<String, dynamic> namedArguments) { 1172 Map<String, dynamic> namedArguments) {
1170 if (namedArguments.isEmpty) { 1173 if (namedArguments.isEmpty) {
1171 return applyFunctionWithPositionalArguments( 1174 return applyFunctionWithPositionalArguments(
1172 function, positionalArguments); 1175 function, positionalArguments);
1173 } 1176 }
1174 // TODO(ahe): The following code can be shared with 1177 // TODO(ahe): The following code can be shared with
1175 // JsInstanceMirror.invoke. 1178 // JsInstanceMirror.invoke.
1176 var interceptor = getInterceptor(function); 1179 var interceptor = getInterceptor(function);
1177 var jsFunction = JS('', '#[#]', interceptor, JS_GET_NAME('CALL_CATCH_ALL')); 1180 var jsFunction = JS('', '#[#]', interceptor,
1181 JS_GET_NAME(JsGetName.CALL_CATCH_ALL));
1178 1182
1179 if (jsFunction == null) { 1183 if (jsFunction == null) {
1180 return functionNoSuchMethod( 1184 return functionNoSuchMethod(
1181 function, positionalArguments, namedArguments); 1185 function, positionalArguments, namedArguments);
1182 } 1186 }
1183 ReflectionInfo info = new ReflectionInfo(jsFunction); 1187 ReflectionInfo info = new ReflectionInfo(jsFunction);
1184 if (info == null || !info.areOptionalParametersNamed) { 1188 if (info == null || !info.areOptionalParametersNamed) {
1185 return functionNoSuchMethod( 1189 return functionNoSuchMethod(
1186 function, positionalArguments, namedArguments); 1190 function, positionalArguments, namedArguments);
1187 } 1191 }
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 String propertyName) { 2056 String propertyName) {
2053 JS_EFFECT(() { 2057 JS_EFFECT(() {
2054 BoundClosure.receiverOf(JS('BoundClosure', 'void 0')); 2058 BoundClosure.receiverOf(JS('BoundClosure', 'void 0'));
2055 BoundClosure.selfOf(JS('BoundClosure', 'void 0')); 2059 BoundClosure.selfOf(JS('BoundClosure', 'void 0'));
2056 }); 2060 });
2057 // TODO(ahe): All the place below using \$ should be rewritten to go 2061 // TODO(ahe): All the place below using \$ should be rewritten to go
2058 // through the namer. 2062 // through the namer.
2059 var function = JS('', '#[#]', functions, 0); 2063 var function = JS('', '#[#]', functions, 0);
2060 String name = JS('String|Null', '#.\$stubName', function); 2064 String name = JS('String|Null', '#.\$stubName', function);
2061 String callName = JS('String|Null', '#[#]', function, 2065 String callName = JS('String|Null', '#[#]', function,
2062 JS_GET_NAME("CALL_NAME_PROPERTY")); 2066 JS_GET_NAME(JsGetName.CALL_NAME_PROPERTY));
2063 2067
2064 var functionType; 2068 var functionType;
2065 if (reflectionInfo is List) { 2069 if (reflectionInfo is List) {
2066 JS('', '#.\$reflectionInfo = #', function, reflectionInfo); 2070 JS('', '#.\$reflectionInfo = #', function, reflectionInfo);
2067 ReflectionInfo info = new ReflectionInfo(function); 2071 ReflectionInfo info = new ReflectionInfo(function);
2068 functionType = info.functionType; 2072 functionType = info.functionType;
2069 } else { 2073 } else {
2070 functionType = reflectionInfo; 2074 functionType = reflectionInfo;
2071 } 2075 }
2072 2076
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 } else { 2159 } else {
2156 throw 'Error in reflectionInfo.'; 2160 throw 'Error in reflectionInfo.';
2157 } 2161 }
2158 2162
2159 JS('', '#[#] = #', prototype, JS_SIGNATURE_NAME(), signatureFunction); 2163 JS('', '#[#] = #', prototype, JS_SIGNATURE_NAME(), signatureFunction);
2160 2164
2161 JS('', '#[#] = #', prototype, callName, trampoline); 2165 JS('', '#[#] = #', prototype, callName, trampoline);
2162 for (int i = 1; i < functions.length; i++) { 2166 for (int i = 1; i < functions.length; i++) {
2163 var stub = functions[i]; 2167 var stub = functions[i];
2164 var stubCallName = JS('String|Null', '#[#]', stub, 2168 var stubCallName = JS('String|Null', '#[#]', stub,
2165 JS_GET_NAME("CALL_NAME_PROPERTY")); 2169 JS_GET_NAME(JsGetName.CALL_NAME_PROPERTY));
2166 if (stubCallName != null) { 2170 if (stubCallName != null) {
2167 JS('', '#[#] = #', prototype, stubCallName, 2171 JS('', '#[#] = #', prototype, stubCallName,
2168 isStatic ? stub : forwardCallTo(receiver, stub, isIntercepted)); 2172 isStatic ? stub : forwardCallTo(receiver, stub, isIntercepted));
2169 } 2173 }
2170 } 2174 }
2171 2175
2172 JS('', '#[#] = #', prototype, JS_GET_NAME('CALL_CATCH_ALL'), trampoline); 2176 JS('', '#[#] = #', prototype, JS_GET_NAME(JsGetName.CALL_CATCH_ALL),
2173 String reqArgProperty = JS_GET_NAME("REQUIRED_PARAMETER_PROPERTY"); 2177 trampoline);
2174 String defValProperty = JS_GET_NAME("DEFAULT_VALUES_PROPERTY"); 2178 String reqArgProperty = JS_GET_NAME(JsGetName.REQUIRED_PARAMETER_PROPERTY);
2179 String defValProperty = JS_GET_NAME(JsGetName.DEFAULT_VALUES_PROPERTY);
2175 JS('', '#.# = #.#', prototype, reqArgProperty, function, reqArgProperty); 2180 JS('', '#.# = #.#', prototype, reqArgProperty, function, reqArgProperty);
2176 JS('', '#.# = #.#', prototype, defValProperty, function, defValProperty); 2181 JS('', '#.# = #.#', prototype, defValProperty, function, defValProperty);
2177 2182
2178 return constructor; 2183 return constructor;
2179 } 2184 }
2180 2185
2181 static cspForwardCall(int arity, bool isSuperCall, String stubName, 2186 static cspForwardCall(int arity, bool isSuperCall, String stubName,
2182 function) { 2187 function) {
2183 var getSelf = RAW_DART_FUNCTION_REF(BoundClosure.selfOf); 2188 var getSelf = RAW_DART_FUNCTION_REF(BoundClosure.selfOf);
2184 // Handle intercepted stub-names with the default slow case. 2189 // Handle intercepted stub-names with the default slow case.
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after
3843 // This is a function that will return a helper function that does the 3848 // This is a function that will return a helper function that does the
3844 // iteration of the sync*. 3849 // iteration of the sync*.
3845 // 3850 //
3846 // Each invocation should give a body with fresh state. 3851 // Each invocation should give a body with fresh state.
3847 final dynamic /* js function */ _outerHelper; 3852 final dynamic /* js function */ _outerHelper;
3848 3853
3849 SyncStarIterable(this._outerHelper); 3854 SyncStarIterable(this._outerHelper);
3850 3855
3851 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); 3856 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper));
3852 } 3857 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/foreign_helper.dart ('k') | sdk/lib/_internal/compiler/js_lib/js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698