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 #include "frameworks/bridge/js_frontend/engine/quickjs/stepper_bridge.h"
17
18 #include "frameworks/bridge/common/utils/utils.h"
19
20 namespace OHOS::Ace::Framework {
21
GetAttrLabel(JSContext * ctx,JSValueConst valObject,StepperLabels & stepperLabel)22 void StepperBridge::GetAttrLabel(JSContext* ctx, JSValueConst valObject, StepperLabels& stepperLabel)
23 {
24 JSPropertyEnum* pTab = nullptr;
25 uint32_t len = 0;
26 if (!CheckAndGetJsProperty(ctx, valObject, &pTab, &len)) {
27 return;
28 }
29 for (uint32_t i = 0; i < len; i++) {
30 const char* key = JS_AtomToCString(ctx, pTab[i].atom);
31 if (key == nullptr) {
32 JS_FreeAtom(ctx, pTab[i].atom);
33 LOGW("key is null. Ignoring!");
34 continue;
35 }
36 std::string keyString = key;
37 JSValue val = JS_GetProperty(ctx, valObject, pTab[i].atom);
38 if (JS_IsNumber(val) || JS_IsBool(val) || JS_IsString(val)) {
39 ScopedString styleVal(ctx, val);
40 const char* valStr = styleVal.get();
41 if (keyString.compare(DOM_STEPPER_LEFT_LABEL) == 0) {
42 stepperLabel.leftLabel = valStr;
43 } else if (keyString.compare(DOM_STEPPER_RIGHT_LABEL) == 0) {
44 stepperLabel.rightLabel = valStr;
45 } else if (keyString.compare(DOM_STEPPER_INITIAL_STATUS) == 0) {
46 stepperLabel.initialStatus = valStr;
47 } else {
48 LOGD("key : %{public}s unsupported. Ignoring!", key);
49 }
50 } else {
51 LOGD("value of unsupported type. Ignoring!");
52 }
53 JS_FreeAtom(ctx, pTab[i].atom);
54 JS_FreeCString(ctx, key);
55 JS_FreeValue(ctx, val);
56 }
57 js_free(ctx, pTab);
58 }
59
60 } // namespace OHOS::Ace::Framework
61