Javascript missing functions

Can you add these missing functions?

For String:

            setMethod ("lastIndexOf",   lastIndexOf);
            setMethod ("trim",          trim);
            setMethod ("toLowerCase",   toLowerCase);
            setMethod ("toUpperCase",   toUpperCase);
            setMethod ("replace",   	replace);

        static var lastIndexOf (Args a)   { return a.thisObject.toString().lastIndexOf (getString (a, 0)); }
        static var trim (Args a)          { return a.thisObject.toString().trim(); }
        static var toUpperCase (Args a)          { return a.thisObject.toString().toUpperCase(); }
        static var toLowerCase (Args a)          { return a.thisObject.toString().toLowerCase(); }
        static var replace (Args a)          	 { return a.thisObject.toString().replace (getString (a, 0), getString (a, 1)); }

For Array:

        setMethod ("reverse",  reverse);

        static var reverse (Args a)
            if (Array<var>* array = a.thisObject.getArray())
                Array<var> res;
                for (int i = array->size(); --i >= 0;)
                    res.add ((*array)[i]);
                return res;
            return var::undefined();

Some of those implementations require a little tweaking.

Javascript’s reverse modifies the original array and returns a reference.

Javascript’s replace ('a', 'b') is more complicated than String::replace, and in this particular case should only replace the first 'a' with 'b'.

If you’ve been using that code it would be sensible to make sure the deviation away from the JS spec hasn’t caused any bugs.