Skip to content

Commit

Permalink
✨ Add some devtools functions for custom inspect formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Apr 13, 2024
1 parent 2fb4bf8 commit 1ef641b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Make `Develry.HttpAgent` classes return sockets from `createConnection` (backport)
* Don't throw errors when an *unused/free* socket has an error in `Develry.HttpAgent` (backport)
* Add some devtools functions for custom inspect formatting (backport)

## 0.8.18 (2024-01-19)

Expand Down
91 changes: 91 additions & 0 deletions lib/devtools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const defStat = Blast.createStaticDefiner(Blast);

/**
* Identifier symbols
*
* @author Jelle De Loecker <[email protected]>
* @since 0.9.3
* @version 0.9.3
*/
const JANEWAY_LEFT = defStat('JANEWAY_LEFT', Symbol.for('janeway_arg_left')),
JANEWAY_RIGHT = defStat('JANEWAY_RIGHT', Symbol.for('janeway_arg_right'));

/**
* Get all the object getters
*
* @author Jelle De Loecker <[email protected]>
* @since 0.9.3
* @version 0.9.3
*/
defStat(function getObjectGetters(obj) {

const result = new Map();

let descriptors,
descriptor,
symbols,
current = obj,
entry,
key;

while (current && typeof current == 'object') {
descriptors = Object.getOwnPropertyDescriptors(current);

// Get the symbols
symbols = this.getObjectSymbols(current);

if (symbols && symbols.length) {
let i;

for (i = 0; i < symbols.length; i++) {
key = symbols[i];
descriptor = Object.getOwnPropertyDescriptor(current, key);

if (descriptor.get) {
descriptor.symbol = key;
descriptors[String(key)] = descriptor;
}
}
}

for (key in descriptors) {

if (key == '__proto__') {
continue;
}

entry = descriptors[key];

if (entry.get) {
result.set(key, entry);
}
}

if (current.__proto__) {
current = current.__proto__;
} else {
break;
}
}

return result;
});

/**
* Get all the symbol properties of the given object
*
* @author Jelle De Loecker <[email protected]>
* @since 0.9.3
* @version 0.9.3
*
* @param {Object} arg
*
* @return {Array}
*/
defStat(function getObjectSymbols(arg) {
if (!Object.getOwnPropertySymbols) {
return [];
}

return Object.getOwnPropertySymbols(arg);
});
1 change: 1 addition & 0 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,7 @@ function BlastInit(modifyPrototype) {
Blast.require('stream_delayed', {client: false});
Blast.require('stream_combined', {client: false});
Blast.require('form_data', {client: false});
Blast.require('devtools', {client: false});
}

Blast.require('request_events', {add_wrapper: true, client: true});
Expand Down

0 comments on commit 1ef641b

Please sign in to comment.