gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/asobj/string.cpp testsui...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/asobj/string.cpp testsui...
Date: Wed, 28 Feb 2007 10:52:38 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/02/28 10:52:38

Modified files:
        .              : ChangeLog 
        server/asobj   : string.cpp 
        testsuite/actionscript.all: String.as 

Log message:
        This is an important cleanup commit. All ActionScript classe should
        get the same threatment !!
        
                * server/asobj/string.cpp: robustness and
                  correctness improvements: use builtin_function,
                  not c_function for buildin methods; make sure
                  methods are applied to a String instance.
                * testsuite/actionscript.all/String.as: add a
                  test for builtin methods being allowed to be
                  called using Function interface
                  (String.prototype.slice.call: just a small example)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2493&r2=1.2494
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/string.cpp?cvsroot=gnash&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/String.as?cvsroot=gnash&r1=1.11&r2=1.12

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2493
retrieving revision 1.2494
diff -u -b -r1.2493 -r1.2494
--- ChangeLog   28 Feb 2007 10:12:23 -0000      1.2493
+++ ChangeLog   28 Feb 2007 10:52:37 -0000      1.2494
@@ -1,5 +1,16 @@
 2007-02-28 Sandro Santilli <address@hidden>
 
+       * server/asobj/string.cpp: robustness and
+         correctness improvements: use builtin_function,
+         not c_function for buildin methods; make sure
+         methods are applied to a String instance.
+       * testsuite/actionscript.all/String.as: add a
+         test for builtin methods being allowed to be
+         called using Function interface
+         (String.prototype.slice.call: just a small example)
+
+2007-02-28 Sandro Santilli <address@hidden>
+
        * server/vm/ASHandlers.cpp: use log_aserror for
          ActionScript errors; (ActionExtends): check
          that the thing being extended is a function !!

Index: server/asobj/string.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/string.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- server/asobj/string.cpp     28 Feb 2007 09:59:54 -0000      1.17
+++ server/asobj/string.cpp     28 Feb 2007 10:52:38 -0000      1.18
@@ -14,7 +14,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.17 2007/02/28 09:59:54 strk Exp $ */
+/* $Id: string.cpp,v 1.18 2007/02/28 10:52:38 strk Exp $ */
 
 // Implementation of ActionScript String class.
 
@@ -31,6 +31,7 @@
 #include "log.h"
 #include "array.h"
 #include "as_value.h"
+#include "GnashException.h"
 
 namespace gnash {
 
@@ -56,22 +57,22 @@
 attachStringInterface(as_object& o)
 {
        // TODO fill in the rest
-       o.init_member("concat", &string_concat);
-       o.init_member("slice", &string_slice);
-       o.init_member("split", &string_split);
-       o.init_member("lastIndexOf", &string_last_index_of);
-       o.init_member("substr", &string_sub_str);
-       o.init_member("substring", &string_sub_string);
-       o.init_member("indexOf", &string_index_of);
-       o.init_member("toString", &string_to_string);
-       o.init_member("fromCharCode", &string_from_char_code);
-       o.init_member("charAt", &string_char_at);
-       o.init_member("charCodeAt", &string_char_code_at);
-       o.init_member("toUpperCase", &string_to_upper_case);
-       o.init_member("toLowerCase", &string_to_lower_case);
+       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));
        
-       boost::intrusive_ptr<builtin_function> length_getter(new 
builtin_function(&string_get_length,NULL));
-       boost::intrusive_ptr<builtin_function> length_setter(new 
builtin_function(&string_set_length,NULL));
+       boost::intrusive_ptr<builtin_function> length_getter(new 
builtin_function(string_get_length));
+       boost::intrusive_ptr<builtin_function> length_setter(new 
builtin_function(string_set_length));
        o.init_property("length", *length_getter, *length_setter);
 
 }
@@ -112,11 +113,23 @@
 
 };
 
+static tu_string_as_object *
+ensureString(as_object* obj)
+{
+       tu_string_as_object* ret = dynamic_cast<tu_string_as_object*>(obj);
+       if ( ! ret )
+       {
+               throw ActionException("builtin method or gettersetter for 
String objects called against non-String instance");
+       }
+       return ret;
+}
 
 static void
 string_get_length(const fn_call& fn)
 {
-       fn.result->set_int(((tu_string_as_object*) 
fn.this_ptr)->m_string.utf8_length());
+       tu_string_as_object* str = ensureString(fn.this_ptr);
+
+       fn.result->set_int(str->m_string.utf8_length());
        return;
 
 }
@@ -134,7 +147,8 @@
 static void
 string_concat(const fn_call& fn)
 {
-       tu_string this_string = ((tu_string_as_object*) fn.this_ptr)->m_string;
+       tu_string_as_object* str = ensureString(fn.this_ptr);
+       tu_string this_string = str->m_string;
        
        int len = strlen(this_string.c_str());
        int pos = len;
@@ -159,7 +173,8 @@
 static void
 string_slice(const fn_call& fn)
 {
-       tu_string this_string = ((tu_string_as_object*) fn.this_ptr)->m_string;
+       tu_string_as_object* str = ensureString(fn.this_ptr);
+       tu_string this_string = str->m_string;
        // Pull a slice out of this_string.
        int     start = 0;
        int     utf8_len = this_string.utf8_length();
@@ -192,8 +207,9 @@
 static void
 string_split(const fn_call& fn)
 {
+       tu_string_as_object* str = ensureString(fn.this_ptr);
 
-       boost::intrusive_ptr<tu_string_as_object> 
this_string_ptr((tu_string_as_object*) fn.this_ptr);
+       boost::intrusive_ptr<tu_string_as_object> this_string_ptr(str); // why 
??
        
        as_value val;
        
@@ -210,7 +226,7 @@
        
        if (fn.nargs >= 1)
        {
-               tu_string this_string = ((tu_string_as_object*) 
fn.this_ptr)->m_string;
+               tu_string this_string = this_string_ptr->m_string;
                
                int     utf8_len = this_string.utf8_length();
 
@@ -269,8 +285,7 @@
 static void
 string_last_index_of(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
 
        if (fn.nargs < 1)
        {
@@ -311,7 +326,9 @@
 static void
 string_sub_str(const fn_call& fn)
 {
-       tu_string this_string = ((tu_string_as_object*) fn.this_ptr)->m_string;
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
+       tu_string this_string = this_string_ptr->m_string;
+
        // Pull a slice out of this_string.
        int     start = 0;
        int     utf8_len = this_string.utf8_length();
@@ -336,7 +353,8 @@
 static void
 string_sub_string(const fn_call& fn)
 {
-       tu_string this_string = ((tu_string_as_object*) fn.this_ptr)->m_string;
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
+       tu_string this_string = this_string_ptr->m_string;
        // Pull a slice out of this_string.
        int     start = 0;
        int     utf8_len = this_string.utf8_length();
@@ -361,8 +379,7 @@
 static void
 string_index_of(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
 
        if (fn.nargs < 1)
        {
@@ -394,8 +411,7 @@
 static void
 string_from_char_code(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
+       //tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
 
        tu_string result;
 
@@ -411,8 +427,7 @@
 static void
 string_char_code_at(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
 
        // assert(fn.nargs == 1);
        if (fn.nargs < 1) {
@@ -442,8 +457,7 @@
 static void
 string_char_at(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
 
        // assert(fn.nargs == 1);
        if (fn.nargs < 1) {
@@ -475,8 +489,7 @@
 static void
 string_to_upper_case(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
 
        fn.result->set_tu_string(this_string_ptr->m_string.utf8_to_upper());
        return;         
@@ -485,8 +498,7 @@
 static void
 string_to_lower_case(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
 
        fn.result->set_tu_string(this_string_ptr->m_string.utf8_to_lower());
        return;         
@@ -495,9 +507,7 @@
 static void
 string_to_string(const fn_call& fn)
 {
-       tu_string_as_object* this_string_ptr = (tu_string_as_object*) 
fn.this_ptr;
-       assert(this_string_ptr);
-
+       tu_string_as_object* this_string_ptr = ensureString(fn.this_ptr);
        fn.result->set_tu_string(this_string_ptr->m_string);
 }
 

Index: testsuite/actionscript.all/String.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/String.as,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- testsuite/actionscript.all/String.as        28 Feb 2007 09:56:40 -0000      
1.11
+++ testsuite/actionscript.all/String.as        28 Feb 2007 10:52:38 -0000      
1.12
@@ -1,7 +1,7 @@
 // Mike Carlson's test program for actionscript strings
 // June 19th, 2006
 
-rcsid="$Id: String.as,v 1.11 2007/02/28 09:56:40 strk Exp $";
+rcsid="$Id: String.as,v 1.12 2007/02/28 10:52:38 strk Exp $";
 
 #include "check.as"
 
@@ -55,6 +55,8 @@
 check_equals ( a.substr(-2,3), "yz" );
 check_equals ( a.substr(-3,2), "xy" );
 check_equals ( a.slice(-5,-3), "vw" );
+check_equals ( a.slice.call(a, -5, -3), "vw" );
+check_equals ( String.prototype.slice.call(a, -5, -3), "vw" );
 check_equals ( a.slice(-4), "wxyz" );
 check_equals ( a.substring(5,2), "cde" );
 check_equals ( a.substring(5,7), "fg" );




reply via email to

[Prev in Thread] Current Thread [Next in Thread]