CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/12/11 11:34:58
Modified files: . : ChangeLog server/asobj : string.cpp testsuite/actionscript.all: String.as testsuite/swfdec: PASSING Log message: fix String.slice, register native String functions, fix static vs. prototoype methods for String. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5128&r2=1.5129 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/string.cpp?cvsroot=gnash&r1=1.46&r2=1.47 http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/String.as?cvsroot=gnash&r1=1.28&r2=1.29 http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/swfdec/PASSING?cvsroot=gnash&r1=1.76&r2=1.77 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.5128 retrieving revision 1.5129 diff -u -b -r1.5128 -r1.5129 --- ChangeLog 11 Dec 2007 10:06:00 -0000 1.5128 +++ ChangeLog 11 Dec 2007 11:34:57 -0000 1.5129 @@ -1,5 +1,12 @@ 2007-12-11 Sandro Santilli <[EMAIL PROTECTED]> + * server/asobj/string.cpp: fix slice, register native functions, + fix static vs. prototoype methods. + * testsuite/actionscript.all/String.as: add more tests + * testsuite/swfdec/PASSING: String.slice tests pass. + +2007-12-11 Sandro Santilli <[EMAIL PROTECTED]> + * server/swf/tag_loaders.cpp (sound_stream_head_loader): tolerate lack of a 'latency' field in MP3 stream. Fixes bug #21729. Note that Ming also reports the file to have the same problem Index: server/asobj/string.cpp =================================================================== RCS file: /sources/gnash/gnash/server/asobj/string.cpp,v retrieving revision 1.46 retrieving revision 1.47 diff -u -b -r1.46 -r1.47 --- server/asobj/string.cpp 4 Dec 2007 11:45:31 -0000 1.46 +++ server/asobj/string.cpp 11 Dec 2007 11:34:58 -0000 1.47 @@ -16,7 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -/* $Id: string.cpp,v 1.46 2007/12/04 11:45:31 strk Exp $ */ +/* $Id: string.cpp,v 1.47 2007/12/11 11:34:58 strk Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -76,22 +76,63 @@ static void attachStringInterface(as_object& o) { + VM& vm = o.getVM(); + // TODO fill in the rest - o.init_member("concat", new builtin_function(string_concat)); - o.init_member("slice", new builtin_function(string_slice)); - o.init_member("split", new builtin_function(string_split)); - o.init_member("lastIndexOf", new builtin_function(string_last_index_of)); - o.init_member("substr", new builtin_function(string_sub_str)); - o.init_member("substring", new builtin_function(string_sub_string)); - o.init_member("indexOf", new builtin_function(string_index_of)); - o.init_member("toString", new builtin_function(string_to_string)); - o.init_member("fromCharCode", new builtin_function(string_from_char_code)); - o.init_member("charAt", new builtin_function(string_char_at)); - o.init_member("charCodeAt", new builtin_function(string_char_code_at)); - o.init_member("toUpperCase", new builtin_function(string_to_upper_case)); - o.init_member("toLowerCase", new builtin_function(string_to_lower_case)); - o.init_member("valueOf", new builtin_function(as_object::tostring_method)); + // ASnative(251, 1) - [String.prototype] valueOf + vm.registerNative(as_object::tostring_method, 251, 1); + o.init_member("valueOf", vm.getNative(251, 1)); + + // ASnative(251, 2) - [String.prototype] toString + vm.registerNative(string_to_string, 251, 2); + o.init_member("toString", vm.getNative(251, 2)); + + // ASnative(251, 3) - [String.prototype] toUpperCase + vm.registerNative(string_to_upper_case, 251, 3); + o.init_member("toUpperCase", vm.getNative(251, 3)); + + // ASnative(251, 4) - [String.prototype] toLowerCase + vm.registerNative(string_to_lower_case, 251, 4); + o.init_member("toLowerCase", vm.getNative(251, 4)); + + // ASnative(251, 5) - [String.prototype] charAt + vm.registerNative(string_char_at, 251, 5); + o.init_member("charAt", vm.getNative(251, 5)); + + // ASnative(251, 6) - [String.prototype] charCodeAt + vm.registerNative(string_char_code_at, 251, 6); + o.init_member("charCodeAt", vm.getNative(251, 6)); + + // ASnative(251, 7) - [String.prototype] concat + vm.registerNative(string_concat, 251, 7); + o.init_member("concat", vm.getNative(251, 7)); + + // ASnative(251, 8) - [String.prototype] indexOf + vm.registerNative(string_index_of, 251, 8); + o.init_member("indexOf", vm.getNative(251, 8)); + + // ASnative(251, 9) - [String.prototype] lastIndexOf + vm.registerNative(string_last_index_of, 251, 9); + o.init_member("lastIndexOf", vm.getNative(251, 9)); + + // ASnative(251, 10) - [String.prototype] slice + vm.registerNative(string_slice, 251, 10); + o.init_member("slice", vm.getNative(251, 10)); + + // ASnative(251, 11) - [String.prototype] substring + vm.registerNative(string_sub_string, 251, 11); + o.init_member("substring", vm.getNative(251, 11)); + + // ASnative(251, 12) - [String.prototype] split + vm.registerNative(string_split, 251, 12); + o.init_member("split", vm.getNative(251, 12)); + + // ASnative(251, 13) - [String.prototype] substr + vm.registerNative(string_sub_str, 251, 13); + o.init_member("substr", vm.getNative(251, 13)); + + // This isn't advertised as native, so might be a proper property ? boost::intrusive_ptr<builtin_function> length_getter(new builtin_function(string_get_length)); o.init_readonly_property("length", *length_getter); @@ -171,7 +212,7 @@ static size_t -valid_index(std::string subject, int index) +valid_index(const std::string& subject, int index) { int myIndex = index; @@ -193,28 +234,29 @@ // Make a copy. std::string str = obj->str(); - ENSURE_FN_ARGS(1, 2, str); + ENSURE_FN_ARGS(1, 2, as_value()); - int start = fn.arg(0).to_number<int>(); + size_t start = valid_index(str, fn.arg(0).to_int()); - int end = str.size(); + size_t len = str.length(); - if (fn.nargs >= 2) { - end = fn.arg(1).to_number<int>(); + size_t end = len; + if (fn.nargs >= 2) + { + end = valid_index(str, fn.arg(1).to_int()); - if (end < start) { - // Swap start and end like substring - std::swap(start, end); } - start = valid_index(str, start); - - end = valid_index(str, end) - start ; - } else { - start = valid_index(str, start); + if (end < start) // move out of if ? + { + return as_value(""); } - return as_value(str.substr(start, end)); + size_t retlen = end-start; + + log_msg("start:%d, end:%d, retlen:%d", start, end, retlen); + + return as_value(str.substr(start, retlen)); } static as_value @@ -591,12 +633,14 @@ if ( cl == NULL ) { + VM& vm = VM::get(); + cl=new builtin_function(&string_ctor, getStringInterface()); - VM::get().addStatic(cl.get()); + vm.addStatic(cl.get()); - // replicate all interface to class, to be able to access - // all methods as static functions - attachStringInterface(*cl); + // ASnative(251, 14) - [String] fromCharCode + vm.registerNative(string_from_char_code, 251, 14); + cl->init_member("fromCharCode", vm.getNative(251, 14)); } Index: testsuite/actionscript.all/String.as =================================================================== RCS file: /sources/gnash/gnash/testsuite/actionscript.all/String.as,v retrieving revision 1.28 retrieving revision 1.29 diff -u -b -r1.28 -r1.29 --- testsuite/actionscript.all/String.as 2 Dec 2007 09:15:55 -0000 1.28 +++ testsuite/actionscript.all/String.as 11 Dec 2007 11:34:58 -0000 1.29 @@ -16,12 +16,71 @@ // Original author: Mike Carlson - June 19th, 2006 -rcsid="$Id: String.as,v 1.28 2007/12/02 09:15:55 strk Exp $"; +rcsid="$Id: String.as,v 1.29 2007/12/11 11:34:58 strk Exp $"; #include "check.as" -// Gnash fails this always returning an object when String -// constructor is invoked. +check_equals(typeof(String), 'function'); +check_equals(typeof(String.prototype), 'object'); +#if OUTPUT_VERSION > 5 + check_equals(String.__proto__, Function.prototype); // both undefined in swf5 +#else + xcheck_equals(String.__proto__, Function.prototype); // gnash fails +#endif +check_equals(typeof(String.prototype.valueOf), 'function'); +check_equals(typeof(String.prototype.toString), 'function'); +check_equals(typeof(String.prototype.toUpperCase), 'function'); +check_equals(typeof(String.prototype.toLowerCase), 'function'); +check_equals(typeof(String.prototype.charAt), 'function'); +check_equals(typeof(String.prototype.charCodeAt), 'function'); +check_equals(typeof(String.prototype.concat), 'function'); +check_equals(typeof(String.prototype.indexOf), 'function'); +check_equals(typeof(String.prototype.lastIndexOf), 'function'); +check_equals(typeof(String.prototype.slice), 'function'); +check_equals(typeof(String.prototype.substring), 'function'); +check_equals(typeof(String.prototype.split), 'function'); +check_equals(typeof(String.prototype.substr), 'function'); +check_equals(typeof(String.prototype.fromCharCode), 'undefined'); +#if OUTPUT_VERSION > 5 + check_equals(typeof(String.valueOf), 'function'); + check_equals(typeof(String.toString), 'function'); +#else + xcheck_equals(typeof(String.valueOf), 'undefined'); + xcheck_equals(typeof(String.toString), 'undefined'); +#endif +check_equals(typeof(String.toUpperCase), 'undefined'); +check_equals(typeof(String.toLowerCase), 'undefined'); +check_equals(typeof(String.charAt), 'undefined'); +check_equals(typeof(String.charCodeAt), 'undefined'); +check_equals(typeof(String.concat), 'undefined'); +check_equals(typeof(String.indexOf), 'undefined'); +check_equals(typeof(String.lastIndexOf), 'undefined'); +check_equals(typeof(String.slice), 'undefined'); +check_equals(typeof(String.substring), 'undefined'); +check_equals(typeof(String.split), 'undefined'); +check_equals(typeof(String.substr), 'undefined'); +check_equals(typeof(String.fromCharCode), 'function'); + +#if OUTPUT_VERSION > 5 +check(String.hasOwnProperty('fromCharCode')); +check(!String.hasOwnProperty('toString')); +check(!String.hasOwnProperty('valueOf')); +check(String.prototype.hasOwnProperty('valueOf')); +check(String.prototype.hasOwnProperty('toString')); +check(String.prototype.hasOwnProperty('toUpperCase')); +check(String.prototype.hasOwnProperty('toLowerCase')); +check(String.prototype.hasOwnProperty('charAt')); +check(String.prototype.hasOwnProperty('charCodeAt')); +check(String.prototype.hasOwnProperty('concat')); +check(String.prototype.hasOwnProperty('indexOf')); +check(String.prototype.hasOwnProperty('lastIndexOf')); +check(String.prototype.hasOwnProperty('slice')); +check(String.prototype.hasOwnProperty('substring')); +check(String.prototype.hasOwnProperty('split')); +check(String.prototype.hasOwnProperty('substr')); +#endif + + check_equals(typeof(String()), 'string'); var a; @@ -42,8 +101,10 @@ //---------------------------------------- // Check String.indexOf +// TODO: test with ASnative(251,8) //----------------------------------------- + // wallawallawashinGTON check_equals ( a.indexOf("lawa"), 3 ); check_equals ( a.indexOf("lawas"), 8 ); @@ -69,6 +130,7 @@ //---------------------------------------- // Check String.split +// TODO: test with ASnative(251,12) //----------------------------------------- check_equals ( typeof(a.split), 'function' ); @@ -138,6 +200,7 @@ //---------------------------------------- // Check String.fromCharCode +// TODO: test with ASnative(251,14) //----------------------------------------- @@ -147,13 +210,15 @@ //------------------------------------------- // Check String.toUpperCase and toLowerCase +// TODO: test with ASnative(251,3) //------------------------------------------- check_equals ( a.toUpperCase(), "WALLAWALLAWASHINGTON" ); check_equals ( a.toLowerCase(), "wallawallawashington" ); //------------------------------------------- -// Check substr / slice / substring +// Check substr +// TODO: test with ASnative(251,13) //------------------------------------------- a = new String("abcdefghijklmnopqrstuvwxyz"); @@ -162,7 +227,25 @@ check_equals ( a.substr(-1,1), "z" ); check_equals ( a.substr(-2,3), "yz" ); check_equals ( a.substr(-3,2), "xy" ); +var b = new String("1234"); +check_equals ( b.substr(3, 6), "4"); + +//------------------------------------------- +// Check slice +// TODO: test with ASnative(251,10) +//------------------------------------------- + +a = new String("abcdefghijklmnopqrstuvwxyz"); check_equals ( a.slice(-5,-3), "vw" ); +check_equals ( typeof(a.slice()), "undefined" ); +check_equals ( typeof(a.slice(-5,3)), "string" ); +check_equals ( a.slice(-5,3), "" ); +check_equals ( typeof(a.slice(-10,22)), "string" ); +check_equals ( a.slice(-10,22), "qrstuv" ); +check_equals ( a.slice(0,0), "" ); +check_equals ( a.slice(0,1), "a" ); +check_equals ( a.slice(1,1), "" ); +check_equals ( a.slice(1,2), "b" ); #if OUTPUT_VERSION > 5 check_equals ( a.slice.call(a, -5, -3), "vw" ); check_equals ( String.prototype.slice.call(a, -5, -3), "vw" ); @@ -173,14 +256,22 @@ check_equals ( String.prototype.slice.call(a, -5, -3), undefined ); #endif check_equals ( a.slice(-4), "wxyz" ); + +//------------------------------------------- +// Check substring +// TODO: test with ASnative(251,11) +//------------------------------------------- + +a = new String("abcdefghijklmnopqrstuvwxyz"); check_equals ( a.substring(5,2), "cde" ); check_equals ( a.substring(5,7), "fg" ); check_equals ( a.substring(3,3), "" ); + check_equals ( a.length, 26 ); check_equals ( a.concat("sir ","william",15), "abcdefghijklmnopqrstuvwxyzsir william15"); + var b = new String("1234"); check_equals ( b.substring(3, 6), "4"); -check_equals ( b.substr(3, 6), "4"); // see check.as #ifdef MING_SUPPORTS_ASM @@ -371,7 +462,7 @@ String.prototype.toString = StringProtoToStringBackup; #if OUTPUT_VERSION < 6 - check_totals(130); + check_totals(170); #else - check_totals(135); + check_totals(191); #endif Index: testsuite/swfdec/PASSING =================================================================== RCS file: /sources/gnash/gnash/testsuite/swfdec/PASSING,v retrieving revision 1.76 retrieving revision 1.77 diff -u -b -r1.76 -r1.77 --- testsuite/swfdec/PASSING 11 Dec 2007 00:14:23 -0000 1.76 +++ testsuite/swfdec/PASSING 11 Dec 2007 11:34:58 -0000 1.77 @@ -554,6 +554,9 @@ string-convert-5.swf:15de6c587a3c3e7c685b8f98ea862790 string-convert-6.swf:841b7cc8e58c33c38efbfe1768ef82cf string-convert-7.swf:b822683afd33802bdd0e7ba31df63d68 +string-slice-5.swf:a98bdbd8ce5ff3cfd5406d3a9d04de33 +string-slice-6.swf:cfe7fde1085617b6673fda9895162e32 +string-slice-7.swf:eaed0b05db4e5a01579a94f283f8a068 string-split-empty-5.swf:0cdbe0cfc78b49bdf37c1e71bfc5743f string-split-empty-6.swf:94aacd4a972c8eae6fa7ebe945074414 string-split-empty-7.swf:3be198e0f9277bf4749bddddf85dce33 _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit