mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 19:21:30 +00:00
[js_runtime/js_dev_runtime] Prefer Array.isArray over checking prototype
Closes https://github.com/dart-lang/sdk/pull/54990 GitOrigin-RevId: 9c51a86c10e70c5f92e8b72894f8d3de138cd17b Change-Id: I4b74f3762ec720b0204331d0945da046be99ba33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353784 Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
792d5005f5
commit
4bea796167
|
@ -54,10 +54,7 @@ _convertJsonToDart(json, reviver(Object? key, Object? value)) {
|
|||
return e;
|
||||
}
|
||||
|
||||
// This test is needed to avoid identifying '{"__proto__":[]}' as an Array.
|
||||
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
|
||||
// bug 621 below is fixed.
|
||||
if (JS<bool>('!', 'Object.getPrototypeOf(#) === Array.prototype', e)) {
|
||||
if (JS<bool>('!', 'Array.isArray(#)', e)) {
|
||||
// In-place update of the elements since JS Array is a Dart List.
|
||||
for (int i = 0; i < JS<int>('!', '#.length', e); i++) {
|
||||
// Use JS indexing to avoid range checks. We know this is the only
|
||||
|
@ -99,10 +96,7 @@ _convertJsonToDartLazy(object) {
|
|||
return object;
|
||||
}
|
||||
|
||||
// This test is needed to avoid identifying '{"__proto__":[]}' as an array.
|
||||
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
|
||||
// bug https://code.google.com/p/v8/issues/detail?id=621 is fixed.
|
||||
if (JS<bool>('!', 'Object.getPrototypeOf(#) !== Array.prototype', object)) {
|
||||
if (JS<bool>('!', '!Array.isArray(#)', object)) {
|
||||
return _JsonMap(object);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,10 +54,7 @@ _convertJsonToDart(json, reviver(Object? key, Object? value)) {
|
|||
return e;
|
||||
}
|
||||
|
||||
// This test is needed to avoid identifying '{"__proto__":[]}' as an Array.
|
||||
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
|
||||
// bug 621 below is fixed.
|
||||
if (JS<bool>('bool', 'Object.getPrototypeOf(#) === Array.prototype', e)) {
|
||||
if (JS<bool>('bool', 'Array.isArray(#)', e)) {
|
||||
// In-place update of the elements since JS Array is a Dart List.
|
||||
for (int i = 0; i < JS<int>('int', '#.length', e); i++) {
|
||||
// Use JS indexing to avoid range checks. We know this is the only
|
||||
|
@ -99,11 +96,7 @@ _convertJsonToDartLazy(object) {
|
|||
return object;
|
||||
}
|
||||
|
||||
// This test is needed to avoid identifying '{"__proto__":[]}' as an array.
|
||||
// TODO(sra): Replace this test with cheaper '#.constructor === Array' when
|
||||
// bug https://code.google.com/p/v8/issues/detail?id=621 is fixed.
|
||||
if (JS<bool>(
|
||||
'bool', 'Object.getPrototypeOf(#) !== Array.prototype', object)) {
|
||||
if (JS<bool>('bool', '!Array.isArray(#)', object)) {
|
||||
return _JsonMap(object);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue