1 /** 2 * Copyright (c) 2023-2024 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 PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_JS_PROXY_JS_PROXY_H_ 17 #define PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_JS_PROXY_JS_PROXY_H_ 18 19 #include "runtime/include/class.h" 20 #include "runtime/include/method.h" 21 22 namespace ark::ets { 23 class EtsClass; 24 class EtsObject; 25 } // namespace ark::ets 26 27 namespace ark::ets::interop::js::js_proxy { 28 29 class JSProxy { 30 public: 31 static std::unique_ptr<JSProxy> Create(EtsClass *etsClass, Span<Method *> targetMethods); 32 GetProxyClass()33 EtsClass *GetProxyClass() const 34 { 35 return proxyKlass_; 36 } 37 IsProxyClass(Class * klass)38 static bool IsProxyClass(Class *klass) 39 { 40 // For class descriptor "Lname;" proxy descriptor is "L$name$;" 41 const uint8_t *descriptor = klass->GetDescriptor(); 42 Span<const uint8_t> desc(descriptor, utf::Mutf8Size(descriptor)); 43 return desc[0] == 'L' && desc[1] == '$' && desc[desc.size() - 1] == ';' && desc[desc.size() - 2U] == '$'; 44 } 45 46 ~JSProxy() = default; 47 48 NO_COPY_SEMANTIC(JSProxy); 49 NO_MOVE_SEMANTIC(JSProxy); 50 51 private: JSProxy(EtsClass * proxyKlass)52 explicit JSProxy(EtsClass *proxyKlass) : proxyKlass_(proxyKlass) {} 53 54 EtsClass *const proxyKlass_ {}; 55 // NOTE(vpukhov): add flag if original class has final methods or public fields 56 // NOTE(vpukhov): must ensure compat-class methods except accessors do not access its private state 57 }; 58 59 } // namespace ark::ets::interop::js::js_proxy 60 61 #endif // !PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_JS_PROXY_JS_PROXY_H_ 62