js_State *js_newstate(js_Alloc alloc, void *actx) { js_State *J; if (!alloc) alloc = js_defaultalloc; J = alloc(actx, NULL, sizeof *J); if (!J) return NULL; memset(J, 0, sizeof(*J)); J->actx = actx; J->alloc = alloc; J->panic = js_defaultpanic; J->stack = alloc(actx, NULL, JS_STACKSIZE * sizeof *J->stack); if (!J->stack) { alloc(actx, NULL, 0); return NULL; } J->gcmark = 1; J->nextref = 0; J->R = jsV_newobject(J, JS_COBJECT, NULL); J->G = jsV_newobject(J, JS_COBJECT, NULL); J->E = jsR_newenvironment(J, J->G, NULL); J->GE = J->E; jsB_init(J); return J; }
js_State *js_newstate(js_Alloc alloc, void *actx, int flags) { js_State *J; assert(sizeof(js_Value) == 16); assert(offsetof(js_Value, type) == 15); if (!alloc) alloc = js_defaultalloc; J = alloc(actx, NULL, sizeof *J); if (!J) return NULL; memset(J, 0, sizeof(*J)); J->actx = actx; J->alloc = alloc; if (flags & JS_STRICT) J->strict = 1; J->trace[0].name = "?"; J->trace[0].file = "[C]"; J->trace[0].line = 0; J->panic = js_defaultpanic; J->stack = alloc(actx, NULL, JS_STACKSIZE * sizeof *J->stack); if (!J->stack) { alloc(actx, NULL, 0); return NULL; } J->gcmark = 1; J->nextref = 0; J->R = jsV_newobject(J, JS_COBJECT, NULL); J->G = jsV_newobject(J, JS_COBJECT, NULL); J->E = jsR_newenvironment(J, J->G, NULL); J->GE = J->E; jsB_init(J); return J; }