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

Function BindMembersToObject

bridge.c:658–697  ·  view source on GitHub ↗

BindMembersToObject - Bind methods, accessors, and properties to a JavaScript object is_static: 0 for instance members, 1 for static members

Source from the content-addressed store, hash-verified

656// BindMembersToObject - Bind methods, accessors, and properties to a JavaScript object
657// is_static: 0 for instance members, 1 for static members
658JSValue BindMembersToObject(JSContext *ctx, JSValue obj,
659 const MethodEntry *methods, int method_count,
660 const AccessorEntry *accessors, int accessor_count,
661 const PropertyEntry *properties, int property_count,
662 int is_static) {
663 // Bind methods
664 for (int i = 0; i < method_count; i++) {
665 const MethodEntry *method = &methods[i];
666 if (method->is_static == is_static) {
667 JSValue method_result = BindMethodToObject(ctx, obj, method);
668 if (JS_IsException(method_result)) {
669 return method_result;
670 }
671 }
672 }
673
674 // Bind accessors
675 for (int i = 0; i < accessor_count; i++) {
676 const AccessorEntry *accessor = &accessors[i];
677 if (accessor->is_static == is_static) {
678 JSValue accessor_result = BindAccessorToObject(ctx, obj, accessor);
679 if (JS_IsException(accessor_result)) {
680 return accessor_result;
681 }
682 }
683 }
684
685 // Bind properties (data properties support)
686 for (int i = 0; i < property_count; i++) {
687 const PropertyEntry *property = &properties[i];
688 if (property->is_static == is_static) {
689 JSValue property_result = BindPropertyToObject(ctx, obj, property);
690 if (JS_IsException(property_result)) {
691 return property_result;
692 }
693 }
694 }
695
696 return JS_UNDEFINED;
697}
698
699// BindMethodToObject - Bind a method to a JavaScript object
700JSValue BindMethodToObject(JSContext *ctx, JSValue obj, const MethodEntry *method) {

Callers 1

CreateClassFunction · 0.85

Calls 4

BindMethodToObjectFunction · 0.85
JS_IsExceptionFunction · 0.85
BindAccessorToObjectFunction · 0.85
BindPropertyToObjectFunction · 0.85

Tested by

no test coverage detected