gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog libbase/GnashException.h server...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libbase/GnashException.h server...
Date: Tue, 23 Jan 2007 17:17:15 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/01/23 17:17:15

Modified files:
        .              : ChangeLog 
        libbase        : GnashException.h 
        server         : sprite_instance.cpp 
        server/asobj   : Date.cpp 

Log message:
                * libbase/GnashException.h: add ActionException class.
                * server/sprite_instance.cpp, server/asobj/Date.cpp:
                  throw an ActionException if methods or gettersetter 
properties are invoked
                  against the wrong instance type.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2156&r2=1.2157
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/GnashException.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/server/sprite_instance.cpp?cvsroot=gnash&r1=1.130&r2=1.131
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Date.cpp?cvsroot=gnash&r1=1.6&r2=1.7

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2156
retrieving revision 1.2157
diff -u -b -r1.2156 -r1.2157
--- ChangeLog   23 Jan 2007 16:41:27 -0000      1.2156
+++ ChangeLog   23 Jan 2007 17:17:14 -0000      1.2157
@@ -1,3 +1,10 @@
+2007-01-23 Sandro Santilli <address@hidden>
+
+       * libbase/GnashException.h: add ActionException class.
+       * server/sprite_instance.cpp, server/asobj/Date.cpp:
+         throw an ActionException if methods or gettersetter properties are 
invoked
+         against the wrong instance type.
+
 2007-01-23 Tomas Groth Christensen <address@hidden>
 
        * backend/sound_handler_sdl.cpp: Also resample if samplerate is correct

Index: libbase/GnashException.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/GnashException.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libbase/GnashException.h    29 Nov 2006 23:54:05 -0000      1.4
+++ libbase/GnashException.h    23 Jan 2007 17:17:14 -0000      1.5
@@ -70,6 +70,26 @@
 
 };
 
+/// An ActionScript error exception 
+class ActionException: public GnashException
+{
+
+public:
+
+       ActionException(const std::string& s)
+               :
+               GnashException(s)
+       {}
+
+       ActionException()
+               :
+               GnashException("ActionScript error")
+       {}
+
+       virtual ~ActionException() throw() {}
+
+};
+
 } // namespace gnash
 
 #endif // def _GNASH_GNASHEXCEPTION__H

Index: server/sprite_instance.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/sprite_instance.cpp,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -b -r1.130 -r1.131
--- server/sprite_instance.cpp  23 Jan 2007 11:23:49 -0000      1.130
+++ server/sprite_instance.cpp  23 Jan 2007 17:17:14 -0000      1.131
@@ -45,6 +45,7 @@
 #include "smart_ptr.h"
 #include "VM.h"
 #include "Range2d.h" // for getBounds
+#include "GnashException.h"
 
 #include <vector>
 #include <string>
@@ -101,17 +102,42 @@
        }
 }
 
+// Wrapper around dynamic_cast to implement user warning.
+// To be used by builtin properties and methods.
+static sprite_instance*
+ensure_sprite(as_object* obj)
+{
+       sprite_instance* ret = dynamic_cast<sprite_instance*>(obj);
+       if ( ! ret )
+       {
+               throw ActionException("builtin method or gettersetter for 
sprite objects called against non-sprite instance");
+       }
+       return ret;
+}
+
+// Wrapper around dynamic_cast to implement user warning.
+// To be used by builtin properties and methods.
+static character*
+ensure_character(as_object* obj)
+{
+       character* ret = dynamic_cast<character*>(obj);
+       if ( ! ret )
+       {
+               throw ActionException("builtin method or gettersetter for 
character objects called against non-character instance");
+       }
+       return ret;
+}
+
 static void sprite_play(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
+
        sprite->set_play_state(sprite_instance::PLAY);
 }
 
 static void sprite_stop(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        sprite->set_play_state(sprite_instance::STOP);
 
@@ -130,10 +156,9 @@
 //removeMovieClip() : Void
 static void sprite_remove_movieclip(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
-       sprite_instance* parent = (sprite_instance*) sprite->get_parent();
+       sprite_instance* parent = 
dynamic_cast<sprite_instance*>(sprite->get_parent());
        if (parent)
        {
                parent->remove_display_object(sprite->get_depth(), 0);
@@ -144,8 +169,7 @@
 //             depth:Number [, initObject:Object]) : MovieClip
 static void sprite_attach_movie(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        if (fn.nargs < 3 || fn.nargs > 4)
        {
@@ -154,7 +178,6 @@
                        " expected 3 to 4, got (%d) - returning undefined",
                        fn.nargs);
                );
-               fn.result->set_undefined();
                return;
        }
 
@@ -168,7 +191,6 @@
                        "returning undefined",
                        id_name.c_str());
                );
-               fn.result->set_undefined();
                return;
        }
        movie_definition* exported_movie = 
dynamic_cast<movie_definition*>(exported.get());
@@ -181,7 +203,6 @@
                        id_name.c_str(),
                        typeid(*(exported.get())).name());
                );
-               fn.result->set_undefined();
                return;
        }
 
@@ -193,13 +214,9 @@
        boost::intrusive_ptr<character> newch = 
exported_movie->create_character_instance(sprite, depth_val);
        assert( dynamic_cast<sprite_instance*>(newch.get()) );
 
-       if (sprite->attachCharacter(*newch, depth_val, newname) )
-       {
-               fn.result->set_as_object(newch.get()); 
-       }
-       else
+       if (! sprite->attachCharacter(*newch, depth_val, newname) )
        {
-               fn.result->set_undefined();
+               return;
        }
 
        /// Properties must be copied *after* the call to attachCharacter
@@ -210,28 +227,23 @@
                newch->copyProperties(*initObject);
        }
 
-       log_warning("MovieClip.attachMovie('%s', %d, '%s')",
-                       id_name.c_str(), depth_val, newname.c_str());
-
+       fn.result->set_as_object(newch.get()); 
 }
 
 // attachAudio(id:Object) : Void
 static void sprite_attach_audio(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.attachAudio() unimplemented -- "
                "returning undefined");
-       fn.result->set_undefined();
 }
 
 //createEmptyMovieClip(name:String, depth:Number) : MovieClip
 static void sprite_create_empty_movieclip(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        if (fn.nargs != 2)
        {
@@ -243,7 +255,6 @@
                                        " returning undefined.",
                                        fn.nargs);
                        );
-                       fn.result->set_undefined();
                        return;
                }
                else
@@ -263,8 +274,7 @@
 
 static void sprite_get_depth(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        int n = sprite->get_depth();
 
@@ -275,8 +285,7 @@
 //swapDepths(target:Object) : Void
 static void sprite_swap_depths(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        
        if (fn.nargs < 1)
        {
@@ -340,8 +349,7 @@
 //duplicateMovieClip(name:String, depth:Number, [initObject:Object]) : 
MovieClip
 static void sprite_duplicate_movieclip(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        
        if (fn.nargs < 2)
        {
@@ -401,8 +409,7 @@
 
 static void sprite_goto_and_play(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        if (fn.nargs < 1)
        {
@@ -421,8 +428,7 @@
 
 static void sprite_goto_and_stop(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        if (fn.nargs < 1)
        {
@@ -441,8 +447,7 @@
 
 static void sprite_next_frame(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        size_t frame_count = sprite->get_frame_count();
        size_t current_frame = sprite->get_current_frame();
@@ -455,8 +460,7 @@
 
 static void sprite_prev_frame(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        size_t current_frame = sprite->get_current_frame();
        if (current_frame > 0)
@@ -468,21 +472,14 @@
 
 static void sprite_get_bytes_loaded(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        fn.result->set_int(sprite->get_bytes_loaded());
 }
 
 static void sprite_get_bytes_total(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
-       if (sprite == NULL)
-       {
-           sprite = dynamic_cast<sprite_instance*>(fn.env->get_target());
-       }
-       assert(sprite);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        // @@ horrible uh ?
        fn.result->set_int(sprite->get_bytes_total());
@@ -490,8 +487,7 @@
 
 static void sprite_load_movie(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: %s not implemented yet", __PRETTY_FUNCTION__);
@@ -500,8 +496,8 @@
 
 static void sprite_hit_test(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       //sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
+       UNUSED(sprite);
 
        static bool warned_1_arg = false;
        static bool warned_2_arg = false;
@@ -519,14 +515,12 @@
                                log_aserror("Can't find hitTest target %s",
                                        tgt_val.to_string());
                                );
-                               fn.result->set_undefined();
                                return;
                        }
                        if ( ! warned_1_arg ) {
                                log_error("FIXME: hitTest(target) 
unimplemented");
                                warned_1_arg=true;
                        }
-                       fn.result->set_undefined();
                        break;
                }
 
@@ -539,7 +533,6 @@
                                x,y);
                                warned_2_arg=true;
                        }
-                       fn.result->set_undefined();
                        break;
                }
 
@@ -553,7 +546,6 @@
                                        x,y,shapeFlag);
                                warned_3_arg=true;
                        }
-                       fn.result->set_undefined();
                        break;
                }
 
@@ -563,7 +555,6 @@
                                log_aserror("hitTest() called with %u args.",
                                        fn.nargs);
                        );
-                       fn.result->set_undefined();
                        break;
                }
        }
@@ -575,8 +566,7 @@
 static void
 sprite_create_text_field(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        if (fn.nargs != 6) // name, depth, x, y, width, height
        {
@@ -584,7 +574,6 @@
                log_msg("createTextField called with %d args, "
                        "expected 6 - returning undefined", fn.nargs);
                );
-               fn.result->set_undefined();
                return;
        }
 
@@ -594,7 +583,6 @@
                log_msg("First argument of createTextField is not a string"
                        " - returning undefined");
                );
-               fn.result->set_undefined();
                return;
        }
        //std::string txt_name = fn.arg(0).to_string();
@@ -605,7 +593,6 @@
                log_msg("Second argument of createTextField is not a number"
                        " - returning undefined");
                );
-               fn.result->set_undefined();
                return;
        }
 
@@ -617,7 +604,6 @@
                log_msg("Third argument of createTextField is not a number"
                        " - returning undefined");
                );
-               fn.result->set_undefined();
                return;
        }
 
@@ -629,7 +615,6 @@
                log_msg("Fourth argument of createTextField is not a number"
                        " - returning undefined");
                );
-               fn.result->set_undefined();
                return;
        }
 
@@ -641,7 +626,6 @@
                log_msg("Fifth argument of createTextField is not a number"
                        " - returning undefined");
                );
-               fn.result->set_undefined();
                return;
        }
        //double txt_width = fn.arg(4).to_number();
@@ -652,7 +636,6 @@
                log_msg("Fifth argument of createTextField is not a number"
                        " - returning undefined");
                );
-               fn.result->set_undefined();
                return;
        }
        //double txt_height = fn.arg(5).to_number();
@@ -723,8 +706,7 @@
 static void
 sprite_getNextHighestDepth(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        unsigned int nextdepth = sprite->getNextHighestDepth();
        fn.result->set_double(static_cast<double>(nextdepth));
@@ -734,8 +716,7 @@
 static void
 sprite_getURL(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.getURL() not implemented yet");
@@ -745,8 +726,7 @@
 static void
 sprite_getBounds(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
 
        boost::intrusive_ptr<as_object> target;
        if ( fn.nargs > 0 )
@@ -778,89 +758,73 @@
 static void
 sprite_globalToLocal(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.globalToLocal() not implemented yet");
-       fn.result->set_undefined();
 }
 
 static void
 sprite_endFill(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.endFill() not implemented yet");
-       fn.result->set_undefined();
 }
 
 static void
 sprite_lineTo(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.lineTo() not implemented yet");
-       fn.result->set_undefined();
 }
 
 static void
 sprite_lineStyle(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.lineStyle() not implemented yet");
-       fn.result->set_undefined();
 }
 
 static void
 sprite_curveTo(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.curveTo() not implemented yet");
-       fn.result->set_undefined();
 }
 
 static void
 sprite_clear(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.clear() not implemented yet");
-       fn.result->set_undefined();
 }
 
 static void
 sprite_beginFill(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.beginFill() not implemented yet");
-       fn.result->set_undefined();
 }
 
 static void
 sprite_beginGradientFill(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.beginGradientFill() not implemented yet");
-       fn.result->set_undefined();
 }
 
 // startDrag([lockCenter:Boolean], [left:Number], [top:Number],
@@ -868,8 +832,7 @@
 static void
 sprite_startDrag(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.startDrag() not implemented yet");
@@ -879,8 +842,7 @@
 static void
 sprite_stopDrag(const fn_call& fn)
 {
-       assert( dynamic_cast<sprite_instance*>(fn.this_ptr) );
-       sprite_instance* sprite = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* sprite = ensure_sprite(fn.this_ptr);
        UNUSED(sprite);
 
        log_error("FIXME: MovieClip.stopDrag() not implemented yet");
@@ -898,8 +860,7 @@
 static void
 character_x_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -920,8 +881,7 @@
 static void
 character_y_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -942,8 +902,7 @@
 static void
 character_xscale_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -994,8 +953,7 @@
 static void
 character_yscale_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1046,8 +1004,7 @@
 static void
 character_xmouse_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1076,8 +1033,7 @@
 static void
 character_ymouse_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1106,8 +1062,7 @@
 static void
 character_alpha_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1128,8 +1083,7 @@
 static void
 character_visible_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1147,8 +1101,7 @@
 static void
 character_width_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1173,8 +1126,7 @@
 static void
 character_height_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1199,8 +1151,7 @@
 static void
 character_rotation_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1233,8 +1184,7 @@
 static void
 character_parent_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<character*>(fn.this_ptr));
-       character* ptr = static_cast<character*>(fn.this_ptr);
+       character* ptr = ensure_character(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1253,8 +1203,7 @@
 static void
 sprite_currentframe_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1272,8 +1221,7 @@
 static void
 sprite_totalframes_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1291,8 +1239,7 @@
 static void
 sprite_framesloaded_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1310,8 +1257,7 @@
 static void
 sprite_target_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1329,8 +1275,7 @@
 static void
 sprite_name_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1338,7 +1283,7 @@
                const std::string& name = ptr->get_name();
                if ( vm.getSWFVersion() < 6 && name.empty() )
                {
-                       fn.result->set_undefined();
+                       return;
                } 
                else
                {
@@ -1357,8 +1302,7 @@
 static void
 sprite_droptarget_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
        UNUSED(ptr);
 
        if ( fn.nargs == 0 ) // getter
@@ -1377,7 +1321,7 @@
                } 
                else
                {
-                       fn.result->set_undefined();
+                       return;
                }
        }
        else // setter
@@ -1392,8 +1336,7 @@
 static void
 sprite_url_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
@@ -1411,15 +1354,11 @@
 static void
 sprite_onrollover_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
-               if ( ! ptr->get_event_handler(event_id::ROLL_OVER, fn.result) )
-               {
-                       fn.result->set_undefined();
-               }
+               ptr->get_event_handler(event_id::ROLL_OVER, fn.result);
        }
        else // setter
        {
@@ -1431,15 +1370,11 @@
 static void
 sprite_onrollout_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
-               if ( ! ptr->get_event_handler(event_id::ROLL_OUT, fn.result) )
-               {
-                       fn.result->set_undefined();
-               }
+               ptr->get_event_handler(event_id::ROLL_OUT, fn.result);
        }
        else // setter
        {
@@ -1450,15 +1385,11 @@
 static void
 sprite_onload_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
 
        if ( fn.nargs == 0 ) // getter
        {
-               if ( ! ptr->get_event_handler(event_id::LOAD, fn.result) )
-               {
-                       fn.result->set_undefined();
-               }
+               ptr->get_event_handler(event_id::LOAD, fn.result);
        }
        else // setter
        {
@@ -1469,8 +1400,7 @@
 static void
 sprite_highquality_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
        UNUSED(ptr);
 
        if ( fn.nargs == 0 ) // getter
@@ -1491,8 +1421,7 @@
 static void
 sprite_focusrect_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
        UNUSED(ptr);
 
        if ( fn.nargs == 0 ) // getter
@@ -1514,8 +1443,7 @@
 static void
 sprite_soundbuftime_getset(const fn_call& fn)
 {
-       assert(dynamic_cast<sprite_instance*>(fn.this_ptr));
-       sprite_instance* ptr = static_cast<sprite_instance*>(fn.this_ptr);
+       sprite_instance* ptr = ensure_sprite(fn.this_ptr);
        UNUSED(ptr);
 
        if ( fn.nargs == 0 ) // getter

Index: server/asobj/Date.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Date.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- server/asobj/Date.cpp       18 Jan 2007 22:53:21 -0000      1.6
+++ server/asobj/Date.cpp       23 Jan 2007 17:17:14 -0000      1.7
@@ -24,6 +24,7 @@
 #include "log.h"
 #include "Date.h"
 #include "fn_call.h"
+#include "GnashException.h"
 
 #include <ctime>
 
@@ -338,7 +339,6 @@
        date_obj->init_member("setUTCSeconds", &date_setutcseconds);
        date_obj->init_member("setYear", &date_setyear);
        date_obj->init_member("toString", &date_tostring);
-       date_obj->init_member("UTC", &date_utc);
 
        struct tm *ti;
        if (fn.nargs == 0) {
@@ -374,113 +374,108 @@
 
        fn.result->set_as_object(date_obj);
 }
+
+// Wrapper around dynamic_cast to implement user warning.
+// To be used by builtin properties and methods.
+static date_as_object*
+ensure_date_object(as_object* obj)
+{
+       date_as_object* ret = dynamic_cast<date_as_object*>(obj);
+       if ( ! ret )
+       {
+               throw ActionException("builtin method or gettersetter for date 
objects called against non-date instance");
+       }
+       return ret;
+}
+
 void date_getdate(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.date);
 }
 void date_getday(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.dayWeek);
 }
 void date_getfullyear(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.year + 1900);
 }
 void date_gethours(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.hour);
 }
 void date_getmilliseconds(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.millisecond);
 }
 void date_getminutes(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.minute);
 }
 void date_getmonth(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.month);
 }
 void date_getseconds(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.second);
 }
 void date_gettime(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_double(date->obj.getTime());
 }
 void date_gettimezoneoffset(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.minutesEast);
 }
 void date_getutcdate(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        tm result = date->obj.convertUTC();
 
        fn.result->set_int(int(result.tm_mday));
 }
 void date_getutcday(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        tm result = date->obj.convertUTC();
 
        fn.result->set_int(int(result.tm_wday));
 }
 void date_getutcfullyear(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        tm result = date->obj.convertUTC();
 
        fn.result->set_int(int(result.tm_year)+1900);
 }
 void date_getutchours(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        tm result = date->obj.convertUTC();
 
        fn.result->set_int(int(result.tm_hour));
 }
 void date_getutcmilliseconds(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        // Milliseconds (value between 0 and 999) won't be affected by timezone
        fn.result->set_int(int(date->obj.millisecond));
 }
 void date_getutcminutes(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        tm result = date->obj.convertUTC();
 
        fn.result->set_int(int(result.tm_min));
 }
 void date_getutcmonth(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        tm result = date->obj.convertUTC();
 
        fn.result->set_int(int(result.tm_mon));
 }
 void date_getutcseconds(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        // Seconds (value between 0 and 59) won't be affected by timezone
        fn.result->set_int(int(date->obj.second));
 }
 void date_getyear(const fn_call& fn) {
-       assert(fn.nargs == 0);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        fn.result->set_int(date->obj.year);
 }
 
@@ -493,7 +488,7 @@
 // then convert back to local time. We should confirm the official behavior!
 void date_setdate(const fn_call& fn) {
        assert(fn.nargs == 1);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        date->obj.date = (long int)(fn.arg(0).to_number());
 
        date->obj.Normalize();
@@ -501,7 +496,7 @@
 }
 void date_setfullyear(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 3);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        date->obj.year = (long int)(fn.arg(0).to_number() - 1900);
        if (fn.nargs >= 2)
                date->obj.month = (long int)(fn.arg(1).to_number());
@@ -513,7 +508,7 @@
 }
 void date_sethours(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 4);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        date->obj.hour = (long int)(fn.arg(0).to_number());
        if (fn.nargs >= 2)
                date->obj.minute = (long int)(fn.arg(1).to_number());
@@ -527,7 +522,7 @@
 }
 void date_setmilliseconds(const fn_call& fn) {
        assert(fn.nargs == 1);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        date->obj.millisecond = (long int)(fn.arg(0).to_number());
 
        date->obj.Normalize();
@@ -535,7 +530,7 @@
 }
 void date_setminutes(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 3);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        // Seconds (value between 0 and 59) won't be affected by timezone
        date->obj.minute = (long int)(fn.arg(0).to_number());
        if (fn.nargs >= 2) date->obj.second = (long int)(fn.arg(1).to_number());
@@ -546,7 +541,7 @@
 }
 void date_setmonth(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 2);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        date->obj.month = (long int)(fn.arg(0).to_number());
        if (fn.nargs >= 2)
                date->obj.date = (long int)(fn.arg(1).to_number());
@@ -556,7 +551,7 @@
 }
 void date_setseconds(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 2);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        // Seconds (value between 0 and 59) won't be affected by timezone
        date->obj.second = (long int)(fn.arg(0).to_number());
        if (fn.nargs >= 2) date->obj.millisecond = (long 
int)(fn.arg(1).to_number());
@@ -564,12 +559,14 @@
        date->obj.Normalize();
        fn.result->set_double(date->obj.getTime());
 }
-void date_settime(const fn_call& /*fn*/) {
+void date_settime(const fn_call& fn) {
+       date_as_object* date = ensure_date_object(fn.this_ptr);
+       UNUSED(date);
        log_msg("%s:unimplemented \n", __FUNCTION__);
 }
 void date_setutcdate(const fn_call& fn) {
        assert(fn.nargs == 1);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
 
        tm utctime = date->obj.convertUTC();
        // Set mday to our new UTC date (yday and wday don't need to be set)
@@ -586,7 +583,7 @@
 }
 void date_setutcfullyear(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 3);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
 
        tm utctime = date->obj.convertUTC();
        // Set year to our new UTC date
@@ -607,7 +604,7 @@
 }
 void date_setutchours(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 4);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
 
        if (fn.nargs >= 4)
        {
@@ -634,7 +631,7 @@
 }
 void date_setutcmilliseconds(const fn_call& fn) {
        assert(fn.nargs == 1);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        date->obj.millisecond = (long int)(fn.arg(0).to_number());
 
        date->obj.Normalize();
@@ -642,7 +639,7 @@
 }
 void date_setutcminutes(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 3);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        // Seconds (value between 0 and 59) won't be affected by timezone
        date->obj.minute = (long int)(fn.arg(0).to_number());
        if (fn.nargs >= 2) date->obj.second = (long int)(fn.arg(1).to_number());
@@ -657,7 +654,7 @@
 }
 void date_setutcmonth(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 2);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
 
        tm utctime = date->obj.convertUTC();
        // Set year to our new UTC date
@@ -676,7 +673,7 @@
 }
 void date_setutcseconds(const fn_call& fn) {
        assert(fn.nargs >= 1 && fn.nargs <= 2);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        // Seconds (value between 0 and 59) won't be affected by timezone
        date->obj.second = (long int)(fn.arg(0).to_number());
        if (fn.nargs >= 2) date->obj.millisecond = (long 
int)(fn.arg(1).to_number());
@@ -686,7 +683,7 @@
 }
 void date_setyear(const fn_call& fn) {
        assert(fn.nargs == 1);
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
        date->obj.year = (long int)(fn.arg(0).to_number());
 
        date->obj.Normalize();
@@ -700,7 +697,7 @@
                
{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
        char* dayweekname[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
 
-       date_as_object* date = (date_as_object*) (as_object*) fn.this_ptr;
+       date_as_object* date = ensure_date_object(fn.this_ptr);
 
        snprintf((char *)&buffer,128,"%s %s %2ld %.2ld:%.2ld:%.2ld %ld",
                dayweekname[date->obj.dayWeek],monthname[date->obj.month],
@@ -709,9 +706,6 @@
 
        fn.result->set_string((char *)&buffer);
 }
-void date_utc(const fn_call& /*fn*/) {
-       log_msg("%s:unimplemented \n", __FUNCTION__);
-}
 
 } // end of gnash namespace
 




reply via email to

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