1 /** 2 * Copyright (c) 2023 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_INTRINSICS_API_H 17 #define PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_INTRINSICS_API_H 18 19 #include <cstdint> 20 21 namespace panda::ets { 22 class EtsObject; 23 class EtsString; 24 class EtsObject; 25 class EtsClass; 26 } // namespace panda::ets 27 28 namespace panda::ets::interop::js { 29 30 class JSValue; 31 32 struct IntrinsicsAPI { 33 // NOLINTBEGIN(readability-identifier-naming) 34 void (*JSRuntimeFinalizationQueueCallback)(EtsObject *obj); 35 JSValue *(*JSRuntimeNewJSValueDouble)(double v); 36 JSValue *(*JSRuntimeNewJSValueString)(EtsString *v); 37 JSValue *(*JSRuntimeNewJSValueObject)(EtsObject *v); 38 double (*JSRuntimeGetValueDouble)(JSValue *etsJsValue); 39 uint8_t (*JSRuntimeGetValueBoolean)(JSValue *etsJsValue); 40 EtsString *(*JSRuntimeGetValueString)(JSValue *etsJsValue); 41 EtsObject *(*JSRuntimeGetValueObject)(JSValue *etsJsValue, EtsObject *cls); 42 JSValue *(*JSRuntimeGetPropertyJSValue)(JSValue *etsJsValue, EtsString *etsPropName); 43 double (*JSRuntimeGetPropertyDouble)(JSValue *etsJsValue, EtsString *etsPropName); 44 EtsString *(*JSRuntimeGetPropertyString)(JSValue *etsJsValue, EtsString *etsPropName); 45 void (*JSRuntimeSetPropertyJSValue)(JSValue *etsJsValue, EtsString *etsPropName, JSValue *value); 46 void (*JSRuntimeSetPropertyDouble)(JSValue *etsJsValue, EtsString *etsPropName, double value); 47 void (*JSRuntimeSetPropertyString)(JSValue *etsJsValue, EtsString *etsPropName, EtsString *value); 48 JSValue *(*JSRuntimeGetElementJSValue)(JSValue *etsJsValue, int32_t index); 49 double (*JSRuntimeGetElementDouble)(JSValue *etsJsValue, int32_t index); 50 JSValue *(*JSRuntimeGetUndefined)(); 51 JSValue *(*JSRuntimeGetNull)(); 52 JSValue *(*JSRuntimeGetGlobal)(); 53 JSValue *(*JSRuntimeCreateObject)(); 54 uint8_t (*JSRuntimeInstanceOf)(JSValue *object, JSValue *ctor); 55 uint8_t (*JSRuntimeInitJSCallClass)(EtsString *clsName); 56 uint8_t (*JSRuntimeInitJSNewClass)(EtsString *clsName); 57 JSValue *(*JSRuntimeCreateLambdaProxy)(EtsObject *lambda); 58 JSValue *(*JSRuntimeLoadModule)(EtsString *module); 59 uint8_t (*JSRuntimeStrictEqual)(JSValue *lhs, JSValue *rhs); 60 void *(*CompilerGetJSNamedProperty)(void *val, char *propName); 61 void *(*CompilerResolveQualifiedJSCall)(void *val, EtsString *qnameStr); 62 void *(*CompilerJSCallCheck)(void *fn); 63 void *(*CompilerJSCallFunction)(void *obj, void *fn, uint32_t argc, void *args); 64 void (*CompilerJSCallVoidFunction)(void *obj, void *fn, uint32_t argc, void *args); 65 void *(*CompilerJSNewInstance)(void *fn, uint32_t argc, void *args); 66 void (*CreateLocalScope)(); 67 void (*CompilerDestroyLocalScope)(); 68 void *(*CompilerConvertVoidToLocal)(); 69 void *(*CompilerConvertU1ToLocal)(bool etsVal); 70 void *(*CompilerConvertU8ToLocal)(uint8_t etsVal); 71 void *(*CompilerConvertI8ToLocal)(int8_t etsVal); 72 void *(*CompilerConvertU16ToLocal)(uint16_t etsVal); 73 void *(*CompilerConvertI16ToLocal)(int16_t etsVal); 74 void *(*CompilerConvertU32ToLocal)(uint32_t etsVal); 75 void *(*CompilerConvertI32ToLocal)(int32_t etsVal); 76 void *(*CompilerConvertU64ToLocal)(uint64_t etsVal); 77 void *(*CompilerConvertI64ToLocal)(int64_t etsVal); 78 void *(*CompilerConvertF32ToLocal)(float etsVal); 79 void *(*CompilerConvertF64ToLocal)(double etsVal); 80 void *(*CompilerConvertJSValueToLocal)(JSValue *etsVal); 81 void *(*CompilerConvertRefTypeToLocal)(EtsObject *etsVal); 82 bool (*CompilerConvertLocalToU1)(void *val); 83 uint8_t (*CompilerConvertLocalToU8)(void *val); 84 int8_t (*CompilerConvertLocalToI8)(void *val); 85 uint16_t (*CompilerConvertLocalToU16)(void *val); 86 int16_t (*CompilerConvertLocalToI16)(void *val); 87 uint32_t (*CompilerConvertLocalToU32)(void *val); 88 int32_t (*CompilerConvertLocalToI32)(void *val); 89 uint64_t (*CompilerConvertLocalToU64)(void *val); 90 int64_t (*CompilerConvertLocalToI64)(void *val); 91 float (*CompilerConvertLocalToF32)(void *val); 92 double (*CompilerConvertLocalToF64)(void *val); 93 JSValue *(*CompilerConvertLocalToJSValue)(void *val); 94 EtsString *(*CompilerConvertLocalToString)(void *val); 95 EtsObject *(*CompilerConvertLocalToRefType)(void *klassPtr, void *val); 96 // NOLINTEND(readability-identifier-naming) 97 }; 98 99 } // namespace panda::ets::interop::js 100 101 #endif // !PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_INTRINSICS_API_H 102