[Swfdec] Branch 'as' - libswfdec/swfdec_as_frame.c libswfdec/swfdec_as_frame.h libswfdec/swfdec_as_function.c libswfdec/swfdec_as_function.h libswfdec/swfdec_as_native_function.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_script_function.c
Benjamin Otte
company at kemper.freedesktop.org
Mon May 21 12:56:50 PDT 2007
libswfdec/swfdec_as_frame.c | 45 ++++++++++++++++++++++------------
libswfdec/swfdec_as_frame.h | 6 +++-
libswfdec/swfdec_as_function.c | 4 ++-
libswfdec/swfdec_as_function.h | 3 --
libswfdec/swfdec_as_native_function.c | 4 +--
libswfdec/swfdec_as_object.c | 3 +-
libswfdec/swfdec_as_script_function.c | 4 +--
7 files changed, 44 insertions(+), 25 deletions(-)
New commits:
diff-tree 9611954464237c3162a09458e506840adb0943e5 (from 210bee663edb435f5f15cd5e8e9649faecd982d9)
Author: Benjamin Otte <otte at gnome.org>
Date: Mon May 21 21:52:06 2007 +0200
add swfdec_as_frame_set_this to allow calling functions without a this object
diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c
index 23b3c41..75e0534 100644
--- a/libswfdec/swfdec_as_frame.c
+++ b/libswfdec/swfdec_as_frame.c
@@ -68,7 +68,8 @@ swfdec_as_frame_mark (SwfdecAsObject *ob
if (frame->script) {
swfdec_as_object_mark (frame->var_object);
}
- swfdec_as_object_mark (frame->thisp);
+ if (frame->thisp)
+ swfdec_as_object_mark (frame->thisp);
if (frame->target)
swfdec_as_object_mark (frame->target);
if (frame->function)
@@ -76,7 +77,6 @@ swfdec_as_frame_mark (SwfdecAsObject *ob
for (i = 0; i < frame->n_registers; i++) {
swfdec_as_value_mark (&frame->registers[i]);
}
- /* FIXME: do we want this? */
for (i = 0; i < frame->argc; i++) {
swfdec_as_value_mark (&frame->argv[i]);
}
@@ -102,18 +102,15 @@ swfdec_as_frame_init (SwfdecAsFrame *fra
}
SwfdecAsFrame *
-swfdec_as_frame_new (SwfdecAsObject *thisp, SwfdecScript *script)
+swfdec_as_frame_new (SwfdecAsContext *context, SwfdecScript *script)
{
- SwfdecAsContext *context;
SwfdecAsFrame *frame;
SwfdecAsStack *stack;
gsize size;
- g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (thisp), NULL);
- g_return_val_if_fail (thisp->properties, NULL);
+ g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL);
g_return_val_if_fail (script != NULL, NULL);
- context = thisp->context;
stack = swfdec_as_stack_new (context, 100); /* FIXME: invent better numbers here */
if (!stack)
return NULL;
@@ -130,10 +127,10 @@ swfdec_as_frame_new (SwfdecAsObject *thi
frame->pc = script->buffer->data;
frame->stack = stack;
frame->scope = NULL;
- frame->var_object = frame->next ? frame->next->var_object : thisp;
+ if (frame->next)
+ frame->var_object = frame->next->var_object;
frame->n_registers = script->n_registers;
frame->registers = g_slice_alloc0 (sizeof (SwfdecAsValue) * frame->n_registers);
- frame->thisp = thisp;
if (script->constant_pool) {
frame->constant_pool_buffer = swfdec_buffer_ref (script->constant_pool);
frame->constant_pool = swfdec_constant_pool_new_from_action (
@@ -148,16 +145,13 @@ swfdec_as_frame_new (SwfdecAsObject *thi
}
SwfdecAsFrame *
-swfdec_as_frame_new_native (SwfdecAsObject *thisp)
+swfdec_as_frame_new_native (SwfdecAsContext *context)
{
- SwfdecAsContext *context;
SwfdecAsFrame *frame;
gsize size;
- g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (thisp), NULL);
- g_return_val_if_fail (thisp->properties, NULL);
+ g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL);
- context = thisp->context;
size = sizeof (SwfdecAsFrame);
if (!swfdec_as_context_use_mem (context, size))
return NULL;
@@ -166,11 +160,32 @@ swfdec_as_frame_new_native (SwfdecAsObje
swfdec_as_object_add (SWFDEC_AS_OBJECT (frame), context, size);
frame->next = context->frame;
context->frame = frame;
- frame->thisp = thisp;
return frame;
}
/**
+ * swfdec_as_frame_set_this:
+ * @frame: a #SwfdecAsFrame
+ * @thisp: object to use as the this object
+ *
+ * Sets the object to be used as this pointer. If this function is not called,
+ * the this value will be undefined.
+ * You may only call this function once per @frame and it must be called
+ * directly after creating the frame and before calling swfdec_as_frame_preload().
+ **/
+void
+swfdec_as_frame_set_this (SwfdecAsFrame *frame, SwfdecAsObject *thisp)
+{
+ g_return_if_fail (SWFDEC_IS_AS_FRAME (frame));
+ g_return_if_fail (frame->thisp == NULL);
+ g_return_if_fail (SWFDEC_IS_AS_OBJECT (thisp));
+
+ frame->thisp = thisp;
+ if (frame->var_object == NULL)
+ frame->var_object = thisp;
+}
+
+/**
* swfdec_as_frame_find_variable:
* @frame: a #SwfdecAsFrame
* @variable: name of the variable to find
diff --git a/libswfdec/swfdec_as_frame.h b/libswfdec/swfdec_as_frame.h
index 126d410..3cacbb1 100644
--- a/libswfdec/swfdec_as_frame.h
+++ b/libswfdec/swfdec_as_frame.h
@@ -67,9 +67,11 @@ struct _SwfdecAsFrameClass {
GType swfdec_as_frame_get_type (void);
-SwfdecAsFrame * swfdec_as_frame_new (SwfdecAsObject * thisp,
+SwfdecAsFrame * swfdec_as_frame_new (SwfdecAsContext * context,
SwfdecScript * script);
-SwfdecAsFrame * swfdec_as_frame_new_native (SwfdecAsObject * thisp);
+SwfdecAsFrame * swfdec_as_frame_new_native (SwfdecAsContext * context);
+void swfdec_as_frame_set_this (SwfdecAsFrame * frame,
+ SwfdecAsObject * thisp);
void swfdec_as_frame_preload (SwfdecAsFrame * frame);
SwfdecAsObject *swfdec_as_frame_find_variable (SwfdecAsFrame * frame,
diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c
index dd91fcc..8928f68 100644
--- a/libswfdec/swfdec_as_function.c
+++ b/libswfdec/swfdec_as_function.c
@@ -83,8 +83,10 @@ swfdec_as_function_call (SwfdecAsFunctio
SWFDEC_AS_VALUE_SET_UNDEFINED (return_value);
klass = SWFDEC_AS_FUNCTION_GET_CLASS (function);
g_assert (klass->call);
- klass->call (function, thisp);
+ klass->call (function);
frame = context->frame;
+ if (thisp)
+ swfdec_as_frame_set_this (frame, thisp);
frame->var_object = SWFDEC_AS_OBJECT (frame);
frame->argc = n_args;
frame->argv = args;
diff --git a/libswfdec/swfdec_as_function.h b/libswfdec/swfdec_as_function.h
index 951911e..ddc92d9 100644
--- a/libswfdec/swfdec_as_function.h
+++ b/libswfdec/swfdec_as_function.h
@@ -44,8 +44,7 @@ struct _SwfdecAsFunctionClass {
SwfdecAsObjectClass object_class;
/* call this function: push a new frame onto the stack */
- void (* call) (SwfdecAsFunction * function,
- SwfdecAsObject * thisp);
+ void (* call) (SwfdecAsFunction * function);
};
GType swfdec_as_function_get_type (void);
diff --git a/libswfdec/swfdec_as_native_function.c b/libswfdec/swfdec_as_native_function.c
index b373e3a..edc2a09 100644
--- a/libswfdec/swfdec_as_native_function.c
+++ b/libswfdec/swfdec_as_native_function.c
@@ -30,12 +30,12 @@
G_DEFINE_TYPE (SwfdecAsNativeFunction, swfdec_as_native_function, SWFDEC_TYPE_AS_FUNCTION)
static void
-swfdec_as_native_function_call (SwfdecAsFunction *function, SwfdecAsObject *thisp)
+swfdec_as_native_function_call (SwfdecAsFunction *function)
{
SwfdecAsNativeFunction *native = SWFDEC_AS_NATIVE_FUNCTION (function);
SwfdecAsFrame *frame;
- frame = swfdec_as_frame_new_native (thisp);
+ frame = swfdec_as_frame_new_native (SWFDEC_AS_OBJECT (function)->context);
g_assert (native->name);
frame->function_name = native->name;
}
diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 1c53e0d..6152d51 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -501,9 +501,10 @@ swfdec_as_object_run (SwfdecAsObject *ob
g_return_if_fail (SWFDEC_AS_OBJECT_HAS_CONTEXT (object));
g_return_if_fail (script != NULL);
- frame = swfdec_as_frame_new (object, script);
+ frame = swfdec_as_frame_new (object->context, script);
if (frame == NULL)
return;
+ swfdec_as_frame_set_this (frame, object);
swfdec_as_frame_preload (frame);
swfdec_as_context_run (object->context);
}
diff --git a/libswfdec/swfdec_as_script_function.c b/libswfdec/swfdec_as_script_function.c
index 2f75150..bbe4eec 100644
--- a/libswfdec/swfdec_as_script_function.c
+++ b/libswfdec/swfdec_as_script_function.c
@@ -30,12 +30,12 @@
G_DEFINE_TYPE (SwfdecAsScriptFunction, swfdec_as_script_function, SWFDEC_TYPE_AS_FUNCTION)
static void
-swfdec_as_script_function_call (SwfdecAsFunction *function, SwfdecAsObject *thisp)
+swfdec_as_script_function_call (SwfdecAsFunction *function)
{
SwfdecAsScriptFunction *script = SWFDEC_AS_SCRIPT_FUNCTION (function);
SwfdecAsFrame *frame;
- frame = swfdec_as_frame_new (thisp, script->script);
+ frame = swfdec_as_frame_new (SWFDEC_AS_OBJECT (function)->context, script->script);
SWFDEC_AS_SCOPE (frame)->next = script->scope;
frame->scope = SWFDEC_AS_SCOPE (frame);
}
More information about the Swfdec
mailing list