-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaster.js
More file actions
103 lines (90 loc) · 3.22 KB
/
Master.js
File metadata and controls
103 lines (90 loc) · 3.22 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// defines the namespace of the handler
export const Master = (Root = Object) => class Master extends Root {
constructor () {
super()
this.trap_getPrototypeOf = []
this.trap_setPrototypeOf = []
this.trap_isExtensible = []
this.trap_preventExtensions = []
this.trap_getOwnPropertyDescriptor = []
this.trap_defineProperty = []
this.trap_has = []
this.trap_get = []
this.trap_get_none = [] // for none existent property
this.trap_set = []
this.trap_deleteProperty = []
this.trap_ownKeys = []
this.trap_apply = []
this.trap_construct = []
}
getPrototypeOf (target) {
let result
if (this.trap_getPrototypeOf.some(func => (result = func(...arguments)))) return result
return Reflect.getPrototypeOf(...arguments)
}
setPrototypeOf (target, prototype) {
let result
if (this.trap_setPrototypeOf.some(func => (result = func(...arguments)))) return result
return Reflect.setPrototypeOf(...arguments)
}
isExtensible (target) {
let result
if (this.trap_isExtensible.some(func => (result = func(...arguments)))) return result
return Reflect.isExtensible(...arguments)
}
preventExtensions (target) {
let result
if (this.trap_preventExtensions.some(func => (result = func(...arguments)))) return result
return Reflect.preventExtensions(...arguments)
}
getOwnPropertyDescriptor (target, prop) {
let result
if (this.trap_getOwnPropertyDescriptor.some(func => (result = func(...arguments)))) return result
return Reflect.getOwnPropertyDescriptor(...arguments)
}
defineProperty (target, prop, descriptor) {
let result
if (this.trap_defineProperty.some(func => (result = func(...arguments)))) return result
return Reflect.defineProperty(...arguments)
}
has (target, prop) {
let result
if (this.trap_has.some(func => (result = func(...arguments)))) return result
return Reflect.has(...arguments)
}
get (target, prop, receiver) {
let result
if (prop in target) {
if (this.trap_get.some(func => (result = func(...arguments)))) return result
} else {
if (this.trap_get_none.some(func => (result = func(...arguments)))) return result
}
return Reflect.get(...arguments)
}
set (target, prop, value, receiver) {
let result
if (this.trap_set.some(func => (result = func(...arguments)))) return result
return Reflect.set(...arguments)
}
deleteProperty (target, prop) {
let result
if (this.trap_deleteProperty.some(func => (result = func(...arguments)))) return result
return Reflect.deleteProperty(...arguments)
}
ownKeys (target) {
let result
if (this.trap_ownKeys.some(func => (result = func(...arguments)))) return result
return Reflect.ownKeys(...arguments)
}
apply (target, thisArg, argumentsList) {
let result
if (this.trap_apply.some(func => (result = func(...arguments)))) return result
return Reflect.apply(...arguments)
}
construct (target, argumentsList, newTarget) {
let result
if (this.trap_construct.some(func => (result = func(...arguments)))) return result
return Reflect.construct(...arguments)
}
}
// mostly as defined at https://developer.mozilla.org/en-US/Docs/Web/JavaScript/Reference/Global_Objects/Proxy