-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv8wrapper.cc
155 lines (130 loc) · 2.82 KB
/
v8wrapper.cc
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// v8 c wrapper
#include "v8wrapper.h"
#include <memory>
using namespace v8;
typedef Local<Value> (*rust_callback)(void*);
extern "C" {
const char*
V8_Version()
{
const char* version = V8_VERSION_STRING;
return version;
}
std::unique_ptr<Platform>
V8_Initialize_Platform()
{
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
V8::Initialize();
return platform;
}
void
V8_Get_Platform(std::unique_ptr<Platform> platform, Platform** out)
{
*out = platform.get();
}
/**
* Associate embedder-specific data with the isolate. |slot| has to be
* between 0 and GetNumberOfDataSlots() - 1.
*/
void
V8_Isolate_SetData(Isolate* isolate, uint32_t slot, void* data)
{
isolate->SetData(slot, data);
}
/**
* Retrieve embedder-specific data from the isolate.
* Returns NULL if SetData has never been called for the given |slot|.
*/
void*
V8_Isolate_GetData(Isolate* isolate, uint32_t slot)
{
return isolate->GetData(slot);
}
void
V8_Isolate_With_Locker(Isolate* isolate, rust_callback callback, void* data)
{
Locker locker(isolate);
callback(data);
}
Isolate*
V8_FunctionCallbackInfo_GetIsolate(FunctionCallbackInfo<Value>& args)
{
return args.GetIsolate();
}
Local<Object>
V8_FunctionCallbackInfo_This(FunctionCallbackInfo<Value>& args)
{
return args.This();
}
int
V8_FunctionCallbackInfo_Length(FunctionCallbackInfo<Value>& args)
{
return args.Length();
}
Local<Object>
V8_FunctionCallbackInfo_Holder(FunctionCallbackInfo<Value>& args)
{
return args.Holder();
}
Local<Value>
V8_FunctionCallbackInfo_NewTarget(FunctionCallbackInfo<Value>& args)
{
return args.NewTarget();
}
bool
V8_FunctionCallbackInfo_IsConstructorCall(FunctionCallbackInfo<Value>& args)
{
return args.IsConstructCall();
}
Local<Value>
V8_FunctionCallbackInfo_Data(FunctionCallbackInfo<Value>& args)
{
return args.Data();
}
void
V8_FunctionCallbackInfo_GetReturnValue(FunctionCallbackInfo<Value>& args,
ReturnValue<Value>* out)
{
*out = args.GetReturnValue();
}
void
V8_ReturnValue_SetLocalValue(ReturnValue<Value>& in, Local<Value> value)
{
in.Set(value);
}
void
V8_ReturnValue_SetNull(ReturnValue<Value>& in)
{
in.SetNull();
}
void
V8_ReturnValue_SetUndefined(ReturnValue<Value>& in)
{
in.SetUndefined();
}
void
V8_ReturnValue_SetBool(ReturnValue<Value>& in, bool value)
{
in.Set(value);
}
void
V8_ReturnValue_SetDouble(ReturnValue<Value>& in, double value)
{
in.Set(value);
}
void
V8_ReturnValue_SetInt32(ReturnValue<Value>& in, int32_t value)
{
in.Set(value);
}
void
V8_ReturnValue_SetUint32(ReturnValue<Value>& in, uint32_t value)
{
in.Set(value);
}
void
V8_Object_GetInternalField(Local<Object>& obj, int index, Local<Value>* field) {
*field = obj->GetInternalField(index);
}
}