BindMethodToObject - Bind a method to a JavaScript object
| 698 | |
| 699 | // BindMethodToObject - Bind a method to a JavaScript object |
| 700 | JSValue 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 |
| 720 | JSValue BindAccessorToObject(JSContext *ctx, JSValue obj, const AccessorEntry *accessor) { |
no test coverage detected