示例#1
0
// ECMA262 15.3.4.2
static ejsval
_ejs_Function_prototype_toString (ejsval env, ejsval _this, uint32_t argc, ejsval *args)
{
    char terrible_fixed_buffer[256];

    if (!EJSVAL_IS_FUNCTION(_this))
        _ejs_throw_nativeerror_utf8 (EJS_TYPE_ERROR, "Function.prototype.toString is not generic.");

    ejsval func_name = _ejs_object_getprop (_this, _ejs_atom_name);

    char *utf8_funcname = _ejs_string_to_utf8(EJSVAL_TO_STRING(func_name));
    
    snprintf(terrible_fixed_buffer, sizeof (terrible_fixed_buffer), "function %s() {}", utf8_funcname);

    free (utf8_funcname);

    return _ejs_string_new_utf8(terrible_fixed_buffer);
}
示例#2
0
ejsval
_ejs_unhandledException(ejsval env, ejsval _this, uint32_t argc, ejsval* args)
{
    ejsval exc = _ejs_undefined;

    if (argc > 0)
        exc = args[0];

    printf ("unhandled exception: ");
    
    if (EJSVAL_IS_UNDEFINED(exc)) {
        EJS_NOT_IMPLEMENTED();
    }
    else {
        ejsval str = ToString(exc);

        printf ("%s\n", _ejs_string_to_utf8(_ejs_string_flatten(str)));
    }
    exit(-1);
    return _ejs_undefined;
}
示例#3
0
ejsval
_ejs_module_get (ejsval arg)
{
    char* arg_utf8 = _ejs_string_to_utf8(EJSVAL_TO_STRING(arg));

    ejsval module EJSVAL_ALIGNMENT;
    if (require_builtin_module (arg_utf8, &module)) {
        free (arg_utf8);
        return module;
    }
    if (require_external_module (arg_utf8, &module)) {
        free (arg_utf8);
        return module;
    }
    if (require_user_module (arg_utf8, &module)) {
        free (arg_utf8);
        return module;
    }
    _ejs_log ("require('%s') failed: module not included in build.\n", arg_utf8);
    free(arg_utf8);
    return _ejs_null;
}
示例#4
0
文件: ejs-gc.c 项目: eddid/jslang
static void
finalize_object(GCObjectPtr p)
{
    GCObjectHeader* headerp = (GCObjectHeader*)p;
    if ((*headerp & EJS_SCAN_TYPE_OBJECT) != 0) {
        SPEW(2, _ejs_log ("finalizing object %p(%s)\n", p, CLASSNAME(p)));
        _ejs_specop_finalize((EJSObject *)p);
    }
    else if ((*headerp & EJS_SCAN_TYPE_CLOSUREENV) != 0) {
        SPEW(2, _ejs_log ("finalizing closureenv %p\n", p));
    }
    else if ((*headerp & EJS_SCAN_TYPE_PRIMSTR) != 0) {
        SPEW(1, {
                EJSPrimString* primstr = (EJSPrimString*)p;
                if (EJS_PRIMSTR_GET_TYPE(primstr) == EJS_STRING_FLAT) {
                    char* utf8 = _ejs_string_to_utf8(primstr);
                    SPEW(2, _ejs_log ("finalizing flat primitive string %p(%s)\n", p, utf8));
                    free (utf8);
                }
                else {
                    SPEW(2, _ejs_log ("finalizing primitive string %p\n", p));
                }
            });