diff --git a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart index c691cfd5e1d..5d5a251af88 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart @@ -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('!', '#.hasOwnProperty(#)', obj, name)) + return JS('', '#[#]', obj, name); } /// Defines a lazy static field. diff --git a/sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart b/sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart index c763ada3c61..6a1472f561c 100644 --- a/sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart +++ b/sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart @@ -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('!', '#.hasOwnProperty(#)', obj, name)) + return JS('', '#[#]', obj, name); } /// Defines a lazy static field.