/** * The Date.prototype object's 'toDateString' routine * * See also: * ECMA-262 v5, 15.9.5.3 * * @return ecma value * Returned value must be freed with ecma_free_value. */ static ecma_value_t ecma_builtin_date_prototype_to_date_string (ecma_value_t this_arg) /**< this argument */ { 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 { ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value); ecma_object_t *obj_p = ecma_get_object_from_value (obj_this); 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_NON_NULL_POINTER (ecma_number_t, ecma_get_internal_property_value (prim_prop_p)); if (ecma_number_is_nan (*prim_value_num_p)) { ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INVALID_DATE_UL); ret_value = ecma_make_string_value (magic_str_p); } else { ret_value = ecma_date_value_to_date_string (*prim_value_num_p); } ECMA_FINALIZE (obj_this); } return ret_value; } /* ecma_builtin_date_prototype_to_date_string */
/** * Process the PromiseResolveThenableJob. * * See also: ES2015 25.4.2.2 * * @return ecma value * Returned value must be freed with ecma_free_value */ static ecma_value_t ecma_process_promise_resolve_thenable_job (void *obj_p) /**< the job to be operated */ { ecma_job_promise_resolve_thenable_t *job_p = (ecma_job_promise_resolve_thenable_t *) obj_p; ecma_object_t *promise_p = ecma_get_object_from_value (job_p->promise); ecma_string_t str_resolve, str_reject; ecma_init_ecma_magic_string (&str_resolve, LIT_INTERNAL_MAGIC_STRING_RESOLVE_FUNCTION); ecma_init_ecma_magic_string (&str_reject, LIT_INTERNAL_MAGIC_STRING_REJECT_FUNCTION); ecma_value_t resolve = ecma_op_object_get (promise_p, &str_resolve); ecma_value_t reject = ecma_op_object_get (promise_p, &str_reject); ecma_value_t argv[] = { resolve, reject }; ecma_value_t ret; ecma_value_t then_call_result = ecma_op_function_call (ecma_get_object_from_value (job_p->then), job_p->thenable, argv, 2); ret = then_call_result; if (ECMA_IS_VALUE_ERROR (then_call_result)) { ret = ecma_op_function_call (ecma_get_object_from_value (reject), ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), &then_call_result, 1); ecma_free_value (then_call_result); } ecma_free_value (resolve); ecma_free_value (reject); ecma_free_promise_resolve_thenable_job (job_p); return ret; } /* ecma_process_promise_resolve_thenable_job */
/** * 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 */
/** * The Object.prototype object's 'toLocaleString' routine * * See also: * ECMA-262 v5, 15.2.4.3 * * @return ecma value * Returned value must be freed with ecma_free_value. */ static ecma_value_t ecma_builtin_object_prototype_object_to_locale_string (ecma_value_t this_arg) /**< this argument */ { ecma_value_t return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 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_raise_type_error (ECMA_ERR_MSG ("")); } 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, 0); } 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 */
/** * Check the object value existance in the collection. * * Used by: * - ecma_builtin_json_object step 1 * - ecma_builtin_json_array step 1 * * @return true, if the object is already in the collection. */ bool ecma_has_object_value_in_collection (ecma_collection_header_t *collection_p, /**< collection */ ecma_value_t object_value) /**< object value */ { JERRY_ASSERT (ecma_is_value_object (object_value)); ecma_object_t *obj_p = ecma_get_object_from_value (object_value); ecma_collection_iterator_t iterator; ecma_collection_iterator_init (&iterator, collection_p); while (ecma_collection_iterator_next (&iterator)) { ecma_value_t value = *iterator.current_value_p; ecma_object_t *current_p = ecma_get_object_from_value (value); if (current_p == obj_p) { return true; } } return false; } /* ecma_has_object_value_in_collection */
/** * The Object.prototype object's 'isPrototypeOf' routine * * See also: * ECMA-262 v5, 15.2.4.6 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_prototype_object_is_prototype_of (ecma_value_t this_arg, /**< this argument */ ecma_value_t arg) /**< routine's first argument */ { /* 1. Is the argument an object? */ if (!ecma_is_value_object (arg)) { return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); } ecma_completion_value_t return_value = ecma_make_empty_completion_value (); /* 2. ToObject(this) */ ECMA_TRY_CATCH (obj_value, ecma_op_to_object (this_arg), return_value); ecma_object_t *obj_p = ecma_get_object_from_value (obj_value); /* 3. Compare prototype to object */ ECMA_TRY_CATCH (v_obj_value, ecma_op_to_object (arg), return_value); ecma_object_t *v_obj_p = ecma_get_object_from_value (v_obj_value); bool is_prototype_of = ecma_op_object_is_prototype_of (obj_p, v_obj_p); return_value = ecma_make_simple_completion_value (is_prototype_of ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE); ECMA_FINALIZE (v_obj_value); ECMA_FINALIZE (obj_value); return return_value; } /* ecma_builtin_object_prototype_object_is_prototype_of */
/** * 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 */
/** * IsCallable operation. * * See also: ECMA-262 v5, 9.11 * * @return true, if value is callable object; * false - otherwise. */ bool ecma_op_is_callable (ecma_value_t value) /**< ecma value */ { if (!ecma_is_value_object (value)) { return false; } ecma_object_t *obj_p = ecma_get_object_from_value (value); JERRY_ASSERT (obj_p != NULL); JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); return (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION || ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION || ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION); } /* ecma_op_is_callable */
/** * ToPrimitive operation. * * See also: * ECMA-262 v5, 9.1 * * @return ecma value * Returned value must be freed with ecma_free_value */ ecma_value_t ecma_op_to_primitive (ecma_value_t value, /**< ecma value */ ecma_preferred_type_hint_t preferred_type) /**< preferred type hint */ { ecma_check_value_type_is_spec_defined (value); if (ecma_is_value_object (value)) { ecma_object_t *obj_p = ecma_get_object_from_value (value); return ecma_op_object_default_value (obj_p, preferred_type); } else { return ecma_copy_value (value); } } /* ecma_op_to_primitive */
/** * 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 */
/** * Deletes an object property. * * @return ecma value * Returned value must be freed with ecma_free_value */ ecma_value_t vm_op_delete_prop (ecma_value_t object, /**< base object */ ecma_value_t property, /**< property name */ bool is_strict) /**< strict mode */ { ecma_value_t completion_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); if (ecma_is_value_undefined (object)) { completion_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE); } else { completion_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); ECMA_TRY_CATCH (check_coercible_ret, ecma_op_check_object_coercible (object), completion_value); ECMA_TRY_CATCH (str_name_value, ecma_op_to_string (property), completion_value); JERRY_ASSERT (ecma_is_value_string (str_name_value)); ecma_string_t *name_string_p = ecma_get_string_from_value (str_name_value); ECMA_TRY_CATCH (obj_value, ecma_op_to_object (object), completion_value); JERRY_ASSERT (ecma_is_value_object (obj_value)); ecma_object_t *obj_p = ecma_get_object_from_value (obj_value); JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); ECMA_TRY_CATCH (delete_op_ret_val, ecma_op_object_delete (obj_p, name_string_p, is_strict), completion_value); completion_value = delete_op_ret_val; ECMA_FINALIZE (delete_op_ret_val); ECMA_FINALIZE (obj_value); ECMA_FINALIZE (str_name_value); ECMA_FINALIZE (check_coercible_ret); } return completion_value; } /* vm_op_delete_prop */
/** * Create a PromiseResolveThenableJob * * @return pointer to the PromiseResolveThenableJob */ static ecma_job_promise_resolve_thenable_t * ecma_create_promise_resolve_thenable_job (ecma_value_t promise, /**< promise to be resolved */ ecma_value_t thenable, /**< thenable object */ ecma_value_t then) /**< 'then' function */ { JERRY_ASSERT (ecma_is_promise (ecma_get_object_from_value (promise))); JERRY_ASSERT (ecma_is_value_object (thenable)); JERRY_ASSERT (ecma_op_is_callable (then)); ecma_job_promise_resolve_thenable_t *job_p; job_p = (ecma_job_promise_resolve_thenable_t *) jmem_heap_alloc_block (sizeof (ecma_job_promise_resolve_thenable_t)); job_p->promise = ecma_copy_value (promise); job_p->thenable = ecma_copy_value (thenable); job_p->then = ecma_copy_value (then); return job_p; } /* ecma_create_promise_resolve_thenable_job */
/** * 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 */
/** * The Object.prototype object's 'propertyIsEnumerable' routine * * See also: * ECMA-262 v5, 15.2.4.7 * * @return ecma value * Returned value must be freed with ecma_free_value. */ static ecma_value_t ecma_builtin_object_prototype_object_property_is_enumerable (ecma_value_t this_arg, /**< this argument */ ecma_value_t arg) /**< routine's first argument */ { ecma_value_t return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (to_string_val, ecma_op_to_string (arg), return_value); /* 2. */ ECMA_TRY_CATCH (obj_val, ecma_op_to_object (this_arg), return_value); ecma_string_t *property_name_string_p = ecma_get_string_from_value (to_string_val); ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); /* 3. */ ecma_property_t property = ecma_op_object_get_own_property (obj_p, property_name_string_p, NULL, ECMA_PROPERTY_GET_NO_OPTIONS); /* 4. */ if (property != ECMA_PROPERTY_TYPE_NOT_FOUND) { bool is_enumerable = ecma_is_property_enumerable (property); return_value = ecma_make_boolean_value (is_enumerable); } else { return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE); } ECMA_FINALIZE (obj_val); ECMA_FINALIZE (to_string_val); return return_value; } /* ecma_builtin_object_prototype_object_property_is_enumerable */
/** * The Array object's 'isArray' routine * * See also: * ECMA-262 v5, 15.4.3.2 * * @return ecma value * Returned value must be freed with ecma_free_value. */ static ecma_value_t ecma_builtin_array_object_is_array (ecma_value_t this_arg, /**< 'this' argument */ ecma_value_t arg) /**< first argument */ { JERRY_UNUSED (this_arg); ecma_simple_value_t is_array = ECMA_SIMPLE_VALUE_FALSE; if (ecma_is_value_object (arg)) { ecma_object_t *obj_p = ecma_get_object_from_value (arg); if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_ARRAY_UL) { is_array = ECMA_SIMPLE_VALUE_TRUE; } } return ecma_make_simple_value (is_array); } /* ecma_builtin_array_object_is_array */
/** * The Object.keys and Object.getOwnPropertyNames routine's common part. * * See also: * ECMA-262 v5, 15.2.3.4 steps 2-5 * ECMA-262 v5, 15.2.3.14 steps 3-6 * * @return ecma value - Array of property names. * Returned value must be freed with ecma_free_value. */ ecma_value_t ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */ bool only_enumerable_properties) /**< list enumerable properties? */ { JERRY_ASSERT (obj_p != NULL); ecma_value_t new_array = ecma_op_create_array_object (NULL, 0, false); JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array)); ecma_object_t *new_array_p = ecma_get_object_from_value (new_array); uint32_t index = 0; ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, false, only_enumerable_properties, false); ecma_collection_iterator_t iter; ecma_collection_iterator_init (&iter, props_p); while (ecma_collection_iterator_next (&iter)) { ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index); ecma_value_t completion = ecma_builtin_helper_def_prop (new_array_p, index_string_p, *iter.current_value_p, true, /* Writable */ true, /* Enumerable */ true, /* Configurable */ false); /* Failure handling */ JERRY_ASSERT (ecma_is_value_true (completion)); ecma_deref_ecma_string (index_string_p); index++; } ecma_free_values_collection (props_p, true); return new_array; } /* ecma_builtin_helper_object_get_properties */
/** * The Object.prototype object's 'propertyIsEnumerable' routine * * See also: * ECMA-262 v5, 15.2.4.7 * * @return completion value * Returned value must be freed with ecma_free_completion_value. */ static ecma_completion_value_t ecma_builtin_object_prototype_object_property_is_enumerable (ecma_value_t this_arg, /**< this argument */ ecma_value_t arg) /**< routine's first argument */ { ecma_completion_value_t return_value = ecma_make_empty_completion_value (); /* 1. */ ECMA_TRY_CATCH (to_string_val, ecma_op_to_string (arg), return_value); /* 2. */ ECMA_TRY_CATCH (obj_val, ecma_op_to_object (this_arg), return_value); ecma_string_t *property_name_string_p = ecma_get_string_from_value (to_string_val); ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); /* 3. */ ecma_property_t *property_p = ecma_op_object_get_own_property (obj_p, property_name_string_p); /* 4. */ if (property_p != NULL) { bool is_enumerable = ecma_is_property_enumerable (property_p); return_value = ecma_make_simple_completion_value (is_enumerable ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE); } else { return_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); } ECMA_FINALIZE (obj_val); ECMA_FINALIZE (to_string_val); return return_value; } /* ecma_builtin_object_prototype_object_property_is_enumerable */
/** * 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 */
/** * 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 */
/** * 'Function call' opcode handler. * * See also: ECMA-262 v5, 11.2.3 * * @return ecma value * Returned value must be freed with ecma_free_value. */ ecma_value_t opfunc_call_n (ecma_value_t this_value, /**< this object value */ ecma_value_t func_value, /**< function object value */ const ecma_value_t *arguments_list_p, /**< stack pointer */ ecma_length_t arguments_list_len) /**< number of arguments */ { ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); if (!ecma_op_is_callable (func_value)) { return ecma_raise_type_error (""); } ecma_object_t *func_obj_p = ecma_get_object_from_value (func_value); ret_value = ecma_op_function_call (func_obj_p, this_value, arguments_list_p, arguments_list_len); return ret_value; } /* opfunc_call_n */
/** * Check whether the value is Object that implements [[Construct]]. * * @return true, if value is constructor object; * false - otherwise. */ bool ecma_is_constructor (ecma_value_t value) /**< ecma value */ { if (!ecma_is_value_object (value)) { return false; } ecma_object_t *obj_p = ecma_get_object_from_value (value); JERRY_ASSERT (obj_p != NULL); JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION) { return (!ecma_get_object_is_builtin (obj_p) || !ecma_builtin_function_is_routine (obj_p)); } return (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION || ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION); } /* ecma_is_constructor */
/** * 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_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_NON_NULL_POINTER (ecma_number_t, ecma_get_internal_property_value (prim_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_date_prototype_get_time */
/** * Fulfill a Promise with a value. * * See also: ES2015 25.4.1.4 */ static void ecma_fulfill_promise (ecma_value_t promise, /**< promise */ ecma_value_t value) /**< fulfilled value */ { ecma_object_t *obj_p = ecma_get_object_from_value (promise); JERRY_ASSERT (ecma_promise_get_state (obj_p) == ECMA_PROMISE_STATE_PENDING); ecma_promise_set_state (obj_p, ECMA_PROMISE_STATE_FULFILLED); ecma_promise_set_result (obj_p, ecma_copy_value_if_not_object (value)); ecma_promise_object_t *promise_p = (ecma_promise_object_t *) obj_p; /* GC can be triggered by ecma_new_values_collection so freeing the collection first and creating a new one might cause a heap after use event. */ ecma_collection_header_t *reject_reactions = promise_p->reject_reactions; ecma_collection_header_t *fulfill_reactions = promise_p->fulfill_reactions; promise_p->reject_reactions = ecma_new_values_collection (); promise_p->fulfill_reactions = ecma_new_values_collection (); /* Reject reactions will never be triggered. */ ecma_free_values_collection (reject_reactions, ECMA_COLLECTION_NO_REF_OBJECTS); ecma_promise_trigger_reactions (fulfill_reactions, value); } /* ecma_fulfill_promise */
/** * 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 */
/** * 'for-in' opcode handler * * See also: * ECMA-262 v5, 12.6.4 * * @return completion value * Returned value must be freed with ecma_free_value */ ecma_collection_header_t * opfunc_for_in (ecma_value_t left_value, /**< left value */ ecma_value_t *result_obj_p) /**< expression object */ { ecma_value_t compl_val = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); ecma_collection_header_t *prop_names_p = NULL; /* 3. */ if (!ecma_is_value_undefined (left_value) && !ecma_is_value_null (left_value)) { /* 4. */ ECMA_TRY_CATCH (obj_expr_value, ecma_op_to_object (left_value), compl_val); ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value); prop_names_p = ecma_op_object_get_property_names (obj_p, false, true, true); if (prop_names_p->unit_number != 0) { ecma_ref_object (obj_p); *result_obj_p = ecma_make_object_value (obj_p); } else { ecma_dealloc_collection_header (prop_names_p); prop_names_p = NULL; } ECMA_FINALIZE (obj_expr_value); } JERRY_ASSERT (ecma_is_value_empty (compl_val)); return prop_names_p; } /* opfunc_for_in */
/** * The Object.prototype object's 'hasOwnProperty' routine * * See also: * ECMA-262 v5, 15.2.4.5 * * @return ecma value * Returned value must be freed with ecma_free_value. */ static ecma_value_t ecma_builtin_object_prototype_object_has_own_property (ecma_value_t this_arg, /**< this argument */ ecma_value_t arg) /**< first argument */ { ecma_value_t return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); /* 1. */ ECMA_TRY_CATCH (to_string_val, ecma_op_to_string (arg), return_value); /* 2. */ ECMA_TRY_CATCH (obj_val, ecma_op_to_object (this_arg), return_value); ecma_string_t *property_name_string_p = ecma_get_string_from_value (to_string_val); ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); /* 3. */ ecma_property_t *property_p = ecma_op_object_get_own_property (obj_p, property_name_string_p); if (property_p != NULL) { return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE); } else { return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE); } ECMA_FINALIZE (obj_val); ECMA_FINALIZE (to_string_val); return return_value; } /* ecma_builtin_object_prototype_object_has_own_property */
/** * 'in' opcode handler. * * See also: ECMA-262 v5, 11.8.7 * * @return ecma value * returned value must be freed with ecma_free_value. */ ecma_value_t opfunc_in (ecma_value_t left_value, /**< left value */ ecma_value_t right_value) /**< right value */ { ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); if (!ecma_is_value_object (right_value)) { ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Expected an object in 'in' check.")); } else { ECMA_TRY_CATCH (str_left_value, ecma_op_to_string (left_value), ret_value); ecma_string_t *left_value_prop_name_p = ecma_get_string_from_value (str_left_value); ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value); ret_value = ecma_make_boolean_value (ecma_op_object_has_property (right_value_obj_p, left_value_prop_name_p)); ECMA_FINALIZE (str_left_value); } return ret_value; } /* opfunc_in */
/** * 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_ECMA_VALUE); JERRY_ASSERT (ecma_is_value_number (ecma_get_internal_property_value (prim_value_prop_p))); return ecma_copy_value (ecma_get_internal_property_value (prim_value_prop_p)); } } return ecma_raise_type_error (ECMA_ERR_MSG ("")); } /* ecma_builtin_number_prototype_object_value_of */