本文整理汇总了C++中ecma_make_number_value函数的典型用法代码示例。如果您正苦于以下问题:C++ ecma_make_number_value函数的具体用法?C++ ecma_make_number_value怎么用?C++ ecma_make_number_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ecma_make_number_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ecma_builtin_date_utc
/**
* The Date object's 'UTC' routine
*
* See also:
* ECMA-262 v5, 15.9.4.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_date_utc (ecma_value_t this_arg __attr_unused___, /**< this argument */
const ecma_value_t args[], /**< arguments list */
ecma_length_t args_number) /**< number of arguments */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
if (args_number < 2)
{
/* Note:
* When the UTC function is called with fewer than two arguments,
* the behaviour is implementation-dependent, so just return NaN.
*/
ecma_number_t *nan_p = ecma_alloc_number ();
*nan_p = ecma_number_make_nan ();
return ecma_make_normal_completion_value (ecma_make_number_value (nan_p));
}
ECMA_TRY_CATCH (time_value, ecma_date_construct_helper (args, args_number), ret_value);
ecma_number_t *time_p = ecma_get_number_from_value (time_value);
ecma_number_t *time_clip_p = ecma_alloc_number ();
*time_clip_p = ecma_date_time_clip (*time_p);
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (time_clip_p));
ECMA_FINALIZE (time_value);
return ret_value;
} /* ecma_builtin_date_utc */
示例2: ecma_builtin_date_utc
/**
* The Date object's 'UTC' routine
*
* See also:
* ECMA-262 v5, 15.9.4.3
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_date_utc (ecma_value_t this_arg, /**< this argument */
const ecma_value_t args[], /**< arguments list */
ecma_length_t args_number) /**< number of arguments */
{
JERRY_UNUSED (this_arg);
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (args_number < 2)
{
/* Note:
* When the UTC function is called with fewer than two arguments,
* the behaviour is implementation-dependent, so just return NaN.
*/
return ecma_make_number_value (ecma_number_make_nan ());
}
ECMA_TRY_CATCH (time_value, ecma_date_construct_helper (args, args_number), ret_value);
ecma_number_t time = ecma_get_number_from_value (time_value);
ret_value = ecma_make_number_value (ecma_date_time_clip (time));
ECMA_FINALIZE (time_value);
return ret_value;
} /* ecma_builtin_date_utc */
示例3: ecma_builtin_date_prototype_get_year
/**
* The Date.prototype object's 'getYear' routine
*
* See also:
* ECMA-262 v5, AnnexB.B.2.4
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_date_prototype_get_year (ecma_value_t this_arg) /**< this argument */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
/* 1. */
ECMA_TRY_CATCH (value, ecma_builtin_date_prototype_get_time (this_arg), ret_value);
ecma_number_t *this_num_p = ecma_get_number_from_value (value);
/* 2. */
if (ecma_number_is_nan (*this_num_p))
{
ecma_string_t *nan_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_NAN);
ret_value = ecma_make_string_value (nan_str_p);
}
else
{
/* 3. */
ecma_number_t *ret_num_p = ecma_alloc_number ();
*ret_num_p = ecma_date_year_from_time (ecma_date_local_time (*this_num_p)) - 1900;
ret_value = ecma_make_number_value (ret_num_p);
}
ECMA_FINALIZE (value);
return ret_value;
} /* ecma_builtin_date_prototype_get_year */
示例4: ecma_builtin_date_prototype_set_time
/**
* The Date.prototype object's 'setTime' routine
*
* See also:
* ECMA-262 v5, 15.9.5.27
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_date_prototype_set_time (ecma_value_t this_arg, /**< this argument */
ecma_value_t time) /**< time */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
}
else
{
/* 1. */
ECMA_OP_TO_NUMBER_TRY_CATCH (t, time, ret_value);
ecma_number_t *value_p = ecma_alloc_number ();
*value_p = ecma_date_time_clip (t);
/* 2. */
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_property_t *prim_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
ecma_number_t *prim_value_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
ecma_get_internal_property_value (prim_prop_p));
*prim_value_num_p = *value_p;
/* 3. */
ret_value = ecma_make_number_value (value_p);
ECMA_OP_TO_NUMBER_FINALIZE (t);
}
return ret_value;
} /* ecma_builtin_date_prototype_set_time */
示例5: ecma_builtin_math_object_random
/**
* The Math object's 'random' routine
*
* See also:
* ECMA-262 v5, 15.8.2.14
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_math_object_random (ecma_value_t this_arg __attr_unused___) /**< 'this' argument */
{
uint32_t rnd = 1;
uint32_t reps_count;
#if RAND_MAX < 0x100
reps_count = 4;
#elif RAND_MAX < 0x10000
reps_count = 2;
#else /* RAND_MAX < 0x10000 */
reps_count = 1;
#endif /* RAND_MAX >= 0x10000 */
for (uint32_t i = 0; i < reps_count; i++)
{
uint32_t next_rand = (uint32_t) rand ();
rnd *= next_rand;
}
const uint32_t max_uint32 = (uint32_t) -1;
ecma_number_t rand = (ecma_number_t) rnd;
rand /= (ecma_number_t) max_uint32;
rand *= (ecma_number_t) (max_uint32 - 1) / (ecma_number_t) max_uint32;
ecma_number_t *rand_p = ecma_alloc_number ();
*rand_p = rand;
return ecma_make_number_value (rand_p);
} /* ecma_builtin_math_object_random */
示例6: ecma_builtin_number_prototype_object_value_of
/**
* The Number.prototype object's 'valueOf' routine
*
* See also:
* ECMA-262 v5, 15.7.4.4
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_number_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */
{
if (ecma_is_value_number (this_arg))
{
return ecma_copy_value (this_arg);
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_NUMBER_UL)
{
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
ecma_number_t *prim_value_num_p;
prim_value_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
ecma_get_internal_property_value (prim_value_prop_p));
ecma_number_t *ret_num_p = ecma_alloc_number ();
*ret_num_p = *prim_value_num_p;
return ecma_make_number_value (ret_num_p);
}
}
return ecma_raise_type_error (ECMA_ERR_MSG (""));
} /* ecma_builtin_number_prototype_object_value_of */
示例7: ecma_builtin_string_prototype_object_char_code_at
/**
* The String.prototype object's 'charCodeAt' routine
*
* See also:
* ECMA-262 v5, 15.5.4.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_char_code_at (ecma_value_t this_arg, /**< this argument */
ecma_value_t arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
/* 1 */
ECMA_TRY_CATCH (check_coercible_val,
ecma_op_check_object_coercible (this_arg),
ret_value);
/* 2 */
ECMA_TRY_CATCH (to_string_val,
ecma_op_to_string (this_arg),
ret_value);
/* 3 */
ECMA_OP_TO_NUMBER_TRY_CATCH (index_num,
arg,
ret_value);
/* 4 */
ecma_string_t *original_string_p = ecma_get_string_from_value (to_string_val);
const ecma_length_t len = ecma_string_get_length (original_string_p);
ecma_number_t *ret_num_p = ecma_alloc_number ();
/* 5 */
// When index_num is NaN, then the first two comparisons are false
if (index_num < 0 || index_num >= len || (ecma_number_is_nan (index_num) && !len))
{
*ret_num_p = ecma_number_make_nan ();
}
else
{
/* 6 */
/*
* String length is currently uit32_t, but index_num may be bigger,
* ToInteger performs floor, while ToUInt32 performs modulo 2^32,
* hence after the check 0 <= index_num < len we assume to_uint32 can be used.
* We assume to_uint32 (NaN) is 0.
*/
JERRY_ASSERT (ecma_number_is_nan (index_num) || ecma_number_to_uint32 (index_num) == ecma_number_trunc (index_num));
ecma_char_t new_ecma_char = ecma_string_get_char_at_pos (original_string_p, ecma_number_to_uint32 (index_num));
*ret_num_p = ecma_uint32_to_number (new_ecma_char);
}
ecma_value_t new_value = ecma_make_number_value (ret_num_p);
ret_value = ecma_make_normal_completion_value (new_value);
ECMA_OP_TO_NUMBER_FINALIZE (index_num);
ECMA_FINALIZE (to_string_val);
ECMA_FINALIZE (check_coercible_val);
return ret_value;
} /* ecma_builtin_string_prototype_object_char_code_at */
示例8: ecma_builtin_helper_string_prototype_object_index_of
/**
* Helper function for string indexOf and lastIndexOf functions
*
* This function implements string indexOf and lastIndexOf with required checks and conversions.
*
* See also:
* ECMA-262 v5, 15.5.4.7
* ECMA-262 v5, 15.5.4.8
*
* Used by:
* - The String.prototype.indexOf routine.
* - The String.prototype.lastIndexOf routine.
*
* @return uint32_t - (last) index of search string
*/
ecma_value_t
ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**< this argument */
ecma_value_t arg1, /**< routine's first argument */
ecma_value_t arg2, /**< routine's second argument */
bool first_index) /**< routine's third argument */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
/* 1 */
ECMA_TRY_CATCH (check_coercible_val,
ecma_op_check_object_coercible (this_arg),
ret_value);
/* 2 */
ECMA_TRY_CATCH (to_str_val,
ecma_op_to_string (this_arg),
ret_value);
/* 3 */
ECMA_TRY_CATCH (search_str_val,
ecma_op_to_string (arg1),
ret_value);
/* 4 */
ECMA_OP_TO_NUMBER_TRY_CATCH (pos_num,
arg2,
ret_value);
/* 5 (indexOf) -- 6 (lastIndexOf) */
ecma_string_t *original_str_p = ecma_get_string_from_value (to_str_val);
const ecma_length_t original_len = ecma_string_get_length (original_str_p);
/* 4b, 6 (indexOf) - 4b, 5, 7 (lastIndexOf) */
ecma_length_t start = ecma_builtin_helper_string_index_normalize (pos_num, original_len, first_index);
/* 7 (indexOf) -- 8 (lastIndexOf) */
ecma_string_t *search_str_p = ecma_get_string_from_value (search_str_val);
ecma_number_t ret_num = ECMA_NUMBER_MINUS_ONE;
/* 8 (indexOf) -- 9 (lastIndexOf) */
ecma_length_t index_of = 0;
if (ecma_builtin_helper_string_find_index (original_str_p, search_str_p, first_index, start, &index_of))
{
ret_num = ((ecma_number_t) index_of);
}
ret_value = ecma_make_number_value (ret_num);
ECMA_OP_TO_NUMBER_FINALIZE (pos_num);
ECMA_FINALIZE (search_str_val);
ECMA_FINALIZE (to_str_val);
ECMA_FINALIZE (check_coercible_val);
return ret_value;
} /* ecma_builtin_helper_string_prototype_object_index_of */
示例9: ecma_copy_value
/**
* Copy ecma value.
*
* Note:
* Operation algorithm.
* switch (valuetype)
* case simple:
* simply return the value as it was passed;
* case number:
* copy the number
* and return new ecma value
* pointing to copy of the number;
* case string:
* increase reference counter of the string
* and return the value as it was passed.
* case object;
* increase reference counter of the object if do_ref_if_object is true
* and return the value as it was passed.
*
* @return See note.
*/
ecma_value_t
ecma_copy_value (ecma_value_t value, /**< ecma value */
bool do_ref_if_object) /**< if the value is object value,
increment reference counter of the object */
{
ecma_value_t value_copy = 0;
switch (ecma_get_value_type_field (value))
{
case ECMA_TYPE_SIMPLE:
{
value_copy = value;
break;
}
case ECMA_TYPE_NUMBER:
{
ecma_number_t *num_p = ecma_get_number_from_value (value);
ecma_number_t *number_copy_p = ecma_alloc_number ();
*number_copy_p = *num_p;
value_copy = ecma_make_number_value (number_copy_p);
break;
}
case ECMA_TYPE_STRING:
{
ecma_string_t *string_p = ecma_get_string_from_value (value);
string_p = ecma_copy_or_ref_ecma_string (string_p);
value_copy = ecma_make_string_value (string_p);
break;
}
case ECMA_TYPE_OBJECT:
{
ecma_object_t *obj_p = ecma_get_object_from_value (value);
if (do_ref_if_object)
{
ecma_ref_object (obj_p);
}
value_copy = value;
break;
}
}
return value_copy;
} /* ecma_copy_value */
示例10: ecma_builtin_date_now
/**
* The Date object's 'now' routine
*
* See also:
* ECMA-262 v5, 15.9.4.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_date_now (ecma_value_t this_arg __attr_unused___) /**< this argument */
{
/*
* FIXME:
* Get the real system time. ex: gettimeofday() on Linux
* Introduce system macros at first.
*/
ecma_number_t *now_num_p = ecma_alloc_number ();
*now_num_p = ECMA_NUMBER_ZERO;
return ecma_make_normal_completion_value (ecma_make_number_value (now_num_p));
} /* ecma_builtin_date_now */
示例11: ecma_builtin_math_object_sqrt
/**
* The Math object's 'sqrt' routine
*
* See also:
* ECMA-262 v5, 15.8.2.17
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_math_object_sqrt (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */
ecma_value_t arg) /**< routine's argument */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
*num_p = DOUBLE_TO_ECMA_NUMBER_T (sqrt (arg_num));
ret_value = ecma_make_number_value (num_p);
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_sqrt */
示例12: ecma_builtin_string_prototype_object_locale_compare
/**
* The String.prototype object's 'localeCompare' routine
*
* See also:
* ECMA-262 v5, 15.5.4.9
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_locale_compare (ecma_value_t this_arg, /**< this argument */
ecma_value_t arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
/* 1. */
ECMA_TRY_CATCH (this_check_coercible_val,
ecma_op_check_object_coercible (this_arg),
ret_value);
/* 2. */
ECMA_TRY_CATCH (this_to_string_val,
ecma_op_to_string (this_arg),
ret_value);
/* 3. */
ECMA_TRY_CATCH (arg_to_string_val,
ecma_op_to_string (arg),
ret_value);
ecma_string_t *this_string_p = ecma_get_string_from_value (this_to_string_val);
ecma_string_t *arg_string_p = ecma_get_string_from_value (arg_to_string_val);
ecma_number_t *result_p = ecma_alloc_number ();
if (ecma_compare_ecma_strings_relational (this_string_p, arg_string_p))
{
*result_p = ecma_int32_to_number (-1);
}
else if (!ecma_compare_ecma_strings (this_string_p, arg_string_p))
{
*result_p = ecma_int32_to_number (1);
}
else
{
*result_p = ecma_int32_to_number (0);
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (result_p));
ECMA_FINALIZE (arg_to_string_val);
ECMA_FINALIZE (this_to_string_val);
ECMA_FINALIZE (this_check_coercible_val);
return ret_value;
} /* ecma_builtin_string_prototype_object_locale_compare */
示例13: ecma_builtin_make_function_object_for_routine
/**
* Construct a Function object for specified built-in routine
*
* See also: ECMA-262 v5, 15
*
* @return pointer to constructed Function object
*/
ecma_object_t*
ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**< identifier of built-in object
that initially contains property
with the routine */
uint16_t routine_id, /**< builtin-wide identifier of the built-in
object's routine property */
ecma_number_t length_prop_num_value) /**< ecma-number - value
of 'length' property
of function object to create */
{
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
ecma_object_t *func_obj_p = ecma_create_object (prototype_obj_p, true, ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION);
ecma_deref_object (prototype_obj_p);
ecma_set_object_is_builtin (func_obj_p, true);
uint64_t packed_value = jrt_set_bit_field_value (0,
builtin_id,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_POS,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_WIDTH);
packed_value = jrt_set_bit_field_value (packed_value,
routine_id,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_POS,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_WIDTH);
ecma_property_t *routine_id_prop_p = ecma_create_internal_property (func_obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_ID);
JERRY_ASSERT ((uint32_t) packed_value == packed_value);
routine_id_prop_p->u.internal_property.value = (uint32_t) packed_value;
ecma_string_t* magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_property_t *len_prop_p = ecma_create_named_data_property (func_obj_p,
magic_string_length_p,
false, false, false);
ecma_deref_ecma_string (magic_string_length_p);
ecma_number_t* len_p = ecma_alloc_number ();
*len_p = length_prop_num_value;
ecma_set_named_data_property_value (len_prop_p, ecma_make_number_value (len_p));
return func_obj_p;
} /* ecma_builtin_make_function_object_for_routine */
示例14: ecma_builtin_date_prototype_get_time
/**
* The Date.prototype object's 'getTime' routine
*
* See also:
* ECMA-262 v5, 15.9.5.9
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_date_prototype_get_time (ecma_value_t this_arg) /**< this argument */
{
if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_DATE_UL)
{
ecma_value_t *date_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, *date_prop_p);
return ecma_make_number_value (*date_num_p);
}
}
return ecma_raise_type_error (ECMA_ERR_MSG (""));
} /* ecma_builtin_date_prototype_get_time */
示例15: ecma_builtin_math_object_round
/**
* The Math object's 'round' routine
*
* See also:
* ECMA-262 v5, 15.8.2.15
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_math_object_round (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */
ecma_value_t arg) /**< routine's argument */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (arg_num)
|| ecma_number_is_zero (arg_num)
|| ecma_number_is_infinity (arg_num))
{
*num_p = arg_num;
}
else if (ecma_number_is_negative (arg_num)
&& arg_num >= -0.5f)
{
*num_p = ecma_number_negate (0.0f);
}
else
{
const ecma_number_t up_half = arg_num + 0.5f;
const ecma_number_t down_half = arg_num - 0.5f;
const ecma_number_t up_rounded = up_half - ecma_op_number_remainder (up_half, 1);
const ecma_number_t down_rounded = down_half - ecma_op_number_remainder (down_half, 1);
if (up_rounded - arg_num <= arg_num - down_rounded)
{
*num_p = up_rounded;
}
else
{
*num_p = down_rounded;
}
}
ret_value = ecma_make_number_value (num_p);
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_round */