forked from shaka-project/shaka-player
/
symbol.js
46 lines (39 loc) · 1.02 KB
/
symbol.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.polyfill.Symbol');
goog.require('shaka.log');
goog.require('shaka.polyfill');
/**
* @summary A polyfill to provide Symbol.prototype.description in all browsers.
* See: https://caniuse.com/mdn-javascript_builtins_symbol_description
* @export
*/
shaka.polyfill.Symbol = class {
/**
* Install the polyfill if needed.
* @export
*/
static install() {
shaka.log.debug('Symbol.install');
// eslint-disable-next-line no-restricted-syntax
const proto = Symbol.prototype;
if (!('description' in proto)) {
Object.defineProperty(proto, 'description', {
get: shaka.polyfill.Symbol.getSymbolDescription_,
});
}
}
/**
* @this {Symbol}
* @return {(string|undefined)}
* @private
*/
static getSymbolDescription_() {
const m = /\((.*)\)/.exec(this.toString());
return m ? m[1] : undefined;
}
};
shaka.polyfill.register(shaka.polyfill.Symbol.install);