• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Bnaya / objectbuffer / 1cc46d885c9a8c4464d8420dc6a68afe83ac9811

pending completion
1cc46d885c9a8c4464d8420dc6a68afe83ac9811

push

github

Bnaya Peretz
wip

458 of 552 branches covered (82.97%)

Branch coverage included in aggregate %.

1249 of 1361 relevant lines covered (91.77%)

277.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.27
/src/internal/objectWrapper.ts
1
import type { ExternalArgs, GlobalCarrier } from "./interfaces";
2
import {
3
  getObjectPropertiesEntries,
4
  deleteObjectPropertyEntryByKey,
5
  objectGet,
6
  objectSet,
7
} from "./objectWrapperHelpers";
8

9
import { INTERNAL_API_SYMBOL } from "./symbols";
10
import {
11
  IllegalObjectPropConfigError,
12
  UnsupportedOperationError,
13
} from "./exceptions";
14
import { BaseProxyTrap } from "./BaseProxyTrap";
15
import { hashMapNodeLookup } from "./hashmap/hashmap";
16
import { object_pointerToHashMap_get } from "./generatedStructs";
17

18
const getOwnPropertyDescriptorHAS = {
19
  configurable: true,
20
  enumerable: true,
21
} as const;
22

23
export class ObjectWrapper
24
  extends BaseProxyTrap
25
  implements ProxyHandler<Record<string, unknown>>
26
{
27
  public get(target: Record<string, unknown>, p: PropertyKey): any {
28
    if (p === INTERNAL_API_SYMBOL) {
1,546✔
29
      return this;
30
    }
31

32
    if (typeof p === "symbol") {
1,222✔
33
      return undefined;
34
    }
35

36
    return objectGet(
37
      this.externalArgs,
38
      this.carrier,
39
      object_pointerToHashMap_get(this.carrier.heap, this.entryPointer),
40
      p
41
    );
42
  }
43

44
  public deleteProperty(
45
    target: Record<string, unknown>,
46
    p: PropertyKey
47
  ): boolean {
48
    if (typeof p === "symbol") {
3!
49
      return false;
50
    }
51

52
    return deleteObjectPropertyEntryByKey(
53
      this.carrier,
54
      object_pointerToHashMap_get(this.carrier.heap, this.entryPointer),
55
      p
56
    );
57
  }
58

59
  public enumerate(): PropertyKey[] {
60
    const gotEntries = getObjectPropertiesEntries(
61
      this.carrier,
62
      object_pointerToHashMap_get(this.carrier.heap, this.entryPointer)
63
    );
64

65
    return gotEntries.map((e) => e.key);
66
  }
67

68
  public ownKeys() {
69
    const gotEntries = getObjectPropertiesEntries(
70
      this.carrier,
71
      object_pointerToHashMap_get(this.carrier.heap, this.entryPointer)
72
    );
73

74
    return gotEntries.map((e) => e.key.toString());
75
  }
76

77
  public getOwnPropertyDescriptor(
78
    target: Record<string, unknown>,
79
    p: PropertyKey
80
  ) {
81
    if (this.has(target, p)) {
203!
82
      return getOwnPropertyDescriptorHAS;
83
    }
84

85
    return undefined;
86
  }
87

88
  public has(target: Record<string, unknown>, p: PropertyKey) {
89
    if (p === INTERNAL_API_SYMBOL) {
204✔
90
      return true;
91
    }
92

93
    if (typeof p === "symbol") {
203!
94
      return false;
95
    }
96

97
    return (
98
      hashMapNodeLookup(
99
        this.carrier.heap,
100
        object_pointerToHashMap_get(this.carrier.heap, this.entryPointer),
101
        p
102
      ) !== 0
103
    );
104
  }
105

106
  public set(
107
    target: Record<string, unknown>,
108
    p: PropertyKey,
109
    value: any
110
  ): boolean {
111
    if (typeof p === "symbol") {
54✔
112
      throw new IllegalObjectPropConfigError();
113
    }
114

115
    objectSet(
116
      this.externalArgs,
117
      this.carrier,
118
      object_pointerToHashMap_get(this.carrier.heap, this.entryPointer),
119
      p,
120
      value
121
    );
122

123
    return true;
124
  }
125

126
  public isExtensible() {
127
    return true;
128
  }
129

130
  public preventExtensions(): boolean {
131
    throw new UnsupportedOperationError();
132
  }
133

134
  public setPrototypeOf(): boolean {
135
    throw new UnsupportedOperationError();
136
  }
137

138
  public defineProperty(): // target: Record<string, unknown>,
139
  // p: PropertyKey,
140
  // attributes: PropertyDescriptor
141
  boolean {
142
    throw new UnsupportedOperationError();
143
    // if (
144
    //   typeof p === "symbol" ||
145
    //   attributes.enumerable === false ||
146
    //   attributes.get ||
147
    //   attributes.set
148
    // ) {
149
    //   throw new IllegalObjectPropConfigError();
150
    // }
151

152
    // return Object.defineProperty(target, p, attributes);
153
  }
154
}
155

156
export function createObjectWrapper<T = any>(
157
  externalArgs: ExternalArgs,
158
  globalCarrier: GlobalCarrier,
159
  entryPointer: number
160
): T {
161
  return new Proxy(
162
    { objectBufferWrapper: "objectBufferWrapper" },
163
    new ObjectWrapper(externalArgs, globalCarrier, entryPointer)
164
  ) as any;
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc