MCPcopy Create free account
hub / github.com/buke/quickjs-go / BindMethodToObject

Function BindMethodToObject

bridge.c:700–717  ·  view source on GitHub ↗

BindMethodToObject - Bind a method to a JavaScript object

Source from the content-addressed store, hash-verified

698
699// BindMethodToObject - Bind a method to a JavaScript object
700JSValue BindMethodToObject(JSContext *ctx, JSValue obj, const MethodEntry *method) {
701 // Create method function
702 JSValue method_func = CreateCFunction(ctx, method->name, method->length,
703 JS_CFUNC_generic_magic, method->handler_id);
704 if (JS_IsException(method_func)) {
705 return method_func;
706 }
707
708 // Define property
709 int result = JS_DefinePropertyValueStr(ctx, obj, method->name, method_func,
710 JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
711 if (result < 0) {
712 JS_FreeValue(ctx, method_func);
713 return JS_ThrowInternalError(ctx, "failed to bind method: %s", method->name);
714 }
715
716 return JS_UNDEFINED;
717}
718
719// BindAccessorToObject - Bind an accessor to a JavaScript object
720JSValue BindAccessorToObject(JSContext *ctx, JSValue obj, const AccessorEntry *accessor) {

Callers 1

BindMembersToObjectFunction · 0.85

Calls 2

CreateCFunctionFunction · 0.85
JS_IsExceptionFunction · 0.85

Tested by

no test coverage detected