Index: pkg/dev_compiler/tool/input_sdk/private/js_array.dart |
diff --git a/pkg/dev_compiler/tool/input_sdk/private/js_array.dart b/pkg/dev_compiler/tool/input_sdk/private/js_array.dart |
index dc9564eb0e507b5343d63b1585d9d1f4a308ea70..260f58d79819ec38525a6180cb72b3fb9d81586c 100644 |
--- a/pkg/dev_compiler/tool/input_sdk/private/js_array.dart |
+++ b/pkg/dev_compiler/tool/input_sdk/private/js_array.dart |
@@ -558,15 +558,22 @@ class JSArray<E> implements List<E>, JSIndexable<E> { |
} |
E operator [](int index) { |
- if (index is! int) throw diagnoseIndexError(this, index); |
- if (index >= length || index < 0) throw diagnoseIndexError(this, index); |
+ // Suppress redundant null checks via JS. |
+ if (index == null || |
ochafik
2017/06/08 17:23:08
I wonder how hard it would be to implement naive f
|
+ JS('int', '#', index) >= JS('int', '#.length', this) || |
+ JS('int', '#', index) < 0) { |
+ throw diagnoseIndexError(this, index); |
+ } |
return JS('var', '#[#]', this, index); |
} |
void operator []=(int index, E value) { |
checkMutable('indexed set'); |
- if (index is! int) throw diagnoseIndexError(this, index); |
- if (index >= length || index < 0) throw diagnoseIndexError(this, index); |
+ if (index == null || |
+ JS('int', '#', index) >= JS('int', '#.length', this) || |
+ JS('int', '#', index) < 0) { |
+ throw diagnoseIndexError(this, index); |
+ } |
JS('void', r'#[#] = #', this, index, value); |
} |