[Swfdec] 2 commits - test/trace
Pekka Lampila
medar at kemper.freedesktop.org
Tue Aug 21 13:03:32 PDT 2007
test/trace/propflags-5.swf |binary
test/trace/propflags-5.swf.trace | 20 +-
test/trace/propflags-6.swf |binary
test/trace/propflags-6.swf.trace | 20 +-
test/trace/propflags-7.swf |binary
test/trace/propflags-7.swf.trace | 19 +-
test/trace/propflags.as | 6
test/trace/trace_properties.as | 304 ++++++++++++++++++++++++++++++---------
8 files changed, 271 insertions(+), 98 deletions(-)
New commits:
diff-tree 92ddd92a1bf234440d90f8707067be07d36ab16c (from f1d548cb56d3e4f8b48eb1fc99ebb006f61c259f)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Tue Aug 21 23:02:26 2007 +0300
Fix errors in the trace_properties.as
Only use own version of hasOwnProperty in version 5
Recompile propflags to use the new code
diff --git a/test/trace/propflags-5.swf b/test/trace/propflags-5.swf
index 3f6f077..acea9ad 100644
Binary files a/test/trace/propflags-5.swf and b/test/trace/propflags-5.swf differ
diff --git a/test/trace/propflags-6.swf b/test/trace/propflags-6.swf
index 0d4ec6c..ea5e27b 100644
Binary files a/test/trace/propflags-6.swf and b/test/trace/propflags-6.swf differ
diff --git a/test/trace/propflags-7.swf b/test/trace/propflags-7.swf
index 086b2bc..ee97994 100644
Binary files a/test/trace/propflags-7.swf and b/test/trace/propflags-7.swf differ
diff --git a/test/trace/trace_properties.as b/test/trace/trace_properties.as
index 6256a42..92294a9 100644
--- a/test/trace/trace_properties.as
+++ b/test/trace/trace_properties.as
@@ -2,81 +2,108 @@
function new_empty_object () {
var hash = new Object ();
+ ASSetPropFlags (hash, null, 0, 7);
for (var prop in hash) {
delete hash[prop];
}
return hash;
}
+#if __SWF_VERSION__ >= 6
function hasOwnProperty (o, prop)
{
- if (o.__proto__ == undefined || o.__proto__ == "assdofjkaofjojsafjpojsafa")
+ if (o.hasOwnProperty != undefined)
+ return o.hasOwnProperty (prop);
+
+ o.hasOwnProperty = Object.prototype.hasOwnProperty;
+ result = o.hasOwnProperty (prop);
+ delete o.hasOwnProperty;
+ return result;
+}
+#else
+// this gets the same result as the above, with following limitations:
+// - if there is a child __proto__[prop] with value that can't be changed, no
+// test can be done and false is returned
+// - native properties that have value undefined by default get overwritten by
+// __proto__[prop]'s value (atleast in version 6 and 7) so their existance
+// won't be detected by this function
+function hasOwnProperty (o, prop)
+{
+ if (o.__proto__ == undefined)
{
- if (o[prop] != undefined)
- return true;
- else
- return false;
o.__proto__ = new_empty_object ();
- o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
- var result;
+
+ o.__proto__[prop] = "safdlojasfljsaiofhiwjhefa";
if (o[prop] != o.__proto__[prop]) {
result = true;
} else {
result = false;
}
- // have to be set to string first, otherwise it won't delete
+
o.__proto__ = "to-be-deleted";
delete o.__proto__;
+ if (o.__proto__ != undefined) {
+ trace ("ERROR: Couldn't delete temporary __proto__");
+ o.__proto__ = undefined;
+ }
+
return result;
}
- else
+
+ if (hasOwnProperty (o.__proto__, prop))
{
- var old = o.__proto__;
- o.__proto__ = "assdofjkaofjojsafjpojsafa";
- delete o.__proto__;
- if (o.__proto__ != undefined && o.__proto__ != "assdofjkaofjojsafjpojsafa") {
- if (hasOwnProperty (o.__proto__, prop))
- {
- var constant = false;
- var old = o.__proto__[prop];
- o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
- if (o.__proto__[prop] != "rapojdfoajiofjhaijhfidsjnfiohrbma") {
- constant = true;
- ASSetPropFlags (o.__proto__, prop, 0, 4);
- o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
- }
- var result;
- if (o[prop] != o.__proto__[prop]) {
- result = true;
- } else {
- result = false;
- }
- o.__proto__[prop] = "to-be-replaced";
- o.__proto__[prop] = old;
- if (constant)
- ASSetPropFlags (o.__proto__, prop, 4);
- return result;
- }
- else
- {
- o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
- var result;
+ var constant = false;
+ var old = o.__proto__[prop];
+
+ o.__proto__[prop] = "safdlojasfljsaiofhiwjhefa";
+ if (o.__proto__[prop] != "safdlojasfljsaiofhiwjhefa") {
+ constant = true;
+ ASSetPropFlags (o.__proto__, prop, 0, 4);
+ o.__proto__[prop] = "safdlojasfljsaiofhiwjhefa";
+ if (o.__proto__[prop] != "safdlojasfljsaiofhiwjhefa") {
if (o[prop] != o.__proto__[prop]) {
- result = true;
+ return true;
} else {
- result = false;
+ trace ("ERROR: can't test property '" + prop + "', __proto__ has superconstant version");
+ return false;
}
- o.__proto__[prop] = "to-be-deleted";
- delete o.__proto__[prop];
- return result;
}
}
- result = hasOwnProperty (o, prop);
- o.__proto__ = old;
+
+ if (o[prop] != o.__proto__[prop]) {
+ result = true;
+ } else {
+ result = false;
+ }
+
+ o.__proto__[prop] = old;
+ if (o.__proto__[prop] != old)
+ trace ("Error: Couldn't set __proto__[\"" + prop + "\"] back to old value");
+ if (constant)
+ ASSetPropFlags (o.__proto__, prop, 4);
+
return result;
}
-}
+ else
+ {
+ o.__proto__[prop] = "safdlojasfljsaiofhiwjhefa";
+
+ if (o[prop] != o.__proto__[prop]) {
+ result = true;
+ } else {
+ result = false;
+ }
+
+ ASSetPropFlags (o, prop, 0, 4);
+ o.__proto__[prop] = "to-be-deleted";
+ delete o.__proto__[prop];
+ if (o.__proto__[prop] != undefined)
+ trace ("ERROR: Couldn't delete temporary __proto__[\"" + prop + "\"]");
+ return result;
+ }
+}
+#endif
function new_info () {
return new_empty_object ();
@@ -95,11 +122,13 @@ function is_blaclisted (o, prop)
if (prop == "mySecretId" || prop == "globalSecretId")
return true;
+#if __SWF_VERSION__ >= 6
if (o == _global.Camera && prop == "names")
return true;
if (o == _global.Microphone && prop == "names")
return true;
+#endif
return false;
}
@@ -231,19 +260,21 @@ function trace_properties_recurse (o, le
flags = " (" + flags + ")";
// handle secretId that keeps track what things we have seen earlier
+ var id_string = "";
var seen = false;
- if (hasOwnProperty (o[prop], "mySecretId")) {
- seen = true;
- } else {
- o[prop]["mySecretId"] = nextSecretId;
- if (o[prop]["mySecretId"] != undefined) {
- ASSetPropFlags (o[prop], "mySecretId", 7);
- nextSecretId++;
+ if (typeof (o[prop]) == "object" || typeof (o[prop]) == "function") {
+ if (hasOwnProperty (o[prop], "mySecretId")) {
+ seen = true;
+ } else {
+ o[prop]["mySecretId"] = nextSecretId;
+ if (o[prop]["mySecretId"] != undefined) {
+ ASSetPropFlags (o[prop], "mySecretId", 7);
+ nextSecretId++;
+ }
}
+ if (o[prop]["mySecretId"] != undefined)
+ id_string = "[" + o[prop]["mySecretId"] + "]";
}
- var id_string = "";
- if (o[prop]["mySecretId"] != undefined)
- id_string = "[" + o[prop]["mySecretId"] + "]";
// put things together
var output = prop + flags + " = " + typeof (o[prop]) + id_string;
@@ -285,5 +316,6 @@ function trace_properties (o, identifier
output += " : toString => \"" + o[prop] + "\"";
trace (output);
- trace_properties_recurse (o, 1, 1);
+ if (typeof (o) == "object" || typeof (o) == "function")
+ trace_properties_recurse (o, 1, 1);
}
diff-tree f1d548cb56d3e4f8b48eb1fc99ebb006f61c259f (from da9fc3e76d3757cb3a8a4459802c753adbbbcbe7)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Tue Aug 21 20:15:05 2007 +0300
Add new recursive version of trace_properties.as, use for propflags test
diff --git a/test/trace/propflags-5.swf b/test/trace/propflags-5.swf
index 893b801..3f6f077 100644
Binary files a/test/trace/propflags-5.swf and b/test/trace/propflags-5.swf differ
diff --git a/test/trace/propflags-5.swf.trace b/test/trace/propflags-5.swf.trace
index e7da22a..78090aa 100644
--- a/test/trace/propflags-5.swf.trace
+++ b/test/trace/propflags-5.swf.trace
@@ -1,11 +1,9 @@
-
-h
-
-h
- c
-h c
- c
-h c
-h
-h
-h
+o object[0] : toString => ""
+ 0 = number : 0
+ 1 (h) = number : 1
+ 2 (p) = number : 2
+ 3 (hp) = number : 3
+ 4 (c) = number : 4
+ 5 (hc) = number : 5
+ 6 (pc) = number : 6
+ 7 (hpc) = number : 7
diff --git a/test/trace/propflags-6.swf b/test/trace/propflags-6.swf
index c702cf4..0d4ec6c 100644
Binary files a/test/trace/propflags-6.swf and b/test/trace/propflags-6.swf differ
diff --git a/test/trace/propflags-6.swf.trace b/test/trace/propflags-6.swf.trace
index a3858d3..78090aa 100644
--- a/test/trace/propflags-6.swf.trace
+++ b/test/trace/propflags-6.swf.trace
@@ -1,11 +1,9 @@
- 0 = 0
-h 1 = 1
- p 2 = 2
-hp 3 = 3
- c 4 = 4
-h c 5 = 5
- pc 6 = 6
-hpc 7 = 7
-h __constructor__ = [type Function]
-hp __proto__ = [object Object]
-h constructor = [type Function] __proto__.constructor = [type Function]
+o object[0] : toString => ""
+ 0 = number : 0
+ 1 (h) = number : 1
+ 2 (p) = number : 2
+ 3 (hp) = number : 3
+ 4 (c) = number : 4
+ 5 (hc) = number : 5
+ 6 (pc) = number : 6
+ 7 (hpc) = number : 7
diff --git a/test/trace/propflags-7.swf b/test/trace/propflags-7.swf
index 8780cfb..086b2bc 100644
Binary files a/test/trace/propflags-7.swf and b/test/trace/propflags-7.swf differ
diff --git a/test/trace/propflags-7.swf.trace b/test/trace/propflags-7.swf.trace
index 3c66620..6a3c4b1 100644
--- a/test/trace/propflags-7.swf.trace
+++ b/test/trace/propflags-7.swf.trace
@@ -1,10 +1,9 @@
- 0 = 0
-h 1 = 1
- p 2 = 2
-hp 3 = 3
- c 4 = 4
-h c 5 = 5
- pc 6 = 6
-hpc 7 = 7
-h __constructor__ = [type Function]
-hp __proto__ = [object Object]
+o object[0] : toString => "undefined"
+ 0 = number : 0
+ 1 (h) = number : 1
+ 2 (p) = number : 2
+ 3 (hp) = number : 3
+ 4 (c) = number : 4
+ 5 (hc) = number : 5
+ 6 (pc) = number : 6
+ 7 (hpc) = number : 7
diff --git a/test/trace/propflags.as b/test/trace/propflags.as
index daca383..944d63e 100644
--- a/test/trace/propflags.as
+++ b/test/trace/propflags.as
@@ -3,12 +3,16 @@
#include "trace_properties.as"
var o = new Object ();
+ASSetPropFlags (o, null, 0, 7);
+for (var prop in o) {
+ delete o[prop];
+}
o[0] = 0;
for (var i = 1; i <= 7; i++) {
o[i] = i;
ASSetPropFlags (o, i, i, 0);
}
-trace_properties (o);
+trace_properties (o, "o");
loadMovie ("FSCommand:quit", "");
diff --git a/test/trace/trace_properties.as b/test/trace/trace_properties.as
index a62fea1..6256a42 100644
--- a/test/trace/trace_properties.as
+++ b/test/trace/trace_properties.as
@@ -1,14 +1,83 @@
-// doesn't work right in Flash 5
+// doesn't work for Flash 5
function new_empty_object () {
var hash = new Object ();
- ASSetPropFlags (hash, null, 0, 7);
for (var prop in hash) {
delete hash[prop];
}
return hash;
}
+function hasOwnProperty (o, prop)
+{
+ if (o.__proto__ == undefined || o.__proto__ == "assdofjkaofjojsafjpojsafa")
+ {
+ if (o[prop] != undefined)
+ return true;
+ else
+ return false;
+ o.__proto__ = new_empty_object ();
+ o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
+ var result;
+ if (o[prop] != o.__proto__[prop]) {
+ result = true;
+ } else {
+ result = false;
+ }
+ // have to be set to string first, otherwise it won't delete
+ o.__proto__ = "to-be-deleted";
+ delete o.__proto__;
+ return result;
+ }
+ else
+ {
+ var old = o.__proto__;
+ o.__proto__ = "assdofjkaofjojsafjpojsafa";
+ delete o.__proto__;
+ if (o.__proto__ != undefined && o.__proto__ != "assdofjkaofjojsafjpojsafa") {
+ if (hasOwnProperty (o.__proto__, prop))
+ {
+ var constant = false;
+ var old = o.__proto__[prop];
+ o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
+ if (o.__proto__[prop] != "rapojdfoajiofjhaijhfidsjnfiohrbma") {
+ constant = true;
+ ASSetPropFlags (o.__proto__, prop, 0, 4);
+ o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
+ }
+ var result;
+ if (o[prop] != o.__proto__[prop]) {
+ result = true;
+ } else {
+ result = false;
+ }
+ o.__proto__[prop] = "to-be-replaced";
+ o.__proto__[prop] = old;
+ if (constant)
+ ASSetPropFlags (o.__proto__, prop, 4);
+ return result;
+ }
+ else
+ {
+ o.__proto__[prop] = "rapojdfoajiofjhaijhfidsjnfiohrbma";
+ var result;
+ if (o[prop] != o.__proto__[prop]) {
+ result = true;
+ } else {
+ result = false;
+ }
+ o.__proto__[prop] = "to-be-deleted";
+ delete o.__proto__[prop];
+ return result;
+ }
+ }
+ result = hasOwnProperty (o, prop);
+ o.__proto__ = old;
+ return result;
+ }
+}
+
+
function new_info () {
return new_empty_object ();
}
@@ -21,52 +90,82 @@ function get_info (info, prop, id) {
return info[prop + "_-_" + id];
}
-// print all properties of a given object, flags are:
-// h = hidden
-// p = permanent
-// P = permanent even without propflag
-// c = constant
-// C = constant even without propflag
-function trace_properties (o)
+function is_blaclisted (o, prop)
{
+ if (prop == "mySecretId" || prop == "globalSecretId")
+ return true;
+
+ if (o == _global.Camera && prop == "names")
+ return true;
+
+ if (o == _global.Microphone && prop == "names")
+ return true;
+
+ return false;
+}
+
+function trace_properties_recurse (o, level, nextSecretId)
+{
+ // to collect info about different properties
var info = new_info ();
- for (var prop in o) {
- set_info (info, prop, "hidden", false);
+
+ // calculate prefix
+ var prefix = "";
+ for (var j = 0; j < level; j++) {
+ prefix = prefix + " ";
}
- var hidden = new Array ();
+ // mark the ones that are not hidden
+ for (var prop in o)
+ {
+ // only get the ones that are not only in the __proto__
+ if (is_blaclisted (o, prop) == false) {
+ if (hasOwnProperty (o, prop) == true)
+ set_info (info, prop, "hidden", false);
+ }
+ }
+ // unhide everything
ASSetPropFlags (o, null, 0, 1);
var all = new Array ();
- for (var prop in o) {
- all.push (prop);
- if (o.hasOwnProperty (prop)) {
- set_info (info, prop, "outproto", true);
- } else {
- set_info (info, prop, "outproto", false);
- }
- if (o.__proto__.hasOwnProperty (prop)) {
- set_info (info, prop, "inproto", true);
- } else {
- set_info (info, prop, "inproto", false);
+ var hidden = new Array ();
+ for (var prop in o)
+ {
+ // only get the ones that are not only in the __proto__
+ if (is_blaclisted (o, prop) == false) {
+ if (hasOwnProperty (o, prop) == true) {
+ all.push (prop);
+ if (get_info (info, prop, "hidden") != false) {
+ set_info (info, prop, "hidden", true);
+ hidden.push (prop);
+ }
+ }
}
}
all.sort ();
- for (var prop in o) {
- if (get_info (info, prop, "hidden") != false) {
- set_info (info, prop, "hidden", true);
- hidden.push (prop);
- }
+ // hide the ones that were already hidden
+ ASSetPropFlags (o, hidden, 1, 0);
+
+ if (all.length == 0) {
+ trace (prefix + "no children");
+ return nextSecretId;
}
- for (var prop in o) {
+ for (var i = 0; i < all.length; i++)
+ {
+ var prop = all[i];
+
+ // try changing value
var old = o[prop];
var val = "hello " + o[prop];
o[prop] = val;
- if (o[prop] != val) {
+ if (o[prop] != val)
+ {
set_info (info, prop, "constant", true);
+
+ // try changing value after removing constant propflag
ASSetPropFlags (o, prop, 0, 4);
o[prop] = val;
if (o[prop] != val) {
@@ -76,72 +175,115 @@ function trace_properties (o)
o[prop] = old;
}
ASSetPropFlags (o, prop, 4);
- } else {
+ }
+ else
+ {
set_info (info, prop, "constant", false);
set_info (info, prop, "superconstant", false);
o[prop] = old;
}
}
- for (var prop in o) {
+ for (var i = 0; i < all.length; i++)
+ {
+ var prop = all[i];
+
+ // remove constant flag
ASSetPropFlags (o, prop, 0, 4);
+
+ // try deleting
var old = o[prop];
delete o[prop];
- if (o.hasOwnProperty (prop)) {
+ if (hasOwnProperty (o, prop))
+ {
set_info (info, prop, "permanent", true);
- ASSetPropFlags (o, prop, 0, 2);
- delete o[prop];
- if (o.hasOwnProperty (prop)) {
- set_info (info, prop, "superpermanent", true);
- } else {
- set_info (info, prop, "superpermanent", false);
- o[prop] = old;
- }
- ASSetPropFlags (o, prop, 4);
- } else {
+ }
+ else
+ {
set_info (info, prop, "permanent", false);
o[prop] = old;
}
+
+ // put constant flag back, if it was set
if (get_info (info, prop, "constant") == true)
ASSetPropFlags (o, prop, 4);
}
- ASSetPropFlags (o, hidden, 1, 0);
-
for (var i = 0; i < all.length; i++) {
- var flags = "";
+ var prop = all[i];
- if (get_info (info, all[i], "hidden") == true) {
+ // format propflags
+ var flags = "";
+ if (get_info (info, prop, "hidden") == true) {
flags += "h";
- } else {
- flags += " ";
}
-
- if (get_info (info, all[i], "superpermanent") == true) {
+ if (get_info (info, prop, "superpermanent") == true) {
flags += "P";
- } else if (get_info (info, all[i], "permanent") == true) {
+ } else if (get_info (info, prop, "permanent") == true) {
flags += "p";
- } else {
- flags += " ";
}
-
- if (get_info (info, all[i], "superconstant") == true) {
+ if (get_info (info, prop, "superconstant") == true) {
flags += "C";
- } else if (get_info (info, all[i], "constant") == true) {
+ } else if (get_info (info, prop, "constant") == true) {
flags += "c";
- } else {
- flags += " ";
}
+ if (flags != "")
+ flags = " (" + flags + ")";
- values = "";
-
- if (get_info (info, all[i], "outproto") == true) {
- values += " " + all[i] + " = " + o[all[i]];
+ // handle secretId that keeps track what things we have seen earlier
+ var seen = false;
+ if (hasOwnProperty (o[prop], "mySecretId")) {
+ seen = true;
+ } else {
+ o[prop]["mySecretId"] = nextSecretId;
+ if (o[prop]["mySecretId"] != undefined) {
+ ASSetPropFlags (o[prop], "mySecretId", 7);
+ nextSecretId++;
+ }
}
- if (get_info (info, all[i], "inproto") == true) {
- values += " __proto__." + all[i] + " = " + o.__proto__[all[i]];
+ var id_string = "";
+ if (o[prop]["mySecretId"] != undefined)
+ id_string = "[" + o[prop]["mySecretId"] + "]";
+
+ // put things together
+ var output = prop + flags + " = " + typeof (o[prop]) + id_string;
+
+ // add value depending on the type
+ if (typeof (o[prop]) == "number" || typeof (o[prop]) == "boolean") {
+ output += " : " + o[prop];
+ } else if (typeof (o[prop]) == "string") {
+ output += " : \"" + o[prop] + "\"";
+ } else if (typeof (o[prop]) == "object") {
+ output += " : toString => \"" + o[prop] + "\"";
}
- trace (flags + values);
+ // print it out
+ trace (prefix + output);
+
+ // recurse if it's object or function that hasn't been seen earlier
+ if (seen == false &&
+ (typeof (o[prop]) == "object" || typeof (o[prop]) == "function"))
+ {
+ // move the next mySecretId to next hundred, this is to avoid screwing up
+ // all the ids between two runs if they disagree at the start
+ nextSecretId += 99;
+ nextSecretId -= nextSecretId % 100;
+
+ // recurse
+ nextSecretId =
+ trace_properties_recurse (o[prop], level + 1, nextSecretId);
+ }
}
+
+ return nextSecretId;
+}
+
+function trace_properties (o, identifier)
+{
+ var output = identifier + " " + typeof (o) + "[0]";
+ if (typeof (o) == "object")
+ output += " : toString => \"" + o[prop] + "\"";
+ trace (output);
+
+ trace_properties_recurse (o, 1, 1);
}
More information about the Swfdec
mailing list