Skip to content

Commit 4bea796

Browse files
mattrberryCommit Queue
authored and
Commit Queue
committed
[js_runtime/js_dev_runtime] Prefer Array.isArray over checking prototype
Closes #54990 GitOrigin-RevId: 9c51a86 Change-Id: I4b74f3762ec720b0204331d0945da046be99ba33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353784 Reviewed-by: Sigmund Cherem <[email protected]> Reviewed-by: Stephen Adams <[email protected]> Commit-Queue: Sigmund Cherem <[email protected]>
1 parent 792d500 commit 4bea796

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

sdk/lib/_internal/js_dev_runtime/patch/convert_patch.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ _convertJsonToDart(json, reviver(Object? key, Object? value)) {
5454
return e;
5555
}
5656

57-
// This test is needed to avoid identifying '{"__proto__":[]}' as an Array.
58-
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
59-
// bug 621 below is fixed.
60-
if (JS<bool>('!', 'Object.getPrototypeOf(#) === Array.prototype', e)) {
57+
if (JS<bool>('!', 'Array.isArray(#)', e)) {
6158
// In-place update of the elements since JS Array is a Dart List.
6259
for (int i = 0; i < JS<int>('!', '#.length', e); i++) {
6360
// Use JS indexing to avoid range checks. We know this is the only
@@ -99,10 +96,7 @@ _convertJsonToDartLazy(object) {
9996
return object;
10097
}
10198

102-
// This test is needed to avoid identifying '{"__proto__":[]}' as an array.
103-
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
104-
// bug https://code.google.com/p/v8/issues/detail?id=621 is fixed.
105-
if (JS<bool>('!', 'Object.getPrototypeOf(#) !== Array.prototype', object)) {
99+
if (JS<bool>('!', '!Array.isArray(#)', object)) {
106100
return _JsonMap(object);
107101
}
108102

sdk/lib/_internal/js_runtime/lib/convert_patch.dart

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ _convertJsonToDart(json, reviver(Object? key, Object? value)) {
5454
return e;
5555
}
5656

57-
// This test is needed to avoid identifying '{"__proto__":[]}' as an Array.
58-
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
59-
// bug 621 below is fixed.
60-
if (JS<bool>('bool', 'Object.getPrototypeOf(#) === Array.prototype', e)) {
57+
if (JS<bool>('bool', 'Array.isArray(#)', e)) {
6158
// In-place update of the elements since JS Array is a Dart List.
6259
for (int i = 0; i < JS<int>('int', '#.length', e); i++) {
6360
// Use JS indexing to avoid range checks. We know this is the only
@@ -99,11 +96,7 @@ _convertJsonToDartLazy(object) {
9996
return object;
10097
}
10198

102-
// This test is needed to avoid identifying '{"__proto__":[]}' as an array.
103-
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
104-
// bug https://code.google.com/p/v8/issues/detail?id=621 is fixed.
105-
if (JS<bool>(
106-
'bool', 'Object.getPrototypeOf(#) !== Array.prototype', object)) {
99+
if (JS<bool>('bool', '!Array.isArray(#)', object)) {
107100
return _JsonMap(object);
108101
}
109102

0 commit comments

Comments
 (0)