Chromium Code Reviews| Index: ppapi/c/pp_var.h |
| =================================================================== |
| --- ppapi/c/pp_var.h (revision 73298) |
| +++ ppapi/c/pp_var.h (working copy) |
| @@ -11,7 +11,8 @@ |
| /** |
| * @file |
| - * Defines the API ... |
| + * This file defines the API for handling the passing of data types between |
| + * your module and the page. |
| */ |
| /** |
| @@ -19,6 +20,11 @@ |
| * @addtogroup Enums |
| * @{ |
| */ |
| + |
| +/** |
| + * PP_VarType is an enumeration of the different types that can be contained |
| + * within a PP_VAR structure. |
| + */ |
| typedef enum { |
| PP_VARTYPE_UNDEFINED, |
| PP_VARTYPE_NULL, |
| @@ -39,17 +45,18 @@ |
| */ |
| /** |
| - * Do not rely on having a predictable and reproducible |
| - * int/double differentiation. |
| - * JavaScript has a "number" type for holding a number, and |
| - * does not differentiate between floating point and integer numbers. The |
| - * JavaScript library will try to optimize operations by using integers |
| - * when possible, but could end up with doubles depending on how the number |
| - * was arrived at. |
| + * The PP_VAR struct is a variant data type and can contain any |
| + * value represented by the PP_VarType enum. This structure is for |
|
dmichael(do not use this one)
2011/02/02 20:12:59
maybe instead of 'any value represented by the PP_
jond
2011/02/02 20:34:39
Done.
|
| + * passing data between native code which can be strongly typed and the browser |
| + * (JavaScript) which isn't strongly typed. |
| * |
| - * Your best bet is to have a wrapper for variables |
| - * that always gets out the type you expect, converting as necessary. |
| - * |
| + * JavaScript has a "number" type for holding a number, and does not |
| + * differentiate between floating point and integer numbers. The |
| + * JavaScript operations will try to optimize operations by using |
| + * integers when possible, but could end up with doubles. Therefore, |
| + * you can't assume a numeric PP_Var will be the type you expect. |
| + * Your code should be capable of handle either int32_t or double for numeric |
|
dmichael(do not use this one)
2011/02/02 20:12:59
handle->handling
(my fault)
jond
2011/02/02 20:34:39
Done.
jond
2011/02/02 20:34:39
Done.
|
| + * PP_Vars sent from JavaScript. |
| */ |
| struct PP_Var { |
| PP_VarType type; |
| @@ -82,28 +89,57 @@ |
| * @addtogroup Functions |
| * @{ |
| */ |
| + |
| +/** |
| + * PP_MakeUndefined() is a utility function used to wrap an undefined value |
| + * into a PP_VAR struct for passing to the browser. |
| + * @return A PP_Var structure |
| + */ |
| PP_INLINE struct PP_Var PP_MakeUndefined() { |
| struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; |
| return result; |
| } |
| +/** |
| + * PP_MakeNull() is a utility function used to wrap a null value into a |
| + * PP_VAR struct for passing to the browser. |
| + * @return A PP_Var structure |
| + */ |
| PP_INLINE struct PP_Var PP_MakeNull() { |
| struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; |
| return result; |
| } |
| +/** |
| + * PP_MakeBool() is a utility function used to wrap a boolean value into a |
| + * PP_VAR struct for passing to the browser. |
| + * @param[in] value A PP_Bool enumeration |
| + * @return A PP_Var structure |
| + */ |
| PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { |
| struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; |
| result.value.as_bool = value; |
| return result; |
| } |
| +/** |
| + * PP_MakeInt32() is a utility function used to wrap a 32 bit integer value |
| + * into a PP_VAR struct for passing to the browser. |
| + * @param[in] value An int32 |
| + * @return A PP_Var structure |
| + */ |
| PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { |
| struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; |
| result.value.as_int = value; |
| return result; |
| } |
| +/** |
| + * PP_MakeDouble() is a utility function used to wrap a double value into a |
| + * PP_VAR struct for passing to the browser. |
| + * @param[in] value A double |
| + * @return A PP_Var structure |
| + */ |
| PP_INLINE struct PP_Var PP_MakeDouble(double value) { |
| struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; |
| result.value.as_double = value; |