In order for this to work, the TS code in this context must have a global namespace `protoSupport` and under it: * * protoSupport * Arena -> { Arena } from 'valdi_protobuf/src/Arena' * protoLibs -> TS protobuf namespace map * "djinni.test": proto.djinni.test * * This is global namespace layout is created by calling `registerProtobufLib` in ProtoSupport.ts */
| 953 | return _jsContext->valueToStaticString(value.get(), toJSExceptionTracker(exceptionTracker)); |
| 954 | } |
| 955 | |
| 956 | BytesView JavaScriptValueDelegate::valueToByteArray(const JSValueRef& value, |
| 957 | const ReferenceInfoBuilder& referenceInfoBuilder, |
| 958 | ExceptionTracker& exceptionTracker) const { |
| 959 | auto typedArray = jsTypedArrayToValueTypedArray( |
| 960 | *_jsContext, value.get(), referenceInfoBuilder, toJSExceptionTracker(exceptionTracker)); |
| 961 | if (typedArray == nullptr) { |
| 962 | return BytesView(); |
| 963 | } |
| 964 | return typedArray->getBuffer(); |
| 965 | } |
| 966 | |
| 967 | Ref<ValueTypedArray> JavaScriptValueDelegate::valueToTypedArray(const JSValueRef& value, |
| 968 | const ReferenceInfoBuilder& referenceInfoBuilder, |
| 969 | ExceptionTracker& exceptionTracker) const { |
| 970 | return jsTypedArrayToValueTypedArray( |
| 971 | *_jsContext, value.get(), referenceInfoBuilder, toJSExceptionTracker(exceptionTracker)); |
| 972 | } |
| 973 | |
| 974 | double JavaScriptValueDelegate::dateToDouble(const JSValueRef& value, ExceptionTracker& exceptionTracker) const { |
| 975 | JSFunctionCallContext ctx(*_jsContext, nullptr, 0, toJSExceptionTracker(exceptionTracker)); |
| 976 | auto millisecondsJs = _jsContext->callObjectProperty(value.get(), "getTime", ctx); |
| 977 | return _jsContext->valueToDouble(millisecondsJs.get(), toJSExceptionTracker(exceptionTracker)); |
| 978 | } |
| 979 | |
| 980 | BytesView JavaScriptValueDelegate::encodeProto(const JSValueRef& proto, |
| 981 | const ReferenceInfoBuilder& referenceInfoBuilder, |
| 982 | ExceptionTracker& exceptionTracker) const { |
| 983 | JSFunctionCallContext ctx(*_jsContext, nullptr, 0, toJSExceptionTracker(exceptionTracker)); |
| 984 | auto bytes = _jsContext->callObjectProperty(proto.get(), "encode", ctx); |
| 985 | return valueToByteArray(bytes, referenceInfoBuilder, exceptionTracker); |
| 986 | } |
| 987 | |
| 988 | /* In order for this to work, the TS code in this context must have a global namespace `protoSupport` and under it: |
| 989 | * |
| 990 | * protoSupport |
| 991 | * Arena -> { Arena } from 'valdi_protobuf/src/Arena' |
| 992 | * protoLibs -> TS protobuf namespace map |
| 993 | * "djinni.test": proto.djinni.test |
| 994 | * |
| 995 | * This is global namespace layout is created by calling `registerProtobufLib` in ProtoSupport.ts |
| 996 | */ |
| 997 | JSValueRef JavaScriptValueDelegate::decodeProto(const BytesView& bytes, |
| 998 | const std::vector<std::string_view>& classNameParts, |
| 999 | const ReferenceInfoBuilder& referenceInfoBuilder, |
| 1000 | ExceptionTracker& exceptionTracker) const { |
| 1001 | static auto kProtoSupportName = STRING_LITERAL("protoSupport"); |
| 1002 | auto protoSupport = |
| 1003 | _jsContext->getPropertyFromGlobalObjectCached(kProtoSupportName, toJSExceptionTracker(exceptionTracker)); |
| 1004 | if (!exceptionTracker) { |
| 1005 | return _jsContext->newUndefined(); |
| 1006 | } |
| 1007 | auto arenaCtor = _jsContext->getObjectProperty(protoSupport.get(), "Arena", toJSExceptionTracker(exceptionTracker)); |
nothing calls this directly
no test coverage detected