Skip to content

Commit cdc73d0

Browse files
committed
getOwnPropertyNames flags
1 parent 87b3e5d commit cdc73d0

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

packages/quickjs-emscripten-core/src/types.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,38 @@ export function evalOptionsToFlags(evalOptions: ContextEvalOptions | number | un
283283
return flags
284284
}
285285

286+
export interface GetOwnPropertyNamesOptions {
287+
/** Include strings in the result */
288+
includeStrings?: boolean
289+
/** Include symbols in the result */
290+
includeSymbols?: boolean
291+
/** Include private properties in the result */
292+
includePrivate?: boolean
293+
/** Only include the enumerable properties */
294+
onlyEnumerable?: boolean
295+
}
296+
297+
/** Convert {@link GetOwnPropertyNamesOptions} to bitfield flags */
298+
export function getOwnPropertyNamesOptionsToFlags(
299+
options: GetOwnPropertyNamesOptions | number | undefined,
300+
): number {
301+
if (typeof options === "number") {
302+
return options
303+
}
304+
305+
if (options === undefined) {
306+
return 0
307+
}
308+
309+
const { includeStrings, includeSymbols, includePrivate, onlyEnumerable } = options
310+
let flags = 0
311+
if (includeStrings) flags |= GetOwnPropertyNamesFlags.JS_GPN_STRING_MASK
312+
if (includeSymbols) flags |= GetOwnPropertyNamesFlags.JS_GPN_SYMBOL_MASK
313+
if (includePrivate) flags |= GetOwnPropertyNamesFlags.JS_GPN_PRIVATE_MASK
314+
if (onlyEnumerable) flags |= GetOwnPropertyNamesFlags.JS_GPN_ENUM_ONLY
315+
return flags
316+
}
317+
286318
export type PromiseExecutor<ResolveT, RejectT> = (
287319
resolve: (value: ResolveT | PromiseLike<ResolveT>) => void,
288320
reject: (reason: RejectT) => void,

packages/quickjs-emscripten-core/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"include": ["src/**/*"],
44
"compilerOptions": {
55
"rootDir": "src",
6-
"outDir": "dist"
6+
"outDir": "dist",
7+
"paths": {
8+
"@jitl/quickjs-ffi-types": ["../quickjs-ffi-types/src"],
9+
"@jitl/quickjs-ffi-types/*": ["../quickjs-ffi-types/src/*"]
10+
}
711
}
812
}

packages/quickjs-ffi-types/src/ffi-types.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ export type IntrinsicsFlags = Brand<number, "IntrinsicsFlags">
108108
*/
109109
export type EvalDetectModule = Brand<number, "EvalDetectModule">
110110

111+
/**
112+
* @private
113+
*/
114+
export type GetOwnPropertyNamesFlags = Brand<number, "GetOwnPropertyNamesFlags">
115+
111116
/**
112117
* State of a promise.
113118
*/
@@ -151,7 +156,7 @@ export const EvalFlags = {
151156
JS_EVAL_FLAG_BACKTRACE_BARRIER: 1 << 6,
152157
} as const
153158

154-
/** Bitfield options for QTS_NewContext intrinsices */
159+
/** Bitfield options for QTS_NewContext intrinsics */
155160
export const IntrinsicsFlags = {
156161
BaseObjects: 1 << 0,
157162
Date: 1 << 1,
@@ -176,3 +181,14 @@ export const JSPromiseStateEnum = {
176181
Fulfilled: 1,
177182
Rejected: 2,
178183
} as const
184+
185+
/** Bitfield options for QTS_GetOwnPropertyNames */
186+
export const GetOwnPropertyNamesFlags = {
187+
JS_GPN_STRING_MASK: 1 << 0,
188+
JS_GPN_SYMBOL_MASK: 1 << 1,
189+
JS_GPN_PRIVATE_MASK: 1 << 2,
190+
/* only include the enumerable properties */
191+
JS_GPN_ENUM_ONLY: 1 << 4,
192+
/* set theJSPropertyEnum.is_enumerable field */
193+
JS_GPN_SET_ENUM: 1 << 5,
194+
}

0 commit comments

Comments
 (0)