这篇教程C++ ECMA_OP_TO_NUMBER_FINALIZE函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中ECMA_OP_TO_NUMBER_FINALIZE函数的典型用法代码示例。如果您正苦于以下问题:C++ ECMA_OP_TO_NUMBER_FINALIZE函数的具体用法?C++ ECMA_OP_TO_NUMBER_FINALIZE怎么用?C++ ECMA_OP_TO_NUMBER_FINALIZE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了ECMA_OP_TO_NUMBER_FINALIZE函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ecma_builtin_date_prototype_set_utc_month/** * The Date.prototype object's 'setUTCMonth' routine * * See also: * ECMA-262 v5, 15.9.5.39 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_date_prototype_set_utc_month (ecma_value_t this_arg, /**< this argument */ ecma_value_t month, /**< month */ ecma_value_t date) /**< date */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = *ecma_get_number_from_value (this_time_value); /* 2. */ ECMA_OP_TO_NUMBER_TRY_CATCH (m, month, ret_value); /* 3. */ ECMA_OP_TO_NUMBER_TRY_CATCH (dt, date, ret_value); if (ecma_is_value_undefined (date)) { dt = ecma_date_date_from_time (t); } /* 4-7. */ ecma_number_t year = ecma_date_year_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_make_day (year, m, dt), ecma_date_time_within_day (t), ECMA_DATE_UTC); ECMA_OP_TO_NUMBER_FINALIZE (dt); ECMA_OP_TO_NUMBER_FINALIZE (m); ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_utc_month */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:43,
示例2: ecma_builtin_date_prototype_set_utc_seconds/** * The Date.prototype object's 'setUTCSeconds' routine * * See also: * ECMA-262 v5, 15.9.5.31 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_date_prototype_set_utc_seconds (ecma_value_t this_arg, /**< this argument */ ecma_value_t sec, /**< second */ ecma_value_t ms) /**< millisecond */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = *ecma_get_number_from_value (this_time_value); /* 2. */ ECMA_OP_TO_NUMBER_TRY_CATCH (s, sec, ret_value); /* 3. */ ECMA_OP_TO_NUMBER_TRY_CATCH (milli, ms, ret_value); if (ecma_is_value_undefined (ms)) { milli = ecma_date_ms_from_time (t); } /* 4-7. */ ecma_number_t hour = ecma_date_hour_from_time (t); ecma_number_t min = ecma_date_min_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_day (t), ecma_date_make_time (hour, min, s, milli), ECMA_DATE_UTC); ECMA_OP_TO_NUMBER_FINALIZE (milli); ECMA_OP_TO_NUMBER_FINALIZE (s); ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_utc_seconds */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:44,
示例3: ecma_builtin_date_prototype_set_utc_hours/** * The Date.prototype object's 'setUTCHours' routine * * See also: * ECMA-262 v5, 15.9.5.35 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_date_prototype_set_utc_hours (ecma_value_t this_arg, /**< this argument */ const ecma_value_t args[], /**< arguments list */ ecma_length_t args_number) /**< number of arguments */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = *ecma_get_number_from_value (this_time_value); /* 2. */ ecma_number_t h = ecma_number_make_nan (); ecma_number_t m = ecma_date_min_from_time (t); ecma_number_t s = ecma_date_sec_from_time (t); ecma_number_t milli = ecma_date_ms_from_time (t); if (args_number > 0 && !ecma_is_value_undefined (args[0])) { ECMA_OP_TO_NUMBER_TRY_CATCH (hour, args[0], ret_value); h = hour; /* 3. */ if (args_number > 1 && !ecma_is_value_undefined (args[1])) { ECMA_OP_TO_NUMBER_TRY_CATCH (min, args[1], ret_value); m = min; /* 4. */ if (args_number > 2 && !ecma_is_value_undefined (args[2])) { ECMA_OP_TO_NUMBER_TRY_CATCH (sec, args[2], ret_value); s = sec; /* 5. */ if (args_number > 3 && !ecma_is_value_undefined (args[3])) { ECMA_OP_TO_NUMBER_TRY_CATCH (ms, args[3], ret_value); milli = ms; ECMA_OP_TO_NUMBER_FINALIZE (ms); } ECMA_OP_TO_NUMBER_FINALIZE (sec); } ECMA_OP_TO_NUMBER_FINALIZE (min); } ECMA_OP_TO_NUMBER_FINALIZE (hour); } if (ecma_is_value_empty (ret_value)) { /* 6-9. */ ret_value = ecma_date_set_internal_property (this_arg, ecma_date_day (t), ecma_date_make_time (h, m, s, milli), ECMA_DATE_UTC); } ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_utc_hours */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:68,
示例4: ecma_builtin_date_prototype_set_full_year/** * The Date.prototype object's 'setFullYear' routine * * See also: * ECMA-262 v5, 15.9.5.40 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_date_prototype_set_full_year (ecma_value_t this_arg, /**< this argument */ const ecma_value_t args[], /**< arguments list */ ecma_length_t args_number) /**< number of arguments */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = ecma_date_local_time (*ecma_get_number_from_value (this_time_value)); if (ecma_number_is_nan (t)) { t = ECMA_NUMBER_ZERO; } /* 2. */ ecma_number_t y = ecma_number_make_nan (); ecma_number_t m = ecma_date_month_from_time (t); ecma_number_t dt = ecma_date_date_from_time (t); if (args_number > 0 && !ecma_is_value_undefined (args[0])) { ECMA_OP_TO_NUMBER_TRY_CATCH (year, args[0], ret_value); y = year; /* 3. */ if (args_number > 1 && !ecma_is_value_undefined (args[1])) { ECMA_OP_TO_NUMBER_TRY_CATCH (month, args[1], ret_value); m = month; /* 4. */ if (args_number > 2 && !ecma_is_value_undefined (args[2])) { ECMA_OP_TO_NUMBER_TRY_CATCH (date, args[2], ret_value); dt = date; ECMA_OP_TO_NUMBER_FINALIZE (date); } ECMA_OP_TO_NUMBER_FINALIZE (month); } ECMA_OP_TO_NUMBER_FINALIZE (year); } if (ecma_is_value_empty (ret_value)) { /* 5-8. */ ret_value = ecma_date_set_internal_property (this_arg, ecma_date_make_day (y, m, dt), ecma_date_time_within_day (t), ECMA_DATE_LOCAL); } ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_full_year */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:63,
示例5: ecma_builtin_date_prototype_set_minutes/** * The Date.prototype object's 'setMinutes' routine * * See also: * ECMA-262 v5, 15.9.5.32 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */static ecma_completion_value_tecma_builtin_date_prototype_set_minutes (ecma_value_t this_arg, /**< 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 (); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = ecma_date_local_time (*ecma_get_number_from_value (this_time_value)); /* 2. */ ecma_number_t m = ecma_number_make_nan (); ecma_number_t s = ecma_date_sec_from_time (t); ecma_number_t milli = ecma_date_ms_from_time (t); if (args_number > 0 && !ecma_is_value_undefined (args[0])) { ECMA_OP_TO_NUMBER_TRY_CATCH (min, args[0], ret_value); m = min; /* 3. */ if (args_number > 1 && !ecma_is_value_undefined (args[1])) { ECMA_OP_TO_NUMBER_TRY_CATCH (sec, args[1], ret_value); s = sec; /* 4. */ if (args_number > 2 && !ecma_is_value_undefined (args[2])) { ECMA_OP_TO_NUMBER_TRY_CATCH (ms, args[2], ret_value); milli = ms; ECMA_OP_TO_NUMBER_FINALIZE (ms); } ECMA_OP_TO_NUMBER_FINALIZE (sec); } ECMA_OP_TO_NUMBER_FINALIZE (min); } if (ecma_is_completion_value_empty (ret_value)) { /* 5-8. */ ecma_number_t hour = ecma_date_hour_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_day (t), ecma_date_make_time (hour, m, s, milli), ECMA_DATE_LOCAL); } ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_minutes */
开发者ID:jiangrunwu,项目名称:iotjs-openwrt,代码行数:60,
示例6: ecma_builtin_date_prototype_set_utc_date/** * The Date.prototype object's 'setUTCDate' routine * * See also: * ECMA-262 v5, 15.9.5.37 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */static ecma_completion_value_tecma_builtin_date_prototype_set_utc_date (ecma_value_t this_arg, /**< this argument */ ecma_value_t date) /**< date */{ ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = *ecma_get_number_from_value (this_time_value); /* 2. */ ECMA_OP_TO_NUMBER_TRY_CATCH (dt, date, ret_value); /* 3-6. */ ecma_number_t year = ecma_date_year_from_time (t); ecma_number_t month = ecma_date_month_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_make_day (year, month, dt), ecma_date_time_within_day (t), ECMA_DATE_UTC); ECMA_OP_TO_NUMBER_FINALIZE (dt); ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_utc_date */
开发者ID:jiangrunwu,项目名称:iotjs-openwrt,代码行数:35,
示例7: ecma_builtin_date_prototype_set_utc_milliseconds/** * The Date.prototype object's 'setUTCMilliseconds' routine * * See also: * ECMA-262 v5, 15.9.5.29 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */static ecma_completion_value_tecma_builtin_date_prototype_set_utc_milliseconds (ecma_value_t this_arg, /**< this argument */ ecma_value_t ms) /**< millisecond */{ ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = *ecma_get_number_from_value (this_time_value); /* 2. */ ECMA_OP_TO_NUMBER_TRY_CATCH (milli, ms, ret_value); /* 3-5. */ ecma_number_t hour = ecma_date_hour_from_time (t); ecma_number_t min = ecma_date_min_from_time (t); ecma_number_t sec = ecma_date_sec_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_day (t), ecma_date_make_time (hour, min, sec, milli), ECMA_DATE_UTC); ECMA_OP_TO_NUMBER_FINALIZE (milli); ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_utc_milliseconds */
开发者ID:jiangrunwu,项目名称:iotjs-openwrt,代码行数:36,
示例8: ecma_builtin_date_prototype_set_date/** * The Date.prototype object's 'setDate' routine * * See also: * ECMA-262 v5, 15.9.5.36 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_date_prototype_set_date (ecma_value_t this_arg, /**< this argument */ ecma_value_t date) /**< date */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = ecma_date_local_time (*ecma_get_number_from_value (this_time_value)); /* 2. */ ECMA_OP_TO_NUMBER_TRY_CATCH (dt, date, ret_value); /* 3-6. */ ecma_number_t year = ecma_date_year_from_time (t); ecma_number_t month = ecma_date_month_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_make_day (year, month, dt), ecma_date_time_within_day (t), ECMA_DATE_LOCAL); ECMA_OP_TO_NUMBER_FINALIZE (dt); ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_date */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:35,
示例9: 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_tecma_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 */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:44,
示例10: ecma_builtin_date_prototype_set_milliseconds/** * The Date.prototype object's 'setMilliseconds' routine * * See also: * ECMA-262 v5, 15.9.5.28 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_date_prototype_set_milliseconds (ecma_value_t this_arg, /**< this argument */ ecma_value_t ms) /**< millisecond */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = ecma_date_local_time (*ecma_get_number_from_value (this_time_value)); /* 2. */ ECMA_OP_TO_NUMBER_TRY_CATCH (milli, ms, ret_value); /* 3-5. */ ecma_number_t hour = ecma_date_hour_from_time (t); ecma_number_t min = ecma_date_min_from_time (t); ecma_number_t sec = ecma_date_sec_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_day (t), ecma_date_make_time (hour, min, sec, milli), ECMA_DATE_LOCAL); ECMA_OP_TO_NUMBER_FINALIZE (milli); ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_milliseconds */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:36,
示例11: 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_tecma_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 */
开发者ID:szledan,项目名称:jerryscript,代码行数:67,
示例12: 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_tecma_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 */
开发者ID:gudbooy,项目名称:jerryscript,代码行数:71,
示例13: ecma_builtin_math_object_pow/** * The Math object's 'pow' routine * * See also: * ECMA-262 v5, 15.8.2.13 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_math_object_pow (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg1, /**< first routine's argument */ ecma_value_t arg2) /**< second routine's argument */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); ECMA_OP_TO_NUMBER_TRY_CATCH (x, arg1, ret_value); ECMA_OP_TO_NUMBER_TRY_CATCH (y, arg2, ret_value); ecma_number_t *num_p = ecma_alloc_number (); *num_p = DOUBLE_TO_ECMA_NUMBER_T (pow (x, y)); ret_value = ecma_make_number_value (num_p); ECMA_OP_TO_NUMBER_FINALIZE (y); ECMA_OP_TO_NUMBER_FINALIZE (x); return ret_value;} /* ecma_builtin_math_object_pow */
开发者ID:SmartFire,项目名称:jerryscript,代码行数:28,
示例14: ecma_builtin_string_object_from_char_code/** * The String object's 'fromCharCode' routine * * See also: * ECMA-262 v5, 15.5.3.2 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_string_object_from_char_code (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); if (args_number == 0) { return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); } ecma_value_t ret_value = ECMA_VALUE_EMPTY; ecma_string_t *ret_string_p = NULL; lit_utf8_size_t utf8_buf_size = args_number * LIT_CESU8_MAX_BYTES_IN_CODE_UNIT; JMEM_DEFINE_LOCAL_ARRAY (utf8_buf_p, utf8_buf_size, lit_utf8_byte_t); lit_utf8_size_t utf8_buf_used = 0; for (ecma_length_t arg_index = 0; arg_index < args_number && ecma_is_value_empty (ret_value); arg_index++) { ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value); uint32_t uint32_char_code = ecma_number_to_uint32 (arg_num); ecma_char_t code_unit = (uint16_t) uint32_char_code; JERRY_ASSERT (utf8_buf_used <= utf8_buf_size - LIT_UTF8_MAX_BYTES_IN_CODE_UNIT); utf8_buf_used += lit_code_unit_to_utf8 (code_unit, utf8_buf_p + utf8_buf_used); JERRY_ASSERT (utf8_buf_used <= utf8_buf_size); ECMA_OP_TO_NUMBER_FINALIZE (arg_num); } if (ecma_is_value_empty (ret_value)) { ret_string_p = ecma_new_ecma_string_from_utf8 (utf8_buf_p, utf8_buf_used); } JMEM_FINALIZE_LOCAL_ARRAY (utf8_buf_p); if (ecma_is_value_empty (ret_value)) { ret_value = ecma_make_string_value (ret_string_p); } return ret_value;} /* ecma_builtin_string_object_from_char_code */
开发者ID:Samsung,项目名称:jerryscript,代码行数:61,
示例15: ecma_builtin_string_object_from_char_code/** * The String object's 'fromCharCode' routine * * See also: * ECMA-262 v5, 15.5.3.2 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */static ecma_completion_value_tecma_builtin_string_object_from_char_code (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 == 0) { ecma_string_t *ret_str_p = ecma_new_ecma_string_from_utf8 (NULL, 0); return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p)); } lit_utf8_size_t utf8_buf_size = args_number * LIT_UTF8_MAX_BYTES_IN_CODE_UNIT; ecma_string_t *ret_str_p; MEM_DEFINE_LOCAL_ARRAY (utf8_buf_p, utf8_buf_size, lit_utf8_byte_t); lit_utf8_size_t utf8_buf_used = 0; FIXME ("Support surrogate pairs"); for (ecma_length_t arg_index = 0; arg_index < args_number; arg_index++) { ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value); uint32_t uint32_char_code = ecma_number_to_uint32 (arg_num); ecma_char_t code_unit = (uint16_t) uint32_char_code; JERRY_ASSERT (utf8_buf_used <= utf8_buf_size - LIT_UTF8_MAX_BYTES_IN_CODE_UNIT); utf8_buf_used += lit_code_unit_to_utf8 (code_unit, utf8_buf_p + utf8_buf_used); JERRY_ASSERT (utf8_buf_used <= utf8_buf_size); ECMA_OP_TO_NUMBER_FINALIZE (arg_num); if (ecma_is_completion_value_throw (ret_value)) { mem_heap_free_block (utf8_buf_p); return ret_value; } JERRY_ASSERT (ecma_is_completion_value_empty (ret_value)); } ret_str_p = ecma_new_ecma_string_from_utf8 (utf8_buf_p, utf8_buf_used); MEM_FINALIZE_LOCAL_ARRAY (utf8_buf_p); return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));} /* ecma_builtin_string_object_from_char_code */
开发者ID:lvidacs,项目名称:jerryscript_old,代码行数:60,
示例16: ecma_builtin_date_prototype_set_year/** * The Date.prototype object's 'setYear' routine * * See also: * ECMA-262 v5, AnnexB.B.2.5 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_date_prototype_set_year (ecma_value_t this_arg, /**< this argument */ ecma_value_t year) /**< year argument */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (this_time_value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); ecma_number_t t = ecma_date_local_time (*ecma_get_number_from_value (this_time_value)); if (ecma_number_is_nan (t)) { t = ECMA_NUMBER_ZERO; } /* 2. */ ecma_number_t y = ecma_number_make_nan (); ECMA_OP_TO_NUMBER_TRY_CATCH (year_value, year, ret_value); y = year_value; /* 3. */ if (ecma_number_is_nan (y)) { ret_value = ecma_date_set_internal_property (this_arg, 0, y, ECMA_DATE_UTC); } else { /* 4. */ if (y >= 0 && y <= 99) { y += 1900; } } ECMA_OP_TO_NUMBER_FINALIZE (year_value); if (ecma_is_value_empty (ret_value)) { /* 5-8. */ ecma_number_t m = ecma_date_month_from_time (t); ecma_number_t dt = ecma_date_date_from_time (t); ret_value = ecma_date_set_internal_property (this_arg, ecma_date_make_day (y, m, dt), ecma_date_time_within_day (t), ECMA_DATE_UTC); } ECMA_FINALIZE (this_time_value); return ret_value;} /* ecma_builtin_date_prototype_set_year */
开发者ID:Akromx16,项目名称:jerryscript,代码行数:59,
示例17: 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_tecma_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 */
开发者ID:SmartFire,项目名称:jerryscript,代码行数:24,
示例18: ecma_builtin_string_prototype_object_char_at/** * The String.prototype object's 'charAt' routine * * See also: * ECMA-262 v5, 15.5.4.4 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */static ecma_completion_value_tecma_builtin_string_prototype_object_char_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); /* 5 */ if (index_num < 0 || index_num >= len || !len) { ret_value = ecma_make_normal_completion_value (ecma_make_string_value ( ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY))); } else { /* 6 */ ecma_char_t new_ecma_char = ecma_string_get_char_at_pos (original_string_p, ecma_number_to_uint32 (index_num)); ret_value = ecma_make_normal_completion_value (ecma_make_string_value ( ecma_new_ecma_string_from_code_unit (new_ecma_char))); } 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_at */
开发者ID:szledan,项目名称:jerryscript,代码行数:55,
示例19: 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_tecma_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 */
开发者ID:SmartFire,项目名称:jerryscript,代码行数:53,
示例20: ecma_builtin_helper_string_prototype_object_index_of//.........这里部分代码省略......... ecma_number_t *ret_num_p = ecma_alloc_number (); *ret_num_p = ecma_int32_to_number (-1); /* 9 */ if (search_len <= original_len) { if (!search_len) { *ret_num_p = ecma_uint32_to_number (firstIndex ? 0 : original_len); } else { /* create utf8 string from original string and advance to position */ MEM_DEFINE_LOCAL_ARRAY (original_str_utf8_p, original_size, lit_utf8_byte_t); ecma_string_to_utf8_string (original_str_p, original_str_utf8_p, (ssize_t) (original_size)); lit_utf8_iterator_t original_it = lit_utf8_iterator_create (original_str_utf8_p, original_size); ecma_length_t index = start; lit_utf8_iterator_advance (&original_it, index); /* create utf8 string from search string */ MEM_DEFINE_LOCAL_ARRAY (search_str_utf8_p, search_size, lit_utf8_byte_t); ecma_string_to_utf8_string (search_str_p, search_str_utf8_p, (ssize_t) (search_size)); lit_utf8_iterator_t search_it = lit_utf8_iterator_create (search_str_utf8_p, search_size); /* iterate original string and try to match at each position */ bool searching = true; while (searching) { /* match as long as possible */ ecma_length_t match_len = 0; lit_utf8_iterator_t stored_original_it = original_it; while (match_len < search_len && index + match_len < original_len && lit_utf8_iterator_read_next (&original_it) == lit_utf8_iterator_read_next (&search_it)) { match_len++; } /* check for match */ if (match_len == search_len) { *ret_num_p = ecma_uint32_to_number (index); break; } else { /* inc/dec index and update iterators and search condition */ lit_utf8_iterator_seek_bos (&search_it); original_it = stored_original_it; if (firstIndex) { if ((searching = (index <= original_len - search_len))) { lit_utf8_iterator_incr (&original_it); index++; } } else { if ((searching = (index > 0))) { lit_utf8_iterator_decr (&original_it); index--; } } } } MEM_FINALIZE_LOCAL_ARRAY (search_str_utf8_p); MEM_FINALIZE_LOCAL_ARRAY (original_str_utf8_p); } } 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 (pos_num); ECMA_FINALIZE (search_str_val); ECMA_FINALIZE (to_str_val); ECMA_FINALIZE (check_coercible_val); return ret_value;} /* ecma_builtin_helper_string_index_normalize */
开发者ID:Jonavin,项目名称:jerryscript,代码行数:101,
示例21: ecma_builtin_helper_array_concat_value/** * Helper function for concatenating an ecma_value_t to an Array. * * See also: * ECMA-262 v5, 15.4.4.4 steps 5.b - 5.c * * Used by: * - The Array.prototype.concat routine. * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ecma_completion_value_tecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, /**< array */ uint32_t *length_p, /**< in-out: array's length */ ecma_value_t value) /**< value to concat */{ ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); /* 5.b */ if (ecma_is_value_object (value) && (ecma_object_get_class_name (ecma_get_object_from_value (value)) == LIT_MAGIC_STRING_ARRAY_UL)) { ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH); /* 5.b.ii */ ECMA_TRY_CATCH (arg_len_value, ecma_op_object_get (ecma_get_object_from_value (value), magic_string_length_p), ret_value); ECMA_OP_TO_NUMBER_TRY_CATCH (arg_len_number, arg_len_value, ret_value); uint32_t arg_len = ecma_number_to_uint32 (arg_len_number); /* 5.b.iii */ for (uint32_t array_index = 0; array_index < arg_len && ecma_is_completion_value_empty (ret_value); array_index++) { ecma_string_t *array_index_string_p = ecma_new_ecma_string_from_uint32 (array_index); /* 5.b.iii.2 */ if (ecma_op_object_get_property (ecma_get_object_from_value (value), array_index_string_p) != NULL) { ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 (*length_p + array_index); /* 5.b.iii.3.a */ ECMA_TRY_CATCH (get_value, ecma_op_object_get (ecma_get_object_from_value (value), array_index_string_p), ret_value); ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor (); { prop_desc.is_value_defined = true; prop_desc.value = get_value; prop_desc.is_writable_defined = true; prop_desc.is_writable = true; prop_desc.is_enumerable_defined = true; prop_desc.is_enumerable = true; prop_desc.is_configurable_defined = true; prop_desc.is_configurable = true; } /* 5.b.iii.3.b */ /* This will always be a simple value since 'is_throw' is false, so no need to free. */ ecma_completion_value_t put_comp = ecma_op_object_define_own_property (obj_p, new_array_index_string_p, &prop_desc, false); JERRY_ASSERT (ecma_is_completion_value_normal_true (put_comp)); ECMA_FINALIZE (get_value); ecma_deref_ecma_string (new_array_index_string_p); } ecma_deref_ecma_string (array_index_string_p); } *length_p += arg_len; ECMA_OP_TO_NUMBER_FINALIZE (arg_len_number); ECMA_FINALIZE (arg_len_value); ecma_deref_ecma_string (magic_string_length_p); } else { ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 ((*length_p)++); ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor (); { prop_desc.is_value_defined = true; prop_desc.value = value; prop_desc.is_writable_defined = true; prop_desc.is_writable = true;//.........这里部分代码省略.........
开发者ID:Jonavin,项目名称:jerryscript,代码行数:101,
示例22: ecma_builtin_function_prototype_object_apply/** * The Function.prototype object's 'apply' routine * * See also: * ECMA-262 v5, 15.3.4.3 * * @return ecma value * Returned value must be freed with ecma_free_value. */static ecma_value_tecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this argument */ ecma_value_t arg1, /**< first argument */ ecma_value_t arg2) /**< second argument */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ if (!ecma_op_is_callable (this_arg)) { ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("")); } else { ecma_object_t *func_obj_p = ecma_get_object_from_value (this_arg); /* 2. */ if (ecma_is_value_null (arg2) || ecma_is_value_undefined (arg2)) { ret_value = ecma_op_function_call (func_obj_p, arg1, NULL, 0); } else { /* 3. */ if (!ecma_is_value_object (arg2)) { ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("")); } else { ecma_object_t *obj_p = ecma_get_object_from_value (arg2); ecma_string_t *length_magic_string_p = ecma_new_ecma_length_string (); /* 4. */ ECMA_TRY_CATCH (length_value, ecma_op_object_get (obj_p, length_magic_string_p), ret_value); ECMA_OP_TO_NUMBER_TRY_CATCH (length_number, length_value, ret_value); /* 5. */ const uint32_t length = ecma_number_to_uint32 (length_number); /* 6. */ JMEM_DEFINE_LOCAL_ARRAY (arguments_list_p, length, ecma_value_t); uint32_t last_index = 0; /* 7. */ for (uint32_t index = 0; index < length && ecma_is_value_empty (ret_value); index++) { ecma_string_t *curr_idx_str_p = ecma_new_ecma_string_from_uint32 (index); ECMA_TRY_CATCH (get_value, ecma_op_object_get (obj_p, curr_idx_str_p), ret_value); arguments_list_p[index] = ecma_copy_value (get_value); last_index = index + 1; ECMA_FINALIZE (get_value); ecma_deref_ecma_string (curr_idx_str_p); } if (ecma_is_value_empty (ret_value)) { JERRY_ASSERT (last_index == length); ret_value = ecma_op_function_call (func_obj_p, arg1, arguments_list_p, length); } for (uint32_t index = 0; index < last_index; index++) { ecma_free_value (arguments_list_p[index]); } JMEM_FINALIZE_LOCAL_ARRAY (arguments_list_p); ECMA_OP_TO_NUMBER_FINALIZE (length_number); ECMA_FINALIZE (length_value); ecma_deref_ecma_string (length_magic_string_p); } } } return ret_value;//.........这里部分代码省略.........
开发者ID:robertsipka,项目名称:jerryscript,代码行数:101,
示例23: ecma_builtin_date_prototype_dispatch_routine/** * Dispatcher of the built-in's routines * * @return ecma value * Returned value must be freed with ecma_free_value. */ecma_value_tecma_builtin_date_prototype_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine * identifier */ ecma_value_t this_arg, /**< 'this' argument value */ const ecma_value_t arguments_list[], /**< list of arguments * passed to routine */ ecma_length_t arguments_number) /**< length of arguments' list */{ if (JERRY_UNLIKELY (builtin_routine_id == ECMA_DATE_PROTOTYPE_TO_JSON)) { return ecma_builtin_date_prototype_to_json (this_arg); } if (!ecma_is_value_object (this_arg) || !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL)) { return ecma_raise_type_error (ECMA_ERR_MSG ("Date object expected")); } ecma_object_t *object_p = ecma_get_object_from_value (this_arg); ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ecma_number_t *prim_value_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, ext_object_p->u.class_prop.u.value); if (builtin_routine_id == ECMA_DATE_PROTOTYPE_GET_TIME) { return ecma_make_number_value (*prim_value_p); } if (builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_TIME) { ecma_value_t time = (arguments_number >= 1 ? arguments_list[0] : ECMA_VALUE_UNDEFINED); ecma_value_t ret_value = ECMA_VALUE_EMPTY; /* 1. */ ECMA_OP_TO_NUMBER_TRY_CATCH (time_num, time, ret_value); *prim_value_p = ecma_date_time_clip (time_num); ret_value = ecma_make_number_value (time_num); ECMA_OP_TO_NUMBER_FINALIZE (time_num); return ret_value; } if (builtin_routine_id <= ECMA_DATE_PROTOTYPE_SET_UTC_MILLISECONDS) { ecma_number_t this_num = *prim_value_p; if (!BUILTIN_DATE_FUNCTION_IS_UTC (builtin_routine_id)) { this_num += ecma_date_local_time_zone (this_num); } if (builtin_routine_id <= ECMA_DATE_PROTOTYPE_GET_UTC_TIMEZONE_OFFSET) { return ecma_builtin_date_prototype_dispatch_get (builtin_routine_id, this_num); } return ecma_builtin_date_prototype_dispatch_set (builtin_routine_id, ext_object_p, this_num, arguments_list, arguments_number); } if (builtin_routine_id == ECMA_DATE_PROTOTYPE_TO_ISO_STRING) { if (ecma_number_is_nan (*prim_value_p) || ecma_number_is_infinity (*prim_value_p)) { return ecma_raise_range_error (ECMA_ERR_MSG ("Date must be a finite number.")); } return ecma_date_value_to_iso_string (*prim_value_p); } if (ecma_number_is_nan (*prim_value_p)) { return ecma_make_magic_string_value (LIT_MAGIC_STRING_INVALID_DATE_UL); } switch (builtin_routine_id) { case ECMA_DATE_PROTOTYPE_TO_STRING: { return ecma_date_value_to_string (*prim_value_p); } case ECMA_DATE_PROTOTYPE_TO_DATE_STRING: { return ecma_date_value_to_date_string (*prim_value_p); } case ECMA_DATE_PROTOTYPE_TO_TIME_STRING://.........这里部分代码省略.........
开发者ID:jimmy-huang,项目名称:jerryscript,代码行数:101,
示例24: ecma_regexp_exec_helper/** * RegExp helper function to start the recursive matching algorithm * and create the result Array object * * @return completion value * Returned value must be freed with ecma_free_completion_value */ecma_completion_value_tecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */ ecma_value_t input_string, /**< input string */ bool ignore_global) /**< ignore global flag */{ ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); JERRY_ASSERT (ecma_is_value_object (regexp_value)); JERRY_ASSERT (ecma_is_value_string (input_string)); ecma_object_t *regexp_object_p = ecma_get_object_from_value (regexp_value); JERRY_ASSERT (ecma_object_get_class_name (regexp_object_p) == LIT_MAGIC_STRING_REGEXP_UL); ecma_property_t *bytecode_prop_p = ecma_get_internal_property (regexp_object_p, ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE); re_bytecode_t *bc_p = ECMA_GET_POINTER (re_bytecode_t, bytecode_prop_p->u.internal_property.value); ecma_string_t *input_string_p = ecma_get_string_from_value (input_string); lit_utf8_size_t input_string_size = ecma_string_get_size (input_string_p); MEM_DEFINE_LOCAL_ARRAY (input_utf8_buffer_p, input_string_size, lit_utf8_byte_t); ecma_string_to_utf8_string (input_string_p, input_utf8_buffer_p, (ssize_t) input_string_size); lit_utf8_iterator_t iterator = lit_utf8_iterator_create (input_utf8_buffer_p, input_string_size); re_matcher_ctx_t re_ctx; re_ctx.input_start_p = iterator.buf_p; re_ctx.input_end_p = iterator.buf_p + iterator.buf_size; /* 1. Read bytecode header and init regexp matcher context. */ re_ctx.flags = (uint8_t) re_get_value (&bc_p); if (ignore_global) { re_ctx.flags &= (uint8_t) ~RE_FLAG_GLOBAL; } JERRY_DDLOG ("Exec with flags [global: %d, ignoreCase: %d, multiline: %d]/n", re_ctx.flags & RE_FLAG_GLOBAL, re_ctx.flags & RE_FLAG_IGNORE_CASE, re_ctx.flags & RE_FLAG_MULTILINE); re_ctx.num_of_captures = re_get_value (&bc_p); JERRY_ASSERT (re_ctx.num_of_captures % 2 == 0); re_ctx.num_of_non_captures = re_get_value (&bc_p); /* We create an invalid iterator, that will be used to identify unused result values. */ lit_utf8_iterator_t unused_iter = lit_utf8_iterator_create (NULL, 0); unused_iter.buf_p = (lit_utf8_byte_t *) 1; MEM_DEFINE_LOCAL_ARRAY (saved_p, re_ctx.num_of_captures + re_ctx.num_of_non_captures, lit_utf8_iterator_t); for (uint32_t i = 0; i < re_ctx.num_of_captures + re_ctx.num_of_non_captures; i++) { saved_p[i] = unused_iter; } re_ctx.saved_p = saved_p; uint32_t num_of_iter_length = (re_ctx.num_of_captures / 2) + (re_ctx.num_of_non_captures - 1); MEM_DEFINE_LOCAL_ARRAY (num_of_iter_p, num_of_iter_length, uint32_t); for (uint32_t i = 0; i < num_of_iter_length; i++) { num_of_iter_p[i] = 0u; } bool is_match = false; re_ctx.num_of_iterations_p = num_of_iter_p; int32_t index = 0; ecma_length_t input_str_len = lit_utf8_string_length (iterator.buf_p, iterator.buf_size); if (iterator.buf_p && (re_ctx.flags & RE_FLAG_GLOBAL)) { ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL); ecma_property_t *lastindex_prop_p = ecma_op_object_get_property (regexp_object_p, magic_str_p); ECMA_OP_TO_NUMBER_TRY_CATCH (lastindex_num, lastindex_prop_p->u.named_data_property.value, ret_value) index = ecma_number_to_int32 (lastindex_num); JERRY_ASSERT (iterator.buf_pos.offset == 0 && !iterator.buf_pos.is_non_bmp_middle); if (!lit_utf8_iterator_is_eos (&iterator) && index <= (int32_t) input_str_len && index > 0) { lit_utf8_iterator_advance (&iterator, (ecma_length_t) index); } ECMA_OP_TO_NUMBER_FINALIZE (lastindex_num); ecma_deref_ecma_string (magic_str_p); } /* 2. Try to match */ lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);//.........这里部分代码省略.........
开发者ID:worm11235,项目名称:jerryscript,代码行数:101,
示例25: ecma_builtin_helper_array_concat_value/** * Helper function for concatenating an ecma_value_t to an Array. * * See also: * ECMA-262 v5, 15.4.4.4 steps 5.b - 5.c * * Used by: * - The Array.prototype.concat routine. * * @return ecma value * Returned value must be freed with ecma_free_value. */ecma_value_tecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, /**< array */ uint32_t *length_p, /**< [in,out] array's length */ ecma_value_t value) /**< value to concat */{ ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 5.b */ if (ecma_is_value_object (value) && (ecma_object_get_class_name (ecma_get_object_from_value (value)) == LIT_MAGIC_STRING_ARRAY_UL)) { ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string (); /* 5.b.ii */ ECMA_TRY_CATCH (arg_len_value, ecma_op_object_get (ecma_get_object_from_value (value), magic_string_length_p), ret_value); ECMA_OP_TO_NUMBER_TRY_CATCH (arg_len_number, arg_len_value, ret_value); uint32_t arg_len = ecma_number_to_uint32 (arg_len_number); /* 5.b.iii */ for (uint32_t array_index = 0; array_index < arg_len && ecma_is_value_empty (ret_value); array_index++) { ecma_string_t *array_index_string_p = ecma_new_ecma_string_from_uint32 (array_index); /* 5.b.iii.2 */ if (ecma_op_object_get_property (ecma_get_object_from_value (value), array_index_string_p) != NULL) { ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 (*length_p + array_index); /* 5.b.iii.3.a */ ECMA_TRY_CATCH (get_value, ecma_op_object_get (ecma_get_object_from_value (value), array_index_string_p), ret_value); /* 5.b.iii.3.b */ /* This will always be a simple value since 'is_throw' is false, so no need to free. */ ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p, new_array_index_string_p, get_value, true, /* Writable */ true, /* Enumerable */ true, /* Configurable */ false); /* Failure handling */ JERRY_ASSERT (ecma_is_value_true (put_comp)); ECMA_FINALIZE (get_value); ecma_deref_ecma_string (new_array_index_string_p); } ecma_deref_ecma_string (array_index_string_p); } *length_p += arg_len; ECMA_OP_TO_NUMBER_FINALIZE (arg_len_number); ECMA_FINALIZE (arg_len_value); ecma_deref_ecma_string (magic_string_length_p); } else { ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 ((*length_p)++); /* 5.c.i */ /* This will always be a simple value since 'is_throw' is false, so no need to free. */ ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p, new_array_index_string_p, value, true, /* Writable */ true, /* Enumerable */ true, /* Configurable */ false); /* Failure handling */ JERRY_ASSERT (ecma_is_value_true (put_comp)); ecma_deref_ecma_string (new_array_index_string_p); } if (ecma_is_value_empty (ret_value)) { ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE); }//.........这里部分代码省略.........
开发者ID:gudbooy,项目名称:jerryscript,代码行数:101,
示例26: ecma_op_abstract_relational_compare//.........这里部分代码省略......... if (!(is_px_string && is_py_string)) { /* 3. */ /* a. */ ECMA_OP_TO_NUMBER_TRY_CATCH (nx, px, ret_value); ECMA_OP_TO_NUMBER_TRY_CATCH (ny, py, ret_value); /* b. */ if (ecma_number_is_nan (nx) || ecma_number_is_nan (ny)) { /* c., d. */ ret_value = ECMA_VALUE_UNDEFINED; } else { bool is_x_less_than_y = (nx < ny);#ifndef JERRY_NDEBUG bool is_x_less_than_y_check; if (nx == ny || (ecma_number_is_zero (nx) && ecma_number_is_zero (ny))) { /* e., f., g. */ is_x_less_than_y_check = false; } else if (ecma_number_is_infinity (nx) && !ecma_number_is_negative (nx)) { /* h. */ is_x_less_than_y_check = false; } else if (ecma_number_is_infinity (ny) && !ecma_number_is_negative (ny)) { /* i. */ is_x_less_than_y_check = true; } else if (ecma_number_is_infinity (ny) && ecma_number_is_negative (ny)) { /* j. */ is_x_less_than_y_check = false; } else if (ecma_number_is_infinity (nx) && ecma_number_is_negative (nx)) { /* k. */ is_x_less_than_y_check = true; } else { /* l. */ JERRY_ASSERT (!ecma_number_is_nan (nx) && !ecma_number_is_infinity (nx)); JERRY_ASSERT (!ecma_number_is_nan (ny) && !ecma_number_is_infinity (ny)); JERRY_ASSERT (!(ecma_number_is_zero (nx) && ecma_number_is_zero (ny))); if (nx < ny) { is_x_less_than_y_check = true; } else { is_x_less_than_y_check = false; } } JERRY_ASSERT (is_x_less_than_y_check == is_x_less_than_y);#endif /* !JERRY_NDEBUG */ ret_value = ecma_make_boolean_value (is_x_less_than_y); } ECMA_OP_TO_NUMBER_FINALIZE (ny); ECMA_OP_TO_NUMBER_FINALIZE (nx); } else { /* 4. */ JERRY_ASSERT (is_px_string && is_py_string); ecma_string_t *str_x_p = ecma_get_string_from_value (px); ecma_string_t *str_y_p = ecma_get_string_from_value (py); bool is_px_less = ecma_compare_ecma_strings_relational (str_x_p, str_y_p); ret_value = ecma_make_boolean_value (is_px_less); } ecma_free_value (prim_second_converted_value); ecma_free_value (prim_first_converted_value); return ret_value;} /* ecma_op_abstract_relational_compare */
开发者ID:Samsung,项目名称:jerryscript,代码行数:101,
示例27: ecma_builtin_number_prototype_object_to_precision//.........这里部分代码省略......... lit_utf8_size_t num_digits; int32_t exponent; if (!ecma_number_is_zero (this_num)) { num_digits = ecma_number_to_decimal (this_num, digits, &exponent); } else { digits[0] = '0'; num_digits = 1; exponent = 1; } int32_t precision = ecma_number_to_int32 (arg_num); num_digits = ecma_builtin_number_prototype_helper_round (digits, num_digits, precision); int buffer_size; if (exponent < -5 || exponent > precision) { /* Exponential notation, precision + 1 digits for number, 5 for exponent, 1 for /0 */ buffer_size = precision + 1 + 5 + 1; } else if (exponent <= 0) { /* Fixed notation, -exponent + 2 digits for leading zeros, precision digits, 1 for /0 */ buffer_size = -exponent + 2 + precision + 1; } else { /* Fixed notation, precision + 1 digits for number, 1 for /0 */ buffer_size = precision + 1 + 1; } if (is_negative) { buffer_size++; } JMEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, lit_utf8_byte_t); lit_utf8_byte_t *actual_char_p = buff; if (is_negative) { *actual_char_p++ = '-'; } /* 10.c, Exponential notation.*/ if (exponent < -5 || exponent > precision) { actual_char_p += ecma_builtin_number_prototype_helper_to_string (digits, num_digits, 1, actual_char_p, (lit_utf8_size_t) precision); *actual_char_p++ = 'e'; exponent--; if (exponent < 0) { exponent *= -1; *actual_char_p++ = '-'; } else { *actual_char_p++ = '+'; } /* Add exponent digits. */ actual_char_p += ecma_uint32_to_utf8_string ((uint32_t) exponent, actual_char_p, 3); } /* Fixed notation. */ else { lit_utf8_size_t to_num_digits = ((exponent <= 0) ? (lit_utf8_size_t) (1 - exponent + precision) : (lit_utf8_size_t) precision); actual_char_p += ecma_builtin_number_prototype_helper_to_string (digits, num_digits, exponent, actual_char_p, to_num_digits); } JERRY_ASSERT (actual_char_p - buff < buffer_size); *actual_char_p = '/0'; ecma_string_t *str_p = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) (actual_char_p - buff)); ret_value = ecma_make_string_value (str_p); JMEM_FINALIZE_LOCAL_ARRAY (buff); } } ECMA_OP_TO_NUMBER_FINALIZE (arg_num); } ECMA_FINALIZE (this_value); return ret_value;} /* ecma_builtin_number_prototype_object_to_precision */
开发者ID:gudbooy,项目名称:jerryscript,代码行数:101,
示例28: ecma_builtin_number_prototype_object_to_exponential//.........这里部分代码省略......... if (ecma_number_is_infinity (this_num)) { ecma_string_t *infinity_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INFINITY_UL); if (is_negative) { ecma_string_t *neg_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_MINUS_CHAR); ecma_string_t *neg_inf_str_p = ecma_concat_ecma_strings (neg_str_p, infinity_str_p); ecma_deref_ecma_string (infinity_str_p); ecma_deref_ecma_string (neg_str_p); ret_value = ecma_make_string_value (neg_inf_str_p); } else { ret_value = ecma_make_string_value (infinity_str_p); } } else { /* Get the parameters of the number if non zero. */ lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER]; lit_utf8_size_t num_digits; int32_t exponent; if (!ecma_number_is_zero (this_num)) { num_digits = ecma_number_to_decimal (this_num, digits, &exponent); } else { digits[0] = '0'; num_digits = 1; exponent = 1; } int32_t frac_digits; if (ecma_is_value_undefined (arg)) { frac_digits = (int32_t) num_digits - 1; } else { frac_digits = ecma_number_to_int32 (arg_num); } num_digits = ecma_builtin_number_prototype_helper_round (digits, num_digits, frac_digits + 1); /* frac_digits + 2 characters for number, 5 characters for exponent, 1 for /0. */ int buffer_size = frac_digits + 2 + 5 + 1; if (is_negative) { /* +1 character for sign. */ buffer_size++; } JMEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, lit_utf8_byte_t); lit_utf8_byte_t *actual_char_p = buff; if (is_negative) { *actual_char_p++ = '-'; } actual_char_p += ecma_builtin_number_prototype_helper_to_string (digits, num_digits, 1, actual_char_p, (lit_utf8_size_t) (frac_digits + 1)); *actual_char_p++ = 'e'; exponent--; if (exponent < 0) { exponent *= -1; *actual_char_p++ = '-'; } else { *actual_char_p++ = '+'; } /* Add exponent digits. */ actual_char_p += ecma_uint32_to_utf8_string ((uint32_t) exponent, actual_char_p, 3); JERRY_ASSERT (actual_char_p - buff < buffer_size); *actual_char_p = '/0'; ecma_string_t *str = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) (actual_char_p - buff)); ret_value = ecma_make_string_value (str); JMEM_FINALIZE_LOCAL_ARRAY (buff); } } } ECMA_OP_TO_NUMBER_FINALIZE (arg_num); ECMA_FINALIZE (this_value); return ret_value;} /* ecma_builtin_number_prototype_object_to_exponential */
开发者ID:gudbooy,项目名称:jerryscript,代码行数:101,
示例29: ecma_builtin_number_prototype_object_to_fixed//.........这里部分代码省略......... { /* 6. */ bool is_negative = false; if (ecma_number_is_negative (this_num)) { is_negative = true; this_num *= -1; } /* We handle infinities separately. */ if (ecma_number_is_infinity (this_num)) { ecma_string_t *infinity_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INFINITY_UL); if (is_negative) { ecma_string_t *neg_str_p = ecma_new_ecma_string_from_utf8 ((const lit_utf8_byte_t *) "-", 1); ecma_string_t *neg_inf_str_p = ecma_concat_ecma_strings (neg_str_p, infinity_str_p); ecma_deref_ecma_string (infinity_str_p); ecma_deref_ecma_string (neg_str_p); ret_value = ecma_make_string_value (neg_inf_str_p); } else { ret_value = ecma_make_string_value (infinity_str_p); } } else { /* Get the parameters of the number if non-zero. */ lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER]; lit_utf8_size_t num_digits; int32_t exponent; if (!ecma_number_is_zero (this_num)) { num_digits = ecma_number_to_decimal (this_num, digits, &exponent); } else { digits[0] = '0'; num_digits = 1; exponent = 1; } /* 7. */ if (exponent > 21) { ret_value = ecma_builtin_number_prototype_object_to_string (this_arg, NULL, 0); } /* 8. */ else { /* 1. */ int32_t frac_digits = ecma_number_to_int32 (arg_num); num_digits = ecma_builtin_number_prototype_helper_round (digits, num_digits, exponent + frac_digits); /* Buffer that is used to construct the string. */ int buffer_size = (exponent > 0) ? exponent + frac_digits + 2 : frac_digits + 3; if (is_negative) { buffer_size++; } JERRY_ASSERT (buffer_size > 0); JMEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, lit_utf8_byte_t); lit_utf8_byte_t *p = buff; if (is_negative) { *p++ = '-'; } lit_utf8_size_t to_num_digits = ((exponent > 0) ? (lit_utf8_size_t) (exponent + frac_digits) : (lit_utf8_size_t) (frac_digits + 1)); p += ecma_builtin_number_prototype_helper_to_string (digits, num_digits, exponent, p, to_num_digits); JERRY_ASSERT (p - buff < buffer_size); /* String terminator. */ *p = 0; ecma_string_t *str = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) (p - buff)); ret_value = ecma_make_string_value (str); JMEM_FINALIZE_LOCAL_ARRAY (buff); } } } } ECMA_OP_TO_NUMBER_FINALIZE (arg_num); ECMA_FINALIZE (this_value); return ret_value;} /* ecma_builtin_number_prototype_object_to_fixed */
开发者ID:gudbooy,项目名称:jerryscript,代码行数:101,
示例30: ecma_builtin_number_prototype_object_to_string//.........这里部分代码省略......... int required_digits = buff_size; if (is_negative) { required_digits--; } if (!is_scale_negative) { /* Leave space for leading zeros / radix point. */ required_digits -= scale + 1; } /* Calculate digits for fractional part. */ while (buff_index < required_digits && (fraction != 0 || is_scale_negative)) { fraction *= (ecma_number_t) radix; lit_utf8_byte_t digit = (lit_utf8_byte_t) floor (fraction); buff[buff_index++] = digit; fraction -= (ecma_number_t) floor (fraction); } if (should_round) { /* Round off last digit. */ if (buff[buff_index - 1] > radix / 2) { buff[buff_index - 2]++; } buff_index--; /* Propagate carry. */ for (int i = buff_index - 1; i > 0 && buff[i] >= radix; i--) { buff[i] = (lit_utf8_byte_t) (buff[i] - radix); buff[i - 1]++; } /* Carry propagated over the whole number, need to add a leading digit. */ if (buff[0] >= radix) { memmove (buff + 1, buff, (size_t) buff_index); buff_index++; buff[0] = 1; } } /* Remove trailing zeros from fraction. */ while (buff_index - 1 > point && buff[buff_index - 1] == 0) { buff_index--; } /* Add leading zeros in case place of radix point is negative. */ if (point <= 0) { memmove (buff - point + 1, buff, (size_t) buff_index); buff_index += -point + 1; for (int i = 0; i < -point + 1; i++) { buff[i] = 0; } point = 1; } /* Convert digits to characters. */ for (int i = 0; i < buff_index; i++) { buff[i] = digit_chars[buff[i]]; } /* Place radix point to the required position. */ if (point < buff_index) { memmove (buff + point + 1, buff + point, (size_t) buff_index); buff[point] = '.'; buff_index++; } /* Add negative sign if necessary. */ if (is_negative) { memmove (buff + 1, buff, (size_t) buff_index); buff_index++; buff[0] = '-'; } JERRY_ASSERT (buff_index <= buff_size); ecma_string_t *str_p = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) buff_index); ret_value = ecma_make_string_value (str_p); JMEM_FINALIZE_LOCAL_ARRAY (buff); } ECMA_OP_TO_NUMBER_FINALIZE (arg_num); } ECMA_FINALIZE (this_value); return ret_value;} /* ecma_builtin_number_prototype_object_to_string */
开发者ID:gudbooy,项目名称:jerryscript,代码行数:101,
注:本文中的ECMA_OP_TO_NUMBER_FINALIZE函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ ECMA_OP_TO_NUMBER_TRY_CATCH函数代码示例 C++ ECMA_FINALIZE函数代码示例 |