Skip to content

Enforce is-plain-object #792

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

Merged
merged 2 commits into from
Jul 29, 2016
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
7 changes: 3 additions & 4 deletions src/components/colorbar/has_colorbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

'use strict';

var Lib = require('../../lib');


module.exports = function hasColorbar(container) {
return (
typeof container.colorbar === 'object' &&
container.colorbar !== null
);
return Lib.isPlainObject(container.colorbar);
};
4 changes: 2 additions & 2 deletions src/components/colorscale/has_colorscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ module.exports = function hasColorscale(trace, containerStr) {
}

return (
(typeof container === 'object' && container !== null) && (
Lib.isPlainObject(container) && (
isArrayWithOneNumber ||
container.showscale === true ||
(isNumeric(container.cmin) && isNumeric(container.cmax)) ||
isValidScale(container.colorscale) ||
(typeof container.colorbar === 'object' && container.colorbar !== null)
Lib.isPlainObject(container.colorbar)
)
);
};
3 changes: 1 addition & 2 deletions src/components/rangeslider/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ var attributes = require('./attributes');


module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, axName, counterAxes) {

if(!layoutIn[axName].rangeslider) return;

var containerIn = typeof layoutIn[axName].rangeslider === 'object' ?
var containerIn = Lib.isPlainObject(layoutIn[axName].rangeslider) ?
layoutIn[axName].rangeslider : {},
containerOut = layoutOut[axName].rangeslider = {};

Expand Down
9 changes: 9 additions & 0 deletions src/lib/is_plain_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@

// more info: http://stackoverflow.com/questions/18531624/isplainobject-thing
module.exports = function isPlainObject(obj) {

// We need to be a little less strict in the `imagetest` container because
// of how async image requests are handled.
//
// N.B. isPlainObject(new Constructor()) will return true in `imagetest`
if(window && window.process && window.process.versions) {
return Object.prototype.toString.call(obj) === '[object Object]';
}

return (
Object.prototype.toString.call(obj) === '[object Object]' &&
Object.getPrototypeOf(obj) === Object.prototype
Expand Down
5 changes: 1 addition & 4 deletions src/plots/mapbox/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,8 @@ proto.dispose = function dispose() {
function isVisible(opts) {
var source = opts.source;

// For some weird reason Lib.isPlainObject fails
// to detect `source` as a plain object in nw.js 0.12.

return (
typeof source === 'object' ||
Lib.isPlainObject(source) ||
(typeof source === 'string' && source.length > 0)
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/traces/scatter/subtypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

'use strict';

var Lib = require('../../lib');

module.exports = {
hasLines: function(trace) {
return trace.visible && trace.mode &&
Expand All @@ -26,7 +28,7 @@ module.exports = {
},

isBubble: function(trace) {
return (typeof trace.marker === 'object' &&
Array.isArray(trace.marker.size));
return Lib.isPlainObject(trace.marker) &&
Array.isArray(trace.marker.size);
}
};