Esempio n. 1
0
ejsval
_ejs_invoke_closure (ejsval closure, ejsval _this, uint32_t argc, ejsval* args)
{
    if (!EJSVAL_IS_FUNCTION(closure)) {
#if DEBUG_LAST_LOOKUP
        extern jschar* last_lookup;
        if (last_lookup) {
            char *last_utf8 = ucs2_to_utf8(last_lookup);
            _ejs_log ("last property lookup was for: %s\n", last_utf8);
            free (last_utf8);
        }
#endif
        
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "object not a function");
    }

#if 0
    if (!EJSVAL_IS_NULL_OR_UNDEFINED(_this) && EJSVAL_IS_PRIMITIVE(_this)) {
        _this = ToObject(_this);
    }
#endif

    EJSFunction *fun = (EJSFunction*)EJSVAL_TO_OBJECT(closure);
    return fun->func (fun->env, _this, argc, args);
}
Esempio n. 2
0
ejsval
_ejs_invoke_closure (ejsval closure, ejsval _this, uint32_t argc, ejsval* args)
{
    if (!EJSVAL_IS_FUNCTION(closure)) {
#if DEBUG_LAST_LOOKUP
        extern jschar* last_lookup;
        if (last_lookup) {
            char *last_utf8 = ucs2_to_utf8(last_lookup);
            _ejs_log ("last property lookup was for: %s\n", last_utf8);
            free (last_utf8);
        }
#endif
        
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "object not a function");
    }

    if (!EJSVAL_IS_NULL_OR_UNDEFINED(_this) && EJSVAL_IS_PRIMITIVE(_this)) {
        _this = ToObject(_this);
    }

    EJSFunction *fun = (EJSFunction*)EJSVAL_TO_OBJECT(closure);
    return fun->func (fun->env, _this, argc, args);

#if not_anymore

    if (fun->bound_argc > 0) {
        ejsval* new_args = (ejsval*)malloc(sizeof(ejsval) * (fun->bound_argc + argc));
        memmove (new_args, fun->bound_args, sizeof(ejsval) * fun->bound_argc);
        memmove (&new_args[fun->bound_argc], args, argc);
        args = new_args;
        argc += fun->bound_argc;
    }

    DEBUG_FUNCTION_ENTER (closure);
    ejsval rv = fun->func (fun->env, fun->bound_this, argc, args);
    DEBUG_FUNCTION_EXIT (closure);

    if (fun->bound_argc > 0)
        free (args);
    return rv;
#endif
}