diff --git a/runtime/js_eval.cpp b/runtime/js_eval.cpp index c821d7b58f37330d42572a652bb597229223132f..b86df5de4f53af599dbf68201c01da264c09d2cf 100644 --- a/runtime/js_eval.cpp +++ b/runtime/js_eval.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -22,16 +22,17 @@ #include "es2panda.h" #include "assembler/assembly-emitter.h" #include "util/options.h" +#include "util/diagnosticEngine.h" namespace ark::ecmascript { JSTaggedValue EvalUtils::GetEvaluatedScript(JSThread *thread, const JSHandle &str, - const es2panda::util::Options &options, uint32_t parserStatus) + const es2panda::util::Options &options, + es2panda::util::DiagnosticEngine &diagnosticEngine, uint32_t parserStatus) { auto buffer = str->GetCString(); - es2panda::Compiler compiler(es2panda::ScriptExtension::JS); es2panda::SourceFile input("eval.js", std::string_view(buffer.get()), false); - std::unique_ptr program {compiler.Compile(input, options, parserStatus)}; + std::unique_ptr program {compiler.Compile(input, options, diagnosticEngine, parserStatus)}; ObjectFactory *objectFactory = thread->GetEcmaVM()->GetFactory(); if (!program) { @@ -79,10 +80,11 @@ JSTaggedValue EvalUtils::DirectEval(JSThread *thread, uint32_t parserStatus, JST JSHandle argStr = JSTaggedValue::ToString(thread, arg0Handle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, argStr.GetTaggedValue()); - es2panda::util::Options options(""); + auto diagnosticEngine = es2panda::util::DiagnosticEngine(); + es2panda::util::Options options("", diagnosticEngine); options.SetEvalMode("direct"); - JSHandle func(thread, GetEvaluatedScript(thread, argStr, options, parserStatus)); + JSHandle func(thread, GetEvaluatedScript(thread, argStr, options, diagnosticEngine, parserStatus)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); uint32_t index = 0; @@ -107,9 +109,10 @@ JSTaggedValue EvalUtils::Eval(JSThread *thread, const JSHandle &a JSHandle argStr = JSTaggedValue::ToString(thread, arg0); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, argStr.GetTaggedValue()); - es2panda::util::Options options(""); + auto diagnosticEngine = es2panda::util::DiagnosticEngine(); + es2panda::util::Options options("", diagnosticEngine); options.SetEvalMode("default"); - JSHandle func(thread, GetEvaluatedScript(thread, argStr, options)); + JSHandle func(thread, GetEvaluatedScript(thread, argStr, options, diagnosticEngine)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); JSHandle thisValue(thread, thread->GetGlobalObject()); @@ -191,9 +194,10 @@ JSTaggedValue EvalUtils::CreateDynamicFunction(EcmaRuntimeCallInfo *argv, Dynami JSHandle rightBraceRightParen = factory->NewFromCanBeCompressString("})"); resultStr = factory->ConcatFromString(resultStr, rightBraceRightParen); - es2panda::util::Options options(""); + auto diagnosticEngine = es2panda::util::DiagnosticEngine(); + es2panda::util::Options options("", diagnosticEngine); options.SetEvalMode("function"); - JSHandle func(thread, GetEvaluatedScript(thread, resultStr, options)); + JSHandle func(thread, GetEvaluatedScript(thread, resultStr, options, diagnosticEngine)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func.GetTaggedValue()); JSHandle thisValue(thread, thread->GetGlobalObject()); diff --git a/runtime/js_eval.h b/runtime/js_eval.h index 8702c4e0b7316573866e990442778b4c1e90404a..ca63fee8c58e809a3be70d17949c0b9e742e30e7 100644 --- a/runtime/js_eval.h +++ b/runtime/js_eval.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -21,6 +21,7 @@ namespace ark::es2panda::util { class Options; +class DiagnosticEngine; } // namespace ark::es2panda::util namespace ark::ecmascript { @@ -35,7 +36,9 @@ public: private: static JSTaggedValue GetEvaluatedScript(JSThread *thread, const JSHandle &str, - const es2panda::util::Options &options, uint32_t parserStatus = 0); + const es2panda::util::Options &options, + es2panda::util::DiagnosticEngine &diagnosticEngine, + uint32_t parserStatus = 0); }; } // namespace ark::ecmascript