Prev: Number list to display in the slide show
Next: FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type? (2010-06-27)
From: VK on 27 Jun 2010 08:19 On Jun 27, 2:10 am, Stefan Weiss <krewech...(a)gmail.com> wrote: > I retract that. Do _not_ look at the SpiderMonkey parser/interpreter > code unless you're drunk or a wizard (or both). Even that can be not enough for core stuff like that :-) A drunk smoking grass wizard would be comfortable I guess :-) To be fair, it is not Gecko only problem: any old enough system if ever studied internally will kill anyone's programming illusions once and forever. My personal hint: do *not* study Java core (anything below Swing) :-) > I found an older version > lying around in my ~/build directory and got curious. Now I've got a > headache. > > To make it short: after peeling away the onion-like layers of macros and > arcane typedefs that make up the JavaScript interpreter, and wrapping my > head around stuff like the difference between JS_ValueToBoolean and > js_ValueToBoolean, what it comes down to is this: > > src/jsinterp.c > ... > BEGIN_CASE(JSOP_NOT) > POP_BOOLEAN(cx, rval, cond); > PUSH_OPND(BOOLEAN_TO_JSVAL(!cond)); > END_CASE(JSOP_NOT) > ... > #define POP_BOOLEAN(cx, v, b) > ... > ok = js_ValueToBoolean(cx, v, &b); // [ed] branch for strings > > src/jsbool.c > ... > js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp) > { > ... > } else if (JSVAL_IS_STRING(v)) { > b = JSSTRING_LENGTH(JSVAL_TO_STRING(v)) ? JS_TRUE : JS_FALSE; > ... > } > *bp = b; > > The length of a string operand for JSOP_NOT (a.k.a. "!") is used to > decide whether the expression evaluates to true or false. There's no > creation of new Boolean objects anywhere. BOOLEAN_TO_JSVAL doesn't > create any, and JS_TRUE and JS_FALSE are (indirectly) defined as 1 and > 0, respectively. Shall we declare now that JavaScript doesn't have true and false values as well? :-) I can tell you right away that JavaScript doesn't have any objects: on C level these are strings and number manipulations as well and nothing else. And C itself does not have any subroutines, identifiers and stuff: in the reality these are just processor instructions and nothing else. Talking about language - is not talking about the engine. I am still collecting data at my spare time. I'll be back :-) |