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

Function BindPropertyToObject

bridge.c:765–783  ·  view source on GitHub ↗

BindPropertyToObject - Bind a data property to a JavaScript object This creates real data properties using JS_DefinePropertyValueStr

Source from the content-addressed store, hash-verified

763// BindPropertyToObject - Bind a data property to a JavaScript object
764// This creates real data properties using JS_DefinePropertyValueStr
765JSValue BindPropertyToObject(JSContext *ctx, JSValue obj, const PropertyEntry *property) {
766 // Duplicate the value to ensure proper reference counting
767 // JS_DefinePropertyValueStr takes ownership of the value
768 JSValue property_value = JS_DupValue(ctx, property->value);
769
770 // Define the data property using QuickJS API
771 // This creates a real data property, not an accessor property
772 int result = JS_DefinePropertyValueStr(ctx, obj, property->name,
773 property_value, property->flags);
774
775 if (result < 0) {
776 // If define failed, we need to free the duplicated value
777 JS_FreeValue(ctx, property_value);
778 return JS_ThrowInternalError(ctx, "failed to bind property: %s", property->name);
779 }
780
781 // Success: property_value ownership has been transferred to QuickJS
782 return JS_UNDEFINED;
783}
784
785
786

Callers 2

BindMembersToObjectFunction · 0.85
CreateClassInstanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected