3 * @brief Embedded JavaScript (EJS)
4 * @overview Main module interface logic.
5 * @remarks The initialization code must be run single-threaded. Includes:
8 /********************************* Copyright **********************************/
12 * Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved.
14 * This software is distributed under commercial and open source licenses.
15 * You may use the GPL open source license described below or you may acquire
16 * a commercial license from Mbedthis Software. You agree to be fully bound
17 * by the terms of either license. Consult the LICENSE.TXT distributed with
18 * this software for full details.
20 * This software is open source; you can redistribute it and/or modify it
21 * under the terms of the GNU General Public License as published by the
22 * Free Software Foundation; either version 2 of the License, or (at your
23 * option) any later version. See the GNU General Public License for more
24 * details at: http://www.mbedthis.com/downloads/gplLicense.html
26 * This program is distributed WITHOUT ANY WARRANTY; without even the
27 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29 * This GPL license does NOT permit incorporating this software into
30 * proprietary programs. If you are unable to comply with the GPL, you must
31 * acquire a commercial license to use this software. Commercial licenses
32 * for this software and support services are available from Mbedthis
33 * Software at http://www.mbedthis.com
37 /********************************** Includes **********************************/
43 /************************************* Code ***********************************/
45 * Initialize the EJS subsystem
48 EjsService *ejsOpenService(MprCtx ctx)
53 service = mprAllocTypeZeroed(ctx, EjsService);
55 mprError(ctx, MPR_LOC, "Can't allocate service memory");
59 interp = ejsCreateInterp(service, 0, 0, 0, 1);
61 mprError(ctx, MPR_LOC, "Can't create master interpreter");
65 service->master = interp;
68 * Restore the default GC settings for the master interpreter.
69 * ejsCreateInterp will have initialized them.
71 ejsGCInit(interp, EJS_DEFAULT_OBJ_INC, EJS_DEFAULT_PROP_INC,
72 EJS_DEFAULT_VAR_INC, EJS_DEFAULT_STR_INC);
75 * Save the default interpreter and global class for all to access
76 * MOB -- don't store these. Store the service
78 mprSetKeyValue(interp, "ejsMaster", interp);
79 mprSetKeyValue(interp, "ejsGlobalClass", interp->global);
82 * Once the Object class is created, this routine will also make the
83 * Global class a subclass of Object.
85 if (ejsDefineObjectClass(interp) < 0) {
86 mprError(ctx, MPR_LOC, "Can't define EJS object class");
92 * Create all the standard classes
94 if (ejsDefineStandardClasses(interp) < 0) {
95 mprError(ctx, MPR_LOC, "Can't define EJS standard classes");
100 if (ejsDefineSystemClasses(interp) < 0) {
101 mprError(ctx, MPR_LOC, "Can't define EJS system classes");
106 if (ejsCreateObjectModel(interp) < 0) {
107 mprError(ctx, MPR_LOC, "Can't create EJS object model");
112 #if UNUSED && BLD_FEATURE_ALLOC_STATS
115 mprLog(ctx, 0, "Obj %d, Var %d, Prop %d\n", sizeof(EjsObj), sizeof(EjsVar),
116 sizeof(EjsProperty));
117 mprLog(ctx, 0, "GCLink %d\n", sizeof(EjsGCLink));
118 mprLog(ctx, 0, "objectState %d\n", (uint) &v.objectState - (uint) &v);
125 /******************************************************************************/
127 * Close down the EJS Service
130 void ejsCloseService(EjsService *sp, bool doStats)
139 ejsTermSystemClasses(ep);
142 ejsFreeVar(ep, sp->globalClass);
144 #if BLD_FEATURE_ALLOC_STATS
146 mprLog(sp, 0, "GC Statistics for the Global Interpreter");
149 ejsDestroyInterp(ep, doStats);
152 mprRemoveKeyValue(sp, "ejsMaster");
153 mprRemoveKeyValue(sp, "ejsGlobalClass");
158 /******************************************************************************/
160 Ejs *ejsGetMasterInterp(EjsService *sp)
165 /******************************************************************************/
166 #if BLD_FEATURE_MULTITHREAD
168 int ejsSetServiceLocks(EjsService *sp, EjsLockFn lock, EjsUnlockFn unlock,
180 /******************************************************************************/
182 * Create and initialize an EJS interpreter. Interpreters have a global object
183 * that has the service global class set as a base class. This way, it
184 * inherits all the desired global properties, methods and classes.
186 * The primary and alternate handles are provided to C methods depending on
187 * the flags provided when the C methods are defined. The global variable
188 * (optionally) defines a predefined global variable space.
191 Ejs *ejsCreateInterp(EjsService *sp, void *primaryHandle, void *altHandle,
192 EjsVar *global, bool useOwnSlab)
198 ep = mprAllocTypeZeroed(sp, Ejs);
204 ep->stkPtr = &ep->stack[EJS_MAX_STACK];
207 ep->primaryHandle = primaryHandle;
208 ep->altHandle = altHandle;
211 ep->objectClass = sp->master->objectClass;
215 ep->slabs = (EjsSlab*) mprAllocZeroed(ep, sizeof(EjsSlab) *
217 ep->slabAllocContext = ep;
220 ep->slabs = sp->master->slabs;
221 ep->slabAllocContext = sp->master;
222 ep->flags |= EJS_FLAGS_SHARED_SLAB;
225 ep->frames = mprCreateItemArray(ep, EJS_INC_FRAMES, EJS_MAX_FRAMES);
226 if (ep->frames == 0) {
231 ejsGCInit(ep, EJS_OBJ_INC, EJS_PROP_INC, EJS_VAR_INC, EJS_STR_INC);
233 if (sp->globalClass == 0) {
235 * Only do this for the Global interpreter. Create a global class
236 * (prototype) object. This is base class from which all global
237 * spaces will inherit.
239 sp->globalClass = ejsCreateObjVar(ep);
240 if (sp->globalClass == 0) {
244 ejsSetClassName(ep, sp->globalClass, "Global");
245 global = sp->globalClass;
250 * The default interpreter uses the Global class as its global
253 ep->global = ejsDupVar(ep, global, EJS_SHALLOW_COPY);
254 if (ep->global == 0) {
258 if (ep->global->objectState != sp->globalClass->objectState) {
259 ejsSetBaseClass(ep->global, sp->globalClass);
264 * Use the global class as our global so we can find the object class
266 baseClass = ejsGetClass(ep, sp->globalClass, "Object");
268 ep->global = ejsCreateSimpleObjUsingClass(ep, baseClass);
269 if (ep->global == 0) {
275 * Override the base class and set to the master Global class
277 ejsSetBaseClass(ep->global, sp->globalClass);
280 ep->global = ejsCreateObjVar(ep);
285 * The "global" variable points to the global space
287 pp = ejsSetProperty(ep, ep->global, "global", ep->global);
292 ejsMakePropertyEnumerable(pp, 0);
295 * The "Global" variable points to the Global class
297 pp = ejsSetProperty(ep, ep->global, "Global", sp->globalClass);
302 ejsMakePropertyEnumerable(pp, 0);
304 ep->local = ejsDupVar(ep, ep->global, EJS_SHALLOW_COPY);
305 if (ep->frames == 0 || ep->global == 0 || ep->local == 0) {
309 ejsSetVarName(ep, ep->local, "topLevelLocal");
311 if (mprAddItem(ep->frames, ep->global) < 0 ||
312 mprAddItem(ep->frames, ep->local) < 0) {
317 ep->result = ejsCreateUndefinedVar(ep);
318 if (ep->result == 0) {
326 /******************************************************************************/
328 * Close an EJS interpreter
331 void ejsDestroyInterp(Ejs *ep, bool doStats)
333 ejsCleanInterp(ep, doStats);
338 /******************************************************************************/
340 * Clean an EJS interpreter of all allocated variables, but DONT destroy.
341 * We use this rather than DestroyInterp so we delay freeing the Ejs struct
342 * until after the service is closed.
345 void ejsCleanInterp(Ejs *ep, bool doStats)
350 ejsDeleteProperty(ep, ep->local, "global");
351 ejsDeleteProperty(ep, ep->global, "global");
355 ejsFreeVar(ep, ep->local);
359 ejsFreeVar(ep, ep->global);
363 ejsFreeVar(ep, ep->result);
366 if (ep->castAlloc && ep->castTemp) {
367 mprFree(ep->castTemp);
371 for (i = ep->frames->length - 1; i >= 0; i--) {
372 mprRemoveItemByIndex(ep->frames, i);
380 #if BLD_FEATURE_ALLOC_STATS
382 mprLog(ep, 0, "GC Statistics for Interpreter (0x%X)", (uint) ep);
386 * Cleanup before printing the alloc report
388 ejsSetGCDebugLevel(ep, 3);
389 ejsCollectGarbage(ep, -1);
393 * If we are the master, dump objects
395 if (ep->service->master == ep) {
400 #if BLD_FEATURE_ALLOC_STATS
402 * Print an alloc report. 1 == do leak report
404 ejsPrintAllocReport(ep, 1);
409 * Must collect garbage here incase sharing interpreters with the
410 * master. If we don't, the mprFree later in DestroyInterp will free
411 * all memory and when the master does GC --> crash.
413 ejsCollectGarbage(ep, -1);
417 /******************************************************************************/
419 * Evaluate an EJS script file. This will evaluate the script at the current
420 * context. Ie. if inside a function, declarations will be local.
423 int ejsEvalFile(Ejs *ep, const char *path, EjsVar *result)
431 mprAssert(path && *path);
433 if ((file = mprOpen(ep, path, O_RDONLY | O_BINARY, 0666)) == 0) {
434 ejsError(ep, EJS_IO_ERROR, "Can't open %s", path);
438 if (mprGetFileInfo(ep, path, &info) < 0) {
439 ejsError(ep, EJS_IO_ERROR, "Can't get file info for %s", path);
443 if ((script = (char*) mprAlloc(ep, info.size + 1)) == NULL) {
444 ejsError(ep, "MemoryError", "Cant malloc %d", (int) info.size);
448 if (mprRead(file, script, info.size) != (int) info.size) {
450 ejsError(ep, EJS_IO_ERROR, "Error reading %s", path);
454 script[info.size] = '\0';
456 saveFileName = ep->fileName;
457 ep->fileName = mprStrdup(ep, path);
459 rc = ejsEvalScript(ep, script, result);
462 mprFree(ep->fileName);
463 ep->fileName = saveFileName;
475 /******************************************************************************/
477 * Create a new variable scope block. This pushes the old local frame down
478 * the stack and creates a new local variables frame.
481 int ejsOpenBlock(Ejs *ep)
486 ep->local = ejsCreateSimpleObj(ep, "Object");
487 ejsSetVarName(ep, ep->local, "local");
489 if (ep->local == 0) {
494 if (ep->frames->length > EJS_MAX_FRAMES && !ep->gotException) {
495 ejsError(ep, EJS_RANGE_ERROR, "Recursion too deep: Max depth %d",
501 * Must add to frames before ejsSetProperty which will make the object live
503 fid = mprAddItem(ep->frames, ep->local);
510 pp = ejsSetProperty(ep, ep->local, "local", ep->local);
511 ejsMakePropertyEnumerable(pp, 0);
516 /******************************************************************************/
518 * Set a new variable scope block. This pushes the old local frame down
519 * the stack and creates a new local variables frame.
522 int ejsSetBlock(Ejs *ep, EjsVar *local)
524 ep->local = ejsDupVar(ep, local, EJS_SHALLOW_COPY);
525 ejsMakeObjPermanent(ep->local, 1);
526 return mprAddItem(ep->frames, ep->local);
529 /******************************************************************************/
531 * Close a variable scope block opened via ejsOpenBlock. Pop back the old
532 * local variables frame.
535 int ejsCloseBlock(Ejs *ep, int fid)
537 mprAssert(ep->local >= 0);
540 mprAssert(ep->local == (EjsVar*) mprGetItem(ep->frames, fid));
544 ejsMakeObjPermanent(ep->local, 0);
545 ejsFreeVar(ep, ep->local);
548 mprRemoveItemByIndex(ep->frames, fid);
550 ep->local = (EjsVar*) mprGetItem(ep->frames,
551 mprGetItemCount(ep->frames) - 1);
556 /******************************************************************************/
558 * Create a new variable scope block and evaluate a script. All frames
559 * created during this context will be automatically deleted when complete.
560 * vp is optional. i.e. created local variables will be discarded
561 * when this routine returns.
564 int ejsEvalBlock(Ejs *ep, char *script, EjsVar *vp)
570 fid = ejsOpenBlock(ep);
575 rc = ejsEvalScript(ep, script, vp);
577 ejsCloseBlock(ep, fid);
582 /******************************************************************************/
584 * Parse and evaluate a EJS. The script is evaluated at the current context.
585 * Return the result in *vp. The result is "owned" by EJ and the caller
586 * must not free it. Returns -1 on errors and zero for success.
589 int ejsEvalScript(Ejs *ep, const char *script, EjsVar *vp)
593 ejsClearVar(ep, ep->result);
594 ep->gotException = 0;
601 * Allocate a new evaluation block, and save the old one
603 if (ejsLexOpenScript(ep, script) < 0) {
604 return MPR_ERR_MEMORY;
608 * Do the actual parsing and evaluation
610 ep->scriptStatus = 0;
613 state = ejsParse(ep, EJS_STATE_BEGIN, EJS_FLAGS_EXE);
615 if (state == EJS_STATE_RET) {
616 state = EJS_STATE_EOF;
618 } while (state != EJS_STATE_EOF && state != EJS_STATE_ERR);
620 ejsLexCloseScript(ep);
622 if (state == EJS_STATE_ERR) {
627 /* Caller must not free. */
631 return ep->scriptStatus;
634 /******************************************************************************/
636 void ejsSetFileName(Ejs *ep, const char *fileName)
638 mprFree(ep->fileName);
639 ep->fileName = mprStrdup(ep, fileName);
642 /******************************************************************************/
644 * Format the stack backtrace
647 char *ejsFormatStack(Ejs* ep)
661 while (ip && frame < EJS_MAX_BACKTRACE) {
662 char *traceLine, *newErrbuf, *line;
663 for (line = ip->line; *line && isspace(*line); line++) {
666 mprAllocSprintf(MPR_LOC_ARGS(ep), &traceLine, MPR_MAX_STRING,
667 " [%02d] %s, %s, line %d -> %s\n",
669 ip->fileName ? ip->fileName : "script",
670 ip->procName ? ip->procName: "global",
671 ip->lineNumber, line);
672 if (traceLine == 0) {
675 newErrbuf = mprRealloc(ep, errbuf, len + strlen(traceLine) + 1);
676 if (newErrbuf == NULL) {
680 memcpy(&errbuf[len], traceLine, strlen(traceLine) + 1);
681 len += strlen(traceLine);
688 /******************************************************************************/
690 * Internal use method to set the error message
692 * Error, ArgError, AssertError, IOError, MemoryError, RangeError,
693 * ReferenceError, SyntaxError, TypeError, MemoryError
696 void ejsError(Ejs* ep, const char *errorType, const char* fmt, ...)
702 va_start(fmtArgs, fmt);
703 mprAllocVsprintf(MPR_LOC_ARGS(ep), &msg, MPR_MAX_STRING, fmt, fmtArgs);
707 * Create a new Error exception object. If bad error type, default to
710 if (ejsGetClass(ep, 0, errorType) == 0) {
713 ep->gotException = 1;
715 error = ejsCreateObj(ep, 0, errorType, msg);
721 stack = ejsFormatStack(ep);
722 ejsSetPropertyToString(ep, error, "stack", stack);
725 ejsWriteVar(ep, ep->result, error, EJS_SHALLOW_COPY);
726 ejsFreeVar(ep, error);
729 /******************************************************************************/
731 void ejsSyntaxError(Ejs *ep, const char *msg)
736 ejsError(ep, EJS_SYNTAX_ERROR, msg);
739 /******************************************************************************/
741 void ejsMemoryError(Ejs *ep)
743 ejsError(ep, EJS_MEMORY_ERROR, "Memory allocation error");
746 /******************************************************************************/
748 void ejsArgError(Ejs *ep, const char *msg)
750 mprAssert(msg && *msg);
752 ejsError(ep, EJS_ARG_ERROR, msg);
755 /******************************************************************************/
757 void ejsInternalError(Ejs *ep, const char *msg)
759 mprAssert(msg && *msg);
761 ejsError(ep, EJS_INTERNAL_ERROR, msg);
764 /******************************************************************************/
766 * Public routine to set the error message. Caller MUST NOT free.
769 char *ejsGetErrorMsg(Ejs *ep)
772 const char *message, *stack, *name;
777 if (! ejsVarIsObject(error)) {
778 name = message = stack = 0;
780 name = ejsGetPropertyAsString(ep, error, "name");
781 message = ejsGetPropertyAsString(ep, error, "message");
782 stack = ejsGetPropertyAsString(ep, error, "stack");
784 if (name == 0 || message == 0) {
785 buf = mprStrdup(ep, "Unspecified execution error\n");
787 mprAllocSprintf(MPR_LOC_ARGS(ep), &buf, 0,
788 "%s Exception: %s\nStack:\n%s\n",
789 name, message, stack ? stack : " " );
791 mprFree(ep->errorMsg);
796 /******************************************************************************/
798 * Get the current line number
801 int ejsGetLineNumber(Ejs *ep)
803 if (ep->input == 0) {
806 return ep->input->lineNumber;
809 /******************************************************************************/
811 * Return the local object
814 EjsVar *ejsGetLocalObj(Ejs *ep)
819 /******************************************************************************/
821 * Return the global object
824 EjsVar *ejsGetGlobalObj(Ejs *ep)
829 /******************************************************************************/
831 * Set the expression return value
834 void ejsSetReturnValue(Ejs *ep, EjsVar *vp)
842 ejsWriteVar(ep, ep->result, vp, EJS_SHALLOW_COPY);
845 /******************************************************************************/
847 * Set the expression return value and free the arg.
850 void ejsSetReturnValueAndFree(Ejs *ep, EjsVar *vp)
855 ejsWriteVar(ep, ep->result, vp, EJS_SHALLOW_COPY);
859 /******************************************************************************/
861 * Set the expression return value to a string value.
864 void ejsSetReturnValueToString(Ejs *ep, const char *value)
869 ejsWriteVarAsString(ep, ep->result, value);
872 /******************************************************************************/
874 * Set the expression return value to a binary string value.
877 void ejsSetReturnValueToBinaryString(Ejs *ep, const uchar *value, int len)
882 ejsWriteVarAsBinaryString(ep, ep->result, value, len);
885 /******************************************************************************/
887 * Set the expression return value to a integer value.
890 void ejsSetReturnValueToInteger(Ejs *ep, int value)
894 ejsWriteVarAsInteger(ep, ep->result, value);
897 /******************************************************************************/
899 * Set the expression return value to an EjsNum value.
902 void ejsSetReturnValueToNumber(Ejs *ep, EjsNum value)
906 ejsWriteVarAsNumber(ep, ep->result, value);
909 /******************************************************************************/
911 * Set the expression return value to a boolean value.
914 void ejsSetReturnValueToBoolean(Ejs *ep, int value)
918 ejsWriteVarAsBoolean(ep, ep->result, value);
921 /******************************************************************************/
923 * Set the expression return value to a boolean value.
926 void ejsSetReturnValueToUndefined(Ejs *ep)
930 ejsWriteVarAsUndefined(ep, ep->result);
933 /******************************************************************************/
935 * Get the expression return value
938 EjsVar *ejsGetReturnValue(Ejs *ep)
945 /******************************************************************************/
947 void *ejsGetUserData(Ejs *ep)
954 /******************************************************************************/
956 * Get a variable given a full variable spec possibly containing "." or "[]".
959 EjsVar *ejsGetVar(Ejs *ep, const char *fullName)
962 mprAssert(fullName && *fullName);
964 return ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 0);
967 /******************************************************************************/
969 * Get a string var given a full variable spec possibly containing "." or "[]".
972 const char *ejsGetStr(Ejs *ep, const char *fullName, const char *defaultValue)
976 mprAssert(fullName && *fullName);
978 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 0);
979 if (vp == 0 || !ejsVarIsString(vp)) {
982 /* MOB -- what about VarToStr */
986 /******************************************************************************/
988 * Get an int var given a full variable spec possibly containing "." or "[]".
991 int ejsGetInt(Ejs *ep, const char *fullName, int defaultValue)
996 mprAssert(fullName && *fullName);
998 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 0);
999 if (vp == 0 || !ejsVarIsInteger(vp)) {
1000 return defaultValue;
1002 /* MOB -- should use VarToInt */
1006 /******************************************************************************/
1008 * Get an bool var given a full variable spec possibly containing "." or "[]".
1011 int ejsGetBool(Ejs *ep, const char *fullName, int defaultValue)
1016 mprAssert(fullName && *fullName);
1018 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 0);
1019 if (vp == 0 || !ejsVarIsBoolean(vp)) {
1020 return defaultValue;
1022 /* MOB -- should use VarToBool */
1026 /******************************************************************************/
1028 * Set a variable that may be an arbitrarily complex object or array reference.
1029 * Will always define in the top most variable frame.
1032 int ejsSetVar(Ejs *ep, const char *fullName, const EjsVar *value)
1036 mprAssert(fullName && *fullName);
1038 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 1);
1040 return MPR_ERR_CANT_CREATE;
1043 if (ejsWriteVar(ep, vp, value, EJS_SHALLOW_COPY) == 0) {
1044 return MPR_ERR_CANT_WRITE;
1050 /******************************************************************************/
1052 * Set a variable that may be an arbitrarily complex object or array reference.
1053 * Will always define in the top most variable frame.
1056 int ejsSetStr(Ejs *ep, const char *fullName, const char *value)
1060 mprAssert(fullName && *fullName);
1062 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 1);
1064 return MPR_ERR_CANT_CREATE;
1067 if (ejsWriteVarAsString(ep, vp, value) == 0) {
1068 return MPR_ERR_CANT_WRITE;
1074 /******************************************************************************/
1076 * Set a variable that may be an arbitrarily complex object or array reference.
1077 * Will always define in the top most variable frame.
1080 int ejsSetInt(Ejs *ep, const char *fullName, int value)
1084 mprAssert(fullName && *fullName);
1086 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 1);
1088 return MPR_ERR_CANT_CREATE;
1092 ejsWriteVarAsInteger(ep, vp, value);
1097 /******************************************************************************/
1099 * Set a variable that may be an arbitrarily complex object or array reference.
1100 * Will always define in the top most variable frame.
1103 int ejsSetBool(Ejs *ep, const char *fullName, bool value)
1107 mprAssert(fullName && *fullName);
1109 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 1);
1111 return MPR_ERR_CANT_CREATE;
1115 ejsWriteVarAsBoolean(ep, vp, value);
1120 /******************************************************************************/
1122 * Set a variable that may be an arbitrarily complex object or array reference.
1123 * Will always define in the top most variable frame. Free the value passed in.
1126 int ejsSetVarAndFree(Ejs *ep, const char *fullName, EjsVar *value)
1130 mprAssert(fullName && *fullName);
1132 vp = ejsFindProperty(ep, 0, 0, ep->global, ep->local, fullName, 1);
1134 return MPR_ERR_CANT_CREATE;
1137 if (ejsWriteVar(ep, vp, value, EJS_SHALLOW_COPY) == 0) {
1138 ejsFreeVar(ep, value);
1139 return MPR_ERR_CANT_WRITE;
1142 ejsFreeVar(ep, value);
1146 /******************************************************************************/
1151 int ejsDeleteVar(Ejs *ep, const char *fullName)
1157 vp = ejsFindProperty(ep, &obj, &propertyName, ep->global, ep->local,
1163 mprAssert(propertyName);
1164 mprAssert(propertyName);
1166 return ejsDeleteProperty(ep, obj, propertyName);
1169 /******************************************************************************/
1171 * Utility routine to crack JavaScript arguments. Return the number of args
1172 * seen. This routine only supports %s and %d type args.
1176 * if (ejsParseArgs(argc, argv, "%s %d", &name, &age) < 2) {
1177 * // Insufficient args
1182 int ejsParseArgs(int argc, char **argv, const char *fmt, ...)
1189 va_start(vargs, fmt);
1195 for (argn = 0, cp = fmt; cp && *cp && argn < argc && argv[argn]; ) {
1203 bp = va_arg(vargs, int*);
1205 if (strcmp(s, "true") == 0 || s[0] == '1') {
1216 ip = va_arg(vargs, int*);
1221 sp = va_arg(vargs, char**);
1235 /******************************************************************************/
1237 * Define the standard classes
1240 int ejsDefineStandardClasses(Ejs *master)
1242 if (ejsDefineArrayClass(master) != 0 ||
1243 ejsDefineBooleanClass(master) != 0 ||
1244 ejsDefineErrorClasses(master) != 0 ||
1245 ejsDefineFunctionClass(master) != 0 ||
1246 ejsDefineNumberClass(master) != 0 ||
1248 ejsDefineDateClass(master) != 0 ||
1250 #if BLD_FEATURE_EJS_E4X
1251 ejsDefineXmlClasses(master) != 0 ||
1253 #if BLD_FEATURE_EJS_DB && NOT_HERE
1254 ejsDefineDbClasses(master) != 0 ||
1256 ejsDefineStringClass(master) != 0) {
1257 return MPR_ERR_MEMORY;
1262 /******************************************************************************/
1264 * Define the EJS System Object Model
1267 int ejsDefineSystemClasses(Ejs *master)
1269 if (ejsDefineSystemClass(master) != 0 ||
1270 ejsDefineAppClass(master) != 0 ||
1271 ejsDefineMemoryClass(master) != 0 ||
1272 ejsDefineLogClass(master) != 0 ||
1273 ejsDefineDebugClass(master) != 0 ||
1274 ejsDefineGCClass(master) != 0 ||
1275 ejsDefineFileSystemClass(master) != 0 ||
1277 ejsDefineFileClass(master) != 0 ||
1278 ejsDefineHTTPClass(master) != 0 ||
1280 ejsDefineGlobalProperties(master) != 0) {
1281 return MPR_ERR_MEMORY;
1286 /******************************************************************************/
1288 * Terminate the system object model and classes
1291 int ejsTermSystemClasses(Ejs *master)
1294 ejsTermHTTPClass(master);
1299 /******************************************************************************/
1301 * Define the EJS object model
1304 int ejsCreateObjectModel(Ejs *ejs)
1308 pp = ejsSetPropertyToNewObj(ejs, ejs->global, "system", "System", 0);
1310 return MPR_ERR_MEMORY;
1313 if (ejsSetPropertyToNewObj(ejs, ejsGetVarPtr(pp), "app", "System.App",
1315 return MPR_ERR_MEMORY;
1320 /******************************************************************************/
1322 void ejsTrace(Ejs *ep, const char *fmt, ...)
1325 char buf[MPR_MAX_LOG_STRING];
1328 va_start(args, fmt);
1329 len = mprVsprintf(buf, sizeof(buf) - 1, fmt, args);
1332 mprLog(ep, 0, buf, len);
1337 /******************************************************************************/
1339 bool ejsGotException(Ejs *ep)
1341 return (bool) ep->gotException;
1344 /******************************************************************************/
1346 void ejsSetPrimaryHandle(Ejs *ep, void *primaryHandle)
1350 ep->primaryHandle = primaryHandle;
1353 /******************************************************************************/
1355 void ejsSetAlternateHandle(Ejs *ep, void *alternateHandle)
1359 ep->altHandle = alternateHandle;
1362 /******************************************************************************/
1367 #endif /* BLD_FEATURE_EJS */
1369 /******************************************************************************/
1376 * vim600: sw=4 ts=4 fdm=marker
1377 * vim<600: sw=4 ts=4