comparison context.c @ 89:e77bc7c799e8

JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
author Atul Varma <varmaa@toolness.com>
date Sun, 09 Aug 2009 22:54:15 -0700
parents 345d4c0e3dd3
children 97d1faf02460
comparison
equal deleted inserted replaced
88:0b2970e8cd67 89:e77bc7c799e8
117 PYM_JSObject *object; 117 PYM_JSObject *object;
118 118
119 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) 119 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object))
120 return NULL; 120 return NULL;
121 121
122 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime);
123
122 JSObject *obj = object->obj; 124 JSObject *obj = object->obj;
123 125
124 if (JS_ObjectIsFunction(self->cx, obj)) { 126 if (JS_ObjectIsFunction(self->cx, obj)) {
125 jsval functionHolder; 127 jsval functionHolder;
126 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { 128 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) {
157 PYM_JSObject *object; 159 PYM_JSObject *object;
158 160
159 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) 161 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object))
160 return NULL; 162 return NULL;
161 163
164 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime);
165
162 JSObject *obj = object->obj; 166 JSObject *obj = object->obj;
163 167
164 if (JS_ObjectIsFunction(self->cx, obj)) { 168 if (JS_ObjectIsFunction(self->cx, obj)) {
165 jsval functionHolder; 169 jsval functionHolder;
166 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { 170 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) {
214 218
215 if (!PyArg_ParseTuple(args, "O!u", &PYM_JSObjectType, &object, 219 if (!PyArg_ParseTuple(args, "O!u", &PYM_JSObjectType, &object,
216 &string)) 220 &string))
217 return NULL; 221 return NULL;
218 222
223 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime);
224
219 JSString *jsString = JS_NewUCStringCopyZ(self->cx, 225 JSString *jsString = JS_NewUCStringCopyZ(self->cx,
220 (const jschar *) string); 226 (const jschar *) string);
221 if (jsString == NULL) { 227 if (jsString == NULL) {
222 PyErr_SetString(PYM_error, "JS_NewStringCopyZ() failed"); 228 PyErr_SetString(PYM_error, "JS_NewStringCopyZ() failed");
223 return NULL; 229 return NULL;
260 PYM_JSObject *object; 266 PYM_JSObject *object;
261 267
262 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) 268 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object))
263 return NULL; 269 return NULL;
264 270
271 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime);
272
265 if (!JS_InitStandardClasses(self->cx, object->obj)) { 273 if (!JS_InitStandardClasses(self->cx, object->obj)) {
266 PyErr_SetString(PYM_error, "JS_InitStandardClasses() failed"); 274 PyErr_SetString(PYM_error, "JS_InitStandardClasses() failed");
267 return NULL; 275 return NULL;
268 } 276 }
269 277
281 int lineNo; 289 int lineNo;
282 290
283 if (!PyArg_ParseTuple(args, "O!s#si", &PYM_JSObjectType, &object, 291 if (!PyArg_ParseTuple(args, "O!s#si", &PYM_JSObjectType, &object,
284 &source, &sourceLen, &filename, &lineNo)) 292 &source, &sourceLen, &filename, &lineNo))
285 return NULL; 293 return NULL;
294
295 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime);
286 296
287 jsval rval; 297 jsval rval;
288 JSBool result; 298 JSBool result;
289 Py_BEGIN_ALLOW_THREADS; 299 Py_BEGIN_ALLOW_THREADS;
290 result = JS_EvaluateScript(self->cx, object->obj, source, sourceLen, 300 result = JS_EvaluateScript(self->cx, object->obj, source, sourceLen,
310 320
311 if (!PyArg_ParseTuple(args, "O!sO", &PYM_JSObjectType, &object, 321 if (!PyArg_ParseTuple(args, "O!sO", &PYM_JSObjectType, &object,
312 &name, &value)) 322 &name, &value))
313 return NULL; 323 return NULL;
314 324
325 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime);
315 jsval jsValue; 326 jsval jsValue;
316 327
317 if (PYM_pyObjectToJsval(self, value, &jsValue) == -1) 328 if (PYM_pyObjectToJsval(self, value, &jsValue) == -1)
318 return NULL; 329 return NULL;
319 330
339 350
340 if (!PyArg_ParseTuple(args, "O!O!O!", &PYM_JSObjectType, &obj, 351 if (!PyArg_ParseTuple(args, "O!O!O!", &PYM_JSObjectType, &obj,
341 &PYM_JSFunctionType, &fun, 352 &PYM_JSFunctionType, &fun,
342 &PyTuple_Type, &funcArgs)) 353 &PyTuple_Type, &funcArgs))
343 return NULL; 354 return NULL;
355
356 PYM_ENSURE_RUNTIME_MATCH(self->runtime, obj->runtime);
357 PYM_ENSURE_RUNTIME_MATCH(self->runtime, fun->base.runtime);
344 358
345 uintN argc = PyTuple_Size(funcArgs); 359 uintN argc = PyTuple_Size(funcArgs);
346 jsval argv[argc]; 360 jsval argv[argc];
347 jsval *currArg = argv; 361 jsval *currArg = argv;
348 362