mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
Description:Optimize source map operator.
Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo <zhangyafei12@huawei.com> Change-Id: I98f7b4d8369e167eacca3197d95e11603760b749
This commit is contained in:
parent
c85fa54e22
commit
4e057d7ed3
@ -50,7 +50,6 @@
|
||||
#include "extractor.h"
|
||||
#include "systemcapability.h"
|
||||
#include "source_map.h"
|
||||
#include "source_map_operator.h"
|
||||
#include "ace_forward_compatibility.h"
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
@ -548,8 +547,7 @@ bool JsRuntime::Initialize(const Options& options)
|
||||
}
|
||||
|
||||
if (!options.preload) {
|
||||
auto operatorObj = std::make_shared<JsEnv::SourceMapOperator>(options.hapPath, isModular);
|
||||
InitSourceMap(operatorObj);
|
||||
InitSourceMap(options.hapPath, isModular);
|
||||
|
||||
if (options.isUnique) {
|
||||
HILOG_INFO("Not supported TimerModule when form render");
|
||||
@ -673,11 +671,11 @@ void JsRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths, const bool& isSy
|
||||
}
|
||||
}
|
||||
|
||||
void JsRuntime::InitSourceMap(const std::shared_ptr<JsEnv::SourceMapOperator> operatorObj)
|
||||
void JsRuntime::InitSourceMap(const std::string& hapPath, bool isModular)
|
||||
{
|
||||
CHECK_POINTER(jsEnv_);
|
||||
jsEnv_->InitSourceMap(operatorObj);
|
||||
JsEnv::SourceMap::RegisterReadSourceMapCallback(JsRuntime::ReadSourceMapData);
|
||||
jsEnv_->InitSourceMap(hapPath, isModular);
|
||||
}
|
||||
|
||||
void JsRuntime::Deinitialize()
|
||||
|
@ -40,7 +40,6 @@ class Extractor;
|
||||
|
||||
namespace JsEnv {
|
||||
class JsEnvironment;
|
||||
class SourceMapOperator;
|
||||
struct UncaughtExceptionInfo;
|
||||
} // namespace JsEnv
|
||||
|
||||
@ -110,7 +109,7 @@ public:
|
||||
void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override;
|
||||
static bool GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer);
|
||||
|
||||
void InitSourceMap(const std::shared_ptr<JsEnv::SourceMapOperator> operatorImpl);
|
||||
void InitSourceMap(const std::string& hapPath, bool isModular);
|
||||
void FreeNativeReference(std::unique_ptr<NativeReference> reference);
|
||||
void FreeNativeReference(std::shared_ptr<NativeReference>&& reference);
|
||||
void StartProfiler(const std::string &perfCmd) override;
|
||||
|
@ -113,15 +113,22 @@ void JsEnvironment::RemoveTask(const std::string& name)
|
||||
}
|
||||
}
|
||||
|
||||
void JsEnvironment::InitSourceMap(const std::shared_ptr<JsEnv::SourceMapOperator> operatorObj)
|
||||
void JsEnvironment::InitSourceMap(const std::string& hapPath, bool isModular)
|
||||
{
|
||||
sourceMapOperator_ = operatorObj;
|
||||
if (engine_ == nullptr) {
|
||||
JSENV_LOG_E("Invalid Native Engine.");
|
||||
return;
|
||||
}
|
||||
auto translateBySourceMapFunc = [&](const std::string& rawStack) {
|
||||
return sourceMapOperator_->TranslateBySourceMap(rawStack);
|
||||
|
||||
sourceMap_ = std::make_shared<SourceMap>();
|
||||
sourceMap_->Init(hapPath, isModular);
|
||||
auto translateBySourceMapFunc = [weak = weak_from_this()](const std::string& rawStack) {
|
||||
std::string retStr;
|
||||
auto jsEnv = weak.lock();
|
||||
if (jsEnv != nullptr && jsEnv->sourceMap_ != nullptr) {
|
||||
retStr = jsEnv->sourceMap_->TranslateBySourceMap(rawStack);
|
||||
}
|
||||
return retStr;
|
||||
};
|
||||
engine_->RegisterTranslateBySourceMap(translateBySourceMapFunc);
|
||||
}
|
||||
@ -134,7 +141,7 @@ void JsEnvironment::RegisterUncaughtExceptionHandler(JsEnv::UncaughtExceptionInf
|
||||
}
|
||||
|
||||
engine_->RegisterUncaughtExceptionHandler(UncaughtExceptionCallback(uncaughtExceptionInfo.uncaughtTask,
|
||||
sourceMapOperator_));
|
||||
sourceMap_));
|
||||
}
|
||||
|
||||
bool JsEnvironment::LoadScript(const std::string& path, std::vector<uint8_t>* buffer, bool isBundle)
|
||||
|
@ -83,7 +83,7 @@ uint32_t Base64CharToInt(char charCode)
|
||||
return DIGIT_NUM;
|
||||
};
|
||||
|
||||
void SourceMap::Init(bool isModular, const std::string& hapPath)
|
||||
void SourceMap::Init(const std::string& hapPath, bool isModular)
|
||||
{
|
||||
isModular_ = isModular;
|
||||
hapPath_ = hapPath;
|
||||
|
@ -74,11 +74,11 @@ void UncaughtExceptionCallback::operator()(NativeValue* value)
|
||||
error = fuc->GetSourceCodeInfo(errorPos);
|
||||
}
|
||||
}
|
||||
if (sourceMapOperator_ == nullptr) {
|
||||
JSENV_LOG_E("sourceMapOperator_ is empty");
|
||||
return;
|
||||
|
||||
if (sourceMap_ != nullptr) {
|
||||
summary += error + "Stacktrace:\n" + sourceMap_->TranslateBySourceMap(errorStack);
|
||||
}
|
||||
summary += error + "Stacktrace:\n" + sourceMapOperator_->TranslateBySourceMap(errorStack);
|
||||
|
||||
if (uncaughtTask_) {
|
||||
uncaughtTask_(summary, errorObj);
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "js_environment_impl.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "source_map_operator.h"
|
||||
#include "uncaught_exception_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -54,7 +53,7 @@ public:
|
||||
|
||||
void InitWorkerModule(std::shared_ptr<WorkerInfo> workerInfo);
|
||||
|
||||
void InitSourceMap(const std::shared_ptr<JsEnv::SourceMapOperator> operatorObj);
|
||||
void InitSourceMap(const std::string& hapPath, bool isModular);
|
||||
|
||||
void InitSyscapModule();
|
||||
|
||||
@ -89,7 +88,7 @@ private:
|
||||
std::unique_ptr<JsEnvironmentImpl> impl_ = nullptr;
|
||||
NativeEngine* engine_ = nullptr;
|
||||
panda::ecmascript::EcmaVM* vm_ = nullptr;
|
||||
std::shared_ptr<SourceMapOperator> sourceMapOperator_ = nullptr;
|
||||
std::shared_ptr<SourceMap> sourceMap_ = nullptr;
|
||||
};
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
SourceMap() = default;
|
||||
~SourceMap() = default;
|
||||
|
||||
void Init(bool isModular, const std::string& hapPath);
|
||||
void Init(const std::string& hapPath, bool isModular);
|
||||
std::string TranslateBySourceMap(const std::string& stackStr);
|
||||
|
||||
static std::string GetOriginalNames(std::shared_ptr<SourceMapData> targetMapData,
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_JS_ENVIRONMENT_SOURCE_MAP_OPERATOR_H
|
||||
#define OHOS_ABILITY_JS_ENVIRONMENT_SOURCE_MAP_OPERATOR_H
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "js_env_logger.h"
|
||||
#include "source_map.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace JsEnv {
|
||||
class SourceMapOperator {
|
||||
public:
|
||||
SourceMapOperator(const std::string hapPath, bool isModular)
|
||||
: hapPath_(hapPath), isModular_(isModular) {}
|
||||
|
||||
~SourceMapOperator() = default;
|
||||
|
||||
std::string TranslateBySourceMap(const std::string& stackStr)
|
||||
{
|
||||
SourceMap sourceMapObj;
|
||||
sourceMapObj.Init(isModular_, hapPath_);
|
||||
return sourceMapObj.TranslateBySourceMap(stackStr);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string hapPath_;
|
||||
bool isModular_ = false;
|
||||
};
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_JS_ENVIRONMENT_SOURCE_MAP_OPERATOR_H
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "source_map.h"
|
||||
#include "source_map_operator.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace JsEnv {
|
||||
@ -45,8 +44,8 @@ class UncaughtExceptionCallback final {
|
||||
public:
|
||||
UncaughtExceptionCallback(
|
||||
std::function<void(const std::string summary, const JsEnv::ErrorObject errorObj)> uncaughtTask,
|
||||
std::shared_ptr<SourceMapOperator> sourceMapOperator)
|
||||
: uncaughtTask_(uncaughtTask), sourceMapOperator_(sourceMapOperator)
|
||||
std::shared_ptr<SourceMap> sourceMap)
|
||||
: uncaughtTask_(uncaughtTask), sourceMap_(sourceMap)
|
||||
{}
|
||||
|
||||
~UncaughtExceptionCallback() = default;
|
||||
@ -57,7 +56,7 @@ public:
|
||||
|
||||
private:
|
||||
std::function<void(std::string summary, const JsEnv::ErrorObject errorObj)> uncaughtTask_;
|
||||
std::shared_ptr<SourceMapOperator> sourceMapOperator_ = nullptr;
|
||||
std::shared_ptr<SourceMap> sourceMap_ = nullptr;
|
||||
};
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
|
@ -387,7 +387,7 @@ HWTEST_F(SourceMapTest, JsEnv_SourceMap_1500, Function | MediumTest | Level1)
|
||||
std::string stackStr = "at anonymous (entry/src/main/ets/pages/Index.ets:111:13)";
|
||||
|
||||
auto mapObj = std::make_shared<SourceMap>();
|
||||
mapObj->Init(true, "");
|
||||
mapObj->Init("", true);
|
||||
mapObj->SplitSourceMap(sourceMaps);
|
||||
std::string stack = mapObj->TranslateBySourceMap(stackStr);
|
||||
EXPECT_STREQ(stack.c_str(), "at anonymous (entry/src/main/ets/pages/Index.ets:85:9)\n");
|
||||
@ -408,7 +408,7 @@ HWTEST_F(SourceMapTest, JsEnv_SourceMap_1600, Function | MediumTest | Level1)
|
||||
std::string stackStr = "at anonymous (entry/src/main/ets/pages/Index.ets:111:13)";
|
||||
|
||||
auto mapObj = std::make_shared<SourceMap>();
|
||||
mapObj->Init(true, sourceMaps);
|
||||
mapObj->Init(sourceMaps, true);
|
||||
std::string stack = mapObj->TranslateBySourceMap(stackStr);
|
||||
size_t pos = stack.find(stackStr);
|
||||
EXPECT_NE(pos, std::string::npos);
|
||||
@ -439,7 +439,7 @@ HWTEST_F(SourceMapTest, JsEnv_SourceMap_1700, Function | MediumTest | Level1)
|
||||
std::string stackStr = "at anonymous (entry/src/main/ets/pages/Index.ets:111:13)";
|
||||
|
||||
auto mapObj = std::make_shared<SourceMap>();
|
||||
mapObj->Init(true, sourceMaps);
|
||||
mapObj->Init(sourceMaps, true);
|
||||
std::string stack = mapObj->TranslateBySourceMap(stackStr);
|
||||
size_t pos = stack.find(stackStr);
|
||||
EXPECT_NE(pos, std::string::npos);
|
||||
@ -470,7 +470,7 @@ HWTEST_F(SourceMapTest, JsEnv_SourceMap_1800, Function | MediumTest | Level1)
|
||||
std::string stackStr = "123/Index.ets:111:13";
|
||||
|
||||
auto mapObj = std::make_shared<SourceMap>();
|
||||
mapObj->Init(true, sourceMaps);
|
||||
mapObj->Init(sourceMaps, true);
|
||||
std::string stack = mapObj->TranslateBySourceMap(stackStr);
|
||||
size_t pos = stack.find(stackStr);
|
||||
EXPECT_NE(pos, std::string::npos);
|
||||
|
Loading…
Reference in New Issue
Block a user