-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathultimate_proxy.js
76 lines (59 loc) · 2.36 KB
/
ultimate_proxy.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
function getUltimateProxy(obj){
let proto = Object.getPrototypeOf(obj);
proto = proto ? getUltimateProxy( Object.getPrototypeOf(obj) ) : proto;
return new Proxy(obj, {
getPrototypeOf: function(target){
console.log("getPrototypeOf", target);
return protoProxy;
},
setPrototypeOf: function(target, prototype){
console.log("setPrototypeOf", target, prototype);
return Object.setPrototypeOf(target, getUltimateProxy(prototype));
},
isExtensible: function(target){
console.log("isExtensible", target);
return Object.isExtensible(target);
},
preventExtensions: function(target){
console.log("preventExtensions", target);
return Object.preventExtensions(target);
},
getOwnPropertyDescriptor: function(target, prop){
console.log("getOwnPropertyDescriptor", target, prop);
return Object.getOwnPropertyDescriptor(target, prop);
},
defineProperty: function(target, prop, descriptor){
console.log("defineProperty", target, prop, descriptor);
return Object.defineProperty(target, prop, descriptor);
},
has: function(target, prop){
console.log("has", target, prop);
return prop in target;
},
get: function(target, prop, receiver){
console.log("get", target, prop, receiver);
return target[prop];
},
set: function(target, prop, value, receiver){
console.log("set", target, prop, value, receiver);
target[prop] = value;
return true;
},
deleteProperty: function(target, prop){
console.log("deleteProperty", target, prop);
return delete target[prop];
},
ownKeys: function(target){
console.log("ownKeys", target);
return Object.keys(target);
},
apply: function(target, thisArg, argumentsList){
console.log("apply", target, thisArg, argumentsList);
return target.apply(thisArg, argumentsList);
},
construct: function(target, argumentsList, newTarget){
console.log("construct", target, argumentsList, newTarget);
return new target(...argumentsList);
}
});
}