[Swfdec] 7 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.h libswfdec/swfdec_as_string.c test/trace
Pekka Lampila
medar at kemper.freedesktop.org
Fri Aug 24 04:54:39 PDT 2007
libswfdec/swfdec_as_context.c | 7 +
libswfdec/swfdec_as_interpret.c | 9 +-
libswfdec/swfdec_as_object.h | 3
libswfdec/swfdec_as_string.c | 128 ++++++++++++++++++++++--------------
test/trace/Makefile.am | 14 +++
test/trace/string-fake-5.swf |binary
test/trace/string-fake-5.swf.trace | 12 +++
test/trace/string-fake-6.swf |binary
test/trace/string-fake-6.swf.trace | 12 +++
test/trace/string-fake-7.swf |binary
test/trace/string-fake-7.swf.trace | 12 +++
test/trace/string-fake.as | 35 +++++++++
test/trace/string-trace-5.swf |binary
test/trace/string-trace-5.swf.trace | 8 ++
test/trace/string-trace-6.swf |binary
test/trace/string-trace-6.swf.trace | 8 ++
test/trace/string-trace-7.swf |binary
test/trace/string-trace-7.swf.trace | 8 ++
test/trace/string-trace.as | 27 +++++++
19 files changed, 233 insertions(+), 50 deletions(-)
New commits:
diff-tree 641a6cfdd685460f61676f732b3f081f2e007c9f (from b132dd4594747f32a97fed84d447973bdc768ae8)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 24 14:46:32 2007 +0300
Forgot to add string-fake test to Makefile.am
diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index b00d70a..004d23d 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -1067,6 +1067,13 @@ EXTRA_DIST = \
string-convert-6.swf.trace \
string-convert-7.swf \
string-convert-7.swf.trace \
+ string-fake.as \
+ string-fake-5.swf \
+ string-fake-5.swf.trace \
+ string-fake-6.swf \
+ string-fake-6.swf.trace \
+ string-fake-7.swf \
+ string-fake-7.swf.trace \
string-indexof.as \
string-indexof-5.swf \
string-indexof-5.swf.trace \
diff-tree b132dd4594747f32a97fed84d447973bdc768ae8 (from 9bab9da501869ee04f07294e9172dbe996c86045)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 24 14:45:46 2007 +0300
Add test case for tracing strings objects
diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 231d8df..b00d70a 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -1097,6 +1097,13 @@ EXTRA_DIST = \
string-split-empty-6.swf.trace \
string-split-empty-7.swf \
string-split-empty-7.swf.trace \
+ string-trace.as \
+ string-trace-5.swf \
+ string-trace-5.swf.trace \
+ string-trace-6.swf \
+ string-trace-6.swf.trace \
+ string-trace-7.swf \
+ string-trace-7.swf.trace \
stringlength.as \
stringlength-5.swf \
stringlength-5.swf.trace \
diff --git a/test/trace/string-trace-5.swf b/test/trace/string-trace-5.swf
new file mode 100644
index 0000000..923ebed
Binary files /dev/null and b/test/trace/string-trace-5.swf differ
diff --git a/test/trace/string-trace-5.swf.trace b/test/trace/string-trace-5.swf.trace
new file mode 100644
index 0000000..7ce9d46
--- /dev/null
+++ b/test/trace/string-trace-5.swf.trace
@@ -0,0 +1,8 @@
+internal
+internal
+internal
+internal
+internal
+valueOf
+internal
+valueOf
diff --git a/test/trace/string-trace-6.swf b/test/trace/string-trace-6.swf
new file mode 100644
index 0000000..d554fae
Binary files /dev/null and b/test/trace/string-trace-6.swf differ
diff --git a/test/trace/string-trace-6.swf.trace b/test/trace/string-trace-6.swf.trace
new file mode 100644
index 0000000..7ce9d46
--- /dev/null
+++ b/test/trace/string-trace-6.swf.trace
@@ -0,0 +1,8 @@
+internal
+internal
+internal
+internal
+internal
+valueOf
+internal
+valueOf
diff --git a/test/trace/string-trace-7.swf b/test/trace/string-trace-7.swf
new file mode 100644
index 0000000..850345b
Binary files /dev/null and b/test/trace/string-trace-7.swf differ
diff --git a/test/trace/string-trace-7.swf.trace b/test/trace/string-trace-7.swf.trace
new file mode 100644
index 0000000..7ce9d46
--- /dev/null
+++ b/test/trace/string-trace-7.swf.trace
@@ -0,0 +1,8 @@
+internal
+internal
+internal
+internal
+internal
+valueOf
+internal
+valueOf
diff --git a/test/trace/string-trace.as b/test/trace/string-trace.as
new file mode 100644
index 0000000..699ac4b
--- /dev/null
+++ b/test/trace/string-trace.as
@@ -0,0 +1,27 @@
+// makeswf -v 7 -r 1 -o string-to-string-7.swf string-to-string.as
+
+var a = new String ("internal");
+
+var b = new String ("internal");
+b.toString = function () { return "toString"; };
+
+var c = new String ("internal");
+c.valueOf = function () { return "valueOf"; };
+
+var d = new String ("internal");
+d.toString = function () { return "toString"; };
+d.valueOf = function () { return "valueOf"; };
+
+trace (a);
+trace ("" + a);
+
+trace (b);
+trace ("" + b);
+
+trace (c);
+trace ("" + c);
+
+trace (d);
+trace ("" + d);
+
+loadMovie ("FSCommand:quit", "");
diff-tree 9bab9da501869ee04f07294e9172dbe996c86045 (from 13aa81dbca1a430cdaca848d23ef36a8192ca54c)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 24 14:44:15 2007 +0300
Add special case to trace: Print string objects using the internal presentation
diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index d08b00a..44e7c5a 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -27,6 +27,7 @@
#include "swfdec_as_function.h"
#include "swfdec_as_script_function.h"
#include "swfdec_as_stack.h"
+#include "swfdec_as_string.h"
#include "swfdec_as_strings.h"
#include "swfdec_as_super.h"
#include "swfdec_as_with.h"
@@ -552,10 +553,14 @@ swfdec_action_trace (SwfdecAsContext *cx
const char *s;
val = swfdec_as_stack_peek (cx, 1);
- if (val->type == SWFDEC_AS_TYPE_UNDEFINED)
+ if (val->type == SWFDEC_AS_TYPE_UNDEFINED) {
s = SWFDEC_AS_STR_undefined;
- else
+ } else if (val->type == SWFDEC_AS_TYPE_OBJECT &&
+ SWFDEC_IS_AS_STRING (swfdec_as_value_to_object (cx, val))) {
+ s = SWFDEC_AS_STRING (swfdec_as_value_to_object (cx, val))->string;
+ } else {
s = swfdec_as_value_to_string (cx, val);
+ }
swfdec_as_stack_pop (cx);
g_signal_emit_by_name (cx, "trace", s);
}
diff-tree 13aa81dbca1a430cdaca848d23ef36a8192ca54c (from 3aeb7081c80edcbb50e66d58265e400d637f75fb)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 24 14:26:11 2007 +0300
Remove the swfdec_as_object_to_string and just use local helper function
diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index f166b37..28a1dd7 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -1237,27 +1237,3 @@ swfdec_as_object_resolve (SwfdecAsObject
return klass->resolve (object);
}
-
-/**
- * swfdec_as_object_to_string:
- * @context: a #SwfdecAsContext
- * @object: a #SwfdecAsObject
- *
- * Converts @object to a string according to the rules of Flash. This might
- * cause calling back into the script engine.
- * <warning>Never use this function for debugging purposes.</warning>
- *
- * Returns: a garbage-collected string representing @object. The value will
- * never be %NULL.
- **/
-const char *
-swfdec_as_object_to_string (SwfdecAsContext *context, SwfdecAsObject *object)
-{
- SwfdecAsValue val;
-
- g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), NULL);
-
- SWFDEC_AS_VALUE_SET_OBJECT (&val, object);
-
- return swfdec_as_value_to_string (context, &val);
-}
diff --git a/libswfdec/swfdec_as_string.c b/libswfdec/swfdec_as_string.c
index c9739c9..c05156f 100644
--- a/libswfdec/swfdec_as_string.c
+++ b/libswfdec/swfdec_as_string.c
@@ -69,6 +69,19 @@ swfdec_as_string_init (SwfdecAsString *s
/*** AS CODE ***/
+static const char *
+swfdec_as_string_object_to_string (SwfdecAsContext *context,
+ SwfdecAsObject *object)
+{
+ SwfdecAsValue val;
+
+ g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), NULL);
+
+ SWFDEC_AS_VALUE_SET_OBJECT (&val, object);
+
+ return swfdec_as_value_to_string (context, &val);
+}
+
static inline const char *
swfdec_as_str_nth_char (const char *s, guint n)
{
@@ -82,7 +95,7 @@ void
swfdec_as_string_lastIndexOf (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
gsize len;
const char *s;
@@ -110,7 +123,7 @@ void
swfdec_as_string_indexOf (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
int offset=0, len, i=-1;
const char *s, *t = NULL;
@@ -135,7 +148,7 @@ void
swfdec_as_string_charAt (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
int i;
const char *s, *t;
@@ -159,7 +172,7 @@ void
swfdec_as_string_charCodeAt (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
int i;
const char *s;
gunichar c;
@@ -309,7 +322,7 @@ swfdec_as_string_split_5 (SwfdecAsContex
const char *str, *end, *delim;
int count;
- str = swfdec_as_object_to_string (cx, object);
+ str = swfdec_as_string_object_to_string (cx, object);
arr = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx));
if (arr == NULL)
return;
@@ -363,7 +376,7 @@ swfdec_as_string_split_6 (SwfdecAsContex
int count;
guint len;
- str = swfdec_as_object_to_string (cx, object);
+ str = swfdec_as_string_object_to_string (cx, object);
arr = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx));
if (arr == NULL)
return;
@@ -437,7 +450,7 @@ void
swfdec_as_string_substr (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
int from, to, len;
from = swfdec_as_value_to_integer (cx, &argv[0]);
@@ -471,7 +484,7 @@ void
swfdec_as_string_substring (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
int from, to, len;
len = g_utf8_strlen (string, -1);
@@ -500,7 +513,7 @@ void
swfdec_as_string_toLowerCase (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
char *s;
s = g_utf8_strdown (string, -1);
@@ -513,7 +526,7 @@ void
swfdec_as_string_toUpperCase (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- const char *string = swfdec_as_object_to_string (cx, object);
+ const char *string = swfdec_as_string_object_to_string (cx, object);
char *s;
s = g_utf8_strup (string, -1);
diff-tree 3aeb7081c80edcbb50e66d58265e400d637f75fb (from f2f9a954cf51088ac352e55ac62fc21f0af5e737)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 24 14:22:30 2007 +0300
Added test for using String's method in normal Object
diff --git a/test/trace/string-fake-5.swf b/test/trace/string-fake-5.swf
new file mode 100644
index 0000000..5d2fd1a
Binary files /dev/null and b/test/trace/string-fake-5.swf differ
diff --git a/test/trace/string-fake-5.swf.trace b/test/trace/string-fake-5.swf.trace
new file mode 100644
index 0000000..20b8340
--- /dev/null
+++ b/test/trace/string-fake-5.swf.trace
@@ -0,0 +1,12 @@
+o: goodbye
+toString: hello
+valueOf: goodbye
+HELLO
+hello
+l
+108
+1
+1
+el
+h,llo
+ell
diff --git a/test/trace/string-fake-6.swf b/test/trace/string-fake-6.swf
new file mode 100644
index 0000000..803f50b
Binary files /dev/null and b/test/trace/string-fake-6.swf differ
diff --git a/test/trace/string-fake-6.swf.trace b/test/trace/string-fake-6.swf.trace
new file mode 100644
index 0000000..20b8340
--- /dev/null
+++ b/test/trace/string-fake-6.swf.trace
@@ -0,0 +1,12 @@
+o: goodbye
+toString: hello
+valueOf: goodbye
+HELLO
+hello
+l
+108
+1
+1
+el
+h,llo
+ell
diff --git a/test/trace/string-fake-7.swf b/test/trace/string-fake-7.swf
new file mode 100644
index 0000000..cda34fd
Binary files /dev/null and b/test/trace/string-fake-7.swf differ
diff --git a/test/trace/string-fake-7.swf.trace b/test/trace/string-fake-7.swf.trace
new file mode 100644
index 0000000..20b8340
--- /dev/null
+++ b/test/trace/string-fake-7.swf.trace
@@ -0,0 +1,12 @@
+o: goodbye
+toString: hello
+valueOf: goodbye
+HELLO
+hello
+l
+108
+1
+1
+el
+h,llo
+ell
diff --git a/test/trace/string-fake.as b/test/trace/string-fake.as
new file mode 100644
index 0000000..323c792
--- /dev/null
+++ b/test/trace/string-fake.as
@@ -0,0 +1,35 @@
+// makeswf -v 7 -r 1 -o test-7.swf test.as
+
+var o = new Object ();
+o.toString = function () { return "hello"; };
+o.valueOf = function () { return "goodbye"; };
+
+trace ("o: " + o);
+trace ("toString: " + o.toString ());
+trace ("valueOf: " + o.valueOf ());
+
+o.toUpperCase = String.prototype.toUpperCase;
+o.toLowerCase = String.prototype.toLowerCase;
+o.charAt = String.prototype.charAt;
+o.charCodeAt = String.prototype.charCodeAt;
+//o.concat = String.prototype.concat;
+o.indexOf = String.prototype.indexOf;
+o.lastIndexOf = String.prototype.lastIndexOf;
+//o.slice = String.prototype.slice;
+o.substring = String.prototype.substring;
+o.split = String.prototype.split;
+o.substr = String.prototype.substr;
+
+trace (o.toUpperCase ());
+trace (o.toLowerCase ());
+trace (o.charAt (3));
+trace (o.charCodeAt (2));
+//trace (o.concat (", and thanks for the fish!"));
+trace (o.indexOf ("e"));
+trace (o.lastIndexOf ("e"));
+//trace (o.slice (1, 3));
+trace (o.substring (1, 3));
+trace (o.split ("e"));
+trace (o.substr (1, 3));
+
+loadMovie ("FSCommand:quit", "");
diff-tree f2f9a954cf51088ac352e55ac62fc21f0af5e737 (from 6360caf2cc3bd3b3b576b3cd36320108aa15e5b5)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 24 14:21:21 2007 +0300
Make most String's functions work with any Object
Added swfdec_as_object_to_string function that calls swfdec_as_value_to_string
diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 28a1dd7..f166b37 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -1237,3 +1237,27 @@ swfdec_as_object_resolve (SwfdecAsObject
return klass->resolve (object);
}
+
+/**
+ * swfdec_as_object_to_string:
+ * @context: a #SwfdecAsContext
+ * @object: a #SwfdecAsObject
+ *
+ * Converts @object to a string according to the rules of Flash. This might
+ * cause calling back into the script engine.
+ * <warning>Never use this function for debugging purposes.</warning>
+ *
+ * Returns: a garbage-collected string representing @object. The value will
+ * never be %NULL.
+ **/
+const char *
+swfdec_as_object_to_string (SwfdecAsContext *context, SwfdecAsObject *object)
+{
+ SwfdecAsValue val;
+
+ g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), NULL);
+
+ SWFDEC_AS_VALUE_SET_OBJECT (&val, object);
+
+ return swfdec_as_value_to_string (context, &val);
+}
diff --git a/libswfdec/swfdec_as_object.h b/libswfdec/swfdec_as_object.h
index a61bc4b..2de6d04 100644
--- a/libswfdec/swfdec_as_object.h
+++ b/libswfdec/swfdec_as_object.h
@@ -177,6 +177,9 @@ void swfdec_as_object_call (SwfdecAsOb
void swfdec_as_object_run (SwfdecAsObject * object,
SwfdecScript * script);
+const char* swfdec_as_object_to_string (SwfdecAsContext * context,
+ SwfdecAsObject * object);
+
G_END_DECLS
#endif
diff --git a/libswfdec/swfdec_as_string.c b/libswfdec/swfdec_as_string.c
index 5cb4d18..c9739c9 100644
--- a/libswfdec/swfdec_as_string.c
+++ b/libswfdec/swfdec_as_string.c
@@ -30,6 +30,7 @@
#include "swfdec_as_native_function.h"
#include "swfdec_as_strings.h"
#include "swfdec_debug.h"
+#include "swfdec_player_internal.h"
G_DEFINE_TYPE (SwfdecAsString, swfdec_as_string, SWFDEC_TYPE_AS_OBJECT)
@@ -76,11 +77,12 @@ swfdec_as_str_nth_char (const char *s, g
return s;
}
-static void
+SWFDEC_AS_NATIVE (251, 9, swfdec_as_string_lastIndexOf)
+void
swfdec_as_string_lastIndexOf (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
gsize len;
const char *s;
@@ -91,23 +93,24 @@ swfdec_as_string_lastIndexOf (SwfdecAsCo
SWFDEC_AS_VALUE_SET_INT (ret, -1);
return;
}
- len = g_utf8_offset_to_pointer (string->string, offset + 1) - string->string;
+ len = g_utf8_offset_to_pointer (string, offset + 1) - string;
} else {
len = G_MAXSIZE;
}
- s = g_strrstr_len (string->string, len, s);
+ s = g_strrstr_len (string, len, s);
if (s) {
- SWFDEC_AS_VALUE_SET_INT (ret, g_utf8_pointer_to_offset (string->string, s));
+ SWFDEC_AS_VALUE_SET_INT (ret, g_utf8_pointer_to_offset (string, s));
} else {
SWFDEC_AS_VALUE_SET_INT (ret, -1);
}
}
-static void
+SWFDEC_AS_NATIVE (251, 8, swfdec_as_string_indexOf)
+void
swfdec_as_string_indexOf (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
int offset=0, len, i=-1;
const char *s, *t = NULL;
@@ -116,22 +119,23 @@ swfdec_as_string_indexOf (SwfdecAsContex
offset = swfdec_as_value_to_integer (object->context, &argv[1]);
if (offset < 0)
offset = 0;
- len = g_utf8_strlen (string->string, -1);
+ len = g_utf8_strlen (string, -1);
if (offset < len) {
- t = strstr (g_utf8_offset_to_pointer (string->string, offset), s);
+ t = strstr (g_utf8_offset_to_pointer (string, offset), s);
}
if (t != NULL) {
- i = g_utf8_pointer_to_offset (string->string, t);
+ i = g_utf8_pointer_to_offset (string, t);
}
SWFDEC_AS_VALUE_SET_INT (ret, i);
}
-static void
+SWFDEC_AS_NATIVE (251, 5, swfdec_as_string_charAt)
+void
swfdec_as_string_charAt (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
int i;
const char *s, *t;
@@ -140,7 +144,7 @@ swfdec_as_string_charAt (SwfdecAsContext
SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_EMPTY);
return;
}
- s = swfdec_as_str_nth_char (string->string, i);
+ s = swfdec_as_str_nth_char (string, i);
if (*s == 0) {
SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_EMPTY);
return;
@@ -150,11 +154,12 @@ swfdec_as_string_charAt (SwfdecAsContext
SWFDEC_AS_VALUE_SET_STRING (ret, s);
}
-static void
+SWFDEC_AS_NATIVE (251, 6, swfdec_as_string_charCodeAt)
+void
swfdec_as_string_charCodeAt (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
int i;
const char *s;
gunichar c;
@@ -164,7 +169,7 @@ swfdec_as_string_charCodeAt (SwfdecAsCon
SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN);
return;
}
- s = swfdec_as_str_nth_char (string->string, i);
+ s = swfdec_as_str_nth_char (string, i);
if (*s == 0) {
if (cx->version > 5) {
SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN);
@@ -266,7 +271,8 @@ swfdec_as_string_construct (SwfdecAsCont
}
}
-static void
+SWFDEC_AS_NATIVE (251, 2, swfdec_as_string_toString)
+void
swfdec_as_string_toString (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
@@ -275,7 +281,8 @@ swfdec_as_string_toString (SwfdecAsConte
SWFDEC_AS_VALUE_SET_STRING (ret, string->string);
}
-static void
+SWFDEC_AS_NATIVE (251, 1, swfdec_as_string_valueOf)
+void
swfdec_as_string_valueOf (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
@@ -302,7 +309,7 @@ swfdec_as_string_split_5 (SwfdecAsContex
const char *str, *end, *delim;
int count;
- str = SWFDEC_AS_STRING (object)->string;
+ str = swfdec_as_object_to_string (cx, object);
arr = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx));
if (arr == NULL)
return;
@@ -347,7 +354,7 @@ swfdec_as_string_split_5 (SwfdecAsContex
}
static void
-swfdec_as_string_split (SwfdecAsContext *cx, SwfdecAsObject *object,
+swfdec_as_string_split_6 (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
SwfdecAsArray *arr;
@@ -356,7 +363,7 @@ swfdec_as_string_split (SwfdecAsContext
int count;
guint len;
- str = SWFDEC_AS_STRING (object)->string;
+ str = swfdec_as_object_to_string (cx, object);
arr = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx));
if (arr == NULL)
return;
@@ -402,6 +409,18 @@ swfdec_as_string_split (SwfdecAsContext
}
}
+SWFDEC_AS_NATIVE (251, 12, swfdec_as_string_split)
+void
+swfdec_as_string_split (SwfdecAsContext *cx, SwfdecAsObject *object,
+ guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
+{
+ if (cx->version == 5) {
+ swfdec_as_string_split_5 (cx, object, argc, argv, ret);
+ } else {
+ swfdec_as_string_split_6 (cx, object, argc, argv, ret);
+ }
+}
+
static const char *
swfdec_as_str_sub (SwfdecAsContext *cx, const char *str, guint offset, guint len)
{
@@ -413,15 +432,16 @@ swfdec_as_str_sub (SwfdecAsContext *cx,
return str;
}
-static void
+SWFDEC_AS_NATIVE (251, 13, swfdec_as_string_substr)
+void
swfdec_as_string_substr (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
int from, to, len;
from = swfdec_as_value_to_integer (cx, &argv[0]);
- len = g_utf8_strlen (string->string, -1);
+ len = g_utf8_strlen (string, -1);
if (argc > 1) {
to = swfdec_as_value_to_integer (cx, &argv[1]);
@@ -443,17 +463,18 @@ swfdec_as_string_substr (SwfdecAsContext
from += len;
from = CLAMP (from, 0, len);
to = CLAMP (to, 0, len - from);
- SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_str_sub (cx, string->string, from, to));
+ SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_str_sub (cx, string, from, to));
}
-static void
+SWFDEC_AS_NATIVE (251, 11, swfdec_as_string_substring)
+void
swfdec_as_string_substring (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
int from, to, len;
- len = g_utf8_strlen (string->string, -1);
+ len = g_utf8_strlen (string, -1);
from = swfdec_as_value_to_integer (cx, &argv[0]);
if (argc > 1) {
to = swfdec_as_value_to_integer (cx, &argv[1]);
@@ -471,29 +492,31 @@ swfdec_as_string_substring (SwfdecAsCont
to = from;
from = tmp;
}
- SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_str_sub (cx, string->string, from, to - from));
+ SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_str_sub (cx, string, from, to - from));
}
-static void
+SWFDEC_AS_NATIVE (251, 4, swfdec_as_string_toLowerCase)
+void
swfdec_as_string_toLowerCase (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
char *s;
- s = g_utf8_strdown (string->string, -1);
+ s = g_utf8_strdown (string, -1);
SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (cx, s));
g_free (s);
}
-static void
+SWFDEC_AS_NATIVE (251, 3, swfdec_as_string_toUpperCase)
+void
swfdec_as_string_toUpperCase (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SwfdecAsString *string = SWFDEC_AS_STRING (object);
+ const char *string = swfdec_as_object_to_string (cx, object);
char *s;
- s = g_utf8_strup (string->string, -1);
+ s = g_utf8_strup (string, -1);
SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (cx, s));
g_free (s);
}
@@ -748,21 +771,17 @@ swfdec_as_string_init_context (SwfdecAsC
SWFDEC_AS_VALUE_SET_OBJECT (&val, string);
swfdec_as_object_set_variable_and_flags (proto, SWFDEC_AS_STR_constructor,
&val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_charAt, SWFDEC_TYPE_AS_STRING, swfdec_as_string_charAt, 1);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_indexOf, SWFDEC_TYPE_AS_STRING, swfdec_as_string_indexOf, 1);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_lastIndexOf, SWFDEC_TYPE_AS_STRING, swfdec_as_string_lastIndexOf, 1);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_charCodeAt, SWFDEC_TYPE_AS_STRING, swfdec_as_string_charCodeAt, 1);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_substr, SWFDEC_TYPE_AS_STRING, swfdec_as_string_substr, 1);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_substring, SWFDEC_TYPE_AS_STRING, swfdec_as_string_substring, 1);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_toLowerCase, SWFDEC_TYPE_AS_STRING, swfdec_as_string_toLowerCase, 0);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_charAt, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_charAt, 1);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_indexOf, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_indexOf, 1);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_lastIndexOf, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_lastIndexOf, 1);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_charCodeAt, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_charCodeAt, 1);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_substr, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_substr, 1);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_substring, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_substring, 1);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_toLowerCase, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_toLowerCase, 0);
swfdec_as_object_add_function (proto, SWFDEC_AS_STR_toString, SWFDEC_TYPE_AS_STRING, swfdec_as_string_toString, 0);
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_toUpperCase, SWFDEC_TYPE_AS_STRING, swfdec_as_string_toUpperCase, 0);
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_toUpperCase, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_toUpperCase, 0);
swfdec_as_object_add_function (proto, SWFDEC_AS_STR_valueOf, SWFDEC_TYPE_AS_STRING, swfdec_as_string_valueOf, 0);
- if (context->version < 6) {
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_split, SWFDEC_TYPE_AS_STRING, swfdec_as_string_split_5, 1);
- } else {
- swfdec_as_object_add_function (proto, SWFDEC_AS_STR_split, SWFDEC_TYPE_AS_STRING, swfdec_as_string_split, 1);
- }
+ swfdec_as_object_add_function (proto, SWFDEC_AS_STR_split, SWFDEC_TYPE_AS_OBJECT, swfdec_as_string_split, 1);
SWFDEC_AS_VALUE_SET_OBJECT (&val, context->Object_prototype);
swfdec_as_object_set_variable_and_flags (proto, SWFDEC_AS_STR___proto__, &val,
SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT);
diff-tree 6360caf2cc3bd3b3b576b3cd36320108aa15e5b5 (from 728258ea82c104389bddb4730402eeac931e3a14)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 24 10:38:56 2007 +0300
Add a FIXME about unimplemented ASSetPropFlags feature (creating length prop)
diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index ccb6a3c..b1b8efc 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -1120,6 +1120,13 @@ swfdec_as_context_ASSetPropFlags (Swfdec
obj = SWFDEC_AS_VALUE_GET_OBJECT (&argv[0]);
flags[0] = swfdec_as_value_to_integer (cx, &argv[2]);
flags[1] = (argc > 3) ? swfdec_as_value_to_integer (cx, &argv[3]) : 0;
+
+ if (flags[0] == 0 && flags[1] == 0) {
+ // we should add autosizing length attribute here
+ SWFDEC_FIXME ("ASSetPropFlags to set special length attribute not implemented");
+ return;
+ }
+
if (SWFDEC_AS_VALUE_IS_NULL (&argv[1])) {
swfdec_as_object_foreach (obj, swfdec_as_context_ASSetPropFlags_foreach, flags);
} else {
More information about the Swfdec
mailing list