/* * Copyright (c) 2021 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 "bindings_implementation.h" namespace OHOS::Ace::Framework { template typename ImplDetail> thread_local std::string JSClassImpl::jsName; template typename ImplDetail> void JSClassImpl::Declare(const char* name) { jsName = name; ImplDetail::Declare(name); } template typename ImplDetail> template void JSClassImpl::Method(const char* name, R (Base::*func)(Args...), MethodOptions options) { static_assert(std::is_base_of_v, "Trying to bind an unrelated method!"); ImplDetail::Method(name, new FunctionBinding(name, options, func)); } template typename ImplDetail> template void JSClassImpl::StaticMethod(const char* name, R (*func)(Args...), MethodOptions options) { ImplDetail::StaticMethod(name, new StaticFunctionBinding(name, options, func)); } template typename ImplDetail> void JSClassImpl::StaticMethod(const char* name, JSFunctionCallback func) { ImplDetail::StaticMethod(name, new StaticFunctionBinding(name, MethodOptions::NONE, func)); } template typename ImplDetail> template void JSClassImpl::CustomMethod(const char* name, MemberFunctionCallback callback) { static_assert(std::is_base_of_v, "Trying to bind an unrelated method!"); ImplDetail::CustomMethod(name, new FunctionBinding(name, MethodOptions::NONE, callback)); } template typename ImplDetail> void JSClassImpl::CustomMethod(const char* name, FunctionCallback callback) { ImplDetail::CustomMethod(name, callback); } template typename ImplDetail> template void JSClassImpl::CustomMethod(const char* name, JSMemberFunctionCallback callback) { ImplDetail::CustomMethod(name, new FunctionBinding(name, MethodOptions::NONE, callback)); } template typename ImplDetail> template void JSClassImpl::CustomProperty( const char* name, MemberFunctionGetCallback getter, MemberFunctionSetCallback setter) { static_assert(std::is_base_of_v, "Trying to bind an unrelated method!"); ImplDetail::CustomProperty(name, new FunctionBinding(name, MethodOptions::NONE, getter), new FunctionBinding(name, MethodOptions::NONE, setter)); } template typename ImplDetail> void JSClassImpl::CustomProperty( const char* name, FunctionGetCallback getter, FunctionSetCallback setter) { ImplDetail::CustomProperty(name, getter, setter); } template typename ImplDetail> template void JSClassImpl::CustomProperty( const char* name, JSMemberFunctionCallback getter, JSMemberFunctionCallback setter) { ImplDetail::CustomProperty(name, new FunctionBinding(name, MethodOptions::NONE, getter), new FunctionBinding(name, MethodOptions::NONE, setter)); } template typename ImplDetail> void JSClassImpl::CustomStaticMethod(const char* name, FunctionCallback callback) { ImplDetail::CustomStaticMethod(name, callback); } template typename ImplDetail> void JSClassImpl::ExoticGetter(ExoticGetterCallback callback) { ImplDetail::ExoticGetter(callback); } template typename ImplDetail> void JSClassImpl::ExoticSetter(ExoticSetterCallback callback) { ImplDetail::ExoticSetter(callback); } template typename ImplDetail> void JSClassImpl::ExoticHasProperty(ExoticHasPropertyCallback callback) { ImplDetail::ExoticHasProperty(callback); } template typename ImplDetail> template void JSClassImpl::StaticConstant(const char* name, T value) { ImplDetail::StaticConstant(name, value); } template typename ImplDetail> void JSClassImpl::Bind(BindingTarget bindTarget, FunctionCallback ctor) { ImplDetail::Bind(bindTarget, ctor); } template typename ImplDetail> void JSClassImpl::Bind( BindingTarget bindTarget, JSFunctionCallback ctor, JSDestructorCallback dtor, JSGCMarkCallback gcMark) { ImplDetail::Bind(bindTarget, ctor, dtor, gcMark); } template typename ImplDetail> template void JSClassImpl::Bind( BindingTarget bindTarget, JSDestructorCallback dtor, JSGCMarkCallback gcMark) { ImplDetail::template Bind(bindTarget, dtor, gcMark); } template typename ImplDetail> template void JSClassImpl::Inherit() { static_assert(std::is_base_of_v, "Calling Inherit() on unrelated classes!"); ImplDetail::template Inherit(); } template typename ImplDetail> template void JSClassImpl::InheritAndBind( BindingTarget bindTarget, JSFunctionCallback ctor, JSDestructorCallback dtor, JSGCMarkCallback gcMark) { static_assert(std::is_base_of_v, "Calling Inherit() on unrelated classes!"); ImplDetail::template InheritAndBind(bindTarget, ctor, dtor, gcMark); } template typename ImplDetail> const char* JSClassImpl::JSName() { return jsName.c_str(); } template typename ImplDetail> JSRef JSClassImpl::NewInstance() { return JSRef::Make(ImplDetail::NewInstance()); } }; // namespace OHOS::Ace::Framework