Commit 345eafda authored by rswindell's avatar rswindell
Browse files

Fixed (finally) JavaScript object initialization segfaults when the JS runtime

"max_bytes" value is insufficient for the number of configured items:
by defining dynamically created objects and arrays as properties of child
objects of the global object immediately after such objects are created,
they are "implicitly rooted", protecting them from (unexpected) garbage
collection. Now the initialization will simply fail with a nice "out of memory"
error. This was a long-standing bug that rarely occurred in the wild.
parent bf9aeb3f
......@@ -595,7 +595,7 @@ long sbbs_t::js_execfile(const char *cmd)
if(cfg.mods_dir[0]==0 || !fexistcase(path))
sprintf(path,"%s%s%s",cfg.exec_dir,fname,js_ext(fname));
} else
sprintf(path,"%s%s",fname,js_ext(fname));
SAFECOPY(path,fname);
if(!fexistcase(path)) {
errormsg(WHERE,ERR_OPEN,path,O_RDONLY);
......@@ -608,6 +608,9 @@ long sbbs_t::js_execfile(const char *cmd)
JSObject* argv=JS_NewArrayObject(js_cx, 0, NULL);
JS_DefineProperty(js_cx, js_scope, "argv", OBJECT_TO_JSVAL(argv)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
if(args!=NULL && argv!=NULL) {
while(*args) {
p=strchr(args,' ');
......@@ -626,8 +629,6 @@ long sbbs_t::js_execfile(const char *cmd)
args+=(strlen(args)+1);
}
}
JS_DefineProperty(js_cx, js_scope, "argv", OBJECT_TO_JSVAL(argv)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
JS_DefineProperty(js_cx, js_scope, "argc", INT_TO_JSVAL(argc)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
......
......@@ -657,11 +657,25 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
break;
}
/* file[] */
val=OBJECT_TO_JSVAL(file_array);
if(!JS_SetProperty(js_cx, parent, "file_list", &val)) {
lprintf("%04d !JavaScript FAILED to set file property",sock);
break;
}
if((dir_array=JS_NewArrayObject(js_cx, 0, NULL))==NULL) {
lprintf("%04d !JavaScript FAILED to create dir_array",sock);
break;
}
/* dir[] */
val=OBJECT_TO_JSVAL(dir_array);
if(!JS_SetProperty(js_cx, parent, "dir_list", &val)) {
lprintf("%04d !JavaScript FAILED to set dir property",sock);
break;
}
if(strcspn(startup->html_index_script,"/\\")==strlen(startup->html_index_script)) {
sprintf(spath,"%s%s",scfg.mods_dir,startup->html_index_script);
if(scfg.mods_dir[0]==0 || !fexist(spath))
......@@ -685,20 +699,6 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
break;
}
/* file[] */
val=OBJECT_TO_JSVAL(file_array);
if(!JS_SetProperty(js_cx, parent, "file_list", &val)) {
lprintf("%04d !JavaScript FAILED to set file property",sock);
break;
}
/* dir[] */
val=OBJECT_TO_JSVAL(dir_array);
if(!JS_SetProperty(js_cx, parent, "dir_list", &val)) {
lprintf("%04d !JavaScript FAILED to set dir property",sock);
break;
}
/* curlib */
if((lib_obj=JS_NewObject(js_cx, NULL, 0, NULL))==NULL) {
lprintf("%04d !JavaScript FAILED to create lib_obj",sock);
......
......@@ -1306,15 +1306,16 @@ JSObject* js_CreateConsoleObject(JSContext* cx, JSObject* parent)
if((color_list=JS_NewArrayObject(cx,0,NULL))==NULL)
return(NULL);
if(!JS_DefineProperty(cx, obj, "color_list", OBJECT_TO_JSVAL(color_list)
,NULL, NULL, 0))
return(NULL);
for(uint i=0;i<sbbs->cfg.total_colors;i++) {
jsval val=INT_TO_JSVAL(sbbs->cfg.color[i]);
if(!JS_SetElement(cx, color_list, i, &val))
return(NULL);
}
if(!JS_DefineProperty(cx, obj, "color_list", OBJECT_TO_JSVAL(color_list)
,NULL, NULL, 0))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,obj,"Controls the user's Telnet/RLogin terminal");
......
......@@ -104,6 +104,10 @@ JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_
if((alldirs=JS_NewObject(cx, NULL, NULL, areaobj))==NULL)
return(NULL);
val=OBJECT_TO_JSVAL(alldirs);
if(!JS_SetProperty(cx, areaobj, "dir", &val))
return(NULL);
JS_NewNumberValue(cx,cfg->min_dspace,&val);
if(!JS_SetProperty(cx, areaobj, "min_diskspace", &val))
return(NULL);
......@@ -138,6 +142,13 @@ JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_
if((libobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_GetArrayLength(cx, lib_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(libobj);
if(!JS_SetElement(cx, lib_list, index, &val))
return(NULL);
val=INT_TO_JSVAL(l);
if(!JS_SetProperty(cx, libobj, "number", &val))
return(NULL);
......@@ -186,6 +197,18 @@ JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_
if((dirobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_GetArrayLength(cx, dir_list, &index)) /* inexplicable exception here on Jul-6-2001 */
return(NULL); /* and again on Aug-7-2001 and Oct-21-2001 */
val=OBJECT_TO_JSVAL(dirobj);
if(!JS_SetElement(cx, dir_list, index, &val))
return(NULL);
/* Add as property (associative array element) */
if(!JS_DefineProperty(cx, alldirs, cfg->dir[d]->code, val
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
val=INT_TO_JSVAL(d);
if(!JS_SetProperty(cx, dirobj, "number", &val))
return(NULL);
......@@ -307,21 +330,6 @@ JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_
#ifdef _DEBUG
js_CreateArrayOfStrings(cx, dirobj, "_property_desc_list", dir_prop_desc, JSPROP_READONLY);
#endif
if(!JS_GetArrayLength(cx, dir_list, &index)) /* inexplicable exception here on Jul-6-2001 */
return(NULL); /* and again on Aug-7-2001 and Oct-21-2001 */
val=OBJECT_TO_JSVAL(dirobj);
if(!JS_SetElement(cx, dir_list, index, &val))
return(NULL);
/* Add as property (associative array element) */
if(!JS_DefineProperty(cx, alldirs, cfg->dir[d]->code, val
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,dirobj,"File Transfer Directories");
#endif
}
......@@ -329,20 +337,8 @@ JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_
#ifdef _DEBUG
js_CreateArrayOfStrings(cx, libobj, "_property_desc_list", lib_prop_desc, JSPROP_READONLY);
#endif
if(!JS_GetArrayLength(cx, lib_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(libobj);
if(!JS_SetElement(cx, lib_list, index, &val))
return(NULL);
}
val=OBJECT_TO_JSVAL(alldirs);
if(!JS_SetProperty(cx, areaobj, "dir", &val))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,alldirs,"Associative array of all directories (use internal code as index)");
JS_DefineProperty(cx,alldirs,"_dont_document",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY);
......
......@@ -99,11 +99,12 @@ js_load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((js_argv=JS_NewArrayObject(cx, 0, NULL)) == NULL)
return(JS_FALSE);
JS_DefineProperty(cx, obj, "argv", OBJECT_TO_JSVAL(js_argv)
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
for(i=1; i<argc; i++)
JS_SetElement(cx, js_argv, i-1, &argv[i]);
JS_DefineProperty(cx, obj, "argv", OBJECT_TO_JSVAL(js_argv)
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, obj, "argc", INT_TO_JSVAL(argc-1)
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
}
......
......@@ -207,6 +207,10 @@ JSObject* DLLCALL js_CreateMsgAreaObject(JSContext* cx, JSObject* parent, scfg_t
if((allsubs=JS_NewObject(cx, NULL, NULL, areaobj))==NULL)
return(NULL);
val=OBJECT_TO_JSVAL(allsubs);
if(!JS_SetProperty(cx, areaobj, "sub", &val))
return(NULL);
/* grp_list[] */
if((grp_list=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(NULL);
......@@ -227,6 +231,13 @@ JSObject* DLLCALL js_CreateMsgAreaObject(JSContext* cx, JSObject* parent, scfg_t
if((grpobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_GetArrayLength(cx, grp_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(grpobj);
if(!JS_SetElement(cx, grp_list, index, &val))
return(NULL);
val=INT_TO_JSVAL(l);
if(!JS_SetProperty(cx, grpobj, "number", &val))
return(NULL);
......@@ -268,6 +279,13 @@ JSObject* DLLCALL js_CreateMsgAreaObject(JSContext* cx, JSObject* parent, scfg_t
if((subobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_GetArrayLength(cx, sub_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(subobj);
if(!JS_SetElement(cx, sub_list, index, &val))
return(NULL);
if(!js_CreateMsgAreaProperties(cx, cfg, subobj, d))
return(NULL);
......@@ -321,13 +339,6 @@ JSObject* DLLCALL js_CreateMsgAreaObject(JSContext* cx, JSObject* parent, scfg_t
}
if(!JS_GetArrayLength(cx, sub_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(subobj);
if(!JS_SetElement(cx, sub_list, index, &val))
return(NULL);
/* Add as property (associative array element) */
if(!JS_DefineProperty(cx, allsubs, cfg->sub[d]->code, val
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
......@@ -343,18 +354,8 @@ JSObject* DLLCALL js_CreateMsgAreaObject(JSContext* cx, JSObject* parent, scfg_t
js_CreateArrayOfStrings(cx, grpobj, "_property_desc_list", msg_grp_prop_desc, JSPROP_READONLY);
#endif
if(!JS_GetArrayLength(cx, grp_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(grpobj);
if(!JS_SetElement(cx, grp_list, index, &val))
return(NULL);
}
val=OBJECT_TO_JSVAL(allsubs);
if(!JS_SetProperty(cx, areaobj, "sub", &val))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,allsubs,"Associative array of all sub-boards (use internal code as index)");
JS_DefineProperty(cx,allsubs,"_dont_document",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY);
......
......@@ -1618,6 +1618,10 @@ JSObject* DLLCALL js_CreateSystemObject(JSContext* cx, JSObject* parent
if((node_list=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(NULL);
if(!JS_DefineProperty(cx, sysobj, "node_list", OBJECT_TO_JSVAL(node_list)
, NULL, NULL, JSPROP_ENUMERATE))
return(NULL);
for(i=0;i<cfg->sys_nodes && i<cfg->sys_lastnode;i++) {
nodeobj = JS_NewObject(cx, &js_node_class, NULL, node_list);
......@@ -1643,10 +1647,6 @@ JSObject* DLLCALL js_CreateSystemObject(JSContext* cx, JSObject* parent
return(NULL);
}
if(!JS_DefineProperty(cx, sysobj, "node_list", OBJECT_TO_JSVAL(node_list)
, NULL, NULL, JSPROP_ENUMERATE))
return(NULL);
return(sysobj);
}
......
......@@ -184,6 +184,10 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if((allprog=JS_NewObject(cx,NULL,NULL,areaobj))==NULL)
return(NULL);
val=OBJECT_TO_JSVAL(allprog);
if(!JS_SetProperty(cx, areaobj, "prog", &val))
return(NULL);
/* sec_list[] */
if((sec_list=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(NULL);
......@@ -203,6 +207,13 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if((secobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_GetArrayLength(cx, sec_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(secobj);
if(!JS_SetElement(cx, sec_list, index, &val))
return(NULL);
val=INT_TO_JSVAL(l);
if(!JS_SetProperty(cx, secobj, "number", &val))
return(NULL);
......@@ -223,14 +234,14 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if((prog_list=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,secobj,"Online Program (door) Sections");
#endif
val=OBJECT_TO_JSVAL(prog_list);
if(!JS_SetProperty(cx, secobj, "prog_list", &val))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,secobj,"Online Program (door) Sections");
#endif
for(d=0;d<cfg->total_xtrns;d++) {
if(cfg->xtrn[d]->sec!=l)
continue;
......@@ -244,6 +255,18 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if((progobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_GetArrayLength(cx, prog_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(progobj);
if(!JS_SetElement(cx, prog_list, index, &val))
return(NULL);
/* Add as property (associative array element) */
if(!JS_DefineProperty(cx, allprog, cfg->xtrn[d]->code, val
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
if(!js_CreateXtrnProgProperties(cx, progobj, cfg->xtrn[d]))
return(NULL);
......@@ -262,18 +285,6 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if(!JS_SetProperty(cx, progobj, "can_run", &val))
return(NULL);
if(!JS_GetArrayLength(cx, prog_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(progobj);
if(!JS_SetElement(cx, prog_list, index, &val))
return(NULL);
/* Add as property (associative array element) */
if(!JS_DefineProperty(cx, allprog, cfg->xtrn[d]->code, val
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,progobj,"Online External Programs (doors)");
#endif
......@@ -283,19 +294,8 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
js_CreateArrayOfStrings(cx, secobj, "_property_desc_list", xtrn_sec_prop_desc, JSPROP_READONLY);
#endif
if(!JS_GetArrayLength(cx, sec_list, &index))
return(NULL);
val=OBJECT_TO_JSVAL(secobj);
if(!JS_SetElement(cx, sec_list, index, &val))
return(NULL);
}
val=OBJECT_TO_JSVAL(allprog);
if(!JS_SetProperty(cx, areaobj, "prog", &val))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,allprog,"Associative array of all external programs (use internal code as index)");
JS_DefineProperty(cx,allprog,"_dont_document",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY);
......@@ -305,11 +305,19 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if((event_array=JS_NewObject(cx,NULL,NULL,areaobj))==NULL)
return(NULL);
val=OBJECT_TO_JSVAL(event_array);
if(!JS_SetProperty(cx, areaobj, "event", &val))
return(NULL);
for(l=0;l<cfg->total_events;l++) {
if((eventobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_DefineProperty(cx, event_array, cfg->event[l]->code, OBJECT_TO_JSVAL(eventobj)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
if((js_str=JS_NewStringCopyZ(cx, cfg->event[l]->cmd))==NULL)
return(NULL);
JS_DefineProperty(cx, eventobj, "cmd", STRING_TO_JSVAL(js_str)
......@@ -344,16 +352,8 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
#ifdef _DEBUG
js_CreateArrayOfStrings(cx, eventobj, "_property_desc_list", event_prop_desc, JSPROP_READONLY);
#endif
if(!JS_DefineProperty(cx, event_array, cfg->event[l]->code, OBJECT_TO_JSVAL(eventobj)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
}
val=OBJECT_TO_JSVAL(event_array);
if(!JS_SetProperty(cx, areaobj, "event", &val))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,event_array,"Associative array of all timed events (use internal code as index)");
JS_DefineProperty(cx,event_array,"_assoc_array",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY);
......@@ -363,6 +363,10 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if((xedit_array=JS_NewObject(cx,NULL,NULL,areaobj))==NULL)
return(NULL);
val=OBJECT_TO_JSVAL(xedit_array);
if(!JS_SetProperty(cx, areaobj, "editor", &val))
return(NULL);
for(l=0;l<cfg->total_xedits;l++) {
#if 0
if(user==NULL && (*cfg->xedit[l]->ar)!=AR_NULL)
......@@ -374,6 +378,10 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
if((xeditobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
return(NULL);
if(!JS_DefineProperty(cx, xedit_array, cfg->xedit[l]->code, OBJECT_TO_JSVAL(xeditobj)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
if((js_str=JS_NewStringCopyZ(cx, cfg->xedit[l]->name))==NULL)
return(NULL);
JS_DefineProperty(cx, xeditobj, "name", STRING_TO_JSVAL(js_str)
......@@ -393,16 +401,8 @@ JSObject* DLLCALL js_CreateXtrnAreaObject(JSContext* cx, JSObject* parent, scfg_
#ifdef _DEBUG
js_CreateArrayOfStrings(cx, xeditobj, "_property_desc_list", xedit_prop_desc, JSPROP_READONLY);
#endif
if(!JS_DefineProperty(cx, xedit_array, cfg->xedit[l]->code, OBJECT_TO_JSVAL(xeditobj)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
return(NULL);
}
val=OBJECT_TO_JSVAL(xedit_array);
if(!JS_SetProperty(cx, areaobj, "editor", &val))
return(NULL);
#ifdef _DEBUG
js_DescribeObject(cx,xedit_array,"Associative array of all external editors (use internal code as index)");
JS_DefineProperty(cx,xedit_array,"_assoc_array",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY);
......
......@@ -531,6 +531,8 @@ long js_exec(const char *fname, char** args)
}
argv=JS_NewArrayObject(js_cx, 0, NULL);
JS_DefineProperty(js_cx, js_scope, "argv", OBJECT_TO_JSVAL(argv)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
for(argc=0;args[argc];argc++) {
arg = JS_NewStringCopyZ(js_cx, args[argc]);
......@@ -540,8 +542,6 @@ long js_exec(const char *fname, char** args)
if(!JS_SetElement(js_cx, argv, argc, &val))
break;
}
JS_DefineProperty(js_cx, js_scope, "argv", OBJECT_TO_JSVAL(argv)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
JS_DefineProperty(js_cx, js_scope, "argc", INT_TO_JSVAL(argc)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
......
......@@ -260,6 +260,10 @@ DLLCALL js_CreateArrayOfStrings(JSContext* cx, JSObject* parent, const char* nam
if((array=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(JS_FALSE);
if(!JS_DefineProperty(cx, parent, name, OBJECT_TO_JSVAL(array)
,NULL,NULL,flags))
return(JS_FALSE);
if(!JS_GetArrayLength(cx, array, &len))
return(JS_FALSE);
......@@ -271,8 +275,7 @@ DLLCALL js_CreateArrayOfStrings(JSContext* cx, JSObject* parent, const char* nam
break;
}
return(JS_DefineProperty(cx, parent, name, OBJECT_TO_JSVAL(array)
,NULL,NULL,flags));
return(JS_TRUE);
}
/* Convert from Synchronet-specific jsMethodSpec to JSAPI's JSFunctionSpec */
......@@ -345,6 +348,10 @@ DLLCALL js_DefineMethods(JSContext* cx, JSObject* obj, jsMethodSpec *funcs, BOOL
if((method_array=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(JS_FALSE);
if(!JS_DefineProperty(cx, obj, method_array_name, OBJECT_TO_JSVAL(method_array)
, NULL, NULL, 0))
return(JS_FALSE);
if(append)
if(!JS_GetArrayLength(cx, method_array, &len))
return(JS_FALSE);
......@@ -396,10 +403,6 @@ DLLCALL js_DefineMethods(JSContext* cx, JSObject* obj, jsMethodSpec *funcs, BOOL
return(JS_FALSE);
}
if(!JS_DefineProperty(cx, obj, method_array_name, OBJECT_TO_JSVAL(method_array)
, NULL, NULL, 0))
return(JS_FALSE);
return(JS_TRUE);
}
......
......@@ -767,6 +767,8 @@ static void js_init_cmdline(JSContext* js_cx, JSObject* js_obj, char* spath)
args=p+1;
}
argv=JS_NewArrayObject(js_cx, 0, NULL);
JS_DefineProperty(js_cx, js_obj, "argv", OBJECT_TO_JSVAL(argv)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
if(args!=NULL && argv!=NULL) {
while(*args) {
......@@ -786,8 +788,6 @@ static void js_init_cmdline(JSContext* js_cx, JSObject* js_obj, char* spath)
args+=(strlen(args)+1);
}
}
JS_DefineProperty(js_cx, js_obj, "argv", OBJECT_TO_JSVAL(argv)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
JS_DefineProperty(js_cx, js_obj, "argc", INT_TO_JSVAL(argc)
,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment