1 // Error_as.cpp: ActionScript "Error" class, for Gnash.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "as_object.h" // for inheritance
28 #include "Global_as.h"
29 #include "GnashException.h"
32 #include "as_function.h"
37 as_value
error_toString(const fn_call
& fn
);
38 as_value
error_ctor(const fn_call
& fn
);
40 void attachErrorInterface(as_object
& o
);
46 Error_class_init(as_object
& where
, const ObjectURI
& uri
)
48 registerBuiltinClass(where
, error_ctor
, attachErrorInterface
, 0, uri
);
55 attachErrorInterface(as_object
& o
)
57 Global_as
& gl
= getGlobal(o
);
60 o
.init_member("toString", gl
.createFunction(error_toString
), flags
);
62 o
.init_member("message", "Error", flags
);
63 o
.init_member("name", "Error", flags
);
68 error_toString(const fn_call
& fn
)
70 as_object
* ptr
= ensure
<ValidThis
>(fn
);
74 ptr
->get_member(getURI(vm
, "message"), &message
);
76 return as_value(message
);
79 /// "e = new Error();" returns an Error, "e = Error"; returns undefined.
81 error_ctor(const fn_call
& fn
)
83 as_object
* err
= fn
.this_ptr
;
84 if (!err
) return as_value();
88 if (fn
.nargs
&& !fn
.arg(0).is_undefined()) {
89 err
->set_member(getURI(vm
, "message"), fn
.arg(0));
96 } // end of gnash namespace