From 772ab277ead1db3aa4c2537d0390dbcf641aa590 Mon Sep 17 00:00:00 2001 From: legendecas Date: Tue, 26 Mar 2019 23:14:04 +0800 Subject: [PATCH] Fixes assertion on calling String builtin with symbol (#2803) JerryScript-DCO-1.0-Signed-off-by: legendecas legendecas@gmail.com --- .../ecma/builtin-objects/ecma-builtin-string.c | 15 +++++++++++++++ tests/jerry/es2015/symbol-prototype-tostring.js | 2 ++ 2 files changed, 17 insertions(+) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string.c index af9910702..b733b9308 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string.c @@ -22,6 +22,9 @@ #include "ecma-helpers.h" #include "ecma-objects.h" #include "ecma-string-object.h" +#ifndef CONFIG_DISABLE_ES2015_SYMBOL_BUILTIN +#include "ecma-symbol-object.h" +#endif /* !CONFIG_DISABLE_ES2015_SYMBOL_BUILTIN */ #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -109,6 +112,9 @@ ecma_builtin_string_object_from_char_code (ecma_value_t this_arg, /**< 'this' ar /** * Handle calling [[Call]] of built-in String object * + * See also: + * ECMA-262 v6, 21.1.1.1 + * * @return ecma value */ ecma_value_t @@ -119,10 +125,19 @@ ecma_builtin_string_dispatch_call (const ecma_value_t *arguments_list_p, /**< ar ecma_value_t ret_value = ECMA_VALUE_EMPTY; + /* 1. */ if (arguments_list_len == 0) { ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); } +#ifndef CONFIG_DISABLE_ES2015_SYMBOL_BUILTIN + /* 2.a */ + else if (ecma_is_value_symbol (arguments_list_p[0])) + { + ret_value = ecma_get_symbol_descriptive_string (arguments_list_p[0]); + } +#endif /* !CONFIG_DISABLE_ES2015_SYMBOL_BUILTIN */ + /* 2.b */ else { ret_value = ecma_op_to_string (arguments_list_p[0]); diff --git a/tests/jerry/es2015/symbol-prototype-tostring.js b/tests/jerry/es2015/symbol-prototype-tostring.js index bea3cc259..7c16c07ad 100644 --- a/tests/jerry/es2015/symbol-prototype-tostring.js +++ b/tests/jerry/es2015/symbol-prototype-tostring.js @@ -29,6 +29,8 @@ try { var foo = Symbol ('foo'); assert (foo.toString () === "Symbol(foo)"); +assert (String (foo) === "Symbol(foo)"); var fooObj = Object (foo); assert (fooObj.toString () === "Symbol(foo)"); +assert (String (fooObj) === "Symbol(foo)");