summaryrefslogtreecommitdiff
path: root/Lib/javascript/jsc/javascriptrun.swg
blob: 3463d23511afca470fe26db5145d157cee5b0dfe (plain)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/* ----------------------------------------------------------------------------
 *  Errors and exceptions
 *
 * ---------------------------------------------------------------------------*/

#define SWIG_Error(code, msg)     SWIG_JSC_exception(context, exception, code, msg)
#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
#define SWIG_fail                 goto fail

void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
 JSStringRef message = JSStringCreateWithUTF8CString(type);
 *exception = JSValueMakeString(context, message);
 JSStringRelease(message);
}

void SWIG_JSC_exception(JSContextRef context, JSValueRef *exception, int code, const char* msg) {
  SWIG_Javascript_Raise(context, exception, msg);
}

/* ----------------------------------------------------------------------------
 *  The parent class of all Proxies
 *
 * ---------------------------------------------------------------------------*/

typedef struct {
  bool swigCMemOwn;
  void *swigCObject;
  swig_type_info *info;
} SwigPrivData;

JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
  JSValueRef jsresult;

  JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
  SwigPrivData *cdata = (SwigPrivData *) JSObjectGetPrivate(obj);

  cdata->swigCMemOwn = false;

  jsresult = JSValueMakeUndefined(context);
  return jsresult;
}

JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
  JSValueRef jsresult;
  long result;

  JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
  SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);

  result = (long) cdata->swigCObject;
  jsresult = JSValueMakeNumber(context, result);

  return jsresult;
}

JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
  JSValueRef jsresult;
  bool result;

  JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
  SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);

  JSObjectRef obj2 = JSValueToObject(context, argv[0], NULL);
  SwigPrivData *cdata2 = (SwigPrivData*) JSObjectGetPrivate(obj2);

  result = (cdata->swigCObject == cdata2->swigCObject);
  jsresult = JSValueMakeBoolean(context, result);

  return jsresult;
}

JSStaticValue _SwigObject_values[] = {
  {
    0, 0, 0, 0
  }
};

JSStaticFunction _SwigObject_functions[] = {
  {
    "disown",_wrap_SwigObject_disown, kJSPropertyAttributeNone
  },
  {
    "equals",_wrap_SwigObject_equals, kJSPropertyAttributeNone
  },
  {
    "getCPtr",_wrap_SwigObject_getCPtr, kJSPropertyAttributeNone
  },
  {
    0, 0, 0
  }
};

JSClassDefinition _SwigObject_objectDefinition;

JSClassRef _SwigObject_classRef;


int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
  SwigPrivData *cdata = (SwigPrivData *) JSObjectGetPrivate(objRef);
  if(cdata == NULL) {
    return SWIG_ERROR;
  }
  if(cdata->info != info) {
    bool type_valid = false;
    swig_cast_info *t = info->cast;
    while(t != NULL) {
      if(t->type == cdata->info) {
        type_valid = true;
        break;
      }
      t = t->next;
    }
    if(!type_valid) {
      return SWIG_TypeError;
    }
  }

  *ptr = cdata->swigCObject;

  if(flags & SWIG_POINTER_DISOWN) {
    cdata->swigCMemOwn = false;
  }

  return SWIG_OK;
}

int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swig_type_info *info, int flags) {
  if(!JSValueIsObject(context, valRef)) {
    return SWIG_TypeError;
  }

  JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
  if(objRef == NULL) {
    return SWIG_ERROR;
  }

  return SWIG_JSC_ConvertInstancePtr(context, objRef, ptr, info, flags);
}

JSObjectRef SWIG_JSC_NewPointerObj(JSContextRef context, void *ptr, swig_type_info *info, int flags) {

  JSClassRef classRef;
  if(info->clientdata == NULL) {
    classRef = _SwigObject_classRef;
  } else {
    classRef = (JSClassRef) info->clientdata;
  }

  JSObjectRef result = JSObjectMake(context, classRef, NULL);

  SwigPrivData* cdata = (SwigPrivData*) malloc(sizeof(SwigPrivData));
  cdata->swigCObject = ptr;
  cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
  cdata->info = info;

  JSObjectSetPrivate(result, cdata);

  return result;
}

#define SWIG_ConvertPtr(obj, ptr, info, flags)    SWIG_JSC_ConvertPtr(context, obj, ptr, info, flags)
#define SWIG_NewPointerObj(ptr, info, flags)      SWIG_JSC_NewPointerObj(context, ptr, info, flags)

#define SWIG_ConvertInstance(obj, pptr, type, flags)    SWIG_JSC_ConvertInstancePtr(context, obj, pptr, type, flags)
#define SWIG_NewInstanceObj(thisvalue, type, flags)     SWIG_JSC_NewPointerObj(context, thisvalue, type, flags)

#define SWIG_ConvertFunctionPtr(obj, pptr, type)        SWIG_JSC_ConvertPtr(context, obj, pptr, type, 0)
#define SWIG_NewFunctionPtrObj(ptr, type)               SWIG_JSC_NewPointerObj(context, ptr, type, 0)

/* ----------------------------------------------------------------------------
 *  A class for packed data
 *
 * ---------------------------------------------------------------------------*/

typedef struct {
  void *data;
  size_t size;
  swig_type_info *type;
} SwigPackedData;

JSStaticValue _SwigPackedData_values[] = {
  {
    0, 0, 0, 0
  }
};
JSStaticFunction _SwigPackedData_functions[] = {
  {
    0, 0, 0
  }
};
JSClassDefinition _SwigPackedData_objectDefinition;
JSClassRef _SwigPackedData_classRef;

SWIGRUNTIMEINLINE
int SwigJSCPacked_Check(JSContextRef context, JSValueRef valRef) {
  return JSValueIsObjectOfClass(context, valRef, _SwigPackedData_classRef);
}

SWIGRUNTIME
swig_type_info* SwigJSCPacked_UnpackData(JSContextRef context, JSValueRef valRef, void *ptr, size_t size) {
  if (SwigJSCPacked_Check(context, valRef)) {
    JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
    SwigPackedData *sobj = (SwigPackedData *) JSObjectGetPrivate(objRef);
    if (sobj->size != size) return 0;
    memcpy(ptr, sobj->data, size);
    return sobj->type;
  } else {
    return 0;
  }
}

SWIGRUNTIME
int SWIG_JSC_ConvertPacked(JSContextRef context, JSValueRef valRef, void *ptr, size_t sz, swig_type_info *ty) {
  swig_type_info *to = SwigJSCPacked_UnpackData(context, valRef, ptr, sz);
  if (!to) return SWIG_ERROR;
  if (ty) {
    if (to != ty) {
      /* check type cast? */
      swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
      if (!tc) return SWIG_ERROR;
    }
  }
  return SWIG_OK;
}

SWIGRUNTIME
JSValueRef SWIG_JSC_NewPackedObj(JSContextRef context, void *data, size_t size, swig_type_info *type) {

  JSClassRef classRef = _SwigObject_classRef;
  JSObjectRef result = JSObjectMake(context, classRef, NULL);

  SwigPackedData* cdata = (SwigPackedData*) malloc(sizeof(SwigPackedData));
  cdata->data = data;
  cdata->size = size;
  cdata->type = type;

  JSObjectSetPrivate(result, cdata);

  return result;
}

/*  SwigPackedData wrappers  */

void _wrap_SwigPackedData_delete(JSObjectRef obj)
{
  SwigPackedData* cdata = (SwigPackedData*) JSObjectGetPrivate(obj);
  if (cdata) {
    free(cdata->data);
  }
}

/* for C++ member pointers, ie, member methods */

#define SWIG_ConvertMember(obj, ptr, sz, ty)            SWIG_JSC_ConvertPacked(context, obj, ptr, sz, ty)
#define SWIG_NewMemberObj(ptr, sz, type)                SWIG_JSC_NewPackedObj(context, ptr, sz, type)


/* ---------------------------------------------------------------------------
 * Support for IN/OUTPUT typemaps (see Lib/typemaps/inoutlist.swg)
 *
 * ---------------------------------------------------------------------------*/

unsigned int SWIGJSC_ArrayLength(JSContextRef context, JSObjectRef arr) {
  static JSStringRef LENGTH = 0;
  JSValueRef exception = NULL;
  JSValueRef js_length;
  double length;

  if (LENGTH == 0) {
    LENGTH = JSStringCreateWithUTF8CString("length");
  }

  js_length = JSObjectGetProperty(context, arr, LENGTH, &exception);
  if (exception == 0 && JSValueIsNumber(context, js_length)) {
    length = JSValueToNumber(context, js_length, 0);
    return (unsigned int) length;
  } else {
    return 0;
  }
}

SWIGRUNTIME
JSValueRef SWIGJSC_AppendOutput(JSContextRef context, JSValueRef value, JSValueRef obj) {
  JSObjectRef arr;
  unsigned int length;

  if (JSValueIsUndefined(context, value)) {
    arr = JSObjectMakeArray(context, 0, 0, 0);
  } else {
    arr = JSValueToObject(context, value, 0);
  }

  length = SWIGJSC_ArrayLength(context, arr);
  JSObjectSetPropertyAtIndex(context, arr, length, obj, 0);
}