add caniuse js api for small system.

Signed-off-by: yudechen <chenyude@huawei.com>
Change-Id: I89e93285a51e8bdbc8ae396f94ae0fa520bdd37a
This commit is contained in:
yudechen
2022-04-07 15:46:12 +08:00
parent 1c7a45f49c
commit a84f4475de
11 changed files with 208 additions and 8 deletions
+3 -1
View File
@@ -1,4 +1,4 @@
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Copyright (c) 2020-2022 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
@@ -78,6 +78,7 @@ ace_lite_include_dirs += [
"//third_party/freetype/include",
"//base/global/resmgr_lite/interfaces/innerkits/include",
"//base/global/i18n_lite/interfaces/kits/i18n/include",
"//base/startup/init_lite/interfaces/innerkits/include",
]
ace_lite_include_dirs_simulator = [
@@ -176,6 +177,7 @@ ace_lite_sources = [
"$ACE_LITE_PATH/src/core/modules/presets/profiler_module.cpp",
"$ACE_LITE_PATH/src/core/modules/presets/render_module.cpp",
"$ACE_LITE_PATH/src/core/modules/presets/require_module.cpp",
"$ACE_LITE_PATH/src/core/modules/presets/syscap_module.cpp",
"$ACE_LITE_PATH/src/core/modules/presets/timer_module.cpp",
"$ACE_LITE_PATH/src/core/modules/presets/version_module.cpp",
"$ACE_LITE_PATH/src/core/modules/router_module.cpp",
+2 -1
View File
@@ -1,4 +1,4 @@
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Copyright (c) 2020-2022 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
@@ -73,6 +73,7 @@ lite_library("ace_lite") {
]
} else {
public_deps += [
"//base/startup/init_lite/interfaces/innerkits/syscap:syscap",
"//build/lite/config/component/cJSON:cjson_shared",
"//foundation/graphic/surface:lite_surface",
"//foundation/multimedia/camera_lite/frameworks:camera_lite",
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Copyright (c) 2020-2022 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
@@ -31,6 +31,7 @@
#include "presets/profiler_module.h"
#include "presets/render_module.h"
#include "presets/require_module.h"
#include "presets/syscap_module.h"
#include "presets/timer_module.h"
#include "presets/version_module.h"
#include "product_adapter.h"
@@ -57,6 +58,7 @@ void JsAppEnvironment::LoadAceBuiltInModules() const
FeaAbilityModule::Load();
JsTestModule::Load();
TimersModule::Load();
SyscapsModule::Load();
PerformaceProfilerModule::Load();
AceVersionModule::Load();
IntlControlModule::Load();
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2022-2022 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.
*/
#include "acelite_config.h"
#if (FEATURE_SYSCAP_MODULE == 1)
#include <string.h>
#include "syscap_module.h"
#include "ace_mem_base.h"
#include "systemcapability.h"
namespace OHOS {
namespace ACELite {
const uint16_t SYSCAP_BUFFER_SIZE = 128;
void SyscapModule::Init()
{
const char * const canIUse = "canIUse";
CreateNamedFunction(canIUse, CanIUse);
}
jerry_value_t SyscapModule::CheckSyscap(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t *args,
const jerry_length_t argsNum,
bool repeated)
{
(void)func; /* unused */
(void)context; /* unused */
(void)repeated; /* unused */
const uint8_t leastArguments = 1;
if ((argsNum != leastArguments)) {
return UNDEFINED;
}
jerry_value_t strVal;
if (jerry_value_is_symbol(args[0])) {
strVal = jerry_get_symbol_descriptive_string(args[0]);
} else {
strVal = jerry_value_to_string(args[0]);
}
if (jerry_value_is_error(strVal)) {
jerry_release_value(strVal);
return jerry_create_boolean(false);
}
jerry_length_t length = jerry_get_utf8_string_length(strVal);
if (length >= SYSCAP_BUFFER_SIZE) {
jerry_release_value(strVal);
return jerry_create_boolean(false);
}
jerry_char_t buffer[SYSCAP_BUFFER_SIZE] = {0};
jerry_size_t syscapStrSize = jerry_string_to_utf8_char_buffer(strVal, buffer, length);
const char *syscapString = (char *)buffer;
bool ret = HasSystemCapability(syscapString);
jerry_release_value(strVal);
return jerry_create_boolean(ret);
}
} // namespace ACELite
} // namespace OHOS
#endif // FEATURE_SYSCAP_MODULE
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2022-2022 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_ACELITE_SYSCAP_MODULE_H
#define OHOS_ACELITE_SYSCAP_MODULE_H
#include "acelite_config.h"
#if (FEATURE_SYSCAP_MODULE == 1)
#include "presets/preset_module.h"
namespace OHOS {
namespace ACELite {
class SyscapModule final : PresetModule {
public:
ACE_DISALLOW_COPY_AND_MOVE(SyscapModule);
static SyscapModule *GetInstance()
{
static SyscapModule instance;
return &instance;
}
void Init() override;
private:
/**
* @fn SyscapModule::SyscapModule()
* @brief Constructor
*/
SyscapModule() : PresetModule(nullptr)
{
}
/**
* @fn SyscapModule::~SyscapModule()
*
*/
~SyscapModule() = default;
/**
* @brief get the syscap.
*/
static jerry_value_t CanIUse(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t *args,
const jerry_length_t argsNum)
{
return CheckSyscap(func, context, args, argsNum, false);
}
/**
* @brief get the syscap whether exist.
* @return the boolean of syscap
*/
static jerry_value_t CheckSyscap(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t *args,
const jerry_length_t argsNum,
bool repeated);
};
} // namespace ACELite
} // namespace OHOS
#endif // FEATURE_SYSCAP_MODULE == 1
namespace OHOS {
namespace ACELite {
class SyscapsModule final {
public:
ACE_DISALLOW_COPY_AND_MOVE(SyscapsModule);
SyscapsModule() = default;
~SyscapsModule() = default;
static void Load()
{
#if (FEATURE_SYSCAP_MODULE == 1)
SyscapModule *syscapModule = const_cast<SyscapModule *>(SyscapModule::GetInstance());
syscapModule->Init();
#endif
}
};
} // namespace ACELite
} // namespace OHOS
#endif // OHOS_ACELITE_SYSCAP_MODULE_H
+6 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Copyright (c) 2020-2022 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
@@ -87,6 +87,11 @@
*/
#define FEATURE_MODULE_DEVICE 1
/**
* syscap module
*/
#define FEATURE_SYSCAP_MODULE 1
/**
* timer module
*/
+8 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Copyright (c) 2020-2022 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
@@ -97,6 +97,13 @@
#define FEATURE_MODULE_DEVICE 1
#endif
/**
* syscap module
*/
#ifndef FEATURE_SYSCAP_MODULE
#define FEATURE_SYSCAP_MODULE 1
#endif
/**
* timer module
*/
+8 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Copyright (c) 2020-2022 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
@@ -74,6 +74,13 @@
#define FEATURE_FEATURE_ABILITY_MODULE 1
#endif
/**
* enable syscap JS API
*/
#ifndef FEATURE_SYSCAP_MODULE
#define FEATURE_SYSCAP_MODULE 0
#endif
/**
* enable timer JS API
*/
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Copyright (c) 2020-2022 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
@@ -85,6 +85,11 @@
*/
#define FEATURE_TIMER_MODULE 1
/**
* syscap module
*/
#define FEATURE_SYSCAP_MODULE 1
/**
* execute timer callback directly for previewer
*/
@@ -142,6 +142,7 @@ SOURCES += \
$${ACELITE_CORE_PATH}/modules/presets/render_module.cpp \
$${ACELITE_CORE_PATH}/modules/presets/require_module.cpp \
$${ACELITE_CORE_PATH}/modules/presets/timer_module.cpp \
$${ACELITE_CORE_PATH}/modules/presets/syscap_module.cpp \
$${ACELITE_CORE_PATH}/modules/presets/version_module.cpp \
$${ACELITE_CORE_PATH}/modules/router_module.cpp \
$${ACELITE_CORE_PATH}/modules/sample_module.cpp \
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 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
@@ -109,6 +109,11 @@
*/
#define FEATURE_TIMER_MODULE 1
/**
* syscap module
*/
#define FEATURE_SYSCAP_MODULE 1
#define FEATURE_CUSTOM_ENTRY_PAGE 1
/**