Changeset 383 for trunk/zoo-project/zoo-kernel/service_internal_js.c
- Timestamp:
- Jan 8, 2013, 3:54:57 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal_js.c
r377 r383 25 25 #include "service_internal.h" 26 26 27 #ifndef JSCLASS_GLOBAL_FLAGS 28 #define JSCLSAS_GLOBAL_FLAGS 0 29 #endif 30 27 31 static char dbg[1024]; 28 32 … … 81 85 82 86 /* The class of the global object. */ 83 JSClass global_class 87 JSClass global_class= { 84 88 "global", JSCLASS_GLOBAL_FLAGS, 85 89 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, … … 99 103 100 104 /* Create a context. */ 101 cx = JS_NewContext(rt,8192 );105 cx = JS_NewContext(rt,81920); 102 106 if (cx == NULL){ 103 107 return 1; 104 108 } 105 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);109 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); 106 110 JS_SetVersion(cx, JSVERSION_LATEST); 107 111 JS_SetErrorReporter(cx, reportError); … … 111 115 global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); 112 116 //#else 113 //global = JS_NewObject(cx, &global_class, NULL,NULL);117 //global = JS_NewObject(cx, &global_class, 0,0); 114 118 //#endif 115 119 … … 150 154 * Load the first part of the ZOO-API 151 155 */ 152 char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+1 6);156 char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+17); 153 157 sprintf(api0,"%s/%s/ZOO-proj4js.js",ntmp,tmpm1->value); 154 158 #ifdef JS_DEBUG … … 158 162 fflush(stderr); 159 163 160 char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+1 1);164 char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+13); 161 165 sprintf(api1,"%s/%s/ZOO-api.js",ntmp,tmpm1->value); 162 166 #ifdef JS_DEBUG … … 200 204 exit(-1); 201 205 } 206 202 207 /* Call a function in obj's scope. */ 203 208 jsval argv[3]; … … 264 269 fprintf(stderr," * %d * \n",res); 265 270 #endif 266 jsval tmp2; 267 JSBool hasElement=JS_GetElement(cx,d,1,&tmp2); 268 if(hasElement==JS_TRUE){ 269 freeMaps(outputs); 270 free(*outputs); 271 *outputs=mapsFromJSObject(cx,tmp2); 272 } 271 if(res==SERVICE_SUCCEEDED){ 272 jsval tmp2; 273 JSBool hasElement=JS_GetElement(cx,d,1,&tmp2); 274 if(hasElement==JS_TRUE){ 275 freeMaps(outputs); 276 free(*outputs); 277 *outputs=mapsFromJSObject(cx,tmp2); 278 } 279 }else{ 280 jsval tmp3; 281 JSBool hasConf=JS_GetElement(cx,d,1,&tmp3); 282 if(hasConf==JS_TRUE){ 283 freeMaps(main_conf); 284 free(*main_conf); 285 *main_conf=mapsFromJSObject(cx,tmp3); 286 } 287 } 288 273 289 } 274 290 else{ 275 291 #ifdef JS_DEBUG 276 fprintf(stderr,"The serice didn't return an array !\n"); 277 #endif 292 fprintf(stderr,"The service didn't return an array !\n"); 293 #endif 294 /** 295 * Extract result 296 */ 278 297 jsval tmp1; 279 298 JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1); … … 283 302 fprintf(stderr," * %d * \n",res); 284 303 #endif 304 /** 305 * Extract outputs when available. 306 */ 285 307 jsval tmp2; 286 308 JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2); 287 #ifdef JS_DEBUG 288 if(!hasElement) 309 if(!JSVAL_IS_VOID(tmp2) && hasElement==JS_TRUE){ 310 freeMaps(outputs); 311 free(*outputs); 312 *outputs=mapsFromJSObject(cx,tmp2); 313 } 314 JS_MaybeGC(cx); 315 #ifdef JS_DEBUG 316 if(JSVAL_IS_VOID(tmp2)) 289 317 fprintf(stderr,"No outputs property returned\n"); 290 if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2))) 291 fprintf(stderr,"outputs is array an as expected\n"); 292 else 293 fprintf(stderr,"outputs is not an array as expected\n"); 294 #endif 295 *outputs=mapsFromJSObject(cx,tmp2); 318 else{ 319 if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2))) 320 fprintf(stderr,"outputs is an array as expected\n"); 321 else 322 fprintf(stderr,"outputs is not an array as expected\n"); 323 } 324 JS_MaybeGC(cx); 325 #endif 326 327 /** 328 * Extract conf when available. 329 */ 330 jsval tmp3; 331 JSBool hasConf=JS_GetProperty(cx,d,"conf",&tmp3); 332 if(!JSVAL_IS_VOID(tmp3) && hasConf==JS_TRUE){ 333 freeMaps(main_conf); 334 free(*main_conf); 335 *main_conf=mapsFromJSObject(cx,tmp3); 336 } 337 JS_MaybeGC(cx); 338 296 339 #ifdef JS_DEBUG 297 340 dumpMaps(*outputs); … … 299 342 } 300 343 /* Cleanup. */ 344 JS_MaybeGC(cx); 301 345 JS_DestroyContext(cx); 302 346 JS_DestroyRuntime(rt); … … 479 523 jsuint len; 480 524 JSBool hasLen=JS_GetArrayLength(cx, tt, &len); 525 #ifdef JS_DEBUG 481 526 if(hasLen==JS_FALSE){ 482 #ifdef JS_DEBUG483 527 fprintf(stderr,"outputs array is empty\n"); 484 #endif 485 } 486 #ifdef JS_DEBUG 528 } 487 529 fprintf(stderr,"outputs array length : %d\n",len); 488 530 #endif … … 694 736 tmp1=JSValToChar(cx,&tmp); 695 737 #ifdef ULINET_DEBUG 738 curl_easy_setopt(handle.handle,CURLOPT_VERBOSE,1); 696 739 fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1); 697 740 #endif
Note: See TracChangeset
for help on using the changeset viewer.