mirror of
https://github.com/videojs/video.js.git
synced 2025-03-17 21:18:27 +02:00
feat: don't throw when re-registering a plugin unless it's a player method (#4140)
This commit is contained in:
parent
0f57341e38
commit
326398d312
@ -5,6 +5,7 @@ import evented from './mixins/evented';
|
||||
import stateful from './mixins/stateful';
|
||||
import * as Events from './utils/events';
|
||||
import * as Fn from './utils/fn';
|
||||
import log from './utils/log';
|
||||
import Player from './player';
|
||||
|
||||
/**
|
||||
@ -305,8 +306,10 @@ class Plugin {
|
||||
throw new Error(`Illegal plugin name, "${name}", must be a string, was ${typeof name}.`);
|
||||
}
|
||||
|
||||
if (pluginExists(name) || Player.prototype.hasOwnProperty(name)) {
|
||||
throw new Error(`Illegal plugin name, "${name}", already exists.`);
|
||||
if (pluginExists(name)) {
|
||||
log.warn(`A plugin named "${name}" already exists. You may want to avoid re-registering plugins!`);
|
||||
} else if (Player.prototype.hasOwnProperty(name)) {
|
||||
throw new Error(`Illegal plugin name, "${name}", cannot share a name with an existing player method!`);
|
||||
}
|
||||
|
||||
if (typeof plugin !== 'function') {
|
||||
|
@ -1,4 +1,6 @@
|
||||
/* eslint-env qunit */
|
||||
import sinon from 'sinon';
|
||||
import log from '../../src/js/utils/log';
|
||||
import Player from '../../src/js/player';
|
||||
import Plugin from '../../src/js/plugin';
|
||||
|
||||
@ -53,12 +55,6 @@ QUnit.test('registerPlugin() illegal arguments', function(assert) {
|
||||
'plugins must have a name'
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => Plugin.registerPlugin('play'),
|
||||
new Error('Illegal plugin name, "play", already exists.'),
|
||||
'plugins cannot share a name with an existing player method'
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => Plugin.registerPlugin('foo'),
|
||||
new Error('Illegal plugin for "foo", must be a function, was undefined.'),
|
||||
@ -70,6 +66,18 @@ QUnit.test('registerPlugin() illegal arguments', function(assert) {
|
||||
new Error('Illegal plugin for "foo", must be a function, was object.'),
|
||||
'plugins must be functions'
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => Plugin.registerPlugin('play', function() {}),
|
||||
new Error('Illegal plugin name, "play", cannot share a name with an existing player method!'),
|
||||
'plugins must be functions'
|
||||
);
|
||||
|
||||
sinon.spy(log, 'warn');
|
||||
Plugin.registerPlugin('foo', function() {});
|
||||
Plugin.registerPlugin('foo', function() {});
|
||||
assert.strictEqual(log.warn.callCount, 1, 'warn on re-registering a plugin');
|
||||
log.warn.restore();
|
||||
});
|
||||
|
||||
QUnit.test('getPlugin()', function(assert) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user