Skip to content

Commit 7c2878a

Browse files
committed
Implement Function.prototype.toString.
JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent 36c80f2 commit 7c2878a

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

jerry-core/ecma/base/ecma-magic-strings.inc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,4 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING__EMPTY, "")
213213
* Implementation-defined magic strings
214214
*/
215215
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_JERRY_UL, "Jerry")
216+
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING__FUNCTION_TO_STRING, "function(){/* ecmascript */}")

jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,18 @@
5353
static ecma_completion_value_t
5454
ecma_builtin_function_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
5555
{
56-
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
56+
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
57+
58+
if (!ecma_op_is_callable (this_arg))
59+
{
60+
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
61+
}
62+
else
63+
{
64+
ecma_string_t *function_to_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING__FUNCTION_TO_STRING);
65+
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (function_to_string_p));
66+
}
67+
return ret_value;
5768
} /* ecma_builtin_function_prototype_object_to_string */
5869

5970
/**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 Samsung Electronics Co., Ltd.
2+
// Copyright 2015 University of Szeged
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
assert (Math.cos.toString() === "function(){/* ecmascript */}");
17+
18+
function none() { return 1; }
19+
assert (none.toString() === "function(){/* ecmascript */}");
20+
21+
function single(b) { return 1; }
22+
assert (single.toString() === "function(){/* ecmascript */}");
23+
24+
function multiple(a,b) { return 1; }
25+
assert (multiple.toString() === "function(){/* ecmascript */}");
26+
27+
function lots(a,b,c,d,e,f,g,h,i,j,k) { return 1; }
28+
assert (lots.toString() === "function(){/* ecmascript */}");

0 commit comments

Comments
 (0)