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

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

Issue 955923002: Reapply "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,
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 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 if (namedArguments != null && !namedArguments.isEmpty) { 1030 if (namedArguments != null && !namedArguments.isEmpty) {
1030 namedArguments.forEach((String name, argument) { 1031 namedArguments.forEach((String name, argument) {
1031 names = '$names\$$name'; 1032 names = '$names\$$name';
1032 namedArgumentList.add(name); 1033 namedArgumentList.add(name);
1033 arguments.add(argument); 1034 arguments.add(argument);
1034 argumentCount++; 1035 argumentCount++;
1035 }); 1036 });
1036 } 1037 }
1037 1038
1038 String selectorName = 1039 String selectorName =
1039 '${JS_GET_NAME("CALL_PREFIX")}\$$argumentCount$names'; 1040 '${JS_GET_NAME(JsGetName.CALL_PREFIX)}\$$argumentCount$names';
1040 1041
1041 return function.noSuchMethod( 1042 return function.noSuchMethod(
1042 createUnmangledInvocationMirror( 1043 createUnmangledInvocationMirror(
1043 #call, 1044 #call,
1044 selectorName, 1045 selectorName,
1045 JSInvocationMirror.METHOD, 1046 JSInvocationMirror.METHOD,
1046 arguments, 1047 arguments,
1047 namedArgumentList)); 1048 namedArgumentList));
1048 } 1049 }
1049 1050
1050 static applyFunctionNewEmitter(Function function, 1051 static applyFunctionNewEmitter(Function function,
1051 List positionalArguments, 1052 List positionalArguments,
1052 Map<String, dynamic> namedArguments) { 1053 Map<String, dynamic> namedArguments) {
1053 if (namedArguments == null) { 1054 if (namedArguments == null) {
1054 int requiredParameterCount = JS('int', r'#[#]', function, 1055 int requiredParameterCount = JS('int', r'#[#]', function,
1055 JS_GET_NAME("REQUIRED_PARAMETER_PROPERTY")); 1056 JS_GET_NAME(JsGetName.REQUIRED_PARAMETER_PROPERTY));
1056 int argumentCount = positionalArguments.length; 1057 int argumentCount = positionalArguments.length;
1057 if (argumentCount < requiredParameterCount) { 1058 if (argumentCount < requiredParameterCount) {
1058 return functionNoSuchMethod(function, positionalArguments, null); 1059 return functionNoSuchMethod(function, positionalArguments, null);
1059 } 1060 }
1060 String selectorName = '${JS_GET_NAME("CALL_PREFIX")}\$$argumentCount'; 1061 String selectorName =
1062 '${JS_GET_NAME(JsGetName.CALL_PREFIX)}\$$argumentCount';
1061 var jsStub = JS('var', r'#[#]', function, selectorName); 1063 var jsStub = JS('var', r'#[#]', function, selectorName);
1062 if (jsStub == null) { 1064 if (jsStub == null) {
1063 // Do a dynamic call. 1065 // Do a dynamic call.
1064 var interceptor = getInterceptor(function); 1066 var interceptor = getInterceptor(function);
1065 var jsFunction = JS('', '#[#]', interceptor, 1067 var jsFunction = JS('', '#[#]', interceptor,
1066 JS_GET_NAME('CALL_CATCH_ALL')); 1068 JS_GET_NAME(JsGetName.CALL_CATCH_ALL));
1067 var defaultValues = JS('var', r'#[#]', function, 1069 var defaultValues = JS('var', r'#[#]', function,
1068 JS_GET_NAME("DEFAULT_VALUES_PROPERTY")); 1070 JS_GET_NAME(JsGetName.DEFAULT_VALUES_PROPERTY));
1069 if (!JS('bool', '# instanceof Array', defaultValues)) { 1071 if (!JS('bool', '# instanceof Array', defaultValues)) {
1070 // The function expects named arguments! 1072 // The function expects named arguments!
1071 return functionNoSuchMethod(function, positionalArguments, null); 1073 return functionNoSuchMethod(function, positionalArguments, null);
1072 } 1074 }
1073 int defaultsLength = JS('int', "#.length", defaultValues); 1075 int defaultsLength = JS('int', "#.length", defaultValues);
1074 int maxArguments = requiredParameterCount + defaultsLength; 1076 int maxArguments = requiredParameterCount + defaultsLength;
1075 if (argumentCount > maxArguments) { 1077 if (argumentCount > maxArguments) {
1076 // The function expects less arguments! 1078 // The function expects less arguments!
1077 return functionNoSuchMethod(function, positionalArguments, null); 1079 return functionNoSuchMethod(function, positionalArguments, null);
1078 } 1080 }
1079 List arguments = new List.from(positionalArguments); 1081 List arguments = new List.from(positionalArguments);
1080 List missingDefaults = JS('JSArray', '#.slice(#)', defaultValues, 1082 List missingDefaults = JS('JSArray', '#.slice(#)', defaultValues,
1081 argumentCount - requiredParameterCount); 1083 argumentCount - requiredParameterCount);
1082 arguments.addAll(missingDefaults); 1084 arguments.addAll(missingDefaults);
1083 return JS('var', '#.apply(#, #)', jsFunction, function, arguments); 1085 return JS('var', '#.apply(#, #)', jsFunction, function, arguments);
1084 } 1086 }
1085 return JS('var', '#.apply(#, #)', jsStub, function, positionalArguments); 1087 return JS('var', '#.apply(#, #)', jsStub, function, positionalArguments);
1086 } else { 1088 } else {
1087 var interceptor = getInterceptor(function); 1089 var interceptor = getInterceptor(function);
1088 var jsFunction = JS('', '#[#]', interceptor, 1090 var jsFunction = JS('', '#[#]', interceptor,
1089 JS_GET_NAME('CALL_CATCH_ALL')); 1091 JS_GET_NAME(JsGetName.CALL_CATCH_ALL));
1090 var defaultValues = JS('JSArray', r'#[#]', function, 1092 var defaultValues = JS('JSArray', r'#[#]', function,
1091 JS_GET_NAME("DEFAULT_VALUES_PROPERTY")); 1093 JS_GET_NAME(JsGetName.DEFAULT_VALUES_PROPERTY));
1092 List keys = JS('JSArray', r'Object.keys(#)', defaultValues); 1094 List keys = JS('JSArray', r'Object.keys(#)', defaultValues);
1093 List arguments = new List.from(positionalArguments); 1095 List arguments = new List.from(positionalArguments);
1094 int used = 0; 1096 int used = 0;
1095 for (String key in keys) { 1097 for (String key in keys) {
1096 var value = namedArguments[key]; 1098 var value = namedArguments[key];
1097 if (value != null) { 1099 if (value != null) {
1098 used++; 1100 used++;
1099 arguments.add(value); 1101 arguments.add(value);
1100 } else { 1102 } else {
1101 arguments.add(JS('var', r'#[#]', defaultValues, key)); 1103 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)) { 1135 if (JS('bool', '# instanceof Array', positionalArguments)) {
1134 arguments = positionalArguments; 1136 arguments = positionalArguments;
1135 } else { 1137 } else {
1136 arguments = new List.from(positionalArguments); 1138 arguments = new List.from(positionalArguments);
1137 } 1139 }
1138 argumentCount = JS('int', '#.length', arguments); 1140 argumentCount = JS('int', '#.length', arguments);
1139 } else { 1141 } else {
1140 arguments = []; 1142 arguments = [];
1141 } 1143 }
1142 1144
1143 String selectorName = '${JS_GET_NAME("CALL_PREFIX")}\$$argumentCount'; 1145 String selectorName =
1146 '${JS_GET_NAME(JsGetName.CALL_PREFIX)}\$$argumentCount';
1144 var jsFunction = JS('var', '#[#]', function, selectorName); 1147 var jsFunction = JS('var', '#[#]', function, selectorName);
1145 if (jsFunction == null) { 1148 if (jsFunction == null) {
1146 var interceptor = getInterceptor(function); 1149 var interceptor = getInterceptor(function);
1147 jsFunction = JS('', '#["call*"]', interceptor); 1150 jsFunction = JS('', '#["call*"]', interceptor);
1148 1151
1149 if (jsFunction == null) { 1152 if (jsFunction == null) {
1150 return functionNoSuchMethod(function, positionalArguments, null); 1153 return functionNoSuchMethod(function, positionalArguments, null);
1151 } 1154 }
1152 ReflectionInfo info = new ReflectionInfo(jsFunction); 1155 ReflectionInfo info = new ReflectionInfo(jsFunction);
1153 int maxArgumentCount = info.requiredParameterCount + 1156 int maxArgumentCount = info.requiredParameterCount +
(...skipping 15 matching lines...) Expand all
1169 static applyFunctionWithNamedArguments(Function function, 1172 static applyFunctionWithNamedArguments(Function function,
1170 List positionalArguments, 1173 List positionalArguments,
1171 Map<String, dynamic> namedArguments) { 1174 Map<String, dynamic> namedArguments) {
1172 if (namedArguments.isEmpty) { 1175 if (namedArguments.isEmpty) {
1173 return applyFunctionWithPositionalArguments( 1176 return applyFunctionWithPositionalArguments(
1174 function, positionalArguments); 1177 function, positionalArguments);
1175 } 1178 }
1176 // TODO(ahe): The following code can be shared with 1179 // TODO(ahe): The following code can be shared with
1177 // JsInstanceMirror.invoke. 1180 // JsInstanceMirror.invoke.
1178 var interceptor = getInterceptor(function); 1181 var interceptor = getInterceptor(function);
1179 var jsFunction = JS('', '#[#]', interceptor, JS_GET_NAME('CALL_CATCH_ALL')); 1182 var jsFunction = JS('', '#[#]', interceptor,
1183 JS_GET_NAME(JsGetName.CALL_CATCH_ALL));
1180 1184
1181 if (jsFunction == null) { 1185 if (jsFunction == null) {
1182 return functionNoSuchMethod( 1186 return functionNoSuchMethod(
1183 function, positionalArguments, namedArguments); 1187 function, positionalArguments, namedArguments);
1184 } 1188 }
1185 ReflectionInfo info = new ReflectionInfo(jsFunction); 1189 ReflectionInfo info = new ReflectionInfo(jsFunction);
1186 if (info == null || !info.areOptionalParametersNamed) { 1190 if (info == null || !info.areOptionalParametersNamed) {
1187 return functionNoSuchMethod( 1191 return functionNoSuchMethod(
1188 function, positionalArguments, namedArguments); 1192 function, positionalArguments, namedArguments);
1189 } 1193 }
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 String propertyName) { 2067 String propertyName) {
2064 JS_EFFECT(() { 2068 JS_EFFECT(() {
2065 BoundClosure.receiverOf(JS('BoundClosure', 'void 0')); 2069 BoundClosure.receiverOf(JS('BoundClosure', 'void 0'));
2066 BoundClosure.selfOf(JS('BoundClosure', 'void 0')); 2070 BoundClosure.selfOf(JS('BoundClosure', 'void 0'));
2067 }); 2071 });
2068 // TODO(ahe): All the place below using \$ should be rewritten to go 2072 // TODO(ahe): All the place below using \$ should be rewritten to go
2069 // through the namer. 2073 // through the namer.
2070 var function = JS('', '#[#]', functions, 0); 2074 var function = JS('', '#[#]', functions, 0);
2071 String name = JS('String|Null', '#.\$stubName', function); 2075 String name = JS('String|Null', '#.\$stubName', function);
2072 String callName = JS('String|Null', '#[#]', function, 2076 String callName = JS('String|Null', '#[#]', function,
2073 JS_GET_NAME("CALL_NAME_PROPERTY")); 2077 JS_GET_NAME(JsGetName.CALL_NAME_PROPERTY));
2074 2078
2075 var functionType; 2079 var functionType;
2076 if (reflectionInfo is List) { 2080 if (reflectionInfo is List) {
2077 JS('', '#.\$reflectionInfo = #', function, reflectionInfo); 2081 JS('', '#.\$reflectionInfo = #', function, reflectionInfo);
2078 ReflectionInfo info = new ReflectionInfo(function); 2082 ReflectionInfo info = new ReflectionInfo(function);
2079 functionType = info.functionType; 2083 functionType = info.functionType;
2080 } else { 2084 } else {
2081 functionType = reflectionInfo; 2085 functionType = reflectionInfo;
2082 } 2086 }
2083 2087
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 } else { 2170 } else {
2167 throw 'Error in reflectionInfo.'; 2171 throw 'Error in reflectionInfo.';
2168 } 2172 }
2169 2173
2170 JS('', '#[#] = #', prototype, JS_SIGNATURE_NAME(), signatureFunction); 2174 JS('', '#[#] = #', prototype, JS_SIGNATURE_NAME(), signatureFunction);
2171 2175
2172 JS('', '#[#] = #', prototype, callName, trampoline); 2176 JS('', '#[#] = #', prototype, callName, trampoline);
2173 for (int i = 1; i < functions.length; i++) { 2177 for (int i = 1; i < functions.length; i++) {
2174 var stub = functions[i]; 2178 var stub = functions[i];
2175 var stubCallName = JS('String|Null', '#[#]', stub, 2179 var stubCallName = JS('String|Null', '#[#]', stub,
2176 JS_GET_NAME("CALL_NAME_PROPERTY")); 2180 JS_GET_NAME(JsGetName.CALL_NAME_PROPERTY));
2177 if (stubCallName != null) { 2181 if (stubCallName != null) {
2178 JS('', '#[#] = #', prototype, stubCallName, 2182 JS('', '#[#] = #', prototype, stubCallName,
2179 isStatic ? stub : forwardCallTo(receiver, stub, isIntercepted)); 2183 isStatic ? stub : forwardCallTo(receiver, stub, isIntercepted));
2180 } 2184 }
2181 } 2185 }
2182 2186
2183 JS('', '#[#] = #', prototype, JS_GET_NAME('CALL_CATCH_ALL'), trampoline); 2187 JS('', '#[#] = #', prototype, JS_GET_NAME(JsGetName.CALL_CATCH_ALL),
2184 String reqArgProperty = JS_GET_NAME("REQUIRED_PARAMETER_PROPERTY"); 2188 trampoline);
2185 String defValProperty = JS_GET_NAME("DEFAULT_VALUES_PROPERTY"); 2189 String reqArgProperty = JS_GET_NAME(JsGetName.REQUIRED_PARAMETER_PROPERTY);
2190 String defValProperty = JS_GET_NAME(JsGetName.DEFAULT_VALUES_PROPERTY);
2186 JS('', '#.# = #.#', prototype, reqArgProperty, function, reqArgProperty); 2191 JS('', '#.# = #.#', prototype, reqArgProperty, function, reqArgProperty);
2187 JS('', '#.# = #.#', prototype, defValProperty, function, defValProperty); 2192 JS('', '#.# = #.#', prototype, defValProperty, function, defValProperty);
2188 2193
2189 return constructor; 2194 return constructor;
2190 } 2195 }
2191 2196
2192 static cspForwardCall(int arity, bool isSuperCall, String stubName, 2197 static cspForwardCall(int arity, bool isSuperCall, String stubName,
2193 function) { 2198 function) {
2194 var getSelf = RAW_DART_FUNCTION_REF(BoundClosure.selfOf); 2199 var getSelf = RAW_DART_FUNCTION_REF(BoundClosure.selfOf);
2195 // Handle intercepted stub-names with the default slow case. 2200 // Handle intercepted stub-names with the default slow case.
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
3874 // This is a function that will return a helper function that does the 3879 // This is a function that will return a helper function that does the
3875 // iteration of the sync*. 3880 // iteration of the sync*.
3876 // 3881 //
3877 // Each invocation should give a body with fresh state. 3882 // Each invocation should give a body with fresh state.
3878 final dynamic /* js function */ _outerHelper; 3883 final dynamic /* js function */ _outerHelper;
3879 3884
3880 SyncStarIterable(this._outerHelper); 3885 SyncStarIterable(this._outerHelper);
3881 3886
3882 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); 3887 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper));
3883 } 3888 }
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