• 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_NAPI_NATIVE_ENGINE_IMPL_JERRYSCRIPT_JERRYSCRIPT_NATIVE_ENGINE_H
17 #define FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_JERRYSCRIPT_JERRYSCRIPT_NATIVE_ENGINE_H
18 
19 #include "jerryscript_headers.h"
20 #include "native_engine/native_engine.h"
21 
22 class JerryScriptNativeEngine : public NativeEngine {
23 public:
24     JerryScriptNativeEngine(void* jsEngine);
25     virtual ~JerryScriptNativeEngine();
26 
27     virtual void Loop(LoopMode mode, bool needSync = false) override;
28 
29     virtual NativeValue* GetGlobal() override;
30     virtual NativeValue* CreateNull() override;
31     virtual NativeValue* CreateUndefined() override;
32     virtual NativeValue* CreateBoolean(bool value) override;
33     virtual NativeValue* CreateNumber(int32_t value) override;
34     virtual NativeValue* CreateNumber(uint32_t value) override;
35     virtual NativeValue* CreateNumber(int64_t value) override;
36     virtual NativeValue* CreateNumber(double value) override;
37     virtual NativeValue* CreateBigInt(int64_t value) override;
38     virtual NativeValue* CreateBigInt(uint64_t value) override;
39     virtual NativeValue* CreateString(const char* value, size_t length) override;
40     virtual NativeValue* CreateString16(const char16_t* value, size_t length) override;
41 
42     virtual NativeValue* CreateSymbol(NativeValue* value) override;
43     virtual NativeValue* CreateExternal(void* value, NativeFinalize callback, void* hint) override;
44 
45     virtual NativeValue* CreateObject() override;
46     virtual NativeValue* CreateFunction(const char* name, size_t length, NativeCallback cb, void* value) override;
47     virtual NativeValue* CreateArray(size_t length) override;
48     virtual NativeValue* CreateBuffer(void** value, size_t length) override;
49     virtual NativeValue* CreateBufferCopy(void** value, size_t length, const void* data) override;
50     virtual NativeValue* CreateBufferExternal(void* value, size_t length, NativeFinalize cb, void* hint) override;
51     virtual NativeValue* CreateArrayBuffer(void** value, size_t length) override;
52     virtual NativeValue* CreateArrayBufferExternal(void* value, size_t length, NativeFinalize cb, void* hint) override;
53 
54     virtual NativeValue* CreateTypedArray(NativeTypedArrayType type,
55                                           NativeValue* value,
56                                           size_t length,
57                                           size_t offset) override;
58     virtual NativeValue* CreateDataView(NativeValue* value, size_t length, size_t offset) override;
59     virtual NativeValue* CreatePromise(NativeDeferred** deferred) override;
60     virtual void SetPromiseRejectCallback(NativeReference* rejectCallbackRef,
61                                           NativeReference* checkCallbackRef) override;
62     virtual NativeValue* CreateError(NativeValue* code, NativeValue* Message) override;
63 
64     virtual NativeValue* CallFunction(NativeValue* thisVar,
65                                       NativeValue* function,
66                                       NativeValue* const* argv,
67                                       size_t argc) override;
68     virtual NativeValue* RunScript(NativeValue* script) override;
69     virtual NativeValue* RunBufferScript(std::vector<uint8_t>& buffer) override;
70     virtual NativeValue* RunActor(std::vector<uint8_t>& buffer, const char *descriptor) override;
71     virtual NativeValue* DefineClass(const char* name,
72                                      NativeCallback callback,
73                                      void* data,
74                                      const NativePropertyDescriptor* properties,
75                                      size_t length) override;
76 
77     virtual NativeValue* CreateInstance(NativeValue* constructor,
78                                         NativeValue* const* argv,
79                                         size_t argc) override;
80 
81     virtual NativeReference* CreateReference(NativeValue* value, uint32_t initialRefcount,
82         NativeFinalize callback = nullptr, void* data = nullptr, void* hint = nullptr) override;
83 
84     virtual bool Throw(NativeValue* error) override;
85     virtual bool Throw(NativeErrorType type, const char* code, const char* message) override;
86 
87     virtual void* CreateRuntime() override;
88     virtual NativeValue* Serialize(NativeEngine* context, NativeValue* value, NativeValue* transfer) override;
89     virtual NativeValue* Deserialize(NativeEngine* context, NativeValue* recorder) override;
90     virtual ExceptionInfo* GetExceptionForWorker() const override;
DeleteSerializationData(NativeValue * value)91     virtual void DeleteSerializationData(NativeValue* value) const override {}
92 
93     virtual NativeValue* LoadModule(NativeValue* str, const std::string& fileName) override;
94 
95     static NativeValue* JerryValueToNativeValue(JerryScriptNativeEngine* engine, jerry_value_t value);
96     virtual NativeValue* ValueToNativeValue(JSValueWrapper& value) override;
97     virtual bool TriggerFatalException(NativeValue* error) override;
98     virtual bool AdjustExternalMemory(int64_t ChangeInBytes, int64_t* AdjustedValue) override;
99     virtual NativeValue* CreateDate(double time) override;
100     virtual NativeValue* CreateBigWords(int sign_bit, size_t word_count, const uint64_t* words) override;
101 
102     void StartCpuProfiler(const std::string fileName = "") override {}
StopCpuProfiler()103     void StopCpuProfiler() override {}
104 
ResumeVM()105     void ResumeVM() override {}
SuspendVM()106     bool SuspendVM() override
107     {
108         return false;
109     }
IsSuspended()110     bool IsSuspended() override
111     {
112         return false;
113     }
CheckSafepoint()114     bool CheckSafepoint() override
115     {
116         return false;
117     }
118 
119     void DumpHeapSnapShot(const std::string &path, bool isVmMode = true,
120         DumpFormat dumpFormat = DumpFormat::JSON) override {}
BuildNativeAndJsBackStackTrace()121     std::string BuildNativeAndJsBackStackTrace() override
122     {
123         return nullptr;
124     }
125     bool StartHeapTracking(double timeInterval, bool isVmMode = true) override
126     {
127         return false;
128     }
129     bool StopHeapTracking(const std::string &filePath, DumpFormat dumpFormat = DumpFormat::JSON) override
130     {
131         return false;
132     }
133 
PrintStatisticResult()134     void PrintStatisticResult() override {}
StartRuntimeStat()135     void StartRuntimeStat() override {}
StopRuntimeStat()136     void StopRuntimeStat() override {}
GetArrayBufferSize()137     size_t GetArrayBufferSize() override
138     {
139         return 0;
140     }
GetHeapTotalSize()141     size_t GetHeapTotalSize() override
142     {
143         return 0;
144     }
GetHeapUsedSize()145     size_t GetHeapUsedSize() override
146     {
147         return 0;
148     }
149 
RegisterUncaughtExceptionHandler(UncaughtExceptionCallback callback)150     void RegisterUncaughtExceptionHandler(UncaughtExceptionCallback callback) override {}
HandleUncaughtException()151     void HandleUncaughtException() override {}
152 };
153 
154 #endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_JERRYSCRIPT_JERRYSCRIPT_NATIVE_ENGINE_H_ */
155