diff --git a/jerry-core/ecma/base/ecma-magic-strings.inc.h b/jerry-core/ecma/base/ecma-magic-strings.inc.h index 81f31ac2ce..54918843a9 100644 --- a/jerry-core/ecma/base/ecma-magic-strings.inc.h +++ b/jerry-core/ecma/base/ecma-magic-strings.inc.h @@ -213,3 +213,4 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING__EMPTY, "") * Implementation-defined magic strings */ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_JERRY_UL, "Jerry") +ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING__FUNCTION_TO_STRING, "function(){/* ecmascript */}") diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp index deb43be95c..3cadb23a27 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp @@ -55,7 +55,18 @@ static ecma_completion_value_t ecma_builtin_function_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */ { - ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg); + 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 (ECMA_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 */ /** diff --git a/tests/jerry/function_prototype_tostring.js b/tests/jerry/function_prototype_tostring.js new file mode 100644 index 0000000000..6c6e219c59 --- /dev/null +++ b/tests/jerry/function_prototype_tostring.js @@ -0,0 +1,28 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +assert (Math.cos.toString() === "function(){/* ecmascript */}"); + +function none() { return 1; } +assert (none.toString() === "function(){/* ecmascript */}"); + +function single(b) { return 1; } +assert (single.toString() === "function(){/* ecmascript */}"); + +function multiple(a,b) { return 1; } +assert (multiple.toString() === "function(){/* ecmascript */}"); + +function lots(a,b,c,d,e,f,g,h,i,j,k) { return 1; } +assert (lots.toString() === "function(){/* ecmascript */}");