Page MenuHomePhabricator

Provide a polyfill for Object.values in core for IE compatibility
Closed, DeclinedPublic

Description

As discussed on IRC, this is something MW core should provide.

Event Timeline

ashley created this task.Jun 28 2020, 11:38 AM
Restricted Application added a project: User-DannyS712. · View Herald TranscriptJun 28 2020, 11:38 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
DannyS712 added a comment.EditedJun 28 2020, 12:15 PM

So here is what I have:

Object.values = function ( obj ) {
    return Object.keys( obj ).map( function ( key ) {
        return obj[ key ];
    } );
};

or

Minified
Object.values = function(o){return Object.keys(o).map(function(k){return o[k];});};

You can test this by using values2 instead, and then comparing the result of Object.values and Object.values2:

[ true, false, 1, 0, -1, 'yes', 'no', [], [ 'e' ], { e: 'f' }, Date, Promise ].forEach( function ( element ) {
    console.log( element, Object.values( element ), Object.values2( element ) );
} );

They all return the same

Should this wait for mediawiki 1.36 to be added?

Assuming this task is about the MediaWiki core project, hence adding that project tag so other people could also find this task when searching via projects.

Change 608479 had a related patch set uploaded (by DannyS712; owner: DannyS712):
[mediawiki/core@master] Add a polyfill for Object.values

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /608479

Restricted Application added a project: Performance-Team. · View Herald TranscriptJun 30 2020, 4:22 PM
Krinkle triaged this task as Medium priority.Jun 30 2020, 4:22 PM
Krinkle moved this task from Inbox to Backlog on the MediaWiki-ResourceLoader board.
ES6
for ( let value of Object.values( obj ) ) {
  console.log( value );
}
ES5
for ( var key in obj ) {
  console.log( obj[ key ] );
}

These are not 100% equivalent, but for most cases this is how you'd use them. What problem is this meant to solve?

ES6
for ( let value of Object.values( obj ) ) {
  console.log( value );
}
ES5
for ( var key in obj ) {
  console.log( obj[ key ] );
}

These are not 100% equivalent, but for most cases this is how you'd use them. What problem is this meant to solve?

In one of my patches for MediaWiki-extensions-GlobalWatchlist I had to rewrite it a bit because Object.values was prohibited, and after discussing it with @ashley I suggested that it be added as a core polyfill

Krinkle closed this task as Declined.Jul 1 2020, 8:23 PM

Change 608479 abandoned by DannyS712:
Add a polyfill for Object.values

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /608479