Pekka Lampila
2007-Aug-22 12:02 UTC
[Swfdec] 3 commits - libswfdec/swfdec_as_array.c libswfdec/swfdec_as_function.c test/trace
libswfdec/swfdec_as_array.c | 18 +--- libswfdec/swfdec_as_function.c | 3 test/trace/trace_properties.as | 165 +++++++++++++++++++++++++++++------------ 3 files changed, 129 insertions(+), 57 deletions(-) New commits: diff-tree adebed995585fa9f993062a75df17ff464113e93 (from 99c2574700ed7aaeef5cadbc45c7bfdd9ad7a6dd) Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Wed Aug 22 15:00:41 2007 +0300 Change Array's properties and flags to match flash player Set Array.constructor and Array.prototype.constructor flags to hidden and permanent. Don't set length in prototype but in constructor and swfdec_as_array_new. diff --git a/libswfdec/swfdec_as_array.c b/libswfdec/swfdec_as_array.c index 864915d..28888ae 100644 --- a/libswfdec/swfdec_as_array.c +++ b/libswfdec/swfdec_as_array.c @@ -323,14 +323,6 @@ swfdec_as_array_append_array (SwfdecAsAr */ static void -swfdec_as_array_add (SwfdecAsObject *object) -{ - swfdec_as_array_set_length (object, 0); - - SWFDEC_AS_OBJECT_CLASS (swfdec_as_array_parent_class)->add (object); -} - -static void swfdec_as_array_set (SwfdecAsObject *object, const char *variable, const SwfdecAsValue *val, guint flags) { @@ -367,7 +359,6 @@ swfdec_as_array_class_init (SwfdecAsArra { SwfdecAsObjectClass *asobject_class = SWFDEC_AS_OBJECT_CLASS (klass); - asobject_class->add = swfdec_as_array_add; asobject_class->set = swfdec_as_array_set; } @@ -401,6 +392,7 @@ swfdec_as_array_new (SwfdecAsContext *co ret = g_object_new (SWFDEC_TYPE_AS_ARRAY, NULL); swfdec_as_object_add (ret, context, sizeof (SwfdecAsArray)); swfdec_as_object_set_constructor (ret, context->Array); + swfdec_as_array_set_length (ret, 0); return ret; } @@ -1064,6 +1056,8 @@ swfdec_as_array_construct (SwfdecAsConte swfdec_as_array_set_length (object, l < 0 ? 0 : l); } else if (argc > 0) { swfdec_as_array_append (array, argc, argv); + } else { + swfdec_as_array_set_length (object, 0); } SWFDEC_AS_VALUE_SET_OBJECT (ret, object); @@ -1090,7 +1084,8 @@ swfdec_as_array_init_context (SwfdecAsCo /* set the right properties on the Array object */ SWFDEC_AS_VALUE_SET_OBJECT (&val, context->Function); - swfdec_as_object_set_variable (array, SWFDEC_AS_STR_constructor, &val); + swfdec_as_object_set_variable_and_flags (array, SWFDEC_AS_STR_constructor, + &val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT); SWFDEC_AS_VALUE_SET_NUMBER (&val, ARRAY_SORT_OPTION_CASEINSENSITIVE); swfdec_as_object_set_variable (array, SWFDEC_AS_STR_CASEINSENSITIVE, &val); SWFDEC_AS_VALUE_SET_NUMBER (&val, ARRAY_SORT_OPTION_DESCENDING); @@ -1104,7 +1099,8 @@ swfdec_as_array_init_context (SwfdecAsCo /* set the right properties on the Array.prototype object */ SWFDEC_AS_VALUE_SET_OBJECT (&val, array); - swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val); + 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_toString, 0, swfdec_as_array_toString, 0); swfdec_as_object_add_function (proto, SWFDEC_AS_STR_join, diff-tree 99c2574700ed7aaeef5cadbc45c7bfdd9ad7a6dd (from 91ff6faecc598f3122830193a476bf866b917a42) Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Wed Aug 22 14:51:08 2007 +0300 Set functions' constructor as hidden and permanent when creating it diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c index 9782a9c..d16110f 100644 --- a/libswfdec/swfdec_as_function.c +++ b/libswfdec/swfdec_as_function.c @@ -86,7 +86,8 @@ swfdec_as_function_set_constructor (Swfd context = object->context; if (context->Function) { SWFDEC_AS_VALUE_SET_OBJECT (&val, context->Function); - swfdec_as_object_set_variable (object, SWFDEC_AS_STR_constructor, &val); + swfdec_as_object_set_variable_and_flags (object, SWFDEC_AS_STR_constructor, + &val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT); } if (context->Function_prototype) { SWFDEC_AS_VALUE_SET_OBJECT (&val, context->Function_prototype); diff-tree 91ff6faecc598f3122830193a476bf866b917a42 (from c5efffeed0afc0e64f4d01a4323c9137189bf41f) Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Wed Aug 22 14:05:39 2007 +0300 Flash 5 fixes and output cleanup to trace_properties.as Construct _global variable by hand when in flash 5, base it on values from flash 6. Make the script output less useless information. diff --git a/test/trace/trace_properties.as b/test/trace/trace_properties.as index e547478..bfa256c 100644 --- a/test/trace/trace_properties.as +++ b/test/trace/trace_properties.as @@ -1,4 +1,71 @@ -// doesn't work for Flash 5 +#if __SWF_VERSION__ == 5 +// create a _global object, since it doesn't have one, these are ver 6 values +_global = new_empty_object (); +_global.ASSetNative = ASSetNative; +_global.ASSetNativeAccessor = ASSetNativeAccessor; +_global.ASSetPropFlags = ASSetPropFlags; +_global.ASconstructor = ASconstructor; +_global.ASnative = ASnative; +_global.Accessibility = Accessibility; +_global.Array = Array; +_global.AsBroadcaster = AsBroadcaster; +_global.AsSetupError = AsSetupError; +_global.Boolean = Boolean; +_global.Button = Button; +_global.Camera = Camera; +_global.Color = Color; +_global.ContextMenu = ContextMenu; +_global.ContextMenuItem = ContextMenuItem; +_global.Date = Date; +_global.Error = Error; +_global.Function = Function; +_global.Infinity = Infinity; +_global.Key = Key; +_global.LoadVars = LoadVars; +_global.LocalConnection = LocalConnection; +_global.Math = Math; +_global.Microphone = Microphone; +_global.Mouse = Mouse; +_global.MovieClip = MovieClip; +_global.MovieClipLoader = MovieClipLoader; +_global.NaN = NaN; +_global.NetConnection = NetConnection; +_global.NetStream = NetStream; +_global.Number = Number; +_global.Object = Object; +_global.PrintJob = PrintJob; +_global.RemoteLSOUsage = RemoteLSOUsage; +_global.Selection = Selection; +_global.SharedObject = SharedObject; +_global.Sound = Sound; +_global.Stage = Stage; +_global.String = String; +_global.System = System; +_global.TextField = TextField; +_global.TextFormat = TextFormat; +_global.TextSnapshot = TextSnapshot; +_global.Video = Video; +_global.XML = XML; +_global.XMLNode = XMLNode; +_global.XMLSocket = XMLSocket; +_global.clearInterval = clearInterval; +_global.clearTimeout = clearTimeout; +_global.enableDebugConsole = enableDebugConsole; +_global.escape = escape; +_global.flash = flash; +_global.isFinite = isFinite; +_global.isNaN = isNaN; +_global.o = o; +_global.parseFloat = parseFloat; +_global.parseInt = parseInt; +_global.setInterval = setInterval; +_global.setTimeout = setTimeout; +_global.showRedrawRegions = showRedrawRegions; +_global.textRenderer = textRenderer; +_global.trace = trace; +_global.unescape = unescape; +_global.updateAfterEvent = updateAfterEvent; +#endif function new_empty_object () { var hash = new Object (); @@ -65,7 +132,8 @@ function hasOwnProperty (o, prop) if (o[prop] != o.__proto__[prop]) { return true; } else { - trace ("ERROR: can't test property '" + prop + "', __proto__ has superconstant version"); + trace ("ERROR: can't test property '" + prop + + "', __proto__ has superconstant version"); return false; } } @@ -79,7 +147,8 @@ function hasOwnProperty (o, prop) o.__proto__[prop] = old; if (o.__proto__[prop] != old) - trace ("Error: Couldn't set __proto__[\"" + prop + "\"] back to old value"); + trace ("Error: Couldn't set __proto__[\"" + prop + + "\"] back to old value"); if (constant) ASSetPropFlags (o.__proto__, prop, 4); @@ -123,12 +192,15 @@ 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; + +#if __SWF_VERSION__ < 6 + if (prop == "__proto__" && o[prop] == undefined) + return true; #endif return false; @@ -260,71 +332,63 @@ function trace_properties_recurse (o, pr if (flags != "") flags = " (" + flags + ")"; - var id_string = ""; - if (typeof (o[prop]) == "object" || typeof (o[prop]) == "function") - id_string = "[" + o[prop]["mySecretId"] + "]"; - - // put things together - var output = prop + flags + " = " + typeof (o[prop]) + id_string; - + var value = ""; // add value depending on the type if (typeof (o[prop]) == "number" || typeof (o[prop]) == "boolean") { - output += " : " + o[prop]; + value += " : " + o[prop]; } else if (typeof (o[prop]) == "string") { - output += " : \"" + o[prop] + "\""; - } else if (typeof (o[prop]) == "object") { - output += " : toString => \"" + o[prop] + "\""; + value += " : \"" + o[prop] + "\""; } - // print it out - trace (indentation + output); - - // recurse if it's object or function that hasn't been seen earlier - if ((typeof (o[prop]) == "object" || typeof (o[prop]) == "function") && - prefix + (prefix != "" ? "." : "") + identifier + "." + prop == o[prop]["mySecretId"]) + // recurse if it's object or function and this is the place it has been + // named after + if (typeof (o[prop]) == "object" || typeof (o[prop]) == "function") { - trace_properties_recurse (o[prop], prefix + (prefix != "" ? "." : "") + - identifier, prop, level + 1); + if (prefix + (prefix != "" ? "." : "") + identifier + "." + prop =+ o[prop]["mySecretId"]) + { + trace (indentation + prop + flags + " = " + typeof (o[prop])); + trace_properties_recurse (o[prop], prefix + (prefix != "" ? "." : "") + + identifier, prop, level + 1); + } + else + { + trace (indentation + prop + flags + " = " + o[prop]["mySecretId"]); + } + } + else + { + trace (indentation + prop + flags + " = " + typeof (o[prop]) + value); } } } function generate_names (o, prefix, identifier) { - var info = new_info (); - // 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); - } + var nothidden = new Array (); + for (var prop in o) { + nothidden.push (prop); } // unhide everything ASSetPropFlags (o, null, 0, 1); var all = new Array (); - 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) { + // only get the ones that are not only in the __proto__ 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 (); // hide the ones that were already hidden - ASSetPropFlags (o, hidden, 1, 0); + ASSetPropFlags (o, null, 1, 0); + ASSetPropFlags (o, nothidden, 0, 1); for (var i = 0; i < all.length; i++) { var prop = all[i]; @@ -359,12 +423,23 @@ function trace_properties (o, prefix, id generate_names (o, prefix, identifier); - var output = identifier + " " + typeof (o) + "[" + prefix + - (prefix != "" ? "." : "") + identifier + "]"; - if (typeof (o) == "object") - output += " : toString => \"" + o[prop] + "\""; - trace (output); - if (typeof (o) == "object" || typeof (o) == "function") + { + if (prefix + (prefix != "" ? "." : "") + identifier == o["mySecretId"]) + { + trace (prefix + (prefix != "" ? "." : "") + identifier + " = " + + typeof (o)); + } + else + { + trace (prefix + (prefix != "" ? "." : "") + identifier + " = " + + o["mySecretId"]); + } trace_properties_recurse (o, prefix, identifier, 1); + } + else + { + trace (prefix + (prefix != "" ? "." : "") + identifier + " = " + + typeof (o[prop]) + value); + } }
Maybe Matching Threads
- 2 commits - test/trace
- 5 commits - libswfdec/swfdec_as_array.c libswfdec/swfdec_as_boolean.c libswfdec/swfdec_as_function.c libswfdec/swfdec_as_math.c libswfdec/swfdec_as_number.c libswfdec/swfdec_as_script_function.c libswfdec/swfdec_initialize.as libswfdec/swfdec_initialize.h
- 12 commits - libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_strings.c libswfdec/swfdec_loader.c libswfdec/swfdec_loader_internal.h libswfdec/swfdec_load_object_as.c libswfdec/swfdec_load_object.c libswfdec/swfdec_load_object.h
- 2 commits - libswfdec/swfdec_as_object.c test/trace
- 10 commits - libswfdec/swfdec_as_function.c libswfdec/swfdec_as_object.c test/trace