static function start() { #-- create a global object jsrt::$global = new js_object(); #-- create the first execution context jsrt::$contexts = array(new js_context(jsrt::$global, array(jsrt::$global), jsrt::$global)); #-- set a few things jsrt::$functions = array(); jsrt::$nan = js_int(acos(1.01)); jsrt::$infinity = js_int(-log(0)); jsrt::$undefined = new js_val(js_val::UNDEFINED, 0); jsrt::$null = new js_val(js_val::NULL, 0); jsrt::$true = new js_val(js_val::BOOLEAN, true); jsrt::$false = new js_val(js_val::BOOLEAN, false); jsrt::$zero = js_int(0); jsrt::$one = js_int(1); jsrt::$exception = NULL; jsrt::$sortfn = NULL; $internal = array("dontenum", "dontdelete", "readonly"); #-- common prototypes jsrt::$proto_object = jsrt::$proto_function = jsrt::$proto_array = jsrt::$proto_string = jsrt::$proto_boolean = jsrt::$proto_number = jsrt::$proto_date = jsrt::$proto_regexp = jsrt::$proto_error = jsrt::$proto_evalerror = jsrt::$proto_rangeerror = jsrt::$proto_referenceerror = jsrt::$proto_syntaxerror = jsrt::$proto_typeerror = jsrt::$proto_urierror = null; jsrt::$proto_object = new js_object(); jsrt::push_context(jsrt::$proto_object); jsrt::define_function(array("js_object", "toString"), 'toString'); jsrt::define_function(array("js_object", "toString"), 'toLocaleString'); jsrt::define_function(array("js_object", "valueOf"), 'valueOf'); jsrt::define_function(array("js_object", "hasOwnProperty"), "hasOwnProperty", array("value")); jsrt::define_function(array("js_object", "isPrototypeOf"), "isPrototypeOf", array("value")); jsrt::define_function(array("js_object", "propertyIsEnumerable"), "propertyIsEnumerable", array("value")); jsrt::pop_context(); jsrt::$proto_function = new js_function(); jsrt::push_context(jsrt::$proto_function); jsrt::define_function(array("js_function", "func_toString"), 'toString'); jsrt::define_function(array("js_function", "func_apply"), 'apply', array("thisArg", "argArray")); jsrt::define_function(array("js_function", "func_call"), 'call', array("thisArg")); jsrt::pop_context(); jsrt::$proto_array = new js_array(); jsrt::push_context(jsrt::$proto_array); jsrt::define_function(array("js_array", "toString"), 'toString'); jsrt::define_function(array("js_array", "toLocaleString"), 'toLocaleString'); jsrt::define_function(array("js_array", "concat"), "concat", array("item")); jsrt::define_function(array("js_array", "join"), "join", array("separator")); jsrt::define_function(array("js_array", "pop"), "pop"); jsrt::define_function(array("js_array", "push"), "push", array("item")); jsrt::define_function(array("js_array", "reverse"), "reverse"); jsrt::define_function(array("js_array", "shift"), "shift"); jsrt::define_function(array("js_array", "slice"), "slice", array("start", "end")); jsrt::define_function(array("js_array", "sort"), "sort", array("comparefn")); jsrt::define_function(array("js_array", "splice"), "splice", array("start", "deleteCount")); jsrt::define_function(array("js_array", "unshift"), "unshift", array("item")); jsrt::pop_context(); jsrt::$proto_string = new js_string(); jsrt::push_context(jsrt::$proto_string); jsrt::define_function(array("js_string", "toString"), 'toString'); jsrt::define_function(array("js_string", "toString"), 'valueOf'); jsrt::define_function(array("js_string", "charAt"), 'charAt', array("pos")); jsrt::define_function(array("js_string", "charCodeAt"), 'charCodeAt', array("pos")); jsrt::define_function(array("js_string", "concat"), 'concat', array("string")); jsrt::define_function(array("js_string", "indexOf"), 'indexOf', array("searchString")); jsrt::define_function(array("js_string", "lastIndexOf"), 'lastIndexOf', array("searchString")); jsrt::define_function(array("js_string", "localeCompare"), 'localeCompare', array("that")); jsrt::define_function(array("js_string", "match"), 'match', array("regexp")); jsrt::define_function(array("js_string", "replace"), 'replace', array("searchValue", "replaceValue")); jsrt::define_function(array("js_string", "search"), 'search', array("regexp")); jsrt::define_function(array("js_string", "slice"), 'slice', array("start", "end")); jsrt::define_function(array("js_string", "split"), 'split', array("separator", "limit")); jsrt::define_function(array("js_string", "substr"), 'substr', array("start", "length")); jsrt::define_function(array("js_string", "substring"), 'substring', array("start", "end")); jsrt::define_function(array("js_string", "toLowerCase"), 'toLowerCase'); jsrt::define_function(array("js_string", "toLocaleLowerCase"), 'toLocaleLowerCase'); jsrt::define_function(array("js_string", "toUpperCase"), 'toUpperCase'); jsrt::define_function(array("js_string", "toLocaleUpperCase"), 'toLocaleUpperCase'); jsrt::pop_context(); jsrt::$proto_boolean = new js_boolean(); jsrt::push_context(jsrt::$proto_boolean); jsrt::define_function(array("js_boolean", "toString"), 'toString'); jsrt::define_function(array("js_boolean", "valueOf"), 'valueOf'); jsrt::pop_context(); jsrt::$proto_number = new js_number(); jsrt::push_context(jsrt::$proto_number); jsrt::define_function(array("js_number", "toString"), 'toString', array("radix")); jsrt::define_function(array("js_number", "toString"), 'toLocaleString', array("radix")); jsrt::define_function(array("js_number", "valueOf"), 'valueOf'); jsrt::define_function(array("js_number", "toFixed"), 'toFixed', array("fractionDigits")); jsrt::define_function(array("js_number", "toExponential"), 'toExponential', array("fractionDigits")); jsrt::define_function(array("js_number", "toPrecision"), 'toPrecision', array("precision")); jsrt::pop_context(); jsrt::$proto_date = new js_date(); jsrt::push_context(jsrt::$proto_date); jsrt::define_function(array("js_date", "toString"), 'toString'); jsrt::define_function(array("js_date", "toDateString"), 'toDateString'); jsrt::define_function(array("js_date", "toTimeString"), 'toTimeString'); jsrt::define_function(array("js_date", "toLocaleString"), 'toLocaleString'); jsrt::define_function(array("js_date", "toLocaleDateString"), 'toLocaleDateString'); jsrt::define_function(array("js_date", "toLocaleTimeString"), 'toLocaleTimeString'); jsrt::define_function(array("js_date", "valueOf"), 'valueOf'); jsrt::define_function(array("js_date", "getTime"), 'getTime'); jsrt::define_function(array("js_date", "getFullYear"), 'getFullYear'); jsrt::define_function(array("js_date", "getUTCFullYear"), 'getUTCFullYear'); jsrt::define_function(array("js_date", "getMonth"), 'getMonth'); jsrt::define_function(array("js_date", "getUTCMonth"), 'getUTCMonth'); jsrt::define_function(array("js_date", "getDate"), 'getDate'); jsrt::define_function(array("js_date", "getUTCDate"), 'getUTCDate'); jsrt::define_function(array("js_date", "getDay"), 'getDay'); jsrt::define_function(array("js_date", "getUTCDay"), 'getUTCDay'); jsrt::define_function(array("js_date", "getHours"), 'getHours'); jsrt::define_function(array("js_date", "getUTCHours"), 'getUTCHours'); jsrt::define_function(array("js_date", "getMinutes"), 'getMinutes'); jsrt::define_function(array("js_date", "getUTCMinutes"), 'getUTCMinutes'); jsrt::define_function(array("js_date", "getSeconds"), 'getSeconds'); jsrt::define_function(array("js_date", "getUTCSeconds"), 'getUTCSeconds'); jsrt::define_function(array("js_date", "getMilliseconds"), 'getMilliseconds'); jsrt::define_function(array("js_date", "getUTCMilliseconds"), 'getUTCMilliseconds'); jsrt::define_function(array("js_date", "getTimezoneOffset"), 'getTimezoneOffset'); jsrt::define_function(array("js_date", "setTime"), 'setTime', array("time")); jsrt::define_function(array("js_date", "setMilliseconds"), 'setMilliseconds', array("ms")); jsrt::define_function(array("js_date", "setUTCMilliseconds"), 'setUTCMilliseconds', array("ms")); jsrt::define_function(array("js_date", "setSeconds"), 'setSeconds', array("sec", "ms")); jsrt::define_function(array("js_date", "setUTCSeconds"), 'setUTCSeconds', array("sec", "ms")); jsrt::define_function(array("js_date", "setMinutes"), 'setMinutes', array("min", "sec", "ms")); jsrt::define_function(array("js_date", "setUTCMinutes"), 'setUTCMinutes', array("min", "sec", "ms")); jsrt::define_function(array("js_date", "setHours"), 'setHours', array("hour", "min", "sec", "ms")); jsrt::define_function(array("js_date", "setUTCHours"), 'setUTCHours', array("hour", "min", "sec", "ms")); jsrt::define_function(array("js_date", "setDate"), 'setDate', array("date")); jsrt::define_function(array("js_date", "setUTCDate"), 'setUTCDate', array("date")); jsrt::define_function(array("js_date", "setMonth"), 'setMonth', array("month", "date")); jsrt::define_function(array("js_date", "setUTCMonth"), 'setUTCMonth', array("month", "date")); jsrt::define_function(array("js_date", "setFullYear"), 'setFullYear', array("year", "month", "date")); jsrt::define_function(array("js_date", "setUTCFullYear"), 'setUTCFullYear', array("year", "month", "date")); jsrt::define_function(array("js_date", "toUTCString"), 'toUTCString'); jsrt::pop_context(); jsrt::$proto_regexp = new js_regexp(); jsrt::push_context(jsrt::$proto_regexp); jsrt::define_function(array("js_regexp", "exec"), 'exec', array("string")); jsrt::define_function(array("js_regexp", "test"), 'test', array("string")); jsrt::define_function(array("js_regexp", "toString"), 'toString'); jsrt::pop_context(); jsrt::$proto_error = new js_error(); jsrt::$proto_error->put("name", js_str("Error")); jsrt::$proto_error->put("message", js_str("")); jsrt::push_context(jsrt::$proto_error); jsrt::define_function(array("js_error", "toString"), 'toString'); jsrt::pop_context(); jsrt::$proto_evalerror = new js_evalerror(); jsrt::$proto_evalerror->put("name", js_str("EvalError")); jsrt::$proto_evalerror->put("message", js_str("")); jsrt::$proto_rangeerror = new js_rangeerror(); jsrt::$proto_rangeerror->put("name", js_str("RangeError")); jsrt::$proto_rangeerror->put("message", js_str("")); jsrt::$proto_referenceerror = new js_referenceerror(); jsrt::$proto_referenceerror->put("name", js_str("ReferenceError")); jsrt::$proto_referenceerror->put("message", js_str("")); jsrt::$proto_syntaxerror = new js_syntaxerror(); jsrt::$proto_syntaxerror->put("name", js_str("SyntaxError")); jsrt::$proto_syntaxerror->put("message", js_str("")); jsrt::$proto_typeerror = new js_typeerror(); jsrt::$proto_typeerror->put("name", js_str("TypeError")); jsrt::$proto_typeerror->put("message", js_str("")); jsrt::$proto_urierror = new js_urierror(); jsrt::$proto_urierror->put("name", js_str("URIError")); jsrt::$proto_urierror->put("message", js_str("")); #-- populate standard objects jsrt::define_variable("NaN", jsrt::$nan); jsrt::define_variable("Infinity", jsrt::$infinity); jsrt::define_variable("undefined", jsrt::$undefined); jsrt::define_function("jsi_eval", "eval"); jsrt::define_function("jsi_parseInt", "parseInt", array("str", "radix")); jsrt::define_function("jsi_parseFloat", "parseFloat", array("str")); jsrt::define_function("jsi_isNaN", "isNaN", array("value")); jsrt::define_function("jsi_isFinite", "isFinite", array("value")); jsrt::define_function("jsi_decodeURI", "decodeURI"); jsrt::define_function("jsi_decodeURIComponent", "decodeURIComponent"); jsrt::define_function("jsi_encodeURI", "encodeURI"); jsrt::define_function("jsi_encodeURIComponent", "encodeURIComponent"); $o = jsrt::define_function(array("js_object", "object"), "Object", array("value"), jsrt::$proto_object); jsrt::$proto_object->put("constructor", $o); $o = jsrt::define_function(array("js_function", "func_object"), "Function", array("value"), jsrt::$proto_function); jsrt::$proto_function->put("constructor", $o); $o = jsrt::define_function(array("js_array", "object"), "Array", array("value"), jsrt::$proto_array); jsrt::$proto_array->put("constructor", $o); $o = jsrt::define_function(array("js_string", "object"), "String", array("value"), jsrt::$proto_string); jsrt::push_context($o); jsrt::define_function(array("js_string", "fromCharCode"), "fromCharCode", array("char")); jsrt::pop_context(); jsrt::$proto_string->put("constructor", $o); $o = jsrt::define_function(array("js_boolean", "object"), "Boolean", array("value"), jsrt::$proto_boolean); jsrt::$proto_boolean->put("constructor", $o); $o = jsrt::define_function(array("js_number", "object"), "Number", array("value"), jsrt::$proto_number); $o->put("MAX_VALUE", js_int(1.7976931348623157E+308), $internal); $o->put("MIN_VALUE", js_int(4.940656458412465E-324), $internal); $o->put("NaN", jsrt::$nan, $internal); $o->put("NEGATIVE_INFINITY", jsrt::expr_u_minus(jsrt::$infinity), $internal); $o->put("POSITIVE_INFINITY", jsrt::$infinity, $internal); jsrt::$proto_number->put("constructor", $o); $o = jsrt::define_function(array("js_date", "object"), "Date", array("year", "month", "date", "hours", "minutes", "seconds", "ms"), jsrt::$proto_date); jsrt::push_context($o); jsrt::define_function(array("js_date", "parse"), "parse", array("string")); jsrt::define_function(array("js_date", "UTC"), "UTC", array("year", "month", "date", "hours", "minutes", "seconds", "ms")); jsrt::pop_context(); jsrt::$proto_date->put("constructor", $o); $o = jsrt::define_function(array("js_regexp", "object"), "RegExp", array("pattern", "flags"), jsrt::$proto_regexp); jsrt::$proto_regexp->put("constructor", $o); $o = jsrt::define_function(array("js_error", "object"), "Error", array("message"), jsrt::$proto_error); jsrt::$proto_error->put("constructor", $o); $o = jsrt::define_function(array("js_evalerror", "object"), "EvalError", array("message"), jsrt::$proto_evalerror); jsrt::$proto_evalerror->put("constructor", $o); $o = jsrt::define_function(array("js_rangeerror", "object"), "RangeError", array("message"), jsrt::$proto_rangeerror); jsrt::$proto_rangeerror->put("constructor", $o); $o = jsrt::define_function(array("js_referenceerror", "object"), "ReferenceError", array("message"), jsrt::$proto_referenceerror); jsrt::$proto_referenceerror->put("constructor", $o); $o = jsrt::define_function(array("js_syntaxerror", "object"), "SyntaxError", array("message"), jsrt::$proto_syntaxerror); jsrt::$proto_syntaxerror->put("constructor", $o); $o = jsrt::define_function(array("js_typeerror", "object"), "TypeError", array("message"), jsrt::$proto_typeerror); jsrt::$proto_typeerror->put("constructor", $o); $o = jsrt::define_function(array("js_urierror", "object"), "URIError", array("message"), jsrt::$proto_urierror); jsrt::$proto_urierror->put("constructor", $o); $math = new js_math(); jsrt::define_variable("Math", $math); $math->put("E", js_int(M_E), $internal); $math->put("LN10", js_int(M_LN10), $internal); $math->put("LN2", js_int(M_LN2), $internal); $math->put("LOG2E", js_int(M_LOG2E), $internal); $math->put("LOG10E", js_int(M_LOG10E), $internal); $math->put("PI", js_int(M_PI), $internal); $math->put("SQRT1_2", js_int(M_SQRT1_2), $internal); $math->put("SQRT2", js_int(M_SQRT2), $internal); jsrt::push_context($math); jsrt::define_function(array("js_math", "abs"), "abs", array("x")); jsrt::define_function(array("js_math", "acos"), "acos", array("x")); jsrt::define_function(array("js_math", "asin"), "asin", array("x")); jsrt::define_function(array("js_math", "atan"), "atan", array("x")); jsrt::define_function(array("js_math", "atan2"), "atan2", array("y", "x")); jsrt::define_function(array("js_math", "ceil"), "ceil", array("x")); jsrt::define_function(array("js_math", "cos"), "cos", array("x")); jsrt::define_function(array("js_math", "exp"), "exp", array("x")); jsrt::define_function(array("js_math", "floor"), "floor", array("x")); jsrt::define_function(array("js_math", "log"), "log", array("x")); jsrt::define_function(array("js_math", "max"), "max", array("value1", "value2")); jsrt::define_function(array("js_math", "min"), "min", array("value1", "value2")); jsrt::define_function(array("js_math", "pow"), "pow", array("x", "y")); jsrt::define_function(array("js_math", "random"), "random"); jsrt::define_function(array("js_math", "round"), "round", array("x")); jsrt::define_function(array("js_math", "sin"), "sin", array("x")); jsrt::define_function(array("js_math", "sqrt"), "sqrt", array("x")); jsrt::define_function(array("js_math", "tan"), "tan", array("x")); jsrt::pop_context(); // extensions to the spec. jsrt::define_variable("global", jsrt::$global); jsrt::define_function(array("jsrt", "write"), "write"); jsrt::define_function(array("jsrt", "write"), "print"); }