Skip to content

Commit

Permalink
Merge pull request #5380 from plotly/cleanup-IE9-IE10-fallbacks
Browse files Browse the repository at this point in the history
Cleanup unused IE9 and IE10 fallbacks
  • Loading branch information
archmoj authored Jan 8, 2021
2 parents c7e5a22 + db453ef commit f502d3d
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 179 deletions.
11 changes: 2 additions & 9 deletions src/lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@

var isArray = Array.isArray;

// IE9 fallbacks

var ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ?
{isView: function() { return false; }} :
ArrayBuffer;

var dv = (typeof DataView === 'undefined') ?
function() {} :
DataView;
var ab = ArrayBuffer;
var dv = DataView;

function isTypedArray(a) {
return ab.isView(a) && !(a instanceof dv);
Expand Down
11 changes: 1 addition & 10 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,6 @@ lib.isIE = function() {
return typeof window.navigator.msSaveBlob !== 'undefined';
};

var IS_IE9_OR_BELOW_REGEX = /MSIE [1-9]\./;
lib.isIE9orBelow = function() {
return lib.isIE() && IS_IE9_OR_BELOW_REGEX.test(window.navigator.userAgent);
};

var IS_SAFARI_REGEX = /Version\/[\d\.]+.*Safari/;
lib.isSafari = function() {
return IS_SAFARI_REGEX.test(window.navigator.userAgent);
Expand All @@ -727,12 +722,8 @@ lib.isIOS = function() {
return IS_IOS_REGEX.test(window.navigator.userAgent);
};

/**
* Duck typing to recognize a d3 selection, mostly for IE9's benefit
* because it doesn't handle instanceof like modern browsers
*/
lib.isD3Selection = function(obj) {
return obj && (typeof obj.classed === 'function');
return obj instanceof d3.selection;
};

/**
Expand Down
31 changes: 3 additions & 28 deletions src/lib/loggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ loggers.log = function() {
for(i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}
apply(console.trace || console.log, messages);
console.trace.apply(console, messages);
}

if(dfltConfig.notifyOnLogging > 1) {
Expand All @@ -50,7 +50,7 @@ loggers.warn = function() {
for(i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}
apply(console.trace || console.log, messages);
console.trace.apply(console, messages);
}

if(dfltConfig.notifyOnLogging > 0) {
Expand All @@ -70,7 +70,7 @@ loggers.error = function() {
for(i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}
apply(console.error, messages);
console.error.apply(console, messages);
}

if(dfltConfig.notifyOnLogging > 0) {
Expand All @@ -81,28 +81,3 @@ loggers.error = function() {
notifier(lines.join('<br>'), 'stick');
}
};

/*
* Robust apply, for IE9 where console.log doesn't support
* apply like other functions do
*/
function apply(f, args) {
if(f && f.apply) {
try {
// `this` should always be console, since here we're always
// applying a method of the console object.
f.apply(console, args);
return;
} catch(e) { /* in case apply failed, fall back on the code below */ }
}

// no apply - just try calling the function on each arg independently
for(var i = 0; i < args.length; i++) {
try {
f(args[i]);
} catch(e) {
// still fails - last resort simple console.log
console.log(args[i]);
}
}
}
4 changes: 0 additions & 4 deletions src/snapshot/filesaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ function fileSaver(url, name, format) {
var blob;
var objectUrl;

if(Lib.isIE9orBelow()) {
reject(new Error('IE < 10 unsupported'));
}

// Safari doesn't allow downloading of blob urls
if(Lib.isSafari()) {
var prefix = format === 'svg' ? ',' : ';base64,';
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot/svgtoimg.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function svgToImg(opts) {
var img = new Image();
var svgBlob, url;

if(format === 'svg' || Lib.isIE9orBelow() || Lib.isSafari()) {
if(format === 'svg' || Lib.isSafari()) {
url = helpers.encodeSVG(svg);
} else {
svgBlob = helpers.createBlob(svg, 'svg');
Expand Down
2 changes: 2 additions & 0 deletions src/snapshot/tosvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ module.exports = function toSVG(gd, format, scale) {
// Fix quotations around font strings and gradient URLs
s = s.replace(DUMMY_REGEX, '\'');

// Do we need this process now that IE9 and IE10 are not supported?

// IE is very strict, so we will need to clean
// svg with the following regex
// yes this is messy, but do not know a better way
Expand Down
1 change: 1 addition & 0 deletions test/image/strict-d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* strict-d3: wrap selection.style to prohibit specific incorrect style values
* that are known to cause problems in IE (at least IE9)
*/

'use strict';

var d3 = require('@plotly/d3');
Expand Down
42 changes: 0 additions & 42 deletions test/jasmine/bundle_tests/ie9_test.js

This file was deleted.

11 changes: 0 additions & 11 deletions test/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ if(argv.info) {
'Run all tests with the `noCI` tag on Firefox in a 1500px wide window:',
' $ npm run test-jasmine -- --tags=noCI --FF --width=1500',
'',
'Run the `ie9_test.js` bundle test with the verbose reporter:',
' $ npm run test-jasmine -- --bundleTest=ie9 --verbose',
'',
'Arguments:',
' - All non-flagged arguments corresponds to the test suites in `test/jasmine/tests/` to be run.',
' No need to add the `_test.js` suffix, we expand them correctly here.',
Expand Down Expand Up @@ -122,7 +119,6 @@ if(isFullSuite) {
var pathToShortcutPath = path.join(__dirname, '..', '..', 'tasks', 'util', 'shortcut_paths.js');
var pathToStrictD3 = path.join(__dirname, '..', '..', 'tasks', 'util', 'strict_d3.js');
var pathToJQuery = path.join(__dirname, 'assets', 'jquery-1.8.3.min.js');
var pathToIE9mock = path.join(__dirname, 'assets', 'ie9_mock.js');
var pathToCustomMatchers = path.join(__dirname, 'assets', 'custom_matchers.js');
var pathToUnpolyfill = path.join(__dirname, 'assets', 'unpolyfill.js');
var pathToMathJax = path.join(constants.pathToDist, 'extras', 'mathjax');
Expand Down Expand Up @@ -323,13 +319,6 @@ if(isBundleTest) {
func.defaultConfig.files.push(constants.pathToPlotlyDistMin);
func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
break;
case 'ie9':
// load ie9_mock.js before plotly.js+test bundle
// to catch reference errors that could occur
// when plotly.js is first loaded.
func.defaultConfig.files.push(pathToIE9mock);
func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
break;
case 'plotschema':
func.defaultConfig.browserify.ignoreTransform = './tasks/compress_attributes.js';
func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
Expand Down
84 changes: 10 additions & 74 deletions test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1643,10 +1643,7 @@ describe('Test lib.js:', function() {
// this is what got us into trouble actually - d3 selections can
// contain non-nodes - say for example d3 selections! then they
// don't work correctly. But it makes a convenient test!
d3.select(1),
// just showing what we actually do in this function: duck type
// using the `classed` method.
{classed: function(v) { return !!v; }}
d3.select(1)
];

yesSelections.forEach(function(v) {
Expand Down Expand Up @@ -1675,28 +1672,25 @@ describe('Test lib.js:', function() {
var stashLogLevel;
var stashOnGraphLogLevel;

function consoleFn(name, hasApply, messages) {
function consoleFn(name, messages) {
var out = function() {
if(hasApply) expect(this).toBe(window.console);
var args = [];
for(var i = 0; i < arguments.length; i++) args.push(arguments[i]);
messages.push([name, args]);
};

if(!hasApply) out.apply = undefined;

return out;
}

function mockConsole(hasApply, hasTrace, hasError) {
function mockConsole() {
var out = {
MESSAGES: []
};
out.log = consoleFn('log', hasApply, out.MESSAGES);
out.log = consoleFn('log', out.MESSAGES);

if(hasError) out.error = consoleFn('error', hasApply, out.MESSAGES);
out.error = consoleFn('error', out.MESSAGES);

if(hasTrace) out.trace = consoleFn('trace', hasApply, out.MESSAGES);
out.trace = consoleFn('trace', out.MESSAGES);

return out;
}
Expand All @@ -1713,8 +1707,8 @@ describe('Test lib.js:', function() {
config.notifyOnLogging = stashOnGraphLogLevel;
});

it('emits one console message if apply is available', function() {
var c = window.console = mockConsole(true, true, true);
it('emits one console message', function() {
var c = window.console = mockConsole();
config.logging = 2;

Lib.log('tick', 'tock', 'tick', 'tock', 1);
Expand All @@ -1728,50 +1722,8 @@ describe('Test lib.js:', function() {
]);
});

it('falls back on console.log if no trace', function() {
var c = window.console = mockConsole(true, false, true);
config.logging = 2;

Lib.log('Hi');
Lib.warn(42);

expect(c.MESSAGES).toEqual([
['log', ['LOG:', 'Hi']],
['log', ['WARN:', 42]]
]);
});

it('falls back on separate calls if no apply', function() {
var c = window.console = mockConsole(false, false, true);
config.logging = 2;

Lib.log('tick', 'tock', 'tick', 'tock', 1);
Lib.warn('I\'m', 'a', 'little', 'cuckoo', 'clock', [1, 2]);
Lib.error('cuckoo!', 'cuckoo!!!', {a: 1, b: 2});

expect(c.MESSAGES).toEqual([
['log', ['LOG:']],
['log', ['tick']],
['log', ['tock']],
['log', ['tick']],
['log', ['tock']],
['log', [1]],
['log', ['WARN:']],
['log', ['I\'m']],
['log', ['a']],
['log', ['little']],
['log', ['cuckoo']],
['log', ['clock']],
['log', [[1, 2]]],
['error', ['ERROR:']],
['error', ['cuckoo!']],
['error', ['cuckoo!!!']],
['error', [{a: 1, b: 2}]]
]);
});

it('omits .log at log level 1', function() {
var c = window.console = mockConsole(true, true, true);
var c = window.console = mockConsole();
config.logging = 1;

Lib.log(1);
Expand All @@ -1785,7 +1737,7 @@ describe('Test lib.js:', function() {
});

it('logs nothing at log level 0', function() {
var c = window.console = mockConsole(true, true, true);
var c = window.console = mockConsole();
config.logging = 0;

Lib.log(1);
Expand All @@ -1795,22 +1747,6 @@ describe('Test lib.js:', function() {
expect(c.MESSAGES).toEqual([]);
});

it('falls back on simple log if there is no console.error', function() {
// TODO

var c = window.console = mockConsole(true, true, false);
config.logging = 2;

Lib.error('who are you', 'who who... are you', {a: 1, b: 2});

expect(c.MESSAGES).toEqual([
['log', ['ERROR:']],
['log', ['who are you']],
['log', ['who who... are you']],
['log', [{a: 1, b: 2}]]
]);
});

describe('should log message in notifier div in accordance notifyOnLogging config option', function() {
var query = '.notifier-note';

Expand Down

0 comments on commit f502d3d

Please sign in to comment.