Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML Reporter: Avoid leaking Map variable in older browsers #1509

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions reporter/es6-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Support IE 9-10, PhantomJS: Fallback for fuzzysort.js used by /reporter/html.js
// eslint-disable-next-line no-unused-vars
var Map = typeof Map === "function" ? Map : function StringMap() {
var store = Object.create( null );
this.get = function( strKey ) {
return store[ strKey ];
};
this.set = function( strKey, val ) {
store[ strKey ] = val;
return this;
};
this.clear = function() {
store = Object.create( null );
};
};
11 changes: 11 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */

const fs = require( "fs" );
const { babel } = require( "@rollup/plugin-babel" );
const { nodeResolve } = require( "@rollup/plugin-node-resolve" );
const commonjs = require( "@rollup/plugin-commonjs" );
Expand Down Expand Up @@ -28,6 +29,16 @@ module.exports = {
* Date: @DATE\n\
*/",

intro: function() {

// Define the (partial) ES6 Map polyfill for "fuzzysort".
// Per https://github.com/qunitjs/qunit/issues/1508:
// 1. Must not leak as global variable, since it's not full Map implementation.
// 2. Must be seen by fuzzysort as-is (e.g. not get renamed as normal
// variables in an imported file would be).
return fs.readFileSync( __dirname + "/reporter/es6-map.js", "utf-8" ).toString().trim();
},

globals: {
global: "(function() { return this; }())"
}
Expand Down
17 changes: 0 additions & 17 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,3 @@ export const localSessionStorage = ( function() {
return undefined;
}
}() );

// Support IE 9-10: Fallback for fuzzysort.js used by /reporter/html.js
if ( !global.Map ) {
global.Map = function StringMap() {
var store = Object.create( null );
this.get = function( strKey ) {
return store[ strKey ];
};
this.set = function( strKey, val ) {
store[ strKey ] = val;
return this;
};
this.clear = function() {
store = Object.create( null );
};
};
}