• 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 #include "frameworks/bridge/js_frontend/engine/v8/v8_stepper_bridge.h"
17 
18 #include "frameworks/bridge/common/utils/utils.h"
19 
20 namespace OHOS::Ace::Framework {
21 
GetAttrLabel(v8::Local<v8::Context> ctx,v8::Local<v8::Value> valObject,StepperLabels & stepperLabel)22 void V8StepperBridge::GetAttrLabel(
23     v8::Local<v8::Context> ctx, v8::Local<v8::Value> valObject, StepperLabels& stepperLabel)
24 {
25     v8::Isolate* isolate = ctx->GetIsolate();
26     ACE_DCHECK(isolate);
27     v8::HandleScope handleScope(isolate);
28 
29     if (!valObject->IsObject()) {
30         LOGE("none found attrs");
31         return;
32     }
33     v8::Local<v8::Object> v8ValObj;
34     if (!valObject->ToObject(ctx).ToLocal(&v8ValObj)) {
35         LOGE("Value to Object fail");
36         return;
37     }
38     v8::Local<v8::Array> properties = v8ValObj->GetOwnPropertyNames(ctx).ToLocalChecked();
39     int32_t len = properties->Length();
40     for (int32_t i = 0; i < len; i++) {
41         v8::Local<v8::Value> key;
42         if (!properties->Get(ctx, i).ToLocal(&key)) {
43             LOGW("key is null. Ignoring!");
44             continue;
45         }
46         v8::String::Utf8Value keyV8Str(isolate, key);
47         const char* keyStr = *keyV8Str;
48         if (keyStr == nullptr) {
49             continue;
50         }
51         v8::Local<v8::Value> val = v8ValObj->Get(ctx, key).ToLocalChecked();
52         if (val->IsNumber() || val->IsBoolean() || val->IsString()) {
53             v8::String::Utf8Value valV8Str(ctx->GetIsolate(), val);
54             const char* valStr = *valV8Str;
55             if (valStr == nullptr) {
56                 continue;
57             }
58             if (strcmp(keyStr, DOM_STEPPER_LEFT_LABEL) == 0) {
59                 stepperLabel.leftLabel = valStr;
60             } else if (strcmp(keyStr, DOM_STEPPER_RIGHT_LABEL) == 0) {
61                 stepperLabel.rightLabel = valStr;
62             } else if (strcmp(keyStr, DOM_STEPPER_INITIAL_STATUS) == 0) {
63                 stepperLabel.initialStatus = valStr;
64             } else {
65                 LOGD("key : %{public}s unsupported. Ignoring!", keyStr);
66             }
67         } else {
68             LOGD("value of unsupported type. Ignoring!");
69         }
70     }
71 }
72 
73 } // namespace OHOS::Ace::Framework