From 45cfc4c464bc6ff3ab14b6866090c7730408d637 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Fri, 24 Dec 2021 11:24:21 +0800 Subject: [PATCH] modify for get async function name Signed-off-by: wengchangcheng --- ecmascript/interpreter/slow_runtime_stub.cpp | 2 +- ecmascript/js_function.cpp | 2 +- ecmascript/js_function.h | 6 ++ ecmascript/js_function_kind.h | 58 ++++++++------------ test/moduletest/async/async.js | 7 +++ test/moduletest/async/expect_output.txt | 3 + 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/ecmascript/interpreter/slow_runtime_stub.cpp b/ecmascript/interpreter/slow_runtime_stub.cpp index a20171f6..6c96a43e 100644 --- a/ecmascript/interpreter/slow_runtime_stub.cpp +++ b/ecmascript/interpreter/slow_runtime_stub.cpp @@ -1589,7 +1589,7 @@ JSTaggedValue SlowRuntimeStub::DefineNCFuncDyn(JSThread *thread, JSFunction *fun JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); - JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::NORMAL_FUNCTION); + JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::ARROW_FUNCTION); ASSERT_NO_ABRUPT_COMPLETION(thread); return jsFunc.GetTaggedValue(); } diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index f631a61e..e82b4291 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -67,7 +67,7 @@ void JSFunction::InitializeJSFunction(JSThread *thread, const JSHandleGetHandledPrototypeString(), desc); ASSERT(success); } - } else if (kind == FunctionKind::NORMAL_FUNCTION) { + } else if (HasAccessor(kind)) { JSHandle accessor = globalConst->GetHandledFunctionNameAccessor(); func->SetPropertyInlinedProps(thread, NAME_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); } diff --git a/ecmascript/js_function.h b/ecmascript/js_function.h index 6a4bd156..d7b5127c 100644 --- a/ecmascript/js_function.h +++ b/ecmascript/js_function.h @@ -253,6 +253,12 @@ public: { return kind >= BUILTIN_CONSTRUCTOR && kind <= GENERATOR_FUNCTION; } + + inline static bool HasAccessor(FunctionKind kind) + { + return kind >= NORMAL_FUNCTION && kind <= ASYNC_FUNCTION; + } + /* -------------- Common API End, Don't change those interface!!! ----------------- */ static void InitializeJSFunction(JSThread *thread, const JSHandle &func, FunctionKind kind = FunctionKind::NORMAL_FUNCTION, bool strict = true); diff --git a/ecmascript/js_function_kind.h b/ecmascript/js_function_kind.h index 50e95fff..5df2362e 100644 --- a/ecmascript/js_function_kind.h +++ b/ecmascript/js_function_kind.h @@ -20,50 +20,40 @@ namespace panda::ecmascript { enum FunctionKind : uint8_t { - // BEGIN constructable functions NORMAL_FUNCTION = 0, - BUILTIN_PROXY_CONSTRUCTOR, - BUILTIN_CONSTRUCTOR, - // BEGIN class constructors - // BEGIN base constructors - BASE_CONSTRUCTOR, - // BEGIN default constructors - DEFAULT_BASE_CONSTRUCTOR, - CLASS_CONSTRUCTOR, - // END base constructors - // BEGIN derived constructors - DEFAULT_DERIVED_CONSTRUCTOR, - // END default constructors - DERIVED_CONSTRUCTOR, - // END derived constructors - // END class constructors - // END constructable functions. - GENERATOR_FUNCTION, - // END generators - - // BEGIN accessors - GETTER_FUNCTION, - SETTER_FUNCTION, - // END accessors // BEGIN arrow functions ARROW_FUNCTION, // BEGIN async functions ASYNC_ARROW_FUNCTION, // END arrow functions ASYNC_FUNCTION, - // BEGIN concise methods 1 - ASYNC_CONCISE_METHOD, - // BEGIN generators - ASYNC_CONCISE_GENERATOR_METHOD, - // END concise methods 1 - ASYNC_GENERATOR_FUNCTION, // END async functions - CONSIZE_METHDOD, + // BEGIN constructable functions + BUILTIN_PROXY_CONSTRUCTOR, + BUILTIN_CONSTRUCTOR, + // BEGIN base constructors + BASE_CONSTRUCTOR, + // BEGIN default constructors + DEFAULT_BASE_CONSTRUCTOR, + // END base constructors + // BEGIN class constructors + CLASS_CONSTRUCTOR, + // BEGIN derived constructors + DEFAULT_DERIVED_CONSTRUCTOR, + // END default constructors + DERIVED_CONSTRUCTOR, + // END derived constructors + // END class constructors + GENERATOR_FUNCTION, + // END generators + // END constructable functions. - CLASS_MEMBERS_INITIALIZER_FUNCTION, - // END concise methods 2 + // BEGIN accessors + GETTER_FUNCTION, + SETTER_FUNCTION, + // END accessors - LAST_FUNCTION_KIND = CLASS_MEMBERS_INITIALIZER_FUNCTION, + LAST_FUNCTION_KIND, }; enum FunctionMode : uint8_t { diff --git a/test/moduletest/async/async.js b/test/moduletest/async/async.js index afa51d7e..d6227dbd 100644 --- a/test/moduletest/async/async.js +++ b/test/moduletest/async/async.js @@ -19,6 +19,13 @@ async function foo() { } var s = foo() +var arrow = () => {} +var async_arrow = async () => {} + +print(foo.name) +print(arrow.name) +print(async_arrow.name) + s.then(msg=>{ print(msg) }) diff --git a/test/moduletest/async/expect_output.txt b/test/moduletest/async/expect_output.txt index 3f92fc88..d7536b0c 100644 --- a/test/moduletest/async/expect_output.txt +++ b/test/moduletest/async/expect_output.txt @@ -11,6 +11,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +foo +arrow +async_arrow main over 1 undefined