Skip to content

Commit ff7a4c3

Browse files
committed
add callMethod convinience function
1 parent 28f8688 commit ff7a4c3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,25 @@ export class QuickJSContext
10741074
return this.success(this.memory.heapValueHandle(resultPtr))
10751075
}
10761076

1077+
/**
1078+
* `handle[key](...args)`
1079+
*
1080+
* Call a method on a JSValue. This is a convenience method that calls {@link getProp} and {@link callFunction}.
1081+
*
1082+
* @returns A result. If the function threw synchronously, `result.error` be a
1083+
* handle to the exception. Otherwise `result.value` will be a handle to the
1084+
* value.
1085+
*/
1086+
callMethod(
1087+
thisHandle: QuickJSHandle,
1088+
key: QuickJSPropertyKey,
1089+
args: QuickJSHandle[] = [],
1090+
): ContextResult<QuickJSHandle> {
1091+
return this.getProp(thisHandle, key).consume((func) =>
1092+
this.callFunction(func, thisHandle, ...args),
1093+
)
1094+
}
1095+
10771096
/**
10781097
* Like [`eval(code)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#Description).
10791098
*

0 commit comments

Comments
 (0)