Passed
Branch v15.x (8faa65)
by Rafael S.
02:24
created

scripts/polyfills.js   A

Complexity

Total Complexity 16
Complexity/F 5.33

Size

Lines of Code 47
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 31
nc 85
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 16
mnd 3
bc 14
fnc 3
bpm 4.6666
cpm 5.3333
noi 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
B Object.defineProperty 0 16 8
A Object.getOwnPropertyDescriptor 0 23 4
A 0 1 1
1
/*!
2
 * @fileoverview Polyfills for old browsers.
3
 * @see https://github.com/inexorabletash/polyfill/blob/master/es5.js
4
 * @see https://gist.github.com/jhermsmeier/9a34b06a107bbf5d2c91
5
 */
6
7
// ES 15.2.3.6 Object.defineProperty ( O, P, Attributes )
8
// Partial support for most common case - getters, setters, and values 
9
if (!Object.defineProperty ||
10
    !(function () { try { Object.defineProperty({}, 'x', {}); return true; } catch (e) { return false; } } ())) {
11
  var orig = Object.defineProperty;
12
  Object.defineProperty = function (o, prop, desc) {
0 ignored issues
show
Compatibility Best Practice introduced by
You are extending the built-in type Object. This may have unintended consequences on other objects using this built-in type. Consider subclassing instead.
Loading history...
13
    // In IE8 try built-in implementation for defining properties on DOM prototypes.
14
    if (orig) { try { return orig(o, prop, desc); } catch (e) {} }
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
15
16
    if (o !== Object(o)) { throw TypeError("Object.defineProperty called on non-object"); }
17
    if (Object.prototype.__defineGetter__ && ('get' in desc)) {
18
      Object.prototype.__defineGetter__.call(o, prop, desc.get);
19
    }
20
    if (Object.prototype.__defineSetter__ && ('set' in desc)) {
21
      Object.prototype.__defineSetter__.call(o, prop, desc.set);
22
    }
23
    if ('value' in desc) {
24
      o[prop] = desc.value;
25
    }
26
    return o;
27
  };
28
}
29
30
//see https://gist.github.com/jhermsmeier/9a34b06a107bbf5d2c91
31
if (!Object.getOwnPropertyDescriptor) {
32
  Object.getOwnPropertyDescriptor = function( object, key ) {
33
    
34
    var hasSupport =
35
      typeof object.__lookupGetter__ === 'function' &&
36
      typeof object.__lookupSetter__ === 'function'
37
    
38
    // TODO: How does one determine this?!
39
    var isGetterSetter = !hasSupport ? null :
40
      object.__lookupGetter__( key ) ||
41
      object.__lookupSetter__( key )
42
    
43
    return isGetterSetter != null ? {
0 ignored issues
show
Best Practice introduced by
Comparing isGetterSetter to null using the != operator is not safe. Consider using !== instead.
Loading history...
44
      configurable: true,
45
      enumerable: true,
46
      get: object.__lookupGetter__( key ),
47
      set: object.__lookupSetter__( key )
48
    } : {
49
      configurable: true,
50
      writable: true,
51
      enumerable: true,
52
      value: object[ key ]
53
    }
54
  }
55
}
56