[Swfdec] 4 commits - libswfdec/swfdec_as_number.c libswfdec/swfdec_as_strings.c libswfdec/swfdec_player_as.c test/trace

Pekka Lampila medar at kemper.freedesktop.org
Fri Aug 31 13:49:49 PDT 2007


 libswfdec/swfdec_as_number.c                 |    6 ++-
 libswfdec/swfdec_as_strings.c                |    1 
 libswfdec/swfdec_player_as.c                 |   52 +++++++++++++++++++++++++++
 test/trace/asfunction-properties-6.swf       |binary
 test/trace/asfunction-properties-6.swf.trace |   22 ++++++++++-
 test/trace/asfunction-properties-7.swf       |binary
 test/trace/asfunction-properties-7.swf.trace |   22 ++++++++++-
 test/trace/asfunction-properties.as          |   16 ++++++--
 8 files changed, 110 insertions(+), 9 deletions(-)

New commits:
diff-tree 4305a7503846739da9ce1db2a9c9e83ff45e10ba (from 9f17806b6f4230e268163b78931fe7a0be53dfe9)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Aug 31 23:45:19 2007 +0300

    Delete __proto__ and constructor properties from ASnative and ASconstructor
    
    Enable testing for these in asfunction-properties

diff --git a/libswfdec/swfdec_player_as.c b/libswfdec/swfdec_player_as.c
index d9c49bf..ee21aa0 100644
--- a/libswfdec/swfdec_player_as.c
+++ b/libswfdec/swfdec_player_as.c
@@ -260,6 +260,8 @@ swfdec_player_object_registerClass (Swfd
 void
 swfdec_player_init_global (SwfdecPlayer *player, guint version)
 {
+  SwfdecAsValue val;
+  SwfdecAsObject *object;
   SwfdecAsContext *context = SWFDEC_AS_CONTEXT (player);
 
   swfdec_as_object_add_function (context->Object, SWFDEC_AS_STR_registerClass, 
@@ -272,5 +274,28 @@ swfdec_player_init_global (SwfdecPlayer 
       0, swfdec_player_ASnative, 2);
   swfdec_as_object_add_function (context->global, SWFDEC_AS_STR_ASconstructor,
       0, swfdec_player_ASconstructor, 2);
+
+  // remove __proto__ and constructor from ASnative and ASconstructor
+
+  swfdec_as_object_get_variable (context->global, SWFDEC_AS_STR_ASnative, &val);
+  g_assert (SWFDEC_AS_VALUE_IS_OBJECT (&val));
+  object = SWFDEC_AS_VALUE_GET_OBJECT (&val);
+  swfdec_as_object_unset_variable_flags (object, SWFDEC_AS_STR___proto__,
+      SWFDEC_AS_VARIABLE_PERMANENT);
+  swfdec_as_object_delete_variable (object, SWFDEC_AS_STR___proto__);
+  swfdec_as_object_unset_variable_flags (object, SWFDEC_AS_STR_constructor,
+      SWFDEC_AS_VARIABLE_PERMANENT);
+  swfdec_as_object_delete_variable (object, SWFDEC_AS_STR_constructor);
+
+  swfdec_as_object_get_variable (context->global, SWFDEC_AS_STR_ASconstructor,
+      &val);
+  g_assert (SWFDEC_AS_VALUE_IS_OBJECT (&val));
+  object = SWFDEC_AS_VALUE_GET_OBJECT (&val);
+  swfdec_as_object_unset_variable_flags (object, SWFDEC_AS_STR___proto__,
+      SWFDEC_AS_VARIABLE_PERMANENT);
+  swfdec_as_object_delete_variable (object, SWFDEC_AS_STR___proto__);
+  swfdec_as_object_unset_variable_flags (object, SWFDEC_AS_STR_constructor,
+      SWFDEC_AS_VARIABLE_PERMANENT);
+  swfdec_as_object_delete_variable (object, SWFDEC_AS_STR_constructor);
 }
 
diff --git a/test/trace/asfunction-properties-6.swf b/test/trace/asfunction-properties-6.swf
index 7b7721f..fcab036 100644
Binary files a/test/trace/asfunction-properties-6.swf and b/test/trace/asfunction-properties-6.swf differ
diff --git a/test/trace/asfunction-properties-6.swf.trace b/test/trace/asfunction-properties-6.swf.trace
index 60d2c04..1b8f651 100644
--- a/test/trace/asfunction-properties-6.swf.trace
+++ b/test/trace/asfunction-properties-6.swf.trace
@@ -1,3 +1,7 @@
+_global.ASconstructor = function
+  no children
+_global.ASnative = function
+  no children
 _global.ASSetNativeAccessor = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
diff --git a/test/trace/asfunction-properties-7.swf b/test/trace/asfunction-properties-7.swf
index 454c58c..782a746 100644
Binary files a/test/trace/asfunction-properties-7.swf and b/test/trace/asfunction-properties-7.swf differ
diff --git a/test/trace/asfunction-properties-7.swf.trace b/test/trace/asfunction-properties-7.swf.trace
index 60d2c04..1b8f651 100644
--- a/test/trace/asfunction-properties-7.swf.trace
+++ b/test/trace/asfunction-properties-7.swf.trace
@@ -1,3 +1,7 @@
+_global.ASconstructor = function
+  no children
+_global.ASnative = function
+  no children
 _global.ASSetNativeAccessor = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
diff --git a/test/trace/asfunction-properties.as b/test/trace/asfunction-properties.as
index 186a750..235eeef 100644
--- a/test/trace/asfunction-properties.as
+++ b/test/trace/asfunction-properties.as
@@ -7,9 +7,8 @@ var b = ASnative (106, 2);
 var c = ASconstructor (106, 1); // _global.Number.prototype.toString
 var d = ASnative (106, 1);
 
-// these two have __proto__ and constructor in swfdec, shouldn't
-//trace_properties (_global.ASconstructor, "_global", "ASconstructor");
-//trace_properties (_global.ASnative, "_global", "ASnative");
+trace_properties (_global.ASconstructor, "_global", "ASconstructor");
+trace_properties (_global.ASnative, "_global", "ASnative");
 trace_properties (_global.ASSetNativeAccessor, "_global", "ASSetNativeAccessor");
 trace_properties (_global.ASSetNative, "_global", "ASSetNative");
 trace_properties (_global.ASSetPropFlags, "_global", "ASSetPropFlags");
diff-tree 9f17806b6f4230e268163b78931fe7a0be53dfe9 (from 88a578f46125d2ef9b9c08d9ed6bf0bc1e161819)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Aug 31 23:38:59 2007 +0300

    Extend asfunction-properties test
    
    Test properties of functions received from ASnative and ASconstructor

diff --git a/test/trace/asfunction-properties-6.swf b/test/trace/asfunction-properties-6.swf
index 1741f67..7b7721f 100644
Binary files a/test/trace/asfunction-properties-6.swf and b/test/trace/asfunction-properties-6.swf differ
diff --git a/test/trace/asfunction-properties-6.swf.trace b/test/trace/asfunction-properties-6.swf.trace
index f5db56f..60d2c04 100644
--- a/test/trace/asfunction-properties-6.swf.trace
+++ b/test/trace/asfunction-properties-6.swf.trace
@@ -1,9 +1,23 @@
-_global.ASSetNative = function
+_global.ASSetNativeAccessor = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
-_global.ASSetNativeAccessor = function
+_global.ASSetNative = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
 _global.ASSetPropFlags = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
+local.a = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
+  prototype (hp) = _global.Object.prototype
+local.b = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
+local.c = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
+  prototype (hp) = _global.Object.prototype
+local.d = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
diff --git a/test/trace/asfunction-properties-7.swf b/test/trace/asfunction-properties-7.swf
index 9f350dc..454c58c 100644
Binary files a/test/trace/asfunction-properties-7.swf and b/test/trace/asfunction-properties-7.swf differ
diff --git a/test/trace/asfunction-properties-7.swf.trace b/test/trace/asfunction-properties-7.swf.trace
index f5db56f..60d2c04 100644
--- a/test/trace/asfunction-properties-7.swf.trace
+++ b/test/trace/asfunction-properties-7.swf.trace
@@ -1,9 +1,23 @@
-_global.ASSetNative = function
+_global.ASSetNativeAccessor = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
-_global.ASSetNativeAccessor = function
+_global.ASSetNative = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
 _global.ASSetPropFlags = function
   __proto__ (hp) = _global.Object.__proto__
   constructor (hp) = _global.Object.constructor
+local.a = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
+  prototype (hp) = _global.Object.prototype
+local.b = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
+local.c = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
+  prototype (hp) = _global.Object.prototype
+local.d = _global.Object.__proto__
+  __proto__ (hp) = _global.Object.__proto__
+  constructor (hp) = _global.Object.constructor
diff --git a/test/trace/asfunction-properties.as b/test/trace/asfunction-properties.as
index d642ca3..186a750 100644
--- a/test/trace/asfunction-properties.as
+++ b/test/trace/asfunction-properties.as
@@ -2,10 +2,21 @@
 
 #include "trace_properties.as"
 
-trace_properties (_global.ASSetNative, "_global", "ASSetNative");
+var a = ASconstructor (106, 2); // _global.Number
+var b = ASnative (106, 2);
+var c = ASconstructor (106, 1); // _global.Number.prototype.toString
+var d = ASnative (106, 1);
+
+// these two have __proto__ and constructor in swfdec, shouldn't
+//trace_properties (_global.ASconstructor, "_global", "ASconstructor");
+//trace_properties (_global.ASnative, "_global", "ASnative");
 trace_properties (_global.ASSetNativeAccessor, "_global", "ASSetNativeAccessor");
+trace_properties (_global.ASSetNative, "_global", "ASSetNative");
 trace_properties (_global.ASSetPropFlags, "_global", "ASSetPropFlags");
-//trace_properties (_global.ASnative, "_global", "ASnative");
-//trace_properties (_global.ASconstructor, "_global", "ASconstructor");
+
+trace_properties (a, "local", "a");
+trace_properties (b, "local", "b");
+trace_properties (c, "local", "c");
+trace_properties (d, "local", "d");
 
 loadMovie ("FSCommand:quit", "");
diff-tree 88a578f46125d2ef9b9c08d9ed6bf0bc1e161819 (from b248b16d97eeed1522e4a5791beaeb316cf584b8)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Aug 31 23:37:21 2007 +0300

    Add ASnative definations for Number valueOf and toString functions

diff --git a/libswfdec/swfdec_as_number.c b/libswfdec/swfdec_as_number.c
index d53e725..9328b26 100644
--- a/libswfdec/swfdec_as_number.c
+++ b/libswfdec/swfdec_as_number.c
@@ -67,7 +67,8 @@ swfdec_as_number_construct (SwfdecAsCont
   }
 }
 
-static void
+SWFDEC_AS_NATIVE (106, 1, swfdec_as_number_toString)
+void
 swfdec_as_number_toString (SwfdecAsContext *cx, SwfdecAsObject *object,
     guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
 {
@@ -83,7 +84,8 @@ swfdec_as_number_toString (SwfdecAsConte
   SWFDEC_AS_VALUE_SET_STRING (ret, s);
 }
 
-static void
+SWFDEC_AS_NATIVE (106, 1, swfdec_as_number_valueOf)
+void
 swfdec_as_number_valueOf (SwfdecAsContext *cx, SwfdecAsObject *object,
     guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
 {
diff-tree b248b16d97eeed1522e4a5791beaeb316cf584b8 (from 19fceebeff8cdda74fcfa2acebe29e2a9b33ed0c)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Aug 31 23:28:36 2007 +0300

    Implement ASconstructor

diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index 9fb0169..e09c854 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -283,6 +283,7 @@ const char swfdec_as_strings[] = 
   SWFDEC_AS_CONSTANT_STRING ("hasTLS")
   SWFDEC_AS_CONSTANT_STRING ("serverString")
   SWFDEC_AS_CONSTANT_STRING ("$version")
+  SWFDEC_AS_CONSTANT_STRING ("ASconstructor")
   /* add more here */
 ;
 
diff --git a/libswfdec/swfdec_player_as.c b/libswfdec/swfdec_player_as.c
index 3643ade..d9c49bf 100644
--- a/libswfdec/swfdec_player_as.c
+++ b/libswfdec/swfdec_player_as.c
@@ -116,6 +116,31 @@ swfdec_get_asnative (SwfdecAsContext *cx
   return NULL;
 }
 
+// same as ASnative, but also sets prototype
+static void
+swfdec_player_ASconstructor (SwfdecAsContext *cx, SwfdecAsObject *obj,
+    guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecAsValue val;
+  SwfdecAsFunction *func;
+  guint x, y;
+
+  x = swfdec_as_value_to_integer (cx, &argv[0]);
+  y = swfdec_as_value_to_integer (cx, &argv[1]);
+
+  func = swfdec_get_asnative (cx, x, y);
+  if (func) {
+    SWFDEC_AS_VALUE_SET_OBJECT (&val, swfdec_as_object_new (cx));
+    swfdec_as_object_set_variable_and_flags (SWFDEC_AS_OBJECT (func),
+	SWFDEC_AS_STR_prototype, &val,
+	SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT);
+
+    SWFDEC_AS_VALUE_SET_OBJECT (rval, SWFDEC_AS_OBJECT (func));
+  } else {
+    SWFDEC_FIXME ("ASconstructor for %u %u missing", x, y);
+  }
+}
+
 static void
 swfdec_player_ASnative (SwfdecAsContext *cx, SwfdecAsObject *obj,
     guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
@@ -245,5 +270,7 @@ swfdec_player_init_global (SwfdecPlayer 
       0, swfdec_player_clearInterval, 1);
   swfdec_as_object_add_function (context->global, SWFDEC_AS_STR_ASnative, 
       0, swfdec_player_ASnative, 2);
+  swfdec_as_object_add_function (context->global, SWFDEC_AS_STR_ASconstructor,
+      0, swfdec_player_ASconstructor, 2);
 }
 


More information about the Swfdec mailing list