add transform_object_properties in jerryx/arg (#1879)

Add a function in jerryx/arg.
jerryx_arg_transform_object_properties, it will validate the properties of a JS object, and convert those properties into native type.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
Zidong Jiang
2017-06-19 19:51:08 -05:00
committed by GitHub
parent 7cc9d65c09
commit e4eecc2019
6 changed files with 424 additions and 15 deletions
+33 -1
View File
@@ -51,6 +51,10 @@ jerry_value_t jerryx_arg_transform_native_pointer_optional (jerryx_arg_js_iterat
const jerryx_arg_t *c_arg_p);
jerry_value_t jerryx_arg_transform_ignore (jerryx_arg_js_iterator_t *js_arg_iter_p,
const jerryx_arg_t *c_arg_p);
jerry_value_t jerryx_arg_transform_object_props (jerryx_arg_js_iterator_t *js_arg_iter_p,
const jerryx_arg_t *c_arg_p);
jerry_value_t jerryx_arg_transform_object_props_optional (jerryx_arg_js_iterator_t *js_arg_iter_p,
const jerryx_arg_t *c_arg_p);
/**
* Create a validation/transformation step (`jerryx_arg_t`) that expects to
@@ -213,7 +217,7 @@ jerryx_arg_function (jerry_value_t *dest, /**< pointer to the jerry_value_t wher
/**
* Create a validation/transformation step (`jerryx_arg_t`) that expects to
* consume one `Object` JS argument that is 'backed' with a native pointer with
* consume one `object` JS argument that is 'backed' with a native pointer with
* a given type info. In case the native pointer info matches, the transform
* will succeed and the object's native pointer will be assigned to *dest.
*
@@ -275,4 +279,32 @@ jerryx_arg_custom (void *dest, /**< pointer to the native argument where the res
};
} /* jerryx_arg_custom */
/**
* Create a jerryx_arg_t instance for object properties.
*
* @return a jerryx_arg_t instance.
*/
static inline jerryx_arg_t
jerryx_arg_object_properties (const jerryx_arg_object_props_t *object_props, /**< pointer to object property mapping */
jerryx_arg_optional_t opt_flag) /**< whether the argument is optional */
{
jerryx_arg_transform_func_t func;
if (opt_flag == JERRYX_ARG_OPTIONAL)
{
func = jerryx_arg_transform_object_props_optional;
}
else
{
func = jerryx_arg_transform_object_props;
}
return (jerryx_arg_t)
{
.func = func,
.dest = NULL,
.extra_info = (uintptr_t) object_props
};
} /* jerryx_arg_object_properties */
#endif /* !JERRYX_ARG_IMPL_H */