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

Unified Diff: sdk/lib/_internal/js_runtime/lib/js_array.dart

Issue 1629553002: List constructor sentinel must not implement 'int' (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/core_patch.dart ('k') | tests/lib/mirrors/constructor_list_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/js_runtime/lib/js_array.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/js_array.dart b/sdk/lib/_internal/js_runtime/lib/js_array.dart
index 78e53b1539a43fd9bdaa48ad2c259d8e774c9039..004127bc9cd29cc1d77ff7447e27194975b7e4f0 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_array.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_array.dart
@@ -4,6 +4,11 @@
part of _interceptors;
+class _Growable {
+ const _Growable();
+}
+const _ListConstructorSentinel = const _Growable();
+
/**
* The interceptor class for [List]. The compiler recognizes this
* class as an interceptor, and changes references to [:this:] to
@@ -14,6 +19,16 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable {
const JSArray();
+ // This factory constructor is the redirection target of the List() factory
+ // constructor. [length] has no type to permit the sentinel value.
+ factory JSArray.list([length = _ListConstructorSentinel]) {
+ if (_ListConstructorSentinel == length) {
+ return new JSArray<E>.emptyGrowable();
+ }
+ return new JSArray<E>.fixed(length);
+ }
+
+
/**
* Returns a fresh JavaScript Array, marked as fixed-length.
*
@@ -21,7 +36,8 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable {
*/
factory JSArray.fixed(int length) {
// Explicit type test is necessary to guard against JavaScript conversions
- // in unchecked mode.
+ // in unchecked mode, and against `new Array(null)` which creates a single
+ // element Array containing `null`.
if (length is !int) {
throw new ArgumentError.value(length, "length", "is not an integer");
}
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/core_patch.dart ('k') | tests/lib/mirrors/constructor_list_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698