add a test for just-fixed crasher
[swfdec.git] / swfdec / swfdec_as_boolean.c
blob65a1ec714dc7abb4482e1081704a4a0aba2fd3d3
1 /* Swfdec
2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include <math.h>
26 #include "swfdec_as_boolean.h"
27 #include "swfdec_as_context.h"
28 #include "swfdec_as_internal.h"
29 #include "swfdec_as_native_function.h"
30 #include "swfdec_as_strings.h"
31 #include "swfdec_debug.h"
33 G_DEFINE_TYPE (SwfdecAsBoolean, swfdec_as_boolean, SWFDEC_TYPE_AS_OBJECT)
35 static void
36 swfdec_as_boolean_class_init (SwfdecAsBooleanClass *klass)
40 static void
41 swfdec_as_boolean_init (SwfdecAsBoolean *boolean)
45 /*** AS CODE ***/
47 SWFDEC_AS_CONSTRUCTOR (107, 2, swfdec_as_boolean_construct, swfdec_as_boolean_get_type)
48 void
49 swfdec_as_boolean_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
50 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
52 gboolean b;
54 if (argc > 0) {
55 b = swfdec_as_value_to_boolean (swfdec_gc_object_get_context (object), &argv[0]);
56 } else {
57 if (!swfdec_as_context_is_constructing (cx))
58 return;
59 b = FALSE;
62 if (swfdec_as_context_is_constructing (cx)) {
63 SWFDEC_AS_BOOLEAN (object)->boolean = b;
64 SWFDEC_AS_VALUE_SET_OBJECT (ret, object);
65 } else {
66 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, b);
70 SWFDEC_AS_NATIVE (107, 1, swfdec_as_boolean_toString)
71 void
72 swfdec_as_boolean_toString (SwfdecAsContext *cx, SwfdecAsObject *object,
73 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
75 SwfdecAsBoolean *b;
77 if (!SWFDEC_IS_AS_BOOLEAN (object))
78 return;
79 b = SWFDEC_AS_BOOLEAN (object);
81 SWFDEC_AS_VALUE_SET_STRING (ret, b->boolean ? SWFDEC_AS_STR_true : SWFDEC_AS_STR_false);
84 SWFDEC_AS_NATIVE (107, 0, swfdec_as_boolean_valueOf)
85 void
86 swfdec_as_boolean_valueOf (SwfdecAsContext *cx, SwfdecAsObject *object,
87 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
89 SwfdecAsBoolean *b;
91 if (!SWFDEC_IS_AS_BOOLEAN (object))
92 return;
93 b = SWFDEC_AS_BOOLEAN (object);
95 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, b->boolean);
98 // only available as ASnative
99 SWFDEC_AS_NATIVE (3, 2, swfdec_as_boolean_old_constructor)
100 void
101 swfdec_as_boolean_old_constructor (SwfdecAsContext *cx, SwfdecAsObject *object,
102 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
104 SWFDEC_STUB ("old 'Boolean' function (only available as ASnative)");