forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.h
More file actions
83 lines (63 loc) · 2.83 KB
/
Copy pathtypes.h
File metadata and controls
83 lines (63 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "base_object.h"
#include "ffi.h"
#include <cstdint>
#include <string>
#include <vector>
namespace node::ffi {
struct FFIFunction;
bool ThrowIfContainsNullBytes(Environment* env,
const Utf8Value& value,
std::string_view label);
struct FunctionSignature {
ffi_type* return_type;
std::vector<ffi_type*> args;
std::string return_type_name;
std::vector<std::string> arg_type_names;
};
v8::Maybe<FunctionSignature> ParseFunctionSignature(
Environment* env, std::string_view name, v8::Local<v8::Object> signature);
v8::Maybe<ffi_type*> ToFFIType(Environment* env, std::string_view type_str);
enum class FFIArgumentCategory {
Regular,
String,
};
v8::Maybe<FFIArgumentCategory> ToFFIArgument(Environment* env,
unsigned int index,
ffi_type* type,
v8::Local<v8::Value> arg,
void* ret);
v8::Local<v8::Value> ToJSArgument(v8::Isolate* isolate,
ffi_type* type,
void* data);
bool ToJSReturnValue(Environment* env,
const v8::FunctionCallbackInfo<v8::Value>& args,
ffi_type* type,
void* result);
bool ToFFIReturnValue(v8::Local<v8::Value> result, ffi_type* type, void* ret);
bool SignaturesMatch(const FFIFunction& fn,
ffi_type* return_type,
const std::vector<ffi_type*>& args);
// True if the FFI type can be read from / written to a raw byte buffer
// without needing V8 operations (conversion, allocation, etc.).
bool IsSBEligibleFFIType(ffi_type* type);
// True if the signature's return type and all argument types are SB-eligible.
bool IsSBEligibleSignature(const FFIFunction& fn);
// True if any argument is pointer-typed. For these, the JS wrapper must
// do a runtime type check to decide fast vs. slow path per call.
bool SignatureHasPointerArgs(const FFIFunction& fn);
// Read a value of the given FFI type from buffer at the given byte offset
// into the output pointer (sized as uint64_t to hold any numeric type).
void ReadFFIArgFromBuffer(ffi_type* type,
const uint8_t* buffer,
size_t offset,
void* out);
// Write a return value of the given FFI type from the ffi_call result
// into the buffer at the given byte offset.
void WriteFFIReturnToBuffer(ffi_type* type,
const void* result,
uint8_t* buffer,
size_t offset);
} // namespace node::ffi
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS