Skip to content

Commit 2b9369d

Browse files
committed
improve getOwnPropertyNames docs
1 parent 481f178 commit 2b9369d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
EitherFFI,
1313
UInt32Pointer,
1414
JSValuePointerPointerPointer,
15+
JSVoidPointer,
1516
} from "@jitl/quickjs-ffi-types"
1617
import { debugLog } from "./debug"
1718
import type { JSPromiseState } from "./deferred-promise"
@@ -58,7 +59,6 @@ import type {
5859
VmPropertyDescriptor,
5960
} from "./vm-interface"
6061
import { QuickJSIterator } from "./QuickJSIterator"
61-
import { JSVoidPointer } from "@jitl/quickjs-ffi-types"
6262

6363
export type ContextResult<S> = DisposableResult<S, QuickJSHandle>
6464

@@ -868,7 +868,17 @@ export class QuickJSContext
868868

869869
/**
870870
* `Object.getOwnPropertyNames(handle)`.
871-
* Similar to the [standard semantics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames).
871+
* Similar to the [standard semantics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames),
872+
* but with extra, non-standard options for:
873+
*
874+
* - fetching array indexes as numbers
875+
* - including symbols
876+
* - only iterating over enumerable properties
877+
*
878+
* To emulate the standard, use these options:
879+
* ```typescript
880+
* context.getOwnPropertyNames(handle, { strings: true, numbersAsStrings: true })
881+
* ```
872882
*/
873883
getOwnPropertyNames(
874884
handle: QuickJSHandle,
@@ -924,13 +934,13 @@ export class QuickJSContext
924934
* }
925935
* ```
926936
*/
927-
getIterator(handle: QuickJSHandle): ContextResult<QuickJSIterator> {
937+
getIterator(iterableHandle: QuickJSHandle): ContextResult<QuickJSIterator> {
928938
const SymbolIterator = (this._SymbolIterator ??= this.memory.manage(
929939
this.getWellKnownSymbol("iterator"),
930940
))
931941
return Scope.withScope((scope) => {
932-
const methodHandle = scope.manage(this.getProp(handle, SymbolIterator))
933-
const iteratorCallResult = this.callFunction(methodHandle, handle)
942+
const methodHandle = scope.manage(this.getProp(iterableHandle, SymbolIterator))
943+
const iteratorCallResult = this.callFunction(methodHandle, iterableHandle)
934944
if (iteratorCallResult.error) {
935945
return iteratorCallResult
936946
}

0 commit comments

Comments
 (0)