Esempio n. 1
0
/*
    Cast the operand to the specified type

    function cast(type: Type) : Object
 */
static EjsAny *castRegExp(Ejs *ejs, EjsRegExp *rp, EjsType *type)
{
    char    *flags;

    switch (type->sid) {
    case S_Boolean:
        return ESV(true);

    case S_String:
        flags = makeFlags(rp);
        return ejsSprintf(ejs, "/%w/%s", rp->pattern, flags);

    default:
        ejsThrowTypeError(ejs, "Can't cast to this type");
        return 0;
    }
    return 0;
}
Esempio n. 2
0
EjsModule *ejsCreateModule(Ejs *ejs, EjsString *name, int version, EjsConstants *constants)
{
    EjsModule   *mp;

    assert(version >= 0);

    if ((mp = mprAllocObj(EjsModule, manageModule)) == NULL) {
        assert(mp);
        return 0;
    }
    mp->name = name;
    mp->version = version;
    mp->vname = (version) ? ejsSprintf(ejs, "%@-%d", name, version) : mp->name;
    if ((mp->constants = constants) == 0) {
        if (ejsCreateConstants(ejs, mp, 0, EC_BUFSIZE, NULL) < 0) {
            return 0;
        }
    }
    assert(mp->checksum == 0);
    return mp;
}