📄 swfdec_as_object.c
字号:
* @data: data to pass to @func * * Calls @func for each variable of @object. If The function is then supposed * to return the new name of the variable or %NULL if the variable should be * removed. This is an internal function for array operations. **/voidswfdec_as_object_foreach_rename (SwfdecAsObject *object, SwfdecAsVariableForeachRename func, gpointer data){ ForeachRenameData fdata = { object, NULL, func, data }; g_return_if_fail (SWFDEC_IS_AS_OBJECT (object)); g_return_if_fail (func != NULL); fdata.properties_new = g_hash_table_new (g_direct_hash, g_direct_equal); g_hash_table_foreach_remove (object->properties, swfdec_as_object_hash_foreach_rename, &fdata); g_hash_table_destroy (object->properties); object->properties = fdata.properties_new;}static char *swfdec_as_object_do_debug (SwfdecAsObject *object){ if (G_OBJECT_TYPE (object) != SWFDEC_TYPE_AS_OBJECT) return g_strdup (G_OBJECT_TYPE_NAME (object)); return g_strdup ("Object");}static voidswfdec_as_object_class_init (SwfdecAsObjectClass *klass){ GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = swfdec_as_object_dispose; klass->mark = swfdec_as_object_do_mark; klass->add = swfdec_as_object_do_add; klass->get = swfdec_as_object_do_get; klass->set = swfdec_as_object_do_set; klass->set_flags = swfdec_as_object_do_set_flags; klass->del = swfdec_as_object_do_delete; klass->foreach = swfdec_as_object_do_foreach; klass->debug = swfdec_as_object_do_debug;}static voidswfdec_as_object_init (SwfdecAsObject *object){}/** * swfdec_as_object_new_empty: * @context: a #SwfdecAsContext * * Creates an empty object. The prototype and constructor properties of the * returned object will not be set. You probably want to call * swfdec_as_object_set_constructor() on the returned object yourself. * You may want to use swfdec_as_object_new() instead. * * Returns: A new #SwfdecAsObject adde to @context or %NULL on OOM. **/SwfdecAsObject *swfdec_as_object_new_empty (SwfdecAsContext *context){ SwfdecAsObject *object; g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL); if (!swfdec_as_context_use_mem (context, sizeof (SwfdecAsObject))) return NULL; object = g_object_new (SWFDEC_TYPE_AS_OBJECT, NULL); swfdec_as_object_add (object, context, sizeof (SwfdecAsObject)); return object;}/** * swfdec_as_object_new: * @context: a #SwfdecAsContext * * Allocates a new Object. This does the same as the Actionscript code * "new Object()". * * Returns: the new object or NULL on out of memory. **/SwfdecAsObject *swfdec_as_object_new (SwfdecAsContext *context){ SwfdecAsObject *object; SwfdecAsValue val; g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL); g_assert (context->Object); g_assert (context->Object_prototype); object = swfdec_as_object_new_empty (context); SWFDEC_AS_VALUE_SET_OBJECT (&val, context->Object); swfdec_as_object_set_variable_and_flags (object, SWFDEC_AS_STR_constructor, &val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT); SWFDEC_AS_VALUE_SET_OBJECT (&val, context->Object_prototype); swfdec_as_object_set_variable_and_flags (object, SWFDEC_AS_STR___proto__, &val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT); return object;}/** * swfdec_as_object_add: * @object: #SwfdecAsObject to make garbage-collected * @context: #SwfdecAsContext that should manage the object * @size: size the object currently uses * * Takes over the reference to @object for the garbage collector of @context. * The object may not already be part of a different context. The given @size * must have been allocated before with swfdec_as_context_use_mem (). * Note that after swfdec_as_object_add() the garbage collector might hold the * only reference to @object. **/voidswfdec_as_object_add (SwfdecAsObject *object, SwfdecAsContext *context, gsize size){ SwfdecAsObjectClass *klass; g_return_if_fail (SWFDEC_IS_AS_OBJECT (object)); g_return_if_fail (SWFDEC_IS_AS_CONTEXT (context)); g_return_if_fail (object->properties == NULL); object->context = context; object->size = size; g_hash_table_insert (context->objects, object, object); object->properties = g_hash_table_new (g_direct_hash, g_direct_equal); klass = SWFDEC_AS_OBJECT_GET_CLASS (object); g_return_if_fail (klass->add); klass->add (object); if (context->debugger) { SwfdecAsDebuggerClass *dklass = SWFDEC_AS_DEBUGGER_GET_CLASS (context->debugger); if (dklass->add) dklass->add (context->debugger, context, object); }}voidswfdec_as_object_collect (SwfdecAsObject *object){ g_return_if_fail (SWFDEC_IS_AS_OBJECT (object)); g_return_if_fail (object->properties != NULL); g_hash_table_foreach (object->properties, swfdec_as_object_free_property, object); g_hash_table_destroy (object->properties); object->properties = NULL; if (object->size) swfdec_as_context_unuse_mem (object->context, object->size); g_object_unref (object);}/** * swfdec_as_object_set_variable: * @object: a #SwfdecAsObject * @variable: garbage-collected name of the variable to set * @value: value to set the variable to * * Sets a variable on @object. It is not guaranteed that getting the variable * after setting it results in the same value. This is a mcaro that calls * swfdec_as_object_set_variable_and_flags() **//** * swfdec_as_object_set_variable_and_flags: * @object: a #SwfdecAsObject * @variable: garbage-collected name of the variable to set * @value: value to set the variable to * @default_flags: flags to use if creating the variable anew - the flags will * be ignored if the property already exists. * * Sets a variable on @object. It is not guaranteed that getting the variable * after setting it results in the same value, because various mechanisms (like * the Actionscript Object.addProperty function or constant variables) can * avoid this. **/voidswfdec_as_object_set_variable_and_flags (SwfdecAsObject *object, const char *variable, const SwfdecAsValue *value, guint default_flags){ SwfdecAsObjectClass *klass; g_return_if_fail (SWFDEC_IS_AS_OBJECT (object)); g_return_if_fail (variable != NULL); g_return_if_fail (SWFDEC_IS_AS_VALUE (value)); if (object->context->debugger) { SwfdecAsDebugger *debugger = object->context->debugger; SwfdecAsDebuggerClass *dklass = SWFDEC_AS_DEBUGGER_GET_CLASS (debugger); if (dklass->set_variable) dklass->set_variable (debugger, object->context, object, variable, value); } klass = SWFDEC_AS_OBJECT_GET_CLASS (object); klass->set (object, variable, value, default_flags);}/** * swfdec_as_object_get_variable: * @object: a #SwfdecAsObject * @variable: a garbage-collected string containing the name of the variable * @value: pointer to a #SwfdecAsValue that takes the return value or %NULL * * Gets the value of the given @variable on @object. It walks the prototype * chain. This is a shortcut macro for * swfdec_as_object_get_variable_and_flags(). * * Returns: %TRUE if the variable existed, %FALSE otherwise *//** * swfdec_as_object_get_variable_and_flags: * @object: a #SwfdecAsObject * @variable: a garbage-collected string containing the name of the variable * @value: pointer to a #SwfdecAsValue that takes the return value or %NULL * @flags: pointer to a guint taking the variable's flags or %NULL * @pobject: pointer to set to the object that really holds the property or * %NULL * * Looks up @variable on @object. It also walks the object's prototype chain. * If the variable exists, its value, flags and the real object containing the * variable will be set and %TRUE will be returned. * * Returns: %TRUE if the variable exists, %FALSE otherwise **/gbooleanswfdec_as_object_get_variable_and_flags (SwfdecAsObject *object, const char *variable, SwfdecAsValue *value, guint *flags, SwfdecAsObject **pobject){ SwfdecAsObjectClass *klass; guint i; SwfdecAsValue tmp_val; guint tmp_flags; SwfdecAsObject *tmp_pobject, *cur; g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), FALSE); g_return_val_if_fail (variable != NULL, FALSE); if (value == NULL) value = &tmp_val; if (flags == NULL) flags = &tmp_flags; if (pobject == NULL) pobject = &tmp_pobject; cur = object; for (i = 0; i < 256 && cur != NULL; i++) { klass = SWFDEC_AS_OBJECT_GET_CLASS (cur); if (klass->get (cur, object, variable, value, flags)) { *pobject = cur; return TRUE; } cur = cur->prototype; } if (i == 256) { swfdec_as_context_abort (object->context, "Prototype recursion limit exceeded"); *flags = 0; *pobject = NULL; return FALSE; } //SWFDEC_WARNING ("no such variable %s", variable); SWFDEC_AS_VALUE_SET_UNDEFINED (value); *flags = 0; *pobject = NULL; return FALSE;}/** * swfdec_as_object_delete_variable: * @object: a #SwfdecAsObject * @variable: garbage-collected name of the variable * * Deletes the given variable if possible. If the variable is protected from * deletion, it will not be deleted. * * Returns: See #SwfdecAsDeleteReutnr for details of the return value. **/SwfdecAsDeleteReturnswfdec_as_object_delete_variable (SwfdecAsObject *object, const char *variable){ SwfdecAsObjectClass *klass; g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), FALSE); g_return_val_if_fail (variable != NULL, FALSE); klass = SWFDEC_AS_OBJECT_GET_CLASS (object); return klass->del (object, variable);}/** * swfdec_as_object_set_variable_flags: * @object: a #SwfdecAsObject * @variable: the variable to modify * @flags: flags to set * * Sets the given flags for the given variable. **/voidswfdec_as_object_set_variable_flags (SwfdecAsObject *object, const char *variable, SwfdecAsVariableFlag flags){ SwfdecAsObjectClass *klass; g_return_if_fail (SWFDEC_IS_AS_OBJECT (object)); g_return_if_fail (variable != NULL); klass = SWFDEC_AS_OBJECT_GET_CLASS (object); klass->set_flags (object, variable, flags, flags);}/** * swfdec_as_object_unset_variable_flags: * @object: a #SwfdecAsObject * @variable: the variable to modify * @flags: flags to unset * * Unsets the given flags for the given variable. The variable must exist in * @object. **/voidswfdec_as_object_unset_variable_flags (SwfdecAsObject *object, const char *variable, SwfdecAsVariableFlag flags){ SwfdecAsObjectClass *klass; g_return_if_fail (SWFDEC_IS_AS_OBJECT (object)); g_return_if_fail (variable != NULL); klass = SWFDEC_AS_OBJECT_GET_CLASS (object); klass->set_flags (object, variable, 0, flags);}/** * swfdec_as_object_foreach: * @object: a #SwfdecAsObject * @func: function to call * @data: data to pass to @func * * Calls @func for every variable of @object or until @func returns %FALSE. The * variables of @object must not be modified by @func. * * Returns: %TRUE if @func always returned %TRUE **/gbooleanswfdec_as_object_foreach (SwfdecAsObject *object, SwfdecAsVariableForeach func, gpointer data){ SwfdecAsObjectClass *klass; g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), FALSE); g_return_val_if_fail (func != NULL, FALSE); klass = SWFDEC_AS_OBJECT_GET_CLASS (object); g_return_val_if_fail (klass->foreach != NULL, FALSE); return klass->foreach (object, func, data);}/*** SIMPLIFICATIONS ***/static voidswfdec_as_object_do_nothing (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval){}/** * swfdec_as_object_add_function: * @object: a #SwfdecAsObject * @name: name of the function. The string does not have to be * garbage-collected. * @type: the required type of the this Object to make this function execute. * May be 0 to accept any type. * @native: a native function or %NULL to just not do anything * @min_args: minimum number of arguments to pass to @native * * Adds @native as a variable named @name to @object. The newly added variable * will not be enumerated. * * Returns: the newly created #SwfdecAsFunction or %NULL on error. **/SwfdecAsFunction *swfdec_as_object_add_function (SwfdecAsObject *object, const char *name, GType type, SwfdecAsNative native, guint min_args){ g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), NULL); g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (type == 0 || g_type_is_a (type, SWFDEC_TYPE_AS_OBJECT), NULL); return swfdec_as_object_add_constructor (object, name, type, 0, native, min_args, NULL);}/** * swfdec_as_object_add_constructor: * @object: a #SwfdecAsObject * @name: name of the function. The string does not have to be * garbage-collected. * @type: the required type of the this Object to make this function execute. * May be 0 to accept any type. * @construct_type: type used when using this function as a constructor. May * be 0 to use the default type. * @native: a native function or %NULL to just not do anything * @min_args: minimum number of arguments to pass to @native * @prototype: An optional object to be set as the "prototype" property of the * new function. The prototype will be hidden and constant. * * Adds @native as a constructor named @name to @object. The newly added variable * will not be enumerated. * * Returns: the newly created #SwfdecAsFunction or %NULL on error. **/SwfdecAsFunction *swfdec_as_object_add_constructor (SwfdecAsObject *object, const char *name, GType type, GType construct_type, SwfdecAsNative native, guint min_args, SwfdecAsObject *prototype)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -