[Swfdec] Branch 'interpreter' - 3 commits - libswfdec/js
libswfdec/swfdec_script.c
Benjamin Otte
company at kemper.freedesktop.org
Wed Jan 31 12:43:16 PST 2007
libswfdec/js/jsinterp.c | 2
libswfdec/swfdec_script.c | 114 +++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 104 insertions(+), 12 deletions(-)
New commits:
diff-tree ae64862c94f18618313c90c28b4071d84693b7b5 (from 71b090ccdeedb1e96b2f8590844844139b00bd85)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 31 21:35:50 2007 +0100
implement BitAnd, BitOr, BitXor, DefineLocal, DefineLocal2 and Return
diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index 9b3a328..46ba618 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -1359,6 +1359,35 @@ swfdec_action_define_function (JSContext
}
static JSBool
+swfdec_action_bitwise (JSContext *cx, guint action, const guint8 *data, guint len)
+{
+ guint32 a, b;
+ double d;
+
+ if (!JS_ValueToECMAUint32 (cx, cx->fp->sp[-1], &a) ||
+ !JS_ValueToECMAUint32 (cx, cx->fp->sp[-2], &b))
+ return JS_FALSE;
+
+ switch (action) {
+ case 0x60:
+ d = (int) (a & b);
+ break;
+ case 0x61:
+ d = (int) (a | b);
+ break;
+ case 0x62:
+ d = (int) (a ^ b);
+ break;
+ default:
+ g_assert_not_reached ();
+ return JS_FALSE;
+ }
+
+ cx->fp->sp--;
+ return JS_NewNumberValue (cx, d, &cx->fp->sp[-1]);
+}
+
+static JSBool
swfdec_action_shift (JSContext *cx, guint action, const guint8 *data, guint len)
{
guint32 amount, value;
@@ -1414,6 +1443,54 @@ swfdec_action_target_path (JSContext *cx
return JS_TRUE;
}
+static JSBool
+swfdec_action_define_local (JSContext *cx, guint action, const guint8 *data, guint len)
+{
+ const char *name;
+
+ if (cx->fp->callobj == NULL) {
+ SWFDEC_ERROR ("FIXME: no local scope");
+ return JS_FALSE;
+ }
+ name = swfdec_js_to_string (cx, cx->fp->sp[-2]);
+ if (name == NULL)
+ return JS_FALSE;
+ if (!JS_SetProperty (cx, cx->fp->callobj, name, &cx->fp->sp[-1]))
+ return JS_FALSE;
+ cx->fp->sp -= 2;
+ return JS_TRUE;
+}
+
+static JSBool
+swfdec_action_define_local2 (JSContext *cx, guint action, const guint8 *data, guint len)
+{
+ const char *name;
+ jsval val = JSVAL_VOID;
+
+ if (cx->fp->callobj == NULL) {
+ SWFDEC_ERROR ("FIXME: no local scope");
+ return JS_FALSE;
+ }
+ name = swfdec_js_to_string (cx, cx->fp->sp[-1]);
+ if (name == NULL)
+ return JS_FALSE;
+ if (!JS_SetProperty (cx, cx->fp->callobj, name, &val))
+ return JS_FALSE;
+ cx->fp->sp--;
+ return JS_TRUE;
+}
+
+static JSBool
+swfdec_action_return (JSContext *cx, guint action, const guint8 *data, guint len)
+{
+ SwfdecScript *script = cx->fp->swf;
+
+ cx->fp->rval = cx->fp->sp[-1];
+ cx->fp->pc = script->buffer->data + script->buffer->length;
+ cx->fp->sp--;
+ return JS_TRUE;
+}
+
/*** PRINT FUNCTIONS ***/
static char *
@@ -1703,12 +1780,12 @@ static const SwfdecActionSpec actions[25
/* version 5 */
[0x3a] = { "Delete", NULL },
[0x3b] = { "Delete2", NULL },
- [0x3c] = { "DefineLocal", NULL }, //, 2, 0, { NULL, NULL, swfdec_action_define_local, swfdec_action_define_local, swfdec_action_define_local } },
+ [0x3c] = { "DefineLocal", NULL, 2, 0, { NULL, NULL, swfdec_action_define_local, swfdec_action_define_local, swfdec_action_define_local } },
[0x3d] = { "CallFunction", NULL, -1, 1, { NULL, NULL, swfdec_action_call_function, swfdec_action_call_function, swfdec_action_call_function } },
- [0x3e] = { "Return", NULL },
+ [0x3e] = { "Return", NULL, 1, 0, { NULL, NULL, swfdec_action_return, swfdec_action_return, swfdec_action_return } },
[0x3f] = { "Modulo", NULL },
[0x40] = { "NewObject", NULL, -1, 1, { NULL, NULL, swfdec_action_new_object, swfdec_action_new_object, swfdec_action_new_object } },
- [0x41] = { "DefineLocal2", NULL },
+ [0x41] = { "DefineLocal2", NULL, 1, 0, { NULL, NULL, swfdec_action_define_local2, swfdec_action_define_local2, swfdec_action_define_local2 } },
[0x42] = { "InitArray", NULL },
[0x43] = { "InitObject", NULL, -1, 1, { NULL, NULL, swfdec_action_init_object, swfdec_action_init_object, swfdec_action_init_object } },
[0x44] = { "Typeof", NULL },
@@ -1731,9 +1808,9 @@ static const SwfdecActionSpec actions[25
[0x54] = { "InstanceOf", NULL },
[0x55] = { "Enumerate2", NULL },
/* version 5 */
- [0x60] = { "BitAnd", NULL },
- [0x61] = { "BitOr", NULL },
- [0x62] = { "BitXor", NULL },
+ [0x60] = { "BitAnd", NULL, 2, 1, { NULL, NULL, swfdec_action_bitwise, swfdec_action_bitwise, swfdec_action_bitwise } },
+ [0x61] = { "BitOr", NULL, 2, 1, { NULL, NULL, swfdec_action_bitwise, swfdec_action_bitwise, swfdec_action_bitwise } },
+ [0x62] = { "BitXor", NULL, 2, 1, { NULL, NULL, swfdec_action_bitwise, swfdec_action_bitwise, swfdec_action_bitwise } },
[0x63] = { "BitLShift", NULL, 2, 1, { NULL, NULL, swfdec_action_shift, swfdec_action_shift, swfdec_action_shift } },
[0x64] = { "BitRShift", NULL, 2, 1, { NULL, NULL, swfdec_action_shift, swfdec_action_shift, swfdec_action_shift } },
[0x65] = { "BitURShift", NULL, 2, 1, { NULL, NULL, swfdec_action_shift, swfdec_action_shift, swfdec_action_shift } },
@@ -1994,8 +2071,11 @@ swfdec_script_interpret (SwfdecScript *s
while (TRUE) {
/* check pc */
- if (pc == endpc) /* needed for scripts created via DefineFunction */
+ if (pc == endpc) {
+ /* scripts created via DefineFunction or the Return action use this way out */
+ *rval = fp->rval;
break;
+ }
if (pc < startpc || pc >= endpc) {
SWFDEC_ERROR ("pc %p not in valid range [%p, %p) anymore", pc, startpc, endpc);
goto internal_error;
diff-tree 71b090ccdeedb1e96b2f8590844844139b00bd85 (from fa4f57c436b5f6232efacfa2b4ac94d14af1f409)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 31 19:59:15 2007 +0100
initialize the constant pool as empty
diff --git a/libswfdec/js/jsinterp.c b/libswfdec/js/jsinterp.c
index ce8d014..910087a 100644
--- a/libswfdec/js/jsinterp.c
+++ b/libswfdec/js/jsinterp.c
@@ -847,6 +847,7 @@ have_fun:
frame.sharpArray = NULL;
frame.dormantNext = NULL;
frame.objAtomMap = NULL;
+ frame.constant_pool = NULL;
/* Compute the 'this' parameter and store it in frame as frame.thisp. */
ok = ComputeThis(cx, thisp, &frame);
@@ -1140,6 +1141,7 @@ js_Execute(JSContext *cx, JSObject *chai
frame.flags = special;
frame.dormantNext = NULL;
frame.objAtomMap = NULL;
+ frame.constant_pool = NULL;
/*
* Here we wrap the call to js_Interpret with code to (conditionally)
diff-tree fa4f57c436b5f6232efacfa2b4ac94d14af1f409 (from 9335e136a9a1f2f3dbbbda7a7b156b55d94e7c4c)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 31 17:28:14 2007 +0100
implement Equals
This is the last action that the compiler had implemented and this branch hadn't
diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index 7c24b10..9b3a328 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -1019,7 +1019,7 @@ swfdec_action_random_number (JSContext *
}
static JSBool
-swfdec_action_less (JSContext *cx, guint action, const guint8 *data, guint len)
+swfdec_action_old_compare (JSContext *cx, guint action, const guint8 *data, guint len)
{
jsval rval, lval;
double l, r;
@@ -1029,7 +1029,17 @@ swfdec_action_less (JSContext *cx, guint
lval = cx->fp->sp[-2];
l = swfdec_action_to_number (cx, lval);
r = swfdec_action_to_number (cx, rval);
- cond = l < r;
+ switch (action) {
+ case 0x0e:
+ cond = l == r;
+ break;
+ case 0x0f:
+ cond = l < r;
+ break;
+ default:
+ g_assert_not_reached ();
+ return JS_FALSE;
+ }
cx->fp->sp--;
if (((SwfdecScript *) cx->fp->swf)->version < 5) {
cx->fp->sp[-1] = INT_TO_JSVAL (cond ? 1 : 0);
@@ -1655,8 +1665,8 @@ static const SwfdecActionSpec actions[25
[0x0b] = { "Subtract", NULL, 2, 1, { NULL, swfdec_action_binary, swfdec_action_binary, swfdec_action_binary, swfdec_action_binary } },
[0x0c] = { "Multiply", NULL, 2, 1, { NULL, swfdec_action_binary, swfdec_action_binary, swfdec_action_binary, swfdec_action_binary } },
[0x0d] = { "Divide", NULL, 2, 1, { NULL, swfdec_action_binary, swfdec_action_binary, swfdec_action_binary, swfdec_action_binary } },
- [0x0e] = { "Equals", NULL },
- [0x0f] = { "Less", NULL, 2, 1, { NULL, swfdec_action_less, swfdec_action_less, swfdec_action_less, swfdec_action_less } },
+ [0x0e] = { "Equals", NULL, 2, 1, { NULL, swfdec_action_old_compare, swfdec_action_old_compare, swfdec_action_old_compare, swfdec_action_old_compare } },
+ [0x0f] = { "Less", NULL, 2, 1, { NULL, swfdec_action_old_compare, swfdec_action_old_compare, swfdec_action_old_compare, swfdec_action_old_compare } },
[0x10] = { "And", NULL },
[0x11] = { "Or", NULL },
[0x12] = { "Not", NULL, 1, 1, { NULL, swfdec_action_not_4, swfdec_action_not_5, swfdec_action_not_5, swfdec_action_not_5 } },
@@ -1705,7 +1715,7 @@ static const SwfdecActionSpec actions[25
[0x45] = { "TargetPath", NULL, 1, 1, { NULL, NULL, swfdec_action_target_path, swfdec_action_target_path, swfdec_action_target_path } },
[0x46] = { "Enumerate", NULL },
[0x47] = { "Add2", NULL, 2, 1, { NULL, NULL, swfdec_action_add2_5, swfdec_action_add2_5, swfdec_action_add2_7 } },
- [0x48] = { "Less2", NULL, 2, 1, { NULL, NULL, swfdec_action_new_comparison_6, swfdec_action_new_comparison_6, swfdec_action_new_comparison_7 } },
+ [0x48] = { "Less2", NULL, 2, 1, { NULL, NULL, swfdec_action_new_comparison_6, swfdec_action_new_comparison_6, swfdec_action_new_comparison_7 } },
[0x49] = { "Equals2", NULL, 2, 1, { NULL, NULL, swfdec_action_equals2, swfdec_action_equals2, swfdec_action_equals2 } },
[0x4a] = { "ToNumber", NULL },
[0x4b] = { "ToString", NULL },
More information about the Swfdec
mailing list