update copyright date
[gnash.git] / libcore / asobj / Error_as.cpp
blob9c67baccb19b8cc02d2c173bcbb839085e7159a9
1 // Error_as.cpp: ActionScript "Error" class, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
5 //
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
21 #include "Error_as.h"
23 #include <sstream>
25 #include "as_object.h" // for inheritance
26 #include "log.h"
27 #include "fn_call.h"
28 #include "Global_as.h"
29 #include "GnashException.h"
30 #include "as_value.h"
31 #include "VM.h"
32 #include "as_function.h"
34 namespace gnash {
36 namespace {
37 as_value error_toString(const fn_call& fn);
38 as_value error_ctor(const fn_call& fn);
40 void attachErrorInterface(as_object& o);
44 // extern
45 void
46 Error_class_init(as_object& where, const ObjectURI& uri)
48 registerBuiltinClass(where, error_ctor, attachErrorInterface, 0, uri);
52 namespace {
54 void
55 attachErrorInterface(as_object& o)
57 Global_as& gl = getGlobal(o);
58 int flags = 0;
60 o.init_member("toString", gl.createFunction(error_toString), flags);
62 o.init_member("message", "Error", flags);
63 o.init_member("name", "Error", flags);
67 as_value
68 error_toString(const fn_call& fn)
70 as_object* ptr = ensure<ValidThis>(fn);
72 VM& vm = getVM(*ptr);
73 as_value message;
74 ptr->get_member(getURI(vm, "message"), &message);
76 return as_value(message);
79 /// "e = new Error();" returns an Error, "e = Error"; returns undefined.
80 as_value
81 error_ctor(const fn_call& fn)
83 as_object* err = fn.this_ptr;
84 if (!err) return as_value();
86 VM& vm = getVM(fn);
88 if (fn.nargs && !fn.arg(0).is_undefined()) {
89 err->set_member(getURI(vm, "message"), fn.arg(0));
92 return as_value();
96 } // end of gnash namespace