-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathwrapper.js
53 lines (49 loc) · 1.53 KB
/
wrapper.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
/**
* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the W3C SOFTWARE AND DOCUMENT NOTICE AND LICENSE.
*
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*/
const {
defineProperty,
} = Object;
/**
* Installs the setter of a given property.
* @param {!Object} object An object for which to wrap the property.
* @param {string} name The name of the property to wrap.
* @param {function(*): void|undefined} setter A setter function}
*/
export function installSetter(object, name, setter) {
const descriptor = {
set: setter,
};
defineProperty(object, name, descriptor);
}
/**
* Installs a setter and getter of a given property.
* @param {!Object} object An object for which to wrap the property.
* @param {string} name The name of the property to wrap.
* @param {function(*): void|undefined} setter A setter function}
* @param {function(): *|undefined} getter A getter function}
*/
export function installSetterAndGetter(object, name, setter, getter) {
const descriptor = {
set: setter,
get: getter,
configurable: true, // This can get uninstalled, we need configurable: true
};
defineProperty(object, name, descriptor);
}
/**
* Installs the setter of a given property.
* @param {!Object} object An object for which to wrap the property.
* @param {string} name The name of the property to wrap.
* @param {function(*): *|undefined} fn A function}
*/
export function installFunction(object, name, fn) {
defineProperty(object, name, {
value: fn,
});
}