-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add some devtools functions for custom inspect formatting
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters