source: trunk/zoo-project/zoo-kernel/service_internal_js.c @ 364

Last change on this file since 364 was 364, checked in by djay, 10 years ago

Update to make ZOO-Kernel able to compile and run from Windows Platforms. A special thanks to Espen Messel, Knut Landmark and Benrd Härtwig for providing many patches that I can successfully apply on the SVN source tree and to Farkas for continuing requesting for ZOO-Kernel to run on Windows platforms privately and through the ZOO-Discuss mailing list.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 17.5 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2012 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#include "service_internal.h"
26
27static char dbg[1024];
28
29JSBool
30JSAlert(JSContext *cx, uintN argc, jsval *argv1)
31{
32  jsval *argv = JS_ARGV(cx,argv1);
33  int i=0;
34  JS_MaybeGC(cx);
35  for(i=0;i<argc;i++){
36    JSString* jsmsg = JS_ValueToString(cx,argv[i]);
37    fprintf(stderr,"[ZOO-API:JS] %s\n",JS_EncodeString(cx,jsmsg));
38  }
39  JS_MaybeGC(cx);
40 
41  return JS_TRUE;
42}
43
44JSBool
45JSLoadScripts(JSContext *cx, uintN argc, jsval *argv1)
46{
47  //map* request = JS_GetContextPrivate(cx);
48  //map* tmpm1=getMap(request,"metapath");
49  JS_MaybeGC(cx);
50
51  char ntmp[1024];
52  getcwd(ntmp,1024);
53
54  jsval *argv = JS_ARGV(cx,argv1);
55  int i=0;
56  JS_MaybeGC(cx);
57  for(i=0;i<argc;i++){
58    JSString* jsmsg = JS_ValueToString(cx,argv[i]);
59    char *filename = JSValToChar(cx,&argv[i]);
60    char *api0=(char*)malloc((strlen(ntmp)+strlen(filename)+2)*sizeof(char));
61    sprintf(api0,"%s/%s",ntmp,filename);
62#ifdef JS_DEBUG
63    fprintf(stderr,"Trying to load %s\n",api0);
64    fflush(stderr);
65#endif
66    JSObject *api_script1=loadZooApiFile(cx,JS_GetGlobalObject(cx),api0);
67  }
68  JS_MaybeGC(cx);
69  JS_SET_RVAL(cx, argv1, JSVAL_VOID);
70 
71  return JS_TRUE;
72}
73
74
75int zoo_js_support(maps** main_conf,map* request,service* s,
76                   maps **inputs,maps **outputs)
77{
78  maps* main=*main_conf;
79  maps* _inputs=*inputs;
80  maps* _outputs=*outputs;
81
82  /* The class of the global object. */
83  JSClass global_class = {
84    "global", JSCLASS_GLOBAL_FLAGS,
85    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
86    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
87    JSCLASS_NO_OPTIONAL_MEMBERS
88  };
89
90  /* JS variables. */
91  JSRuntime *rt;
92  JSContext *cx;
93  JSObject  *global;
94
95  /* Create a JS runtime. */
96  rt = JS_NewRuntime(8L * 1024L * 1024L);
97  if (rt == NULL)
98    return 1;
99 
100  /* Create a context. */
101  cx = JS_NewContext(rt,8192);
102  if (cx == NULL){
103    return 1;
104  }
105  JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);
106  JS_SetVersion(cx, JSVERSION_LATEST);
107  JS_SetErrorReporter(cx, reportError);
108
109  /* Create the global object. */
110  //#ifdef JS_NewCompartmentAndGlobalObject
111  global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
112  //#else
113  //global = JS_NewObject(cx, &global_class, NULL,NULL);
114  //#endif
115
116  /* Populate the global object with the standard globals,
117     like Object and Array. */
118  if (!JS_InitStandardClasses(cx, global)){
119    return 1;
120  }
121
122  if (!JS_DefineFunction(cx, global, "ZOORequest", JSRequest, 4, 0))
123    return 1;
124  if (!JS_DefineFunction(cx, global, "ZOOUpdateStatus", JSUpdateStatus, 2, 0))
125    return 1;
126  if (!JS_DefineFunction(cx, global, "alert", JSAlert, 2, 0))
127    return 1; 
128  if (!JS_DefineFunction(cx, global, "importScripts", JSLoadScripts, 1, 0))
129    return 1;
130
131  /**
132   * Add private context object
133   */
134  void* cxPrivate = request;
135  JS_SetContextPrivate(cx,cxPrivate);
136   
137  map* tmpm1=getMap(request,"metapath");
138  char ntmp[1024];
139  getcwd(ntmp,1024);
140
141  /**
142   * Load the first part of the ZOO-API
143   */
144  char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+16);
145  sprintf(api0,"%s/%s/ZOO-proj4js.js",ntmp,tmpm1->value);
146#ifdef JS_DEBUG
147  fprintf(stderr,"Trying to load %s\n",api0);
148#endif
149  JSObject *api_script1=loadZooApiFile(cx,global,api0);
150  fflush(stderr);
151
152  char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+11);
153  sprintf(api1,"%s/%s/ZOO-api.js",ntmp,tmpm1->value);
154#ifdef JS_DEBUG
155  fprintf(stderr,"Trying to load %s\n",api1);
156#endif
157  JSObject *api_script2=loadZooApiFile(cx,global,api1);
158  fflush(stderr);
159
160  /* Your application code here. This may include JSAPI calls
161     to create your own custom JS objects and run scripts. */
162  maps* out=*outputs;
163  int res=SERVICE_FAILED;
164  maps* mc=*main_conf;
165  map* tmpm2=getMap(s->content,"serviceProvider");
166
167  char *filename=(char*)malloc(strlen(tmpm1->value)+strlen(tmpm2->value)+strlen(ntmp)+3);
168  sprintf(filename,"%s/%s/%s",ntmp,tmpm1->value,tmpm2->value);
169  filename[strlen(tmpm1->value)+strlen(tmpm2->value)+strlen(ntmp)+2]=0;
170#ifdef JS_DEBUG
171  fprintf(stderr,"FILENAME %s\n",filename);
172#endif
173  struct stat file_status;
174  stat(filename, &file_status);
175  char *source=(char*)malloc(file_status.st_size);
176  uint16 lineno;
177  jsval rval;
178  JSBool ok ;
179  JSObject *script = JS_CompileFile(cx, global, filename);
180  if(script!=NULL){
181    (void)JS_ExecuteScript(cx, global, script, &rval);
182  }
183  else{
184    char tmp1[1024];
185    sprintf(tmp1,"Unable to load JavaScript file %s",filename);
186    map* err=createMap("text",tmp1);
187    addMapToMap(&err,createMap("code","NoApplicableCode"));
188    printExceptionReportResponse(mc,err);
189    JS_DestroyContext(cx);
190    JS_DestroyRuntime(rt);
191    JS_ShutDown();
192    exit(-1);
193  }
194  /* Call a function in obj's scope. */
195  jsval argv[3];
196  JSObject *jsargv1=JSObject_FromMaps(cx,*main_conf);
197  argv[0] = OBJECT_TO_JSVAL(jsargv1);
198  JSObject *jsargv2=JSObject_FromMaps(cx,*inputs);
199  argv[1] = OBJECT_TO_JSVAL(jsargv2);
200  JSObject *jsargv3=JSObject_FromMaps(cx,*outputs);
201  argv[2] = OBJECT_TO_JSVAL(jsargv3);
202  jsval rval1=JSVAL_NULL;
203#ifdef JS_DEBUG
204  fprintf(stderr, "object %p\n", (void *) argv[2]);
205#endif
206
207  ok = JS_CallFunctionName(cx, global, s->name, 3, argv, &rval1);
208
209#ifdef JS_DEBUG
210  fprintf(stderr, "object %p\n", (void *) argv[2]);
211#endif
212
213  JSObject *d;
214  if (ok==JS_TRUE && JSVAL_IS_OBJECT(rval1)==JS_TRUE) {
215#ifdef JS_DEBUG
216    fprintf(stderr,"Function run sucessfully !\n");
217#endif
218    /* Should get a number back from the service function call. */
219    ok = JS_ValueToObject(cx, rval1, &d);
220  }else{
221    /* Unable to run JS function */
222    char tmp1[1024];
223    if(strlen(dbg)==0)
224      sprintf(dbg,"No result was found after the function call");
225    sprintf(tmp1,"Unable to run %s from the JavaScript file %s : \n %s",s->name,filename,dbg);
226#ifdef JS_DEBUG
227    fprintf(stderr,"%s",tmp1);
228#endif
229    map* err=createMap("text",tmp1);
230    addToMap(err,"code","NoApplicableCode");
231    printExceptionReportResponse(*main_conf,err);
232    freeMap(&err);
233    free(err);
234    JS_DestroyContext(cx);
235    JS_DestroyRuntime(rt);
236    JS_ShutDown();
237    // Should return -1 here but the unallocation won't work from zoo_service_loader.c line 1847
238    exit(-1);
239  }
240
241  jsval t=OBJECT_TO_JSVAL(d);
242  if(JS_IsArrayObject(cx,d)){
243#ifdef JS_DEBUG
244    fprintf(stderr,"An array was returned !\n");
245#endif
246    jsuint       len;
247    if((JS_GetArrayLength(cx, d, &len)==JS_FALSE)){
248#ifdef JS_DEBUG
249      fprintf(stderr,"outputs array is empty\n");
250#endif
251    }
252    jsval tmp1;
253    JSBool hasResult=JS_GetElement(cx,d,0,&tmp1);
254    res=JSVAL_TO_INT(tmp1);
255#ifdef JS_DEBUG
256    fprintf(stderr," * %d * \n",res);
257#endif
258    jsval tmp2;
259    JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
260    if(hasElement==JS_TRUE){
261          freeMaps(outputs);
262          free(*outputs);
263      *outputs=mapsFromJSObject(cx,tmp2);
264    }
265  }
266  else{
267#ifdef JS_DEBUG
268    fprintf(stderr,"The serice didn't return an array !\n");
269#endif
270    jsval tmp1;
271    JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1);
272    res=JSVAL_TO_INT(tmp1);
273
274#ifdef JS_DEBUG
275    fprintf(stderr," * %d * \n",res);
276#endif
277    jsval tmp2;
278    JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2);
279#ifdef JS_DEBUG
280    if(!hasElement)
281      fprintf(stderr,"No outputs property returned\n");
282    if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
283      fprintf(stderr,"outputs is array an as expected\n");
284    else
285      fprintf(stderr,"outputs is not an array as expected\n");
286#endif
287    *outputs=mapsFromJSObject(cx,tmp2);
288#ifdef JS_DEBUG
289    dumpMaps(*outputs);
290#endif
291  }
292  /* Cleanup. */
293  JS_DestroyContext(cx);
294  JS_DestroyRuntime(rt);
295  JS_ShutDown();
296#ifdef JS_DEBUG
297  fprintf(stderr,"Returned value %d\n",res);
298#endif
299  return res;
300}
301
302JSObject * loadZooApiFile(JSContext *cx,JSObject  *global, char* filename){
303  struct stat api_status;
304  int s=stat(filename, &api_status);
305  if(s==0){
306    jsval rval;
307    JSBool ok ;
308    JSObject *script = JS_CompileFile(cx, JS_GetGlobalObject(cx), filename);
309    if(script!=NULL){
310      (void)JS_ExecuteScript(cx, JS_GetGlobalObject(cx), script, &rval);
311#ifdef JS_DEBUG
312      fprintf(stderr,"**************\n%s correctly loaded\n**************\n",filename);
313#endif
314      return script;
315    }
316#ifdef JS_DEBUG
317    else
318      fprintf(stderr,"\n**************\nUnable to run %s\n**************\n",filename);
319#endif
320  }
321#ifdef JS_DEBUG
322  else
323    fprintf(stderr,"\n**************\nUnable to load %s\n**************\n",filename);
324#endif
325  return NULL;
326}
327
328JSObject* JSObject_FromMaps(JSContext *cx,maps* t){
329
330  JSObject* res=JS_NewObject(cx, NULL, NULL, NULL);
331  //JSObject *res = JS_NewArrayObject(cx, 0, NULL);
332  if(res==NULL)
333    fprintf(stderr,"Array Object is NULL!\n");
334  maps* tmp=t;
335
336  while(tmp!=NULL){
337    jsuint len;
338    JSObject* res1=JS_NewObject(cx, NULL, NULL, NULL);
339    JSObject *pval=JSObject_FromMap(cx,tmp->content);
340    jsval pvalj=OBJECT_TO_JSVAL(pval);
341    JS_SetProperty(cx, res, tmp->name, &pvalj);
342
343#ifdef JS_DEBUG
344    fprintf(stderr,"Length of the Array %d, element : %s added \n",len,tmp->name);
345#endif
346    tmp=tmp->next;
347  } 
348  return res;
349}
350
351JSObject* JSObject_FromMap(JSContext *cx,map* t){
352  JSObject* res=JS_NewObject(cx, NULL, NULL, NULL);
353  jsval resf =  OBJECT_TO_JSVAL(res);
354  map* tmpm=t;
355  map* isArray=getMap(t,"isArray");
356  map* isBinary=getMap(t,"size");
357  map* tmap=getMapType(t);
358#ifdef DEBUG
359  if(tmap==NULL)
360    fprintf(stderr,"tmap is null !\n");
361  else
362    fprintf(stderr,"tmap is not null ! (%s = %s)\n",tmap->name,tmap->value);
363#endif
364  /* Avoid gesture of binary content which failed due to strlen function use */
365  if(isBinary!=NULL){
366    return res;
367  }
368  while(tmpm!=NULL){
369    if(isArray==NULL || strncasecmp(tmpm->name,"value",5)!=0 || 
370       (tmap!=NULL && strncasecmp(tmpm->name,tmap->name,strlen(tmap->name))!=0)){
371      jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm->value,strlen(tmpm->value)));
372      JS_SetProperty(cx, res, tmpm->name,&jsstr);
373#ifdef JS_DEBUG
374      fprintf(stderr,"%s => %s\n",tmpm->name,tmpm->value);
375#endif
376    }
377    tmpm=tmpm->next;
378  }
379  if(isArray!=NULL){
380    map* len=getMap(t,"length");
381    int cnt=atoi(len->value);
382    JSObject* values=JS_NewArrayObject( cx, cnt, NULL );
383    JSObject* mvalues=JS_NewArrayObject( cx, cnt, NULL );
384    map *tmpm1,*tmpm2;
385    int i=0;
386    for(i=0;i<cnt;i++){
387      tmpm1=getMapArray(t,"value",i);
388      tmpm2=getMapArray(t,tmap->name,i);
389      if(tmpm1!=NULL){
390        jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm1->value,strlen(tmpm1->value)));
391        JS_SetElement( cx, values, i, &jsstr );
392      }
393      if(tmpm2!=NULL){
394        jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm2->value,strlen(tmpm2->value)));
395        JS_SetElement( cx, mvalues, i, &jsstr );
396      }
397    }
398    jsval jvalues=OBJECT_TO_JSVAL(values);
399    jsval jmvalues=OBJECT_TO_JSVAL(mvalues);
400    JS_SetProperty(cx, res,"value",&jvalues);
401    JS_SetProperty(cx, res,tmap->name,&jmvalues);
402  }
403  return res;
404}
405
406maps* mapsFromJSObject(JSContext *cx,jsval t){
407  maps *res=NULL;
408  maps *tres=NULL;
409  jsint oi=0;
410  JSObject* tt=JSVAL_TO_OBJECT(t);
411  if(JS_IsArrayObject(cx,tt)){
412#ifdef JS_DEBUG
413    fprintf(stderr,"Is finally an array !\n");
414#endif
415  }
416  else{
417#ifdef JS_DEBUG
418    fprintf(stderr,"Is not an array !\n");
419#endif
420    JSIdArray *idp=JS_Enumerate(cx,tt);
421    if(idp!=NULL) {
422      int index;
423      jsdouble argNum;
424#ifdef JS_DEBUG
425      fprintf(stderr,"Properties length :  %d \n",idp->length);
426#endif
427     
428      for (index=0,argNum=idp->length;index<argNum;index++) { 
429        jsval id = idp->vector[index];
430        jsval vp;
431        JSString* str; 
432        JS_IdToValue(cx,id,&vp);
433        char *c, *tmp;
434        JSString *jsmsg;
435        size_t len1;
436        jsmsg = JS_ValueToString(cx,vp);
437        len1 = JS_GetStringLength(jsmsg);
438
439        tres=(maps*)malloc(MAPS_SIZE);
440        tres->name=strdup(JS_EncodeString(cx,jsmsg));
441        tres->content=NULL;
442        tres->next=NULL;
443
444        jsval nvp=JSVAL_NULL;
445        if((JS_GetProperty(cx, tt, JS_EncodeString(cx,jsmsg), &nvp)==JS_FALSE)){
446#ifdef JS_DEBUG
447          fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,JS_EncodeString(cx,jsmsg));
448#endif
449        }
450       
451        JSObject *nvp1=JSVAL_TO_OBJECT(JSVAL_NULL);
452        JS_ValueToObject(cx,nvp,&nvp1);
453        jsval nvp1j=OBJECT_TO_JSVAL(nvp1);
454        if(JSVAL_IS_OBJECT(nvp1j)){
455          tres->content=mapFromJSObject(cx,nvp1j);
456        }
457
458        if(res==NULL)
459          res=dupMaps(&tres);
460        else
461          addMapsToMaps(&res,tres);
462        freeMaps(&tres);
463        free(tres);
464        tres=NULL;
465       
466       
467      }
468    }
469  }
470
471  jsuint len;
472  JSBool hasLen=JS_GetArrayLength(cx, tt, &len);
473  if(hasLen==JS_FALSE){
474#ifdef JS_DEBUG
475    fprintf(stderr,"outputs array is empty\n");
476#endif
477  }
478#ifdef JS_DEBUG
479  fprintf(stderr,"outputs array length : %d\n",len);
480#endif
481  for(oi=0;oi < len;oi++){
482#ifdef JS_DEBUG
483    fprintf(stderr,"outputs array length : %d step %d \n",len,oi);
484#endif
485    jsval tmp1;
486    JSBool hasElement=JS_GetElement(cx,tt,oi,&tmp1);
487    JSObject *otmp1=JSVAL_TO_OBJECT(tmp1);
488    JSIdArray *idp=JS_Enumerate(cx,otmp1);
489    if(idp!=NULL) {
490      int index;
491      jsdouble argNum;
492#ifdef JS_DEBUG
493      fprintf(stderr,"Properties length :  %d \n",idp->length);
494#endif
495      tres=(maps*)malloc(MAPS_SIZE);
496      tres->name=NULL;
497      tres->content=NULL;
498      tres->next=NULL;
499
500      for (index=0,argNum=idp->length;index<argNum;index++) { 
501        jsval id = idp->vector[index];
502        jsval vp;
503        JSString* str; 
504        JS_IdToValue(cx,id,&vp);
505        char *c, *tmp;
506        JSString *jsmsg;
507        size_t len1;
508        jsmsg = JS_ValueToString(cx,vp);
509        len1 = JS_GetStringLength(jsmsg);
510#ifdef JS_DEBUG
511        fprintf(stderr,"Enumerate id : %d => %s\n",oi,JS_EncodeString(cx,jsmsg));
512#endif
513        jsval nvp=JSVAL_NULL;
514        if((JS_GetProperty(cx, JSVAL_TO_OBJECT(tmp1), JS_EncodeString(cx,jsmsg), &nvp)==JS_FALSE)){
515#ifdef JS_DEBUG
516          fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,JS_EncodeString(cx,jsmsg));
517#endif
518        }
519       
520        if(JSVAL_IS_OBJECT(nvp)){
521#ifdef JS_DEBUG
522          fprintf(stderr,"JSVAL NVP IS OBJECT\n");
523#endif
524        }
525
526        JSObject *nvp1=JSVAL_TO_OBJECT(JSVAL_NULL);
527        JS_ValueToObject(cx,nvp,&nvp1);
528        jsval nvp1j=OBJECT_TO_JSVAL(nvp1);
529        if(JSVAL_IS_OBJECT(nvp1j)){
530          JSString *jsmsg1;
531          JSObject *nvp2=JSVAL_TO_OBJECT(JSVAL_NULL);
532          jsmsg1 = JS_ValueToString(cx,nvp1j);
533          len1 = JS_GetStringLength(jsmsg1);
534#ifdef JS_DEBUG
535          fprintf(stderr,"JSVAL NVP1J IS OBJECT %s = %s\n",JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
536#endif
537          if(strcasecmp(JS_EncodeString(cx,jsmsg1),"[object Object]")==0){
538            tres->name=strdup(JS_EncodeString(cx,jsmsg));
539            tres->content=mapFromJSObject(cx,nvp1j);
540          }
541          else
542            if(strcasecmp(JS_EncodeString(cx,jsmsg),"name")==0){
543              tres->name=strdup(JS_EncodeString(cx,jsmsg1));
544            }
545            else{
546              if(tres->content==NULL)
547                tres->content=createMap(JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
548              else
549                addToMap(tres->content,JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
550            }
551        }
552#ifdef JS_DEBUG
553        else
554          fprintf(stderr,"JSVAL NVP1J IS NOT OBJECT !!\n");
555#endif
556
557      }
558#ifdef JS_DEBUG
559      dumpMaps(tres);
560#endif
561      if(res==NULL)
562        res=dupMaps(&tres);
563      else
564        addMapsToMaps(&res,tres);
565      freeMaps(&tres);
566      free(tres);
567      tres=NULL;
568
569    }
570  }
571#ifdef JS_DEBUG
572  dumpMaps(res);
573#endif
574  return res;
575}
576
577map* mapFromJSObject(JSContext *cx,jsval t){
578  map *res=NULL;
579  JSIdArray *idp=JS_Enumerate(cx,JSVAL_TO_OBJECT(t));
580#ifdef JS_DEBUG
581  fprintf(stderr,"Properties %p\n",(void*)t);
582#endif
583  if(idp!=NULL) {
584    int index;
585    jsdouble argNum;
586#ifdef JS_DEBUG
587    fprintf(stderr,"Properties length :  %d \n",idp->length);
588#endif
589    for (index=0,argNum=idp->length;index<argNum;index++) { 
590      jsval id = idp->vector[index];
591      jsval vp;
592      JSString* str; 
593      JS_IdToValue(cx,id,&vp);
594      char *c, *tmp;
595      JSString *jsmsg,*jsmsg1;
596      size_t len,len1;
597      jsmsg = JS_ValueToString(cx,vp);
598      len = JS_GetStringLength(jsmsg);
599      jsval nvp;
600      JS_GetProperty(cx, JSVAL_TO_OBJECT(t), JS_EncodeString(cx,jsmsg), &nvp);
601      jsmsg1 = JS_ValueToString(cx,nvp);
602      len1 = JS_GetStringLength(jsmsg1);
603#ifdef JS_DEBUG
604      fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
605#endif
606      if(res!=NULL){
607#ifdef JS_DEBUG
608        fprintf(stderr,"%s - %s\n",JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
609#endif
610        addToMap(res,JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
611      }
612      else{
613        res=createMap(JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
614        res->next=NULL;
615      }
616#ifdef JS_DEBUG
617      dumpMap(res);
618#endif
619    }
620  }
621#ifdef JS_DEBUG
622  dumpMap(res);
623#endif
624  return res;
625}
626
627/* The error reporter callback. */
628void reportError(JSContext *cx, const char *message, JSErrorReport *report)
629{
630  sprintf(dbg,"%s:%u:%s\n",
631          report->filename ? report->filename : "<no filename>",
632          (unsigned int) report->lineno,
633          message);
634#ifdef JS_DEBUG
635  fprintf(stderr,"%s",dbg);
636#endif
637  fflush(stderr);
638}
639
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png