From 1e9111a1931cf7a5623d6c211aa44aed689008fe Mon Sep 17 00:00:00 2001 From: Daniel Kofanov Date: Tue, 12 Nov 2024 03:26:27 +0800 Subject: [PATCH] [es2panda] Refactor options Signed-off-by: Daniel Kofanov --- runtime/js_eval.cpp | 20 ++++++++------------ runtime/js_eval.h | 10 +++++----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/runtime/js_eval.cpp b/runtime/js_eval.cpp index 9104fd27f..c821d7b58 100644 --- a/runtime/js_eval.cpp +++ b/runtime/js_eval.cpp @@ -25,15 +25,13 @@ namespace ark::ecmascript { JSTaggedValue EvalUtils::GetEvaluatedScript(JSThread *thread, const JSHandle &str, - const es2panda::CompilerOptions &options, uint32_t parserStatus) + const es2panda::util::Options &options, uint32_t parserStatus) { auto buffer = str->GetCString(); es2panda::Compiler compiler(es2panda::ScriptExtension::JS); es2panda::SourceFile input("eval.js", std::string_view(buffer.get()), false); - auto fullOptions = es2panda::util::Options {}; - fullOptions.SetCompilerOptions(options); - std::unique_ptr program {compiler.Compile(input, fullOptions, parserStatus)}; + std::unique_ptr program {compiler.Compile(input, options, parserStatus)}; ObjectFactory *objectFactory = thread->GetEcmaVM()->GetFactory(); if (!program) { @@ -81,9 +79,8 @@ JSTaggedValue EvalUtils::DirectEval(JSThread *thread, uint32_t parserStatus, JST JSHandle argStr = JSTaggedValue::ToString(thread, arg0Handle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, argStr.GetTaggedValue()); - es2panda::CompilerOptions options; - options.isEval = true; - options.isDirectEval = true; + es2panda::util::Options options(""); + options.SetEvalMode("direct"); JSHandle func(thread, GetEvaluatedScript(thread, argStr, options, parserStatus)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); @@ -110,8 +107,8 @@ JSTaggedValue EvalUtils::Eval(JSThread *thread, const JSHandle &a JSHandle argStr = JSTaggedValue::ToString(thread, arg0); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, argStr.GetTaggedValue()); - es2panda::CompilerOptions options; - options.isEval = true; + es2panda::util::Options options(""); + options.SetEvalMode("default"); JSHandle func(thread, GetEvaluatedScript(thread, argStr, options)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); @@ -194,9 +191,8 @@ JSTaggedValue EvalUtils::CreateDynamicFunction(EcmaRuntimeCallInfo *argv, Dynami JSHandle rightBraceRightParen = factory->NewFromCanBeCompressString("})"); resultStr = factory->ConcatFromString(resultStr, rightBraceRightParen); - es2panda::CompilerOptions options; - options.isEval = true; - options.isFunctionEval = true; + es2panda::util::Options options(""); + options.SetEvalMode("function"); JSHandle func(thread, GetEvaluatedScript(thread, resultStr, options)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); diff --git a/runtime/js_eval.h b/runtime/js_eval.h index fba454738..8702c4e0b 100644 --- a/runtime/js_eval.h +++ b/runtime/js_eval.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * 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 @@ -19,9 +19,9 @@ #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/js_tagged_value-inl.h" -namespace ark::es2panda { -struct CompilerOptions; -} // namespace ark::es2panda +namespace ark::es2panda::util { +class Options; +} // namespace ark::es2panda::util namespace ark::ecmascript { class EvalUtils { @@ -35,7 +35,7 @@ public: private: static JSTaggedValue GetEvaluatedScript(JSThread *thread, const JSHandle &str, - const es2panda::CompilerOptions &options, uint32_t parserStatus = 0); + const es2panda::util::Options &options, uint32_t parserStatus = 0); }; } // namespace ark::ecmascript -- Gitee