• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_V8_V8_UTILS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_V8_V8_UTILS_H
18 
19 #include "third_party/v8/include/v8.h"
20 
21 #include "frameworks/bridge/js_frontend/engine/v8/v8_engine.h"
22 
23 namespace OHOS::Ace::Framework {
24 
25 bool GetParamsWithCallbackId(const v8::Local<v8::Context>& context, const v8::Local<v8::Array>& args,
26     std::map<std::string, std::string>& params, std::string& callbackId);
27 
28 bool GetParams(const v8::Local<v8::Context>& context, const v8::Local<v8::Value>& args,
29     std::map<std::string, std::string>& params);
30 
31 void ExtractEachInfo(const std::string& tempStack, std::vector<std::string>& res);
32 
33 void GetPosInfo(const std::string& temp, int32_t start, std::string& line, std::string& column);
34 
35 std::string GetSourceInfo(const std::string& line, const std::string& column, const RefPtr<RevSourceMap>& pageMap,
36     const RefPtr<RevSourceMap>& appMap, bool isAppPage);
37 
38 enum class JsErrorType {
39     JS_CRASH = 0,
40     COMPILE_ERROR,
41     RUNTIME_ERROR,
42     FIRE_EVENT_ERROR,
43     DESTROY_APP_ERROR,
44     DESTROY_PAGE_ERROR,
45     LOAD_JS_BUNDLE_ERROR,
46     ANIMATION_START_ERROR,
47     ANIMATION_FINISH_ERROR,
48     ANIMATION_CANCEL_ERROR,
49     ANIMATION_REPEAT_ERROR,
50     ANIMATION_FRAME_ERROR,
51     STRINGIFY_ERROR,
52     CALLBACK_PROCESS_ERROR,
53 };
54 
55 class V8Utils {
56 public:
57     static void JsStdDumpErrorAce(v8::Isolate* isolate, v8::TryCatch* tryCatch,
58         JsErrorType errorType = JsErrorType::JS_CRASH, int32_t instanceId = 0, const RefPtr<JsAcePage>& page = nullptr);
59     static std::string JsStdDumpSourceFile(const std::string& tempStack, const RefPtr<RevSourceMap>& pageMap,
60         const RefPtr<RevSourceMap>& appMap);
61 };
62 
63 } // namespace OHOS::Ace::Framework
64 
65 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_V8_V8_UTILS_H
66