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

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

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