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

Side by Side Diff: sdk/lib/_internal/js_runtime/lib/js_helper.dart

Issue 1539033002: js_runtime tweaks for better code (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/constant_map.dart ('k') | no next file » | 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) 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:_js_embedded_names' show 7 import 'dart:_js_embedded_names' show
8 DEFERRED_LIBRARY_URIS, 8 DEFERRED_LIBRARY_URIS,
9 DEFERRED_LIBRARY_HASHES, 9 DEFERRED_LIBRARY_HASHES,
10 GET_TYPE_FROM_NAME, 10 GET_TYPE_FROM_NAME,
(...skipping 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 return result; 2362 return result;
2363 } 2363 }
2364 2364
2365 invokeClosure(Function closure, 2365 invokeClosure(Function closure,
2366 var isolate, 2366 var isolate,
2367 int numberOfArguments, 2367 int numberOfArguments,
2368 var arg1, 2368 var arg1,
2369 var arg2, 2369 var arg2,
2370 var arg3, 2370 var arg3,
2371 var arg4) { 2371 var arg4) {
2372 if (numberOfArguments == 0) { 2372 switch (numberOfArguments) {
2373 return JS_CALL_IN_ISOLATE(isolate, () => closure()); 2373 case 0:
2374 } else if (numberOfArguments == 1) { 2374 return JS_CALL_IN_ISOLATE(isolate, () => closure());
2375 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1)); 2375 case 1:
2376 } else if (numberOfArguments == 2) { 2376 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1));
2377 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2)); 2377 case 2:
2378 } else if (numberOfArguments == 3) { 2378 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2));
2379 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3)); 2379 case 3:
2380 } else if (numberOfArguments == 4) { 2380 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3));
2381 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3, arg4)); 2381 case 4:
2382 } else { 2382 return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3, arg4));
2383 throw new Exception(
2384 'Unsupported number of arguments for wrapped closure');
2385 } 2383 }
2384 throw new Exception('Unsupported number of arguments for wrapped closure');
2386 } 2385 }
2387 2386
2388 /** 2387 /**
2389 * Called by generated code to convert a Dart closure to a JS 2388 * Called by generated code to convert a Dart closure to a JS
2390 * closure when the Dart closure is passed to the DOM. 2389 * closure when the Dart closure is passed to the DOM.
2391 */ 2390 */
2392 convertDartClosureToJS(closure, int arity) { 2391 convertDartClosureToJS(closure, int arity) {
2393 if (closure == null) return null; 2392 if (closure == null) return null;
2394 var function = JS('var', r'#.$identity', closure); 2393 var function = JS('var', r'#.$identity', closure);
2395 if (JS('bool', r'!!#', function)) return function; 2394 if (JS('bool', r'!!#', function)) return function;
2396 2395
2397 // We use $0 and $1 to not clash with variable names used by the 2396 function = JS(
2398 // compiler and/or minifier. 2397 'var',
2399 function = JS('var', 2398 r'''
2400 '(function(closure, arity, context, invoke) {' 2399 (function(closure, arity, context, invoke) {
2401 ' return function(a1, a2, a3, a4) {' 2400 return function(a1, a2, a3, a4) {
2402 ' return invoke(closure, context, arity, a1, a2, a3, a4);' 2401 return invoke(closure, context, arity, a1, a2, a3, a4);
2403 ' };' 2402 };
2404 '})(#,#,#,#)', 2403 })(#,#,#,#)''',
2405 closure, 2404 closure,
2406 arity, 2405 arity,
2407 // Capture the current isolate now. Remember that "#" 2406 JS_CURRENT_ISOLATE_CONTEXT(),
2408 // in JS is simply textual substitution of compiled 2407 DART_CLOSURE_TO_JS(invokeClosure));
2409 // expressions.
2410 JS_CURRENT_ISOLATE_CONTEXT(),
2411 DART_CLOSURE_TO_JS(invokeClosure));
2412 2408
2413 JS('void', r'#.$identity = #', closure, function); 2409 JS('void', r'#.$identity = #', closure, function);
2414 return function; 2410 return function;
2415 } 2411 }
2416 2412
2417 /** 2413 /**
2418 * Super class for Dart closures. 2414 * Super class for Dart closures.
2419 */ 2415 */
2420 abstract class Closure implements Function { 2416 abstract class Closure implements Function {
2421 // TODO(ahe): These constants must be in sync with 2417 // TODO(ahe): These constants must be in sync with
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 // unneeded code. 4072 // unneeded code.
4077 class _UnreachableError extends AssertionError { 4073 class _UnreachableError extends AssertionError {
4078 _UnreachableError(); 4074 _UnreachableError();
4079 String toString() => "Assertion failed: Reached dead code"; 4075 String toString() => "Assertion failed: Reached dead code";
4080 } 4076 }
4081 4077
4082 @NoInline() 4078 @NoInline()
4083 void assertUnreachable() { 4079 void assertUnreachable() {
4084 throw new _UnreachableError(); 4080 throw new _UnreachableError();
4085 } 4081 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/constant_map.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698