1 /* 2 * Copyright (c) 2021-2022 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 OHOS_JS_WINDOW_UTILS_H 17 #define OHOS_JS_WINDOW_UTILS_H 18 #include <map> 19 #include "js_runtime_utils.h" 20 #include "native_engine/native_engine.h" 21 #include "native_engine/native_value.h" 22 #include "window.h" 23 24 #ifndef WINDOW_PREVIEW 25 #include "window_manager.h" 26 #else 27 #include "mock/window_manager.h" 28 #endif 29 30 #include "window_option.h" 31 #include "window_visibility_info.h" 32 #include "wm_common.h" 33 namespace OHOS { 34 namespace Rosen { 35 constexpr int32_t RGB_LENGTH = 6; 36 constexpr int32_t RGBA_LENGTH = 8; 37 38 #define CHECK_NAPI_RETCODE(errCode, code, call) \ 39 do { \ 40 napi_status retCode = (call); \ 41 if (retCode != napi_ok) { \ 42 WLOGFE("napi call failed, return %{public}d", static_cast<int32_t>(retCode)); \ 43 errCode = code; \ 44 } \ 45 } while (0) 46 47 #define CHECK_NAPI_ENV_RETURN_IF_NULL(env) \ 48 do { \ 49 if ((env) == nullptr) { \ 50 TLOGE(WmsLogTag::DEFAULT, "env is invalid"); \ 51 return nullptr; \ 52 } \ 53 } while (0) 54 55 #define CHECK_NAPI_CREATE_OBJECT_RETURN_IF_NULL(env, objValue) \ 56 do { \ 57 napi_create_object((env), &(objValue)); \ 58 if ((objValue) == nullptr) { \ 59 TLOGE(WmsLogTag::DEFAULT, "Failed to get object"); \ 60 return nullptr; \ 61 } \ 62 } while (0) 63 64 enum class ApiWindowType : uint32_t { 65 TYPE_BASE, 66 TYPE_APP = TYPE_BASE, 67 TYPE_SYSTEM_ALERT, 68 TYPE_INPUT_METHOD, 69 TYPE_STATUS_BAR, 70 TYPE_PANEL, 71 TYPE_KEYGUARD, 72 TYPE_VOLUME_OVERLAY, 73 TYPE_NAVIGATION_BAR, 74 TYPE_FLOAT, 75 TYPE_WALLPAPER, 76 TYPE_DESKTOP, 77 TYPE_LAUNCHER_RECENT, 78 TYPE_LAUNCHER_DOCK, 79 TYPE_VOICE_INTERACTION, 80 TYPE_POINTER, 81 TYPE_FLOAT_CAMERA, 82 TYPE_DIALOG, 83 TYPE_SCREENSHOT, 84 TYPE_SYSTEM_TOAST, 85 TYPE_DIVIDER, 86 TYPE_GLOBAL_SEARCH, 87 TYPE_HANDWRITE, 88 TYPE_END 89 }; 90 91 enum class LifeCycleEventType : uint32_t { 92 FOREGROUND = 1, 93 ACTIVE, 94 INACTIVE, 95 BACKGROUND, 96 RESUMED, 97 PAUSED, 98 DESTROYED, 99 }; 100 101 const std::map<WindowType, ApiWindowType> NATIVE_JS_TO_WINDOW_TYPE_MAP { 102 { WindowType::WINDOW_TYPE_APP_SUB_WINDOW, ApiWindowType::TYPE_APP }, 103 { WindowType::WINDOW_TYPE_DIALOG, ApiWindowType::TYPE_DIALOG }, 104 { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ApiWindowType::TYPE_SYSTEM_ALERT }, 105 { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, ApiWindowType::TYPE_INPUT_METHOD }, 106 { WindowType::WINDOW_TYPE_STATUS_BAR, ApiWindowType::TYPE_STATUS_BAR }, 107 { WindowType::WINDOW_TYPE_PANEL, ApiWindowType::TYPE_PANEL }, 108 { WindowType::WINDOW_TYPE_KEYGUARD, ApiWindowType::TYPE_KEYGUARD }, 109 { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, ApiWindowType::TYPE_VOLUME_OVERLAY }, 110 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, ApiWindowType::TYPE_NAVIGATION_BAR }, 111 { WindowType::WINDOW_TYPE_FLOAT, ApiWindowType::TYPE_FLOAT }, 112 { WindowType::WINDOW_TYPE_FLOAT_CAMERA, ApiWindowType::TYPE_FLOAT_CAMERA }, 113 { WindowType::WINDOW_TYPE_WALLPAPER, ApiWindowType::TYPE_WALLPAPER }, 114 { WindowType::WINDOW_TYPE_DESKTOP, ApiWindowType::TYPE_DESKTOP }, 115 { WindowType::WINDOW_TYPE_LAUNCHER_RECENT, ApiWindowType::TYPE_LAUNCHER_RECENT }, 116 { WindowType::WINDOW_TYPE_LAUNCHER_DOCK, ApiWindowType::TYPE_LAUNCHER_DOCK }, 117 { WindowType::WINDOW_TYPE_VOICE_INTERACTION, ApiWindowType::TYPE_VOICE_INTERACTION }, 118 { WindowType::WINDOW_TYPE_POINTER, ApiWindowType::TYPE_POINTER }, 119 { WindowType::WINDOW_TYPE_SCREENSHOT, ApiWindowType::TYPE_SCREENSHOT }, 120 { WindowType::WINDOW_TYPE_SYSTEM_TOAST, ApiWindowType::TYPE_SYSTEM_TOAST }, 121 { WindowType::WINDOW_TYPE_DOCK_SLICE, ApiWindowType::TYPE_DIVIDER }, 122 { WindowType::WINDOW_TYPE_GLOBAL_SEARCH, ApiWindowType::TYPE_GLOBAL_SEARCH }, 123 { WindowType::WINDOW_TYPE_HANDWRITE, ApiWindowType::TYPE_HANDWRITE }, 124 }; 125 126 const std::map<ApiWindowType, WindowType> JS_TO_NATIVE_WINDOW_TYPE_MAP { 127 { ApiWindowType::TYPE_APP, WindowType::WINDOW_TYPE_APP_SUB_WINDOW }, 128 { ApiWindowType::TYPE_DIALOG, WindowType::WINDOW_TYPE_DIALOG }, 129 { ApiWindowType::TYPE_SYSTEM_ALERT, WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW }, 130 { ApiWindowType::TYPE_INPUT_METHOD, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT }, 131 { ApiWindowType::TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_STATUS_BAR }, 132 { ApiWindowType::TYPE_PANEL, WindowType::WINDOW_TYPE_PANEL }, 133 { ApiWindowType::TYPE_KEYGUARD, WindowType::WINDOW_TYPE_KEYGUARD }, 134 { ApiWindowType::TYPE_VOLUME_OVERLAY, WindowType::WINDOW_TYPE_VOLUME_OVERLAY }, 135 { ApiWindowType::TYPE_NAVIGATION_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR }, 136 { ApiWindowType::TYPE_FLOAT, WindowType::WINDOW_TYPE_FLOAT }, 137 { ApiWindowType::TYPE_FLOAT_CAMERA, WindowType::WINDOW_TYPE_FLOAT_CAMERA }, 138 { ApiWindowType::TYPE_WALLPAPER, WindowType::WINDOW_TYPE_WALLPAPER }, 139 { ApiWindowType::TYPE_DESKTOP, WindowType::WINDOW_TYPE_DESKTOP }, 140 { ApiWindowType::TYPE_LAUNCHER_RECENT, WindowType::WINDOW_TYPE_LAUNCHER_RECENT }, 141 { ApiWindowType::TYPE_LAUNCHER_DOCK, WindowType::WINDOW_TYPE_LAUNCHER_DOCK }, 142 { ApiWindowType::TYPE_VOICE_INTERACTION, WindowType::WINDOW_TYPE_VOICE_INTERACTION }, 143 { ApiWindowType::TYPE_POINTER, WindowType::WINDOW_TYPE_POINTER }, 144 { ApiWindowType::TYPE_SCREENSHOT, WindowType::WINDOW_TYPE_SCREENSHOT }, 145 { ApiWindowType::TYPE_SYSTEM_TOAST, WindowType::WINDOW_TYPE_SYSTEM_TOAST }, 146 { ApiWindowType::TYPE_DIVIDER, WindowType::WINDOW_TYPE_DOCK_SLICE }, 147 { ApiWindowType::TYPE_GLOBAL_SEARCH, WindowType::WINDOW_TYPE_GLOBAL_SEARCH }, 148 { ApiWindowType::TYPE_HANDWRITE, WindowType::WINDOW_TYPE_HANDWRITE }, 149 }; 150 151 enum class ApiWindowMode : uint32_t { 152 UNDEFINED = 1, 153 FULLSCREEN, 154 PRIMARY, 155 SECONDARY, 156 FLOATING, 157 MODE_END = FLOATING 158 }; 159 160 const std::map<WindowMode, ApiWindowMode> NATIVE_TO_JS_WINDOW_MODE_MAP { 161 { WindowMode::WINDOW_MODE_UNDEFINED, ApiWindowMode::UNDEFINED }, 162 { WindowMode::WINDOW_MODE_FULLSCREEN, ApiWindowMode::FULLSCREEN }, 163 { WindowMode::WINDOW_MODE_SPLIT_PRIMARY, ApiWindowMode::PRIMARY }, 164 { WindowMode::WINDOW_MODE_SPLIT_SECONDARY, ApiWindowMode::SECONDARY }, 165 { WindowMode::WINDOW_MODE_FLOATING, ApiWindowMode::FLOATING }, 166 }; 167 168 const std::map<ApiWindowMode, WindowMode> JS_TO_NATIVE_WINDOW_MODE_MAP { 169 {ApiWindowMode::UNDEFINED, WindowMode::WINDOW_MODE_UNDEFINED }, 170 {ApiWindowMode::FULLSCREEN, WindowMode::WINDOW_MODE_FULLSCREEN }, 171 {ApiWindowMode::PRIMARY, WindowMode::WINDOW_MODE_SPLIT_PRIMARY }, 172 {ApiWindowMode::SECONDARY, WindowMode::WINDOW_MODE_SPLIT_SECONDARY }, 173 {ApiWindowMode::FLOATING, WindowMode::WINDOW_MODE_FLOATING }, 174 }; 175 176 enum class ApiOrientation : uint32_t { 177 BEGIN = 0, 178 UNSPECIFIED = BEGIN, 179 PORTRAIT = 1, 180 LANDSCAPE = 2, 181 PORTRAIT_INVERTED = 3, 182 LANDSCAPE_INVERTED = 4, 183 AUTO_ROTATION = 5, 184 AUTO_ROTATION_PORTRAIT = 6, 185 AUTO_ROTATION_LANDSCAPE = 7, 186 AUTO_ROTATION_RESTRICTED = 8, 187 AUTO_ROTATION_PORTRAIT_RESTRICTED = 9, 188 AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10, 189 LOCKED = 11, 190 AUTO_ROTATION_UNSPECIFIED = 12, 191 USER_ROTATION_PORTRAIT = 13, 192 USER_ROTATION_LANDSCAPE = 14, 193 USER_ROTATION_PORTRAIT_INVERTED = 15, 194 USER_ROTATION_LANDSCAPE_INVERTED = 16, 195 FOLLOW_DESKTOP = 17, 196 END = FOLLOW_DESKTOP, 197 }; 198 199 const std::map<ApiOrientation, Orientation> JS_TO_NATIVE_ORIENTATION_MAP { 200 {ApiOrientation::UNSPECIFIED, Orientation::UNSPECIFIED }, 201 {ApiOrientation::PORTRAIT, Orientation::VERTICAL }, 202 {ApiOrientation::LANDSCAPE, Orientation::HORIZONTAL }, 203 {ApiOrientation::PORTRAIT_INVERTED, Orientation::REVERSE_VERTICAL }, 204 {ApiOrientation::LANDSCAPE_INVERTED, Orientation::REVERSE_HORIZONTAL }, 205 {ApiOrientation::AUTO_ROTATION, Orientation::SENSOR }, 206 {ApiOrientation::AUTO_ROTATION_PORTRAIT, Orientation::SENSOR_VERTICAL }, 207 {ApiOrientation::AUTO_ROTATION_LANDSCAPE, Orientation::SENSOR_HORIZONTAL }, 208 {ApiOrientation::AUTO_ROTATION_RESTRICTED, Orientation::AUTO_ROTATION_RESTRICTED }, 209 {ApiOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED }, 210 {ApiOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED }, 211 {ApiOrientation::LOCKED, Orientation::LOCKED }, 212 {ApiOrientation::AUTO_ROTATION_UNSPECIFIED, Orientation::AUTO_ROTATION_UNSPECIFIED }, 213 {ApiOrientation::USER_ROTATION_PORTRAIT, Orientation::USER_ROTATION_PORTRAIT }, 214 {ApiOrientation::USER_ROTATION_LANDSCAPE, Orientation::USER_ROTATION_LANDSCAPE }, 215 {ApiOrientation::USER_ROTATION_PORTRAIT_INVERTED, Orientation::USER_ROTATION_PORTRAIT_INVERTED }, 216 {ApiOrientation::USER_ROTATION_LANDSCAPE_INVERTED, Orientation::USER_ROTATION_LANDSCAPE_INVERTED }, 217 {ApiOrientation::FOLLOW_DESKTOP, Orientation::FOLLOW_DESKTOP }, 218 }; 219 220 const std::map<Orientation, ApiOrientation> NATIVE_TO_JS_ORIENTATION_MAP { 221 {Orientation::UNSPECIFIED, ApiOrientation::UNSPECIFIED }, 222 {Orientation::VERTICAL, ApiOrientation::PORTRAIT }, 223 {Orientation::HORIZONTAL, ApiOrientation::LANDSCAPE }, 224 {Orientation::REVERSE_VERTICAL, ApiOrientation::PORTRAIT_INVERTED }, 225 {Orientation::REVERSE_HORIZONTAL, ApiOrientation::LANDSCAPE_INVERTED }, 226 {Orientation::SENSOR, ApiOrientation::AUTO_ROTATION }, 227 {Orientation::SENSOR_VERTICAL, ApiOrientation::AUTO_ROTATION_PORTRAIT }, 228 {Orientation::SENSOR_HORIZONTAL, ApiOrientation::AUTO_ROTATION_LANDSCAPE }, 229 {Orientation::AUTO_ROTATION_RESTRICTED, ApiOrientation::AUTO_ROTATION_RESTRICTED }, 230 {Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, ApiOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED }, 231 {Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, ApiOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED }, 232 {Orientation::LOCKED, ApiOrientation::LOCKED }, 233 {Orientation::FOLLOW_RECENT, ApiOrientation::UNSPECIFIED }, 234 {Orientation::AUTO_ROTATION_UNSPECIFIED, ApiOrientation::AUTO_ROTATION_UNSPECIFIED }, 235 {Orientation::USER_ROTATION_PORTRAIT, ApiOrientation::USER_ROTATION_PORTRAIT }, 236 {Orientation::USER_ROTATION_LANDSCAPE, ApiOrientation::USER_ROTATION_LANDSCAPE }, 237 {Orientation::USER_ROTATION_PORTRAIT_INVERTED, ApiOrientation::USER_ROTATION_PORTRAIT_INVERTED }, 238 {Orientation::USER_ROTATION_LANDSCAPE_INVERTED, ApiOrientation::USER_ROTATION_LANDSCAPE_INVERTED }, 239 {Orientation::FOLLOW_DESKTOP, ApiOrientation::FOLLOW_DESKTOP }, 240 }; 241 242 enum class RectChangeReason : uint32_t { 243 UNDEFINED = 0, 244 MAXIMIZE, 245 RECOVER, 246 MOVE, 247 DRAG, 248 DRAG_START, 249 DRAG_END, 250 }; 251 252 const std::map<WindowSizeChangeReason, RectChangeReason> JS_SIZE_CHANGE_REASON { 253 { WindowSizeChangeReason::UNDEFINED, RectChangeReason::UNDEFINED }, 254 { WindowSizeChangeReason::MAXIMIZE, RectChangeReason::MAXIMIZE }, 255 { WindowSizeChangeReason::RECOVER, RectChangeReason::RECOVER }, 256 { WindowSizeChangeReason::ROTATION, RectChangeReason::UNDEFINED }, 257 { WindowSizeChangeReason::DRAG, RectChangeReason::DRAG }, 258 { WindowSizeChangeReason::DRAG_START, RectChangeReason::DRAG_START }, 259 { WindowSizeChangeReason::DRAG_END, RectChangeReason::DRAG_END }, 260 { WindowSizeChangeReason::RESIZE, RectChangeReason::UNDEFINED }, 261 { WindowSizeChangeReason::MOVE, RectChangeReason::MOVE }, 262 { WindowSizeChangeReason::HIDE, RectChangeReason::UNDEFINED }, 263 { WindowSizeChangeReason::TRANSFORM, RectChangeReason::UNDEFINED }, 264 { WindowSizeChangeReason::CUSTOM_ANIMATION_SHOW, RectChangeReason::UNDEFINED }, 265 { WindowSizeChangeReason::FULL_TO_SPLIT, RectChangeReason::UNDEFINED }, 266 { WindowSizeChangeReason::SPLIT_TO_FULL, RectChangeReason::UNDEFINED }, 267 { WindowSizeChangeReason::FULL_TO_FLOATING, RectChangeReason::UNDEFINED }, 268 { WindowSizeChangeReason::FLOATING_TO_FULL, RectChangeReason::UNDEFINED }, 269 { WindowSizeChangeReason::END, RectChangeReason::UNDEFINED }, 270 }; 271 272 napi_value CreateJsWindowInfoArrayObject(napi_env env, const std::vector<sptr<WindowVisibilityInfo>>& infos); 273 napi_value CreateJsWindowInfoObject(napi_env env, const sptr<WindowVisibilityInfo>& window); 274 napi_value GetRectAndConvertToJsValue(napi_env env, const Rect& rect); 275 napi_value CreateJsWindowPropertiesObject(napi_env env, sptr<Window>& window, const Rect& drawableRect); 276 napi_value CreateJsSystemBarPropertiesObject(napi_env env, sptr<Window>& window); 277 void GetSystemBarPropertiesFromJs(sptr<Window>& window, 278 std::map<WindowType, SystemBarProperty>& newProperties, 279 std::map<WindowType, SystemBarPropertyFlag>& newPropertyFlags, 280 std::map<WindowType, SystemBarProperty>& properties, 281 std::map<WindowType, SystemBarPropertyFlag>& propertyFlags); 282 bool SetSystemBarPropertiesFromJs(napi_env env, napi_value jsObject, sptr<Window>& window, 283 std::map<WindowType, SystemBarProperty>& properties, 284 std::map<WindowType, SystemBarPropertyFlag>& propertyFlags); 285 bool SetWindowStatusBarContentColor(napi_env env, napi_value jsObject, 286 std::map<WindowType, SystemBarProperty>& properties, 287 std::map<WindowType, SystemBarPropertyFlag>& propertyFlags); 288 bool SetWindowNavigationBarContentColor(napi_env env, napi_value jsObject, 289 std::map<WindowType, SystemBarProperty>& properties, 290 std::map<WindowType, SystemBarPropertyFlag>& propertyFlags); 291 bool GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProperties, 292 std::map<WindowType, SystemBarPropertyFlag>& systemBarpropertyFlags, 293 napi_env env, napi_callback_info info, sptr<Window>& window); 294 bool ParseAndCheckRect(napi_env env, napi_value jsObject, const Rect& windowRect, Rect& touchableRect); 295 WmErrorCode ParseTouchableAreas(napi_env env, napi_callback_info info, const Rect& windowRect, 296 std::vector<Rect>& touchableAreas); 297 void GetSpecificBarStatus(sptr<Window>& window, const std::string& name, 298 std::map<WindowType, SystemBarProperty>& newSystemBarProperties, 299 std::map<WindowType, SystemBarProperty>& systemBarProperties); 300 bool GetSpecificBarStatus(napi_env env, napi_callback_info info, 301 std::map<WindowType, SystemBarProperty>& systemBarProperties); 302 napi_value CreateJsSystemBarRegionTintArrayObject(napi_env env, 303 const SystemBarRegionTints& tints); 304 napi_value ConvertAvoidAreaToJsValue(napi_env env, const AvoidArea& avoidArea, AvoidAreaType type); 305 bool CheckCallingPermission(std::string permission); 306 napi_value WindowTypeInit(napi_env env); 307 napi_value AvoidAreaTypeInit(napi_env env); 308 napi_value WindowModeInit(napi_env env); 309 napi_value ColorSpaceInit(napi_env env); 310 napi_value OrientationInit(napi_env env); 311 napi_value WindowStageEventTypeInit(napi_env env); 312 napi_value WindowEventTypeInit(napi_env env); 313 napi_value WindowLayoutModeInit(napi_env env); 314 napi_value BlurStyleInit(napi_env env); 315 napi_value MaximizePresentationInit(napi_env env); 316 napi_value WindowErrorCodeInit(napi_env env); 317 napi_value WindowErrorInit(napi_env env); 318 napi_value WindowStatusTypeInit(napi_env env); 319 napi_value RectChangeReasonInit(napi_env env); 320 napi_value GetWindowLimitsAndConvertToJsValue(napi_env env, const WindowLimits& windowLimits); 321 napi_value ConvertTitleButtonAreaToJsValue(napi_env env, const TitleButtonRect& titleButtonRect); 322 bool GetAPI7Ability(napi_env env, AppExecFwk::Ability* &ability); 323 bool GetWindowMaskFromJsValue(napi_env env, napi_value jsObject, std::vector<std::vector<uint32_t>>& windowMask); 324 void ConvertJSSystemBarStyleToSystemBarProperties(napi_env env, napi_value jsObject, 325 std::map<WindowType, SystemBarProperty>& properties, 326 std::map<WindowType, SystemBarPropertyFlag>& propertyFlags); 327 std::unique_ptr<AbilityRuntime::NapiAsyncTask> CreateAsyncTask(napi_env env, napi_value lastParam, 328 std::unique_ptr<AbilityRuntime::NapiAsyncTask::ExecuteCallback>&& execute, 329 std::unique_ptr<AbilityRuntime::NapiAsyncTask::CompleteCallback>&& complete, napi_value* result); 330 template<class T> ParseJsValue(napi_value jsObject,napi_env env,const std::string & name,T & data)331 bool ParseJsValue(napi_value jsObject, napi_env env, const std::string& name, T& data) 332 { 333 napi_value value = nullptr; 334 napi_get_named_property(env, jsObject, name.c_str(), &value); 335 napi_valuetype type = napi_undefined; 336 napi_typeof(env, value, &type); 337 if (type != napi_undefined) { 338 if (!AbilityRuntime::ConvertFromJsValue(env, value, data)) { 339 return false; 340 } 341 } else { 342 return false; 343 } 344 return true; 345 } 346 template<class T> ConvertNativeValueToVector(napi_env env,napi_value nativeArray,std::vector<T> & out)347 inline bool ConvertNativeValueToVector(napi_env env, napi_value nativeArray, std::vector<T>& out) 348 { 349 if (nativeArray == nullptr) { 350 return false; 351 } 352 T value; 353 uint32_t size = 0; 354 napi_get_array_length(env, nativeArray, &size); 355 for (uint32_t i = 0; i < size; i++) { 356 napi_value getElementValue = nullptr; 357 napi_get_element(env, nativeArray, i, &getElementValue); 358 if (!AbilityRuntime::ConvertFromJsValue(env, getElementValue, value)) { 359 return false; 360 } 361 out.emplace_back(value); 362 } 363 return true; 364 } 365 } 366 } 367 #endif