Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ultraviolet
Path: blob/main/src/client/native/object.js
305 views
1
import EventEmitter from "events";
2
import HookEvent from "../hook.js";
3
4
/**
5
* @typedef {import('../index').default} UVClient
6
*/
7
8
class ObjectHook extends EventEmitter {
9
/**
10
*
11
* @param {UVClient} ctx
12
*/
13
constructor(ctx) {
14
super();
15
this.ctx = ctx;
16
this.window = ctx.window;
17
this.Object = this.window.Object;
18
this.getOwnPropertyDescriptors = this.Object.getOwnPropertyDescriptors;
19
this.getOwnPropertyDescriptor = this.Object.getOwnPropertyDescriptor;
20
this.getOwnPropertyNames = this.Object.getOwnPropertyNames;
21
}
22
overrideGetPropertyNames() {
23
this.ctx.override(
24
this.Object,
25
"getOwnPropertyNames",
26
(target, that, args) => {
27
if (!args.length) return target.apply(that, args);
28
let [object] = args;
29
30
const event = new HookEvent(
31
{ names: target.call(that, object) },
32
target,
33
that
34
);
35
this.emit("getOwnPropertyNames", event);
36
37
if (event.intercepted) return event.returnValue;
38
return event.data.names;
39
}
40
);
41
}
42
overrideGetOwnPropertyDescriptors() {
43
this.ctx.override(
44
this.Object,
45
"getOwnPropertyDescriptors",
46
(target, that, args) => {
47
if (!args.length) return target.apply(that, args);
48
let [object] = args;
49
50
const event = new HookEvent(
51
{ descriptors: target.call(that, object) },
52
target,
53
that
54
);
55
this.emit("getOwnPropertyDescriptors", event);
56
57
if (event.intercepted) return event.returnValue;
58
return event.data.descriptors;
59
}
60
);
61
}
62
}
63
64
export default ObjectHook;
65
66