-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.ts
More file actions
88 lines (83 loc) · 3.72 KB
/
object.ts
File metadata and controls
88 lines (83 loc) · 3.72 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @fileoverview Safe references to `Object` static methods and prototype
* methods.
*
* Annex B legacy accessor methods (`__defineGetter__`, `__lookupGetter__`,
* etc.) are exposed alongside the canonical static methods —
* implementations exist in V8, SpiderMonkey, and JavaScriptCore even
* though the spec calls them "normative optional".
*/
import { uncurryThis } from './uncurry'
export const ObjectCtor: ObjectConstructor = Object
// ─── Object (static) ───────────────────────────────────────────────────
export const ObjectAssign = Object.assign
export const ObjectCreate = Object.create
export const ObjectDefineProperties = Object.defineProperties
export const ObjectDefineProperty = Object.defineProperty
export const ObjectEntries = Object.entries
export const ObjectFreeze = Object.freeze
export const ObjectFromEntries = Object.fromEntries
export const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
export const ObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors
export const ObjectGetOwnPropertyNames = Object.getOwnPropertyNames
export const ObjectGetOwnPropertySymbols = Object.getOwnPropertySymbols
export const ObjectGetPrototypeOf = Object.getPrototypeOf
export const ObjectHasOwn = Object.hasOwn
export const ObjectIs = Object.is
export const ObjectIsExtensible = Object.isExtensible
export const ObjectIsFrozen = Object.isFrozen
export const ObjectIsSealed = Object.isSealed
export const ObjectKeys = Object.keys
export const ObjectPreventExtensions = Object.preventExtensions
export const ObjectSeal = Object.seal
export const ObjectSetPrototypeOf = Object.setPrototypeOf
export const ObjectValues = Object.values
// ─── Object (prototype) ────────────────────────────────────────────────
export const ObjectPrototype = Object.prototype
export const ObjectPrototypeHasOwnProperty = uncurryThis(
Object.prototype.hasOwnProperty,
)
export const ObjectPrototypeIsPrototypeOf = uncurryThis(
Object.prototype.isPrototypeOf,
)
export const ObjectPrototypePropertyIsEnumerable = uncurryThis(
Object.prototype.propertyIsEnumerable,
)
export const ObjectPrototypeToString = uncurryThis(Object.prototype.toString)
export const ObjectPrototypeValueOf = uncurryThis(Object.prototype.valueOf)
// Annex B legacy accessor methods. Spec'd as "normative optional" but
// implemented in every major engine (V8, SpiderMonkey, JavaScriptCore).
// Equivalent to Object.defineProperty / Object.getOwnPropertyDescriptor
// but operate on a target's prototype chain rather than its own props,
// which is occasionally what you actually want (e.g. probing whether
// a class defines a getter without instantiating).
//
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__
const _objectProto = Object.prototype as unknown as {
__defineGetter__: (this: object, key: PropertyKey, fn: () => unknown) => void
__defineSetter__: (
this: object,
key: PropertyKey,
fn: (value: unknown) => void,
) => void
__lookupGetter__: (
this: object,
key: PropertyKey,
) => (() => unknown) | undefined
__lookupSetter__: (
this: object,
key: PropertyKey,
) => ((value: unknown) => void) | undefined
}
export const ObjectPrototypeDefineGetter = uncurryThis(
_objectProto.__defineGetter__,
)
export const ObjectPrototypeDefineSetter = uncurryThis(
_objectProto.__defineSetter__,
)
export const ObjectPrototypeLookupGetter = uncurryThis(
_objectProto.__lookupGetter__,
)
export const ObjectPrototypeLookupSetter = uncurryThis(
_objectProto.__lookupSetter__,
)