/** * The String.prototype object's 'toString' routine * * See also: * ECMA-262 v5, 15.5.4.2 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_string_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */ { if (ecma_is_value_string (this_arg)) { return ecma_make_normal_completion_value (ecma_copy_value (this_arg, true)); } 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_STRING_UL) { ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE); ecma_string_t *prim_value_str_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, prim_value_prop_p->u.internal_property.value); prim_value_str_p = ecma_copy_or_ref_ecma_string (prim_value_str_p); return ecma_make_normal_completion_value (ecma_make_string_value (prim_value_str_p)); } } return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } /* ecma_builtin_string_prototype_object_to_string */
/** * Handle calling [[Call]] of built-in SyntaxError object * * @return ecma value */ ecma_value_t ecma_builtin_syntax_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); if (arguments_list_len != 0 && !ecma_is_value_undefined (arguments_list_p[0])) { ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); ECMA_TRY_CATCH (msg_str_value, ecma_op_to_string (arguments_list_p[0]), ret_value); ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_SYNTAX, message_string_p); ret_value = ecma_make_object_value (new_error_object_p); ECMA_FINALIZE (msg_str_value); return ret_value; } else { ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_SYNTAX); return ecma_make_object_value (new_error_object_p); } } /* ecma_builtin_syntax_error_dispatch_call */
/** * The Function.prototype object's 'call' routine * * See also: * ECMA-262 v5, 15.3.4.4 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_function_prototype_object_call (ecma_value_t this_arg, /**< this argument */ const ecma_value_t* arguments_list_p, /**< list of arguments */ ecma_length_t arguments_number) /**< number of arguments */ { if (!ecma_op_is_callable (this_arg)) { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *func_obj_p = ecma_get_object_from_value (this_arg); if (arguments_number == 0) { return ecma_op_function_call (func_obj_p, ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), NULL); } else { return ecma_op_function_call_array_args (func_obj_p, arguments_list_p[0], (arguments_number == 1u) ? NULL : (arguments_list_p + 1), (ecma_length_t) (arguments_number - 1u)); } } } /* ecma_builtin_function_prototype_object_call */
/** * [[HasInstance]] ecma object's operation * * See also: * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 9 */ ecma_completion_value_t ecma_op_object_has_instance (ecma_object_t *obj_p, /**< the object */ ecma_value_t value) /**< argument 'V' */ { JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); const ecma_object_type_t type = ecma_get_object_type (obj_p); ecma_assert_object_type_is_valid (type); switch (type) { case ECMA_OBJECT_TYPE_ARRAY: case ECMA_OBJECT_TYPE_GENERAL: case ECMA_OBJECT_TYPE_STRING: case ECMA_OBJECT_TYPE_ARGUMENTS: { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } case ECMA_OBJECT_TYPE_FUNCTION: case ECMA_OBJECT_TYPE_BOUND_FUNCTION: case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION: case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: { return ecma_op_function_has_instance (obj_p, value); } } JERRY_UNREACHABLE (); } /* ecma_op_object_has_instance */
/** * ToObject operation. * * See also: * ECMA-262 v5, 9.9 * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t ecma_op_to_object (ecma_value_t value) /**< ecma-value */ { ecma_check_value_type_is_spec_defined (value); if (ecma_is_value_number (value)) { return ecma_op_create_number_object (value); } else if (ecma_is_value_string (value)) { return ecma_op_create_string_object (&value, 1); } else if (ecma_is_value_object (value)) { return ecma_make_normal_completion_value (ecma_copy_value (value, true)); } else { if (ecma_is_value_undefined (value) || ecma_is_value_null (value)) { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { JERRY_ASSERT (ecma_is_value_boolean (value)); return ecma_op_create_boolean_object (value); } } } /* ecma_op_to_object */
/** * The Object object's 'getPrototypeOf' routine * * See also: * ECMA-262 v5, 15.2.3.2 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_get_prototype_of (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg) /**< routine's argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); /* 1. */ if (!ecma_is_value_object (arg)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { /* 2. */ ecma_object_t *obj_p = ecma_get_object_from_value (arg); ecma_object_t *prototype_p = ecma_get_object_prototype (obj_p); if (prototype_p) { ret_value = ecma_make_normal_completion_value (ecma_make_object_value (prototype_p)); ecma_ref_object (prototype_p); } else { ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_NULL); } } return ret_value; } /* ecma_builtin_object_object_get_prototype_of */
/** * Handle calling [[Call]] of a built-in error object * * @return ecma value */ ecma_value_t ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**< native error type */ const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); if (arguments_list_len != 0 && !ecma_is_value_undefined (arguments_list_p[0])) { ecma_value_t ret_value = ECMA_VALUE_EMPTY; ECMA_TRY_CATCH (msg_str_value, ecma_op_to_string (arguments_list_p[0]), ret_value); ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (error_type, message_string_p); ret_value = ecma_make_object_value (new_error_object_p); ECMA_FINALIZE (msg_str_value); return ret_value; } else { ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type); return ecma_make_object_value (new_error_object_p); } } /* ecma_builtin_helper_error_dispatch_call */
/** * The Object object's 'isSealed' routine * * See also: * ECMA-262 v5, 15.2.3.11 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_is_sealed (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg) /**< routine's argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); // 1. if (!ecma_is_value_object (arg)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *obj_p = ecma_get_object_from_value (arg); bool is_sealed; // 3. if (ecma_get_object_extensible (obj_p)) { is_sealed = false; } else { /* the value can be updated in the loop below */ is_sealed = true; // 2. ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, false, false, false); ecma_collection_iterator_t iter; ecma_collection_iterator_init (&iter, props_p); while (ecma_collection_iterator_next (&iter)) { ecma_string_t *property_name_p = ecma_get_string_from_value (*iter.current_value_p); // 2.a ecma_property_t *property_p = ecma_op_object_get_own_property (obj_p, property_name_p); // 2.b if (ecma_is_property_configurable (property_p)) { is_sealed = false; break; } } ecma_free_values_collection (props_p, true); } // 4. ret_value = ecma_make_simple_completion_value (is_sealed ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE); } return ret_value; } /* ecma_builtin_object_object_is_sealed */
/** * The Date.prototype object's 'toJSON' routine * * See also: * ECMA-262 v5, 15.9.5.44 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_date_prototype_to_json (ecma_value_t this_arg, /**< this argument */ ecma_value_t arg __attr_unused___) /**< key */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); /* 1. */ ECMA_TRY_CATCH (obj, ecma_op_to_object (this_arg), ret_value); /* 2. */ ECMA_TRY_CATCH (tv, ecma_op_to_primitive (obj, ECMA_PREFERRED_TYPE_NUMBER), ret_value); /* 3. */ if (ecma_is_value_number (tv)) { ecma_number_t num_value_p = *ecma_get_number_from_value (tv); if (ecma_number_is_nan (num_value_p) || ecma_number_is_infinity (num_value_p)) { ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_NULL); } } if (ecma_is_completion_value_empty (ret_value)) { ecma_string_t *to_iso_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_TO_ISO_STRING_UL); ecma_object_t *value_obj_p = ecma_get_object_from_value (obj); /* 4. */ ECMA_TRY_CATCH (to_iso, ecma_op_object_get (value_obj_p, to_iso_str_p), ret_value); /* 5. */ if (!ecma_op_is_callable (to_iso)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } /* 6. */ else { ecma_object_t *to_iso_obj_p = ecma_get_object_from_value (to_iso); ret_value = ecma_op_function_call (to_iso_obj_p, this_arg, NULL); } ECMA_FINALIZE (to_iso); ecma_deref_ecma_string (to_iso_str_p); } ECMA_FINALIZE (tv); ECMA_FINALIZE (obj); return ret_value; } /* ecma_builtin_date_prototype_to_json */
/** * The Array.prototype's 'toLocaleString' single element operation routine * * See also: * ECMA-262 v5, 15.4.4.3 steps 6-8 and 10.b-d * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ ecma_completion_value_t ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /** < this object */ uint32_t index) /** < array index */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index); ECMA_TRY_CATCH (index_value, ecma_op_object_get (obj_p, index_string_p), ret_value); if (ecma_is_value_undefined (index_value) || ecma_is_value_null (index_value)) { ecma_string_t *return_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); ret_value = ecma_make_normal_completion_value (ecma_make_string_value (return_string_p)); } else { ECMA_TRY_CATCH (index_obj_value, ecma_op_to_object (index_value), ret_value); ecma_object_t *index_obj_p = ecma_get_object_from_value (index_obj_value); ecma_string_t *locale_string_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL); ECMA_TRY_CATCH (to_locale_value, ecma_op_object_get (index_obj_p, locale_string_magic_string_p), ret_value); if (ecma_op_is_callable (to_locale_value)) { ecma_object_t *locale_func_obj_p = ecma_get_object_from_value (to_locale_value); ECMA_TRY_CATCH (call_value, ecma_op_function_call (locale_func_obj_p, ecma_make_object_value (index_obj_p), NULL), ret_value); ret_value = ecma_op_to_string (call_value); ECMA_FINALIZE (call_value); } else { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } ECMA_FINALIZE (to_locale_value); ecma_deref_ecma_string (locale_string_magic_string_p); ECMA_FINALIZE (index_obj_value); } ECMA_FINALIZE (index_value); ecma_deref_ecma_string (index_string_p); return ret_value; } /* ecma_builtin_helper_get_to_locale_string_at_index */
/** * Handle calling [[Construct]] of built-in Function.prototype object * * @return completion-value */ ecma_completion_value_t ecma_builtin_function_prototype_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } /* ecma_builtin_function_prototype_dispatch_construct */
/** * Handle calling [[Call]] of built-in [[ThrowTypeError]] object * * See also: * ECMA-262 v5, 13.2.3 * * @return completion-value */ ecma_completion_value_t ecma_builtin_type_error_thrower_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); /* The object should throw TypeError */ return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } /* ecma_builtin_type_error_thrower_dispatch_call */
/** * Reject sequence for PutValue * * @return completion value * Returned value must be freed with ecma_free_completion_value */ static ecma_completion_value_t ecma_reject_put (bool is_throw) /**< Throw flag */ { if (is_throw) { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { return ecma_make_empty_completion_value (); } } /* ecma_reject_put */
/** * Reject sequence * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t ecma_reject (bool is_throw) /**< Throw flag */ { if (is_throw) { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); } } /* ecma_reject */
/** * Perform 'eval' with code stored in continuous character buffer * * See also: * ecma_op_eval * ECMA-262 v5, 15.1.2.1 (steps 2 to 8) * * @return completion value */ ecma_completion_value_t ecma_op_eval_chars_buffer (const jerry_api_char_t *code_p, /**< code characters buffer */ size_t code_buffer_size, /**< size of the buffer */ bool is_direct, /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */ bool is_called_from_strict_mode_code) /**< is eval is called from strict mode code */ { JERRY_ASSERT (code_p != NULL); ecma_completion_value_t completion; ecma_compiled_code_t *bytecode_data_p; jsp_status_t parse_status; bool is_strict_call = (is_direct && is_called_from_strict_mode_code); parse_status = parser_parse_eval (code_p, code_buffer_size, is_strict_call, &bytecode_data_p); if (parse_status == JSP_STATUS_SYNTAX_ERROR) { completion = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_SYNTAX)); } else if (parse_status == JSP_STATUS_REFERENCE_ERROR) { completion = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE)); } else { JERRY_ASSERT (parse_status == JSP_STATUS_OK); completion = vm_run_eval (bytecode_data_p, is_direct); } return completion; } /* ecma_op_eval_chars_buffer */
/** * CheckObjectCoercible operation. * * See also: * ECMA-262 v5, 9.10 * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t ecma_op_check_object_coercible (ecma_value_t value) /**< ecma-value */ { ecma_check_value_type_is_spec_defined (value); if (ecma_is_value_undefined (value) || ecma_is_value_null (value)) { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { return ecma_make_empty_completion_value (); } } /* ecma_op_check_object_coercible */
/** * The Function.prototype object's 'toString' routine * * See also: * ECMA-262 v5, 15.3.4.2 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_function_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); if (!ecma_op_is_callable (this_arg)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_string_t *function_to_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__FUNCTION_TO_STRING); ret_value = ecma_make_normal_completion_value (ecma_make_string_value (function_to_string_p)); } return ret_value; } /* ecma_builtin_function_prototype_object_to_string */
/** * The Object object's 'create' routine * * See also: * ECMA-262 v5, 15.2.3.5 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_create (ecma_value_t this_arg, /**< 'this' argument */ ecma_value_t arg1, /**< routine's first argument */ ecma_value_t arg2) /**< routine's second argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); // 1. if (!ecma_is_value_object (arg1) && !ecma_is_value_null (arg1)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *obj_p = NULL; if (!ecma_is_value_null (arg1)) { obj_p = ecma_get_object_from_value (arg1); } // 2-3. ecma_object_t *result_obj_p = ecma_op_create_object_object_noarg_and_set_prototype (obj_p); // 4. if (!ecma_is_value_undefined (arg2)) { ECMA_TRY_CATCH (obj, ecma_builtin_object_object_define_properties (this_arg, ecma_make_object_value (result_obj_p), arg2), ret_value); ECMA_FINALIZE (obj); } // 5. if (ecma_is_completion_value_empty (ret_value)) { ret_value = ecma_make_normal_completion_value (ecma_copy_value (ecma_make_object_value (result_obj_p), true)); } ecma_deref_object (result_obj_p); } return ret_value; } /* ecma_builtin_object_object_create */
/** * The Object object's 'getOwnPropertyDescriptor' routine * * See also: * ECMA-262 v5, 15.2.3.3 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_get_own_property_descriptor (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg1, /**< routine's first argument */ ecma_value_t arg2) /**< routine's second argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); // 1. if (!ecma_is_value_object (arg1)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); return ret_value; } ecma_object_t *obj_p = ecma_get_object_from_value (arg1); // 2. ECMA_TRY_CATCH (name_str_value, ecma_op_to_string (arg2), ret_value); ecma_string_t *name_str_p = ecma_get_string_from_value (name_str_value); // 3. ecma_property_t *prop_p = ecma_op_object_get_own_property (obj_p, name_str_p); if (prop_p != NULL) { ecma_property_descriptor_t prop_desc = ecma_get_property_descriptor_from_property (prop_p); // 4. ecma_object_t* desc_obj_p = ecma_op_from_property_descriptor (&prop_desc); ecma_free_property_descriptor (&prop_desc); ret_value = ecma_make_normal_completion_value (ecma_make_object_value (desc_obj_p)); } else { ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); } ECMA_FINALIZE (name_str_value); return ret_value; } /* ecma_builtin_object_object_get_own_property_descriptor */
/** * The Object object's 'defineProperty' routine * * See also: * ECMA-262 v5, 15.2.3.6 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_define_property (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg1, /**< routine's first argument */ ecma_value_t arg2, /**< routine's second argument */ ecma_value_t arg3) /**< routine's third argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); if (!ecma_is_value_object (arg1)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *obj_p = ecma_get_object_from_value (arg1); ECMA_TRY_CATCH (name_str_value, ecma_op_to_string (arg2), ret_value); ecma_string_t *name_str_p = ecma_get_string_from_value (name_str_value); ecma_property_descriptor_t prop_desc; ECMA_TRY_CATCH (conv_result, ecma_op_to_property_descriptor (arg3, &prop_desc), ret_value); ECMA_TRY_CATCH (define_own_prop_ret, ecma_op_object_define_own_property (obj_p, name_str_p, &prop_desc, true), ret_value); ret_value = ecma_make_normal_completion_value (ecma_copy_value (arg1, true)); ECMA_FINALIZE (define_own_prop_ret); ecma_free_property_descriptor (&prop_desc); ECMA_FINALIZE (conv_result); ECMA_FINALIZE (name_str_value); } return ret_value; } /* ecma_builtin_object_object_define_property */
/** * PutValue operation part (lexical environment base or unresolvable reference). * * See also: ECMA-262 v5, 8.7.2, sections 3 and 5 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ ecma_completion_value_t ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */ ecma_string_t *var_name_string_p, /**< variable name */ bool is_strict, /**< flag indicating strict mode */ ecma_value_t value) /**< ECMA-value */ { const bool is_unresolvable_reference = (ref_base_lex_env_p == NULL); // 3. if (unlikely (is_unresolvable_reference)) { // 3.a. if (is_strict) { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE)); } else { // 3.b. ecma_object_t *global_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL); ecma_completion_value_t completion = ecma_op_object_put (global_object_p, var_name_string_p, value, false); ecma_deref_object (global_object_p); JERRY_ASSERT (ecma_is_completion_value_normal_true (completion) || ecma_is_completion_value_normal_false (completion)); return ecma_make_empty_completion_value (); } } // 5. JERRY_ASSERT (ref_base_lex_env_p != NULL && ecma_is_lexical_environment (ref_base_lex_env_p)); // 5.a return ecma_op_set_mutable_binding (ref_base_lex_env_p, var_name_string_p, value, is_strict); } /* ecma_op_put_value_lex_env_base */
/** * Standard ecma-error object constructor. * * @return pointer to ecma-object representing specified error * with reference counter set to one. */ ecma_object_t * ecma_new_standard_error_with_message (ecma_standard_error_t error_type, /**< native error type */ ecma_string_t *message_string_p) /**< message string */ { ecma_object_t *new_error_obj_p = ecma_new_standard_error (error_type); ecma_string_t *message_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE); ecma_property_t *prop_p = ecma_create_named_data_property (new_error_obj_p, message_magic_string_p, ECMA_PROPERTY_CONFIGURABLE_WRITABLE); ecma_ref_ecma_string (message_string_p); ecma_set_named_data_property_value (prop_p, ecma_make_string_value (message_string_p)); ecma_deref_ecma_string (message_magic_string_p); return new_error_obj_p; } /* ecma_new_standard_error_with_message */
/** * Raise a standard ecma-error with the given type and message. * * @return ecma value * Returned value must be freed with ecma_free_value */ ecma_value_t ecma_raise_standard_error (ecma_standard_error_t error_type, /**< error type */ const lit_utf8_byte_t *msg_p) /**< error message */ { ecma_object_t *error_obj_p; if (msg_p != NULL) { ecma_string_t *error_msg_p = ecma_new_ecma_string_from_utf8 (msg_p, lit_zt_utf8_string_size (msg_p)); error_obj_p = ecma_new_standard_error_with_message (error_type, error_msg_p); ecma_deref_ecma_string (error_msg_p); } else { error_obj_p = ecma_new_standard_error (error_type); } return ecma_make_error_obj_value (error_obj_p); } /* ecma_raise_standard_error */
/** * The Object object's 'preventExtensions' routine * * See also: * ECMA-262 v5, 15.2.3.10 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_prevent_extensions (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg) /**< routine's argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); if (!ecma_is_value_object (arg)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *obj_p = ecma_get_object_from_value (arg); ecma_set_object_extensible (obj_p, false); ret_value = ecma_make_normal_completion_value (ecma_copy_value (arg, true)); } return ret_value; } /* ecma_builtin_object_object_prevent_extensions */
/** * The Object object's 'keys' routine * * See also: * ECMA-262 v5, 15.2.3.14 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_keys (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg) /**< routine's argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); if (!ecma_is_value_object (arg)) { /* 1. */ ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *obj_p = ecma_get_object_from_value (arg); /* 3-6. */ ret_value = ecma_builtin_helper_object_get_properties (obj_p, true); } return ret_value; } /* ecma_builtin_object_object_keys */
/** * [[Delete]] ecma general object's operation * * See also: * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 * ECMA-262 v5, 8.12.7 * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t ecma_op_general_object_delete (ecma_object_t *obj_p, /**< the object */ ecma_string_t *property_name_p, /**< property name */ bool is_throw) /**< flag that controls failure handling */ { JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); JERRY_ASSERT (property_name_p != NULL); // 1. ecma_property_t *desc_p = ecma_op_object_get_own_property (obj_p, property_name_p); // 2. if (desc_p == NULL) { return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); } // 3. if (ecma_is_property_configurable (desc_p)) { // a. ecma_delete_property (obj_p, desc_p); // b. return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); } else if (is_throw) { // 4. return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { // 5. return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); } JERRY_UNREACHABLE (); } /* ecma_op_general_object_delete */
/** * GetValue operation part (lexical environment base or unresolvable reference). * * See also: ECMA-262 v5, 8.7.1, sections 3 and 5 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ ecma_completion_value_t ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */ ecma_string_t *var_name_string_p, /**< variable name */ bool is_strict) /**< flag indicating strict mode */ { const bool is_unresolvable_reference = (ref_base_lex_env_p == NULL); // 3. if (unlikely (is_unresolvable_reference)) { return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE)); } // 5. JERRY_ASSERT (ref_base_lex_env_p != NULL && ecma_is_lexical_environment (ref_base_lex_env_p)); // 5.a return ecma_op_get_binding_value (ref_base_lex_env_p, var_name_string_p, is_strict); } /* ecma_op_get_value_lex_env_base */
/** * The Date.prototype object's 'getTime' routine * * See also: * ECMA-262 v5, 15.9.5.9 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_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_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 = ECMA_GET_NON_NULL_POINTER (ecma_number_t, prim_value_prop_p->u.internal_property.value); ecma_number_t *ret_num_p = ecma_alloc_number (); *ret_num_p = *prim_value_num_p; return ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p)); } } return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } /* ecma_builtin_date_prototype_get_time */
/** * The Object object's 'isExtensible' routine * * See also: * ECMA-262 v5, 15.2.3.13 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_object_is_extensible (ecma_value_t this_arg __attr_unused___, /**< 'this' argument */ ecma_value_t arg) /**< routine's argument */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); if (!ecma_is_value_object (arg)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *obj_p = ecma_get_object_from_value (arg); bool extensible = ecma_get_object_extensible (obj_p); ret_value = ecma_make_simple_completion_value (extensible ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE); } return ret_value; } /* ecma_builtin_object_object_is_extensible */
/** * The Object.prototype object's 'toLocaleString' routine * * See also: * ECMA-262 v5, 15.2.4.3 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_prototype_object_to_locale_string (ecma_value_t this_arg) /**< this argument */ { ecma_completion_value_t return_value = ecma_make_empty_completion_value (); /* 1. */ ECMA_TRY_CATCH (obj_val, ecma_op_to_object (this_arg), return_value); ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); ecma_string_t *to_string_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_TO_STRING_UL); /* 2. */ ECMA_TRY_CATCH (to_string_val, ecma_op_object_get (obj_p, to_string_magic_string_p), return_value); /* 3. */ if (!ecma_op_is_callable (to_string_val)) { return_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { /* 4. */ ecma_object_t *to_string_func_obj_p = ecma_get_object_from_value (to_string_val); return_value = ecma_op_function_call (to_string_func_obj_p, this_arg, NULL); } ECMA_FINALIZE (to_string_val); ecma_deref_ecma_string (to_string_magic_string_p); ECMA_FINALIZE (obj_val); return return_value; } /* ecma_builtin_object_prototype_object_to_locale_string */