Repository navigation
Expand file tree
/
Copy pathJsArgConverter.h
More file actions
95 lines (60 loc) · 2.36 KB
/
Copy pathJsArgConverter.h
File metadata and controls
95 lines (60 loc) · 2.36 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
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef JSARGCONVERTER_H_
#define JSARGCONVERTER_H_
#include <string>
#include <vector>
#include "JEnv.h"
#include "v8.h"
#include "MetadataEntry.h"
namespace tns {
enum class BufferCastType {
Byte,
Short,
Int,
Long,
Float,
Double
};
class JsArgConverter {
public:
JsArgConverter(const v8::Local<v8::Object>& caller, const v8::FunctionCallbackInfo<v8::Value>& args, const std::string& methodSignature, MetadataEntry* entry);
JsArgConverter(const v8::FunctionCallbackInfo<v8::Value>& args, bool hasImplementationObject, const std::string& methodSignature, MetadataEntry* entry);
JsArgConverter(const v8::FunctionCallbackInfo<v8::Value>& args, const std::string& methodSignature);
JsArgConverter(const JsArgConverter&) = delete;
JsArgConverter& operator=(const JsArgConverter&) = delete;
~JsArgConverter();
jvalue* ToArgs();
int Length() const;
bool IsValid() const;
struct Error;
Error GetError() const;
struct Error {
Error() :
index(-1), msg(std::string()) {
}
int index;
std::string msg;
};
static BufferCastType GetCastType(const v8::Local<v8::ArrayBufferView>& view);
private:
bool ConvertArg(const v8::Local<v8::Value>& jsArg, int index);
bool ConvertJavaScriptArray(const v8::Local<v8::Array>& jsArr, int index);
bool ConvertJavaScriptNumber(const v8::Local<v8::Value>& jsValue, int index);
bool ConvertJavaScriptBoolean(const v8::Local<v8::Value>& jsValue, int index);
bool ConvertJavaScriptString(const v8::Local<v8::Value>& jsValue, int index);
void SetConvertedObject(int index, jobject obj, bool isGlobal = false);
template<typename T>
bool ConvertFromCastFunctionObject(T value, int index);
v8::Isolate* m_isolate;
int m_argsLen;
bool m_isValid;
jvalue m_args[255];
int m_args_refs[255];
int m_args_refs_size = 0;
std::string m_methodSignature;
std::vector<std::string> m_ownedTokens;
// May point at m_ownedTokens, which is why the converter is not copyable.
const std::vector<std::string>* m_tokens = &m_ownedTokens;
Error m_error;
};
}
#endif /* JSARGCONVERTER_H_ */