mirror of
https://github.com/titaniumnetwork-dev/Ultraviolet.git
synced 2025-05-15 20:40:01 -04:00
40 lines
No EOL
1.5 KiB
JavaScript
40 lines
No EOL
1.5 KiB
JavaScript
import EventEmitter from "../events.js";
|
|
import HookEvent from "../hook.js";
|
|
|
|
class ObjectHook extends EventEmitter {
|
|
constructor(ctx) {
|
|
super();
|
|
this.ctx = ctx;
|
|
this.window = ctx.window;
|
|
this.Object = this.window.Object;
|
|
this.getOwnPropertyDescriptors = this.Object.getOwnPropertyDescriptors;
|
|
this.getOwnPropertyDescriptor = this.Object.getOwnPropertyDescriptor;
|
|
this.getOwnPropertyNames = this.Object.getOwnPropertyNames;
|
|
};
|
|
overrideGetPropertyNames() {
|
|
this.ctx.override(this.Object, 'getOwnPropertyNames', (target, that, args) => {
|
|
if (!args.length) return target.apply(that, args);
|
|
let [ object ] = args;
|
|
|
|
const event = new HookEvent({ names: target.call(that, object) }, target, that);
|
|
this.emit('getOwnPropertyNames', event);
|
|
|
|
if (event.intercepted) return event.returnValue;
|
|
return event.data.names;
|
|
});
|
|
};
|
|
overrideGetOwnPropertyDescriptors() {
|
|
this.ctx.override(this.Object, 'getOwnPropertyDescriptors', (target, that, args) => {
|
|
if (!args.length) return target.apply(that, args);
|
|
let [ object ] = args;
|
|
|
|
const event = new HookEvent({ descriptors: target.call(that, object) }, target, that);
|
|
this.emit('getOwnPropertyDescriptors', event);
|
|
|
|
if (event.intercepted) return event.returnValue;
|
|
return event.data.descriptors;
|
|
});
|
|
};
|
|
};
|
|
|
|
export default ObjectHook; |