-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathreflect.js
78 lines (64 loc) · 2.41 KB
/
reflect.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {PLATFORM} from 'aurelia-pal';
if (typeof FEATURE_NO_ES2015 === 'undefined') {
const bind = Function.prototype.bind;
if (typeof PLATFORM.global.Reflect === 'undefined') {
PLATFORM.global.Reflect = {};
}
if (typeof Reflect.defineProperty !== 'function') {
Reflect.defineProperty = function(target, propertyKey, descriptor) {
if (typeof target === 'object' ? target === null : typeof target !== 'function') {
throw new TypeError('Reflect.defineProperty called on non-object');
}
try {
Object.defineProperty(target, propertyKey, descriptor);
return true;
} catch (e) {
return false;
}
};
}
if (typeof Reflect.construct !== 'function') {
Reflect.construct = function(Target, args) {
if (args) {
switch (args.length){
case 0: return new Target();
case 1: return new Target(args[0]);
case 2: return new Target(args[0], args[1]);
case 3: return new Target(args[0], args[1], args[2]);
case 4: return new Target(args[0], args[1], args[2], args[3]);
}
}
var a = [null];
a.push.apply(a, args);
return new (bind.apply(Target, a));
};
}
if (typeof Reflect.ownKeys !== 'function') {
Reflect.ownKeys = function(o) { return (Object.getOwnPropertyNames(o).concat(Object.getOwnPropertySymbols(o))); }
}
} // endif FEATURE_NO_ES2015
if (typeof FEATURE_NO_ESNEXT === 'undefined') {
const emptyMetadata = Object.freeze({});
const metadataContainerKey = '__metadata__';
if (typeof Reflect.getOwnMetadata !== 'function') {
Reflect.getOwnMetadata = function(metadataKey, target, targetKey) {
if (target.hasOwnProperty(metadataContainerKey)) {
return (target[metadataContainerKey][targetKey] || emptyMetadata)[metadataKey];
}
};
}
if (typeof Reflect.defineMetadata !== 'function') {
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey) {
let metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : (target[metadataContainerKey] = {});
let targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
targetContainer[metadataKey] = metadataValue;
};
}
if (typeof Reflect.metadata !== 'function') {
Reflect.metadata = function(metadataKey, metadataValue) {
return function(target, targetKey) {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
};
};
}
} // endif FEATURE_NO_ESNEXT