[dartdevc] Using hasOwnProperty instead of getOwnPropertyDescriptor.value.

getOwnPropertyDescriptor is significantly slower than hasOwnProperty, and we didn't seem to be using any behavior specific to the descriptor besides the value.

Change-Id: I3329177ee78a5ca823e554dd4f7b0bd26e1d5be0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138331
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Mark Zhou 2020-03-04 20:26:06 +00:00 committed by commit-bot@chromium.org
parent 6f4876849b
commit c426b60da4
2 changed files with 12 additions and 4 deletions

View file

@ -53,9 +53,13 @@ Iterable getOwnNamesAndSymbols(obj) {
return JS('', '#.concat(#)', names, symbols);
}
/// Returns the value of field `name` on `obj`.
///
/// We use this instead of obj[name] since obj[name] checks the entire
/// prototype chain instead of just `obj`.
safeGetOwnProperty(obj, name) {
var desc = getOwnPropertyDescriptor(obj, name);
if (desc != null) return JS('', '#.value', desc);
if (JS<bool>('!', '#.hasOwnProperty(#)', obj, name))
return JS<Object>('', '#[#]', obj, name);
}
/// Defines a lazy static field.

View file

@ -51,9 +51,13 @@ Iterable getOwnNamesAndSymbols(obj) {
return JS('', '#.concat(#)', names, symbols);
}
/// Returns the value of field `name` on `obj`.
///
/// We use this instead of obj[name] since obj[name] checks the entire
/// prototype chain instead of just `obj`.
safeGetOwnProperty(obj, name) {
var desc = getOwnPropertyDescriptor(obj, name);
if (desc != null) return JS('', '#.value', desc);
if (JS<bool>('!', '#.hasOwnProperty(#)', obj, name))
return JS<Object>('', '#[#]', obj, name);
}
/// Defines a lazy static field.