Skip to content

Commit

Permalink
Validate container option in map constructor (#5695)
Browse files Browse the repository at this point in the history
* Validate container option

* import HTMLElement
  • Loading branch information
jingsam authored and mollymerp committed Nov 21, 2017
1 parent fc4bf61 commit 3a0af63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions flow-typed/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ declare interface Window extends EventTarget, IDBEnvironment {

Blob: typeof Blob;
HTMLImageElement: typeof HTMLImageElement;
HTMLElement: typeof HTMLElement;
HTMLVideoElement: typeof HTMLVideoElement;
HTMLCanvasElement: typeof HTMLCanvasElement;
Image: typeof Image;
Expand Down
6 changes: 4 additions & 2 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const util = require('../util/util');
const browser = require('../util/browser');
const window = require('../util/window');
const {HTMLImageElement} = require('../util/window');
const {HTMLImageElement, HTMLElement} = require('../util/window');
const DOM = require('../util/dom');
const ajax = require('../util/ajax');

Expand Down Expand Up @@ -280,8 +280,10 @@ class Map extends Camera {
} else {
this._container = container;
}
} else {
} else if (options.container instanceof HTMLElement) {
this._container = options.container;
} else {
throw new Error(`Invalid type: 'container' must be a String or HTMLElement.`);
}

if (options.maxBounds) {
Expand Down

0 comments on commit 3a0af63

Please sign in to comment.