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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/js_runtime/lib/js_helper.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/js_helper.dart b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
index d6dd538c03993dd5d2a5ab8a739371179bf222af..48e1efa6f5aac001d6bc9918ec2e63201c860a0f 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_helper.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
@@ -2369,20 +2369,19 @@ invokeClosure(Function closure,
var arg2,
var arg3,
var arg4) {
- if (numberOfArguments == 0) {
- return JS_CALL_IN_ISOLATE(isolate, () => closure());
- } else if (numberOfArguments == 1) {
- return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1));
- } else if (numberOfArguments == 2) {
- return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2));
- } else if (numberOfArguments == 3) {
- return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3));
- } else if (numberOfArguments == 4) {
- return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3, arg4));
- } else {
- throw new Exception(
- 'Unsupported number of arguments for wrapped closure');
+ switch (numberOfArguments) {
+ case 0:
+ return JS_CALL_IN_ISOLATE(isolate, () => closure());
+ case 1:
+ return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1));
+ case 2:
+ return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2));
+ case 3:
+ return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3));
+ case 4:
+ return JS_CALL_IN_ISOLATE(isolate, () => closure(arg1, arg2, arg3, arg4));
}
+ throw new Exception('Unsupported number of arguments for wrapped closure');
}
/**
@@ -2394,21 +2393,18 @@ convertDartClosureToJS(closure, int arity) {
var function = JS('var', r'#.$identity', closure);
if (JS('bool', r'!!#', function)) return function;
- // We use $0 and $1 to not clash with variable names used by the
- // compiler and/or minifier.
- function = JS('var',
- '(function(closure, arity, context, invoke) {'
- ' return function(a1, a2, a3, a4) {'
- ' return invoke(closure, context, arity, a1, a2, a3, a4);'
- ' };'
- '})(#,#,#,#)',
- closure,
- arity,
- // Capture the current isolate now. Remember that "#"
- // in JS is simply textual substitution of compiled
- // expressions.
- JS_CURRENT_ISOLATE_CONTEXT(),
- DART_CLOSURE_TO_JS(invokeClosure));
+ function = JS(
+ 'var',
+ r'''
+ (function(closure, arity, context, invoke) {
+ return function(a1, a2, a3, a4) {
+ return invoke(closure, context, arity, a1, a2, a3, a4);
+ };
+ })(#,#,#,#)''',
+ closure,
+ arity,
+ JS_CURRENT_ISOLATE_CONTEXT(),
+ DART_CLOSURE_TO_JS(invokeClosure));
JS('void', r'#.$identity = #', closure, function);
return function;
« 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