-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcallback.c
More file actions
250 lines (216 loc) · 7.25 KB
/
callback.c
File metadata and controls
250 lines (216 loc) · 7.25 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include <JavaScriptCore/JSObjectRef.h>
#include <assert.h>
#include <stdlib.h>
#include "_cgo_export.h"
#include "callback.h"
//=========================================================
// Native Callback
//---------------------------------------------------------
static void nativecallback_Finalize(JSObjectRef object)
{
void* data = JSObjectGetPrivate( object );
finalize_go( data );
}
static JSValueRef nativecallback_CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
assert( exception );
// Routine must set private to callback point in Go
void* data = JSObjectGetPrivate( function );
JSValueRef ret = nativecallback_CallAsFunction_go( data, ctx, function, thisObject, argumentCount, (void *)arguments, exception );
assert( *exception==NULL || (*exception && !ret) );
return ret;
}
static JSValueRef nativecallback_ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception)
{
if ( type == kJSTypeString ) {
JSStringRef str = JSStringCreateWithUTF8CString( "nativecallback" );
JSValueRef ret = JSValueMakeString( ctx, str );
JSStringRelease( str );
return ret;
}
return 0;
}
JSClassRef JSClassDefinition_NativeCallback()
{
static JSClassDefinition def = {
0,
kJSClassAttributeNone,
"nativecallback",
NULL, // parentClass
NULL, // staticValues;
NULL, // staticFunctions;
NULL, // initialize;
nativecallback_Finalize, // finalize;
NULL, // hasProperty;
NULL, // getProperty;
NULL, // setProperty;
NULL, // deleteProperty;
NULL, // getPropertyNames;
nativecallback_CallAsFunction, // callAsFunction;
NULL, // callAsConstructor;
NULL, // hasInstance;
nativecallback_ConvertToType // convertToType;
};
return JSClassCreate( &def );
}
//=========================================================
// Native Function
//---------------------------------------------------------
static void nativefunction_Finalize(JSObjectRef object)
{
void* data = JSObjectGetPrivate( object );
finalize_go( data );
}
static JSValueRef nativefunction_CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
assert( exception );
// Routine must set private to callback point in Go
void* data = JSObjectGetPrivate( function );
JSValueRef ret = nativefunction_CallAsFunction_go(data, ctx, function, thisObject, argumentCount, (void*)arguments, exception );
assert( *exception==NULL || (*exception && !ret) );
return ret;
}
static JSValueRef nativefunction_ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception)
{
if ( type == kJSTypeString ) {
JSStringRef str = JSStringCreateWithUTF8CString( "nativefunction" );
JSValueRef ret = JSValueMakeString( ctx, str );
JSStringRelease( str );
return ret;
}
return 0;
}
JSClassRef JSClassDefinition_NativeFunction()
{
static JSClassDefinition def = {
0,
kJSClassAttributeNone,
"nativefunction",
NULL, // parentClass
NULL, // staticValues;
NULL, // staticFunctions;
NULL, // initialize;
nativefunction_Finalize, // finalize;
NULL, // hasProperty;
NULL, // getProperty;
NULL, // setProperty;
NULL, // deleteProperty;
NULL, // getPropertyNames;
nativefunction_CallAsFunction, // callAsFunction;
NULL, // callAsConstructor;
NULL, // hasInstance;
nativefunction_ConvertToType // convertToType;
};
return JSClassCreate( &def );
}
//=========================================================
// Native Object
//---------------------------------------------------------
static void nativeobject_Finalize(JSObjectRef object)
{
void* data = JSObjectGetPrivate( object );
finalize_go( data );
}
static JSValueRef nativeobject_GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
assert( exception );
// Routine must set private to callback point in Go
void* data = JSObjectGetPrivate( object );
JSValueRef ret = nativeobject_GetProperty_go( data, (void*)ctx, (void*)object, (void*)propertyName, (void**)exception );
assert( *exception==NULL || (*exception && !ret) );
return ret;
}
static bool nativeobject_SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
assert( exception );
// Routine must set private to callback point in Go
void* data = JSObjectGetPrivate( object );
return nativeobject_SetProperty_go( data, (void*)ctx, (void*)object, propertyName, (void*)value, exception );
}
static JSValueRef nativeobject_ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception)
{
if ( type == kJSTypeString ) {
void* data = JSObjectGetPrivate( object );
JSStringRef str = nativeobject_ConvertToString_go( data, (void*)ctx, (void*)object );
if ( !str ) {
str = JSStringCreateWithUTF8CString( "nativeobject" );
}
JSValueRef ret = JSValueMakeString( ctx, str );
JSStringRelease( str );
return ret;
}
return 0;
}
JSClassRef JSClassDefinition_NativeObject()
{
static JSClassDefinition def = {
0,
kJSClassAttributeNone,
"nativeobject",
NULL, // parentClass
NULL, // staticValues;
NULL, // staticFunctions;
NULL, // initialize;
nativeobject_Finalize, // finalize;
NULL, // hasProperty;
nativeobject_GetProperty, // getProperty;
nativeobject_SetProperty, // setProperty;
NULL, // deleteProperty;
NULL, // getPropertyNames;
NULL, // callAsFunction;
NULL, // callAsConstructor;
NULL, // hasInstance;
nativeobject_ConvertToType // convertToType;
};
return JSClassCreate( &def );
}
//=========================================================
// Native Method
//---------------------------------------------------------
static void nativemethod_Finalize(JSObjectRef object)
{
void* data = JSObjectGetPrivate( object );
finalize_go( data );
}
static JSValueRef nativemethod_CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
assert( exception );
// Routine must set private to callback point in Go
void* data = JSObjectGetPrivate( function );
JSValueRef ret = nativemethod_CallAsFunction_go( data, ctx, function, thisObject, argumentCount, (void*)arguments, exception );
assert( *exception==NULL || (*exception && !ret) );
return ret;
}
static JSValueRef nativemethod_ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception)
{
if ( type == kJSTypeString ) {
JSStringRef str = JSStringCreateWithUTF8CString( "nativemethod" );
JSValueRef ret = JSValueMakeString( ctx, str );
JSStringRelease( str );
return ret;
}
return 0;
}
JSClassRef JSClassDefinition_NativeMethod()
{
static JSClassDefinition def = {
0,
kJSClassAttributeNone,
"nativemethod",
NULL, // parentClass
NULL, // staticValues;
NULL, // staticFunctions;
NULL, // initialize;
nativemethod_Finalize, // finalize;
NULL, // hasProperty;
NULL, // getProperty;
NULL, // setProperty;
NULL, // deleteProperty;
NULL, // getPropertyNames;
nativemethod_CallAsFunction, // callAsFunction;
NULL, // callAsConstructor;
NULL, // hasInstance;
nativemethod_ConvertToType // convertToType;
};
return JSClassCreate( &def );
}