public static void init scriptabl scope boolean seal continu obj new continu obj export asj class max prototyp id scope seal public object get implement return implement public void init implement object implement thi implement implement public string get class name return continu public scriptabl construct context cx scriptabl scope object arg throw context report runtim error direct call is not support public object call context cx scriptabl scope scriptabl thi obj object arg return interpret restart continu thi cx scope arg public static boolean is continu constructor id function object f if f ha tag ftag f method id id constructor return true return fals protect void init prototyp id int id string s int ariti switch id case id constructor ariti 0 s constructor break default throw new illeg argument except string valu of id init prototyp method ftag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag ftag return super exec id call f cx scope thi obj arg int id f method id switch id case id constructor throw context report runtim error direct call is not support throw new illeg argument except string valu of id protect int find prototyp id string s int id gener last updat 2004 09 08 12 02 41 cest l0 id 0 string x null if s length 11 x constructor id id constructor if x null x s x equal s id 0 gener return id scriptabl output stream constructor creat a scriptabl output stream for us in serial java script object call exclud standard object name param out the output stream to write to param scope the scope contain the object public scriptabl output stream output stream out scriptabl scope throw io except super out thi scope scope tabl new hashtabl 31 tabl put scope enabl replac object true exclud standard object name add a qualifi name to the list of object to be exclud from serial name exclud from serial ar look up in the new scope and replac upon deseri param name a fulli qualifi name of the form a b c where a must be a properti of the top level object the object need not exist in which case the name is ignor throw illeg argument except if the object is not a link scriptabl public void add option exclud name string name object obj lookup qualifi name scope name if obj null obj uniqu tag not found if obj instanceof scriptabl throw new illeg argument except object for exclud name name is not a scriptabl it is obj get class get name tabl put obj name add a qualifi name to the list of object to be exclud from serial name exclud from serial ar look up in the new scope and replac upon deseri param name a fulli qualifi name of the form a b c where a must be a properti of the top level object throw illeg argument except if the object is not found or is not a link scriptabl public void add exclud name string name object obj lookup qualifi name scope name if obj instanceof scriptabl throw new illeg argument except object for exclud name name not found tabl put obj name return true if the name is exclud from serial public boolean ha exclud name string name return tabl get name null remov a name from the list of name to exclud public void remov exclud name string name tabl remov name add the name of the standard object and their prototyp to the list of exclud name public void exclud standard object name string name object object prototyp function function prototyp string string prototyp math no math prototyp arrai arrai prototyp error error prototyp number number prototyp date date prototyp reg exp reg exp prototyp script script prototyp continu continu prototyp for int i 0 i name length i add exclud name name i string option name xml xml prototyp xml list xml list prototyp for int i 0 i option name length i add option exclud name option name i static object lookup qualifi name scriptabl scope string qualifi name string token st new string token qualifi name object result scope while st ha more token string s st next token result scriptabl object get properti scriptabl result s if result null result instanceof scriptabl break return result static final long serial versionuid 2692990309789917727l pend lookup string name thi name name pend lookup string name thi name name string get name return name protect object replac object object obj throw io except string name string tabl get obj if name null return obj return new pend lookup name creat a java script function object from a java method p the code member code argument must be either a java lang reflect method or a java lang reflect constructor and must match on of two form p the first form is a member with zero or more paramet of the follow type object string boolean scriptabl int or doubl the long type is not support becaus the doubl represent of a long which is the emca mandat storag type for number mai lose precis if the member is a method the return valu must be void or on of the type allow for paramet p the runtim will perform appropri convers base upon the type of the paramet a paramet type of object specifi that no convers ar to be done a paramet of type string will us context to string to convert argument similarli paramet of type doubl boolean and scriptabl will caus context to number context to boolean and context to object respect to be call p if the method is not static the java thi valu will correspond to the java script thi valu ani attempt to call the function with a thi valu that is not of the right java type will result in an error p the second form is the variabl argument or vararg form if the function object will be us as a constructor the member must have the follow paramet pre context cx object arg function ctor obj boolean in new expr pre and if it is a method be static and return an object result p otherwis if the function object will i not i be us to defin a constructor the member must be a static method with paramet context cx scriptabl thi obj object arg function fun obj pre pre and an object result p when the function vararg form is call as part of a function call the code arg code paramet contain the argument with code thi obj code set to the java script thi valu code fun obj code is the function object for the invok function p when the constructor vararg form is call or invok while evalu a code new code express code arg code contain the argument code ctor obj code refer to thi function object and code in new expr code is true if and onli if a code new code express caus the call thi support defin a function that ha differ behavior when call as a constructor than when invok as a normal function call for exampl the boolean constructor when call as a function will convert to boolean rather than creat a new object p param name the name of the function param method or constructor a java lang reflect method or a java lang reflect constructor that defin the object param scope enclos scope of function see org mozilla javascript scriptabl public function object string name member method or constructor scriptabl scope if method or constructor instanceof constructor member new member box constructor method or constructor is static true well doesn t take a thi els member new member box method method or constructor is static member is static string method name member get name thi function name name class type member arg type int ariti type length if ariti 4 type 1 is arrai type 2 is arrai either variabl arg or an error if type 1 is arrai if is static type 0 script runtim context class type 1 get compon type script runtim object class type 2 script runtim function class type 3 boolean type throw context report runtim error1 msg vararg ctor method name parm length vararg ctor els if is static type 0 script runtim context class type 1 script runtim scriptabl class type 2 get compon type script runtim object class type 3 script runtim function class throw context report runtim error1 msg vararg fun method name parm length vararg method els parm length ariti if ariti 0 type tag new byte ariti for int i 0 i ariti i int tag get type tag type i if tag java unsupport type throw context report runtim error2 msg bad parm type i get name method name type tag i byte tag if member is method method method member method class return type method get return type if return type void type ha void return true els return type tag get type tag return type els class ctor type member get declar class if script runtim scriptabl class is assign from ctor type throw context report runtim error1 msg bad ctor return ctor type get name script runtim set function proto and parent thi scope return on of tt java type tt constant to indic desir type or link java unsupport type if the convert is not possibl public static int get type tag class type if type script runtim string class return java string type if type script runtim integ class type integ type return java int type if type script runtim boolean class type boolean type return java boolean type if type script runtim doubl class type doubl type return java doubl type if script runtim scriptabl class is assign from type return java scriptabl type if type script runtim object class return java object type note that the long type is not support see the javadoc for the constructor for thi class return java unsupport type public static object convert arg context cx scriptabl scope object arg int type tag switch type tag case java string type if arg instanceof string return arg return script runtim to string arg case java int type if arg instanceof integ return arg return new integ script runtim to int32 arg case java boolean type if arg instanceof boolean return arg return script runtim to boolean arg boolean true boolean fals case java doubl type if arg instanceof doubl return arg return new doubl script runtim to number arg case java scriptabl type if arg instanceof scriptabl return arg return script runtim to object cx scope arg case java object type return arg default throw new illeg argument except return the valu defin by the method us to construct the object number of paramet of the method or 1 if the method is a vararg form public int get ariti return parm length 0 1 parm length return the same valu as link get ariti public int get length return get ariti public string get function name return function name null function name get java method or constructor thi function repres public member get method or constructor if member is method return member method els return member ctor static method find singl method method method string name method found null for int i 0 n method length i n i method method method i if method null name equal method get name if found null throw context report runtim error2 msg no overload name method get declar class get name found method return found return all public method declar by the specifi class thi exclud inherit method param clazz the class from which to pull public declar method return the public method declar in the specifi class see class get declar method static method get method list class clazz method method null try get declar method mai be reject by the secur manag but get method is more expens if saw secur except method clazz get declar method catch secur except e if we get an except onc give up on get declar method saw secur except true if method null method clazz get method int count 0 for int i 0 i method length i if saw secur except method i get declar class clazz modifi is public method i get modifi method i null els count method result new method count int j 0 for int i 0 i method length i if method i null result j method i return result defin thi function as a java script constructor p set up the prototyp and constructor properti also call set parent and set prototyp with appropri valu then add the function object as a properti of the given scope us code prototyp get class name code as the name of the properti param scope the scope in which to defin the constructor typic the global object param prototyp the prototyp object see org mozilla javascript scriptabl set parent scope see org mozilla javascript scriptabl set prototyp see org mozilla javascript scriptabl get class name public void add as constructor scriptabl scope scriptabl prototyp script runtim set function proto and parent thi scope set immun prototyp properti prototyp prototyp set parent scope thi final int attr scriptabl object dontenum scriptabl object perman scriptabl object readonli defin properti prototyp constructor thi attr string name prototyp get class name defin properti scope name thi scriptabl object dontenum set parent scope scope deprec us link get type tag class and link convert arg context scriptabl object int for type convert public static object convert arg context cx scriptabl scope object arg class desir int tag get type tag desir if tag java unsupport type throw context report runtim error1 msg cant convert desir get name return convert arg cx scope arg tag perform convers on argument type if need and invok the underli java method or constructor p implement function call see org mozilla javascript function call context scriptabl scriptabl object public object call context cx scriptabl scope scriptabl thi obj object arg object result boolean check method result fals if parm length 0 if parm length vararg method object invok arg cx thi obj arg thi result member invok null invok arg check method result true els boolean in new expr thi obj null boolean b in new expr boolean true boolean fals object invok arg cx arg thi b result member is ctor member new instanc invok arg member invok null invok arg els if is static class clazz member get declar class if clazz is instanc thi obj boolean compat fals if thi obj scope scriptabl parent scope get parent scope if scope parent scope call with dynam scope for standalon function us parent scope as thi obj compat clazz is instanc parent scope if compat thi obj parent scope if compat couldn t find an object to call thi on throw script runtim type error1 msg incompat call function name object invok arg if parm length arg length do not alloc new argument arrai if java argument ar the same as the origin js on invok arg arg for int i 0 i parm length i object arg arg i object convert convert arg cx scope arg type tag i if arg convert if invok arg arg invok arg object arg clone invok arg i convert els if parm length 0 invok arg script runtim empti arg els invok arg new object parm length for int i 0 i parm length i object arg i arg length arg i undefin instanc invok arg i convert arg cx scope arg type tag i if member is method result member invok thi obj invok arg check method result true els result member new instanc invok arg if check method result if ha void return result undefin instanc els if return type tag java unsupport type result cx get wrap factori wrap cx scope result null xxx the code assum that if return type tag java object type then the java method did a proper job of convert the result to js primit or scriptabl to avoid potenti costli context java toj call return result return new link scriptabl instanc us the default constructor for the class of the underli java method return null to indic that the call method should be us to creat new object public scriptabl creat object context cx scriptabl scope if member is ctor parm length vararg ctor return null scriptabl result try result scriptabl member get declar class new instanc catch except ex throw context throw as script runtim ex ex result set prototyp get class prototyp result set parent scope get parent scope return result boolean is var arg method return parm length vararg method boolean is var arg constructor return parm length vararg ctor privat void read object object input stream in throw io except class not found except in default read object if parm length 0 class type member arg type type tag new byte parm length for int i 0 i parm length i type tag i byte get type tag type i if member is method method method member method class return type method get return type if return type void type ha void return true els return type tag get type tag return type static void init scriptabl scope boolean seal nativ math obj new nativ math obj activ prototyp map max id obj set prototyp get object prototyp scope obj set parent scope scope if seal obj seal object scriptabl object defin properti scope math obj scriptabl object dontenum privat nativ math public string get class name return math protect void init prototyp id int id if id last method id string name int ariti switch id case id to sourc ariti 0 name to sourc break case id ab ariti 1 name ab break case id aco ariti 1 name aco break case id asin ariti 1 name asin break case id atan ariti 1 name atan break case id atan2 ariti 2 name atan2 break case id ceil ariti 1 name ceil break case id co ariti 1 name co break case id exp ariti 1 name exp break case id floor ariti 1 name floor break case id log ariti 1 name log break case id max ariti 2 name max break case id min ariti 2 name min break case id pow ariti 2 name pow break case id random ariti 0 name random break case id round ariti 1 name round break case id sin ariti 1 name sin break case id sqrt ariti 1 name sqrt break case id tan ariti 1 name tan break default throw new illeg state except string valu of id init prototyp method math tag id name ariti els string name doubl x switch id case id e x math e name e break case id pi x math pi name pi break case id ln10 x 2 302585092994046 name ln10 break case id ln2 x 0 6931471805599453 name ln2 break case id log2e x 1 4426950408889634 name log2e break case id log10e x 0 4342944819032518 name log10e break case id sqrt1 2 x 0 7071067811865476 name sqrt1 2 break case id sqrt2 x 1 4142135623730951 name sqrt2 break default throw new illeg state except string valu of id init prototyp valu id name script runtim wrap number x dontenum readonli perman public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag math tag return super exec id call f cx scope thi obj arg doubl x int method id f method id switch method id case id to sourc return math case id ab x script runtim to number arg 0 ab 0 0 should be 0 0 but 0 0 0 0 fals x x 0 0 0 0 x 0 0 x x break case id aco case id asin x script runtim to number arg 0 if x x 1 0 x x 1 0 x method id id aco math aco x math asin x els x doubl nan break case id atan x script runtim to number arg 0 x math atan x break case id atan2 x script runtim to number arg 0 x math atan2 x script runtim to number arg 1 break case id ceil x script runtim to number arg 0 x math ceil x break case id co x script runtim to number arg 0 x x doubl posit infin x doubl neg infin doubl nan math co x break case id exp x script runtim to number arg 0 x x doubl posit infin x x doubl neg infin 0 0 math exp x break case id floor x script runtim to number arg 0 x math floor x break case id log x script runtim to number arg 0 java s log 0 infin we need nan x x 0 doubl nan math log x break case id max case id min x method id id max doubl neg infin doubl posit infin for int i 0 i arg length i doubl d script runtim to number arg i if d d x d nan break if method id id max if x d x d doe not work due to 0 0 0 0 x math max x d els x math min x d break case id pow x script runtim to number arg 0 x js pow x script runtim to number arg 1 break case id random x math random break case id round x script runtim to number arg 0 if x x x doubl posit infin x doubl neg infin round onli finit x long l math round x if l 0 x doubl l els we must propag the sign of d into the result if x 0 0 x script runtim neg zero els if x 0 0 x 0 0 break case id sin x script runtim to number arg 0 x x doubl posit infin x doubl neg infin doubl nan math sin x break case id sqrt x script runtim to number arg 0 x math sqrt x break case id tan x script runtim to number arg 0 x math tan x break default throw new illeg state except string valu of method id return script runtim wrap number x see ecma 15 8 2 13 privat doubl js pow doubl x doubl y doubl result if y y y is nan result is alwai nan result y els if y 0 java s pow nan 0 nan we need 1 result 1 0 els if x 0 mani dirrer from java s math pow if 1 x 0 result y 0 0 doubl posit infin els x is 0 need to check if y is an odd integ long y long long y if y long y y long 0x1 0 result y 0 0 0 doubl neg infin els result y 0 0 0 doubl posit infin els result math pow x y if result result check for broken java implement that give nan when thei should return someth els if y doubl posit infin if x 1 0 1 0 x result doubl posit infin els if 1 0 x x 1 0 result 0 els if y doubl neg infin if x 1 0 1 0 x result 0 els if 1 0 x x 1 0 result doubl posit infin els if x doubl posit infin result y 0 doubl posit infin 0 0 els if x doubl neg infin long y long long y if y long y y long 0x1 0 y is odd integ result y 0 doubl neg infin 0 0 els result y 0 doubl posit infin 0 0 return result protect int find prototyp id string s int id gener last updat 2004 03 17 13 51 32 cet l0 id 0 string x null int c l switch s length case 1 if s char at 0 e id id e break l0 break l case 2 if s char at 0 p s char at 1 i id id pi break l0 break l case 3 switch s char at 0 case l if s char at 2 2 s char at 1 n id id ln2 break l0 break l case a if s char at 2 s s char at 1 b id id ab break l0 break l case c if s char at 2 s s char at 1 o id id co break l0 break l case e if s char at 2 p s char at 1 x id id exp break l0 break l case l if s char at 2 g s char at 1 o id id log break l0 break l case m c s char at 2 if c n if s char at 1 i id id min break l0 els if c x if s char at 1 a id id max break l0 break l case p if s char at 2 w s char at 1 o id id pow break l0 break l case s if s char at 2 n s char at 1 i id id sin break l0 break l case t if s char at 2 n s char at 1 a id id tan break l0 break l break l case 4 switch s char at 1 case n x ln10 id id ln10 break l case c x aco id id aco break l case e x ceil id id ceil break l case q x sqrt id id sqrt break l case s x asin id id asin break l case t x atan id id atan break l break l case 5 switch s char at 0 case l x log2e id id log2e break l case s x sqrt2 id id sqrt2 break l case a x atan2 id id atan2 break l case f x floor id id floor break l case r x round id id round break l break l case 6 c s char at 0 if c l x log10e id id log10e els if c r x random id id random break l case 7 x sqrt1 2 id id sqrt1 2 break l case 8 x to sourc id id to sourc break l if x null x s x equal s id 0 gener return id member box ctor public nativ java constructor member box ctor thi ctor ctor public object call context cx scriptabl scope scriptabl thi obj object arg return nativ java class construct specif cx scope arg ctor public string get function name string sig java member live connect signatur ctor arg type return init concat sig public string to string return java constructor ctor get name interpret data int languag version string sourc file string encod sourc thi languag version languag version thi it sourc file sourc file thi encod sourc encod sourc init interpret data interpret data parent thi parent data parent thi languag version parent languag version thi it sourc file parent it sourc file thi encod sourc parent encod sourc init privat void init itsi code new byte initi max icod length it string tabl new string initi stringtabl size boolean eval script flag true if script correspond to eval code public boolean is top level return top level public boolean is function return it function type 0 public string get function name return it name public int get param count return arg count public int get param and var count return arg name length public string get param or var name int index return arg name index public string get sourc name return it sourc file public boolean is gener script return script runtim is gener script it sourc file public int get line number return interpret get line number thi public int get function count return it nest function null 0 it nest function length public debugg script get function int index return it nest function index public debugg script get parent return parent data static final long serial versionuid 5733330028285400526l nativ reg exp ctor public string get function name return reg exp public object call context cx scriptabl scope scriptabl thi obj object arg if arg length 0 arg 0 instanceof nativ reg exp arg length 1 arg 1 undefin instanc return arg 0 return construct cx scope arg public scriptabl construct context cx scriptabl scope object arg nativ reg exp re new nativ reg exp re compil cx scope arg script runtim set object proto and parent re scope return re privat static reg exp impl get impl context cx context get current context return reg exp impl script runtim get reg exp proxi cx max instanc id dollar id base 9 protect int get max instanc id return super get max instanc id max instanc id protect int find instanc id info string s int id gener last updat 2001 05 24 16 09 31 gmt 02 00 l0 id 0 string x null int c l switch s length case 2 switch s char at 1 case if s char at 0 id id ampersand break l0 break l case if s char at 0 id id quot break l0 break l case if s char at 0 id id star break l0 break l case if s char at 0 id id plu break l0 break l case 1 if s char at 0 id id dollar 1 break l0 break l case 2 if s char at 0 id id dollar 2 break l0 break l case 3 if s char at 0 id id dollar 3 break l0 break l case 4 if s char at 0 id id dollar 4 break l0 break l case 5 if s char at 0 id id dollar 5 break l0 break l case 6 if s char at 0 id id dollar 6 break l0 break l case 7 if s char at 0 id id dollar 7 break l0 break l case 8 if s char at 0 id id dollar 8 break l0 break l case 9 if s char at 0 id id dollar 9 break l0 break l case if s char at 0 id id underscor break l0 break l case if s char at 0 id id back quot break l0 break l break l case 5 x input id id input break l case 9 c s char at 4 if c m x last match id id last match els if c p x last paren id id last paren els if c i x multilin id id multilin break l case 11 x left context id id left context break l case 12 x right context id id right context break l if x null x s x equal s id 0 gener if id 0 return super find instanc id info s int attr switch id case id multilin case id star case id input case id underscor attr perman break default attr perman readonli break return instanc id info attr super get max instanc id id protect string get instanc id name int id int shift id super get max instanc id if 1 shift shift max instanc id switch shift case id multilin return multilin case id star return case id input return input case id underscor return case id last match return last match case id ampersand return case id last paren return last paren case id plu return case id left context return left context case id back quot return case id right context return right context case id quot return must be on of 1 9 convert to 0 8 int substr number shift dollar id base 1 char buf char 1 substr number return new string buf return super get instanc id name id protect object get instanc id valu int id int shift id super get max instanc id if 1 shift shift max instanc id reg exp impl impl get impl object string result switch shift case id multilin case id star return script runtim wrap boolean impl multilin case id input case id underscor string result impl input break case id last match case id ampersand string result impl last match break case id last paren case id plu string result impl last paren break case id left context case id back quot string result impl left context break case id right context case id quot string result impl right context break default must be on of 1 9 convert to 0 8 int substr number shift dollar id base 1 string result impl get paren sub string substr number break return string result null string result to string return super get instanc id valu id protect void set instanc id valu int id object valu int shift id super get max instanc id switch shift case id multilin case id star get impl multilin script runtim to boolean valu return case id input case id underscor get impl input script runtim to string valu return super set instanc id valu id valu static void init scriptabl scope boolean seal nativ call obj new nativ call obj export asj class max prototyp id scope seal nativ call nativ call nativ function function scriptabl scope object arg thi function function set parent scope scope leav prototyp null thi origin arg arg null script runtim empti arg arg initi valu of argument int param and var count function get param and var count int param count function get param count if param and var count 0 for int i 0 i param count i string name function get param or var name i object val i arg length arg i undefin instanc defin properti name val perman initi argument properti but onli if it wa not overriden by the paramet with the same name if super ha argument thi defin properti argument new argument thi perman if param and var count 0 for int i param count i param and var count i string name function get param or var name i if super ha name thi defin properti name undefin instanc perman public string get class name return call protect int find prototyp id string s return s equal constructor id constructor 0 protect void init prototyp id int id string s int ariti if id id constructor ariti 1 s constructor els throw new illeg argument except string valu of id init prototyp method call tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag call tag return super exec id call f cx scope thi obj arg int id f method id if id id constructor if thi obj null throw context report runtim error1 msg onli from new call script runtim check deprec cx call nativ call result new nativ call result set prototyp get object prototyp scope return result throw new illeg argument except string valu of id deprec us link wrap except wrap except throwabl to report except in java code public java script except object valu thi valu 0 creat a java script except wrap the given java script valu param valu the java script valu thrown public java script except object valu string sourc name int line number record error origin sourc name line number null 0 thi valu valu public string detail if valu instanceof scriptabl to prevent potenti of evalu and throw more except return script runtim default object to string scriptabl valu return script runtim to string valu return the valu wrap by thi except public object get valu return valu deprec us link rhino except sourc name from the super class public string get sourc name return sourc name deprec us link rhino except line number from the super class public int get line number return line number static final long serial versionuid 6460763940409461664l public nativ java class public nativ java class scriptabl scope class cl thi parent scope thi java object cl init member protect void init member class cl class java object member java member lookup class parent cl cl static field and method member get field and method object thi cl true public string get class name return java class public boolean ha string name scriptabl start return member ha name true public object get string name scriptabl start when us as a constructor script runtim new object ask for our prototyp to creat an object of the correct type we don t realli care what the object is sinc we re return on construct out of whole cloth so we return null if name equal prototyp return null object result scriptabl not found if static field and method null result static field and method get name if result null return result if member ha name true result member get thi name java object true els experiment look for nest class by append name to current class name class nest class find nest class get class object name if nest class null throw member report member not found name nativ java class nest valu new nativ java class scriptabl object get top level scope thi nest class nest valu set parent scope thi result nest valu return result public void put string name scriptabl start object valu member put thi name java object valu true public object get id return member get id true public class get class object return class super unwrap public object get default valu class hint if hint null hint script runtim string class return thi to string if hint script runtim boolean class return boolean true if hint script runtim number class return script runtim na nobj return thi public object call context cx scriptabl scope scriptabl thi obj object arg if it look like a cast of an object to thi class type walk the prototyp chain to see if there s a wrapper of a object that s an instanceof thi class if arg length 1 arg 0 instanceof scriptabl class c get class object scriptabl p scriptabl arg 0 do if p instanceof wrapper object o wrapper p unwrap if c is instanc o return p p p get prototyp while p null return construct cx scope arg public scriptabl construct context cx scriptabl scope object arg class class object get class object int modifi class object get modifi if modifi is interfac modifi modifi is abstract modifi member box ctor member ctor int index nativ java method find function cx ctor arg if index 0 string sig nativ java method script signatur arg throw context report runtim error2 msg no java ctor class object get name sig found the constructor so try invok it return construct specif cx scope arg ctor index els scriptabl top level scriptabl object get top level scope thi string msg try try to construct an interfac us java adapt to construct a new class on the fly that implement thi interfac object v top level get java adapt top level if v not found function f function v object adapt arg thi arg 0 return scriptabl f construct cx top level adapt arg catch except ex fall through to error string m ex get messag if m null msg m throw context report runtim error2 msg cant instanti msg class object get name static scriptabl construct specif context cx scriptabl scope object arg member box ctor scriptabl top level scriptabl object get top level scope scope class class object ctor get declar class class arg type ctor arg type object orig arg arg for int i 0 i arg length i object arg arg i object x context js to java arg arg type i if x arg if arg orig arg arg object orig arg clone arg i x object instanc ctor new instanc arg we need to forc thi to be wrap becaus construct ha to return a scriptabl return cx get wrap factori wrap new object cx top level instanc public string to string return java class get class object get name determin if prototyp is a wrap java object and perform a java instanceof except if valu is an instanc of nativ java class it isn t consid an instanc of the java class thi forestal ani name conflict between java lang class s method and the static method expos by a java nativ class public boolean ha instanc scriptabl valu if valu instanceof wrapper valu instanceof nativ java class object instanc wrapper valu unwrap return get class object is instanc instanc valu wasn t someth we understand return fals privat static class find nest class class parent class string name string nest class name parent class get name name class loader loader parent class get class loader if loader null alert if loader is null nest class should be load via system class loader which can be differ from the loader that brought rhino class that class for name would us but class loader get system class loader is java 2 onli return kit class or null nest class name els return kit class or null loader nest class name public abstract class secur proxi extend secur control protect abstract void call process file secur context cx scriptabl scope string filenam public lazili load ctor scriptabl object scope string ctor name string class name boolean seal thi class name class name thi ctor name ctor name thi seal seal if getter null method method function object get method list get class getter function object find singl method method get properti setter function object find singl method method set properti scope defin properti ctor name thi getter setter scriptabl object dontenum public object get properti scriptabl object obj synchron obj if is replac boolean remov on error fals class cl kit class or null class name if cl null remov on error true els try scriptabl object defin class obj cl seal is replac true catch invoc target except ex throwabl target ex get target except if target instanceof runtim except throw runtim except target remov on error true catch rhino except ex remov on error true catch instanti except ex remov on error true catch illeg access except ex remov on error true catch secur except ex treat secur except as absenc of object thei can be due to the follow reason java lang runtim permiss creat class loader remov on error true catch linkag error ex no depend class remov on error true if remov on error obj delet ctor name return scriptabl not found get just ad object return obj get ctor name obj public object set properti scriptabl object obj object val synchron obj is replac true return val public class function node extend script or fn node public function node string name super token function function name name public string get function name return function name public boolean requir activ return it need activ public boolean get ignor dynam scope return it ignor dynam scope public static final int function express statement 3 public int get function type return it function type public static xml lib extract from scope or null scriptabl scope scriptabl object so script runtim get librari scope or null scope if so null if librrai is not yet initi return null return null ensur lazili initi of real xml librari instanc which is done on first access to xml properti scriptabl object get properti so xml return xml lib so get associ valu xml lib kei public static xml lib extract from scope scriptabl scope xml lib lib extract from scope or null scope if lib null return lib string msg script runtim get messag0 msg xml not avail throw context report runtim error msg protect final xml lib bind to scope scriptabl scope scriptabl object so script runtim get librari scope or null scope if so null standard librari should be initi at thi point throw new illeg state except return xml lib so associ valu xml lib kei thi public abstract boolean isxml name context cx object name public abstract boolean isxml name context cx object name public abstract ref name ref context cx object name scriptabl scope int member type flag scriptabl scope int member type flag public abstract ref name ref context cx object namespac object name scriptabl scope int member type flag escap the reserv charact in a valu of an attribut and surround it by param valu unescap text return the escap text escap the reserv charact in a valu of a text node param valu unescap text return the escap text construct namespac for default xml statement public abstract object to default xml namespac context cx object uri valu call frame clone frozen if frozen kit code bug call frame copi try copi call frame clone catch clone not support except ex throw new illeg state except clone stack but keep var sourc to point to valu from thi frame to share variabl copi stack object stack clone copi s dbl doubl s dbl clone copi frozen fals return copi continu jump continu c call frame current thi captur frame call frame c get implement if thi captur frame null current null continu and current execut doe not share ani frame if there is noth to captur or if there is no current execut frame thi branch frame null els search for branch frame where parent frame chain start from captur and current meet call frame chain1 thi captur frame call frame chain2 current first work parent of chain1 or chain2 until the same frame depth int diff chain1 frame index chain2 frame index if diff 0 if diff 0 swap to make sure that chain1 frame index chain2 frame index and diff 0 chain1 current chain2 thi captur frame diff diff do chain1 chain1 parent frame while diff 0 if chain1 frame index chain2 frame index kit code bug now walk parent in parallel until a share frame is found or until the root is reach while chain1 chain2 chain1 null chain1 chain1 parent frame chain2 chain2 parent frame thi branch frame chain1 if thi branch frame null thi branch frame frozen kit code bug privat static string bytecod name int bytecod if valid bytecod bytecod throw new illeg argument except string valu of bytecod if token printi code return string valu of bytecod if valid token code bytecod return token name bytecod switch bytecod case icod dup return dup case icod dup2 return dup2 case icod swap return swap case icod pop return pop case icod pop result return pop result case icod ifeq pop return ifeq pop case icod var inc dec return var inc dec case icod name inc dec return name inc dec case icod prop inc dec return prop inc dec case icod elem inc dec return elem inc dec case icod ref inc dec return ref inc dec case icod scope load return scope load case icod scope save return scope save case icod typeofnam return typeofnam case icod name and thi return name and thi case icod prop and thi return prop and thi case icod elem and thi return elem and thi case icod valu and thi return valu and thi case icod closur expr return closur expr case icod closur stmt return closur stmt case icod callspeci return callspeci case icod retundef return retundef case icod gosub return gosub case icod startsub return startsub case icod retsub return retsub case icod line return line case icod shortnumb return shortnumb case icod intnumb return intnumb case icod liter new return liter new case icod liter set return liter set case icod spare arraylit return spare arraylit case icod reg ind c0 return reg ind c0 case icod reg ind c1 return reg ind c1 case icod reg ind c2 return reg ind c2 case icod reg ind c3 return reg ind c3 case icod reg ind c4 return reg ind c4 case icod reg ind c5 return reg ind c5 case icod reg ind1 return load ind1 case icod reg ind2 return load ind2 case icod reg ind4 return load ind4 case icod reg str c0 return reg str c0 case icod reg str c1 return reg str c1 case icod reg str c2 return reg str c2 case icod reg str c3 return reg str c3 case icod reg str1 return load str1 case icod reg str2 return load str2 case icod reg str4 return load str4 case icod getvar1 return getvar1 case icod setvar1 return setvar1 case icod undef return undef case icod zero return zero case icod on return on case icod enterdq return enterdq case icod leavedq return leavedq case icod tail call return tail call case icod local clear return local clear icod without name throw new illeg state except string valu of bytecod privat static boolean valid icod int icod return min icod icod icod 1 privat static boolean valid token code int token return token first bytecod token token token token last bytecod token privat static boolean valid bytecod int bytecod return valid icod bytecod valid token code bytecod public object compil compil environ compil env script or fn node tree string encod sourc boolean return function thi compil env compil env new node transform transform tree if token print tree system out println tree to string tree tree if return function tree tree get function node 0 script or fn tree it data new interpret data compil env get languag version script or fn get sourc name encod sourc it data top level true if return function gener functioni code els generatei code from tree script or fn return it data public script creat script object object bytecod object static secur domain interpret data idata interpret data bytecod return interpret function creat script it data static secur domain public function creat function object context cx scriptabl scope object bytecod object static secur domain interpret data idata interpret data bytecod return interpret function creat function cx scope it data static secur domain privat void gener functioni code it in function flag true function node the function function node script or fn it data it function type the function get function type it data it need activ the function requir activ it data it name the function get function name if the function get ignor dynam scope if compil env is us dynam scope it data us dynam scope true generatei code from tree the function get last child privat void generatei code from tree node tree gener nest function gener reg exp liter visit statement tree fix label goto add return result onli to script as function alwai end with return if it data it function type 0 add token token return result if it data itsi code length itsi code top make it data itsi code length exactli itsi code top to save memori and catch bug with jump beyound icod as earli as possibl byte tmp new byte itsi code top system arraycopi it data itsi code 0 tmp 0 itsi code top it data itsi code tmp if it string size 0 it data it string tabl null els it data it string tabl new string it string size obj to int map iter iter it string new iter for iter start iter done iter next string str string iter get kei int index iter get valu if it data it string tabl index null kit code bug it data it string tabl index str if it doubl tabl top 0 it data it doubl tabl null els if it data it doubl tabl length it doubl tabl top doubl tmp new doubl it doubl tabl top system arraycopi it data it doubl tabl 0 tmp 0 it doubl tabl top it data it doubl tabl tmp if it except tabl top 0 it data it except tabl length it except tabl top int tmp new int it except tabl top system arraycopi it data it except tabl 0 tmp 0 it except tabl top it data it except tabl tmp it data it max var script or fn get param and var count it max frame arrai interpret method need thi amount for it stack and s dbl arrai it data it max frame arrai it data it max var it data it max local it data it max stack it data arg name script or fn get param and var name it data arg count script or fn get param count it data encod sourc start script or fn get encod sourc start it data encod sourc end script or fn get encod sourc end if it liter id size 0 it data liter id it liter id to arrai if token printi code dumpi code it data privat void gener nest function int function count script or fn get function count if function count 0 return interpret data arrai new interpret data function count for int i 0 i function count i function node def script or fn get function node i interpret jsi new interpret jsi compil env compil env jsi script or fn def jsi it data new interpret data it data jsi gener functioni code arrai i jsi it data it data it nest function arrai privat void gener reg exp liter int n script or fn get regexp count if n 0 return context cx context get context reg exp proxi rep script runtim check reg exp proxi cx object arrai new object n for int i 0 i n i string string script or fn get regexp string i string flag script or fn get regexp flag i arrai i rep compil reg exp cx string flag it data it reg exp liter arrai privat void updat line number node node int lineno node get lineno if lineno it line number lineno 0 if it data first linepc 0 it data first linepc lineno it line number lineno add icod icod line add uint16 lineno 0xffff privat runtim except bad tree node node throw new runtim except node to string privat void visit statement node node int type node get type node child node get first child switch type case token function int fn index node get exist int prop node function prop int fn type script or fn get function node fn index get function type onli function express or function express statement need closur code creat new function object on stack as function statement ar initi at script function start in addit function express can not present here at statement level thei must onli present as express if fn type function node function express statement add index op icod closur stmt fn index els if fn type function node function statement throw kit code bug break case token script case token label case token loop case token block case token empti case token with updat line number node while child null visit statement child child child get next break case token enterwith visit express child 0 add token token enterwith stack chang 1 break case token leavewith add token token leavewith break case token local block int local alloc local node put int prop node local prop local updat line number node while child null visit statement child child child get next add index op icod local clear local releas local local break case token switch updat line number node see comment in ir factori creat switch for descript of switch node node switch node node jump node visit express child 0 for node jump case node node jump child get next case node null case node node jump case node get next if case node get type token case throw bad tree case node node test case node get first child add icod icod dup stack chang 1 visit express test 0 add token token sheq stack chang 1 if true icod ifeq pop will jump and remov case valu from stack add goto case node target icod ifeq pop stack chang 1 add icod icod pop stack chang 1 break case token target mark target label node break case token ifeq case token ifn node target node jump node target visit express child 0 add goto target type stack chang 1 break case token goto node target node jump node target add goto target type break case token jsr node target node jump node target add goto target icod gosub break case token final account for incom gotosub address stack chang 1 int final regist get local block ref node add index op icod startsub final regist stack chang 1 while child null visit statement child child child get next add index op icod retsub final regist break case token expr void case token expr result updat line number node visit express child 0 add icod type token expr void icod pop icod pop result stack chang 1 break case token try node jump try node node jump node int except object local get local block ref try node int scope local alloc local add index op icod scope save scope local int try start itsi code top while child null visit statement child child child get next node catch target try node target if catch target null int catch startpc it label tabl get target label catch target add except handler try start catch startpc catch startpc fals except object local scope local node final target try node get final if final target null int final startpc it label tabl get target label final target add except handler try start final startpc final startpc true except object local scope local add index op icod local clear scope local releas local scope local break case token catch scope int local index get local block ref node int scope index node get exist int prop node catch scope prop string name child get string child child get next visit express child 0 load express object add string prefix name add index prefix local index add token token catch scope add uint8 scope index 0 1 0 stack chang 1 break case token throw updat line number node visit express child 0 add token token throw add uint16 it line number 0xffff stack chang 1 break case token rethrow updat line number node add index op token rethrow get local block ref node break case token return updat line number node if child null visit express child ecf tail add token token return stack chang 1 els add icod icod retundef break case token return result updat line number node add token token return result break case token enum init kei case token enum init valu visit express child 0 add index op type get local block ref node stack chang 1 break default throw bad tree node if it stack depth 0 throw kit code bug privat void visit express node node int context flag int type node get type node child node get first child int save stack depth it stack depth switch type case token function int fn index node get exist int prop node function prop function node fn script or fn get function node fn index see comment in visit statement for token function case if fn get function type function node function express throw kit code bug add index op icod closur expr fn index stack chang 1 break case token local load int local index get local block ref node add index op token local load local index stack chang 1 break case token comma node last child node get last child while child last child visit express child 0 add icod icod pop stack chang 1 child child get next preserv tail context flag if ani visit express child context flag ecf tail break case token us stack indic that stack wa modifi extern like place catch object stack chang 1 break case token ref call case token call case token new if type token new visit express child 0 els gener call fun and thi child int arg count 0 while child child get next null visit express child 0 arg count int call type node get int prop node specialcal prop node non specialcal if call type node non specialcal emb line number and sourc filenam add index op icod callspeci arg count add uint8 call type add uint8 type token new 1 0 add uint16 it line number 0xffff els if type token call if context flag ecf tail 0 type icod tail call add index op type arg count adjust stack if type token new new f arg result stack chang arg count els call f thi obj arg result ref call f thi obj arg ref stack chang 1 arg count if arg count it data it max calle arg it data it max calle arg arg count break case token and case token or visit express child 0 add icod icod dup stack chang 1 int after second jump start itsi code top int jump type token and token ifn token ifeq add goto op jump stack chang 1 add icod icod pop stack chang 1 child child get next preserv tail context flag if ani visit express child context flag ecf tail resolv forward goto after second jump start break case token hook node if then child get next node if els if then get next visit express child 0 int els jump start itsi code top add goto op token ifn stack chang 1 preserv tail context flag if ani visit express if then context flag ecf tail int after els jump start itsi code top add goto op token goto resolv forward goto els jump start it stack depth save stack depth preserv tail context flag if ani visit express if els context flag ecf tail resolv forward goto after els jump start break case token getprop visit express child 0 child child get next add string op token getprop child get string break case token getelem case token delprop case token bitand case token bitor case token bitxor case token lsh case token rsh case token ursh case token add case token sub case token mod case token div case token mul case token eq case token ne case token sheq case token shne case token in case token instanceof case token le case token lt case token ge case token gt visit express child 0 child child get next visit express child 0 add token type stack chang 1 break case token po case token neg case token not case token bitnot case token typeof case token void visit express child 0 if type token void add icod icod pop add icod icod undef els add token type break case token get ref case token del ref visit express child 0 add token type break case token setprop case token setprop op visit express child 0 child child get next string properti child get string child child get next if type token setprop op add icod icod dup stack chang 1 add string op token getprop properti compens for the follow us stack stack chang 1 visit express child 0 add string op token setprop properti stack chang 1 break case token setelem case token setelem op visit express child 0 child child get next visit express child 0 child child get next if type token setelem op add icod icod dup2 stack chang 2 add token token getelem stack chang 1 compens for the follow us stack stack chang 1 visit express child 0 add token token setelem stack chang 2 break case token set ref case token set ref op visit express child 0 child child get next if type token set ref op add icod icod dup stack chang 1 add token token get ref compens for the follow us stack stack chang 1 visit express child 0 add token token set ref stack chang 1 break case token setnam string name child get string visit express child 0 child child get next visit express child 0 add string op token setnam name stack chang 1 break case token typeofnam string name node get string int index 1 us typeofnam if an activ frame exist sinc the var all exist there instead of in jreg if it in function flag it data it need activ index script or fn get param or var index name if index 1 add string op icod typeofnam name stack chang 1 els add var op token getvar index stack chang 1 add token token typeof break case token bindnam case token name case token string add string op type node get string stack chang 1 break case token inc case token dec visit inc dec node child break case token number doubl num node get doubl int inum int num if inum num if inum 0 add icod icod zero check for neg zeprivat void gener call fun and thi node left gener code to place on stack function and thi obj int type left get type switch type case token name string name left get string stack function thi obj add string op icod name and thi name stack chang 2 break case token getprop case token getelem node target left get first child visit express target 0 node id target get next if type token getprop string properti id get string stack target function thi obj add string op icod prop and thi properti stack chang 1 els visit express id 0 stack target id function thi obj add icod icod elem and thi break default includ token getvar visit express left 0 stack valu function thi obj add icod icod valu and thi stack chang 1 break privat void visit inc dec node node node child int incr decr mask node get exist int prop node incrdecr prop int child type child get type switch child type case token getvar if it data it need activ kit code bug string name child get string int i script or fn get param or var index name add var op icod var inc dec i add uint8 incr decr mask stack chang 1 break case token name string name child get string add string op icod name inc dec name add uint8 incr decr mask stack chang 1 break case token getprop node object child get first child visit express object 0 string properti object get next get string add string op icod prop inc dec properti add uint8 incr decr mask break case token getelem node object child get first child visit express object 0 node index object get next visit express index 0 add icod icod elem inc dec add uint8 incr decr mask stack chang 1 break case token get ref node ref child get first child visit express ref 0 add icod icod ref inc dec add uint8 incr decr mask break default throw bad tree node privat void visit liter node node node child int type node get type int count object properti id null if type token arraylit count 0 for node n child n null n n get next count els if type token objectlit properti id object node get prop node object id prop count properti id length els throw bad tree node add index op icod liter new count stack chang 1 while child null visit express child 0 add icod icod liter set stack chang 1 child child get next if type token arraylit int skip index int node get prop node skip index prop if skip index null add token token arraylit els int index it liter id size it liter id add skip index add index op icod spare arraylit index els int index it liter id size it liter id add properti id add index op token objectlit index privat int get local block ref node node node local block node node get prop node local block prop return local block get exist int prop node local prop privat int get target label node target int label target label id if label 1 return label label it label tabl top if it label tabl null label it label tabl length if it label tabl null it label tabl new int min label tabl size els int tmp new int it label tabl length 2 system arraycopi it label tabl 0 tmp 0 label it label tabl tmp it label tabl top label 1 it label tabl label 1 target label id label return label privat void mark target label node target int label get target label target if it label tabl label 1 can mark label onli onc kit code bug it label tabl label itsi code top privat void add goto node target int goto op int label get target label target if label it label tabl top kit code bug int targetpc it label tabl label if targetpc 1 add backward goto goto op targetpc els int gotopc itsi code top add goto op goto op int top it fixup tabl top if it fixup tabl null top it fixup tabl length if it fixup tabl null it fixup tabl new long min fixup tabl size els long tmp new long it fixup tabl length 2 system arraycopi it fixup tabl 0 tmp 0 top it fixup tabl tmp it fixup tabl top top 1 it fixup tabl top long label 32 gotopc privat void fix label goto for int i 0 i it fixup tabl top i long fixup it fixup tabl i int label int fixup 32 int jump sourc int fixup int pc it label tabl label if pc 1 unloc label throw kit code bug resolv goto jump sourc pc it fixup tabl top 0 privat void add backward goto int goto op int jumppc int frompc itsi code top ensur that thi is a jump backward if frompc jumppc throw kit code bug add goto op goto op resolv goto frompc jumppc privat void resolv forward goto int frompc ensur that forward jump skip at least self bytecod if itsi code top frompc 3 throw kit code bug resolv goto frompc itsi code top privat void resolv goto int frompc int jumppc int offset jumppc frompc ensur that jump do not overlap if 0 offset offset 2 throw kit code bug int offset site frompc 1 if offset short offset if it data long jump null it data long jump new uint map it data long jump put offset site jumppc offset 0 byte arrai it data itsi code arrai offset site byte offset 8 arrai offset site 1 byte offset privat void add token int token if valid token code token throw kit code bug add uint8 token privat void add icod int icod if valid icod icod throw kit code bug write neg icod as uint8 bit add uint8 icod 0xff privat void add uint8 int valu if valu 0xff 0 throw kit code bug byte arrai it data itsi code int top itsi code top if top arrai length arrai increasei code capas 1 arrai top byte valu itsi code top top 1 privat void add uint16 int valu if valu 0xffff 0 throw kit code bug byte arrai it data itsi code int top itsi code top if top 2 arrai length arrai increasei code capas 2 arrai top byte valu 8 arrai top 1 byte valu itsi code top top 2 privat void add int int i byte arrai it data itsi code int top itsi code top if top 4 arrai length arrai increasei code capas 4 arrai top byte i 24 arrai top 1 byte i 16 arrai top 2 byte i 8 arrai top 3 byte i itsi code top top 4 privat int get doubl index doubl num int index it doubl tabl top if index 0 it data it doubl tabl new doubl 64 els if it data it doubl tabl length index doubl na new doubl index 2 system arraycopi it data it doubl tabl 0 na 0 index it data it doubl tabl na it data it doubl tabl index num it doubl tabl top index 1 return index privat void add goto op int goto op byte arrai it data itsi code int top itsi code top if top 3 arrai length arrai increasei code capas 3 arrai top byte goto op offset would written later itsi code top top 1 2 privat void add var op int op int var index switch op case token getvar case token setvar if var index 128 add icod op token getvar icod getvar1 icod setvar1 add uint8 var index return fallthrough case icod var inc dec add index op op var index return throw kit code bug privat void add string op int op string str add string prefix str if valid icod op add icod op els add token op privat void add index op int op int index add index prefix index if valid icod op add icod op els add token op privat void add string prefix string str int index it string get str 1 if index 1 index it string size it string put str index if index 4 add icod icod reg str c0 index els if index 0xff add icod icod reg str1 add uint8 index els if index 0xffff add icod icod reg str2 add uint16 index els add icod icod reg str4 add int index privat void add index prefix int index if index 0 kit code bug if index 6 add icod icod reg ind c0 index els if index 0xff add icod icod reg ind1 add uint8 index els if index 0xffff add icod icod reg ind2 add uint16 index els add icod icod reg ind4 add int index privat void add except handler int icod start int icod end int handler start boolean is final int except object local int scope local int top it except tabl top int tabl it data it except tabl if tabl null if top 0 kit code bug tabl new int except slot size 2 it data it except tabl tabl els if tabl length top tabl new int tabl length 2 system arraycopi it data it except tabl 0 tabl 0 top it data it except tabl tabl tabl top except try start slot icod start tabl top except try end slot icod end tabl top except handler slot handler start tabl top except type slot is final 1 0 tabl top except local slot except object local tabl top except scope slot scope local it except tabl top top except slot size privat byte increasei code capas int extra size int capac it data itsi code length int top itsi code top if top extra size capac throw kit code bug capac 2 if top extra size capac capac top extra size byte arrai new byte capac system arraycopi it data itsi code 0 arrai 0 top it data itsi code arrai return arrai privat void stack chang int chang if chang 0 it stack depth chang els int new depth it stack depth chang if new depth it data it max stack it data it max stack new depth it stack depth new depth privat int alloc local int local slot it local top it local top if it local top it data it max local it data it max local it local top return local slot privat void releas local int local slot it local top if local slot it local top kit code bug privat static int get short byte i code int pc return i code pc 8 i code pc 1 0xff privat static int get index byte i code int pc return i code pc 0xff 8 i code pc 1 0xff privat static int get int byte i code int pc return i code pc 24 i code pc 1 0xff 16 i code pc 2 0xff 8 i code pc 3 0xff privat static int get except handler call frame frame boolean onli final int except tabl frame idata it except tabl if except tabl null no except handler return 1 icod switch in the interpret increment pc immedi and it is necessari to subtract 1 from the save pc to point it befor the start of the next instruct int pc frame pc 1 opt us binari search int best 1 best start 0 best end 0 for int i 0 i except tabl length i except slot size int start except tabl i except try start slot int end except tabl i except try end slot if start pc pc end continu if onli final except tabl i except type slot 1 continu if best 0 sinc handler alwai nest and thei never have share end although thei can share start it is suffici to compar handler end if best end end continu check the abov assumpt if best start start kit code bug should be nest if best end end kit code bug no en share best i best start start best end end return best privat static void dumpi code interpret data idata if token printi code return byte i code idata itsi code int i code length i code length string string idata it string tabl print stream out system out out println i code dump for idata it name length i code length out println max stack idata it max stack int index reg 0 for int pc 0 pc i code length out flush out print pc int token i code pc int icod length bytecod span token string tname bytecod name token int old pc pc pc switch token default if icod length 1 kit code bug out println tname break case icod gosub case token goto case token ifeq case token ifn case icod ifeq pop case icod leavedq int newpc pc get short i code pc 1 out println tname newpc pc 2 break case icod var inc dec case icod name inc dec case icod prop inc dec case icod elem inc dec case icod ref inc dec int incr decr type i code pc out println tname incr decr type pc break case icod callspeci int call type i code pc 0xff boolean is new i code pc 1 0 int line get index i code pc 2 out println tname call type is new index reg line pc 4 break case token catch scope boolean after fisrt flag i code pc 0 out println tname after fisrt flag pc break case token regexp out println tname idata it reg exp liter index reg break case token objectlit case icod spare arraylit out println tname idata liter id index reg break case icod closur expr case icod closur stmt out println tname idata it nest function index reg break case token call case icod tail call case token ref call case token new out println tname index reg break case token throw int line get index i code pc out println tname line pc 2 break case icod shortnumb int valu get short i code pc out println tname valu pc 2 break case icod intnumb int valu get int i code pc out println tname valu pc 4 break case token number doubl valu idata it doubl tabl index reg out println tname valu pc 2 break case icod line int line get index i code pc out println tname line pc 2 break case icod reg str1 string str string 0xff i code pc out println tname str pc break case icod reg str2 string str string get index i code pc out println tname str pc 2 break case icod reg str4 string str string get int i code pc out println tname str pc 4 break case icod reg ind1 index reg 0xff i code pc out println tname index reg pc break case icod reg ind2 index reg get index i code pc out println tname index reg pc 2 break case icod reg ind4 index reg get int i code pc out println tname index reg pc 4 break case icod getvar1 case icod setvar1 index reg i code pc out println tname index reg pc break if old pc icod length pc kit code bug int tabl idata it except tabl if tabl null out println except handler tabl length except slot size for int i 0 i tabl length i except slot size int try start tabl i except try start slot int try end tabl i except try end slot int handler start tabl i except handler slot int type tabl i except type slot int except local tabl i except local slot int scope local tabl i except scope slot out println try start try start try end try end handler start handler start type type 0 catch final except local except local out flush privat static int bytecod span int bytecod switch bytecod case token throw sourc line return 1 2 case icod gosub case token goto case token ifeq case token ifn case icod ifeq pop case icod leavedq target pc offset return 1 2 case icod callspeci call type is new line number return 1 1 1 2 case token catch scope scope flag return 1 1 case icod var inc dec case icod name inc dec case icod prop inc dec case icod elem inc dec case icod ref inc dec type of return 1 1 case icod shortnumb short number return 1 2 case icod intnumb int number return 1 4 case icod reg ind1 ubyt index return 1 1 case icod reg ind2 ushort index return 1 2 case icod reg ind4 int index return 1 4 case icod reg str1 ubyt string index return 1 1 case icod reg str2 ushort string index return 1 2 case icod reg str4 int string index return 1 4 case icod getvar1 case icod setvar1 byte var index return 1 1 case icod line line number return 1 2 if valid bytecod bytecod throw kit code bug return 1 static int get line number interpret data data uint map present line new uint map byte i code data itsi code int i code length i code length for int pc 0 pc i code length int bytecod i code pc int span bytecod span bytecod if bytecod icod line if span 3 kit code bug int line get index i code pc 1 present line put line 0 pc span return present line get kei static void captur interpret stack info rhino except ex context cx context get current context if cx null cx last interpret frame null no interpret invoc ex interpret stack info null ex interpret line data null return ha interpret frame on the stack call frame arrai if cx previou interpret invoc null cx previou interpret invoc size 0 arrai new call frame 1 els int previou count cx previou interpret invoc size if cx previou interpret invoc peek cx last interpret frame it can happen if except wa gener after frame wa push to cx previou interpret invoc but befor assign to cx last interpret frame in thi case frame ha to be ignor previou count arrai new call frame previou count 1 cx previou interpret invoc to arrai arrai arrai arrai length 1 call frame cx last interpret frame int interpret frame count 0 for int i 0 i arrai length i interpret frame count 1 arrai i frame index int linepc new int interpret frame count fill linepc with pc posit from all interpret frame start from the most nest frame int linepc index interpret frame count for int i arrai length i 0 i call frame frame arrai i while frame null linepc index linepc linepc index frame pc sourc line start frame frame parent frame if linepc index 0 kit code bug ex interpret stack info arrai ex interpret line data linepc static string get sourc posit from stack context cx int linep call frame frame call frame cx last interpret frame interpret data idata frame idata if frame pc sourc line start 0 linep 0 get index idata itsi code frame pc sourc line start els linep 0 0 return idata it sourc file static string get patch stack rhino except ex string nativ stack trace string tag org mozilla javascript interpret interpret loop string buffer sb new string buffer nativ stack trace length 1000 string line separ system get properti line separ call frame arrai call frame ex interpret stack info int linepc ex interpret line data int arrai index arrai length int linepc index linepc length int offset 0 while arrai index 0 arrai index int po nativ stack trace index of tag offset if po 0 break skip tag length po tag length skip until the end of line for po nativ stack trace length po char c nativ stack trace char at po if c n c r break sb append nativ stack trace substr offset po offset po call frame frame arrai arrai index while frame null if linepc index 0 kit code bug linepc index interpret data idata frame idata sb append line separ sb append tat script if idata it name null idata it name length 0 sb append sb append idata it name sb append sb append idata it sourc file int pc linepc linepc index if pc 0 includ line info onli if avail sb append sb append get index idata itsi code pc sb append frame frame parent frame sb append nativ stack trace substr offset return sb to string static string get encod sourc interpret data idata if idata encod sourc null return null return idata encod sourc substr idata encod sourc start idata encod sourc end privat static void init function context cx scriptabl scope interpret function parent int index interpret function fn fn interpret function creat function cx scope parent index script runtim init function cx scope fn fn idata it function type parent idata eval script flag static object interpret interpret function ifun context cx scriptabl scope scriptabl thi obj object arg if script runtim ha top call cx kit code bug if cx interpret secur domain ifun secur domain object save domain cx interpret secur domain cx interpret secur domain ifun secur domain try return ifun secur control call with domain ifun secur domain cx ifun scope thi obj arg final cx interpret secur domain save domain call frame frame new call frame init frame cx scope thi obj arg null 0 arg length ifun null frame return interpret loop cx frame null public static object restart continu continu c context cx scriptabl scope object arg if script runtim ha top call cx return script runtim do top call c cx scope null arg object arg if arg length 0 arg undefin instanc els arg arg 0 call frame captur frame call frame c get implement if captur frame null no frame to restart return arg continu jump cjump new continu jump c null cjump result arg return interpret loop cx null cjump privat static object interpret loop context cx call frame frame object throwabl throwabl hold except object to rethrow or catch it is also us for continu restart in which case it hold continu jump final object dbl mrk uniqu tag doubl mark final object undefin undefin instanc final boolean instruct count cx instruct threshold 0 arbitrari number to add to instruct count when call other function final int invoc cost 100 arbitrari except cost for instruct count final int except cost 100 string string reg null int index reg 1 if cx last interpret frame null save the top frame from the previou interpret loop invoc on the stack if cx previou interpret invoc null cx previou interpret invoc new obj arrai cx previou interpret invoc push cx last interpret frame when restart continu throwabl is not null and to jump to the code that rewind continu state index reg should be set to 1 with the normal call throabl null and index reg 1 allow to catch bug with us ind reg to access arrai eleemnt befor initi index reg if throwabl null assert assumpt if throwabl instanceof continu jump it should be continu kit code bug object interpret result null doubl interpret result dbl 0 0 state loop for without except try if throwabl null recov from except index reg contain the index of handler if index reg 0 normal excepton handler transfer control appropri if frame frozen xxx deal with exceptio frame frame clone frozen int tabl frame idata it except tabl frame pc tabl index reg except handler slot if instruct count frame pc prev branch frame pc frame save stack top frame empti stack top int scope local frame local shift tabl index reg except scope slot int ex local frame local shift tabl index reg except local slot frame scope scriptabl frame stack scope local frame stack ex local throwabl throwabl null els continu restor continu jump cjump continu jump throwabl clear throwabl to indic that execpt ar ok throwabl null if cjump branch frame frame kit code bug check that we have at least on frozen frame in the case of detach continu restor unwind code ensur that if cjump captur frame null kit code bug need to rewind branch frame captur frame and all frame in between int rewind count cjump captur frame frame index 1 if cjump branch frame null rewind count cjump branch frame frame index int enter count 0 call frame enter frame null call frame x cjump captur frame for int i 0 i rewind count i if x frozen kit code bug if is frame enter exit requir x if enter frame null alloc enough space to store the rest of rewind frame in case all of them would requir to enter enter frame new call frame rewind count i enter frame enter count x enter count x x parent frame while enter count 0 execut enter walk enter frame in the revers order sinc thei were store start from the captur frame not branch frame enter count x enter frame enter count enter frame cx x script runtim empti arg continu jump is almost done captur frame point to the call to the function that captur continu so clone captur frame and emul return that function with the supli result frame cjump captur frame clone frozen set call result frame cjump result cjump result dbl restart the execut should be alreadi clear if throwabl null kit code bug els if frame frozen kit code bug us local variabl for constant valu in frame for faster access object stack frame stack doubl s dbl frame s dbl object var frame var sourc stack doubl var dbl frame var sourc s dbl byte i code frame idata itsi code string string frame idata it string tabl us local for stack top as well sinc execpt handler can onli exist at statement level where stack is empti it is necessari to save restor stack top onli accross function call and normal return int stack top frame save stack top store new frame in cx which is us for error report etc cx last interpret frame frame loop for except handler assum that pc is alreadi increment pass the instruct start when it search the except handler int op i code frame pc jumpless run back indent to eas imlement read switch op case token throw object valu stack stack top if valu dbl mrk valu script runtim wrap number s dbl stack top stack top int sourc line get index i code frame pc throwabl new java script except valu frame idata it sourc file sourc line break without except case token rethrow index reg frame local shift throwabl stack index reg break without except case token ge case token le case token gt case token lt stack top object rh stack stack top 1 object lh stack stack top boolean val bln object compar number compar doubl r dbl l dbl if rh dbl mrk r dbl s dbl stack top 1 l dbl stack doubl frame stack top els if lh dbl mrk r dbl script runtim to number rh l dbl s dbl stack top els break number compar switch op case token ge val bln l dbl r dbl break object compar case token le val bln l dbl r dbl break object compar case token gt val bln l dbl r dbl break object compar case token lt val bln l dbl r dbl break object compar default throw kit code bug switch op case token ge val bln script runtim cmp le rh lh break case token le val bln script runtim cmp le lh rh break case token gt val bln script runtim cmp lt rh lh break case token lt privat static void init frame context cx scriptabl caller scope scriptabl thi obj object arg doubl arg dbl int arg shift int arg count interpret function fn or script call frame parent frame call frame frame interpret data idata fn or script idata boolean us activ idata it need activ debug frame debugg frame null if cx debugg null debugg frame cx debugg get frame cx idata if debugg frame null us activ true if us activ copi arg to new arrai to pass to enter activ function or debugg frame on enter if arg dbl null arg get arg arrai arg arg dbl arg shift arg count arg shift 0 arg dbl null scriptabl scope if idata it function type 0 if idata us dynam scope scope fn or script get parent scope els scope caller scope if us activ scope script runtim creat function activ fn or script scope arg els scope caller scope script runtim init script fn or script thi obj cx scope fn or script idata eval script flag if idata it nest function null if idata it function type 0 idata it need activ kit code bug for int i 0 i idata it nest function length i interpret data fdata idata it nest function i if fdata it function type function node function statement init function cx scope fn or script i scriptabl script reg exp null if idata it reg exp liter null wrap regexp for function ar store in interpret function but for script which should not contain refer to scope the regexp re wrap dure each script execut if idata it function type 0 script reg exp fn or script function reg exp els script reg exp fn or script creat reg exp wrap cx scope initi arg var local and stack int empti stack top idata it max var idata it max local 1 int max frame arrai idata it max frame arrai if max frame arrai empti stack top idata it max stack 1 kit code bug object stack doubl s dbl boolean stack reus if frame stack null max frame arrai frame stack length reus stack from old frame stack reus true stack frame stack s dbl frame s dbl els stack reus fals stack new object max frame arrai s dbl new doubl max frame arrai int defin arg idata arg count if defin arg arg count defin arg arg count fill the frame structur frame parent frame parent frame frame frame index parent frame null 0 parent frame frame index 1 if frame frame index cx get maximum interpret stack depth throw context report runtim error exceed maximum stack depth frame frozen fals frame fn or script fn or script frame idata idata frame stack stack frame s dbl s dbl frame var sourc frame frame local shift idata it max var frame empti stack top empti stack top frame debugg frame debugg frame frame us activ us activ frame thi obj thi obj frame script reg exp script reg exp initi initi valu of variabl that chang dure interpret frame result undefin instanc frame pc 0 frame pc prev branch 0 frame pc sourc line start idata first linepc frame scope scope frame save stack top empti stack top frame save call op 0 system arraycopi arg arg shift stack 0 defin arg if arg dbl null system arraycopi arg dbl arg shift s dbl 0 defin arg for int i defin arg i idata it max var i stack i undefin instanc if stack reus clean the stack part and space beyond stack if ani of the old arrai to allow to gc object there for int i empti stack top 1 i stack length i stack i null enter frame cx frame arg privat static boolean is frame enter exit requir call frame frame return frame debugg frame null frame idata it need activ privat static void enter frame context cx call frame frame object arg if frame debugg frame null frame debugg frame on enter cx frame scope frame thi obj arg if frame idata it need activ enter activ onli when it need activ true not when us activ hold sinc debugg should not interfer with activ chain script runtim enter activ function cx frame scope privat static void exit frame context cx call frame frame object throwabl if frame idata it need activ script runtim exit activ function cx if frame debugg frame null try if throwabl instanceof throwabl frame debugg frame on exit cx true throwabl els object result continu jump cjump continu jump throwabl if cjump null result frame result els result cjump result if result uniqu tag doubl mark doubl result dbl if cjump null result dbl frame result dbl els result dbl cjump result dbl result script runtim wrap number result dbl frame debugg frame on exit cx fals result catch throwabl ex system err println rhino usag warn on exit termin with except ex print stack trace system err privat static void set call result call frame frame object call result doubl call result dbl if frame save call op token call frame stack frame save stack top call result frame s dbl frame save stack top call result dbl els if frame save call op token new if construct return scriptabl then it replac on stack top save origin instanc of the object if call result instanceof scriptabl frame stack frame save stack top call result els kit code bug frame save call op 0 privat static void captur continu context cx call frame frame int stack top continu c new continu script runtim set object proto and parent c script runtim get top call scope cx make sure that all frame upstack frame ar frozen call frame x frame parent frame while x null x frozen x frozen true allow to gc unus stack space for int i x save stack top 1 i x stack length i allow to gc unus stack space x stack i null if x save call op token call the call will alwai overwrit the stack top with the result x stack x save stack top null els if x save call op token new kit code bug the new oper us stack top to store the construct object so it shall not be clear see comment in set call result x x parent frame c init implement frame parent frame frame stack stack top c privat static int stack int32 call frame frame int i object x frame stack i doubl valu if x uniqu tag doubl mark valu frame s dbl i els valu script runtim to number x return script runtim to int32 valu privat static doubl stack doubl call frame frame int i object x frame stack i if x uniqu tag doubl mark return script runtim to number x els return frame s dbl i privat static boolean stack boolean call frame frame int i object x frame stack i if x boolean true return true els if x boolean fals return fals els if x uniqu tag doubl mark doubl d frame s dbl i return d d d 0 0 els if x null x undefin instanc return fals els if x instanceof number doubl d number x doubl valu return d d d 0 0 els if x instanceof boolean return boolean x boolean valu els return script runtim to boolean x privat static void do add object stack doubl s dbl int stack top context cx object rh stack stack top 1 object lh stack stack top doubl d boolean left right order if rh uniqu tag doubl mark d s dbl stack top 1 if lh uniqu tag doubl mark s dbl stack top d return left right order true fallthrough to object number code els if lh uniqu tag doubl mark d s dbl stack top lh rh left right order fals fallthrough to object number code els if lh instanceof scriptabl rh instanceof scriptabl stack stack top script runtim add lh rh cx els if lh instanceof string string lstr string lh string rstr script runtim to string rh stack stack top lstr concat rstr els if rh instanceof string string lstr script runtim to string lh string rstr string rh stack stack top lstr concat rstr els doubl l dbl lh instanceof number number lh doubl valu script runtim to number lh doubl r dbl rh instanceof number number rh doubl valu script runtim to number rh stack stack top uniqu tag doubl mark s dbl stack top l dbl r dbl return handl object lh number d code if lh instanceof scriptabl rh script runtim wrap number d if left right order object tmp lh lh rh rh tmp stack stack top script runtim add lh rh cx els if lh instanceof string string lstr string lh string rstr script runtim to string d if left right order stack stack top lstr concat rstr els stack stack top rstr concat lstr els doubl l dbl lh instanceof number number lh doubl valu script runtim to number lh stack stack top uniqu tag doubl mark s dbl stack top l dbl d privat static object get arg arrai object stack doubl s dbl int shift int count if count 0 return script runtim empti arg object arg new object count for int i 0 i count i shift object val stack shift if val uniqu tag doubl mark val script runtim wrap number s dbl shift arg i val return arg privat static void add instruct count context cx call frame frame int extra cx instruct count frame pc frame pc prev branch extra if cx instruct count cx instruct threshold cx observ instruct count cx instruct count cx instruct count 0 java member scriptabl scope class cl thi member new hashtabl 23 thi static member new hashtabl 7 thi cl cl reflect scope boolean ha string name boolean is static hashtabl ht is static static member member object obj ht get name if obj null return true els return null find explicit function name is static object get scriptabl scope string name object java object boolean is static hashtabl ht is static static member member object member ht get name if is static member null try to get static member from instanc lc3 member static member get name if member null member thi get explicit function scope name java object is static if member null return scriptabl not found if member instanceof scriptabl return member context cx context get context object rval class type try if member instanceof bean properti bean properti bp bean properti member if bp getter null return scriptabl not found rval bp getter invok java object context empti arg type bp getter method get return type els field field field member rval field get is static null java object type field get type catch except ex throw context throw as script runtim ex ex need to wrap the object befor we return it scope scriptabl object get top level scope scope return cx get wrap factori wrap cx scope rval type void put scriptabl scope string name object java object object valu boolean is static hashtabl ht is static static member member object member ht get name if is static member null try to get static member from instanc lc3 member static member get name if member null throw report member not found name if member instanceof field and method field and method fam field and method ht get name member fam field is thi a bean properti set if member instanceof bean properti bean properti bp bean properti member if bp setter null throw report member not found name if there s onli on setter or if the valu is null us the main setter otherwis let the nativ java method decid which setter to us if bp setter null valu null class set type bp setter arg type 0 object arg context js to java valu set type try bp setter invok java object arg catch except ex throw context throw as script runtim ex ex els object arg valu bp setter call context get context scriptabl object get top level scope scope scope arg els if member instanceof field string str member null msg java intern privat msg java method assign throw context report runtim error1 str name field field field member object java valu context js to java valu field get type try field set java object java valu catch illeg access except access ex throw new runtim except unexpect illeg access except access java field catch illeg argument except arg ex throw context report runtim error3 msg java intern field type valu get class get name field java object get class get name object get id boolean is static hashtabl ht is static static member member int len ht size object result new object len enumer kei ht kei for int i 0 i len i result i kei next element return result static string java signatur class type if type is arrai return type get name els int arrai dimens 0 do arrai dimens type type get compon type while type is arrai string name type get name string suffix if arrai dimens 1 return name concat suffix els int length name length arrai dimens suffix length string buffer sb new string buffer length sb append name while arrai dimens 0 arrai dimens sb append suffix return sb to string static string live connect signatur class arg type int n arg type length if n 0 return string buffer sb new string buffer sb append for int i 0 i n i if i 0 sb append sb append java signatur arg type i sb append return sb to string privat member box find explicit function string name boolean is static int sig start name index of if sig start 0 return null hashtabl ht is static static member member member box method or ctor null boolean is ctor is static sig start 0 if is ctor explicit request for an overload constructor method or ctor ctor els explicit request for an overload method string true name name substr 0 sig start object obj ht get true name if is static obj null try to get static member from instanc lc3 obj static member get true name if obj instanceof nativ java method nativ java method njm nativ java method obj method or ctor njm method if method or ctor null for int i 0 i method or ctor length i class type method or ctor i arg type string sig live connect signatur type if sig start sig length name length name region match sig start sig 0 sig length return method or ctor i return null privat object get explicit function scriptabl scope string name object java object boolean is static hashtabl ht is static static member member object member null member box method or ctor find explicit function name is static if method or ctor null scriptabl prototyp scriptabl object get function prototyp scope if method or ctor is ctor nativ java constructor fun new nativ java constructor method or ctor fun set prototyp prototyp member fun ht put name fun els string true name method or ctor get name member ht get true name if member instanceof nativ java method nativ java method member method length 1 nativ java method fun new nativ java method method or ctor name fun set prototyp prototyp ht put name fun member fun return member privat void reflect scriptabl scope we reflect method first becaus we want overload field method name to be alloc to the nativ java method befor the field get in the wai method method cl get method for int i 0 i method length i method method method i int mod method get modifi if modifi is public mod continu boolean is static modifi is static mod hashtabl ht is static static member member string name method get name object valu ht get name if valu null ht put name method els obj arrai overload method if valu instanceof obj arrai overload method obj arrai valu els if valu instanceof method kit code bug valu should be instanc of method as at thi stage static member and member can onli contain method overload method new obj arrai overload method add valu ht put name overload method overload method add method replac method instanc by wrap nativ java method object first in static member and then in member for int tabl cursor 0 tabl cursor 2 tabl cursor boolean is static tabl cursor 0 hashtabl ht is static static member member enumer e ht kei while e ha more element string name string e next element member box method box object valu ht get name if valu instanceof method method box new member box 1 method box 0 new member box method valu els obj arrai overload method obj arrai valu int n overload method size if n 2 kit code bug method box new member box n for int i 0 i n i method method method overload method get i method box i new member box method nativ java method fun new nativ java method method box if scope null script runtim set function proto and parent fun scope ht put name fun reflect field field field cl get field for int i 0 i field length i field field field i int mod field get modifi if modifi is public mod continu boolean is static modifi is static mod hashtabl ht is static static member member string name field get name object member ht get name if member null ht put name field els if member instanceof nativ java method nativ java method method nativ java method member field and method fam new field and method scope method method field hashtabl fmht is static static field and method field and method if fmht null fmht new hashtabl 4 if is static static field and method fmht els field and method fmht fmht put name fam ht put name fam els if member instanceof field field old field field member if thi newli reflect field shadow an inherit field then replac it otherwis sinc access to the field would be ambigu from java no field should be reflect for now the first field found win unless anoth field explicitli shadow it if old field get declar class is assign from field get declar class ht put name field els unknown member type kit code bug creat bean propeti from correspond get set method first for static member and then for instanc member for int tabl cursor 0 tabl cursor 2 tabl cursor boolean is static tabl cursor 0 hashtabl ht is static static member member hashtabl to add new hashtabl now for each member make bean properti for enumer e ht kei e ha more element is thi a getter string name string e next element boolean member is get method name start with get boolean member is set method name start with set boolean member is is method name start with is if member is get method member is is method member is set method doubl check name compon string name compon name substr member is is method 2 3 if name compon length 0 continu make the bean properti name string bean properti name name compon char ch0 name compon char at 0 if charact is upper case ch0 if name compon length 1 bean properti name name compon to lower case els char ch1 name compon char at 1 if charact is upper case ch1 bean properti name charact to lower case ch0 name compon substr 1 if we alreadi have a member by thi name don t do thi properti if ht contain kei bean properti name to add contain kei bean properti name continu find the getter method or if there is none the is method member box getter null string getter name get concat name compon string is name is concat name compon getter find getter is static ht getter name if there wa no valid getter check for an is method if getter null getter find getter is static ht is name setter member box setter null nativ java method setter null string setter name set concat name compon if ht contain kei setter name is thi valu a method object member ht get setter name if member instanceof nativ java method nativ java method njm set nativ java method member if getter null we have a getter now do we have a match setter class type getter method get return type setter extract set method type njm set method is static els no getter find ani set method setter extract set method njm set method is static if njm set method length 1 setter njm set make the properti bean properti bp new bean properti getter setter setter to add put bean properti name bp add the new bean properti for enumer e to add kei e ha more element object kei e next element object valu to add get kei ht put kei valu reflect constructor constructor constructor cl get constructor ctor new member box constructor length for int i 0 i constructor length i ctor i new member box constructor i privat member box find getter boolean is static hashtabl ht string getter name if ht contain kei getter name check that the getter is a method object member ht get getter name if member instanceof nativ java method nativ java method njm get nativ java method member return extract get method njm get method is static return null privat static member box extract get method member box method boolean is static inspect the list of all member box for the onli on have no paramet for int method idx 0 method idx method length method idx member box method method method idx doe getter method have an empti paramet list with a return valu eg a get someth or is someth if method arg type length 0 is static method is static class type method method get return type if type void type return method break return null privat static member box extract set method class type member box method boolean is static note it mai be prefer to allow nativ java method find function to find the appropri setter unfortun it requir an instanc of the target arg to determin that make two pass on to find a method with direct type assign and on to find a widen convers for int pass 1 pass 2 pass for int i 0 i method length i member box method method i if is static method is static if method method get return type void type class param method arg type if param length 1 if pass 1 if param 0 type return method els if pass 2 kit code bug if param 0 is assign from type return method return null privat static member box extract set method member box method boolean is static for int i 0 i method length i member box method method i if is static method is static if method method get return type void type if method arg type length 1 return method return null hashtabl get field and method object scriptabl scope object java object boolean is static hashtabl ht is static static field and method field and method if ht null return null int len ht size hashtabl result new hashtabl len enumer e ht element while len 0 field and method fam field and method e next element field and method fam new new field and method scope fam method fam field fam new java object java object result put fam field get name fam new return result static java member lookup class scriptabl scope class dynam type class static type java member member class cach cach class cach get scope hashtabl ct cach class tabl class cl dynam type for member java member ct get cl if member null return member try member new java member cach scope cl break catch secur except e reflect mai fail for object that ar in a restrict access packag e g sun if we get a secur except try again with the static type if it is interfac otherwis try superclass if static type null static type is interfac cl static type static type null try static type onli onc els class parent cl get superclass if parent null if cl is interfac last resort after fail static type interfac parent script runtim object class els throw e cl parent if cach is cach enabl ct put cl member return member runtim except report member not found string member name return context report runtim error2 msg java member not found cl get name member name bean properti member box getter member box setter nativ java method setter thi getter getter thi setter setter thi setter setter field and method scriptabl scope member box method field field super method thi field field set parent scope scope set prototyp scriptabl object get function prototyp scope public object get default valu class hint if hint script runtim function class return thi object rval class type try rval field get java object type field get type catch illeg access except acc ex throw context report runtim error1 msg java intern privat field get name context cx context get context rval cx get wrap factori wrap cx thi rval type if rval instanceof scriptabl rval scriptabl rval get default valu hint return rval static final long serial versionuid 8743165779676009808l public evalu except string detail super detail creat an except with the specifi detail messag error intern to the java script engin will simpli throw a runtim except param detail the error messag param sourc name the name of the sourc repons for the error param line number the line number of the sourc public evalu except string detail string sourc name int line number thi detail sourc name line number null 0 creat an except with the specifi detail messag error intern to the java script engin will simpli throw a runtim except param detail the error messag param sourc name the name of the sourc repons for the error param line number the line number of the sourc param column number the column number of the sourc mai be zero if unknown param line sourc the sourc of the line contain the error mai be null if unknown public evalu except string detail string sourc name int line number string line sourc int column number super detail record error origin sourc name line number line sourc column number deprec us link rhino except sourc name from the super class public string get sourc name return sourc name deprec us link rhino except line number from the super class public int get line number return line number deprec us link rhino except column number from the super class public int get column number return column number deprec us link rhino except line sourc from the super class public string get line sourc return line sourc static void init scriptabl scope boolean seal nativ boolean obj new nativ boolean fals obj export asj class max prototyp id scope seal privat nativ boolean boolean b boolean valu b public string get class name return boolean public object get default valu class type hint thi is actual non ecma but will be propos as a chang in round 2 if type hint script runtim boolean class return script runtim wrap boolean boolean valu return super get default valu type hint protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 0 s to string break case id to sourc ariti 0 s to sourc break case id valu of ariti 0 s valu of break default throw new illeg argument except string valu of id init prototyp method boolean tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag boolean tag return super exec id call f cx scope thi obj arg int id f method id if id id constructor boolean b script runtim to boolean arg 0 if thi obj null new boolean val creat a new boolean object return new nativ boolean b boolean val convert val to a boolean return script runtim wrap boolean b the rest of boolean prototyp method requir thi obj to be boolean if thi obj instanceof nativ boolean throw incompat call error f boolean valu nativ boolean thi obj boolean valu switch id case id to string return valu true fals case id to sourc return valu new boolean true new boolean fals case id valu of return script runtim wrap boolean valu throw new illeg argument except string valu of id protect int find prototyp id string s int id gener last updat 2004 03 17 13 28 00 cet l0 id 0 string x null int c int s length s length if s length 7 x valu of id id valu of els if s length 8 c s char at 3 if c o x to sourc id id to sourc els if c t x to string id id to string els if s length 11 x constructor id id constructor if x null x s x equal s id 0 gener return id public string choos file if cwd null string dir system get properti user dir if dir null cwd new file dir if cwd null dlg set current directori cwd dlg set dialog titl select a file to load int return val dlg show open dialog thi if return val j file chooser approv option string result dlg get select file get path cwd new file dlg get select file get parent return result return null public static void main string arg js consol consol new js consol arg public void creat file chooser dlg new j file chooser javax swing filechoos file filter filter new javax swing filechoos file filter public boolean accept file f if f is directori return true string name f get name int i name last index of if i 0 i name length 1 string ext name substr i 1 to lower case if ext equal js return true return fals public string get descript return java script file js dlg add choosabl file filter filter new javax swing filechoos file filter public boolean accept file f if f is directori return true string name f get name int i name last index of if i 0 i name length 1 string ext name substr i 1 to lower case if ext equal js return true return fals public string get descript return java script file js public js consol string arg super rhino java script consol j menu bar menubar new j menu bar creat file chooser string file item load exit string file cmd load exit char file short cut l x string edit item cut copi past char edit short cut t c p string plaf item metal window motif boolean plaf state true fals fals j menu file menu new j menu file file menu set mnemon f j menu edit menu new j menu edit edit menu set mnemon e j menu plaf menu new j menu platform plaf menu set mnemon p for int i 0 i file item length i j menu item item new j menu item file item i file short cut i item set action command file cmd i item add action listen thi file menu add item for int i 0 i edit item length i j menu item item new j menu item edit item i edit short cut i item add action listen thi edit menu add item button group group new button group for int i 0 i plaf item length i j radio button menu item item new j radio button menu item plaf item i plaf state i group add item item add action listen thi plaf menu add item menubar add file menu menubar add edit menu menubar add plaf menu setj menu bar menubar consol text area new consol text area arg j scroll pane scroller new j scroll pane consol text area set content pane scroller consol text area set row 24 consol text area set column 80 add window listen new window adapt public void window close window event e system exit 0 pack set visibl true system set in consol text area get in system set out consol text area get out system set err consol text area get err main set in consol text area get in main set out consol text area get out main set err consol text area get err main main arg consol text area set column 80 add window listen new window adapt public void window close window event e system exit 0 public void action perform action event e string cmd e get action command string plaf name null if cmd equal load string f choos file if f null f f replac consol text area eval load f els if cmd equal exit system exit 0 els if cmd equal cut consol text area cut els if cmd equal copi consol text area copi els if cmd equal past consol text area past els if cmd equal metal plaf name javax swing plaf metal metal look and feel els if cmd equal window plaf name com sun java swing plaf window window look and feel els if cmd equal motif plaf name com sun java swing plaf motif motif look and feel if plaf name null try ui manag set look and feel plaf name swing util updat compon treeui thi consol text area post updateui updat compon treeui seem to mess up the file chooser dialog so just creat a new on creat file chooser catch except exc j option pane show messag dialog thi exc get messag platform j option pane error messag privat quit action quit action public global public global context cx init cx set the action to call from quit public void init quit action quit action quit action if quit action null throw new illeg argument except quit action is null if thi quit action null throw new illeg argument except the method is onc call thi quit action quit action public void init context factori factori factori call new context action public object run context cx init cx return null factori call new context action public object run context cx init cx return null public void init context cx defin some global function particular to the shell note that these function ar not part of ecma init standard object cx seal std lib string name defin class deseri help load load class print quit read file read url run command seal serial spawn sync toint32 version defin function properti name global class scriptabl object dontenum set up environ in the global scope to provid access to the system environ variabl environ defin class thi environ environ new environ thi defin properti environ environ scriptabl object dontenum histori nativ arrai cx new arrai thi 0 defin properti histori histori scriptabl object dontenum initi true print a help messag thi method is defin as a java script function public static void help context cx scriptabl thi obj object arg function fun obj print stream out get instanc fun obj get out out println tool error report get messag msg help print the string valu of it argument thi method is defin as a java script function note that it argument ar of the vararg form which allow it to handl an arbitrari number of argument suppli to the java script function public static object print context cx scriptabl thi obj object arg function fun obj print stream out get instanc fun obj get out for int i 0 i arg length i if i 0 out print convert the arbitrari java script valu into a string form string s context to string arg i out print s out println return context get undefin valu call embed specif quit action pass it argument as int32 exit code thi method is defin as a java script function public static void quit context cx scriptabl thi obj object arg function fun obj global global get instanc fun obj if global quit action null int exit code arg length 0 0 script runtim to int32 arg 0 global quit action quit cx exit code get and set the languag version thi method is defin as a java script function public static doubl version context cx scriptabl thi obj object arg function fun obj doubl result doubl cx get languag version if arg length 0 doubl d context to number arg 0 cx set languag version int d return result load and execut a set of java script sourc file thi method is defin as a java script function public static void load context cx scriptabl thi obj object arg function fun obj for int i 0 i arg length i main process file cx thi obj context to string arg i load a java class that defin a java script object us the convent outlin in scriptabl object defin class p thi method is defin as a java script function except illeg access except if access is not avail to a reflect class member except instanti except if unabl to instanti the name class except invoc target except if an except is thrown dure execut of method of the name class except class definit except if the format of the class caus thi except in scriptabl object defin class see org mozilla javascript scriptabl object defin class public static void defin class context cx scriptabl thi obj object arg function fun obj throw illeg access except instanti except invoc target except class clazz get class arg scriptabl object defin class thi obj clazz load and execut a script compil to a class file p thi method is defin as a java script function when call as a java script function a singl argument is expect thi argument should be the name of a class that implement the script interfac as will ani script compil by jsc except illeg access except if access is not avail to the class except instanti except if unabl to instanti the name class except invoc target except if an except is thrown dure execut of method of the name class see org mozilla javascript scriptabl object defin class public static void load class context cx scriptabl thi obj object arg function fun obj throw illeg access except instanti except invoc target except class clazz get class arg if script class is assign from clazz throw report runtim error msg must implement script script script script clazz new instanc script exec cx thi obj privat static class get class object arg throw illeg access except instanti except invoc target except if arg length 0 throw report runtim error msg expect string arg object arg0 arg 0 if arg0 instanceof wrapper object wrap wrapper arg0 unwrap if wrap instanceof class return class wrap string class name context to string arg 0 try return class for name class name catch class not found except cnfe throw report runtim error msg class not found class name public static void serial context cx scriptabl thi obj object arg function fun obj throw io except if arg length 2 throw context report runtim error expect an object to serial and a filenam to write the serial to object obj arg 0 string filenam context to string arg 1 file output stream fo new file output stream filenam scriptabl scope scriptabl object get top level scope thi obj scriptabl output stream out new scriptabl output stream fo scope out write object obj out close public static object deseri context cx scriptabl thi obj object arg function fun obj throw io except class not found except if arg length 1 throw context report runtim error expect a filenam to read the serial from string filenam context to string arg 0 file input stream fi new file input stream filenam scriptabl scope scriptabl object get top level scope thi obj object input stream in new scriptabl input stream fi scope object deseri in read object in close return context to object deseri scope the spawn function run a given function or script in a differ thread js function g a 7 js a 3 3 js spawn g thread thread 1 5 main js a 3 public static object spawn context cx scriptabl thi obj object arg function fun obj scriptabl scope fun obj get parent scope runner runner if arg length 0 arg 0 instanceof function object new arg null if arg length 1 arg 1 instanceof scriptabl new arg cx get element scriptabl arg 1 if new arg null new arg script runtim empti arg runner new runner scope function arg 0 new arg els if arg length 0 arg 0 instanceof script runner new runner scope script arg 0 els throw report runtim error msg spawn arg runner factori cx get factori thread thread new thread runner thread start return thread the sync function creat a synchron function in the sens of a java synchron method from an exist function the new function synchron on the code thi code object of it invoc js var o f sync function x print entri packag java lang thread sleep x 1000 print exit js spawn function o f 5 thread thread 0 5 main entri js spawn function o f 5 thread thread 1 5 main js exit entri exit public static object sync context cx scriptabl thi obj object arg function fun obj if arg length 1 arg 0 instanceof function return new synchron function arg 0 els throw report runtim error msg sync arg execut the specifi command with the given argument and option as a separ process and return the exit statu of the process p usag pre run command command run command command arg1 argn run command command arg1 argn option pre all except the last argument to run command ar convert to string and denot command name and it argument if the last argument is a java script object it is an option object otherwis it is convert to string denot the last argument and option object assum to be empti te follow properti of the option object ar process ul li tt arg tt provid an arrai of addit command argument li tt env tt explicit environ object all it enumerat properti defin the correspond environ variabl name li tt input tt the process input if it is not java io input stream it is convert to string and sent to the process as it input if not specifi no input is provid to the process li tt output tt the process output instead of java lang system out if it is not instanc of java io output stream the process output is read convert to a string append to the output properti valu convert to string and put as the new valu of the output properti li tt err tt the process error output instead of java lang system err if it is not instanc of java io output stream the process error output is read convert to a string append to the err properti valu convert to string and put as the new valu of the err properti ul public static object run command context cx scriptabl thi obj object arg function fun obj throw io except int l arg length if l 0 l 1 arg 0 instanceof scriptabl throw report runtim error msg run command bad arg input stream in null output stream out null err null byte arrai output stream out byte null err byte null object out obj null err obj null string environ null scriptabl param null object add arg null if arg l 1 instanceof scriptabl param scriptabl arg l 1 l object env obj scriptabl object get properti param env if env obj scriptabl not found if env obj null environ new string 0 els if env obj instanceof scriptabl throw report runtim error msg run command bad env scriptabl env hash scriptabl env obj object id scriptabl object get properti id env hash environ new string id length for int i 0 i id length i object kei obj id i val string kei if kei obj instanceof string kei string kei obj val scriptabl object get properti env hash kei els int ikei number kei obj int valu kei integ to string ikei val scriptabl object get properti env hash ikei if val scriptabl object not found val undefin instanc environ i kei script runtim to string val object in obj scriptabl object get properti param input if in obj scriptabl not found in to input stream in obj out obj scriptabl object get properti param output if out obj scriptabl not found out to output stream out obj if out null out byte new byte arrai output stream out out byte err obj scriptabl object get properti param err if err obj scriptabl not found err to output stream err obj if err null err byte new byte arrai output stream err err byte object add arg obj scriptabl object get properti param arg if add arg obj scriptabl not found scriptabl s context to object add arg obj get top level scope thi obj add arg cx get element s global global get instanc fun obj if out null out global null global get out system out if err null err global null global get err system err if no explicit input stream do not send ani input to process in particular do not us system in to avoid deadlock when wait for user input to send to process which is alreadi termin as it is not alwai possibl to interrupt read method string cmd new string add arg null l l add arg length for int i 0 i l i cmd i script runtim to string arg i if add arg null for int i 0 i add arg length i cmd l i script runtim to string add arg i int exit code run process cmd environ in out err if out byte null string s script runtim to string out obj out byte to string scriptabl object put properti param output s if err byte null string s script runtim to string err obj err byte to string scriptabl object put properti param err s return new integ exit code the seal function seal all suppli argument public static void seal context cx scriptabl thi obj object arg function fun obj for int i 0 i arg length i object arg arg i if arg instanceof scriptabl object arg undefin instanc if arg instanceof scriptabl arg undefin instanc throw report runtim error msg shell seal not object els throw report runtim error msg shell seal not scriptabl for int i 0 i arg length i object arg arg i scriptabl object arg seal object the read file read the given file context and convert it to a string us the specifi charact code or default charact code if explicit code argument is not given p usag pre read file file path read file file path char code pre the first form convert file s context to string us the default charact code public static object read file context cx scriptabl thi obj object arg function fun obj throw io except if arg length 0 throw report runtim error msg shell read file bad arg string path script runtim to string arg 0 string char code null if arg length 2 char code script runtim to string arg 1 return read url path char code true the read url open connect to the given url read all it data and convert them to a string us the specifi charact code or default charact code if explicit code argument is not given p usag pre read url url read url url char code pre the first form convert file s context to string us the default char code public static object read url context cx scriptabl thi obj object arg function fun obj throw io except if arg length 0 throw report runtim error msg shell read url bad arg string url script runtim to string arg 0 string char code null if arg length 2 char code script runtim to string arg 1 return read url url char code fals convert the argumnet to int32 number public static object toint32 context cx scriptabl thi obj object arg function fun obj object arg arg length 0 arg 0 undefin instanc if arg instanceof integ return arg return script runtim wrap int script runtim to int32 arg public input stream get in return in stream null system in in stream public void set in input stream in in stream in public print stream get out return out stream null system out out stream public void set out print stream out out stream out public print stream get err return err stream null system err err stream public void set err print stream err err stream err public void set seal std lib boolean valu seal std lib valu privat static global get instanc function function scriptabl scope function get parent scope if scope instanceof global throw report runtim error msg bad shell function scope string valu of scope return global scope if ani of in out err is null the correspond process stream will be close immedi otherwis it will be close as soon as all data will be read from written to process privat static int run process string cmd string environ input stream in output stream out output stream err throw io except process p if environ null p runtim get runtim exec cmd els p runtim get runtim exec cmd environ pipe thread in thread null err thread null try input stream err process null try if err null err process p get error stream els p get error stream close input stream out process null try if out null out process p get input stream els p get input stream close output stream in process null try if in null in process p get output stream els p get output stream close if out null read process output on thi thread if err null err thread new pipe thread true err process err err thread start if in null in thread new pipe thread fals in in process in thread start pipe true out process out els if in null no output read process input on thi thread if err null err thread new pipe thread true err process err err thread start pipe fals in in process in close els if err null no output or input read process err on thi thread pipe true err process err err process close err process null wait for process complet for try p wait for break catch interrupt except ex return p exit valu final pipe will close stream as well but for reliabl duplic it in ani case if in process null in process close final if out process null out process close final if err process null err process close final p destroi if in thread null for try in thread join break catch interrupt except ex if err thread null for try err thread join break catch interrupt except ex static void pipe boolean from process input stream from output stream to throw io except try final int size 4096 byte buffer new byte size for int n if from process n from read buffer 0 size els try n from read buffer 0 size catch io except ex ignor except as it can be caus by close pipe break if n 0 break if from process to write buffer 0 n to flush els try to write buffer 0 n to flush catch io except ex ignor except as it can be caus by close pipe break final try if from process from close els to close catch io except ex ignor error on close on window jvm mai throw invalid refrenc except if process termin too fast privat static input stream to input stream object valu throw io except input stream is null string s null if valu instanceof wrapper object unwrap wrapper valu unwrap if unwrap instanceof input stream is input stream unwrap els if unwrap instanceof byte is new byte arrai input stream byte unwrap els if unwrap instanceof reader s read reader reader unwrap els if unwrap instanceof char s new string char unwrap if is null if s null s script runtim to string valu is new byte arrai input stream s get byte return is privat static output stream to output stream object valu output stream os null if valu instanceof wrapper object unwrap wrapper valu unwrap if unwrap instanceof output stream os output stream unwrap return os privat static string read url string file path string char code boolean url is file throw io except int chunk length input stream is null try if url is file url url obj new url file path url connect uc url obj open connect is uc get input stream chunk length uc get content length if chunk length 0 chunk length 1024 if char code null string type uc get content type if type null char code get char code from type type els file f new file file path long length f length chunk length int length if chunk length length throw new io except too big file size length if chunk length 0 return is new file input stream f reader r if char code null r new input stream reader is els r new input stream reader is char code return read reader r chunk length final if is null is close privat static string get char code from type string type int i type index of if i 0 int end type length i while i end type char at i i string charset charset if charset region match true 0 type i charset length i charset length while i end type char at i i if i end type char at i i while i end type char at i i if i end i is at the start of non empti char code spec while type char at end 1 end return type substr i end return null privat static string read reader reader reader throw io except return read reader reader 4096 privat static string read reader reader reader int initi buffer size throw io except char buffer new char initi buffer size int offset 0 for int n reader read buffer offset buffer length offset if n 0 break offset n if offset buffer length char tmp new char buffer length 2 system arraycopi buffer 0 tmp 0 offset buffer tmp return new string buffer 0 offset static runtim except report runtim error string msg id string messag tool error report get messag msg id return context report runtim error messag static runtim except report runtim error string msg id string msg arg string messag tool error report get messag msg id msg arg return context report runtim error messag runner scriptabl scope function func object arg thi scope scope f func thi arg arg runner scriptabl scope script script thi scope scope s script public void run factori call thi public object run context cx if f null return f call cx scope scope arg els return s exec cx scope pipe thread boolean from process input stream from output stream to set daemon true thi from process from process thi from from thi to to public void run try global pipe from process from to catch io except ex throw context throw as script runtim ex ex public class reg exp impl implement reg exp proxi public boolean is reg exp scriptabl obj return obj instanceof nativ reg exp public object compil reg exp context cx string sourc string flag return nativ reg exp compiler sourc flag fals public scriptabl wrap reg exp context cx scriptabl scope object compil return new nativ reg exp scope compil public object action context cx scriptabl scope scriptabl thi obj object arg int action type glob data data new glob data data mode action type switch action type case ra match object rval data optarg 1 rval match or replac cx scope thi obj arg thi data fals return data arrayobj null rval data arrayobj case ra search data optarg 1 return match or replac cx scope thi obj arg thi data fals case ra replac object arg1 arg length 2 undefin instanc arg 1 string repstr null function lambda null if arg1 instanceof function lambda function arg1 els repstr script runtim to string arg1 data optarg 2 data lambda lambda data repstr repstr data dollar repstr null 1 repstr index of data char buf null data left index 0 object val match or replac cx scope thi obj arg thi data true sub string rc thi right context if data char buf null if data global val null val equal boolean true didn t match even onc return data str sub string lc thi left context replac glob data cx scope thi lc index lc length data char buf append rc char arrai rc index rc length return data char buf to string default throw kit code bug analog of c match or replac privat static object match or replac context cx scriptabl scope scriptabl thi obj object arg reg exp impl re impl glob data data boolean forc flat nativ reg exp re string str script runtim to string thi obj data str str scriptabl top scope scriptabl object get top level scope scope if arg length 0 object compil nativ reg exp compiler fals re new nativ reg exp top scope compil els if arg 0 instanceof nativ reg exp re nativ reg exp arg 0 els string src script runtim to string arg 0 string opt if data optarg arg length arg 0 src opt script runtim to string arg data optarg els opt null object compil nativ reg exp compiler src opt forc flat re new nativ reg exp top scope compil data regexp re data global re get flag nativ reg exp jsreg glob 0 int indexp 0 object result null if data mode ra search result re execut reg exp cx scope re impl str indexp nativ reg exp test if result null result equal boolean true result new integ re impl left context length els result new integ 1 els if data global re last index 0 for int count 0 indexp 0 str length count result re execut reg exp cx scope re impl str indexp nativ reg exp test if result null result equal boolean true break if data mode ra match match glob data cx scope count re impl els if data mode ra replac kit code bug sub string last match re impl last match int left index data left index int leftlen last match index left index data left index last match index last match length replac glob data cx scope re impl left index leftlen if re impl last match length 0 if indexp 0 str length break indexp 0 els result re execut reg exp cx scope re impl str indexp data mode ra replac nativ reg exp test nativ reg exp match return result public int find split context cx scriptabl scope string target string separ scriptabl re obj int ip int matchlen boolean match string parensp int i ip 0 int length target length int result int version cx get languag version nativ reg exp re nativ reg exp re obj again while true imit c label js1 2 deviat from perl by never match at end of string int ipsav ip 0 reus ip to save object creation ip 0 i object ret re execut reg exp cx scope thi target ip nativ reg exp test if ret boolean true mismatch ensur our caller advanc i past end of string ip 0 ipsav matchlen 0 1 match 0 fals return length i ip 0 ip 0 ipsav match 0 true sub string sep thi last match matchlen 0 sep length if matchlen 0 0 empti string match never split on an empti match at the start of a find split cycl same rule as for an empti global match in match or replac if i ip 0 bump along to avoid stick at an empti match but don t bump past end of string our caller must do that by ad sep length to our return valu if i length if version context version 1 2 matchlen 0 1 result i els result 1 break i continu again imit c goto pr assert size t i sep length result i matchlen 0 break int size paren null 0 paren length parensp 0 new string size for int num 0 num size num sub string parsub get paren sub string num parensp 0 num parsub to string return result analog of regexp paren substr in c jsregexp h assum zero base i e for 3 i 2 sub string get paren sub string int i if paren null i paren length sub string parsub paren i if parsub null return parsub return sub string empti sub string privat static void match glob glob data mdata context cx scriptabl scope int count reg exp impl re impl if mdata arrayobj null scriptabl s scriptabl object get top level scope scope mdata arrayobj script runtim new object cx s arrai null sub string matchsub re impl last match string matchstr matchsub to string mdata arrayobj put count mdata arrayobj matchstr privat static void replac glob glob data rdata context cx scriptabl scope reg exp impl re impl int left index int leftlen int replen string lambda str if rdata lambda null invok lambda function with arg last match 1 2 n left context length whole string sub string paren re impl paren int paren count paren null 0 paren length object arg new object paren count 3 arg 0 re impl last match to string for int i 0 i paren count i sub string sub paren i if sub null arg i 1 sub to string els arg i 1 undefin instanc arg paren count 1 new integ re impl left context length arg paren count 2 rdata str thi is a hack to prevent expos of re impl data to js function which can run new regexp modif regexp that ar us later by the engin todo redesign is necessari if re impl script runtim get reg exp proxi cx kit code bug reg exp impl re2 new reg exp impl re2 multilin re impl multilin re2 input re impl input script runtim set reg exp proxi cx re2 try scriptabl parent scriptabl object get top level scope scope object result rdata lambda call cx parent parent arg lambda str script runtim to string result final script runtim set reg exp proxi cx re impl replen lambda str length els lambda str null replen rdata repstr length if rdata dollar 0 int skip new int 1 int dp rdata dollar do sub string sub interpret dollar cx re impl rdata repstr dp skip if sub null replen sub length skip 0 dp skip 0 els dp dp rdata repstr index of dp while dp 0 int growth leftlen replen re impl right context length string buffer char buf rdata char buf if char buf null char buf new string buffer growth rdata char buf char buf els char buf ensur capac rdata char buf length growth char buf append re impl left context char arrai left index leftlen if rdata lambda null char buf append lambda str els do replac rdata cx re impl privat static sub string interpret dollar context cx reg exp impl re string da int dp int skip char dc int num tmp if da char at dp kit code bug allow a real backslash liter to escap 1 etc int version cx get languag version if version context version default version context version 1 4 if dp 0 da char at dp 1 return null int dal da length if dp 1 dal return null interpret all perl match induc dollar variabl dc da char at dp 1 if nativ reg exp is digit dc int cp if version context version default version context version 1 4 if dc 0 return null check for overflow to avoid gobbl arbitrari decim digit num 0 cp dp while cp dal nativ reg exp is digit dc da char at cp tmp 10 num dc 0 if tmp num break num tmp els ecma 3 1 9 or 01 99 int paren count re paren null 0 re paren length num dc 0 if num paren count return null cp dp 2 if dp 2 dal dc da char at dp 2 if nativ reg exp is digit dc tmp 10 num dc 0 if tmp paren count cp num tmp if num 0 return null 0 or 00 is not valid adjust num from 1 n origin to 0 arrai index origin num skip 0 cp dp return re get paren sub string num skip 0 2 switch dc case return new sub string case return re last match case return re last paren case if version context version 1 2 js1 2 imit the perl4 bug where left context at each step in an iter us of a global regexp start from last match not from the start of the target string but perl4 doe start at the begin of the target string when it is us in a substitut so we emul that special case here re left context index 0 re left context length re last match index return re left context case return re right context return null analog of do replac in jsstr c privat static void do replac glob data rdata context cx reg exp impl reg exp impl string buffer char buf rdata char buf int cp 0 string da rdata repstr int dp rdata dollar if dp 1 int skip new int 1 do int len dp cp char buf append da substr cp dp cp dp sub string sub interpret dollar cx reg exp impl da dp skip if sub null len sub length if len 0 char buf append sub char arrai sub index len cp skip 0 dp skip 0 els dp dp da index of dp while dp 0 int dal da length if dal cp char buf append da substr cp dal final class ir factori ir factori parser parser thi parser parser script or fn node creat script return new script or fn node token script script for associ file url name with toplevel script void init script script or fn node script node node bodi node children bodi get first child if children null script node add children to back children leaf node creat leaf int node type return new node node type node creat leaf int node type int node op return new node node type node op statement leaf node node creat switch node expr int lineno the switch will be rewritten from switch expr case test1 statement1 default statement default case testn statementsn to switch expr case test1 goto label1 case testn goto labeln goto label default label1 statement1 label default statement default labeln statementsn break label where insid switch each break without label will be replac by goto break label if the origin switch doe not have the default label then the transform code would contain after the switch instead of goto label default the follow goto goto break label node jump switch node new node jump token switch expr lineno node block new node token block switch node return block if case express argument is null it indic default label void add switch case node switch block node case express node statement if switch block get type token block throw kit code bug node jump switch node node jump switch block get first child if switch node get type token switch throw kit code bug node goto target node new target if case express null node jump case node new node jump token case case express case node target goto target switch node add child to back case node els switch node set default goto target switch block add child to back goto target switch block add child to back statement void close switch node switch block if switch block get type token block throw kit code bug node jump switch node node jump switch block get first child if switch node get type token switch throw kit code bug node switch break target node new target switch node target is onli us by node transform to detect switch end switch node target switch break target node default target switch node get default if default target null default target switch break target switch block add child after make jump token goto default target switch node switch block add child to back switch break target node creat variabl int lineno return new node token var lineno node creat expr statement node expr int lineno int type if parser insid function type token expr void els type token expr result return new node type expr lineno node creat expr statement no return node expr int lineno return new node token expr void expr lineno node creat default namespac node expr int lineno default xml namespac requir activ set requir activ node n creat unari token defaultnamespac expr node result creat expr statement n lineno return result name node creat name string name check activ name name token name return node new string token name name string for liter node creat string string string return node new string string number for liter node creat number doubl number return node new number number catch claus of try catch final param var name the name of the variabl to bind to the except param catch cond the condit under which to catch the except mai be null if no condit is given param stmt the statement in the catch claus param lineno the start line number of the catch claus node creat catch string var name node catch cond node stmt int lineno if catch cond null catch cond new node token empti return new node token catch creat name var name catch cond stmt lineno throw node creat throw node expr int lineno return new node token throw expr lineno return node creat return node expr int lineno return expr null new node token return lineno new node token return expr lineno label node creat label int lineno return new node jump token label lineno node get label loop node label return node jump label get loop label node creat label statement node label arg node statement node jump label node jump label arg make a target and put it after the statement node and in the label node so break get the right target node break target node new target node block new node token block label statement break target label target break target return block break possibl label node creat break node break statement int lineno node jump n new node jump token break lineno node jump jump statement int t break statement get type if t token loop t token label jump statement node jump break statement els if t token block break statement get first child get type token switch jump statement node jump break statement get first child els throw kit code bug n set jump statement jump statement return n continu possibl label node creat continu node loop int lineno if loop get type token loop kit code bug node jump n new node jump token continu lineno n set jump statement node jump loop return n statement block creat the empti statement block must make subsequ call to add statement to the node node creat block int lineno return new node token block lineno function node creat function string name return new function node name node init function function node fn node int function index node statement int function type fn node it function type function type fn node add child to back statement int function count fn node get function count if function count 0 function contain other function requir activ object fn node it need activ true for int i 0 i function count i function node fn fn node get function node i nest function express statement overrid var if fn get function type function node function express statement string name fn get function name if name null name length 0 fn node remov param or var name if function type function node function express string name fn node get function name if name null name length 0 fn node ha param or var name a function express need to have it name as a variabl if it isn t alreadi alloc as a variabl see ecma ch 13 we add code to the begin of the function to initi a local variabl of the function s name to the function valu fn node add var name node set fn new node token expr void new node token setnam node new string token bindnam name new node token thisfn statement add children to front set fn add return to end if need node last stmt statement get last child if last stmt null last stmt get type token return statement add child to back new node token return node result node new string token function fn node get function name result put int prop node function prop function index return result add a child to the back of the given node thi function break the factori abstract but it remov a requir from implementor of node void add child to back node parent node child parent add child to back child creat loop node the parser will later call creat while creat do while creat for creat for in to finish loop gener node creat loop node node loop label int lineno node jump result new node jump token loop lineno if loop label null node jump loop label set loop result return result while node creat while node loop node cond node bodi return creat loop node jump loop loop while bodi cond null null do while node creat do while node loop node bodi node cond return creat loop node jump loop loop do while bodi cond null null for node creat for node loop node init node test node incr node bodi return creat loop node jump loop loop for bodi test init incr privat node creat loop node jump loop int loop type node bodi node cond node init node incr node bodi target node new target node cond target node new target if loop type loop for cond get type token empti cond new node token true node jump ifeq new node jump token ifeq cond ifeq target bodi target node break target node new target loop add child to back bodi target loop add children to back bodi if loop type loop while loop type loop for propag lineno to condit loop add children to back new node token empti loop get lineno loop add child to back cond target loop add child to back ifeq loop add child to back break target loop target break target node continu target cond target if loop type loop while loop type loop for just add a goto to the condit in the do while loop add child to front make jump token goto cond target if loop type loop for if init get type token empti if init get type token var init new node token expr void init loop add child to front init node incr target node new target loop add child after incr target bodi if incr get type token empti incr new node token expr void incr loop add child after incr incr target continu target incr target loop set continu continu target return loop for in node creat for in node loop node lh node obj node bodi boolean is for each string name int type lh get type node lvalu if type token var check that there wa onli on variabl given we can t do thi in the parser becaus then the parser would have to know someth about the init node of the for in loop node last child lh get last child if lh get first child last child parser report error msg mult index lvalu node new string token name last child get string els lvalu make refer lh if lvalu null parser report error msg bad for in lh return obj node local block new node token local block int init type is for each token enum init valu token enum init kei node init new node init type obj init put prop node local block prop local block node cond new node token enum next cond put prop node local block prop local block node id new node token enum id id put prop node local block prop local block node new bodi new node token block node assign simpl assign lvalu id new bodi add child to back new node token expr void assign new bodi add child to back bodi loop creat while loop cond new bodi loop add child to front init if type token var loop add child to front lh local block add child to back loop return local block try catch final the ir factori tri to express as much as possibl in the tree the respons remain for codegen ar to add the java handler either but not both of target and final might not be defin a catch handler for javascript except that unwrap the except onto the stack and got oe to the catch target a final handler and a goto to goto around these handler node creat try catch final node try block node catch block node final block int lineno boolean ha final final block null final block get type token block final block ha children short circuit if try block get type token block try block ha children ha final return try block boolean ha catch catch block ha children short circuit if ha final ha catch bc final might be an empti block return try block node handler block new node token local block node jump pn new node jump token try try block lineno pn put prop node local block prop handler block if ha catch jump around catch code node end catch node new target pn add child to back make jump token goto end catch make a target for the catch that the tcf node know about node catch target node new target pn target catch target mark it pn add child to back catch target given try try block catch e if condit1 someth1 catch e if conditionn somethingn catch e someth default rewrit as try try block goto after catch catch x with new catch scope e x if condit1 someth1 goto after catch with new catch scope e x if conditionn somethingn goto after catch with new catch scope e x someth default goto after catch after catch if there is no default catch then the last with block arround someth default is replac by rethrow it is assum that catch handler gener will store execept object in handler block regist block with local for except scope object node catch scope block new node token local block expect catchblock children to be cond block pair node cb catch block get first child boolean ha default fals int scope index 0 while cb null int catch line no cb get lineno node name cb get first child node cond name get next node catch statement cond get next cb remov child name cb remov child cond cb remov child catch statement add goto to the catch statement to jump out of catch but prefix it with leavewith sinc try catch produc with code in order to limit the scope of the except object catch statement add child to back new node token leavewith catch statement add child to back make jump token goto end catch creat condit if when present node cond stmt if cond get type token empti cond stmt catch statement ha default true els cond stmt creat if cond catch statement null catch line no gener code to creat the scope object and store it in catch scope block regist node catch scope new node token catch scope name creat us local handler block catch scope put prop node local block prop catch scope block catch scope put int prop node catch scope prop scope index catch scope block add child to back catch scope add with statement base on catch scope object catch scope block add child to back creat with creat us local catch scope block cond stmt catch line no move to next cb cb cb get next scope index pn add child to back catch scope block if ha default gener code to rethrow if no catch claus wa execut node rethrow new node token rethrow rethrow put prop node local block prop handler block pn add child to back rethrow pn add child to back end catch if ha final node final target node new target pn set final final target add jsr final to the try block pn add child to back make jump token jsr final target jump around final code node final end node new target pn add child to back make jump token goto final end pn add child to back final target node f block new node token final final block f block put prop node local block prop handler block pn add child to back f block pn add child to back final end handler block add child to back pn return handler block with node creat with node obj node bodi int lineno set requir activ node result new node token block lineno result add child to back new node token enterwith obj node bodi node new node token with bodi lineno result add children to back bodi node result add child to back new node token leavewith return result dotqueri public node creat dot queri node obj node bodi int lineno set requir activ node result new node token dotqueri obj bodi lineno return result node creat arrai liter obj arrai elem int skip count int length elem size int skip index null if skip count 0 skip index new int skip count node arrai new node token arraylit for int i 0 j 0 i length i node elem node elem get i if elem null arrai add child to back elem els skip index j i j if skip count 0 arrai put prop node skip index prop skip index return arrai object liter br creat object liter rewrit it argument as object creation plu object properti entri so later compil stage don t need to know about object liter node creat object liter obj arrai elem int size elem size 2 node object new node token objectlit object properti if size 0 properti script runtim empti arg els properti new object size for int i 0 i size i properti i elem get 2 i node valu node elem get 2 i 1 object add child to back valu object put prop node object id prop properti return object regular express node creat reg exp int regexp index node n new node token regexp n put int prop node regexp prop regexp index return n if statement node creat if node cond node if true node if fals int lineno int cond statu is alwai defin boolean cond if cond statu alwai true boolean return if true els if cond statu alwai fals boolean if if fals null return if fals replac if fals xxx by empti block return new node token block lineno node result new node token block lineno node if not target node new target node jump ifn new node jump token ifn cond ifn target if not target result add child to back ifn result add children to back if true if if fals null node end target node new target result add child to back make jump token goto end target result add child to back if not target result add children to back if fals result add child to back end target els result add child to back if not target return result node creat cond expr node cond node if true node if fals int cond statu is alwai defin boolean cond if cond statu alwai true boolean return if true els if cond statu alwai fals boolean return if fals return new node token hook cond if true if fals unari node creat unari int node type node child int child type child get type switch node type case token delprop node n if child type token name transform delet name a to delet bind a string a child set type token bindnam node left child node right node new string child get string n new node node type left right els if child type token getprop child type token getelem node left child get first child node right child get last child child remov child left child remov child right n new node node type left right els if child type token get ref node ref child get first child child remov child ref n new node token del ref ref els n new node token true return n case token typeof if child type token name child set type token typeofnam return child break case token bitnot if child type token number int valu script runtim to int32 child get doubl child set doubl valu return child break case token neg if child type token number child set doubl child get doubl return child break case token not int statu is alwai defin boolean child if statu 0 int type if statu alwai true boolean type token fals els type token true if child type token true child type token fals child set type type return child return new node type break return new node node type child node creat call or new int node type node child int type node non specialcal if child get type token name string name child get string if name equal eval type node specialcal eval els if name equal with type node specialcal with els if child get type token getprop string name child get last child get string if name equal eval type node specialcal eval node node new node node type child if type node non specialcal call to these function requir activ object set requir activ node put int prop node specialcal prop type return node node creat inc dec int node type boolean post node child child make refer child if child null string msg if node type token dec msg msg bad decr els msg msg bad incr parser report error msg return null int child type child get type switch child type case token name case token getprop case token getelem case token get ref node n new node node type child int incr decr mask 0 if node type token dec incr decr mask node decr flag if post incr decr mask node post flag n put int prop node incrdecr prop incr decr mask return n throw kit code bug node creat properti get node target string namespac string name int member type flag if namespac null member type flag 0 if target null return creat name name check activ name name token getprop if script runtim is special properti name node ref new node token ref special target ref put prop node name prop name return new node token get ref ref return new node token getprop target creat string name node elem creat string name member type flag node properti flag return creat member ref get target namespac elem member type flag node creat element get node target string namespac node elem int member type flag opt could optim to creat properti get iff elem is string that can not be number if namespac null member type flag 0 stand alon aaa as primari express is arrai liter declar and should not come here if target null throw kit code bug return new node token getelem target elem return creat member ref get target namespac elem member type flag privat node creat member ref get node target string namespac node elem int member type flag node ns node null if namespac null see 11 1 2 in ecma 357 if namespac equal ns node new node token null els ns node creat name namespac node ref if target null if namespac null ref new node token ref name elem els ref new node token ref ns name ns node elem els if namespac null ref new node token ref member target elem els ref new node token ref ns member target ns node elem if member type flag 0 ref put int prop node member type prop member type flag return new node token get ref ref binari node creat binari int node type node left node right switch node type case token add numer addit and string concaten if left type token string string s2 if right type token string s2 right get string els if right type token number s2 script runtim number to string right get doubl 10 els break string s1 left get string left set string s1 concat s2 return left els if left type token number if right type token number left set doubl left get doubl right get doubl return left els if right type token string string s1 s2 s1 script runtim number to string left get doubl 10 s2 right get string right set string s1 concat s2 return right can t do anyth if we don t know both type sinc 0 object is suppos to call to string on the object and do string concanten rather than addit break case token sub numer subtract if left type token number doubl ld left get doubl if right type token number both number left set doubl ld right get doubl return left els if ld 0 0 first 0 0 x x return new node token neg right els if right type token number if right get doubl 0 0 second 0 x 0 x can not make simpli x becaus x 0 must be number return new node token po left break case token mul numer multipl if left type token number doubl ld left get doubl if right type token number both number left set doubl ld right get doubl return left els if ld 1 0 first 1 1 x x return new node token po right els if right type token number if right get doubl 1 0 second 1 x 1 x can not make simpli x becaus x 0 must be number return new node token po left can t do x 0 infin 0 give nan not 0 break case token div number divis if right type token number doubl rd right get doubl if left type token number both constant just divid trust java to handl x 0 left set doubl left get doubl rd return left els if rd 1 0 second 1 x 1 x not simpli x to forc number convert return new node token po left break case token and sinc x y give x not fals when boolean x is fals and y not boolean y when boolean x is true x y can onli be simplifi if x is defin see bug 309957 int left statu is alwai defin boolean left if left statu alwai fals boolean if the first on is fals just return it return left els if left statu alwai true boolean if first is true set to second return right break case token or sinc x y give x not true when boolean x is true and y not boolean y when boolean x is fals x y can onli be simplifi if x is defin see bug 309957 int left statu is alwai defin boolean left if left statu alwai true boolean if the first on is true just return it return left els if left statu alwai fals boolean if first is fals set to second return right break return new node node type left right privat node simpl assign node left node right int node type left get type switch node type case token name left set type token bindnam return new node token setnam left right case token getprop case token getelem node obj left get first child node id left get last child int type if node type token getprop type token setprop els type token setelem return new node type obj id right case token get ref node ref left get first child check mutabl refer ref return new node token set ref ref right throw kit code bug privat void check mutabl refer node n int member type flag n get int prop node member type prop 0 if member type flag node descend flag 0 parser report error msg bad assign left node creat assign int assign type node left node right left make refer left if left null parser report error msg bad assign left return right int assign op switch assign type case token assign return simpl assign left right case token assign bitor assign op token bitor break case token assign bitxor assign op token bitxor break case token assign bitand assign op token bitand break case token assign lsh assign op token lsh break case token assign rsh assign op token rsh break case token assign ursh assign op token ursh break case token assign add assign op token add break case token assign sub assign op token sub break case token assign mul assign op token mul break case token assign div assign op token div break case token assign mod assign op token mod break default throw kit code bug int node type left get type switch node type case token name string s left get string node op left node new string token name s node op new node assign op op left right node lvalu left node new string token bindnam s return new node token setnam lvalu left op case token getprop case token getelem node obj left get first child node id left get last child int type node type token getprop token setprop op token setelem op node op left new node token us stack node op new node assign op op left right return new node type obj id op case token get ref node ref left get first child check mutabl refer ref node op left new node token us stack node op new node assign op op left right return new node token set ref op ref op throw kit code bug node creat us local node local block if token local block local block get type throw kit code bug node result new node token local load result put prop node local block prop local block return result privat node jump make jump int type node target node jump n new node jump type n target target return n privat node make refer node node int type node get type switch type case token name case token getprop case token getelem case token get ref return node case token call node set type token ref call return new node token get ref node signal caller to report error return null check if node alwai mean true or fals in boolean context privat static int is alwai defin boolean node node switch node get type case token fals case token null return alwai fals boolean case token true return alwai true boolean case token number doubl num node get doubl if num num num 0 0 return alwai true boolean els return alwai fals boolean return 0 privat void check activ name string name int token if parser insid function boolean activ fals if argument equal name parser compil env activ name null parser compil env activ name contain kei name activ true els if length equal name if token token getprop parser compil env get languag version context version 1 2 us of length in 1 2 requir an activ object activ true if activ set requir activ privat void set requir activ if parser insid function function node parser current script or fn it need activ true public static void init context cx scriptabl scope boolean seal nativ reg exp proto new nativ reg exp proto re re compil compiler null fals proto activ prototyp map max prototyp id proto set parent scope scope proto set prototyp get object prototyp scope nativ reg exp ctor ctor new nativ reg exp ctor bug 324006 ecma 262 15 10 6 1 sai the initi valu of reg exp prototyp constructor is the builtin reg exp constructor proto put constructor proto ctor script runtim set function proto and parent ctor scope ctor set immun prototyp properti proto if seal proto seal object ctor seal object defin properti scope reg exp ctor scriptabl object dontenum nativ reg exp scriptabl scope object regexp compil thi re re compil regexp compil thi last index 0 script runtim set object proto and parent thi scope public string get class name return reg exp public object call context cx scriptabl scope scriptabl thi obj object arg return exec sub cx scope arg match public scriptabl construct context cx scriptabl scope object arg return scriptabl exec sub cx scope arg match scriptabl compil context cx scriptabl scope object arg if arg length 0 arg 0 instanceof nativ reg exp if arg length 1 arg 1 undefin instanc report error throw script runtim type error0 msg bad regexp compil nativ reg exp that obj nativ reg exp arg 0 thi re that obj re thi last index that obj last index return thi string s arg length 0 script runtim to string arg 0 string global arg length 1 arg 1 undefin instanc script runtim to string arg 1 null thi re re compil compiler s global fals thi last index 0 return thi public string to string string buffer buf new string buffer buf append if re sourc length 0 buf append re sourc els see bugzilla 226045 buf append buf append if re flag jsreg glob 0 buf append g if re flag jsreg fold 0 buf append i if re flag jsreg multilin 0 buf append m return buf to string nativ reg exp nativ reg exp privat static reg exp impl get impl context cx return reg exp impl script runtim get reg exp proxi cx privat object exec sub context cx scriptabl scope obj object arg int match type reg exp impl re impl get impl cx string str if arg length 0 str re impl input if str null report error msg no re input for to string els str script runtim to string arg 0 doubl d re flag jsreg glob 0 last index 0 object rval if d 0 str length d last index 0 rval null els int indexp int d rval execut reg exp cx scope obj re impl str indexp match type if re flag jsreg glob 0 last index rval null rval undefin instanc 0 indexp 0 return rval static object compiler string str string global boolean flat re compil regexp new re compil regexp sourc str to char arrai int length str length int flag 0 if global null for int i 0 i global length i char c global char at i if c g flag jsreg glob els if c i flag jsreg fold els if c m flag jsreg multilin els report error msg invalid re flag string valu of c regexp flag flag compil state state new compil state regexp sourc length flag if flat length 0 if debug system out println flat str state result new re node reop flat state result chr state cpbegin 0 state result length length state result flat index 0 state prog length 5 els if pars disjunct state return null regexp program new byte state prog length 1 if state class count 0 regexp class list new re char set state class count regexp class count state class count int endpc emitr bytecod state regexp 0 state result regexp program endpc reop end if debug system out println prog length endpc for int i 0 i endpc i system out print regexp program i if i endpc 1 system out print system out println regexp paren count state paren count if re start with liter init anchor ch accordingli switch regexp program 0 case reop ucflat1 case reop ucflat1i regexp anchor ch char get index regexp program 1 break case reop flat1 case reop flat1i regexp anchor ch char regexp program 1 0xff break case reop flat case reop fla ti int k get index regexp program 1 regexp anchor ch regexp sourc k break if debug if regexp anchor ch 0 system out println anchor ch char regexp anchor ch return regexp static boolean is digit char c return 0 c c 9 privat static boolean is word char c return charact is letter c is digit c c privat static boolean is line term char c return script runtim isj line termin c privat static boolean isr white space int c return c u0020 c u0009 c n c r c 0x2028 c 0x2029 c u000c c u000b c u00a0 charact get type char c charact space separ privat static char upcas char ch if ch 128 if a ch ch z return char ch a a return ch char cu charact to upper case ch if ch 128 cu 128 return ch return cu privat static char downcas char ch if ch 128 if a ch ch z return char ch a a return ch char cl charact to lower case ch if ch 128 cl 128 return ch return cl privat static int toascii hex digit int c if c 0 return 1 if c 9 return c 0 c 0x20 if a c c f return c a 10 return 1 privat static boolean pars disjunct compil state state if pars altern state return fals char sourc state cpbegin int index state cp if index sourc length sourc index re node alt result state cp alt result new re node reop alt alt result kid state result if pars disjunct state return fals alt result kid2 state result state result alt result alt next jump end jump end state prog length 9 return true privat static boolean pars altern compil state state re node head term null re node tail term null char sourc state cpbegin while true if state cp state cpend sourc state cp state paren nest 0 sourc state cp if head term null state result new re node reop empti els state result head term return true if pars term state return fals if head term null head term state result els if tail term null head term next state result tail term state result while tail term next null tail term tail term next els tail term next state result tail term tail term next while tail term next null tail term tail term next calcul the total size of the bitmap requir for a class express privat static boolean calcul bitmap size compil state state re node target char src int index int end char rang start 0 char c int n int digit int n digit int i int max 0 boolean in rang fals target bmsize 0 if index end return true if src index index while index end int local max 0 n digit 2 switch src index case index c src index switch c case b local max 0x8 break case f local max 0xc break case n local max 0xa break case r local max 0xd break case t local max 0x9 break case v local max 0xb break case c if index 1 end charact is letter src index 1 local max char src index 0x1f els local max break case u n digit 2 fall thru case x n 0 for i 0 i n digit index end i c src index n kit x digit to int c n if n 0 back off to accept the origin as a liter index i 1 n break local max n break case d if in rang report error msg bad rang return fals local max 9 break case d case s case s case w case w if in rang report error msg bad rang return fals target bmsize 65535 return true case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 thi is a non ecma extens decim escap in thi case octal ar suppos to be an error insid class rang but support here for backward compat n c 0 c src index if 0 c c 7 index n 8 n c 0 c src index if 0 c c 7 index i 8 n c 0 if i 0377 n i els index local max n break default local max c break break default local max src index break if in rang if rang start local max report error msg bad rang return fals in rang fals els if index end 1 if src index index in rang true rang start char local max continu if state flag jsreg fold 0 char cu upcas char local max char cd downcas char local max local max cu cd cu cd if local max max max local max target bmsize max return true privat static void do flat compil state state char c state result new re node reop flat state result chr c state result length 1 state result flat index 1 state prog length 3 privat static int get decim valu char c compil state state int max valu string overflow messag id boolean overflow fals int start state cp char src state cpbegin int valu c 0 for state cp state cpend state cp c src state cp if is digit c break if overflow int digit c 0 if valu max valu digit 10 valu valu 10 digit els overflow true valu max valu if overflow report error overflow messag id string valu of src start state cp start return valu privat static boolean pars term compil state state char src state cpbegin char c src state cp int n digit 2 int paren base count state paren count int num tmp re node term int term start int ocp state cp switch c assert and atom case state result new re node reop bol state prog length return true case state result new re node reop eol state prog length return true case if state cp state cpend c src state cp switch c assert escap case b state result new re node reop wbdry state prog length return true case b state result new re node reop wnonbdri state prog length return true decim escap case 0 under strict ecma 3 we interpret 0 as nul and don t accept octal howev xxx and sinc rhino doesn t have a strict mode we ll just behav the old wai for compat reason see http bugzilla mozilla org show bug cgi id 141078 octal escap num 0 while state cp state cpend c src state cp if c 0 c 7 state cp tmp 8 num c 0 if tmp 0377 break num tmp els break c char num do flat state c break case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 term start state cp 1 num get decim valu c state 0xffff msg overlarg backref n 9 and count of parenthes then treat as octal instead if num 9 num state paren count state cp term start num 0 while state cp state cpend c src state cp if c 0 c 7 state cp tmp 8 num c 0 if tmp 0377 break num tmp els break c char num do flat state c break otherwis it s a back refer state result new re node reop backref state result paren index num 1 state prog length 3 break control escap case f c 0xc do flat state c break case n c 0xa do flat state c break case r c 0xd do flat state c break case t c 0x9 do flat state c break case v c 0xb do flat state c break control letter case c if state cp 1 state cpend charact is letter src state cp 1 c char src state cp 0x1f els back off to accept the origin as a liter state cp c do flat state c break unicod escap sequenc case u n digit 2 fall thru hex escap sequenc case x int n 0 int i for i 0 i n digit state cp state cpend i int digit c src state cp n kit x digit to int c n if n 0 back off to accept the origin u or x as a liter state cp i 2 n src state cp break c char n do flat state c break charact class escap case d state result new re node reop digit state prog length break case d state result new re node reop nondigit state prog length break case s state result new re node reop space state prog length break case s state result new re node reop nonspac state prog length break case w state result new re node reop alnum state prog length break case w state result new re node reop nonalnum state prog length break ident escap default state result new re node reop flat state result chr c state result length 1 state result flat index state cp 1 state prog length 3 break break els a trail is an error report error msg trail backslash return fals case re node result null term start state cp if state cp 1 state cpend src state cp c src state cp 1 c c state cp 2 if c result new re node reop assert assert next asserttest state prog length 4 els if c result new re node reop assert not assertnot next assertnottest state prog length 4 els result new re node reop lparen lparen index rparen index state prog length 6 result paren index state paren count state paren nest if pars disjunct state return fals if state cp state cpend src state cp report error msg unterm paren return fals state cp state paren nest if result null result kid state result state result result break case report error msg re unmatch right paren return fals case state result new re node reop class term start state cp state result start index term start while true if state cp state cpend report error msg unterm class return fals if src state cp state cp els if src state cp state result kidlen state cp term start break state cp state result index state class count call calcul bitmap size now as we want ani error it find to be report dure the pars phase not at execut if calcul bitmap size state state result src term start state cp return fals state prog length 3 claprivat static void resolv forward jump byte arrai int from int pc if from pc throw kit code bug add index arrai from pc from privat static int get offset byte arrai int pc return get index arrai pc privat static int add index byte arrai int pc int index if index 0 throw kit code bug if index 0xffff throw context report runtim error too complex regexp arrai pc byte index 8 arrai pc 1 byte index return pc 2 privat static int get index byte arrai int pc return arrai pc 0xff 8 arrai pc 1 0xff privat static int emitr bytecod compil state state re compil re int pc re node t re node next alt int next alt fixup next term fixup byte program re program while t null program pc t op switch t op case reop empti pc break case reop alt next alt t kid2 next alt fixup pc address of next altern pc offset len pc emitr bytecod state re pc t kid program pc reop jump next term fixup pc address of follow term pc offset len resolv forward jump program next alt fixup pc pc emitr bytecod state re pc next alt program pc reop jump next alt fixup pc pc offset len resolv forward jump program next term fixup pc resolv forward jump program next alt fixup pc break case reop flat consecut flat s if possibl if t flat index 1 while t next null t next op reop flat t flat index t length t next flat index t length t next length t next t next next if t flat index 1 t length 1 if state flag jsreg fold 0 program pc 1 reop fla ti els program pc 1 reop flat pc add index program pc t flat index pc add index program pc t length els if t chr 256 if state flag jsreg fold 0 program pc 1 reop flat1i els program pc 1 reop flat1 program pc byte t chr els if state flag jsreg fold 0 program pc 1 reop ucflat1i els program pc 1 reop ucflat1 pc add index program pc t chr break case reop lparen pc add index program pc t paren index pc emitr bytecod state re pc t kid program pc reop rparen pc add index program pc t paren index break case reop backref pc add index program pc t paren index break case reop assert next term fixup pc pc offset len pc emitr bytecod state re pc t kid program pc reop asserttest resolv forward jump program next term fixup pc break case reop assert not next term fixup pc pc offset len pc emitr bytecod state re pc t kid program pc reop assertnottest resolv forward jump program next term fixup pc break case reop quant if t min 0 t max 1 program pc 1 t greedi reop star reop minimalstar els if t min 0 t max 1 program pc 1 t greedi reop opt reop minimalopt els if t min 1 t max 1 program pc 1 t greedi reop plu reop minimalplu els if t greedi program pc 1 reop minimalqu pc add index program pc t min max can be 1 which add index doe not accept pc add index program pc t max 1 pc add index program pc t paren count pc add index program pc t paren index next term fixup pc pc offset len pc emitr bytecod state re pc t kid program pc reop endchild resolv forward jump program next term fixup pc break case reop class pc add index program pc t index re class list t index new re char set t bmsize t start index t kidlen break default break t t next return pc privat static void push prog state re global data g data int min int max re back track data back track last to save int continu pc int continu op g data state stack top new re prog state g data state stack top min max g data cp back track last to save continu pc continu op privat static re prog state pop prog state re global data g data re prog state state g data state stack top g data state stack top state previou return state privat static void push back track state re global data g data byte op int target g data back track stack top new re back track data g data op target privat static boolean flatn matcher re global data g data int match char int length char char int end if g data cp length end return fals for int i 0 i length i if g data regexp sourc match char i char g data cp i return fals g data cp length return true privat static boolean flatni matcher re global data g data int match char int length char char int end if g data cp length end return fals for int i 0 i length i if upcas g data regexp sourc match char i upcas char g data cp i return fals g data cp length return true privat static boolean backref matcher re global data g data int paren index char char int end int len int i int paren content g data paren index paren index if paren content 1 return true len g data paren length paren index if g data cp len end return fals if g data regexp flag jsreg fold 0 for i 0 i len i if upcas char paren content i upcas char g data cp i return fals els for i 0 i len i if char paren content i char g data cp i return fals g data cp len return true add a singl charact to the re char set privat static void add charact to char set re char set cs char c int byte index int c 8 if c cs length throw new runtim except cs bit byte index 1 c 0x7 add a charact rang c1 to c2 inclus to the re char set privat static void add charact rang to char set re char set cs char c1 char c2 int i int byte index1 int c1 8 int byte index2 int c2 8 if c2 cs length c1 c2 throw new runtim except c1 0x7 c2 0x7 if byte index1 byte index2 cs bit byte index1 int 0xff 7 c2 c1 c1 els cs bit byte index1 0xff c1 for i byte index1 1 i byte index2 i cs bit i byte 0xff cs bit byte index2 int 0xff 7 c2 compil the sourc of the class into a re char set privat static void process char set re global data g data re char set char set synchron char set if char set convert process char set impl g data char set char set convert true privat static void process char set impl re global data g data re char set char set int src char set start index int end src char set strlength char rang start 0 thi ch int byte length char c int n int n digit int i boolean in rang fals char set sens true byte length char set length 8 1 char set bit new byte byte length if src end return if g data regexp sourc src char set sens fals src while src end n digit 2 switch g data regexp sourc src case src c g data regexp sourc src switch c case b thi ch 0x8 break case f thi ch 0xc break case n thi ch 0xa break case r thi ch 0xd break case t thi ch 0x9 break case v thi ch 0xb break case c if src 1 end is word g data regexp sourc src 1 thi ch char g data regexp sourc src 0x1f els src thi ch break case u n digit 2 fall thru case x n 0 for i 0 i n digit src end i c g data regexp sourc src int digit toascii hex digit c if digit 0 back off to accept the origin as a liter src i 1 n break n n 4 digit thi ch char n break case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 thi is a non ecma extens decim escap in thi case octal ar suppos to be an error insid class rang but support here for backward compat n c 0 c g data regexp sourc src if 0 c c 7 src n 8 n c 0 c g data regexp sourc src if 0 c c 7 src i 8 n c 0 if i 0377 n i els src thi ch char n break case d add charact rang to char set char set 0 9 continu don t need rang process case d add charact rang to char set char set char 0 char 0 1 add charact rang to char set char set char 9 1 char char set length continu case s for i int char set length i 0 i if isr white space i add charact to char set char set char i continu case s for i int char set length i 0 i if isr white space i add charact to char set char set char i continu case w for i int char set length i 0 i if is word char i add charact to char set char set char i continu case w for i int char set length i 0 i if is word char i add charact to char set char set char i continu default thi ch c break break default thi ch g data regexp sourc src break if in rang if g data regexp flag jsreg fold 0 add charact rang to char set char set upcas rang start upcas thi ch add charact rang to char set char set downcas rang start downcas thi ch els add charact rang to char set char set rang start thi ch in rang fals els if g data regexp flag jsreg fold 0 add charact to char set char set upcas thi ch add charact to char set char set downcas thi ch els add charact to char set char set thi ch if src end 1 if g data regexp sourc src src in rang true rang start thi ch privat static boolean class matcher re global data g data re char set char set char ch if char set convert process char set g data char set int byte index ch 8 if char set sens if char set length 0 ch char set length char set bit byte index 1 ch 0x7 0 return fals els if char set length 0 ch char set length char set bit byte index 1 ch 0x7 0 return fals return true privat static boolean executer bytecod re global data g data char char int end int pc 0 byte program g data regexp program int current continu op int current continu pc boolean result fals current continu pc 0 current continu op reop end if debug system out println input new string char start at g data cp int op program pc for if debug system out println test at g data cp op op switch op case reop empti result true break case reop bol if g data cp 0 if g data multilin g data regexp flag jsreg multilin 0 if is line term char g data cp 1 result fals break els result fals break result true break case reop eol if g data cp end if g data multilin g data regexp flag jsreg multilin 0 if is line term char g data cp result fals break els result fals break result true break case reop wbdry result g data cp 0 is word char g data cp 1 g data cp end is word char g data cp break case reop wnonbdri result g data cp 0 is word char g data cp 1 g data cp end is word char g data cp break case reop dot result g data cp end is line term char g data cp if result g data cp break case reop digit result g data cp end is digit char g data cp if result g data cp break case reop nondigit result g data cp end is digit char g data cp if result g data cp break case reop space result g data cp end isr white space char g data cp if result g data cp break case reop nonspac result g data cp end isr white space char g data cp if result g data cp break case reop alnum result g data cp end is word char g data cp if result g data cp break case reop nonalnum result g data cp end is word char g data cp if result g data cp break case reop flat int offset get index program pc pc index len int length get index program pc pc index len result flatn matcher g data offset length char end break case reop fla ti int offset get index program pc pc index len int length get index program pc pc index len result flatni matcher g data offset length char end break case reop flat1 char match ch char program pc 0xff result g data cp end char g data cp match ch if result g data cp break case reop flat1i char match ch char program pc 0xff result g data cp end upcas char g data cp upcas match ch if result g data cp break case reop ucflat1 char match ch char get index program pc pc index len result g data cp end char g data cp match ch if result g data cp break case reop ucflat1i char match ch char get index program pc pc index len result g data cp end upcas char g data cp upcas match ch if result g data cp break case reop alt int nextpc byte nextop push prog state g data 0 0 null current continu pc current continu op nextpc pc get offset program pc nextop program nextpc push back track state g data nextop nextpc pc index len op program pc continu case reop jump int offset re prog state state pop prog state g data current continu pc state continu pc current continu op state continu op offset get offset program pc pc offset op program pc continu case reop lparen int paren index get index program pc pc index len g data set paren paren index g data cp 0 op program pc continu case reop rparen int cap index int paren index get index program pc pc index len cap index g data paren index paren index g data set paren paren index cap index g data cp cap index if paren index g data last paren g data last paren paren index op program pc continu case reop backref int paren index get index program pc pc index len result backref matcher g data paren index char end break case reop class int index get index program pc pc index len if g data cp end if class matcher g data g data regexp class list index char g data cp g data cp result true break result fals break case reop assert case reop assert not byte test op push prog state g data 0 0 g data back track stack top current continu pc current continu op if op reop assert test op reop asserttest els test op reop assertnottest push back track state g data test op pc get offset program pc pc index len op program pc continu case reop asserttest case reop assertnottest re prog state state pop prog state g data g data cp state index g data back track stack top state back track current continu pc state continu pc current continu op state continu op if result if op reop asserttest result true els result fals els if oprivat static boolean match reg exp re global data g data re compil re char char int start int end boolean multilin if re paren count 0 g data paren new long re paren count els g data paren null g data back track stack top null g data state stack top null g data multilin multilin g data regexp re g data last paren 0 int anchor ch g data regexp anchor ch have to includ the posit beyond the last charact in order to detect end of input line condit for int i start i end i if the first node is a liter match step the index into the string until that match is made or fail if it can t be found at all if anchor ch 0 for if i end return fals char match ch char i if match ch anchor ch g data regexp flag jsreg fold 0 upcas match ch upcas char anchor ch break i g data cp i for int j 0 j re paren count j g data set paren j 1 0 boolean result executer bytecod g data char end g data back track stack top null g data state stack top null if result g data skip i start return true return fals object execut reg exp context cx scriptabl scope obj reg exp impl re string str int indexp int match type re global data g data new re global data int start indexp 0 char char arrai str to char arrai int end char arrai length if start end start end call the recurs matcher to do the real work boolean match match reg exp g data re char arrai start end re multilin if match if match type prefix return null return undefin instanc int index g data cp int i index indexp 0 i int matchlen i start g data skip int ep index index matchlen object result scriptabl obj if match type test test for a match and updat cx reg exp impl don t alloc an arrai object do return true result boolean true obj null els the arrai return on match ha element 0 bound to the match string element 1 through re paren count bound to the paren match an index properti tell the length of the left context and an input properti refer to the input string scriptabl scope get top level scope scope obj result script runtim new object cx scope arrai null obj scriptabl result string matchstr new string char arrai index matchlen obj put 0 obj matchstr if re paren count 0 re paren null re last paren sub string empti sub string els sub string parsub null int num re paren new sub string re paren count for num 0 num re paren count num int cap index g data paren index num string parstr if cap index 1 int cap length g data paren length num parsub new sub string char arrai cap index cap length re paren num parsub if match type test continu parstr parsub to string obj put num 1 obj parstr els if match type test obj put num 1 obj undefin instanc re last paren parsub if match type test defin the index and input properti last for better for in loop order so thei come after the element obj put index obj new integ start g data skip obj put input obj str if re last match null re last match new sub string re left context new sub string re right context new sub string re last match char arrai char arrai re last match index index re last match length matchlen re left context char arrai char arrai if cx get languag version context version 1 2 js1 2 emul perl4 0 1 8 patch level 36 for global regexp us in scalar context and unintention for the string match list psuedo context on hi there bye the follow would result languag while g print s g perl4 036 hi there hihitherehi thereby perl5 hi hi there hihitherehi thereby js1 2 hi there hihitherethereby insofar as js1 2 alwai defin as left context from the last match for global regexp it wa more consist than perl4 re left context index start re left context length g data skip els for js1 3 and ecm av2 emul perl5 exactli js1 3 hi hi there hihitherehi thereby re left context index 0 re left context length start g data skip re right context char arrai char arrai re right context index ep re right context length end ep return result int get flag return re flag privat static void report error string messag id string arg string msg script runtim get messag1 messag id arg throw script runtim construct error syntax error msg max instanc id 5 protect int get max instanc id return max instanc id protect int find instanc id info string s int id gener last updat 2001 05 24 12 01 22 gmt 02 00 l0 id 0 string x null int c int s length s length if s length 6 c s char at 0 if c g x global id id global els if c s x sourc id id sourc els if s length 9 c s char at 0 if c l x last index id id last index els if c m x multilin id id multilin els if s length 10 x ignor case id id ignor case if x null x s x equal s id 0 gener string id map if id 0 return super find instanc id info s int attr switch id case id last index attr perman dontenum break case id sourc case id global case id ignor case case id multilin attr perman readonli dontenum break default throw new illeg state except return instanc id info attr id protect string get instanc id name int id switch id case id last index return last index case id sourc return sourc case id global return global case id ignor case return ignor case case id multilin return multilin return super get instanc id name id protect object get instanc id valu int id switch id case id last index return script runtim wrap number last index case id sourc return new string re sourc case id global return script runtim wrap boolean re flag jsreg glob 0 case id ignor case return script runtim wrap boolean re flag jsreg fold 0 case id multilin return script runtim wrap boolean re flag jsreg multilin 0 return super get instanc id valu id protect void set instanc id valu int id object valu if id id last index last index script runtim to number valu return super set instanc id valu id valu protect void init prototyp id int id string s int ariti switch id case id compil ariti 1 s compil break case id to string ariti 0 s to string break case id to sourc ariti 0 s to sourc break case id exec ariti 1 s exec break case id test ariti 1 s test break case id prefix ariti 1 s prefix break default throw new illeg argument except string valu of id init prototyp method regexp tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag regexp tag return super exec id call f cx scope thi obj arg int id f method id switch id case id compil return real thi thi obj f compil cx scope arg case id to string case id to sourc return real thi thi obj f to string case id exec return real thi thi obj f exec sub cx scope arg match case id test object x real thi thi obj f exec sub cx scope arg test return boolean true equal x boolean true boolean fals case id prefix return real thi thi obj f exec sub cx scope arg prefix throw new illeg argument except string valu of id privat static nativ reg exp real thi scriptabl thi obj id function object f if thi obj instanceof nativ reg exp throw incompat call error f return nativ reg exp thi obj string id map protect int find prototyp id string s int id gener last updat 2004 03 17 13 54 21 cet l0 id 0 string x null int c l switch s length case 4 c s char at 0 if c e x exec id id exec els if c t x test id id test break l case 6 x prefix id id prefix break l case 7 x compil id id compil break l case 8 c s char at 3 if c o x to sourc id id to sourc els if c t x to string id id to string break l if x null x s x equal s id 0 gener return id class re node re node byte op thi op op compil state char sourc int length int flag thi cpbegin sourc thi cp 0 thi cpend length thi flag flag thi paren count 0 thi class count 0 thi prog length 0 re prog state re prog state previou int min int max int index re back track data back track int continu pc int continu op thi previou previou thi min min thi max max thi index index thi continu op continu op thi continu pc continu pc thi back track back track re back track data re global data g data int op int pc previou g data back track stack top continu op op continu pc pc last paren g data last paren if g data paren null paren long g data paren clone cp g data cp state stack top g data state stack top get start of parenthesi captur content 1 for empti int paren index int i return int paren i get length of parenthesi captur content int paren length int i return int paren i 32 void set paren int i int index int length paren i long index 0xffffffffl long length 32 re char set int length int start index int strlength thi length length thi start index start index thi strlength strlength static final long serial versionuid 924022554283675333l public string get class name return java arrai public static nativ java arrai wrap scriptabl scope object arrai return new nativ java arrai scope arrai public object unwrap return arrai public nativ java arrai scriptabl scope object arrai super scope null script runtim object class class cl arrai get class if cl is arrai throw new runtim except arrai expect thi arrai arrai thi length arrai get length arrai thi cl cl get compon type public boolean ha string id scriptabl start return id equal length super ha id start public boolean ha int index scriptabl start return 0 index index length public object get string id scriptabl start if id equal length return new integ length object result super get id start if result not found scriptabl object ha properti get prototyp id throw context report runtim error2 msg java member not found arrai get class get name id return result public object get int index scriptabl start if 0 index index length context cx context get context object obj arrai get arrai index return cx get wrap factori wrap cx thi obj cl return undefin instanc public void put string id scriptabl start object valu ignor assign to length it s readonli if id equal length super put id start valu public void put int index scriptabl start object valu if 0 index index length arrai set arrai index context js to java valu cl return super put index start valu public object get default valu class hint if hint null hint script runtim string class return arrai to string if hint script runtim boolean class return boolean true if hint script runtim number class return script runtim na nobj return thi public object get id object result new object length int i length while i 0 result i new integ i return result public boolean ha instanc scriptabl valu if valu instanceof wrapper return fals object instanc wrapper valu unwrap return cl is instanc instanc public scriptabl get prototyp if prototyp null prototyp scriptabl object get class prototyp thi get parent scope arrai return prototyp token stream parser parser reader sourc reader string sourc string int lineno thi parser parser thi lineno lineno if sourc reader null if sourc string null kit code bug thi sourc reader sourc reader thi sourc buffer new char 512 thi sourc end 0 els if sourc string null kit code bug thi sourc string sourc string thi sourc end sourc string length thi sourc cursor 0 string token to string int token if token print tree string name token name token switch token case token string case token regexp case token name return name thi string case token number return number thi number return name return static boolean is keyword string s return token eof string to keyword s privat static int string to keyword string name string id map the follow assum that token eof 0 final int id break token break id case token case id continu token continu id default token default id delet token delprop id do token do id els token els id export token export id fals token fals id for token for id function token function id if token if id in token in id new token new id null token null id return token return id switch token switch id thi token thi id true token true id typeof token typeof id var token var id void token void id while token while id with token with the follow ar ifdef reserv java keyword in jsscan c id abstract token reserv id boolean token reserv id byte token reserv id catch token catch id char token reserv id class token reserv id const token reserv id debugg token reserv id doubl token reserv id enum token reserv id extend token reserv id final token reserv id final token final id float token reserv id goto token reserv id implement token reserv id import token import id instanceof token instanceof id int token reserv id interfac token reserv id long token reserv id nativ token reserv id packag token reserv id privat token reserv id protect token reserv id public token reserv id short token reserv id static token reserv id super token reserv id synchron token reserv id throw token throw id throw token reserv id transient token reserv id try token try id volatil token reserv int id string s name gener last updat 2001 06 01 17 45 01 cest l0 id 0 string x null int c l switch s length case 2 c s char at 1 if c f if s char at 0 i id id if break l0 els if c n if s char at 0 i id id in break l0 els if c o if s char at 0 d id id do break l0 break l case 3 switch s char at 0 case f if s char at 2 r s char at 1 o id id for break l0 break l case i if s char at 2 t s char at 1 n id id int break l0 break l case n if s char at 2 w s char at 1 e id id new break l0 break l case t if s char at 2 y s char at 1 r id id try break l0 break l case v if s char at 2 r s char at 1 a id id var break l0 break l break l case 4 switch s char at 0 case b x byte id id byte break l case c c s char at 3 if c e if s char at 2 s s char at 1 a id id case break l0 els if c r if s char at 2 a s char at 1 h id id char break l0 break l case e c s char at 3 if c e if s char at 2 s s char at 1 l id id els break l0 els if c m if s char at 2 u s char at 1 n id id enum break l0 break l case g x goto id id goto break l case l x long id id long break l case n x null id id null break l case t c s char at 3 if c e if s char at 2 u s char at 1 r id id true break l0 els if c s if s char at 2 i s char at 1 h id id thi break l0 break l case v x void id id void break l case w x with id id with break l break l case 5 switch s char at 2 case a x class id id class break l case e x break id id break break l case i x while id id while break l case l x fals id id fals break l case n c s char at 0 if c c x const id id const els if c f x final id id final break l case o c s char at 0 if c f x float id id float els if c s x short id id short break l case p x super id id super break l case r x throw id id throw break l case t x catch id id catch break l break l case 6 switch s char at 1 case a x nativ id id nativ break l case e c s char at 0 if c d x delet id id delet els if c r x return id id return break l case h x throw id id throw break l case m x import id id import break l case o x doubl id id doubl break l case t x static id id static break l case u x public id id public break l case w x switch id id switch break l case x x export id id export break l case y x typeof id id typeof break l break l case 7 switch s char at 1 case a x packag id id packag break l case e x default id id default break l case i x final id id final break l case o x boolean id id boolean break l case r x privat id id privat break l case x x extend id id extend break l break l case 8 switch s char at 0 case a x abstract id id abstract break l case c x continu id id continu break l case d x debugg id id debugg break l case f x function id id function break l case v x volatil id id volatil break l break l case 9 c s char at 0 if c i x interfac id id interfac els if c p x protect id id protect els if c t x transient id id transient break l case 10 c s char at 1 if c m x implement id id implement els if c n x instanceof id id instanceof break l case 12 x synchron id id synchron break l if x null x s x equal s id 0 gener string id map if id 0 return token eof return id 0xff final int get lineno return lineno final int get lineno return lineno final string get string return string final string get string return string final doubl get number return number final doubl get number return number final boolean eof return hiteof final int get token throw io except int c retri for eat whitespac possibl sensit to newlin for c get char if c eof char return token eof els if c n dirti line fals return token eol els if isj space c if c dirti line true break if c return token xmlattr identifi keyword instanceof watch out for start with a backslash boolean identifi start boolean is unicod escap start fals if c c get char if c u identifi start true is unicod escap start true string buffer top 0 els identifi start fals unget char c c els identifi start charact is java identifi start char c if identifi start string buffer top 0 add to string c if identifi start boolean contain escap is unicod escap start for if is unicod escap start strictli speak we should probabl push back all the bad charact if the backslash uxxxx sequenc is malform but sinc there isn t a correct context is there for a bad unicod escap sequenc in an identifi we can report an error here int escap val 0 for int i 0 i 4 i c get char escap val kit x digit to int c escap val next check take care about c 0 and bad escap if escap val 0 break if escap val 0 parser add error msg invalid escap return token error add to string escap val is unicod escap start fals els c get char if c c get char if c u is unicod escap start true contain escap true els parser add error msg illeg charact return token error els if c eof char charact is java identifi part char c break add to string c unget char c string str get string from buffer if contain escap opt we shouldn t have to make a string object to check if it s a keyword return the correspond token if it s a keyword int result string to keyword str if result token eof if result token reserv return result els if parser compil env is reserv keyword as identifi return result els if implement permit to us futur reserv keyword in violat with the ecma script treat it as name but issu warn parser add warn msg reserv keyword str thi string string all string intern str return token name is it a number if is digit c c is digit peek char string buffer top 0 int base 10 if c 0 c get char if c x c x base 16 c get char els if is digit c base 8 els add to string 0 if base 16 while 0 kit x digit to int c 0 add to string c c get char els while 0 c c 9 we permit 08 and 09 as decim number which make our behavior a superset of the ecma numer grammar we might not alwai be so permiss so we warn about it if base 8 c 8 parser add warn msg bad octal liter c 8 8 9 base 10 add to string c c get char boolean is integ true if base 10 c c e c e is integ fals if c do add to string c c get char while is digit c if c e c e add to string c c get char if c c add to string c c get char if is digit c parser add error msg miss expon return token error do add to string c c get char while is digit c unget char c string num string get string from buffer doubl dval if base 10 is integ try us java convers to number from string dval doubl valu of num string doubl valu catch number format except ex parser add error msg caught nfe return token error els dval script runtim string to number num string 0 base thi number dval return token number is it a string if c c we attempt to accumul a string the fast wai by build it directli out of the reader but if there ar ani escap charact in the string we revert to build it out of a string buffer int quot char c string buffer top 0 c get char str loop while c quot char if c n c eof char unget char c parser add error msg untermin string lit return token error if c we ve hit an escap charact int escap val c get char switch c case b c b break case f c f break case n c n break case r c r break case t c t break v a late addit to the ecma spec it is not in java so us 0xb case v c 0xb break case u get 4 hex digit if the u escap is not follow by 4 hex digit us u the liter charact sequenc that follow int escap start string buffer top add to string u escap val 0 for int i 0 i 4 i c gprivat static boolean is alpha int c us z a if c z return a c els return a c c z static boolean is digit int c return 0 c c 9 static boolean isj space int c if c 127 return c 0x20 c 0x9 c 0xc c 0xb els return c 0xa0 charact get type char c charact space separ privat static boolean isj format char int c return c 127 charact get type char c charact format parser call the method when it get or in liter context void read reg exp int start token throw io except string buffer top 0 if start token token assign div miss scan add to string els if start token token div kit code bug int c while c get char if c n c eof char unget char c throw parser report error msg untermin re lit if c add to string c c get char add to string c int re end string buffer top while true if match char g add to string g els if match char i add to string i els if match char m add to string m els break if is alpha peek char throw parser report error msg invalid re flag thi string new string string buffer 0 re end thi reg exp flag new string string buffer re end string buffer top re end boolean isxml attribut return xml is attribut int get firstxml token throw io except xml open tag count 0 xml is attribut fals xml is tag content fals unget char return get nextxml token int get nextxml token throw io except string buffer top 0 rememb the xml for int c get char c eof char c get char if xml is tag content switch c case add to string c xml is tag content fals xml is attribut fals break case add to string c if peek char c get char add to string c xml is tag content fals xml open tag count break case unget char c thi string get string from buffer return token xml case case add to string c if read quot string c return token error break case add to string c xml is attribut true break case case t case r case n add to string c break default add to string c xml is attribut fals break if xml is tag content xml open tag count 0 thi string get string from buffer return token xmlend els switch c case add to string c c peek char switch c case c get char skip add to string c c peek char switch c case c get char skip add to string c c get char if c add to string c if read xml comment return token error els throw awai the string in progress string buffer top 0 thi string null parser add error msg xml bad form return token error break case c get char skip add to string c if get char c get char d get char a get char t get char a get char add to string c add to string d add to string a add to string t add to string a add to string if readcdata return token error els throw awai the string in progress string buffer top 0 thi string null parser add error msg xml bad form return token error break default if read entiti return token error break break case c get char skip add to string c if readpi return token error break case end tag c get char skip add to string c if xml open tag count 0 throw awai the string in progress string buffer top 0 thi string null parser add error msg xml bad form return token error xml is tag content true xml open tag count break default start tag xml is tag content true xml open tag count break break case unget char c thi string get string from buffer return token xml default add to string c break string buffer top 0 throw awai the string in progress thi string null parser add error msg xml bad form return token error privat boolean read quot string int quot throw io except for int c get char c eof char c get char add to string c if c quot return true string buffer top 0 throw awai the string in progress thi string null parser add error msg xml bad form return fals privat boolean read xml comment throw io except for int c get char c eof char add to string c if c peek char c get char add to string c if peek char c get char skip add to string c return true els continu c get char string buffer top 0 throw awai the string in progress thi string null parser add error msg xml bad form return fals privat boolean readcdata throw io except for int c get char c eof char add to string c if c peek char c get char add to string c if peek char c get char skip add to string c return true els continu c get char string buffer top 0 throw awai the string in progress thi string null parser add error msg xml bad form return fals privat boolean read entiti throw io except int decl tag 1 for int c get char c eof char c get char add to string c switch c case decl tag break case decl tag if decl tag 0 return true break string buffer top 0 throw awai the string in progress thi string null parser add error msg xml bad form return fals privat boolean readpi throw io except for int c get char c eof char c get char add to string c if c peek char c get char skip add to string c return true string buffer top 0 throw awai the string in progress thi string null parser add error msg xml bad form return fals privat string get string from buffer return new string string buffer 0 string buffer top privat void add to string int c int n string buffer top if n string buffer length char tmp new char string buffer length 2 system arraycopi string buffer 0 tmp 0 n string buffer tmp string buffer n char c string buffer top n 1 privat void unget char int c can not unread past across line boundari if unget cursor 0 unget buffer unget cursor 1 n kit code bug unget buffer unget cursor c privat boolean match char int test throw io except int c get char if c test return true els unget char c return fals privat int peek char throw io except int c get char unget char c return c privat int get char throw io except if unget cursor 0 return unget buffer unget cursor for int c if sourc string null if sourc cursor sourc end hiteof true return eof char c sourc string char at sourc cursor els if sourc cursor sourc end if fill sourc buffer hiteof true return eof char c sourc buffer sourc cursor if line end char 0 if line end char r c n line end char n continu line end char 1 line start sourc cursor 1 lineno if c 127 if c n c r line end char c c n els if isj format char c continu if script runtim isj line termin c line end char c c n return c privat void skip line throw io except skip to end of line int c while c get char eof char c n unget char c final int get offset int n sourc cursor line start if line end char 0 n return n final string get line if sourc string null string case int line end sourc cursor if line end char 0 line end els for line end sourc end line end int c sourc string char at line end if script runtim isj line termin c break return sourc string substr line start line end els reader case int line length sourc cursor line start if line end char 0 line length els read until the end of line for line length int i line start line length if i sourc end try if fill sourc buffer break catch io except ioe ignor it we re alreadi displai an error break i recalculu as fill sourc buffer can move save line buffer and chang line start i line start line length int c sourc buffer i if script runtim isj line termin c break return new string sourc buffer line start line length privat boolean fill sourc buffer throw io except if sourc string null kit code bug if sourc end sourc buffer length if line start 0 system arraycopi sourc buffer line start sourc buffer 0 sourc end line start sourc end line start sourc cursor line start line start 0 els char tmp new char sourc buffer length 2 system arraycopi sourc buffer 0 tmp 0 sourc end sourc buffer tmp int n sourc reader read sourc buffer sourc end sourc buffer length sourc end if n 0 return fals sourc end n return true static void init scriptabl scope boolean seal base function obj new base function obj is prototyp properti immun true obj export asj class max prototyp id scope seal public base function public base function scriptabl scope scriptabl prototyp super scope prototyp public string get class name return function implement the instanceof oper for java script function object p code foo new foo br foo instanceof foo true br code param instanc the valu that appear on the lh of the instanceof oper return true if the prototyp properti of thi appear in valu s prototyp chain public boolean ha instanc scriptabl instanc object proto prop scriptabl object get properti thi prototyp if proto prop instanceof scriptabl return script runtim js deleg to instanc scriptabl proto prop throw script runtim type error1 msg instanceof bad prototyp get function name max instanc id 5 protect int get max instanc id return max instanc id protect int find instanc id info string s int id gener last updat 2001 05 20 00 12 12 gmt 02 00 l0 id 0 string x null int c l switch s length case 4 x name id id name break l case 5 x ariti id id ariti break l case 6 x length id id length break l case 9 c s char at 0 if c a x argument id id argument els if c p x prototyp id id prototyp break l if x null x s x equal s id 0 gener string id map if id 0 return super find instanc id info s int attr switch id case id length case id ariti case id name attr dontenum readonli perman break case id prototyp attr is prototyp properti immun dontenum readonli perman dontenum break case id argument attr dontenum perman break default throw new illeg state except return instanc id info attr id protect string get instanc id name int id switch id case id length return length case id ariti return ariti case id name return name case id prototyp return prototyp case id argument return argument return super get instanc id name id protect object get instanc id valu int id switch id case id length return script runtim wrap int get length case id ariti return script runtim wrap int get ariti case id name return get function name case id prototyp return get prototyp properti case id argument return get argument return super get instanc id valu id protect void set instanc id valu int id object valu if id id prototyp if is prototyp properti immun prototyp properti valu null valu uniqu tag null valu return els if id id argument if valu not found thi should not be call sinc argument is perman kit code bug default put argument valu super set instanc id valu id valu protect void fill constructor properti id function object ctor fix up bootstrap problem get prototyp of the id function object can not return function prototyp becaus function object is not yet defin ctor set prototyp thi super fill constructor properti ctor protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 1 s to string break case id to sourc ariti 1 s to sourc break case id appli ariti 2 s appli break case id call ariti 1 s call break default throw new illeg argument except string valu of id init prototyp method function tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag function tag return super exec id call f cx scope thi obj arg int id f method id switch id case id constructor return js constructor cx scope arg case id to string base function realf real function thi obj f int indent script runtim to int32 arg 0 return realf decompil indent 0 case id to sourc base function realf real function thi obj f int indent 0 int flag decompil to sourc flag if arg length 0 indent script runtim to int32 arg 0 if indent 0 flag 0 els indent 0 return realf decompil indent flag case id appli case id call return script runtim appli or call id id appli cx scope thi obj arg throw new illeg argument except string valu of id privat base function real function scriptabl thi obj id function object f object x thi obj get default valu script runtim function class if x instanceof base function return base function x throw script runtim type error1 msg incompat call f get function name make valu as dont enum dont delet read onli prototyp properti of thi function object public void set immun prototyp properti object valu if is prototyp properti immun throw new illeg state except prototyp properti valu null valu uniqu tag null valu is prototyp properti immun true protect scriptabl get class prototyp object proto val get prototyp properti if proto val instanceof scriptabl return scriptabl proto val return get class prototyp thi object should be overridden public object call context cx scriptabl scope scriptabl thi obj object arg return undefin instanc public scriptabl construct context cx scriptabl scope object arg scriptabl result creat object cx scope if result null object val call cx scope result arg if val instanceof scriptabl result scriptabl val els object val call cx scope null arg if val instanceof scriptabl it is program error not to return scriptabl from the call method if creat object return null throw new illeg state except bad implementaion of call as constructor name get function name in get class get name result scriptabl val if result get prototyp null result set prototyp get class prototyp if result get parent scope null scriptabl parent get parent scope if result parent result set parent scope parent return result creat new script object the default implement of link construct us the method to to get the valu for tt thi obj tt argument when invok link call the metho is allow to return tt null tt to indic that link call will creat a new object itself in thi case link construct will set scope and prototyp on the result link call unless thei ar alreadi set public scriptabl creat object context cx scriptabl scope scriptabl new instanc new nativ object new instanc set prototyp get class prototyp new instanc set parent scope get parent scope return new instanc decompil the sourc inform associ with thi js function script back into a string param indent how much to indent the decompil result param flag flag specifi format of decompil output string decompil int indent int flag string buffer sb new string buffer boolean justbodi 0 flag decompil onli bodi flag if justbodi sb append function sb append get function name sb append n t sb append nativ code ariti sb append get ariti sb append n if justbodi sb append n return sb to string public int get ariti return 0 public int get ariti return 0 public int get length return 0 public int get length return 0 public string get function name return final object get prototyp properti object result prototyp properti if result null synchron thi result prototyp properti if result null setup default prototyp result prototyp properti els if result uniqu tag null valu result null return result privat void setup default prototyp nativ object obj new nativ object final int attr scriptabl object dontenum obj defin properti constructor thi attr put the prototyp properti into the object now then in the wacki case of a user defin a function object we don t get an infinit loop try to find the prototyp prototyp properti obj scriptabl proto get object prototyp thi if proto obj not the on we just made it must remain ground obj set prototyp proto privat object get argument function name argument is deprec so we us a slow wai of get it that doesn t add to the invoc cost todo add warn error base on version object valu default get argument if valu not found should after chang function name argument it activ still be avail dure function call thi code assum it should not default get argument not found mean assign argument return valu context cx context get context nativ call activ script runtim find function activ cx thi return activ null null activ get argument activ privat static object js constructor context cx scriptabl scope object arg int arglen arg length string buffer sourc buf new string buffer sourc buf append function version 1 2 function constructor behavior print anonym as the function name if the version under which the function wa compil is less than 1 2 or if it s greater than 1 2 becaus we need to be closer to ecma if cx get languag version context version 1 2 sourc buf append anonym sourc buf append append argument as coma separ string for int i 0 i arglen 1 i if i 0 sourc buf append sourc buf append script runtim to string arg i sourc buf append if arglen 0 append function bodi string fun bodi script runtim to string arg arglen 1 sourc buf append fun bodi sourc buf append string sourc sourc buf to string int linep new int 1 string filenam context get sourc posit from stack linep if filenam null filenam eval ed string linep 0 1 string sourceuri script runtim make url for gener script fals filenam linep 0 scriptabl global scriptabl object get top level scope scope error report report report default error report for eval cx get error report compil with explicit interpret instanc to forc interpret mode return cx compil function global sourc new interpret report sourceuri 1 null protect int find prototyp id string s int id string id map gener last updat 2004 03 17 13 23 22 cet l0 id 0 string x null int c l switch s length case 4 x call id id call break l case 5 x appli id id appli break l case 8 c s char at 3 if c o x to sourc id id to sourc els if c t x to string id id to string break l case 11 x constructor id id constructor break l if x null x s x equal s id 0 gener return id search for class cach object in the given scope the method first call link scriptabl object get top level scope scriptabl scope to get the top most scope and then tri to locat associ class cach object in the prototyp chain of the top scope param scope scope to search for class cach object return previous associ class cach object or a new instanc of class cach if no class cach object wa found see associ scriptabl object top scope public static class cach get scriptabl scope class cach cach cach class cach scriptabl object get top scope valu scope akei if cach null xxx warn somehow about wrong cach usag cach new class cach return cach associ class cach object with the given top level scope the class cach object can onli be associ with the given scope onc param top scope scope to associ thi class cach object with return true if no prevou class cach object were embed into the scope and thi class cach were successfulli associ or fals otherwis see get scriptabl scope public boolean associ scriptabl object top scope if top scope get parent scope null can onli associ cach with top level scope throw new illeg argument except if thi top scope associ valu akei thi scope top scope return true return fals empti cach of gener java class and java reflect inform public synchron void clear cach class tabl new hashtabl java adapt gener class new hashtabl interfac adapt cach null check if gener java class and java reflect inform is cach public final boolean is cach enabl return cach is enabl set whether to cach some valu p by default the engin will cach the result of tt class get method tt and similar call thi can speed execut dramat but increas the memori footprint also with cach enabl refer mai be held to object past the lifetim of ani real usag p if cach is enabl and thi method is call with a code fals code argument the cach will be empti p cach is enabl by default param enabl if true cach is enabl see clear cach public synchron void set cach enabl boolean enabl if enabl cach is enabl return if enabl clear cach cach is enabl enabl deprec the method alwai return fals see set invok optim enabl boolean enabl public boolean is invok optim enabl return fals deprec the method doe noth invok optim is no longer us by rhino on modern jdk like 1 4 or 1 5 the disadvatag of the optim like incres memori usag or longer initi time overweight small speed increas that can be gain us gener proxi class to replac reflect public synchron void set invok optim enabl boolean enabl intern engin method to return serial number for gener class to ensur name uniqu public final synchron int new class serial number return gener class serial object get interfac adapt class cl object result hashtabl cach interfac adapt cach if cach null result null els result cach get cl return result synchron void cach interfac adapt class cl object iadapt if cach is enabl if interfac adapt cach null interfac adapt cach new hashtabl interfac adapt cach put cl iadapt nativ java packag boolean intern usag string packag name class loader class loader thi packag name packag name thi class loader class loader deprec nativ java packag is an intern class do not us it directli public nativ java packag string packag name class loader class loader thi fals packag name class loader deprec nativ java packag is an intern class do not us it directli public nativ java packag string packag name thi fals packag name context get current context get applic class loader public string get class name return java packag public boolean ha string id scriptabl start return true public boolean ha int index scriptabl start return fals public void put string id scriptabl start object valu can t add properti to java packag sorri public void put int index scriptabl start object valu throw context report runtim error0 msg pkg int public object get string id scriptabl start return get pkg properti id start true public object get int index scriptabl start return not found need to look for a class by that name void forc packag string name scriptabl scope nativ java packag pkg int end name index of if end 1 end name length string id name substr 0 end object cach super get id thi if cach null cach instanceof nativ java packag pkg nativ java packag cach els string new packag packag name length 0 id packag name id pkg new nativ java packag true new packag class loader script runtim set object proto and parent pkg scope super put id thi pkg if end name length pkg forc packag name substr end 1 scope synchron object get pkg properti string name scriptabl start boolean creat pkg object cach super get name start if cach not found return cach string class name packag name length 0 name packag name name context cx context get context class shutter shutter cx get class shutter scriptabl new valu null if shutter null shutter visibl to script class name class cl null if class loader null cl kit class or null class loader class name els cl kit class or null class name if cl null new valu new nativ java class get top level scope thi cl new valu set prototyp get prototyp if new valu null creat pkg nativ java packag pkg pkg new nativ java packag true class name class loader script runtim set object proto and parent pkg get parent scope new valu pkg if new valu null make it avail for fast lookup and share of lazili reflect constructor and static member super put name start new valu return new valu public object get default valu class ignor return to string public string to string return java packag packag name public class script or fn node extend node public script or fn node int node type super node type public final string get sourc name return sourc name public final string get sourc name return sourc name public final void set sourc name string sourc name thi sourc name sourc name public final int get encod sourc start return encod sourc start public final int get encod sourc start return encod sourc start public final int get encod sourc end return encod sourc end public final int get encod sourc end return encod sourc end public final void set encod sourc bound int start int end thi encod sourc start start thi encod sourc end end public final int get base lineno return base lineno public final void set base lineno int lineno on time action if lineno 0 base lineno 0 kit code bug base lineno lineno public final int get end lineno return end lineno public final void set end lineno int lineno on time action if lineno 0 end lineno 0 kit code bug end lineno lineno public final int get function count if function null return 0 return function size public final function node get function node int i return function node function get i public final int add function function node fn node if fn node null kit code bug if function null function new obj arrai function add fn node return function size 1 public final int get regexp count if regexp null return 0 return regexp size 2 public final string get regexp string int index return string regexp get index 2 public final string get regexp flag int index return string regexp get index 2 1 public final int add regexp string string string flag if string null kit code bug if regexp null regexp new obj arrai regexp add string regexp add flag return regexp size 2 1 public final boolean ha param or var string name return it variabl name ha name public final int get param or var index string name return it variabl name get name 1 public final string get param or var name int index return string it variabl get index public final int get param count return var start public final int get param and var count return it variabl size public final string get param and var name int n it variabl size if n 0 return script runtim empti string string arrai new string n it variabl to arrai arrai return arrai public final void add param string name check addparam is not call after add local if var start it variabl size kit code bug allow non uniqu paramet name us the last occurr int index var start it variabl add name it variabl name put name index public final void add var string name int v index it variabl name get name 1 if v index 1 there s alreadi a variabl or paramet with thi name return int index it variabl size it variabl add name it variabl name put name index public final void remov param or var string name int i it variabl name get name 1 if i 1 it variabl remov i it variabl name remov name obj to int map iter iter it variabl name new iter for iter start iter done iter next int v iter get valu if v i iter set valu v 1 public final object get compil data return compil data public final void set compil data object data if data null throw new illeg argument except can onli call onc if compil data null throw new illeg state except compil data data public argument nativ call activ thi activ activ scriptabl parent activ get parent scope set parent scope parent set prototyp scriptabl object get object prototyp parent arg activ origin arg length obj new integ arg length nativ function f activ function calle obj f int version f get languag version if version context version 1 3 version context version default caller obj null els caller obj not found public string get class name return argument public boolean ha int index scriptabl start if 0 index index arg length if arg index not found return true return super ha index start public object get int index scriptabl start if 0 index index arg length object valu arg index if valu not found if share with activ index nativ function f activ function string arg name f get param or var name index valu activ get arg name activ if valu not found kit code bug return valu return super get index start privat boolean share with activ int index nativ function f activ function int defin count f get param count if index defin count check if argument is not hidden by later argument with the same name as hidden argument ar not share with activ if index defin count 1 string arg name f get param or var name index for int i index 1 i defin count i if arg name equal f get param or var name i return fals return true return fals public void put int index scriptabl start object valu if 0 index index arg length if arg index not found if share with activ index string arg name arg name activ function get param or var name index activ put arg name activ valu return synchron thi if arg index not found if arg activ origin arg arg object arg clone arg index valu return super put index start valu public void delet int index if 0 index index arg length synchron thi if arg index not found if arg activ origin arg arg object arg clone arg index not found return super delet index max instanc id 3 protect int get max instanc id return max instanc id protect int find instanc id info string s int id gener last updat 2002 04 09 20 46 33 cest l0 id 0 string x null int c if s length 6 c s char at 5 if c e x calle id id calle els if c h x length id id length els if c r x caller id id caller if x null x s x equal s id 0 gener if id 0 return super find instanc id info s int attr switch id case id calle case id caller case id length attr dontenum break default throw new illeg state except return instanc id info attr id protect string get instanc id name int id switch id case id calle return calle case id length return length case id caller return caller return null protect object get instanc id valu int id switch id case id calle return calle obj case id length return length obj case id caller object valu caller obj if valu uniqu tag null valu valu null els if valu null nativ call caller activ parent activ call if caller null valu caller get argument caller els valu null return valu return super get instanc id valu id protect void set instanc id valu int id object valu switch id case id calle calle obj valu return case id length length obj valu return case id caller caller obj valu null valu uniqu tag null valu return super set instanc id valu id valu object get id boolean get all object id super get id get all if get all arg length 0 boolean present null int extra count arg length for int i 0 i id length i object id id i if id instanceof integ int index integ id int valu if 0 index index arg length if present null present new boolean arg length if present index present index true extra count if extra count 0 object tmp new object extra count id length system arraycopi id 0 tmp extra count id length id tmp int offset 0 for int i 0 i arg length i if present null present i id offset new integ i offset if offset extra count kit code bug return id static final long serial versionuid 4174889037736658296l public obj arrai public obj arrai public final boolean is seal return seal public final void seal seal true public final boolean is empti return size 0 public final int size return size public final void set size int new size if new size 0 throw new illeg argument except if seal throw on sele mutat int n size if new size n for int i new size i n i set impl i null els if new size n if new size field store size ensur capac new size size new size public final object get int index if 0 index index size throw on invalid index index size return get impl index public final void set int index object valu if 0 index index size throw on invalid index index size if seal throw on sele mutat set impl index valu privat object get impl int index switch index case 0 return f0 case 1 return f1 case 2 return f2 case 3 return f3 case 4 return f4 return data index field store size privat void set impl int index object valu switch index case 0 f0 valu break case 1 f1 valu break case 2 f2 valu break case 3 f3 valu break case 4 f4 valu break default data index field store size valu public int index of object obj int n size for int i 0 i n i object current get impl i if current obj current null current equal obj return i return 1 public int last index of object obj for int i size i 0 i object current get impl i if current obj current null current equal obj return i return 1 public final object peek int n size if n 0 throw on empti stack top read return get impl n 1 public final object pop if seal throw on sele mutat int n size n object top switch n case 1 throw on empti stack top read case 0 top f0 f0 null break case 1 top f1 f1 null break case 2 top f2 f2 null break case 3 top f3 f3 null break case 4 top f4 f4 null break default top data n field store size data n field store size null size n return top public final void push object valu add valu public final void add object valu if seal throw on sele mutat int n size if n field store size ensur capac n 1 size n 1 set impl n valu public final void add int index object valu int n size if 0 index index n throw on invalid index index n 1 if seal throw on sele mutat object tmp switch index case 0 if n 0 f0 valu break tmp f0 f0 valu valu tmp case 1 if n 1 f1 valu break tmp f1 f1 valu valu tmp case 2 if n 2 f2 valu break tmp f2 f2 valu valu tmp case 3 if n 3 f3 valu break tmp f3 f3 valu valu tmp case 4 if n 4 f4 valu break tmp f4 f4 valu valu tmp index field store size default ensur capac n 1 if index n system arraycopi data index field store size data index field store size 1 n index data index field store size valu size n 1 public final void remov int index int n size if 0 index index n throw on invalid index index n if seal throw on sele mutat n switch index case 0 if n 0 f0 null break f0 f1 case 1 if n 1 f1 null break f1 f2 case 2 if n 2 f2 null break f2 f3 case 3 if n 3 f3 null break f3 f4 case 4 if n 4 f4 null break f4 data 0 index field store size default if index n system arraycopi data index field store size 1 data index field store size n index data n field store size null size n public final void clear if seal throw on sele mutat int n size for int i 0 i n i set impl i null size 0 public final object to arrai object arrai new object size to arrai arrai 0 return arrai public final void to arrai object arrai to arrai arrai 0 public final void to arrai object arrai int offset int n size switch n default system arraycopi data 0 arrai offset field store size n field store size case 5 arrai offset 4 f4 case 4 arrai offset 3 f3 case 3 arrai offset 2 f2 case 2 arrai offset 1 f1 case 1 arrai offset 0 f0 case 0 break privat void ensur capac int minim capac int requir minim capac field store size if requir 0 throw new illeg argument except if data null int alloc field store size 2 if alloc requir alloc requir data new object alloc els int alloc data length if alloc requir if alloc field store size alloc field store size 2 els alloc 2 if alloc requir alloc requir object tmp new object alloc if size field store size system arraycopi data 0 tmp 0 size field store size data tmp privat static runtim except on invalid index int index int upper bound u2209 is not element of string msg index u2209 0 upper bound throw new index out of bound except msg privat static runtim except on empti stack top read throw new runtim except empti stack privat static runtim except on sele mutat throw new illeg state except attempt to modifi seal arrai privat void write object object output stream os throw io except os default write object int n size for int i 0 i n i object obj get impl i os write object obj privat void read object object input stream is throw io except class not found except is default read object it read size int n size if n field store size data new object n field store size for int i 0 i n i object obj is read object set impl i obj public abstract class rhino except extend runtim except rhino except interpret captur interpret stack info thi rhino except string detail super detail interpret captur interpret stack info thi public final string get messag string detail detail if sourc name null line number 0 return detail string buffer buf new string buffer detail buf append if sourc name null buf append sourc name if line number 0 buf append buf append line number buf append return buf to string public string detail return super get messag get the uri of the script sourc contain the error or null if that inform is not avail public final string sourc name return sourc name initi the uri of the script sourc contain the error param sourc name the uri of the script sourc repons for the error it should not be tt null tt throw illeg state except if the method is call more then onc public final void init sourc name string sourc name if sourc name null throw new illeg argument except if thi sourc name null throw new illeg state except thi sourc name sourc name return the line number of the statement caus the error or zero if not avail public final int line number return line number initi the line number of the script statement caus the error param line number the line number in the script sourc it should be posit number throw illeg state except if the method is call more then onc public final void init line number int line number if line number 0 throw new illeg argument except string valu of line number if thi line number 0 throw new illeg state except thi line number line number the column number of the locat of the error or zero if unknown public final int column number return column number initi the column number of the script statement caus the error param column number the column number in the script sourc it should be posit number throw illeg state except if the method is call more then onc public final void init column number int column number if column number 0 throw new illeg argument except string valu of column number if thi column number 0 throw new illeg state except thi column number column number the sourc text of the line caus the error or null if unknown public final string line sourc return line sourc initi the text of the sourc line contain the error param line sourc the text of the sourc line repons for the error it should not be tt null tt throw illeg state except if the method is call more then onc public final void init line sourc string line sourc if line sourc null throw new illeg argument except if thi line sourc null throw new illeg state except thi line sourc line sourc final void record error origin string sourc name int line number string line sourc int column number xxx for compat allow for now 1 to mean 0 if line number 1 line number 0 if sourc name null init sourc name sourc name if line number 0 init line number line number if line sourc null init line sourc line sourc if column number 0 init column number column number privat string gener stack trace get stabl refer to work properli with concurr access char arrai writer writer new char arrai writer super print stack trace new print writer writer string orig stack trace writer to string return interpret get patch stack thi orig stack trace public void print stack trace print writer s if interpret stack info null super print stack trace s els s print gener stack trace public void print stack trace print stream s if interpret stack info null super print stack trace s els s print gener stack trace see context throw as script runtim ex throwabl e public wrap except throwabl except super wrap except to string thi except except kit init caus thi except int linep 0 string sourc name context get sourc posit from stack linep int line number linep 0 if sourc name null init sourc name sourc name if line number 0 init line number line number get the wrap except return the except that wa present as a argument to the constructor when thi object wa creat public throwabl get wrap except return except deprec us link get wrap except instead public object unwrap return get wrap except static void init scriptabl scope boolean seal nativ script obj new nativ script null obj export asj class max prototyp id scope seal privat nativ script script script thi script script return the name of thi java script class script public string get class name return script public object call context cx scriptabl scope scriptabl thi obj object arg if script null return script exec cx scope return undefin instanc public scriptabl construct context cx scriptabl scope object arg throw context report runtim error0 msg script is not constructor public int get length return 0 public int get ariti return 0 string decompil int indent int flag if script instanceof nativ function return nativ function script decompil indent flag return super decompil indent flag protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 0 s to string break case id exec ariti 0 s exec break case id compil ariti 1 s compil break default throw new illeg argument except string valu of id init prototyp method script tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag script tag return super exec id call f cx scope thi obj arg int id f method id switch id case id constructor string sourc arg length 0 script runtim to string arg 0 script script compil cx sourc nativ script nscript new nativ script script script runtim set object proto and parent nscript scope return nscript case id to string nativ script real real thi thi obj f script real script real script if real script null return return cx decompil script real script 0 case id exec throw context report runtim error1 msg cant call indirect exec case id compil nativ script real real thi thi obj f string sourc script runtim to string arg 0 real script compil cx sourc return real throw new illeg argument except string valu of id privat static nativ script real thi scriptabl thi obj id function object f if thi obj instanceof nativ script throw incompat call error f return nativ script thi obj privat static script compil context cx string sourc int linep 0 string filenam context get sourc posit from stack linep if filenam null filenam script object linep 0 1 error report report report default error report for eval cx get error report return cx compil string sourc null report filenam linep 0 null protect int find prototyp id string s int id gener last updat 2001 05 23 13 25 01 gmt 02 00 l0 id 0 string x null l switch s length case 4 x exec id id exec break l case 7 x compil id id compil break l case 8 x to string id id to string break l case 11 x constructor id id constructor break l if x null x s x equal s id 0 gener return id wrap the object p the valu return must be on of ul li java lang boolean li li java lang string li li java lang number li li org mozilla javascript scriptabl object li li the valu return by context get undefin valu li li null li ul param cx the current context for thi thread param scope the scope of the execut script param obj the object to be wrap note it can be null param static type type hint if secur restrict prevent to wrap object base on it class static type will be us instead return the wrap valu public object wrap context cx scriptabl scope object obj class static type if obj null obj undefin instanc obj instanceof scriptabl return obj if static type null static type is primit if static type void type return undefin instanc if static type charact type return new integ int charact obj char valu return obj if is java primit wrap if obj instanceof string obj instanceof number obj instanceof boolean return obj els if obj instanceof charact return string valu of charact obj char valu class cl obj get class if cl is arrai return nativ java arrai wrap scope obj return wrap as java object cx scope obj static type wrap an object newli creat by a constructor call param cx the current context for thi thread param scope the scope of the execut script param obj the object to be wrap return the wrap valu public scriptabl wrap new object context cx scriptabl scope object obj if obj instanceof scriptabl return scriptabl obj class cl obj get class if cl is arrai return nativ java arrai wrap scope obj return wrap as java object cx scope obj null wrap java object as scriptabl instanc to allow full access to it method and field from java script p link wrap context scriptabl object class and link wrap new object context scriptabl object call thi method when thei can not convert tt java object tt to java script primit valu or java script arrai p subclass can overrid the method to provid custom wrapper for java object param cx the current context for thi thread param scope the scope of the execut script param java object the object to be wrap param static type type hint if secur restrict prevent to wrap object base on it class static type will be us instead return the wrap valu which shall not be null public scriptabl wrap as java object context cx scriptabl scope object java object class static type scriptabl wrap wrap new nativ java object scope java object static type return wrap return code fals code if result of java method which is instanc of code string code code number code code boolean code and code charact code should be us directli as java script primit type by default the method return true to indic that instanc of code string code code number code code boolean code and code charact code should be wrap as ani other java object and script can access ani java method avail in these object us link set java primit wrap boolean to chang thi public final boolean is java primit wrap return java primit wrap see is java primit wrap public final void set java primit wrap boolean valu context cx context get current context if cx null cx is seal context on seal mutat java primit wrap valu public static final object instanc new undefin privat undefin public object read resolv return instanc public node transform public final void transform script or fn node tree transform compil unit tree for int i 0 i tree get function count i function node fn tree get function node i transform fn privat void transform compil unit script or fn node tree loop new obj arrai loop end new obj arrai to save against upcheck if no final block ar us ha final fals transform compil unit r tree tree privat void transform compil unit r final script or fn node tree final node parent node node null sibl loop for node previou null if node null node parent get first child els previou node node node get next if node null break int type node get type switch type case token label case token switch case token loop loop push node loop end push node jump node target break case token with loop push node node leav node get next if leav get type token leavewith kit code bug loop end push leav break case token try node jump jump node jump node node finallytarget jump get final if finallytarget null ha final true loop push node loop end push finallytarget break case token target case token leavewith if loop end is empti loop end peek node loop end pop loop pop break case token return if we didn t support try final it wouldn t be necessari to put leavewith node here but as we do need a seri of jsr final node befor each return we need to ensur that each final block get the correct scope which could mean that some leavewith node ar necessari if ha final break skip the whole mess node unwind block null for int i loop size 1 i 0 i node n node loop get i int elemtyp n get type if elemtyp token try elemtyp token with node unwind if elemtyp token try node jump jsrnode new node jump token jsr node jsrtarget node jump n get final jsrnode target jsrtarget unwind jsrnode els unwind new node token leavewith if unwind block null unwind block new node token block node get lineno unwind block add child to back unwind if unwind block null node return node node node return expr return node get first child node replac current parent previou node unwind block if return expr null unwind block add child to back return node els node store new node token expr result return expr unwind block add child to front store return node new node token return result unwind block add child to back return node transform return express transform compil unit r tree store skip transform compil unit r to avoid infinit loop continu sibl loop break case token break case token continu node jump jump node jump node node jump jump statement jump get jump statement if jump statement null kit code bug for int i loop size if i 0 parser ir factori ensur that break continu alwai ha a jump statement associ with it which should be found throw kit code bug i node n node loop get i if n jump statement break int elemtyp n get type if elemtyp token with node leav new node token leavewith previou add befor current parent previou node leav els if elemtyp token try node jump try node node jump n node jump jsr final new node jump token jsr jsr final target try node get final previou add befor current parent previou node jsr final if type token break jump target jump statement target els jump target jump statement get continu jump set type token goto break case token call visit call node tree break case token new visit new node tree break case token var node result new node token block for node cursor node get first child cursor null move cursor to next befor creat assign get chanc to chang n next node n cursor if n get type token name kit code bug cursor cursor get next if n ha children continu node init n get first child n remov child init n set type token bindnam n new node token setnam n init node pop new node token expr void n node get lineno result add child to back pop node replac current parent previou node result break case token name case token setnam case token delprop turn name to var for faster access if possibl if tree get type token function function node tree requir activ break node name sourc if type token name name sourc node els name sourc node get first child if name sourc get type token bindnam if type token delprop break throw kit code bug string name name sourc get string if tree ha param or var name if type token name node set type token getvar els if type token setnam node set type token setvar name sourc set type token string els if type token delprop local variabl ar by definit perman node n new node token fals node replac current parent previou node n els throw kit code bug break transform compil unit r tree node protect void visit new node node script or fn node tree protect void visit call node node script or fn node tree privat static node add befor current node parent node previou node current node to add if previou null if current parent get first child kit code bug parent add child to front to add els if current previou get next kit code bug parent add child after to add previou return to add privat static node replac current node parent node previou node current node replac if previou null if current parent get first child kit code bug parent replac child current replac els if previou next current check cach prev next current is necessari due to possibl tree mutat parent replac child after previou replac els parent replac child current replac return replac privat static final int dtobasestr buffer size 1078 privat static char basedigit int digit return char digit 10 a 10 digit 0 digit privat static int lo0bit int y int k int x y if x 7 0 if x 1 0 return 0 if x 2 0 return 1 return 2 k 0 if x 0xffff 0 k 16 x 16 if x 0xff 0 k 8 x 8 if x 0xf 0 k 4 x 4 if x 0x3 0 k 2 x 2 if x 1 0 k x 1 if x 1 0 return 32 return k return the number 0 through 32 of most signific zero bit in x privat static int hi0bit int x int k 0 if x 0xffff0000 0 k 16 x 16 if x 0xff000000 0 k 8 x 8 if x 0xf0000000 0 k 4 x 4 if x 0xc0000000 0 k 2 x 2 if x 0x80000000 0 k if x 0x40000000 0 return 32 return k privat static void stuff bit byte bit int offset int val bit offset byte val 24 bit offset 1 byte val 16 bit offset 2 byte val 8 bit offset 3 byte val bit in b in bit d must be finit and nonzero privat static big integ d2b doubl d int e int bit byte dbl bit int i k y z de long d bit doubl doubl to long bit d int d0 int d bit 32 int d1 int d bit z d0 frac mask d0 0x7fffffff clear sign bit which we ignor if de int d0 exp shift 0 z exp msk1 if y d1 0 dbl bit new byte 8 k lo0bit y y k if k 0 stuff bit dbl bit 4 y z 32 k z k els stuff bit dbl bit 4 y stuff bit dbl bit 0 z i z 0 2 1 els js assert z dbl bit new byte 4 k lo0bit z z k stuff bit dbl bit 0 z k 32 i 1 if de 0 e 0 de bia p 1 k bit 0 p k els e 0 de bia p 1 1 k bit 0 32 i hi0bit z return new big integ dbl bit static string js dtobasestr int base doubl d if 2 base base 36 throw new illeg argument except bad base base check for infin and nan if doubl is nan d return nan els if doubl is infinit d return d 0 0 infin infin els if d 0 alert should it distinguish 0 0 from 0 0 return 0 boolean neg if d 0 0 neg fals els neg true d d get the integ part of d includ sign string int digit doubl dfloor math floor d long lfloor long dfloor if lfloor dfloor int part fit long int digit long to string neg lfloor lfloor base els big integ should be us long floor bit doubl doubl to long bit dfloor int exp int floor bit exp shiftl exp mask shift long mantissa if exp 0 mantissa floor bit frac maskl 1 els mantissa floor bit frac maskl exp msk1l if neg mantissa mantissa exp 1075 big integ x big integ valu of mantissa if exp 0 x x shift left exp els if exp 0 x x shift right exp int digit x to string base if d dfloor no fraction part return int digit els we have a fraction char buffer the output string int p index to current posit in the buffer int q int digit doubl df the fraction part of d big integ b buffer new char dtobasestr buffer size p 0 df d dfloor long d bit doubl doubl to long bit d int word0 int d bit 32 int word1 int d bit int e new int 1 int bbit new int 1 b d2b df e bbit js assert e 0 at thi point df b 2 e e must be less than zero becaus 0 df 1 int s2 word0 exp shift1 exp mask exp shift1 if s2 0 s2 1 s2 bia p 1 2 s2 next doubl d d 2 js assert s2 e big integ mlo big integ valu of 1 big integ mhi mlo if word1 0 word0 bndry mask 0 word0 exp mask exp mask 1 0 the special case here we want to be within a quarter of the last input signific digit instead of on half of it when the output string s valu is less than d s2 log2p mhi big integ valu of 1 log2p b b shift left e 0 s2 big integ s big integ valu of 1 s s shift left s2 at thi point we have the follow s 2 s2 1 df b 2 s2 0 d prev doubl d 2 mlo 2 s2 next doubl d d 2 mhi 2 s2 big integ big base big integ valu of base boolean done fals do b b multipli big base big integ div result b divid and remaind s b div result 1 digit char div result 0 int valu if mlo mhi mlo mhi mlo multipli big base els mlo mlo multipli big base mhi mhi multipli big base do we yet have the shortest string that will round to d int j b compar to mlo j is b 2 s2 compar with mlo 2 s2 big integ delta s subtract mhi int j1 delta signum 0 1 b compar to delta j1 is b 2 s2 compar with 1 mhi 2 s2 if j1 0 word1 1 0 if j 0 digit done true els if j 0 j 0 word1 1 0 if j1 0 either dig or dig 1 would work here as the least signific digit us whichev would produc an output valu closer to d b b shift left 1 j1 b compar to s if j1 0 the even test j1 0 digit 1 is not here becaus it mess up odd base output such as 3 5 in base 3 digit done true els if j1 0 digit done true js assert digit uint32 base buffer p basedigit digit while done string buffer sb new string buffer int digit length 1 p sb append int digit sb append sb append buffer 0 p return sb to string static int word0 doubl d long d bit doubl doubl to long bit d return int d bit 32 static doubl set word0 doubl d int i long d bit doubl doubl to long bit d d bit long i 32 d bit 0x0ffffffffl return doubl long bit to doubl d bit static int word1 doubl d long d bit doubl doubl to long bit d return int d bit return b 5 k k must be nonneg xxxx the c version built a cach of these static big integ pow5mult big integ b int k return b multipli big integ valu of 5 pow k static boolean round off string buffer buf int i buf length while i 0 i char c buf char at i if c 9 buf set char at i char c 1 buf set length i 1 return fals buf set length 0 return true bufsiz should be two greater than the maximum number of output charact expect static int js dtoa doubl d int mode boolean bia up int ndigit boolean sign string buffer buf argument ndigit decpt sign ar similar to those of ecvt and fcvt trail zero ar suppress from the return string if not null rve is set to point to the end of the return valu if d is infin or nan then decpt is set to 9999 mode 0 shortest string that yield d when read in and round to nearest 1 like 0 but with steel white stop rule e g with ieee p754 arithmet mode 0 give 1e23 wherea mode 1 give 9 999999999999999e22 2 max 1 ndigit signific digit thi give a return valu similar to that of ecvt except that trail zero ar suppress 3 through ndigit past the decim point thi give a return valu similar to that from fcvt except that trail zero ar suppress and ndigit can be neg 4 9 should give the same return valu as 2 3 i e 4 mode 9 same return as mode 2 mode 1 these mode ar mainli for debug often thei run slower but sometim faster than mode 2 3 4 5 8 9 left to right digit gener 6 9 don t try fast float point estim if applic valu of mode other than 0 9 ar treat as mode 0 suffici space is alloc to the return valu to hold the suppress trail zero int b2 b5 i iep ilim ilim0 ilim1 j j1 k k0 m2 m5 s2 s5 char dig long l long x big integ b b1 delta mlo mhi s int be new int 1 int bbit new int 1 doubl d2 ds ep boolean spec case denorm k check try quick leftright if word0 d sign bit 0 set sign for everyth includ 0 s and na ns sign 0 true word0 d sign bit clear sign bit d set word0 d word0 d sign bit els sign 0 fals if word0 d exp mask exp mask infin or nan buf append word1 d 0 word0 d frac mask 0 infin nan return 9999 if d 0 no digit buf set length 0 buf append 0 copi 0 to buffer return 1 b d2b d be bbit if i int word0 d exp shift1 exp mask exp shift1 0 d2 set word0 d word0 d frac mask1 exp 11 log x log 1 5 x 1 5 1 5 log10 x log x log 10 log 1 5 log 10 x 1 5 1 5 log 10 log10 d i bia log 2 log 10 log10 d2 thi suggest comput an approxim k to log10 d by k i bia 0 301029995663981 d2 1 5 0 289529654602168 0 176091259055681 we want k to be too larg rather than too small the error in the first order taylor seri approxim is in our favor so we just round up the constant enough to compens for ani error in the multipl of i bia by 0 301029995663981 sinc i bia 1077 and 1077 0 30103 2 52 7 2e 14 ad 1e 13 to the constant term more than suffic henc we adjust the constant term to 0 1760912590558 we could get a more accur k by invok log10 but thi is probabl not worthwhil i bia denorm fals els d is denorm i bbit 0 be 0 bia p 1 1 x i 32 word0 d 64 i word1 d i 32 word1 d 32 i d2 x word0 d2 31 exp msk1 adjust expon d2 set word0 x word0 x 31 exp msk1 i bia p 1 1 1 denorm true at thi point d f 2 i where 1 f 2 d2 is an approxim of f ds d2 1 5 0 289529654602168 0 1760912590558 i 0 301029995663981 k int ds if ds 0 0 ds k k want k floor ds k check true if k 0 k ten pmax if d ten k k k check fals at thi point floor log10 d k floor log10 d 1 if k check is zero we re guarante that k floor log10 d j bbit 0 i 1 at thi point d b 2 j where b is an odd integ if j 0 b2 0 s2 j els b2 j s2 0 if k 0 b5 0 s5 k s2 k els b2 k b5 k s5 0 at thi point d 10 k b 2 b2 5 b5 2 s2 5 s5 where b is an odd integ b2 0 b5 0 s2 0 and s5 0 if mode 0 mode 9 mode 0 try quick true if mode 5 mode 4 try quick fals leftright true ilim ilim1 0 switch mode case 0 case 1 ilim ilim1 1 i 18 ndigit 0 break case 2 leftright fals no break case 4 if ndigit 0 ndigit 1 ilim ilim1 i ndigit break case 3 leftright fals no break case 5 i ndigit k 1 ilim i ilim1 i 1 if i 0 i 1 ilim is the maximum number of signific digit we want base on k and ndigit ilim1 is the maximum number of signific digit we want base on k and ndigit when it turn out that k wa comput too high by on boolean fast fail fals if ilim 0 ilim quick max try quick try to get by with float point arithmet i 0 d2 d k0 k ilim0 ilim iep 2 conserv divid d by 10 k keep track of the roundoff error and avoid overflow if k 0 ds ten k 0xf j k 4 if j bletch 0 prevent overflow j bletch 1 d bigten n bigten 1 iep for j 0 j 1 i if j 1 0 iep ds bigten i d ds els if j1 k 0 d ten j1 0xf for j j1 4 j 0 j 1 i if j 1 0 iep d bigten i check that k wa comput correctli if k check d 1 0 ilim 0 if ilim1 0 fast fail true els ilim ilim1 k d 10 iep ep bound the cumul error ep iep d 7 0 word0 ep p 1 exp msk1 ep iep d 7 0 ep set word0 ep word0 ep p 1 exp msk1 if ilim 0 s mhi null d 5 0 if d ep buf append 1 k return k 1 if d ep buf set length 0 buf append 0 copi 0 to buffer return 1 fast fail true if fast fail fast fail true if leftright us steel white method of onli gener digit need ep 0 5 ten ilim 1 ep for i 0 l long d d l buf append char 0 l if d ep return k 1 if 1 0 d ep goto bump up char last ch while true last ch buf char at buf length 1 privat static void strip trail zero string buffer buf while s 0 s int bl buf length while bl 0 buf char at bl 0 buf set length bl 1 static void js dtostr string buffer buffer int mode int precis doubl d int dec pt posit of decim point rel to first digit return by js dtoa boolean sign new boolean 1 true if the sign bit wa set in d int n digit number of significand digit return by js dtoa js assert buffer size size t mode dtostr standard exponenti dtostr standard buffer size dtostr variabl buffer size precis if mode dtostr fix d 1e21 d 1e21 mode dtostr standard chang mode here rather than below becaus the buffer mai not be larg enough to hold a larg integ dec pt js dtoa d dtoa mode mode mode dtostr fix precis sign buffer n digit buffer length if infin infin or nan return the string regardless of the mode if dec pt 9999 boolean exponenti notat fals int minn digit 0 minimum number of significand digit requir by mode and precis int p int q switch mode case dtostr standard if dec pt 5 dec pt 21 exponenti notat true els minn digit dec pt break case dtostr fix if precis 0 minn digit dec pt precis els minn digit dec pt break case dtostr exponenti js assert precis 0 minn digit precis fall through case dtostr standard exponenti exponenti notat true break case dtostr precis js assert precis 0 minn digit precis if dec pt 5 dec pt precis exponenti notat true break if the number ha fewer than minn digit pad it with zero at the end if n digit minn digit p minn digit n digit minn digit do buffer append 0 while buffer length p if exponenti notat insert a decim point if more than on significand digit if n digit 1 buffer insert 1 buffer append e if dec pt 1 0 buffer append buffer append dec pt 1 js snprintf num end buffer size num end buffer e d dec pt 1 els if dec pt n digit some kind of a fraction in fix notat js assert dec pt n digit if dec pt 0 dd dd dd dd buffer insert dec pt els 0 00 00dd dd for int i 0 i 1 dec pt i buffer insert 0 0 buffer insert 1 if neg and neither 0 0 nor nan output a lead if sign 0 word0 d sign bit word1 d 0 word0 d exp mask exp mask word1 d 0 word0 d frac mask 0 buffer insert 0 public id function object id function call idcal object tag int id int ariti if ariti 0 throw new illeg argument except thi idcal idcal thi tag tag thi method id id thi ariti ariti if ariti 0 throw new illeg argument except public id function object id function call idcal object tag int id string name int ariti scriptabl scope super scope null if ariti 0 throw new illeg argument except if name null throw new illeg argument except thi idcal idcal thi tag tag thi method id id thi ariti ariti thi function name name public void init function string name scriptabl scope if name null throw new illeg argument except if scope null throw new illeg argument except thi function name name set parent scope scope public final boolean ha tag object tag return thi tag tag public final int method id return method id public final void mark as constructor scriptabl prototyp properti us call as constructor true set immun prototyp properti prototyp properti public final void add as properti scriptabl target scriptabl object defin properti target function name thi scriptabl object dontenum public void export as scope properti add as properti get parent scope public scriptabl get prototyp lazi initi of prototyp for nativ function thi mai not be call at all scriptabl proto super get prototyp if proto null proto get function prototyp get parent scope set prototyp proto return proto public object call context cx scriptabl scope scriptabl thi obj object arg return idcal exec id call thi cx scope thi obj arg public scriptabl creat object context cx scriptabl scope if us call as constructor return null throw error if not explicitli code to be us as constructor to satisfi ecma script standard see bugzilla 202019 to follow current 2003 05 01 spider monkei behavior chang it to return super creat object cx scope throw script runtim type error1 msg not ctor function name string decompil int indent int flag string buffer sb new string buffer boolean justbodi 0 flag decompil onli bodi flag if justbodi sb append function sb append get function name sb append sb append nativ code for if idcal instanceof scriptabl scriptabl sobj scriptabl idcal sb append sobj get class name sb append sb append get function name sb append ariti sb append get ariti sb append justbodi n n return sb to string public int get ariti return ariti public int get length return get ariti public int get length return get ariti public string get function name return function name null function name public final runtim except unknown it is program error to call id like method for unknown function return new illeg argument except bad function id method id master idcal static void init scriptabl scope boolean seal nativ object obj new nativ object obj export asj class max prototyp id scope seal public string get class name return object public string to string return script runtim default object to string thi protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 0 s to string break case id to local string ariti 0 s to local string break case id valu of ariti 0 s valu of break case id ha own properti ariti 1 s ha own properti break case id properti is enumer ariti 1 s properti is enumer break case id is prototyp of ariti 1 s is prototyp of break case id to sourc ariti 0 s to sourc break default throw new illeg argument except string valu of id init prototyp method object tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag object tag return super exec id call f cx scope thi obj arg int id f method id switch id case id constructor if thi obj null base function construct will set up parent proto return f construct cx scope arg if arg length 0 arg 0 null arg 0 undefin instanc return new nativ object return script runtim to object cx scope arg 0 case id to local string for now just alia to string case id to string if cx ha featur context featur to string as sourc string s script runtim default object to sourc cx scope thi obj arg int l s length if l 0 s char at 0 s char at l 1 strip that surround to sourc s s substr 1 l 1 return s return script runtim default object to string thi obj case id valu of return thi obj case id ha own properti boolean result if arg length 0 result fals els string s script runtim to string id or index cx arg 0 if s null int index script runtim last index result cx result thi obj ha index thi obj els result thi obj ha s thi obj return script runtim wrap boolean result case id properti is enumer boolean result if arg length 0 result fals els string s script runtim to string id or index cx arg 0 if s null int index script runtim last index result cx result thi obj ha index thi obj if result thi obj instanceof scriptabl object scriptabl object so scriptabl object thi obj int attr so get attribut index result attr scriptabl object dontenum 0 els result thi obj ha s thi obj if result thi obj instanceof scriptabl object scriptabl object so scriptabl object thi obj int attr so get attribut s result attr scriptabl object dontenum 0 return script runtim wrap boolean result case id is prototyp of boolean result fals if arg length 0 arg 0 instanceof scriptabl scriptabl v scriptabl arg 0 do v v get prototyp if v thi obj result true break while v null return script runtim wrap boolean result case id to sourc return script runtim default object to sourc cx scope thi obj arg default throw new illeg argument except string valu of id protect int find prototyp id string s int id gener last updat 2003 11 11 01 51 40 cet l0 id 0 string x null int c l switch s length case 7 x valu of id id valu of break l case 8 c s char at 3 if c o x to sourc id id to sourc els if c t x to string id id to string break l case 11 x constructor id id constructor break l case 13 x is prototyp of id id is prototyp of break l case 14 c s char at 0 if c h x ha own properti id id ha own properti els if c t x to local string id id to local string break l case 20 x properti is enumer id id properti is enumer break l if x null x s x equal s id 0 gener return id nativ java top packag class loader loader super true loader public object call context cx scriptabl scope scriptabl thi obj object arg return construct cx scope arg public scriptabl construct context cx scriptabl scope object arg class loader loader null if arg length 0 object arg arg 0 if arg instanceof wrapper arg wrapper arg unwrap if arg instanceof class loader loader class loader arg if loader null context report runtim error0 msg not classload return null return new nativ java packag true loader public static void init context cx scriptabl scope boolean seal class loader loader cx get applic class loader final nativ java top packag top new nativ java top packag loader top set prototyp get object prototyp scope top set parent scope scope string name kit semicolon split common packag for int i 0 i name length i top forc packag name i scope get class implement id function object get class new id function object top ftag id get class get class 1 scope we want to get a real alia and not a distinct java packag with the same packag name so that we share class and top that ar underneath nativ java packag java alia nativ java packag top get java top it s safe to downcast here sinc init standard object take a scriptabl object scriptabl object global scriptabl object scope if seal get class seal object get class export as scope properti global defin properti packag top scriptabl object dontenum global defin properti java java alia scriptabl object dontenum public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag ftag if f method id id get class return js get class cx scope arg throw f unknown privat scriptabl js get class context cx scriptabl scope object arg if arg length 0 arg 0 instanceof wrapper scriptabl result thi class cl wrapper arg 0 unwrap get class evalu the class name by get success properti of the string to find the appropri nativ java class object string name cl get name int offset 0 for int index name index of offset string prop name index 1 name substr offset name substr offset index object prop result get prop name result if prop instanceof scriptabl break fall through to error result scriptabl prop if index 1 return result offset index 1 throw context report runtim error0 msg not java obj privat protect domain domain loader class loader parent protect domain domain super parent null parent get system class loader thi domain domain public class defin class string name byte data return super defin class name data 0 data length domain public void link class class cl resolv class cl the moment of constructor invoc context permiss protect domain static domain context access control get context if static domain null stati permiss static domain get permiss set read onli public void add permiss permiss throw new runtim except not implement public boolean impli permiss permiss if stati permiss null if stati permiss impli permiss return fals try context check permiss permiss return true catch access control except ex return fals public enumer element return new enumer public boolean ha more element return fals public object next element return null return new enumer public boolean ha more element return fals return new enumer public boolean ha more element return fals public object next element return null public string to string string buffer sb new string buffer sb append get class get name sb append sb append integ to hex string system ident hash code thi sb append context sb append context sb append static permit sb append stati permiss sb append return sb to string public java polici secur to trigger error on jdk 1 1 with lazi load new code sourc null java secur cert certif null protect void call process file secur final context cx final scriptabl scope final string filenam access control do privileg new privileg action public object run url url get url obj filenam protect domain static domain get url domain url main process file secur cx scope url to extern form static domain return null access control do privileg new privileg action public object run url url get url obj filenam protect domain static domain get url domain url main process file secur cx scope url to extern form static domain return null privat url get url obj string url url url obj try url obj new url url catch malformedurl except ex assum as main process file secur it is file need to build it url string cur dir system get properti user dir cur dir cur dir replac if cur dir end with cur dir cur dir try url cur dirurl new url file cur dir url obj new url cur dirurl url catch malformedurl except ex2 throw new runtim except can not construct file url for url ex2 get messag return url obj privat protect domain get url domain url url code sourc cs cs new code sourc url java secur cert certif null permiss collect pc polici get polici get permiss cs return new protect domain cs pc public gener class loader creat class loader class loader parent loader object secur domain protect domain domain protect domain secur domain return new loader parent loader domain public object get dynam secur domain object secur domain protect domain static domain protect domain secur domain return get dynam domain static domain privat protect domain get dynam domain protect domain static domain context permiss p new context permiss static domain protect domain context domain new protect domain null p return context domain public object call with domain object secur domain final context cx final callabl callabl final scriptabl scope final scriptabl thi obj final object arg protect domain static domain protect domain secur domain there is no direct wai in java to intersect permit accord stack context with addit domain the follow implement first construct protect domain that allow action onli allow by both static domain and current stack context and then construct access control for thi dynam domain if thi is too slow altern solut would be to gener class per domain with a proxi method to call to infect java stack anoth optim in case of script come from world domain that is have minim default privileg is to construct on access control context base on protect domain with least possibl privileg and simpli call access control do privileg with thi untrust context protect domain dynam domain get dynam domain static domain protect domain tmp dynam domain access control context restrict new access control context tmp privileg action action new privileg action public object run return callabl call cx scope thi obj arg return access control do privileg action restrict privileg action action new privileg action public object run return callabl call cx scope thi obj arg static void init scriptabl scope boolean seal nativ error obj new nativ error scriptabl object put properti obj name error scriptabl object put properti obj messag scriptabl object put properti obj file name scriptabl object put properti obj line number new integ 0 obj export asj class max prototyp id scope seal static nativ error make context cx scriptabl scope id function object ctor obj object arg scriptabl proto scriptabl ctor obj get prototyp ctor obj nativ error obj new nativ error obj set prototyp proto obj set parent scope scope if arg length 1 scriptabl object put properti obj messag script runtim to string arg 0 if arg length 2 scriptabl object put properti obj file name arg 1 if arg length 3 int line script runtim to int32 arg 2 scriptabl object put properti obj line number new integ line return obj public string get class name return error public string to string return js to string thi protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 0 s to string break case id to sourc ariti 0 s to sourc break default throw new illeg argument except string valu of id init prototyp method error tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag error tag return super exec id call f cx scope thi obj arg int id f method id switch id case id constructor return make cx scope f arg case id to string return js to string thi obj case id to sourc return js to sourc cx scope thi obj throw new illeg argument except string valu of id privat static string js to string scriptabl thi obj return get string thi obj name get string thi obj messag privat static string js to sourc context cx scriptabl scope scriptabl thi obj emul of spider monkei behavior object name scriptabl object get properti thi obj name object messag scriptabl object get properti thi obj messag object file name scriptabl object get properti thi obj file name object line number scriptabl object get properti thi obj line number string buffer sb new string buffer sb append new if name not found name undefin instanc sb append script runtim to string name sb append if messag not found file name not found line number not found if messag not found messag sb append script runtim unev cx scope messag if file name not found line number not found sb append if file name not found file name sb append script runtim unev cx scope file name if line number not found int line script runtim to int32 line number if line 0 sb append sb append script runtim to string line sb append return sb to string privat static string get string scriptabl obj string id object valu scriptabl object get properti obj id if valu not found return return script runtim to string valu protect int find prototyp id string s int id string id map gener last updat 2004 03 17 13 35 15 cet l0 id 0 string x null int c int s length s length if s length 8 c s char at 3 if c o x to sourc id id to sourc els if c t x to string id id to string els if s length 11 x constructor id id constructor if x null x s x equal s id 0 gener return id privat error report chain report privat default error report static error report for eval error report report default error report r new default error report r for eval true r chain report report return r public void warn string messag string sourceuri int line string line text int line offset if chain report null chain report warn messag sourceuri line line text line offset els do noth public void error string messag string sourceuri int line string line text int line offset if for eval throw script runtim construct error syntax error messag sourceuri line line text line offset if chain report null chain report error messag sourceuri line line text line offset els throw runtim error messag sourceuri line line text line offset public evalu except runtim error string messag string sourceuri int line string line text int line offset if chain report null return chain report runtim error messag sourceuri line line text line offset els return new evalu except messag sourceuri line line text line offset public abstract class xml object extend id scriptabl object public xml object public xml object scriptabl scope scriptabl prototyp super scope prototyp implement of ecma script ha public abstract boolean ecma ha context cx object id public abstract boolean ecma ha context cx object id implement of ecma script get public abstract object ecma get context cx object id public abstract object ecma get context cx object id implement of ecma script put public abstract void ecma put context cx object id object valu public abstract void ecma put context cx object id object valu implement of ecma script delet public abstract boolean ecma delet context cx object id return an addit object to look for method that runtim should consid dure method search return null if no such object avail gener refer to implement x y x y etc public abstract ref member ref context cx object elem gener refer to implement x ns x ns y x ns y etc public abstract ref member ref context cx object namespac object elem int member type flag wrap thi object into nativ with to implement the with statement public abstract nativ with enter with scriptabl scope public abstract nativ with enter with scriptabl scope wrap thi object into nativ with to implement the queri public abstract nativ with enter dot queri scriptabl scope custom tt tt oper should return link scriptabl not found if thi object doe not have custom addit oper for the given valu or the result of the addit oper p the default implement return link scriptabl not found to indic no custom addit oper param cx the context object associ with the current thread param thi is left if true the object should calcul thi valu if fals the object should calcul valu thi param valu the second argument for addit oper public object add valu context cx boolean thi is left object valu return scriptabl not found creat an except with the specifi detail messag error intern to the java script engin will simpli throw a runtim except param sourc name the name of the sourc repons for the error param line number the line number of the sourc param column number the column number of the sourc mai be zero if unknown param line sourc the sourc of the line contain the error mai be null if unknown ecma error string error name string error messag string sourc name int line number string line sourc int column number record error origin sourc name line number line sourc column number thi error name error name thi error messag error messag deprec ecma error error instanc should not be construct explicitli sinc thei ar gener by the engin public ecma error scriptabl nativ error string sourc name int line number int column number string line sourc thi intern error script runtim to string nativ error sourc name line number line sourc column number public string detail return error name error messag get the name of the error ecma edit 3 defin the follow error eval error rang error refer error syntax error type error and uri error addit error name mai be ad in the futur see ecma edit 3 15 11 7 9 return the name of the error public string get name return error name get the messag correspond to the error see ecma edit 3 15 11 7 10 return an implemen defin string describ the error public string get error messag return error messag deprec us link rhino except sourc name from the super class public string get sourc name return sourc name deprec us link rhino except line number from the super class public int get line number return line number deprec us link rhino except column number from the super class public int get column number return column number deprec us link rhino except line sourc from the super class public string get line sourc return line sourc deprec alwai return b null b public scriptabl get error object return null public abstract class ref implement serializ public boolean ha context cx return true public abstract object get context cx public abstract object get context cx public abstract object set context cx object valu public abstract object set context cx object valu public boolean delet context cx return fals public static void init context cx scriptabl scope boolean seal nativ global obj new nativ global for int id 1 id last scope function id id string name int ariti 1 switch id case id decodeuri name decodeuri break case id decodeuri compon name decodeuri compon break case id encodeuri name encodeuri break case id encodeuri compon name encodeuri compon break case id escap name escap break case id eval name eval break case id is finit name is finit break case id is nan name is nan break case id isxml name name isxml name break case id pars float name pars float break case id pars int name pars int ariti 2 break case id unescap name unescap break case id unev name unev break default throw kit code bug id function object f new id function object obj ftag id name ariti scope if seal f seal object f export as scope properti scriptabl object defin properti scope nan script runtim na nobj scriptabl object dontenum scriptabl object defin properti scope infin script runtim wrap number doubl posit infin scriptabl object dontenum scriptabl object defin properti scope undefin undefin instanc scriptabl object dontenum string error method kit semicolon split convers error eval error rang error refer error syntax error type error uri error intern error java except each error constructor get it own error object as a prototyp with the name properti set to the name of the error for int i 0 i error method length i string name error method i scriptabl error proto script runtim new object cx scope error script runtim empti arg error proto put name error proto name if seal if error proto instanceof scriptabl object scriptabl object error proto seal object id function object ctor new id function object obj ftag id new common error name 1 scope ctor mark as constructor error proto if seal ctor seal object ctor export as scope properti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag ftag int method id f method id switch method id case id decodeuri case id decodeuri compon string str script runtim to string arg 0 return decod str method id id decodeuri case id encodeuri case id encodeuri compon string str script runtim to string arg 0 return encod str method id id encodeuri case id escap return js escap arg case id eval return js eval cx scope arg case id is finit boolean result if arg length 1 result fals els doubl d script runtim to number arg 0 result d d d doubl posit infin d doubl neg infin return script runtim wrap boolean result case id is nan the global method is nan as per ecma 262 15 1 2 6 boolean result if arg length 1 result true els doubl d script runtim to number arg 0 result d d return script runtim wrap boolean result case id isxml name object name arg length 0 undefin instanc arg 0 xml lib xml lib xml lib extract from scope scope return script runtim wrap boolean xml lib isxml name cx name case id pars float return js pars float arg case id pars int return js pars int arg case id unescap return js unescap arg case id unev object valu arg length 0 arg 0 undefin instanc return script runtim unev cx scope valu case id new common error the implement of all the ecma error constructor syntax error type error etc return nativ error make cx scope f arg throw f unknown the global method pars int as per ecma 262 15 1 2 2 privat object js pars int object arg string s script runtim to string arg 0 int radix script runtim to int32 arg 1 int len s length if len 0 return script runtim na nobj boolean neg fals int start 0 char c do c s char at start if charact is whitespac c break start while start len if c neg c start final int no radix 1 if radix 0 radix no radix els if radix 2 radix 36 return script runtim na nobj els if radix 16 len start 1 s char at start 0 c s char at start 1 if c x c x start 2 if radix no radix radix 10 if len start 1 s char at start 0 c s char at start 1 if c x c x radix 16 start 2 els if 0 c c 9 radix 8 start doubl d script runtim string to number s start radix return script runtim wrap number neg d d the global method pars float as per ecma 262 15 1 2 3 param cx unus param thi obj unus param arg the argument to pars float ignor arg 1 param fun obj unus privat object js pars float object arg if arg length 1 return script runtim na nobj string s script runtim to string arg 0 int len s length int start 0 scan forward to skip whitespac char c for if start len return script runtim na nobj c s char at start if token stream isj space c break start int i start if c c i if i len return script runtim na nobj c s char at i if c i check for infin if i 8 len s region match i infin 0 8 doubl d if s char at start d doubl neg infin els d doubl posit infin return script runtim wrap number d return script runtim na nobj find the end of the legal bit int decim 1 int expon 1 for i len i switch s char at i case if decim 1 onli allow a singl decim point break decim i continu case e case e if expon 1 break expon i continu case case onli allow or after e or e if expon i 1 break continu case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 continu default break break s s substr start i try return doubl valu of s catch number format except ex return script runtim na nobj the global method escap as per ecma 262 15 1 2 4 includ code for the mask argument support by the c escap method which us to be part of the browser imbed blame for the strang constant name should be direct there privat object js escap object arg final int url xalpha 1 url xpalpha 2 url path 4 string s script runtim to string arg 0 int mask url xalpha url xpalpha url path if arg length 1 the mask argument non ecma doubl d script runtim to number arg 1 if d d mask int d d 0 mask url xalpha url xpalpha url path throw context report runtim error0 msg bad esc mask string buffer sb null for int k 0 l s length k l k int c s char at k if mask 0 c 0 c 9 c a c z c a c z c c c c c 0 mask url path c c if sb null sb append char c els if sb null sb new string buffer l 3 sb append s sb set length k int hex size if c 256 if c mask url xpalpha sb append continu sb append hex size 2 els sb append sb append u hex size 4 append hexadecim form of c left pad with 0 for int shift hex size 1 4 shift 0 shift 4 int digit 0xf c shift int hc digit 10 0 digit a 10 digit sb append char hc return sb null s sb to string the global unescap method as per ecma 262 15 1 2 5 privat object js unescap object arg string s script runtim to string arg 0 int first escap po s index of if first escap po 0 int l s length char buf s to char arrai int destin first escap po for int k first escap po k l char c buf k k if c k l int end start if buf k u start k 1 end k 5 els start k end k 2 if end l int x 0 for int i start i end i x kit x digit to int buf i x if x 0 c char x k end buf destin c destin s new string buf 0 destin return s privat object js eval context cx scriptabl scope object arg string m script runtim get messag1 msg cant call indirect eval throw nativ global construct error cx eval error m scope static boolean is eval function object function obj if function obj instanceof id function object id function object function id function object function obj if function ha tag ftag function method id id eval return true return fals deprec us link script runtim construct error string string instead public static ecma error construct error context cx string error string messag scriptabl scope return script runtim construct error error messag deprec us link script runtim construct error string string string int int string instead public static ecma error construct error context cx string error string messag scriptabl scope string sourc name int line number int column number string line sourc return script runtim construct error error messag sourc name line number line sourc column number privat static string encod string str boolean full uri byte utf8buf null string buffer sb null for int k 0 length str length k length k char c str char at k if encod unescap c full uri if sb null sb append c els if sb null sb new string buffer length 3 sb append str sb set length k utf8buf new byte 6 if 0xdc00 c c 0xdfff throw context report runtim error0 msg bad uri int v if c 0xd800 0xdbff c v c els k if k length throw context report runtim error0 msg bad uri char c2 str char at k if 0xdc00 c2 c2 0xdfff throw context report runtim error0 msg bad uri v c 0xd800 10 c2 0xdc00 0x10000 int l on uc4 to utf8 char utf8buf v for int j 0 j l j int d 0xff utf8buf j sb append sb append to hex char d 4 sb append to hex char d 0xf return sb null str sb to string privat static char to hex char int i if i 4 0 kit code bug return char i 10 i 0 i 10 a privat static int un hex char c if a c c f return c a 10 els if a c c f return c a 10 els if 0 c c 9 return c 0 els return 1 privat static int un hex char c1 char c2 int i1 un hex c1 int i2 un hex c2 if i1 0 i2 0 return i1 4 i2 return 1 privat static string decod string str boolean full uri char buf null int buf top 0 for int k 0 length str length k length char c str char at k if c if buf null buf buf top c k els if buf null decod alwai compress so result can not be bigger then str length buf new char length str get char 0 k buf 0 buf top k int start k if k 3 length throw context report runtim error0 msg bad uri int b un hex str char at k 1 str char at k 2 if b 0 throw context report runtim error0 msg bad uri k 3 if b 0x80 0 c char b els decod utf 8 sequenc into uc4 char and encod it into utf 16 int utf8 tail uc4 char min uc4 char if b 0xc0 0x80 first utf 8 should be ousid 0x80 0xbf throw context report runtim error0 msg bad uri els if b 0x20 0 utf8 tail 1 uc4 char b 0x1f min uc4 char 0x80 els if b 0x10 0 utf8 tail 2 uc4 char b 0x0f min uc4 char 0x800 els if b 0x08 0 utf8 tail 3 uc4 char b 0x07 min uc4 char 0x10000 els if b 0x04 0 utf8 tail 4 uc4 char b 0x03 min uc4 char 0x200000 els if b 0x02 0 utf8 tail 5 uc4 char b 0x01 min uc4 char 0x4000000 els first utf 8 can not be 0xff or 0xfe throw context report runtim error0 msg bad uri if k 3 utf8 tail length throw context report runtim error0 msg bad uri for int j 0 j utf8 tail j if str char at k throw context report runtim error0 msg bad uri b un hex str char at k 1 str char at k 2 if b 0 b 0xc0 0x80 throw context report runtim error0 msg bad uri uc4 char uc4 char 6 b 0x3f k 3 check for overlong and other should not present code if uc4 char min uc4 char uc4 char 0xfffe uc4 char 0xffff uc4 char 0xfffd if uc4 char 0x10000 uc4 char 0x10000 if uc4 char 0xfffff throw context report runtim error0 msg bad uri char h char uc4 char 10 0xd800 c char uc4 char 0x3ff 0xdc00 buf buf top h els c char uc4 char if full uri uri decod reserv index of c 0 for int x start x k x buf buf top str char at x els buf buf top c return buf null str new string buf 0 buf top privat static boolean encod unescap char c boolean full uri if a c c z a c c z 0 c c 9 return true if index of c 0 return true if full uri return uri decod reserv index of c 0 return fals privat static int on uc4 to utf8 char byte utf8 buffer int uc4 char int utf8 length 1 js assert uc4 char 0x7fffffff if uc4 char 0x7f 0 utf8 buffer 0 byte uc4 char els int i int a uc4 char 11 utf8 length 2 while a 0 a 5 utf8 length i utf8 length while i 0 utf8 buffer i byte uc4 char 0x3f 0x80 uc4 char 6 utf8 buffer 0 byte 0x100 1 8 utf8 length uc4 char return utf8 length public interfac listen notifi about newli creat link context object public void context creat context cx notifi that the specifi link context instanc is no longer associ with the current thread get global context factori see ha explicit global see init global context factori public static context factori get global return global check if global factori wa set return true to indic that link init global context factori wa alreadi call and fals to indic that the global factori wa not explicitli set see get global see init global context factori public static boolean ha explicit global return ha custom global set global context factori the method can onli be call onc see get global see ha explicit global public static void init global context factori factori if factori null throw new illeg argument except if ha custom global throw new illeg state except ha custom global true global factori creat new link context instanc to be associ with the current thread thi is a callback method us by rhino to creat link context instanc when it is necessari to associ on with the current execut thread tt make context tt is allow to call link context seal object on the result to prevent link context chang by hostil script or applet protect context make context return new context implement of link context ha featur int featur index thi can be us to custom link context without introduc addit subclass protect boolean ha featur context cx int featur index int version switch featur index case context featur non ecma get year dure the great date rewrit of 1 3 we tri to track the evolv ecma standard which then had a definit of get year which alwai subtract 1900 which we implement not realiz that it wa incompat with the old behavior now rather than thrash the behavior yet again we ve decid to leav it with the 1900 behavior and point peopl to the get full year method but we try to protect exist script that have specifi a version version cx get languag version return version context version 1 0 version context version 1 1 version context version 1 2 case context featur member expr as function name return fals case context featur reserv keyword as identifi return fals case context featur to string as sourc version cx get languag version return version context version 1 2 case context featur parent proto proprti return true case context featur e4x version cx get languag version return version context version default version context version 1 6 case context featur dynam scope return fals case context featur strict var return fals case context featur strict eval return fals it is a bug to call the method with unknown featur index throw new illeg argument except string valu of featur index creat class loader for gener class thi method creat an instanc of the default implement of link gener class loader rhino us thi interfac to load gener jvm class when no link secur control is instal applic can overrid the method to provid custom class load protect gener class loader creat class loader class loader parent return new defin class loader parent get class loader to us when search for java class unless it wa explicitli initi with link init applic class loader class loader the method return null to indic that thread get context class loader should be us public final class loader get applic class loader return applic class loader set explicit class loader to us when search for java class see get applic class loader public final void init applic class loader class loader loader if loader null throw new illeg argument except loader is null if kit test if can load rhino class loader throw new illeg argument except loader can not resolv rhino class if thi applic class loader null throw new illeg state except applic class loader can onli be set onc check not seal thi applic class loader loader execut top call to script or function when the runtim is about to execut a script or function that will creat the first stack frame with scriptabl code it call thi method to perform the real call in thi wai execut of ani script happen insid thi function protect object do top call callabl callabl context cx scriptabl scope scriptabl thi obj object arg return callabl call cx scope thi obj arg implement of link context observ instruct count int instruct count thi can be us to custom link context without introduc addit subclass protect void observ instruct count context cx int instruct count protect void on context creat context cx object listen thi listen for int i 0 i listen l listen kit get listen listen i if l null break l context creat cx protect void on context releas context cx object listen thi listen for int i 0 i listen l listen kit get listen listen i if l null break l context releas cx public final void add listen listen listen check not seal synchron listen lock if disabl listen throw new illeg state except listen kit add listen listen listen public final void remov listen listen listen check not seal synchron listen lock if disabl listen throw new illeg state except listen kit remov listen listen listen the method is us onli to imlement context disabl static context listen final void disabl context listen check not seal synchron listen lock disabl listen true listen null check if thi is a seal context factori see seal public final boolean is seal return seal seal thi context factori so ani attempt to modifi it like to add or remov it listen will throw an except see is seal public final void seal check not seal seal true protect final void check not seal if seal throw new illeg state except call link context action run context cx us the link context instanc associ with the current thread if no context is associ with the thread then link make context will be call to construct new context instanc the instanc will be temporari associ with the thread dure call to link context action run context see context factori call context action see context call context factori factori callabl callabl scriptabl scope scriptabl thi obj object arg public final object call context action action return context call thi action same as link context enter with the differ that if a new context need to be creat then thi context factori is us to creat it instead of the global context factori return a context associ with the current thread public final context enter return enter null same as link context enter context with the differ that if a new context need to be creat then thi context factori is us to creat it instead of the global context factori return a context associ with the current thread public final context enter context cx return context enter cx thi same as link context exit although if you us link enter or link enter context method on thi object you should us thi exit method instead of the static on in link context public final void exit context exit thi number node doubl number super token number thi number number privat static class string node extend node string node int type string str super type thi str str public static class jump extend node public jump int type super type jump int type int lineno super type lineno jump int type node child super type child jump int type node child int lineno super type child lineno public final jump get jump statement if type token break type token continu kit code bug return jump node public final void set jump statement jump jump statement if type token break type token continu kit code bug if jump statement null kit code bug if thi jump node null kit code bug onli onc thi jump node jump statement public final node get default if type token switch kit code bug return target2 public final void set default node default target if type token switch kit code bug if default target type token target kit code bug if target2 null kit code bug onli onc target2 default target public final node get final if type token try kit code bug return target2 public final void set final node final target if type token try kit code bug if final target type token target kit code bug if target2 null kit code bug onli onc target2 final target public final jump get loop if type token label kit code bug return jump node public final void set loop jump loop if type token label kit code bug if loop null kit code bug if jump node null kit code bug onli onc jump node loop public final node get continu if type token loop kit code bug return target2 public final void set continu node continu target if type token loop kit code bug if continu target type token target kit code bug if target2 null kit code bug onli onc target2 continu target public node int node type type node type public node int node type node child type node type first last child child next null public node int node type node left node right type node type first left last right left next right right next null public node int node type node left node mid node right type node type first left last right left next mid mid next right right next null public node int node type int line type node type lineno line public node int node type node child int line thi node type child lineno line public node int node type node left node right int line thi node type left right lineno line public node int node type node left node mid node right int line thi node type left mid right lineno line public static node new number doubl number return new number node number public static node new string string str return new string node token string str public static node new string int type string str return new string node type str public int get type return type public void set type int type thi type type public boolean ha children return first null public node get first child return first public node get last child return last public node get next return next public node get child befor node child if child first return null node n first while n next child n n next if n null throw new runtim except node is not a child return n public node get last sibl node n thi while n next null n n next return n public void add child to front node child child next first first child if last null last child public void add child to back node child child next null if last null first last child return last next child last child public void add children to front node children node last sib children get last sibl last sib next first first children if last null last last sib public void add children to back node children if last null last next children last children get last sibl if first null first children add child befor node public void add child befor node new child node node if new child next null throw new runtim except new child had sibl in add child befor if first node new child next first first new child return node prev get child befor node add child after new child prev add child after node public void add child after node new child node node if new child next null throw new runtim except new child had sibl in add child after new child next node next node next new child if last node last new child public void remov child node child node prev get child befor child if prev null first first next els prev next child next if child last last prev child next null public void replac child node child node new child new child next child next if child first first new child els node prev get child befor child prev next new child if child last last new child child next null public void replac child after node prev child node new child node child prev child next new child next child next prev child next new child if child last last new child child next null privat static final string prop to string int prop type if token print tree if context print tree is fals the compil can remov all these string switch prop type case function prop return function case local prop return local case local block prop return local block case regexp prop return regexp case casearrai prop return casearrai case targetblock prop return targetblock case variabl prop return variabl case isnumb prop return isnumb case directcal prop return directcal case specialcal prop return specialcal case skip index prop return skip index case object id prop return object id prop case incrdecr prop return incrdecr prop case catch scope prop return catch scope prop case label id prop return label id prop case member type prop return member type prop case name prop return name prop default kit code bug return null privat prop list item lookup properti int prop type prop list item x prop list head while x null prop type x type x x next return x privat prop list item ensur properti int prop type prop list item item lookup properti prop type if item null item new prop list item item type prop type item next prop list head prop list head item return item public void remov prop int prop type prop list item x prop list head if x null prop list item prev null while x type prop type prev x x x next if x null return if prev null prop list head x next els prev next x next public object get prop int prop type prop list item item lookup properti prop type if item null return null return item object valu public int get int prop int prop type int default valu prop list item item lookup properti prop type if item null return default valu return item int valu public int get exist int prop int prop type prop list item item lookup properti prop type if item null kit code bug return item int valu public void put prop int prop type object prop if prop null remov prop prop type els prop list item item ensur properti prop type item object valu prop public void put int prop int prop type int prop prop list item item ensur properti prop type item int valu prop public int get lineno return lineno can onli be call when tt get type token number tt public final doubl get doubl return number node thi number public final void set doubl doubl number number node thi number number can onli be call when node ha string context public final string get string return string node thi str can onli be call when node ha string context public final void set string string s if s null kit code bug string node thi str s public static node new target return new node token target public final int label id if type token target kit code bug return get int prop label id prop 1 public void label id int label id if type token target kit code bug put int prop label id prop label id public string to string if token print tree string buffer sb new string buffer to string new obj to int map sb return sb to string return string valu of type privat void to string obj to int map print id string buffer sb if token print tree sb append token name type if thi instanceof string node sb append sb append get string els if thi instanceof script or fn node script or fn node sof script or fn node thi if thi instanceof function node function node fn function node thi sb append sb append fn get function name sb append sourc name sb append sof get sourc name sb append encod sourc length sb append sof get encod sourc end sof get encod sourc start sb append base line sb append sof get base lineno sb append end line sb append sof get end lineno sb append els if thi instanceof jump jump jump jump thi if type token break type token continu sb append label append print id jump get jump statement print id sb sb append els if type token try node catch node jump target node final target jump get final if catch node null sb append catch append print id catch node print id sb sb append if final target null sb append final append print id final target print id sb sb append els if type token label type token loop type token switch sb append break append print id jump target print id sb sb append if type token loop sb append continu append print id jump get continu print id sb sb append els sb append target append print id jump target print id sb sb append els if type token number sb append sb append get doubl els if type token target sb append append print id thi print id sb if lineno 1 sb append sb append lineno for prop list item x prop list head x null x x next int type x type sb append sb append prop to string type sb append string valu switch type case targetblock prop can t add thi as it recurs valu target block properti break case local block prop can t add thi as it is dull valu last local block break case isnumb prop switch x int valu case both valu both break case right valu right break case left valu left break default throw kit code bug break case specialcal prop switch x int valu case specialcal eval valu eval break case specialcal with valu with break default non specialcal should not be store throw kit code bug break default object obj x object valu if obj null valu obj to string els valu string valu of x int valu break sb append valu sb append public string to string tree script or fn node tree top if token print tree string buffer sb new string buffer to string tree helper tree top thi null 0 sb return sb to string return null privat static void to string tree helper script or fn node tree top node n obj to int map print id int level string buffer sb if token print tree if print id null print id new obj to int map gener print id tree top print id for int i 0 i level i sb append n to string print id sb sb append n for node cursor n get first child cursor null cursor cursor get next if cursor get type token function int fn index cursor get exist int prop node function prop function node fn tree top get function node fn index to string tree helper fn fn null level 1 sb els to string tree helper tree top cursor print id level 1 sb privat static void gener print id node n obj to int map map if token print tree map put n map size for node cursor n get first child cursor null cursor cursor get next gener print id cursor map privat static void append print id node n obj to int map print id string buffer sb if token print tree if n null int id print id get n 1 sb append if id 1 sb append id 1 els sb append not avail privat string str public consol write consol text area text area string str thi text area text area thi str str public void run text area write str privat string buffer buffer public consol writer consol text area text area thi text area text area buffer new string buffer public synchron void write int ch buffer append char ch if ch n flush buffer public synchron void write char data int off int len for int i off i len i buffer append data i if data i n flush buffer public synchron void flush if buffer length 0 flush buffer public void close flush privat void flush buffer string str buffer to string buffer set length 0 swing util invok later new consol write text area str privat int output mark 0 public void select int start int end request focu super select start end public consol text area string argv super histori new java util vector consol1 new consol writer thi consol2 new consol writer thi out new print stream consol1 err new print stream consol2 pipe output stream out pipe new pipe output stream in pipe new print writer out pipe in new pipe input stream try out pipe connect in catch io except exc exc print stack trace get document add document listen thi add kei listen thi set line wrap true set font new font monospac 0 12 synchron void return press document doc get document int len doc get length segment segment new segment try doc get text output mark len output mark segment catch javax swing text bad locat except ignor ignor print stack trace if segment count 0 histori add element segment to string histori index histori size in pipe write segment arrai segment offset segment count append n output mark doc get length in pipe write n in pipe flush consol1 flush public void eval string str in pipe write str in pipe write n in pipe flush consol1 flush public void kei press kei event e int code e get kei code if code kei event vk back space code kei event vk left if output mark get caret posit e consum els if code kei event vk home int caret po get caret posit if caret po output mark e consum els if caret po output mark if e is control down if e is shift down move caret posit output mark els set caret posit output mark e consum els if code kei event vk enter return press e consum els if code kei event vk up histori index if histori index 0 if histori index histori size histori index histori size 1 if histori index 0 string str string histori element at histori index int len get document get length replac rang str output mark len int caret po output mark str length select caret po caret po els histori index els histori index e consum els if code kei event vk down int caret po output mark if histori size 0 histori index if histori index 0 histori index 0 int len get document get length if histori index histori size string str string histori element at histori index replac rang str output mark len caret po output mark str length els histori index histori size replac rang output mark len select caret po caret po e consum public void kei type kei event e int kei char e get kei char if kei char 0x8 kei event vk back space if output mark get caret posit e consum els if get caret posit output mark set caret posit output mark public synchron void kei releas kei event e public synchron void write string str insert str output mark int len str length output mark len select output mark output mark public synchron void insert updat document event e int len e get length int off e get offset if output mark off output mark len public synchron void remov updat document event e int len e get length int off e get offset if output mark off if output mark off len output mark len els output mark off public synchron void post updateui thi attempt to cleanup the damag done by updat compon treeui request focu set caret get caret select output mark output mark public synchron void chang updat document event e public input stream get in return in public print stream get out return out public print stream get err return err privat interpret function interpret data idata object static secur domain thi idata idata alwai get context from the current thread to avoid secur breach via pass mangl context instanc with bogu secur control context cx context get context secur control sc cx get secur control object dynam domain if sc null dynam domain sc get dynam secur domain static secur domain els if static secur domain null throw new illeg argument except dynam domain null thi secur control sc thi secur domain dynam domain privat interpret function interpret function parent int index thi idata parent idata it nest function index thi secur control parent secur control thi secur domain parent secur domain creat script from compil bytecod static interpret function creat script interpret data idata object static secur domain interpret function f f new interpret function idata static secur domain return f creat function compil from function constructor static interpret function creat function context cx scriptabl scope interpret data idata object static secur domain interpret function f f new interpret function idata static secur domain f init interpret function cx scope return f creat function embed in script or anoth function static interpret function creat function context cx scriptabl scope interpret function parent int index interpret function f new interpret function parent index f init interpret function cx scope return f scriptabl creat reg exp wrap context cx scriptabl scope if idata it reg exp liter null kit code bug reg exp proxi rep script runtim check reg exp proxi cx int n idata it reg exp liter length scriptabl arrai new scriptabl n for int i 0 i n i arrai i rep wrap reg exp cx scope idata it reg exp liter i return arrai privat void init interpret function context cx scriptabl scope init script function cx scope if idata it reg exp liter null function reg exp creat reg exp wrap cx scope public string get function name return idata it name null idata it name call the function param cx the current context param scope the scope us for the call param the valu of thi param function argument must not be null you can us link script runtim empti arg to pass empti argument return the result of the function call public object call context cx scriptabl scope scriptabl thi obj object arg if script runtim ha top call cx return script runtim do top call thi cx scope thi obj arg return interpret interpret thi cx scope thi obj arg public object exec context cx scriptabl scope if idata it function type 0 can onli be appli to script throw new illeg state except if script runtim ha top call cx it will go through call path but thei ar equival return script runtim do top call thi cx scope scope script runtim empti arg return interpret interpret thi cx scope scope script runtim empti arg public string get encod sourc return interpret get encod sourc idata public debugg script get debugg view return idata protect int get languag version return idata languag version protect int get param count return idata arg count protect int get param and var count return idata arg name length protect string get param or var name int index return idata arg name index public compil environ error report default error report instanc languag version context version default gener debug info true us dynam scope fals reserv keyword as identifi fals allow member expr as function name fals xml avail true optim level 0 gener sourc true public void init from context context cx set error report cx get error report thi languag version cx get languag version us dynam scope cx compil function with dynam scope flag gener debug info cx is gener debug chang cx is gener debug reserv keyword as identifi cx ha featur context featur reserv keyword as identifi allow member expr as function name cx ha featur context featur member expr as function name xml avail cx ha featur context featur e4x optim level cx get optim level gener sourc cx is gener sourc activ name cx activ name public final error report get error report return error report public void set error report error report error report if error report null throw new illeg argument except thi error report error report public final int get languag version return languag version public void set languag version int languag version context check languag version languag version thi languag version languag version public final boolean is gener debug info return gener debug info public void set gener debug info boolean flag thi gener debug info flag public final boolean is us dynam scope return us dynam scope public final boolean is reserv keyword as identifi return reserv keyword as identifi public void set reserv keyword as identifi boolean flag reserv keyword as identifi flag public final boolean is allow member expr as function name return allow member expr as function name public void set allow member expr as function name boolean flag allow member expr as function name flag public final boolean is xml avail return xml avail public void set xml avail boolean flag xml avail flag public final int get optim level return optim level public void set optim level int level context check optim level level thi optim level level public final boolean is gener sourc return gener sourc specifi whether or not sourc inform should be gener p without sourc inform evalu the to string method on java script function produc onli nativ code for the bodi of the function note that code gener without sourc is not fulli ecma conform public void set gener sourc boolean gener sourc thi gener sourc gener sourc public static string name int token if print name return string valu of token switch token case error return error case eof return eof case eol return eol case enterwith return enterwith case leavewith return leavewith case return return return case goto return goto case ifeq return ifeq case ifn return ifn case setnam return setnam case bitor return bitor case bitxor return bitxor case bitand return bitand case eq return eq case ne return ne case lt return lt case le return le case gt return gt case ge return ge case lsh return lsh case rsh return rsh case ursh return ursh case add return add case sub return sub case mul return mul case div return div case mod return mod case not return not case bitnot return bitnot case po return po case neg return neg case new return new case delprop return delprop case typeof return typeof case getprop return getprop case setprop return setprop case getelem return getelem case setelem return setelem case call return call case name return name case number return number case string return string case null return null case thi return thi case fals return fals case true return true case sheq return sheq case shne return shne case regexp return object case bindnam return bindnam case throw return throw case rethrow return rethrow case in return in case instanceof return instanceof case local load return local load case getvar return getvar case setvar return setvar case catch scope return catch scope case enum init kei return enum init kei case enum init valu return enum init valu case enum next return enum next case enum id return enum id case thisfn return thisfn case return result return return result case arraylit return arraylit case objectlit return objectlit case get ref return get ref case set ref return set ref case del ref return del ref case ref call return ref call case ref special return ref special case defaultnamespac return defaultnamespac case escxmltext return escxmltext case escxmlattr return escxmlattr case ref member return ref member case ref ns member return ref ns member case ref name return ref name case ref ns name return ref ns name case try return try case semi return semi case lb return lb case rb return rb case lc return lc case rc return rc case lp return lp case rp return rp case comma return comma case assign return assign case assign bitor return assign bitor case assign bitxor return assign bitxor case assign bitand return assign bitand case assign lsh return assign lsh case assign rsh return assign rsh case assign ursh return assign ursh case assign add return assign add case assign sub return assign sub case assign mul return assign mul case assign div return assign div case assign mod return assign mod case hook return hook case colon return colon case or return or case and return and case inc return inc case dec return dec case dot return dot case function return function case export return export case import return import case if return if case els return els case switch return switch case case return case case default return default case while return while case do return do case for return for case break return break case continu return continu case var return var case with return with case catch return catch case final return final case reserv return reserv case empti return empti case block return block case label return label case target return target case loop return loop case expr void return expr void case expr result return expr result case jsr return jsr case script return script case typeofnam return typeofnam case us stack return us stack case setprop op return setprop op case setelem op return setelem op case local block return local block case set ref op return set ref op case dotdot return dotdot case coloncolon return coloncolon case xml return xml case dotqueri return dotqueri case xmlattr return xmlattr case xmlend return xmlend case to object return to object case to doubl return to doubl token without name throw new illeg state except string valu of token privat special ref scriptabl target int type string name thi target target thi type type thi name name static ref creat special context cx object object string name scriptabl target script runtim to object or null cx object if target null throw script runtim undef read error object name int type if name equal proto type special proto els if name equal parent type special parent els throw new illeg argument except name if cx ha featur context featur parent proto proprti clear special after check for valid name type special none return new special ref target type name public object get context cx switch type case special none return script runtim get object prop target name cx case special proto return target get prototyp case special parent return target get parent scope default throw kit code bug public object set context cx object valu switch type case special none return script runtim set object prop target name valu cx case special proto case special parent scriptabl obj script runtim to object or null cx valu if obj null check that obj doe not contain on it prototyp scope chain to prevent cycl scriptabl search obj do if search target throw context report runtim error1 msg cyclic valu name if type special proto search search get prototyp els search search get parent scope while search null if type special proto target set prototyp obj els target set parent scope obj return obj default throw kit code bug public boolean ha context cx if type special none return script runtim ha object elem target name cx return true public boolean delet context cx if type special none return script runtim delet object elem target name cx return fals privat static final int function end token last token 1 string get encod sourc return sourc to string 0 int get current offset return sourc top int mark function start int function type int save offset get current offset add token token function append char function type return save offset int mark function end int function start int offset get current offset append char function end return offset void add token int token if 0 token token token last token throw new illeg argument except append char token void addeol int token if 0 token token token last token throw new illeg argument except append char token append char token eol void add name string str add token token name append string str void add string string str add token token string append string str void add regexp string regexp string flag add token token regexp append string regexp flag void add number doubl n add token token number encod the number in the sourc stream save as number type char char char char char where type is d doubl s short j long we need to retain float vs integ type info to keep the behavior of liveconnect type guess the same after decompil liveconnect tri to present 1 0 to java as a float doubl opt thi is no longer true we could compress the format thi mai not be the most space effici encod the char creat below mai take up to 3 byte in constant pool utf 8 encod so a doubl could take up to 12 byte long lbit long n if lbit n if it s float point save as a doubl bit pattern 12 15 97 our scanner onli return doubl for f p lbit doubl doubl to long bit n append d append char lbit 48 append char lbit 32 append char lbit 16 append char lbit els we can ignor neg valu bc thei re alreadi prefix by neg if lbit 0 kit code bug will it fit in a char thi give a short encod for integ valu up to 2 16 if lbit charact max valu append s append char lbit els integr but won t fit in a char store as a long append j append char lbit 48 append char lbit 32 append char lbit 16 append char lbit privat void append string string str int l str length int length encod size 1 if l 0x8000 length encod size 2 int next top sourc top length encod size l if next top sourc buffer length increas sourc capac next top if l 0x8000 us 2 char to encod string exceed 32k were the highest bit in the first char indic presenc of the next byte sourc buffer sourc top char 0x8000 l 16 sourc top sourc buffer sourc top char l sourc top str get char 0 l sourc buffer sourc top sourc top next top privat void append char c if sourc top sourc buffer length increas sourc capac sourc top 1 sourc buffer sourc top c sourc top privat void increas sourc capac int minim capac call thi onli when capac increas is must if minim capac sourc buffer length kit code bug int new capac sourc buffer length 2 if new capac minim capac new capac minim capac char tmp new char new capac system arraycopi sourc buffer 0 tmp 0 sourc top sourc buffer tmp privat string sourc to string int offset if offset 0 sourc top offset kit code bug return new string sourc buffer offset sourc top offset decompil the sourc inform associ with thi js function script back into a string for the most part thi just mean translat token back to their string represent there s a littl bit of lookahead logic to decid the proper space indent most of the work in map the origin sourc to the prettyprint decompil version is done by the parser param sourc encod sourc tree present param flag flag to select output format param properti indent properti public static string decompil string sourc int flag uint map properti int length sourc length if length 0 return int indent properti get int initi indent prop 0 if indent 0 throw new illeg argument except int indent gap properti get int indent gap prop 4 if indent gap 0 throw new illeg argument except int case gap properti get int case gap prop 2 if case gap 0 throw new illeg argument except string buffer result new string buffer boolean just function bodi 0 flag decompil onli bodi flag boolean to sourc 0 flag decompil to sourc flag spew token in sourc for debug as type number char if print sourc system err println length length for int i 0 i length i note that token to name will fail unless context print tree is true string tokennam null if token print name tokennam token name sourc char at i if tokennam null tokennam string pad tokennam length 7 t t t system err println tokennam pad int sourc char at i t script runtim escap string sourc substr i i 1 system err println int brace nest 0 boolean after firsteol fals int i 0 int top function type if sourc char at i token script i top function type 1 els top function type sourc char at i 1 if to sourc add an initi newlin to exactli match js result append n for int j 0 j indent j result append els if top function type function node function express result append while i length switch sourc char at i case token name case token regexp re wrap in s in parser i print sourc string sourc i 1 fals result continu case token string i print sourc string sourc i 1 true result continu case token number i print sourc number sourc i 1 result continu case token true result append true break case token fals result append fals break case token null result append null break case token thi result append thi break case token function i skip function type result append function break case function end do noth break case token comma result append break case token lc brace nest if token eol get next sourc length i indent indent gap result append break case token rc brace nest don t print the close rc if it close the toplevel function and we re call from decompil function bodi if just function bodi brace nest 0 break result append switch get next sourc length i case token eol case function end indent indent gap break case token while case token els indent indent gap result append break break case token lp result append break case token rp result append if token lc get next sourc length i result append break case token lb result append break case token rb result append break case token eol if to sourc break boolean new line true if after firsteol after firsteol true if just function bodi throw awai just ad function name and restor the origin indent result set length 0 indent indent gap new line fals if new line result append n add indent if ani token remain less setback if next token is a label case or default if i 1 length int less 0 int next token sourc char at i 1 if next token token case next token token default less indent gap case gap els if next token token rc less indent gap elabor check against label skip past a follow inlin name and look for a colon els if next token token name int after name get sourc string end sourc i 2 if sourc char at after name token colon less indent gap for less indent less result append break case token dot result append break case token new result append new break case token delprop result append delet break case token if result append if break case token els result append els break case token for result append for break case token in result append in break case token with result append with break case token while result append while break case token do result append do break case token try result append try break case token catch result append catch break case token final result append final break case token throw result append throw break case token switch result append switch break case token break result append break if token name get next sourc length i result append break case token continu result append continu if token name get next sourc length i result append break case token case result append case break case token default result append default break case token return result append return if token semi get next sourc length i result append break case token var result append var break case token semi result append if token eol get next sourc length i separ in for privat static int get next string sourc int length int i return i 1 length sourc char at i 1 token eof privat static int get sourc string end string sourc int offset return print sourc string sourc offset fals null privat static int print sourc string string sourc int offset boolean as quot string string buffer sb int length sourc char at offset offset if 0x8000 length 0 length 0x7fff length 16 sourc char at offset offset if sb null string str sourc substr offset offset length if as quot string sb append str els sb append sb append script runtim escap string str sb append return offset length privat static int print sourc number string sourc int offset string buffer sb doubl number 0 0 char type sourc char at offset offset if type s if sb null int ival sourc char at offset number ival offset els if type j type d if sb null long lbit lbit long sourc char at offset 48 lbit long sourc char at offset 1 32 lbit long sourc char at offset 2 16 lbit long sourc char at offset 3 if type j number lbit els number doubl long bit to doubl lbit offset 4 els bad sourc throw new runtim except if sb null sb append script runtim number to string number 10 return offset public static class class or null string class name try return class for name class name catch class not found except ex catch secur except ex catch linkag error ex catch illeg argument except e can be thrown if name ha charact that a class name can not contain return null public static class class or null class loader loader string class name try return loader load class class name catch class not found except ex catch secur except ex catch linkag error ex catch illeg argument except e can be thrown if name ha charact that a class name can not contain return null static object new instanc or null class cl try return cl new instanc catch secur except x catch linkag error ex catch instanti except x catch illeg access except x return null check that test class is acces from the given loader static boolean test if can load rhino class class loader loader class test class script runtim context factori class class x kit class or null loader test class get name if x test class the check cover the case when x null loader doe not know about test class or the case when x null x test class loader load a class unrel to test class return fals return true if init caus method exist in throwabl call tt ex init caus caus tt or otherwis do noth return the tt ex tt argument public static runtim except init caus runtim except ex throwabl caus if throwabl init caus null object arg caus try throwabl init caus invok ex arg catch except e ignor ani except return ex split string into arrai of string us semicolon as string termin after the last string is requir public static string semicolon split string s string arrai null for loop 2 time first to count semicolon and then to fill arrai int count 0 int cursor 0 for int next s index of cursor if next 0 break if arrai null arrai count s substr cursor next count cursor next 1 after the last semicolon if arrai null arrai size count state check for requir termin if cursor s length throw new illeg argument except arrai new string count els arrai fill state stop the loop break return arrai if charact tt c tt is a hexadecim digit return tt accumul tt 16 plu correspond number otheris return 1 public static int x digit to int int c int accumul check us 0 9 a z a z if c 9 c 0 if 0 c break check els if c f if a c c a 10 break check els if c f if a c c a 10 break check return 1 return accumul 4 c add i listen i to i bag i of listen the function doe not modifi i bag i and return a new collect contain i listen i and all listen from i bag i bag without listen alwai repres as the null valu p usag exampl pre privat volatil object chang listen public void add my listen properti chang listen l synchron thi chang listen kit add listen chang listen l public void remov text listen properti chang listen l synchron thi chang listen kit remov listen chang listen l public void fire chang event object old valu object new valu get immun local copi object listen chang listen if listen null properti chang event e new properti chang event thi some properti old valu new valu for int i 0 i object l kit get listen listen i if l null break properti chang listen l properti chang e pre param listen listen to add to i bag i param bag current collect of listen return a new bag contain all listen from i bag i and i listen i see remov listen object bag object listen see get listen object bag int index public static object add listen object bag object listen if listen null throw new illeg argument except if listen instanceof object throw new illeg argument except if bag null bag listen els if bag instanceof object bag new object bag listen els object arrai object bag int l arrai length bag ha at least 2 element if it is arrai if l 2 throw new illeg argument except object tmp new object l 1 system arraycopi arrai 0 tmp 0 l tmp l listen bag tmp return bag remov i listen i from i bag i of listen the function doe not modifi i bag i and return a new collect contain all listen from i bag i except i listen i if i bag i doe not contain i listen i the function return i bag i p for usag exampl see link add listen object bag object listen param listen listen to remov from i bag i param bag current collect of listen return a new bag contain all listen from i bag i except i listen i see add listen object bag object listen see get listen object bag int index public static object remov listen object bag object listen if listen null throw new illeg argument except if listen instanceof object throw new illeg argument except if bag listen bag null els if bag instanceof object object arrai object bag int l arrai length bag ha at least 2 element if it is arrai if l 2 throw new illeg argument except if l 2 if arrai 1 listen bag arrai 0 els if arrai 0 listen bag arrai 1 els int i l do i if arrai i listen object tmp new object l 1 system arraycopi arrai 0 tmp 0 i system arraycopi arrai i 1 tmp i l i 1 bag tmp break while i 0 return bag get listen at i index i posit in i bag i or null if i index i equal to number of listen in i bag i p for usag exampl see link add listen object bag object listen param bag current collect of listen param index index of the listen to access return listen at the given index or null see add listen object bag object listen see remov listen object bag object listen public static object get listen object bag int index if index 0 if bag null return null if bag instanceof object return bag object arrai object bag bag ha at least 2 element if it is arrai if arrai length 2 throw new illeg argument except return arrai 0 els if index 1 if bag instanceof object if bag null throw new illeg argument except return null object arrai object bag the arrai access will check for index on it own return arrai 1 els bag ha to arrai object arrai object bag int l arrai length if l 2 throw new illeg argument except if index l return null return arrai index static object init hash hashtabl h object kei object initi valu synchron h object current h get kei if current null h put kei initi valu els initi valu current return initi valu complex kei object kei1 object kei2 thi kei1 kei1 thi kei2 kei2 public boolean equal object anoth obj if anoth obj instanceof complex kei return fals complex kei anoth complex kei anoth obj return kei1 equal anoth kei1 kei2 equal anoth kei2 public int hash code if hash 0 hash kei1 hash code kei2 hash code return hash public static object make hash kei from pair object kei1 object kei2 if kei1 null throw new illeg argument except if kei2 null throw new illeg argument except return new complex kei kei1 kei2 public static string read reader reader r throw io except char buffer new char 512 int cursor 0 for int n r read buffer cursor buffer length cursor if n 0 break cursor n if cursor buffer length char tmp new char buffer length 2 system arraycopi buffer 0 tmp 0 cursor buffer tmp return new string buffer 0 cursor public static byte read stream input stream is int initi buffer capac throw io except if initi buffer capac 0 throw new illeg argument except bad initi buffer capac initi buffer capac byte buffer new byte initi buffer capac int cursor 0 for int n is read buffer cursor buffer length cursor if n 0 break cursor n if cursor buffer length byte tmp new byte buffer length 2 system arraycopi buffer 0 tmp 0 cursor buffer tmp if cursor buffer length byte tmp new byte cursor system arraycopi buffer 0 tmp 0 cursor buffer tmp return buffer throw runtim except to indic fail assert the function never return and it return type is runtim except onli to be abl to write tt throw kit code bug tt if plain tt kit code bug tt trigger unreach code error public static runtim except code bug throw runtim except runtim except ex new illeg state except fail assert print stack trace asap ex print stack trace system err throw ex privat static vm bridg make instanc for int i 0 i 3 i string class name if i 0 class name org mozilla javascript vm bridg custom els if i 1 class name org mozilla javascript jdk13 vm bridg jdk13 els class name org mozilla javascript jdk11 vm bridg jdk11 class cl kit class or null class name if cl null vm bridg bridg vm bridg kit new instanc or null cl if bridg null return bridg throw new illeg state except fail to creat vm bridg instanc return a helper object to optim link context access p the runtim will pass the result helper object to the subsequ call to link get context object context helper and link set context object context helper context cx method in thi wai the implement can us the helper to cach inform about current thread to make link context access faster get link context instanc associ with the current thread or null if none param context helper the result of link get thread context helper call from the current thread associ link context instanc with the current thread or remov the current associ if tt cx tt is null param context helper the result of link get thread context helper call from the current thread protect abstract void set context object context helper context cx return the class loader instanc associ with the current thread protect abstract class loader get current thread class loader in mani jvm ss public method in privat class ar not access by default sun bug 4071593 vm bridg instanc should try to workaround that via for exampl call method set access true when it is avail the implement is respons to catch all possibl except like secur except if the workaround is not avail return true if it wa possibl to make method access or fals otherwis creat helper object to creat later proxi implement the specifi interfac later under jdk 1 3 the implement can look like pre return java lang reflect proxi get proxi class interfac get constructor new class java lang reflect invoc handler class pre param interfac arrai with on or more interfac class object protect object get interfac proxi helper context factori cf class interfac throw context report runtim error vm bridg get interfac proxi helper is not support creat proxi object for link interfac adapt the proxi should call link interfac adapt invok context factori cf object target scriptabl top scope method method object arg as implement of interfac method associ with tt proxi helper tt param proxi helper the result of the previou call to link get interfac proxi helper context factori class protect object new interfac proxi object proxi helper context factori cf interfac adapt adapt object target scriptabl top scope throw context report runtim error vm bridg new interfac proxi is not support static final long serial versionuid 6358550398665688245l member box method method init method member box constructor constructor init constructor privat void init method method thi member object method thi arg type method get paramet type privat void init constructor constructor thi member object constructor thi arg type constructor get paramet type method method return method member object constructor ctor return constructor member object boolean is method return member object instanceof method boolean is ctor return member object instanceof constructor boolean is static return modifi is static member object get modifi string get name return member object get name class get declar class return member object get declar class string to java declar string buffer sb new string buffer if is method method method method sb append method get return type sb append sb append method get name els constructor ctor ctor string name ctor get declar class get name int last dot name last index of if last dot 0 name name substr last dot 1 sb append name sb append java member live connect signatur arg type return sb to string public string to string return member object to string object invok object target object arg method method method try try return method invok target arg catch illeg access except ex method access search access method method arg type if access null member object access method access els if vm bridg instanc try to make access method throw context throw as script runtim ex ex retri after recoveri return method invok target arg catch except ex throw context throw as script runtim ex ex object new instanc object arg constructor ctor ctor try try return ctor new instanc arg catch illeg access except ex if vm bridg instanc try to make access ctor throw context throw as script runtim ex ex return ctor new instanc arg catch except ex throw context throw as script runtim ex ex privat static method search access method method method class param int modifi method get modifi if modifi is public modifi modifi is static modifi class c method get declar class if modifi is public c get modifi string name method get name class intf c get interfac for int i 0 n intf length i n i class intf intf i if modifi is public intf get modifi try return intf get method name param catch no such method except ex catch secur except ex for c c get superclass if c null break if modifi is public c get modifi try method m c get method name param int m modifi m get modifi if modifi is public m modifi modifi is static m modifi return m catch no such method except ex catch secur except ex return null privat void read object object input stream in throw io except class not found except in default read object member member read member in if member instanceof method init method member els init constructor member privat void write object object output stream out throw io except out default write object write member out member object write a constructor or method object method and constructor ar not serializ so we must serial inform about the class the name and the paramet and recreat upon deseri privat static void write member object output stream out member member throw io except if member null out write boolean fals return out write boolean true if member instanceof method member instanceof constructor throw new illeg argument except not method or constructor out write boolean member instanceof method out write object member get name out write object member get declar class if member instanceof method write paramet out method member get paramet type els write paramet out constructor member get paramet type read a method or a constructor from the stream privat static member read member object input stream in throw io except class not found except if in read boolean return null boolean is method in read boolean string name string in read object class declar class in read object class parm read paramet in try if is method return declar get method name parm els return declar get constructor parm catch no such method except e throw new io except cannot find member e write an arrai of paramet type to the stream requir special handl becaus primit type cannot be found upon deseri by the default java implement privat static void write paramet object output stream out class parm throw io except out write short parm length outer for int i 0 i parm length i class parm parm i out write boolean parm is primit if parm is primit out write object parm continu for int j 0 j primit length j if parm equal primit j out write byte j continu outer throw new illeg argument except primit parm not found read an arrai of paramet type from the stream privat static class read paramet object input stream in throw io except class not found except class result new class in read short for int i 0 i result length i if in read boolean result i class in read object continu result i primit in read byte return result static void check valid attribut int attribut final int mask readonli dontenum perman if attribut mask 0 throw new illeg argument except string valu of attribut public scriptabl object public scriptabl object scriptabl scope scriptabl prototyp if scope null throw new illeg argument except parent scope object scope prototyp object prototyp return the name of the class thi is typic the same name as the constructor class extend scriptabl object must implement thi abstract method return true if the name properti is defin param name the name of the properti param start the object in which the lookup began return true if and onli if the properti wa found in the object public boolean ha string name scriptabl start return null get name slot name return true if the properti index is defin param index the numer index for the properti param start the object in which the lookup began return true if and onli if the properti wa found in the object public boolean ha int index scriptabl start return null get slot null index return the valu of the name properti or not found if the properti wa creat us defin properti the appropri getter method is call param name the name of the properti param start the object in which the lookup began return the valu of the properti mai be null or not found public object get string name scriptabl start slot slot get name slot name if slot null return scriptabl not found if slot instanceof getter slot getter slot gslot getter slot slot if gslot getter null return get by getter gslot start return slot valu return the valu of the index properti or not found param index the numer index for the properti param start the object in which the lookup began return the valu of the properti mai be null or not found public object get int index scriptabl start slot slot get slot null index if slot null return scriptabl not found return slot valu set the valu of the name properti creat it if need be if the properti wa creat us defin properti the appropri setter method is call p if the properti s attribut includ readonli no action is taken thi method will actual set the properti in the start object param name the name of the properti param start the object whose properti is be set param valu valu to set the properti to public void put string name scriptabl start object valu slot slot last access get local copi if name slot string kei slot wa delet 0 int hash name hash code slot get slot name hash if slot null if start thi start put name start valu return slot add slot name hash null note cach is not updat in put if start thi is seal throw context report runtim error1 msg modifi seal name if slot attribut scriptabl object readonli 0 return if slot instanceof getter slot getter slot gslot getter slot slot if gslot setter null set by setter gslot start valu return if thi start slot valu valu els start put name start valu set the valu of the index properti creat it if need be param index the numer index for the properti param start the object whose properti is be set param valu valu to set the properti to public void put int index scriptabl start object valu slot slot get slot null index if slot null if start thi start put index start valu return slot add slot null index null if start thi is seal throw context report runtim error1 msg modifi seal integ to string index if slot attribut scriptabl object readonli 0 return if thi start slot valu valu els start put index start valu remov a name properti from the object if the properti is not found or it ha the perman attribut no action is taken param name the name of the properti public void delet string name remov slot name name hash code remov the index properti from the object if the properti is not found or it ha the perman attribut no action is taken param index the numer index for the properti public void delet int index remov slot null index deprec us link get attribut string name the engin alwai ignor the start argument public final int get attribut string name scriptabl start return get attribut name deprec us link get attribut int index the engin alwai ignor the start argument public final int get attribut int index scriptabl start return get attribut index deprec us link set attribut string name int attribut the engin alwai ignor the start argument public final void set attribut string name scriptabl start int attribut set attribut name attribut deprec us link set attribut int index int attribut the engin alwai ignor the start argument public void set attribut int index scriptabl start int attribut set attribut index attribut get the attribut of a name properti the properti is specifi by code name code as defin for code ha code p param name the identifi for the properti return the bitset of attribut except evalu except if the name properti is not found see org mozilla javascript scriptabl object ha see org mozilla javascript scriptabl object readonli see org mozilla javascript scriptabl object dontenum see org mozilla javascript scriptabl object perman see org mozilla javascript scriptabl object empti public int get attribut string name slot slot get name slot name if slot null throw context report runtim error1 msg prop not found name return slot attribut get the attribut of an index properti param index the numer index for the properti except evalu except if the name properti is not found is not found return the bitset of attribut see org mozilla javascript scriptabl object ha see org mozilla javascript scriptabl object readonli see org mozilla javascript scriptabl object dontenum see org mozilla javascript scriptabl object perman see org mozilla javascript scriptabl object empti public int get attribut int index slot slot get slot null index if slot null throw context report runtim error1 msg prop not found string valu of index return slot attribut set the attribut of a name properti the properti is specifi by code name code as defin for code ha code p the possibl attribut ar readonli dontenum and perman combin of attribut ar express by the bitwis or of attribut empti is the state of no attribut set ani unus bit ar reserv for futur us param name the name of the properti param attribut the bitset of attribut except evalu except if the name properti is not found see org mozilla javascript scriptabl ha see org mozilla javascript scriptabl object readonli see org mozilla javascript scriptabl object dontenum see org mozilla javascript scriptabl object perman see org mozilla javascript scriptabl object empti public void set attribut string name int attribut check valid attribut attribut slot slot get name slot name if slot null throw context report runtim error1 msg prop not found name slot attribut short attribut set the attribut of an index properti param index the numer index for the properti param attribut the bitset of attribut except evalu except if the name properti is not found see org mozilla javascript scriptabl ha see org mozilla javascript scriptabl object readonli see org mozilla javascript scriptabl object dontenum see org mozilla javascript scriptabl object perman see org mozilla javascript scriptabl object empti public void set attribut int index int attribut check valid attribut attribut slot slot get slot null index if slot null throw context report runtim error1 msg prop not found string valu of index slot attribut short attribut return the prototyp of the object public scriptabl get prototyp return prototyp object set the prototyp of the object public void set prototyp scriptabl m prototyp object m return the parent enclos scope of the object public scriptabl get parent scope return parent scope object set the parent enclos scope of the object public void set parent scope scriptabl m parent scope object m return an arrai of id for the properti of the object p ani properti with the attribut dontenum ar not list p return an arrai of java lang object with an entri for everi list properti properti access via an integ index will have a correspond integ entri in the return arrai properti access by a string will have a string entri in the return arrai public object get id return get id fals return an arrai of id for the properti of the object p all properti even those with attribut dontenum ar list p return an arrai of java lang object with an entri for everi list properti properti access via an integ index will have a correspond integ entri in the return arrai properti access by a string will have a string entri in the return arrai public object get all id return get id true implement the default valu intern method p note that the to primit convers is a no op for everi type other than object for which default valu is call see ecma 9 1 p a code hint code of null mean no hint param type hint the type hint return the default valu for the object see ecma 8 6 2 6 public object get default valu class type hint context cx null for int i 0 i 2 i boolean try to string if type hint script runtim string class try to string i 0 els try to string i 1 string method name object arg if try to string method name to string arg script runtim empti arg els method name valu of arg new object 1 string hint if type hint null hint undefin els if type hint script runtim string class hint string els if type hint script runtim scriptabl class hint object els if type hint script runtim function class hint function els if type hint script runtim boolean class type hint boolean type hint boolean els if type hint script runtim number class type hint script runtim byte class type hint byte type type hint script runtim short class type hint short type type hint script runtim integ class type hint integ type type hint script runtim float class type hint float type type hint script runtim doubl class type hint doubl type hint number els throw context report runtim error1 msg invalid type type hint to string arg 0 hint object v get properti thi method name if v instanceof function continu function fun function v if cx null cx context get context v fun call cx fun get parent scope thi arg if v null if v instanceof scriptabl return v if type hint script runtim scriptabl class type hint script runtim function class return v if try to string v instanceof wrapper let a wrap java lang string pass for a primit string object u wrapper v unwrap if u instanceof string return u fall through to error string arg type hint null undefin type hint get name throw script runtim type error1 msg default valu arg implement the instanceof oper p thi oper ha been propos to ecma param instanc the valu that appear on the lh of the instanceof oper return true if thi appear in valu s prototyp chain public boolean ha instanc scriptabl instanc default for js object other than function is to do prototyp chase thi will be overridden in nativ function and non js object return script runtim js deleg to instanc thi custom tt tt oper must return link scriptabl not found if thi object doe not have custom equal oper for the given valu tt boolean true tt if thi object is equival to tt valu tt tt boolean fals tt if thi object is not equival to tt valu tt p the default implement return boolean true if tt thi valu tt or link scriptabl not found otherwis it indic that by default custom equal is avail onli if tt valu tt is tt thi tt in which case true is return protect object equival valu object valu return thi valu boolean true scriptabl not found defin java script object from a java class that implement scriptabl if the given class ha a method pre static void init context cx scriptabl scope boolean seal pre or it compat form pre static void init scriptabl scope pre then it is invok and no further initi is done p howev if no such a method is found then the class s constructor and method ar us to initi a class in the follow manner p first the zero paramet constructor of the class is call to creat the prototyp if no such constructor exist a link evalu except is thrown p next all method ar scan for special prefix that indic that thei have special mean for defin java script object these special prefix ar ul li code js function code for a java script function li code js static function code for a java script function that is a properti of the constructor li code js get code for a getter of a java script properti li code js set code for a setter of a java script properti li code js constructor code for a java script function that is the constructor ul p if the method s name begin with js function a java script function is creat with a name form from the rest of the java method name follow js function so a java method name js function foo will defin a java script method foo call thi java script function will caus the java method to be call the paramet of the method must be of number and type as defin by the function object class the java script function is then ad as a properti of the prototyp p if the method s name begin with js static function it is handl similarli except that the result java script function is ad as a properti of the constructor object the java method must be static if the method s name begin with js get or js set the method is consid to defin a properti access to the defin properti will result in call to these getter and setter method if no setter is defin the properti is defin as readonli p if the method s name is js constructor the method is consid to defin the bodi of the constructor onli on method of thi name mai be defin if no method is found that can serv as constructor a java constructor will be select to serv as the java script constructor in the follow manner if the class ha onli on java constructor that constructor is us to defin the java script constructor if the the class ha two constructor on must be the zero argument constructor otherwis an link evalu except would have alreadi been thrown when the prototyp wa to be creat in thi case the java constructor with on or more paramet will be us to defin the java script constructor if the class ha three or more constructor an link evalu except will be thrown p final if there is a method pre static void finish init scriptabl scope function object constructor scriptabl prototyp pre it will be call to finish ani initi the code scope code argument will be pass along with the newli creat constructor and the newli creat prototyp p param scope the scope in which to defin the constructor param clazz the java class to us to defin the java script object and properti except illeg access except if access is not avail to a reflect class member except instanti except if unabl to instanti the name class except invoc target except if an except is thrown dure execut of method of the name class see org mozilla javascript function see org mozilla javascript function object see org mozilla javascript scriptabl object readonli see org mozilla javascript scriptabl object defin properti public static void defin class scriptabl scope class clazz throw illeg access except instanti except invoc target except defin class scope clazz fals fals defin java script object from a java class option allow seal similar to code defin class scriptabl scope class clazz code except that seal is allow an object that is seal cannot have properti ad or remov note that seal is not allow in the current ecma iso languag specif but is like for the next version param scope the scope in which to defin the constructor param clazz the java class to us to defin the java script object and properti the class must implement scriptabl param seal whether or not to creat seal standard object that cannot be modifi except illeg access except if access is not avail to a reflect class member except instanti except if unabl to instanti the name class except invoc target except if an except is thrown dure execut of method of the name class sinc 1 4r3 public static void defin class scriptabl scope class clazz boolean seal throw illeg access except instanti except invoc target except defin class scope clazz seal fals defin java script object from a java class option allow seal and map of java inherit to java script prototyp base inherit similar to code defin class scriptabl scope class clazz code except that seal and inherit map ar allow an object that is seal cannot have properti ad or remov note that seal is not allow in the current ecma iso languag specif but is like for the next version param scope the scope in which to defin the constructor param clazz the java class to us to defin the java script object and properti the class must implement scriptabl param seal whether or not to creat seal standard object that cannot be modifi param map inherit whether or not to map java inherit to java script prototyp base inherit return the class name for the prototyp of the specifi class except illeg access except if access is not avail to a reflect class member except instanti except if unabl to instanti the name class except invoc target except if an except is thrown dure execut of method of the name class sinc 1 6r2 public static string defin class scriptabl scope class clazz boolean seal boolean map inherit throw illeg access except instanti except invoc target except method method function object get method list clazz for int i 0 i method length i method method method i if method get name equal init continu class parm type method get paramet type if parm type length 3 parm type 0 script runtim context class parm type 1 script runtim scriptabl class parm type 2 boolean type modifi is static method get modifi object arg context get context scope seal boolean true boolean fals method invok null arg return null if parm type length 1 parm type 0 script runtim scriptabl class modifi is static method get modifi object arg scope method invok null arg return null if we got here there isn t an init method with the right paramet type constructor ctor clazz get constructor constructor proto ctor null for int i 0 i ctor length i if ctor i get paramet type length 0 proto ctor ctor i break if proto ctor null throw context report runtim error1 msg zero arg ctor clazz get name scriptabl proto scriptabl proto ctor new instanc script runtim empti arg string class name proto get class name set the prototyp s prototyp try to map java inherit to js prototyp base inherit if request to do so scriptabl super proto null if map inherit class super class clazz get superclass if script runtim scriptabl class is assign from super class string name scriptabl object defin class scope super class seal map inherit if name null super proto scriptabl object get class prototyp scope name if super proto null super proto scriptabl object get object prototyp scope proto set prototyp super proto find out whether there ar ani method that begin with js if so then onli method that begin with special prefix will be defin as java script entiti final string function prefix js function final string static function prefix js static function final string getter prefix js get final string setter prefix js set final string ctor name js constructor member ctor member function object find singl method method ctor name if ctor member null if ctor length 1 ctor member ctor 0 els if ctor length 2 if ctor 0 get paramet type length 0 ctor member ctor 1 els if ctor 1 get paramet type length 0 ctor member ctor 0 if ctor member null throw context report runtim error1 msg ctor multipl parm clazz get name function object ctor new function object class name ctor member scope if ctor is var arg method throw context report runtim error1 msg vararg ctor ctor member get name ctor add as constructor scope proto method finish init null for int i 0 i method length i if method i ctor member continu string name method i get name if name equal finish init class parm type method i get paramet type if parm type length 3 parm type 0 script runtim scriptabl class parm type 1 function object class parm type 2 script runtim scriptabl class modifi is static method i get modifi finish init method i continu ignor ani compil gener method if name index of 1 continu if name equal ctor name continu string prefix null if name start with function prefix prefix function prefix els if name start with static function prefix prefix static function prefix if modifi is static method i get modifi throw context report runtim error js static function must be us with static method els if name start with getter prefix prefix getter prefix els if name start with setter prefix prefix setter prefix els continu name name substr prefix length if prefix setter prefix continu deal with set when we see get if prefix getter prefix if proto instanceof scriptabl object throw context report runtim error2 msg extend scriptabl proto get class to string name method setter function object find singl method method setter prefix name int attr scriptabl object perman scriptabl object dontenum setter null 0 scriptabl object readonli scriptabl object proto defin properti name null method i setter attr continu function object f new function object name method i proto if f is var arg constructor throw context report runtim error1 msg vararg fun ctor member get name scriptabl dest prefix static function prefix ctor proto defin properti dest name f dontenum if seal f seal object call user code to complet initi if necessari if finish init null object finish arg scope ctor proto finish init invok null finish arg seal the object if necessari if seal ctor seal object if proto instanceof scriptabl object scriptabl object proto seal object return class name defin a java script properti creat the properti with an initi valu and set it attribut param properti name the name of the properti to defin param valu the initi valu of the properti param attribut the attribut of the java script properti see org mozilla javascript scriptabl put public void defin properti string properti name object valu int attribut put properti name thi valu set attribut properti name attribut util method to add properti to arbitrari scriptabl object if destin is instanc of scriptabl object call defin properti there otherwis call put in destin ignor attribut public static void defin properti scriptabl destin string properti name object valu int attribut if destin instanceof scriptabl object destin put properti name destin valu return scriptabl object so scriptabl object destin so defin properti properti name valu attribut defin a java script properti with getter and setter side effect if the setter is not found the attribut readonli is ad to the given attribut p the getter must be a method with zero paramet and the setter if found must be a method with on paramet p param properti name the name of the properti to defin thi name also affect the name of the setter and getter to search for if the properti id is foo then code clazz code will be search for get foo and set foo method param clazz the java class to search for the getter and setter param attribut the attribut of the java script properti see org mozilla javascript scriptabl put public void defin properti string properti name class clazz int attribut int length properti name length if length 0 throw new illeg argument except char buf new char 3 length properti name get char 0 length buf 3 buf 3 charact to upper case buf 3 buf 0 g buf 1 e buf 2 t string getter name new string buf buf 0 s string setter name new string buf method method function object get method list clazz method getter function object find singl method method getter name method setter function object find singl method method setter name if setter null attribut scriptabl object readonli defin properti properti name null getter setter null null setter attribut defin a java script properti us thi method onli if you wish to defin getter and setter for a given properti in a scriptabl object to creat a properti without special getter or setter side effect us code defin properti string int code if code setter code is null the attribut readonli is ad to the given attribut p sever form of getter or setter ar allow in all case the type of the valu paramet can be ani on of the follow type object string boolean scriptabl byte short int long float or doubl the runtim will perform appropri convers base upon the type of the paramet see descript in function object the first form ar nonstat method of the class refer to by thi pre object get foo void set foo some type valu pre next ar static method that mai be of ani class the object whose properti is be access is pass in as an extra argument pre static object get foo scriptabl object obj static void set foo scriptabl object obj some type valu pre final it is possibl to deleg to anoth object entir us the code deleg to code paramet in thi case the method ar nonstat method of the class deleg to and the object whose properti is be access is pass in as an extra argument pre object get foo scriptabl object obj void set foo scriptabl object obj some type valu pre param properti name the name of the properti to defin param deleg to an object to call the getter and setter method on or null depend on the form us abov param getter the method to invok to get the valu of the properti param setter the method to invok to set the valu of the properti param attribut the attribut of the java script properti public void defin properti string properti name object deleg to method getter method setter int attribut if deleg to null modifi is static getter get modifi deleg to ha static accessor class parm type getter get paramet type if parm type length 0 if parm type length 1 parm type 0 script runtim scriptabl object class throw context report runtim error1 msg bad getter parm getter to string els if deleg to null throw context report runtim error1 msg obj getter parm getter to string if setter null if deleg to ha static accessor modifi is static setter get modifi throw context report runtim error0 msg getter static parm type setter get paramet type if parm type length 2 if parm type 0 script runtim scriptabl object class throw context report runtim error0 msg setter2 parm if deleg to null throw context report runtim error1 msg setter1 parm setter to string els if parm type length 1 if deleg to null throw context report runtim error1 msg setter2 expect setter to string els throw context report runtim error0 msg setter parm class setter type parm type parm type length 1 int setter type tag function object get type tag setter type if setter type tag function object java unsupport type throw context report runtim error2 msg setter2 expect setter type get name setter to string getter slot gslot new getter slot gslot deleg to deleg to gslot getter new member box getter if setter null gslot setter new member box setter gslot attribut short attribut slot insert add slot properti name properti name hash code gslot if insert gslot throw new runtim except properti alreadi exist search for name in a class ad the result method as properti p us reflect to find the method of the given name then function object ar construct from the method found and ar ad to thi object as properti with the given name param name the name of the method to add as function properti param clazz the class to search for the method param attribut the attribut of the new properti see org mozilla javascript function object public void defin function properti string name class clazz int attribut method method function object get method list clazz for int i 0 i name length i string name name i method m function object find singl method method name if m null throw context report runtim error2 msg method not found name clazz get name function object f new function object name m thi defin properti name f attribut get the object prototyp properti see ecma 15 2 4 public static scriptabl get object prototyp scriptabl scope return get class prototyp scope object get the function prototyp properti see ecma 15 3 4 public static scriptabl get function prototyp scriptabl scope return get class prototyp scope function get the prototyp for the name class for exampl code get class prototyp s date code will first walk up the parent chain to find the outermost scope then will search that scope for the date constructor and then will return date prototyp if ani of the lookup fail or the prototyp is not a java script object then null will be return param scope an object in the scope chain param class name the name of the constructor return the prototyp for the name class or null if it cannot be found public static scriptabl get class prototyp scriptabl scope string class name scope get top level scope scope object ctor get properti scope class name object proto if ctor instanceof base function proto base function ctor get prototyp properti els if ctor instanceof scriptabl scriptabl ctor obj scriptabl ctor proto ctor obj get prototyp ctor obj els return null if proto instanceof scriptabl return scriptabl proto return null get the global scope p walk the parent scope chain to find an object with a null parent scope the global object param obj a java script object return the correspond global scope public static scriptabl get top level scope scriptabl obj for scriptabl parent obj get parent scope if parent null return obj obj parent seal thi object a seal object mai not have properti ad or remov onc an object is seal it mai not be unseal sinc 1 4r3 public synchron void seal object if count 0 count 1 count return true if thi object is seal it is an error to attempt to add or remov properti to a seal object return true if seal fals otherwis sinc 1 4r3 public final boolean is seal return count 0 get a name properti from an object or ani object in it prototyp chain p search the prototyp chain for a properti name code name code p param obj a java script object param name a properti name return the valu of a properti with name code name code found in code obj code or ani object in it prototyp chain or code scriptabl not found code if not found sinc 1 5r2 public static object get properti scriptabl obj string name scriptabl start obj object result do result obj get name start if result scriptabl not found break obj obj get prototyp while obj null return result get an index properti from an object or ani object in it prototyp chain p search the prototyp chain for a properti with integr index code index code note that if you wish to look for properti with numer but non integr indici you should us get properti scriptabl string with the string valu of the index p param obj a java script object param index an integr index return the valu of a properti with index code index code found in code obj code or ani object in it prototyp chain or code scriptabl not found code if not found sinc 1 5r2 public static object get properti scriptabl obj int index scriptabl start obj object result do result obj get index start if result scriptabl not found break obj obj get prototyp while obj null return result return whether a name properti is defin in an object or ani object in it prototyp chain p search the prototyp chain for a properti name code name code p param obj a java script object param name a properti name return the true if properti wa found sinc 1 5r2 public static boolean ha properti scriptabl obj string name return null get base obj name return whether an index properti is defin in an object or ani object in it prototyp chain p search the prototyp chain for a properti with index code index code p param obj a java script object param index a properti index return the true if properti wa found sinc 1 5r2 public static boolean ha properti scriptabl obj int index return null get base obj index put a name properti in an object or in an object in it prototyp chain p seach for the name properti in the prototyp chain if it is found the valu of the properti in code obj code is chang through a call to link scriptabl put string scriptabl object on the prototyp pass code obj code as the code start code argument thi allow the prototyp to veto the properti set in case the prototyp defin the properti with read onli attribut if the properti is not found it is ad in code obj code param obj a java script object param name a properti name param valu ani java script valu accept by scriptabl put sinc 1 5r2 public static void put properti scriptabl obj string name object valu scriptabl base get base obj name if base null base obj base put name obj valu put an index properti in an object or in an object in it prototyp chain p seach for the index properti in the prototyp chain if it is found the valu of the properti in code obj code is chang through a call to link scriptabl put int scriptabl object on the prototyp pass code obj code as the code start code argument thi allow the prototyp to veto the properti set in case the prototyp defin the properti with read onli attribut if the properti is not found it is ad in code obj code param obj a java script object param index a properti index param valu ani java script valu accept by scriptabl put sinc 1 5r2 public static void put properti scriptabl obj int index object valu scriptabl base get base obj index if base null base obj base put index obj valu remov the properti from an object or it prototyp chain p search for a properti with code name code in obj or it prototyp chain if it is found the object s delet method is call param obj a java script object param name a properti name return true if the properti doesn t exist or wa successfulli remov sinc 1 5r2 public static boolean delet properti scriptabl obj string name scriptabl base get base obj name if base null return true base delet name return base ha name obj remov the properti from an object or it prototyp chain p search for a properti with code index code in obj or it prototyp chain if it is found the object s delet method is call param obj a java script object param index a properti index return true if the properti doesn t exist or wa successfulli remov sinc 1 5r2 public static boolean delet properti scriptabl obj int index scriptabl base get base obj index if base null return true base delet index return base ha index obj return an arrai of all id from an object and it prototyp p param obj a java script object return an arrai of all id from all object in the prototyp chain if a given id occur multipl time in the prototyp chain it will occur onli onc in thi list sinc 1 5r2 public static object get properti id scriptabl obj if obj null return script runtim empti arg object result obj get id obj to int map map null for obj obj get prototyp if obj null break object id obj get id if id length 0 continu if map null if result length 0 result id continu map new obj to int map result length id length for int i 0 i result length i map intern result i result null allow to gc the result for int i 0 i id length i map intern id i if map null result map get kei return result call a method of an object param obj the java script object param method name the name of the function properti param arg the argument for the call see context get current context public static object call method scriptabl obj string method name object arg return call method null obj method name arg call a method of an object param cx the context object associ with the current thread param obj the java script object param method name the name of the function properti param arg the argument for the call public static object call method context cx scriptabl obj string method name object arg object fun obj get properti obj method name if fun obj instanceof function throw script runtim not function error obj method name function fun function fun obj xxx what should be the scope when call fun obj the follow favor scope store in the object on the assumpt that is more us especi under dynam scope setup an altern is to check for dynam scope flag and us scriptabl object get top level scope fun if the flag is not set but that requir access to context and messi code so for now it is not check scriptabl scope scriptabl object get top level scope obj if cx null return fun call cx scope obj arg els return context call null fun scope obj arg privat static scriptabl get base scriptabl obj string name do if obj ha name obj break obj obj get prototyp while obj null return obj privat static scriptabl get base scriptabl obj int index do if obj ha index obj break obj obj get prototyp while obj null return obj get arbitrari applic specif valu associ with thi object param kei kei object to select particular valu see associ valu object kei object valu public final object get associ valu object kei hashtabl h associ valu if h null return null return h get kei get arbitrari applic specif valu associ with the top scope of the given scope the method first call link get top level scope scriptabl scope and then search the prototyp chain of the top scope for the first object contain the associ valu with the given kei param scope the start scope param kei kei object to select particular valu see get associ valu object kei public static object get top scope valu scriptabl scope object kei scope scriptabl object get top level scope scope for if scope instanceof scriptabl object scriptabl object so scriptabl object scope object valu so get associ valu kei if valu null return valu scope scope get prototyp if scope null return null associ arbitrari applic specif valu with thi object valu can onli be associ with the given object and kei onli onc the method ignor ani subsequ attempt to chang the alreadi associ valu p the associ valu ar not seril param kei kei object to select particular valu param valu the valu to associ return the pass valu if the method is call first time for the given kei or old valu for ani subsequ call see get associ valu object kei public final object associ valu object kei object valu if valu null throw new illeg argument except hashtabl h associ valu if h null synchron thi h associ valu if h null h new hashtabl associ valu h return kit init hash h kei valu privat object get by getter getter slot slot scriptabl start object getter thi object arg if slot deleg to null if start thi walk the prototyp chain to find an appropri object to invok the getter on class clazz slot getter get declar class while clazz is instanc start start start get prototyp if start thi break if start null start thi break getter thi start arg script runtim empti arg els getter thi slot deleg to arg new object thi return slot getter invok getter thi arg privat void set by setter getter slot slot scriptabl start object valu if start thi if slot deleg to null slot setter get declar class is instanc start start put slot string kei start valu return object setter thi object arg object setter result context cx context get context class p type slot setter arg type class desir p type p type length 1 alert cach tag sinc it is alreadi calcul in defin properti int tag function object get type tag desir object actual arg function object convert arg cx start valu tag if slot deleg to null setter thi start arg new object actual arg els if start thi kit code bug setter thi slot deleg to arg new object thi actual arg check start is seal start is alwai instanc of scriptabl object due to logic in if start thi abov if scriptabl object start is seal throw context report runtim error1 msg modifi seal slot string kei setter result slot setter invok setter thi arg if slot setter method get return type void type replac getter slot by a simpl on slot replac new slot replac int kei slot int kei replac string kei slot string kei replac attribut slot attribut replac valu setter result synchron thi int i get slot posit slot slot string kei slot int kei check slot wa not delet replac befor synchron if i 0 slot i slot slot i replac it is import to make sure that last access slot to prevent access the old slot via last access and then invok setter on more time last access replac privat slot get name slot string name queri last access cach and check that it wa not delet slot slot last access if name slot string kei slot wa delet 0 return slot int hash name hash code slot slot thi slot get stabl local refer int i get slot posit slot name hash if i 0 return null slot slot i updat cach here string kei equal name hold but it can be that slot string kei name to make last name cach work need to chang the kei slot string kei name last access slot return slot privat slot get slot string id int index slot slot thi slot get local copi int i get slot posit slot id index return i 0 null slot i privat static int get slot posit slot slot string id int index if slot null int start index 0x7fffffff slot length int i start do slot slot slot i if slot null break if slot remov slot int kei index slot string kei id id null id equal slot string kei return i if i slot length i 0 while i start return 1 add a new slot to the hash tabl thi method must be synchron sinc it is alter the hash tabl itself note that we search again for the slot to set sinc anoth thread could have ad the given properti or caus the tabl to grow while thi thread wa search privat synchron slot add slot string id int index slot new slot if is seal string str id null id integ to string index throw context report runtim error1 msg add seal str if slot null slot new slot 5 return add slot impl id index new slot must be insid synchron thi privat slot add slot impl string id int index slot new slot int start index 0x7fffffff slot length int i start for slot slot slot i if slot null slot remov if 4 count 1 3 slot length grow return add slot impl id index new slot slot new slot null new slot new slot slot string kei id slot int kei index slot i slot count return slot if slot int kei index slot string kei id id null id equal slot string kei return slot if i slot length i 0 if i start slot should never be full or bug in grow code throw new illeg state except remov a slot from the hash tabl thi method must be synchron sinc it is alter the hash tabl itself we might be abl to optim thi more but delet ar not common privat synchron void remov slot string name int index if is seal string str name null name integ to string index throw context report runtim error1 msg remov seal str int i get slot posit slot name index if i 0 slot slot slot i if slot attribut perman 0 mark the slot as remov to handl a case when anoth thread manag to put just remov slot into last access cach slot wa delet byte 1 if slot last access last access remov count if count 0 slot i remov els with no slot it is ok to mark with null slot i null must be insid synchron thi privat void grow slot new slot new slot slot length 2 1 for int j slot length 1 j 0 j slot slot slot j if slot null slot remov continu int k slot int kei 0x7fffffff new slot length while new slot k null if k new slot length k 0 the end of the synchron statement will caus the memori write to be propag on a multiprocessor machin we want to make sure that the new tabl is prepar to be read xxx caus the thi pointer to be null in call stack frame on the ms jvm synchron slot new slot k slot slot new slot object get id boolean get all slot s slot object a script runtim empti arg if s null return a int c 0 for int i 0 i s length i slot slot s i if slot null slot remov continu if get all slot attribut dontenum 0 if c 0 a new object s length i a c slot string kei null object slot string kei new integ slot int kei if c a length return a object result new object c system arraycopi a 0 result 0 c return result privat synchron void write object object output stream out throw io except out default write object int n count if n 0 n 1 count slot s slot if s null if n 0 kit code bug out write int 0 els out write int s length for int i 0 n 0 i slot slot s i if slot null slot remov n out write object slot privat void read object object input stream in throw io except class not found except in default read object last access remov int capac in read int if capac 0 slot new slot capac int n count boolean wa seal fals if n 0 n 1 n wa seal true count 0 for int i 0 i n i slot s slot in read object add slot impl s string kei s int kei s if wa seal count 1 count privat void read object object input stream in throw io except class not found except in default read object if string kei null int kei string kei hash code static void init scriptabl scope boolean seal nativ number obj new nativ number 0 0 obj export asj class max prototyp id scope seal privat nativ number doubl number doubl valu number public string get class name return number protect void fill constructor properti id function object ctor final int attr scriptabl object dontenum scriptabl object perman scriptabl object readonli ctor defin properti nan script runtim na nobj attr ctor defin properti posit infin script runtim wrap number doubl posit infin attr ctor defin properti neg infin script runtim wrap number doubl neg infin attr ctor defin properti max valu script runtim wrap number doubl max valu attr ctor defin properti min valu script runtim wrap number doubl min valu attr super fill constructor properti ctor protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 1 s to string break case id to local string ariti 1 s to local string break case id to sourc ariti 0 s to sourc break case id valu of ariti 0 s valu of break case id to fix ariti 1 s to fix break case id to exponenti ariti 1 s to exponenti break case id to precis ariti 1 s to precis break default throw new illeg argument except string valu of id init prototyp method number tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag number tag return super exec id call f cx scope thi obj arg int id f method id if id id constructor doubl val arg length 1 script runtim to number arg 0 0 0 if thi obj null new number val creat a new number object return new nativ number val number val convert val to a number valu return script runtim wrap number val the rest of number prototyp method requir thi obj to be number if thi obj instanceof nativ number throw incompat call error f doubl valu nativ number thi obj doubl valu switch id case id to string case id to local string to local string is just an alia for to string for now int base arg length 0 10 script runtim to int32 arg 0 return script runtim number to string valu base case id to sourc return new number script runtim to string valu case id valu of return script runtim wrap number valu case id to fix return num to valu arg d toa dtostr fix d toa dtostr fix 20 0 case id to exponenti return num to valu arg d toa dtostr standard exponenti d toa dtostr exponenti 0 1 case id to precis return num to valu arg d toa dtostr standard d toa dtostr precis 1 0 default throw new illeg argument except string valu of id public string to string return script runtim number to string doubl valu 10 privat static string num to doubl val object arg int zero arg mode int on arg mode int precis min int precis offset int precis if arg length 0 precis 0 on arg mode zero arg mode els we allow a larger rang of precis than ecma requir thi is permit by ecma precis script runtim to int32 arg 0 if precis precis min precis max precis string msg script runtim get messag1 msg bad precis script runtim to string arg 0 throw script runtim construct error rang error msg string buffer sb new string buffer d toa js dtostr sb on arg mode precis precis offset val return sb to string protect int find prototyp id string s int id gener last updat 2004 03 17 13 41 35 cet l0 id 0 string x null int c l switch s length case 7 c s char at 0 if c t x to fix id id to fix els if c v x valu of id id valu of break l case 8 c s char at 3 if c o x to sourc id id to sourc els if c t x to string id id to string break l case 11 c s char at 0 if c c x constructor id id constructor els if c t x to precis id id to precis break l case 13 x to exponenti id id to exponenti break l case 14 x to local string id id to local string break l if x null x s x equal s id 0 gener return id privat static final object import tag new object public import top level public import top level public import top level context cx thi cx fals public import top level context cx boolean seal init standard object cx seal public string get class name return top scope flag global java import public static void init context cx scriptabl scope boolean seal import top level obj new import top level obj export asj class max prototyp id scope seal public void init standard object context cx boolean seal assum that context init standard object initi java import properti lazili so the abov init call is not yet call cx init standard object thi seal top scope flag true if seal is true then export asj class cx seal would seal thi obj sinc thi is scope as well it would not allow to add variabl id function object ctor export asj class max prototyp id thi fals if seal ctor seal object delet constructor defin by export asj class so constructor name would refer to object constructor and not to java import prototyp constructor delet constructor public boolean ha string name scriptabl start return super ha name start get packag properti name start not found public object get string name scriptabl start object result super get name start if result not found return result result get packag properti name start return result privat object get packag properti string name scriptabl start object result not found object element synchron import packag element import packag to arrai for int i 0 i element length i nativ java packag p nativ java packag element i object v p get pkg properti name start fals if v null v instanceof nativ java packag if result not found result v els throw context report runtim error2 msg ambig import result to string v to string return result deprec kept onli for compat public void import packag context cx scriptabl thi obj object arg function fun obj js import packag arg privat object js construct scriptabl scope object arg import top level result new import top level for int i 0 i arg length i object arg arg i if arg instanceof nativ java class result import class nativ java class arg els if arg instanceof nativ java packag result import packag nativ java packag arg els throw context report runtim error1 msg not class not pkg context to string arg set explicitli prototyp and scope as otherwis in top scope mode base function construct would keep them set to null it also allow to us java import without new and still get properli initi object result set parent scope scope result set prototyp thi return result privat object js import class object arg for int i 0 i arg length i object arg arg i if arg instanceof nativ java class throw context report runtim error1 msg not class context to string arg import class nativ java class arg return undefin instanc privat object js import packag object arg for int i 0 i arg length i object arg arg i if arg instanceof nativ java packag throw context report runtim error1 msg not pkg context to string arg import packag nativ java packag arg return undefin instanc privat void import packag nativ java packag pkg synchron import packag for int j 0 j import packag size j if pkg import packag get j pkg null break if pkg null import packag add pkg privat void import class nativ java class cl string s cl get class object get name string n s substr s last index of 1 object val get n thi if val not found val cl throw context report runtim error1 msg prop defin n defin properti n cl dontenum put n thi cl protect void init prototyp id int id string s int ariti switch id case id constructor ariti 0 s constructor break case id import class ariti 1 s import class break case id import packag ariti 1 s import packag break default throw new illeg argument except string valu of id init prototyp method import tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag import tag return super exec id call f cx scope thi obj arg int id f method id switch id case id constructor return js construct scope arg case id import class return real thi thi obj f js import class arg case id import packag return real thi thi obj f js import packag arg throw new illeg argument except string valu of id privat import top level real thi scriptabl thi obj id function object f if top scope flag when us as top scope import packag and import class ar global function that ignor thi obj return thi if thi obj instanceof import top level throw incompat call error f return import top level thi obj protect int find prototyp id string s int id gener last updat 2004 06 08 02 03 11 cest l0 id 0 string x null int c int s length s length if s length 11 c s char at 0 if c c x constructor id id constructor els if c i x import class id id import class els if s length 13 x import packag id id import packag if x null x s x equal s id 0 gener return id creat a new context note that the context must be associ with a thread befor it can be us to execut a script see enter see call context action public context set languag version version default optim level codegen class null 0 1 maximum interpret stack depth integ max valu get the current context the current context is per thread thi method look up the context associ with the current thread p return the context associ with the current thread or null if no context is associ with the current thread see org mozilla javascript context enter see org mozilla javascript context exit public static context get current context object helper vm bridg instanc get thread context helper return vm bridg instanc get context helper get a context associ with the current thread creat on if need be the context store the execut state of the java script engin so it is requir that the context be enter befor execut mai begin onc a thread ha enter a context then get current context mai be call to find the context that is associ with the current thread p call code enter code will return either the context current associ with the thread or will creat a new context and associ it with the current thread each call to code enter code must have a match call to code exit code for exampl pre context cx context enter try cx evalu string final context exit pre instead of us tt enter tt tt exit tt pair consid us link call context action which guarante proper associ of context instanc with the current thread and is faster with thi method the abov exampl becom pre context call new context action public object run context cx cx evalu string return null pre return a context associ with the current thread see get current context see exit see call context action public static context enter return enter null get a context associ with the current thread us the given context if need be p the same as code enter code except that code cx code is associ with the current thread and return if the current thread ha no associ context and code cx code is not associ with ani other thread param cx a context to associ with the thread if possibl return a context associ with the current thread see enter see call context action see context factori call context action public static context enter context cx return enter cx context factori get global static final context enter context cx context factori factori object helper vm bridg instanc get thread context helper context old vm bridg instanc get context helper if old null if cx null cx old cx enter count 0 the supli context must be the context for the current thread if it is alreadi enter throw new illeg argument except cannot enter context activ on anoth thread if old factori null context with associ factori will be releas automat and doe not need to chang enter count return old if old seal on seal mutat cx old els if cx null cx factori make context els if cx seal on seal mutat if cx enter count 0 cx factori null throw new illeg state except if cx creation event wa sent cx creation event wa sent true factori on context creat cx if old null vm bridg instanc set context helper cx cx enter count return cx exit a block of code requir a context call code exit code will remov the associ between the current thread and a context if the prior call to code enter code on thi thread newli associ a context with thi thread onc the current thread no longer ha an associ context it cannot be us to execut java script until it is again associ with a context see org mozilla javascript context enter see call context action see context factori call context action public static void exit exit context factori get global static void exit context factori factori object helper vm bridg instanc get thread context helper context cx vm bridg instanc get context helper if cx null throw new illeg state except call context exit without previou context enter if cx factori null context with associ factori will be releas automat and doe not need to chang enter count return if cx enter count 1 kit code bug if cx seal on seal mutat cx enter count if cx enter count 0 vm bridg instanc set context helper null factori on context releas cx call link context action run context cx us the context instanc associ with the current thread if no context is associ with the thread then tt context factori get global make context tt will be call to construct new context instanc the instanc will be temporari associ with the thread dure call to link context action run context return the result of link context action run context public static object call context action action return call context factori get global action call link callabl call context cx scriptabl scope scriptabl thi obj object arg us the context instanc associ with the current thread if no context is associ with the thread then link context factori make context will be call to construct new context instanc the instanc will be temporari associ with the thread dure call to link context action run context p it is allow to us null for tt factori tt argument in which case the factori associ with the scope will be us to creat new context instanc see context factori call context action public static object call context factori factori callabl callabl scriptabl scope scriptabl thi obj object arg if factori null factori context factori get global object helper vm bridg instanc get thread context helper context cx vm bridg instanc get context helper if cx null object result if cx factori null result callabl call cx scope thi obj arg els context wa associ with the thread via context enter set factori to make context enter exit to be no op dure call cx factori factori try result callabl call cx scope thi obj arg final cx factori null return result cx prepar new context factori helper try return callabl call cx scope thi obj arg final releas context helper cx the method implement link context factori call context action logic static object call context factori factori context action action object helper vm bridg instanc get thread context helper context cx vm bridg instanc get context helper if cx null if cx factori null return action run cx els cx factori factori try return action run cx final cx factori null cx prepar new context factori helper try return action run cx final releas context helper cx privat static context prepar new context context factori factori object context helper context cx factori make context if cx factori null cx enter count 0 throw new illeg state except factori make context return context instanc alreadi associ with some thread cx factori factori factori on context creat cx if factori is seal cx is seal cx seal null vm bridg instanc set context context helper cx return cx privat static void releas context object context helper context cx vm bridg instanc set context context helper null try cx factori on context releas cx final cx factori null deprec see context factori add listen context factori listen see context factori get global public static void add context listen context listen listen special workaround for the debugg string dbg org mozilla javascript tool debugg main if dbg equal listen get class get name class cl listen get class class factori class kit class or null org mozilla javascript context factori class sig factori class object arg context factori get global try method m cl get method attach to sig m invok listen arg catch except ex runtim except rex new runtim except kit init caus rex ex throw rex return context factori get global add listen listen deprec see context factori remov listen context factori listen see context factori get global public static void remov context listen context listen listen context factori get global add listen listen return link context factori instanc us to creat thi context or the result of link context factori get global if no factori wa us for context creation public final context factori get factori context factori result factori if result null result context factori get global return result check if thi is a seal context a seal context instanc doe not allow to modifi ani of it properti and will throw an except on ani such attempt see seal object seal kei public final boolean is seal return seal seal thi context object so ani attempt to modifi ani of it properti includ call link enter and link exit method will throw an except p if tt seal kei tt is not null call link unseal object seal kei with the same kei unseal the object if tt seal kei tt is null unseal is no longer possibl see is seal see unseal object public final void seal object seal kei if seal on seal mutat seal true thi seal kei seal kei unseal previous seal context object the tt seal kei tt argument should not be null and should match tt seal kei tt supli with the last call to link seal object or an except will be thrown see is seal see seal object seal kei public final void unseal object seal kei if seal kei null throw new illeg argument except if thi seal kei seal kei throw new illeg argument except if seal throw new illeg state except seal fals thi seal kei null static void on seal mutat throw new illeg state except get the current languag version p the languag version number affect java script semant as detail in the overview document return an integ that is on of version 1 0 version 1 1 etc public final int get languag version return version set the languag version p set the languag version will affect function and script compil subsequ see the overview document for version specif behavior param version the version as specifi by version 1 0 version 1 1 etc public void set languag version int version if seal on seal mutat check languag version version object listen properti listen if listen null version thi version fire properti chang impl listen languag version properti new integ thi version new integ version thi version version public static boolean is valid languag version int version switch version case version default case version 1 0 case version 1 1 case version 1 2 case version 1 3 case version 1 4 case version 1 5 case version 1 6 return true return fals public static void check languag version int version if is valid languag version version return throw new illeg argument except bad languag version version get the implement version p the implement version is of the form pre i name lang ver i code releas code i rel num date i pre where i name i is the name of the product i lang ver i is the languag version i rel num i is the releas number and i date i is the releas date for that specif releas in the form yyyi mm dd return a string that encod the product languag version releas number and date public final string get implement version xxx probabl it would be better to emb thi directli into sourc with special build preprocess but that would requir some ant tweak and then replac token in resourc file wa simpler if implement version null implement version script runtim get messag0 implement version return implement version get the current error report see org mozilla javascript error report public final error report get error report if error report null return default error report instanc return error report chang the current error report return the previou error report see org mozilla javascript error report public final error report set error report error report report if seal on seal mutat if report null throw new illeg argument except error report old get error report if report old return old object listen properti listen if listen null fire properti chang impl listen error report properti old report thi error report report return old get the current local return the default local if none ha been set see java util local public final local get local if local null local local get default return local set the current local see java util local public final local set local local loc if seal on seal mutat local result local local loc return result regist an object to receiv notif when a bound properti ha chang see java bean properti chang event see remov properti chang listen java bean properti chang listen param l the listen public final void add properti chang listen properti chang listen l if seal on seal mutat properti listen kit add listen properti listen l remov an object from the list of object regist to receiv notif of chang to a bound properti see java bean properti chang event see add properti chang listen java bean properti chang listen param l the listen public final void remov properti chang listen properti chang listen l if seal on seal mutat properti listen kit remov listen properti listen l notifi ani regist listen that a bound properti ha chang see add properti chang listen java bean properti chang listen see remov properti chang listen java bean properti chang listen see java bean properti chang listen see java bean properti chang event param properti the bound properti param old valu the old valu param new vale the new valu final void fire properti chang string properti object old valu object new valu object listen properti listen if listen null fire properti chang impl listen properti old valu new valu privat void fire properti chang impl object listen string properti object old valu object new valu for int i 0 i object l kit get listen listen i if l null break if l instanceof properti chang listen properti chang listen pcl properti chang listen l pcl properti chang new properti chang event thi properti old valu new valu report a warn us the error report for the current thread param messag the warn messag to report param sourc name a string describ the sourc such as a filenam param lineno the start line number param line sourc the text of the line mai be null param line offset the offset into line sourc where problem wa detect see org mozilla javascript error report public static void report warn string messag string sourc name int lineno string line sourc int line offset context cx context get context cx get error report warn messag sourc name lineno line sourc line offset report a warn us the error report for the current thread param messag the warn messag to report see org mozilla javascript error report public static void report warn string messag int linep 0 string filenam get sourc posit from stack linep context report warn messag filenam linep 0 null 0 report an error us the error report for the current thread param messag the error messag to report param sourc name a string describ the sourc such as a filenam param lineno the start line number param line sourc the text of the line mai be null param line offset the offset into line sourc where problem wa detect see org mozilla javascript error report public static void report error string messag string sourc name int lineno string line sourc int line offset context cx get current context if cx null cx get error report error messag sourc name lineno line sourc line offset els throw new evalu except messag sourc name lineno line sourc line offset report an error us the error report for the current thread param messag the error messag to report see org mozilla javascript error report public static void report error string messag int linep 0 string filenam get sourc posit from stack linep context report error messag filenam linep 0 null 0 report a runtim error us the error report for the current thread param messag the error messag to report param sourc name a string describ the sourc such as a filenam param lineno the start line number param line sourc the text of the line mai be null param line offset the offset into line sourc where problem wa detect return a runtim except that will be thrown to termin the execut of the script see org mozilla javascript error report public static evalu except report runtim error string messag string sourc name int lineno string line sourc int line offset context cx get current context if cx null return cx get error report runtim error messag sourc name lineno line sourc line offset els throw new evalu except messag sourc name lineno line sourc line offset static evalu except report runtim error0 string messag id string msg script runtim get messag0 messag id return report runtim error msg static evalu except report runtim error1 string messag id object arg1 string msg script runtim get messag1 messag id arg1 return report runtim error msg static evalu except report runtim error2 string messag id object arg1 object arg2 string msg script runtim get messag2 messag id arg1 arg2 return report runtim error msg static evalu except report runtim error3 string messag id object arg1 object arg2 object arg3 string msg script runtim get messag3 messag id arg1 arg2 arg3 return report runtim error msg static evalu except report runtim error4 string messag id object arg1 object arg2 object arg3 object arg4 string msg script runtim get messag4 messag id arg1 arg2 arg3 arg4 return report runtim error msg report a runtim error us the error report for the current thread param messag the error messag to report see org mozilla javascript error report public static evalu except report runtim error string messag int linep 0 string filenam get sourc posit from stack linep return context report runtim error messag filenam linep 0 null 0 initi the standard object creat instanc of the standard object and their constructor object string number date etc set up scope to act as a global object as in ecma 15 1 p thi method must be call to initi a scope befor script can be evalu in that scope p thi method doe not affect the context it is call upon return the initi scope public final scriptabl object init standard object return init standard object null fals initi the standard object creat instanc of the standard object and their constructor object string number date etc set up scope to act as a global object as in ecma 15 1 p thi method must be call to initi a scope befor script can be evalu in that scope p thi method doe not affect the context it is call upon param scope the scope to initi or null in which case a new object will be creat to serv as the scope return the initi scope the method return the valu of the scope argument if it is not null or newli alloc scope object which is an instanc link scriptabl object public final scriptabl init standard object scriptabl object scope return init standard object scope fals initi the standard object creat instanc of the standard object and their constructor object string number date etc set up scope to act as a global object as in ecma 15 1 p thi method must be call to initi a scope befor script can be evalu in that scope p thi method doe not affect the context it is call upon p thi form of the method also allow for creat seal standard object an object that is seal cannot have properti ad chang or remov thi is us to creat a superglob that can be share among sever top level object note that seal is not allow in the current ecma iso languag specif but is like for the next version param scope the scope to initi or null in which case a new object will be creat to serv as the scope param seal whether or not to creat seal standard object that cannot be modifi return the initi scope the method return the valu of the scope argument if it is not null or newli alloc scope object sinc 1 4r3 public scriptabl object init standard object scriptabl object scope boolean seal return script runtim init standard object thi scope seal get the singleton object that repres the java script undefin valu public static object get undefin valu return undefin instanc evalu a java script sourc string the provid sourc name and line number ar us for error messag and for produc debug inform param scope the scope to execut in param sourc the java script sourc param sourc name a string describ the sourc such as a filenam param lineno the start line number param secur domain an arbitrari object that specifi secur inform about the origin or owner of the script for implement that don t care about secur thi valu mai be null return the result of evalu the string see org mozilla javascript secur control public final object evalu string scriptabl scope string sourc string sourc name int lineno object secur domain script script compil string sourc sourc name lineno secur domain if script null return script exec thi scope els return null evalu a reader as java script sourc all charact of the reader ar consum param scope the scope to execut in param in the reader to get java script sourc from param sourc name a string describ the sourc such as a filenam param lineno the start line number param secur domain an arbitrari object that specifi secur inform about the origin or owner of the script for implement that don t care about secur thi valu mai be null return the result of evalu the sourc except io except if an io except wa gener by the reader public final object evalu reader scriptabl scope reader in string sourc name int lineno object secur domain throw io except script script compil reader scope in sourc name lineno secur domain if script null return script exec thi scope els return null check whether a string is readi to be compil p string is compil unit is intend to support interact compil of javascript if compil the string would result in an error that might be fix by append more sourc thi method return fals in everi other case it return true p interact shell mai accumul sourc line us thi method after each new line is append to check whether the statement be enter is complet param sourc the sourc buffer to check return whether the sourc is readi for compil sinc 1 4 releas 2 public final boolean string is compil unit string sourc boolean errorseen fals compil environ compil env new compil environ compil env init from context thi no sourc name or sourc text manag becaus we re just go to throw awai the result compil env set gener sourc fals parser p new parser compil env default error report instanc try p pars sourc null 1 catch evalu except ee errorseen true return fals onli if an error occur as a result of read past the end of the file i e if the sourc could be fix by append more sourc if errorseen p eof return fals els return true deprec see compil reader reader in string sourc name int lineno object secur domain public final script compil reader scriptabl scope reader in string sourc name int lineno object secur domain throw io except return compil reader in sourc name lineno secur domain compil the sourc in the given reader p return a script that mai later be execut will consum all the sourc in the reader param in the input reader param sourc name a string describ the sourc such as a filenam param lineno the start line number for report error param secur domain an arbitrari object that specifi secur inform about the origin or owner of the script for implement that don t care about secur thi valu mai be null return a script that mai later be execut except io except if an io except wa gener by the reader see org mozilla javascript script public final script compil reader reader in string sourc name int lineno object secur domain throw io except if lineno 0 for compat illeg argument except can not be thrown here lineno 0 return script compil impl null in null sourc name lineno secur domain fals null null compil the sourc in the given string p return a script that mai later be execut param sourc the sourc string param sourc name a string describ the sourc such as a filenam param lineno the start line number for report error param secur domain an arbitrari object that specifi secur inform about the origin or owner of the script for implement that don t care about secur thi valu mai be null return a script that mai later be execut see org mozilla javascript script public final script compil string string sourc string sourc name int lineno object secur domain if lineno 0 for compat illeg argument except can not be thrown here lineno 0 return compil string sourc null null sourc name lineno secur domain final script compil string string sourc interpret compil error report compil error report string sourc name int lineno object secur domain try return script compil impl null null sourc sourc name lineno secur domain fals compil compil error report catch io except ex should not happen when deal with sourc as string throw new runtim except compil a java script function p the function sourc must be a function definit as defin by ecma e g function f a return a param scope the scope to compil rel to param sourc the function definit sourc param sourc name a string describ the sourc such as a filenam param lineno the start line number param secur domain an arbitrari object that specifi secur inform about the origin or owner of the script for implement that don t care about secur thi valu mai be null return a function that mai later be call see org mozilla javascript function public final function compil function scriptabl scope string sourc string sourc name int lineno object secur domain return compil function scope sourc null null sourc name lineno secur domain final function compil function scriptabl scope string sourc interpret compil error report compil error report string sourc name int lineno object secur domain try return function compil impl scope null sourc sourc name lineno secur domain true compil compil error report catch io except ioe should never happen becaus we just made the reader from a string throw new runtim except decompil the script p the canon sourc of the script is return param script the script to decompil param indent the number of space to indent the result return a string repres the script sourc public final string decompil script script script int indent nativ function script impl nativ function script return script impl decompil indent 0 decompil a java script function p decompil a previous compil java script function object to canon sourc p return function bodi of nativ code if no decompil inform is avail param fun the java script function to decompil param indent the number of space to indent the result return a string repres the function sourc public final string decompil function function fun int indent if fun instanceof base function return base function fun decompil indent 0 els return function fun get class name n t nativ code n n decompil the bodi of a java script function p decompil the bodi a previous compil java script function object to canon sourc omit the function header and trail brace return nativ code if no decompil inform is avail param fun the java script function to decompil param indent the number of space to indent the result return a string repres the function bodi sourc public final string decompil function bodi function fun int indent if fun instanceof base function base function bf base function fun return bf decompil indent decompil onli bodi flag alert not sure what the right respons here is return nativ code n creat a new java script object equival to evalu new object param scope the scope to search for the constructor and to evalu against return the new object public final scriptabl new object scriptabl scope return new object scope object script runtim empti arg creat a new java script object by execut the name constructor the call code new object scope foo code is equival to evalu new foo param scope the scope to search for the constructor and to evalu against param constructor name the name of the constructor to call return the new object public final scriptabl new object scriptabl scope string constructor name return new object scope constructor name script runtim empti arg creat a new java script object by execut the name constructor search code scope code for the name constructor call it with the given argument and return the result p the code pre object arg a b new object scope foo arg pre is equival to evalu new foo a b assum that the foo constructor ha been defin in code scope code param scope the scope to search for the constructor and to evalu against param constructor name the name of the constructor to call param arg the arrai of argument for the constructor return the new object public final scriptabl new object scriptabl scope string constructor name object arg scope scriptabl object get top level scope scope function ctor script runtim get exist ctor thi scope constructor name if arg null arg script runtim empti arg return ctor construct thi scope arg creat an arrai with a specifi initi length p param scope the scope to creat the object in param length the initi length java script arrai mai have addit properti ad dynam return the new arrai object public final scriptabl new arrai scriptabl scope int length nativ arrai result new nativ arrai length script runtim set object proto and parent result scope return result creat an arrai with a set of initi element param scope the scope to creat the object in param element the initi element each object in thi arrai must be an accept java script type and type of arrai should be exactli object not some object subclass return the new arrai object public final scriptabl new arrai scriptabl scope object element if element get class get compon type script runtim object class throw new illeg argument except nativ arrai result new nativ arrai element script runtim set object proto and parent result scope return result get the element of a java script arrai p if the object defin a length properti convert to doubl number then the number is convert uint32 valu as defin in ecma 9 6 and java arrai of that size is alloc the arrai is initi with the valu obtain by call get on object for each valu of i in 0 length 1 if there is not a defin valu for a properti the undefin valu is us to initi the correspond element in the arrai the java arrai is then return if the object doesn t defin a length properti or it is not a number empti arrai is return param object the java script arrai or arrai like object return a java arrai of object sinc 1 4 releas 2 public final object get element scriptabl object return script runtim get arrai element object convert the valu to a java script boolean valu p see ecma 9 2 param valu a java script valu return the correspond boolean valu convert us the ecma rule public static boolean to boolean object valu return script runtim to boolean valu convert the valu to a java script number valu p return a java doubl for the java script number p see ecma 9 3 param valu a java script valu return the correspond doubl valu convert us the ecma rule public static doubl to number object valu return script runtim to number valu convert the valu to a java script string valu p see ecma 9 8 p param valu a java script valu return the correspond string valu convert us the ecma rule public static string to string object valu return script runtim to string valu convert the valu to an java script object valu p note that a scope must be provid to look up the constructor for number boolean and string p see ecma 9 9 p addition arbitrari java object and class will be wrap in a scriptabl object with it java field and method reflect as java script properti of the object param valu ani java object param scope global scope contain constructor for number boolean and string return new java script object public static scriptabl to object object valu scriptabl scope return script runtim to object scope valu deprec see to object object scriptabl public static scriptabl to object object valu scriptabl scope class static type return script runtim to object scope valu conveni method to convert java valu to it closest represent in java script p if valu is an instanc of string number boolean function or scriptabl it is return as it and will be treat as the correspond java script type of string number boolean function and object p note that for number instanc dure ani arithmet oper in java script the engin will alwai us the result of tt number doubl valu tt result in a precis loss if the number can not fit into doubl p if valu is an instanc of charact it will be convert to string of length 1 and it java script type will be string p the rest of valu will be wrap as live connect object by call link wrap factori wrap context cx scriptabl scope object obj class static type as in pre context cx context get current context return cx get wrap factori wrap cx scope valu null pre param valu ani java object param scope top scope object return valu suitabl to pass to ani api that take java script valu public static object java toj object valu scriptabl scope if valu instanceof string valu instanceof number valu instanceof boolean valu instanceof scriptabl return valu els if valu instanceof charact return string valu of charact valu char valu els context cx context get context return cx get wrap factori wrap cx scope valu null convert a java script valu into the desir type us the semant defin with live connect3 and throw an illeg argument except if the convers cannot be perform param valu the java script valu to convert param desir type the java type to convert to primit java type ar repres us the type field in the correspond wrapper class in java lang return the convert valu throw evalu except if the convers cannot be perform public static object js to java object valu class desir type throw evalu except return nativ java object coerc type impl desir type valu deprec see js to java object class throw illeg argument except if the convers cannot be perform note that link js to java object class throw link evalu except instead public static object to type object valu class desir type throw illeg argument except try return js to java valu desir type catch evalu except ex illeg argument except ex2 new illeg argument except ex get messag kit init caus ex2 ex throw ex2 rethrow the except wrap it as the script runtim except unless the except is instanc of link ecma error or link evalu except it will be wrap as link wrap except a subclass of link evalu except the result except object alwai contain sourc name and line number of script that trigger except p thi method alwai throw an except it return valu is provid onli for conveni to allow a usag like pre throw context throw as script runtim ex ex pre to indic that code after the method is unreach throw evalu except throw ecma error public static runtim except throw as script runtim ex throwabl e while e instanceof invoc target except e invoc target except e get target except special handl of error so script would not catch them if e instanceof error throw error e if e instanceof rhino except throw rhino except e throw new wrap except e tell whether debug inform is be gener sinc 1 3 public final boolean is gener debug return gener debug specifi whether or not debug inform should be gener p set the gener of debug inform on will set the optim level to zero sinc 1 3 public final void set gener debug boolean gener debug if seal on seal mutat gener debug chang true if gener debug get optim level 0 set optim level 0 thi gener debug gener debug tell whether sourc inform is be gener sinc 1 3 public final boolean is gener sourc return gener sourc specifi whether or not sourc inform should be gener p without sourc inform evalu the to string method on java script function produc onli nativ code for the bodi of the function note that code gener without sourc is not fulli ecma conform sinc 1 3 public final void set gener sourc boolean gener sourc if seal on seal mutat thi gener sourc gener sourc get the current optim level p the optim level is express as an integ between 1 and 9 sinc 1 3 public final int get optim level return optim level set the current optim level p the optim level is expect to be an integ between 1 and 9 ani neg valu will be interpret as 1 and ani valu greater than 9 will be interpret as 9 an optim level of 1 indic that interpret mode will alwai be us level 0 through 9 indic that class file mai be gener higher optim level trade off compil time perform for runtim perform the optim level can t be set greater than 1 if the optim packag doesn t exist at run time param optim level an integ indic the level of optim to perform sinc 1 3 public final void set optim level int optim level if seal on seal mutat if optim level 2 to be compat with cocoon fork optim level 1 check optim level optim level if codegen class null optim level 1 thi optim level optim level public static boolean is valid optim level int optim level return 1 optim level optim level 9 public static void check optim level int optim level if is valid optim level optim level return throw new illeg argument except optim level outsid 1 9 optim level return the maximum stack depth in term of number of call frame allow in a singl invoc of interpret if the set depth would be exceed the interpret will throw an evalu except in the script default to integ max valu the set onli ha effect for interpret function those compil with optim level set to 1 as the interpret doesn t us the java stack but rather manag it own stack in the heap memori a runawai recurs in interpret code would eventu consum all avail memori and caus out of memori error instead of a stack overflow error limit to onli a singl thread thi set help prevent such situat return the current maximum interpret stack depth public final int get maximum interpret stack depth return maximum interpret stack depth set the maximum stack depth in term of number of call frame allow in a singl invoc of interpret if the set depth would be exceed the interpret will throw an evalu except in the script default to integ max valu the set onli ha effect for interpret function those compil with optim level set to 1 as the interpret doesn t us the java stack but rather manag it own stack in the heap memori a runawai recurs in interpret code would eventu consum all avail memori and caus out of memori error instead of a stack overflow error limit to onli a singl thread thi set help prevent such situat param max the new maximum interpret stack depth throw illeg state except if thi context s optim level is not 1 throw illeg argument except if the new depth is not at least 1 public final void set maximum interpret stack depth int max if seal on seal mutat if optim level 1 throw new illeg state except cannot set maximum interpret stack depth when optim level 1 if max 1 throw new illeg argument except cannot set maximum interpret stack depth to less than 1 maximum interpret stack depth max set the secur control for thi context p secur control mai onli be set if it is current null and link secur control ha global is tt fals tt otherwis a secur except is thrown param control a secur control object throw secur except if there is alreadi a secur control object for thi context or global instal see secur control init global secur control control see secur control ha global public final void set secur control secur control control if seal on seal mutat if control null throw new illeg argument except if secur control null throw new secur except can not overwrit exist secur control object if secur control ha global throw new secur except can not overwrit exist global secur control object secur control control set the live connect access filter for thi context p link class shutter mai onli be set if it is current null otherwis a secur except is thrown param shutter a class shutter object throw secur except if there is alreadi a class shutter object for thi context public final void set class shutter class shutter shutter if seal on seal mutat if shutter null throw new illeg argument except if class shutter null throw new secur except cannot overwrit exist class shutter object class shutter shutter final class shutter get class shutter return class shutter get a valu correspond to a kei p sinc the context is associ with a thread it can be us to maintain valu that can be later retriev us the current thread p note that the valu ar maintain with the context so if the context is disassoci from the thread the valu cannot be retreiv also if privat data is to be maintain in thi manner the kei should be a java lang object whose refer is not divulg to untrust code param kei the kei us to lookup the valu return a valu previous store us put thread local public final object get thread local object kei if hashtabl null return null return hashtabl get kei put a valu that can later be retriev us a given kei p param kei the kei us to index the valu param valu the valu to save public final void put thread local object kei object valu if seal on seal mutat if hashtabl null hashtabl new hashtabl hashtabl put kei valu remov valu from thread local storag param kei the kei for the entri to remov sinc 1 5 releas 2 public final void remov thread local object kei if seal on seal mutat if hashtabl null return hashtabl remov kei deprec see featur dynam scope see ha featur int public final boolean ha compil function with dynam scope return compil function with dynam scope flag deprec see featur dynam scope see ha featur int public final void set compil function with dynam scope boolean flag if seal on seal mutat compil function with dynam scope flag flag deprec see class cach get scriptabl see class cach set cach enabl boolean public static void set cach enabl boolean cach enabl set a wrap factori for thi context p the wrap factori allow custom object wrap behavior for java object manipul with java script see wrap factori sinc 1 5 releas 4 public final void set wrap factori wrap factori wrap factori if seal on seal mutat if wrap factori null throw new illeg argument except thi wrap factori wrap factori return the current wrap factori or null if none is defin see wrap factori sinc 1 5 releas 4 public final wrap factori get wrap factori if wrap factori null wrap factori new wrap factori return wrap factori return the current debugg return the debugg or null if none is attach public final debugg get debugg return debugg return the debugg context data associ with current context return the debugg data or null if debugg is not attach public final object get debugg context data return debugg data set the associ debugg param debugg the debugg to be us on callback from the engin param context data arbitrari object that debugg can us to store per context data public final void set debugg debugg debugg object context data if seal on seal mutat thi debugg debugg debugg data context data return debugg script instanc if ani associ with the script if callabl support debugg script implement the method return it otherwis null is return public static debugg script get debugg view script script if script instanceof nativ function return nativ function script get debugg view return null control certain aspect of script semant should be overwritten to alter default behavior p the default implement call link context factori ha featur context cx int featur index that allow to custom context behavior without introduc context subclass link context factori document give an exampl of ha featur implement param featur index featur index to check return true if the code featur index code featur is turn on see featur non ecma get year see featur member expr as function name see featur reserv keyword as identifi see featur to string as sourc see featur parent proto proprti see featur e4x see featur dynam scope see featur strict var see featur strict eval public boolean ha featur int featur index context factori f get factori return f ha featur thi featur index get set threshold of execut instruct counter that trigger call to code observ instruct count code when the threshold is zero instruct count is disabl otherwis each time the run time execut at least the threshold valu of script instruct code observ instruct count code will be call public final int get instruct observ threshold return instruct threshold public final void set instruct observ threshold int threshold if seal on seal mutat if threshold 0 throw new illeg argument except instruct threshold threshold allow applic to monitor counter of execut script instruct in context subclass run time call thi when instruct count is enabl and the counter reach limit set by code set instruct observ threshold code the method is us to observ long run script and if necessari to termin them p the instruct count support is avail onli for interpret script gener when the optim level is set to 1 p the default implement call link context factori observ instruct count context cx int instruct count that allow to custom context behavior without introduc context subclass param instruct count amount of script instruct execut sinc last call to code observ instruct count code throw error to termin the script see set optim level int protect void observ instruct count int instruct count context factori f get factori f observ instruct count thi instruct count creat class loader for gener class the method call link context factori creat class loader class loader us the result of link get factori public gener class loader creat class loader class loader parent context factori f get factori return f creat class loader parent public final class loader get applic class loader if applic class loader null context factori f get factori class loader loader f get applic class loader if loader null class loader thread loader vm bridg instanc get current thread class loader if thread loader null kit test if can load rhino class thread loader thread get context class loader is not cach sinc it cach prevent it from gc which mai lead to a memori leak and hide updat to thread get context class loader return thread loader thread get context class loader can not load rhino class try to us the loader of context factori or context subclass class f class f get class if f class script runtim context factori class loader f class get class loader els loader get class get class loader applic class loader loader return applic class loader public final void set applic class loader class loader loader if seal on seal mutat if loader null restor default behaviour applic class loader null return if kit test if can load rhino class loader throw new illeg argument except loader can not resolv rhino class applic class loader loader intern method that report an error for miss call to enter static context get context context cx get current context if cx null throw new runtim except no context associ with current thread return cx privat object compil impl scriptabl scope reader sourc reader string sourc string string sourc name int lineno object secur domain boolean return function interpret compil error report compil error report throw io except if secur domain null secur control null throw new illeg argument except secur domain should be null if set secur control wa never call on of sourc reader or sourc string ha to be null if sourc reader null sourc string null kit code bug scope should be given if and onli if compil function if scope null return function kit code bug compil environ compil env new compil environ compil env init from context thi if compil error report null compil error report compil env get error report if debugg null if sourc reader null sourc string kit read reader sourc reader sourc reader null parser p new parser compil env compil error report if return function p call by compil function true script or fn node tree if sourc string null tree p pars sourc string sourc name lineno els tree p pars sourc reader sourc name lineno if return function if tree get function count 1 tree get first child null tree get first child get type token function xxx the check just look for the first child and allow for more node after it for compat with sourc like function throw new illeg argument except compil function onli accept sourc with singl js function sourc string if compil null compil creat compil string encod sourc p get encod sourc object bytecod compil compil compil env tree encod sourc return function if debugg null if sourc string null kit code bug if bytecod instanceof debugg script debugg script dscript debugg script bytecod notifi debugg r thi dscript sourc string els throw new runtim except not support object result if return function result compil creat function object thi scope bytecod secur domain els result compil creat script object bytecod secur domain return result privat static void notifi debugg r context cx debugg script dscript string debug sourc cx debugg handl compil done cx dscript debug sourc for int i 0 i dscript get function count i notifi debugg r cx dscript get function i debug sourc privat interpret creat compil interpret result null if optim level 0 codegen class null result interpret kit new instanc or null codegen class if result null result new interpret return result static string get sourc posit from stack int linep context cx get current context if cx null return null if cx last interpret frame null return interpret get sourc posit from stack cx linep a bit of a hack but the onli wai to get filenam and line number from an enclos frame char arrai writer writer new char arrai writer runtim except re new runtim except re print stack trace new print writer writer string s writer to string int open 1 int close 1 int colon 1 for int i 0 i s length i char c s char at i if c colon i els if c open i els if c close i els if c n open 1 close 1 colon 1 open colon colon close string file str s substr open 1 colon if file str end with java string line str s substr colon 1 close try linep 0 integ pars int line str if linep 0 0 linep 0 0 return file str catch number format except e fall through open close colon 1 return null reg exp proxi get reg exp proxi if reg exp proxi null class cl kit class or null org mozilla javascript regexp reg exp impl if cl null reg exp proxi reg exp proxi kit new instanc or null cl return reg exp proxi final boolean is versionecma1 return version version default version version 1 3 the method must not be public or protect secur control get secur control secur control global secur control global if global null return global return secur control public final boolean is gener debug chang return gener debug chang add a name to the list of name forc the creation of real activ object for function param name the name of the object to add to the list public void add activ name string name if seal on seal mutat if activ name null activ name new hashtabl 5 activ name put name name check whether the name is in the list of name of object forc the creation of activ object param name the name of the object to test return true if an function activ object is need public final boolean is activ need string name return activ name null activ name contain kei name remov a name from the list of name forc the creation of real activ object for function param name the name of the object to remov from the list public void remov activ name string name if seal on seal mutat if activ name null activ name remov name public static void defin class scriptabl object scope try scriptabl object defin class scope environ class catch except e throw new error e get messag public string get class name return environ public environ if the prototyp instanc null the prototyp instanc thi public environ scriptabl object scope set parent scope scope object ctor script runtim get top level prop scope environ if ctor null ctor instanceof scriptabl scriptabl s scriptabl ctor set prototyp scriptabl s get prototyp s public boolean ha string name scriptabl start if thi the prototyp instanc return super ha name start return system get properti name null public object get string name scriptabl start if thi the prototyp instanc return super get name start string result system get properti name if result null return script runtim to object get parent scope result els return scriptabl not found public void put string name scriptabl start object valu if thi the prototyp instanc super put name start valu els system get properti put name script runtim to string valu privat object collect id properti prop system get properti enumer name prop properti name vector kei new vector while name ha more element kei add element name next element object id new object kei size kei copi into id return id public object get id if thi the prototyp instanc return super get id return collect id public object get all id if thi the prototyp instanc return super get all id return collect id public parser compil environ compil env error report error report thi compil env compil env thi error report error report protect decompil creat decompil compil environ compil env return new decompil void add warn string messag id string messag arg string messag script runtim get messag1 messag id messag arg error report warn messag sourceuri ts get lineno ts get line ts get offset void add error string messag id syntax error count string messag script runtim get messag0 messag id error report error messag sourceuri ts get lineno ts get line ts get offset runtim except report error string messag id add error messag id throw a parser except except to unwind the recurs descent pars throw new parser except privat int peek token throw io except int tt current flag token if tt token eof tt ts get token if tt token eol do tt ts get token while tt token eol tt ti after eol current flag token tt return tt clear ti mask privat int peek flag token throw io except peek token return current flag token privat void consum token current flag token token eof privat int next token throw io except int tt peek token consum token return tt privat int next flag token throw io except peek token int tt flag current flag token consum token return tt flag privat boolean match token int to match throw io except int tt peek token if tt to match return fals consum token return true privat int peek token oreol throw io except int tt peek token check for last peek token flag if current flag token ti after eol 0 tt token eol return tt privat void set check for label if current flag token clear ti mask token name throw kit code bug current flag token ti check label privat void must match token int to match string messag id throw io except parser except if match token to match report error messag id privat void must havexml if compil env is xml avail report error msg xml not avail public string get encod sourc return encod sourc public boolean eof return ts eof boolean insid function return nest of function 0 privat node enter loop node loop label node loop nf creat loop node loop label ts get lineno if loop set null loop set new obj arrai if loop and switch set null loop and switch set new obj arrai loop set push loop loop and switch set push loop return loop privat void exit loop loop set pop loop and switch set pop privat node enter switch node switch selector int lineno node switch label node switch node nf creat switch switch selector lineno if loop and switch set null loop and switch set new obj arrai loop and switch set push switch node return switch node privat void exit switch loop and switch set pop public script or fn node pars string sourc string string sourceuri int lineno thi sourceuri sourceuri thi ts new token stream thi null sourc string lineno try return pars catch io except ex should never happen throw new illeg state except public script or fn node pars reader sourc reader string sourceuri int lineno throw io except thi sourceuri sourceuri thi ts new token stream thi sourc reader null lineno return pars privat script or fn node pars throw io except thi decompil creat decompil compil env thi nf new ir factori thi current script or fn nf creat script int sourc start offset decompil get current offset thi encod sourc null decompil add token token script thi current flag token token eof thi syntax error count 0 int base lineno ts get lineno line number where sourc start so we have someth to add node to until we ve collect all the sourc node pn nf creat leaf token block try for int tt peek token if tt token eof break node n if tt token function consum token try n function call by compil function function node function express function node function statement catch parser except e break els n statement nf add child to back pn n catch stack overflow error ex string msg script runtim get messag0 mag too deep parser recurs throw context report runtim error msg sourceuri ts get lineno null 0 if thi syntax error count 0 string msg string valu of thi syntax error count msg script runtim get messag1 msg got syntax error msg throw error report runtim error msg sourceuri base lineno null 0 current script or fn set sourc name sourceuri current script or fn set base lineno base lineno current script or fn set end lineno ts get lineno int sourc end offset decompil get current offset current script or fn set encod sourc bound sourc start offset sourc end offset nf init script current script or fn pn if compil env is gener sourc encod sourc decompil get encod sourc thi decompil null it help gc return current script or fn privat node pars function bodi throw io except nest of function node pn nf creat block ts get lineno try bodi loop for node n int tt peek token switch tt case token error case token eof case token rc break bodi loop case token function consum token n function function node function statement break default n statement break nf add child to back pn n catch parser except e ignor it final nest of function return pn privat node function int function type throw io except parser except int synthet type function type int base lineno ts get lineno line number where sourc start int function sourc start decompil mark function start function type string name node member expr node null if match token token name name ts get string decompil add name name if match token token lp if compil env is allow member expr as function name extens to ecma if function name doe not follow by assum name start member expr node member expr head nf creat name name name member expr node member expr tail fals member expr head must match token token lp msg no paren parm els if match token token lp anonym function name els name if compil env is allow member expr as function name note that member expr can not start with like in function 1 2 to string becaus function alreadi process as anonym function member expr node member expr fals must match token token lp msg no paren parm if member expr node null synthet type function node function express boolean nest insid function function node fn node nf creat function name if nest nest of with 0 1 nest function ar not affect by the dynam scope flag as dynam scope is alreadi a parent of their scope 2 function defin under the with statement also immun to thi setup in which case dynam scope is ignor in favor of with object fn node it ignor dynam scope true int function index current script or fn add function fn node int function sourc end script or fn node save script or fn current script or fn current script or fn fn node int save nest of with nest of with nest of with 0 hashtabl save label set label set label set null obj arrai save loop set loop set loop set null obj arrai save loop and switch set loop and switch set loop and switch set null node bodi string sourc try decompil add token token lp if match token token rp boolean first true do if first decompil add token token comma first fals must match token token name msg no parm string s ts get string if fn node ha param or var s add warn msg dup parm s fn node add param s decompil add name s while match token token comma must match token token rp msg no paren after parm decompil add token token rp must match token token lc msg no brace bodi decompil addeol token lc bodi pars function bodi must match token token rc msg no brace after bodi decompil add token token rc function sourc end decompil mark function end function sourc start if function type function node function express if compil env get languag version context version 1 2 function f function g is not allow in 1 2 or later but for compat with old script the check is done onli if languag is explicitli set xxx warn need if version version default int tt peek token oreol if tt token function report error msg no semi stmt add eol onli if function is not part of express sinc it get semi eol from statement in that case decompil add token token eol final loop and switch set save loop and switch set loop set save loop set label set save label set nest of with save nest of with current script or fn save script or fn fn node set encod sourc bound function sourc start function sourc end fn node set sourc name sourceuri fn node set base lineno base lineno fn node set end lineno ts get lineno node pn nf init function fn node function index bodi synthet type if member expr node null pn nf creat assign token assign member expr node pn if function type function node function express xxx check j script behavior should it be creat expr statement pn nf creat expr statement no return pn base lineno return pn privat node statement throw io except node pn nf creat block ts get lineno int tt while tt peek token token eof tt token rc nf add child to back pn statement return pn privat node condit throw io except parser except node pn must match token token lp msg no paren cond decompil add token token lp pn expr fals must match token token rp msg no paren after cond decompil add token token rp there s a check here in jspars c that correct to return pn match a name return null if no match privat node match jump label name throw io except parser except node label null int tt peek token oreol if tt token name consum token string name ts get string decompil add name name if label set null label node label set get name if label null report error msg undef label return label privat node statement throw io except try node pn statement helper null if pn null return pn catch parser except e skip to end of statement int lineno ts get lineno guess statement end for int tt peek token oreol consum token switch tt case token error case token eof case token eol case token semi break guess statement end return nf creat expr statement nf creat name error lineno whether the catch e e instanceof except syntax is implement privat node statement helper node statement label throw io except parser except node pn null int tt tt peek token switch tt case token if consum token decompil add token token if int lineno ts get lineno node cond condit decompil addeol token lc node if true statement node if fals null if match token token els decompil add token token rc decompil add token token els decompil addeol token lc if fals statement decompil addeol token rc pn nf creat if cond if true if fals lineno return pn case token switch consum token decompil add token token switch int lineno ts get lineno must match token token lp msg no paren switch decompil add token token lp pn enter switch expr fals lineno statement label try must match token token rp msg no paren after switch decompil add token token rp must match token token lc msg no brace switch decompil addeol token lc boolean ha default fals switch loop for tt next token node case express switch tt case token rc break switch loop case token case decompil add token token case case express expr fals must match token token colon msg no colon case decompil addeol token colon break case token default if ha default report error msg doubl switch default decompil add token token default ha default true case express null must match token token colon msg no colon case decompil addeol token colon break default report error msg bad switch break switch loop node block nf creat leaf token block while tt peek token token rc tt token case tt token default tt token eof nf add child to back block statement case express null add default labl nf add switch case pn case express block decompil addeol token rc nf close switch pn final exit switch return pn case token while consum token decompil add token token while node loop enter loop statement label try node cond condit decompil addeol token lc node bodi statement decompil addeol token rc pn nf creat while loop cond bodi final exit loop return pn case token do consum token decompil add token token do decompil addeol token lc node loop enter loop statement label try node bodi statement decompil add token token rc must match token token while msg no while do decompil add token token while node cond condit pn nf creat do while loop bodi cond final exit loop alwai auto insert semicon to follow spider monkei it is requir by ema script but is ignor by the rest of world see bug 238945 match token token semi decompil addeol token semi return pn case token for consum token boolean is for each fals decompil add token token for node loop enter loop statement label try node init node init is also foo in foo in object node cond node cond is also object in foo in object node incr null to kill warn node bodi see if thi is a for each instead of just a for if match token token name decompil add name ts get string if ts get string equal each is for each true els report error msg no paren for must match token token lp msg no paren for decompil add token token lp tt peek token if tt token semi init nf creat leaf token empti els if tt token var set init to a var list or initi consum token consum the var token init variabl true els init expr true if match token token in decompil add token token in cond is the object over which we re iter cond expr fals els ordinari for loop must match token token semi msg no semi for decompil add token token semi if peek token token semi no loop condit cond nf creat leaf token empti els cond expr fals must match token token semi msg no semi for cond decompil add token token semi if peek token token rp incr nf creat leaf token empti els incr expr fals must match token token rp msg no paren for ctrl decompil add token token rp decompil addeol token lc bodi statement decompil addeol token rc if incr null cond could be null if in obj got eaten by the init node pn nf creat for in loop init cond bodi is for each els pn nf creat for loop init cond incr bodi final exit loop return pn case token try consum token int lineno ts get lineno node tryblock node catchblock null node finallyblock null decompil add token token try decompil addeol token lc tryblock statement decompil addeol token rc catchblock nf creat leaf token block boolean saw default catch fals int peek peek token if peek token catch while match token token catch if saw default catch report error msg catch unreach decompil add token token catch must match token token lp msg no paren catch decompil add token token lp must match token token name msg bad catchcond string var name ts get string decompil add name var name node catch cond null if match token token if decompil add token token if catch cond expr fals els saw default catch true must match token token rp msg bad catchcond decompil add token token rp must match token token lc msg no brace catchblock decompil addeol token lc nf add child to back catchblock nf creat catch var name catch cond statement ts get lineno must match token token rc msg no brace after bodi decompil addeol token rc els if peek token final must match token token final privat node variabl boolean in for init throw io except parser except node pn nf creat variabl ts get lineno boolean first true decompil add token token var for node name node init must match token token name msg bad var string s ts get string if first decompil add token token comma first fals decompil add name s current script or fn add var s name nf creat name s omit check for argument hide if match token token assign decompil add token token assign init assign expr in for init nf add child to back name init nf add child to back pn name if match token token comma break return pn privat node expr boolean in for init throw io except parser except node pn assign expr in for init while match token token comma decompil add token token comma pn nf creat binari token comma pn assign expr in for init return pn privat node assign expr boolean in for init throw io except parser except node pn cond expr in for init int tt peek token if token first assign tt tt token last assign consum token decompil add token tt pn nf creat assign tt pn assign expr in for init return pn privat node cond expr boolean in for init throw io except parser except node if true node if fals node pn or expr in for init if match token token hook decompil add token token hook if true assign expr fals must match token token colon msg no colon cond decompil add token token colon if fals assign expr in for init return nf creat cond expr pn if true if fals return pn privat node or expr boolean in for init throw io except parser except node pn and expr in for init if match token token or decompil add token token or pn nf creat binari token or pn or expr in for init return pn privat node and expr boolean in for init throw io except parser except node pn bit or expr in for init if match token token and decompil add token token and pn nf creat binari token and pn and expr in for init return pn privat node bit or expr boolean in for init throw io except parser except node pn bit xor expr in for init while match token token bitor decompil add token token bitor pn nf creat binari token bitor pn bit xor expr in for init return pn privat node bit xor expr boolean in for init throw io except parser except node pn bit and expr in for init while match token token bitxor decompil add token token bitxor pn nf creat binari token bitxor pn bit and expr in for init return pn privat node bit and expr boolean in for init throw io except parser except node pn eq expr in for init while match token token bitand decompil add token token bitand pn nf creat binari token bitand pn eq expr in for init return pn privat node eq expr boolean in for init throw io except parser except node pn rel expr in for init for int tt peek token switch tt case token eq case token ne case token sheq case token shne consum token int decompil token tt int pars token tt if compil env get languag version context version 1 2 java script 1 2 us shallow equal for and in addit convert and for decompil into and sinc the decompil is suppos to show canon sourc and in 1 2 ar allow onli as an alia to switch tt case token eq pars token token sheq break case token ne pars token token shne break case token sheq decompil token token eq break case token shne decompil token token ne break decompil add token decompil token pn nf creat binari pars token pn rel expr in for init continu break return pn privat node rel expr boolean in for init throw io except parser except node pn shift expr for int tt peek token switch tt case token in if in for init break fall through case token instanceof case token le case token lt case token ge case token gt consum token decompil add token tt pn nf creat binari tt pn shift expr continu break return pn privat node shift expr throw io except parser except node pn add expr for int tt peek token switch tt case token lsh case token ursh case token rsh consum token decompil add token tt pn nf creat binari tt pn add expr continu break return pn privat node add expr throw io except parser except node pn mul expr for int tt peek token if tt token add tt token sub consum token decompil add token tt flush new line pn nf creat binari tt pn mul expr continu break return pn privat node mul expr throw io except parser except node pn unari expr for int tt peek token switch tt case token mul case token div case token mod consum token decompil add token tt pn nf creat binari tt pn unari expr continu break return pn privat node unari expr throw io except parser except int tt tt peek token switch tt case token void case token not case token bitnot case token typeof consum token decompil add token tt return nf creat unari tt unari expr case token add consum token convert to special po token in decompil and pars tree decompil add token token po return nf creat unari token po unari expr case token sub consum token convert to special neg token in decompil and pars tree decompil add token token neg return nf creat unari token neg unari expr case token inc case token dec consum token decompil add token tt return nf creat inc dec tt fals member expr true case token delprop consum token decompil add token token delprop return nf creat unari token delprop unari expr case token error consum token break xml stream encount in express case token lt if compil env is xml avail consum token node pn xml initi return member expr tail true pn fall thru to the default handl of relop default node pn member expr true don t look across a newlin boundari for a postfix incop tt peek token oreol if tt token inc tt token dec consum token decompil add token tt return nf creat inc dec tt true pn return pn return nf creat name err onli reach on error try to continu privat node xml initi throw io except int tt ts get firstxml token if tt token xml tt token xmlend report error msg syntax return null make a new node to append to node pnxml nf creat leaf token new string xml ts get string boolean f anonym xml trim start with node pn nf creat name f anonym xml list xml nf add child to back pnxml pn pn null node expr for tt ts get nextxml token switch tt case token xml xml ts get string decompil add name xml must match token token lc msg syntax decompil add token token lc expr peek token token rc nf creat string expr fals must match token token rc msg syntax decompil add token token rc if pn null pn nf creat string xml els pn nf creat binari token add pn nf creat string xml int node type if ts isxml attribut node type token escxmlattr els node type token escxmltext expr nf creat unari node type expr pn nf creat binari token add pn expr break case token xmlend xml ts get string decompil add name xml if pn null pn nf creat string xml els pn nf creat binari token add pn nf creat string xml nf add child to back pnxml pn return pnxml default report error msg syntax return null privat void argument list node list node throw io except parser except boolean match match match token token rp if match boolean first true do if first decompil add token token comma first fals nf add child to back list node assign expr fals while match token token comma must match token token rp msg no paren arg decompil add token token rp privat node member expr boolean allow call syntax throw io except parser except int tt node pn check for new express tt peek token if tt token new eat the new token consum token decompil add token token new make a new node to append to pn nf creat call or new token new member expr fals if match token token lp decompil add token token lp add the argument to pn if ani ar suppli argument list pn xxx there s a check in the c sourc against too mani constructor argument how mani do we claim to support experiment syntax allow an object liter to follow a new express which will mean a kind of anonym class built with the java adapt the object liter will be pass as an addit argument to the constructor tt peek token if tt token lc nf add child to back pn primari expr els pn primari expr return member expr tail allow call syntax pn privat node member expr tail boolean allow call syntax node pn throw io except parser except tail loop for int tt peek token switch tt case token dot case token dotdot int member type flag string s consum token decompil add token tt member type flag 0 if tt token dotdot must havexml member type flag node descend flag if compil env is xml avail must match token token name msg no name after dot s ts get string decompil add name s pn nf creat properti get pn null s member type flag break tt next token switch tt handl name ns name ns ns expr case token name s ts get string decompil add name s pn properti name pn s member type flag break handl name expr case token mul decompil add name pn properti name pn member type flag break handl attr ns attr ns ns attr attr case token xmlattr decompil add token token xmlattr pn attribut access pn member type flag break default report error msg no name after dot break case token dotqueri consum token must havexml decompil add token token dotqueri pn nf creat dot queri pn expr fals ts get lineno must match token token rp msg no paren decompil add token token rp break case token lb consum token decompil add token token lb pn nf creat element get pn null expr fals 0 must match token token rb msg no bracket index decompil add token token rb break case token lp if allow call syntax break tail loop consum token decompil add token token lp pn nf creat call or new token call pn add the argument to pn if ani ar suppli argument list pn break default break tail loop return pn privat node attribut access node pn int member type flag throw io except member type flag node attribut flag int tt next token switch tt handl name ns name ns ns expr case token name string s ts get string decompil add name s pn properti name pn s member type flag break handl name expr case token mul decompil add name pn properti name pn member type flag break handl expr case token lb decompil add token token lb pn nf creat element get pn null expr fals member type flag must match token token rb msg no bracket index decompil add token token rb break default report error msg no name after xml attr pn nf creat properti get pn null member type flag break return pn check if follow name in which case it becom qualifi name privat node properti name node pn string name int member type flag throw io except parser except string namespac null if match token token coloncolon decompil add token token coloncolon namespac name int tt next token switch tt handl name name case token name name ts get string decompil add name name break handl name case token mul decompil add name name break handl name expr case token lb decompil add token token lb pn nf creat element get pn namespac expr fals member type flag must match token token rb msg no bracket index decompil add token token rb return pn default report error msg no name after coloncolon name pn nf creat properti get pn namespac name member type flag return pn privat node primari expr throw io except parser except node pn int tt flag next flag token int tt tt flag clear ti mask switch tt case token function return function function node function express case token lb obj arrai elem new obj arrai int skip count 0 decompil add token token lb boolean after lb or comma true for tt peek token if tt token comma consum token decompil add token token comma if after lb or comma after lb or comma true els elem add null skip count els if tt token rb consum token decompil add token token rb break els if after lb or comma report error msg no bracket arg elem add assign expr fals after lb or comma fals return nf creat arrai liter elem skip count case token lc obj arrai elem new obj arrai decompil add token token lc if match token token rc boolean first true commaloop do object properti if first decompil add token token comma els first fals tt peek token switch tt case token name case token string consum token map nam es to strin gs in object liter context but tell the decompil the proper type string s ts get string if tt token name decompil add name s els decompil add string s properti script runtim get index object s break case token number consum token doubl n ts get number decompil add number n properti script runtim get index object n break case token rc trail comma is ok break commaloop default report error msg bad prop break commaloop must match token token colon msg no colon prop objlit is us as in object liter for decompil to solv space ambigu decompil add token token objectlit elem add properti elem add assign expr fals while match token token comma must match token token rc msg no brace prop decompil add token token rc return nf creat object liter elem case token lp brendan s ir jspars c make a new node tag with tok lp here i m not sure i understand why isn t the group alreadi implicit in the structur of the pars tree also tok lp is alreadi overload i think in the c ir as function call decompil add token token lp pn expr fals decompil add token token rp must match token token rp msg no paren return pn case token xmlattr must havexml decompil add token token xmlattr pn attribut access null 0 return pn case token name string name ts get string if tt flag ti check label 0 if peek token token colon do not consum colon it is us as unwind indic to return to statement helper xxx better wai return nf creat label ts get lineno decompil add name name if compil env is xml avail pn properti name null name 0 els pn nf creat name name return pn case token number doubl n ts get number decompil add number n return nf creat number n case token string string s ts get string decompil add string s return nf creat string s case token div case token assign div got or which should be treat as regexp in fact ts read reg exp tt string flag ts reg exp flag ts reg exp flag null string re ts get string decompil add regexp re flag int index current script or fn add regexp re flag return nf creat reg exp index case token null case token thi case token fals case token true decompil add token tt return nf creat leaf tt case token reserv report error msg reserv id break case token error the scanner or on of it subroutin report the error break case token eof report error msg unexpect eof break default report error msg syntax break return null should never reach here protect object get thread context helper to make subsequ batch call to get context set context faster associ perman on element arrai with context local so get context set context would need just to read write the first arrai element note that it is necessari to us object not context to allow garbag collect of rhino class for detail see comment by attila szegedi in http bugzilla mozilla org show bug cgi id 281067 c5 object storag object context local get if storag null storag new object 1 context local set storag return storag protect context get context object context helper object storag object context helper return context storag 0 protect void set context object context helper context cx object storag object context helper storag 0 cx protect class loader get current thread class loader return thread current thread get context class loader protect boolean try to make access object access object if access object instanceof access object return fals access object access access object access object if access is access return true try access set access true catch except ex return access is access protect object get interfac proxi helper context factori cf class interfac xxx how to handl interfac arrai withclass from differ class loader us cf get applic class loader class loader loader interfac 0 get class loader class cl proxi get proxi class loader interfac constructor c try c cl get constructor new class invoc handler class catch no such method except ex should not happen throw kit init caus new illeg state except ex return c protect object new interfac proxi object proxi helper final context factori cf final interfac adapt adapt final object target final scriptabl top scope constructor c constructor proxi helper invoc handler handler new invoc handler public object invok object proxi method method object arg return adapt invok cf target top scope method arg object proxi try proxi c new instanc new object handler catch invoc target except ex throw context throw as script runtim ex ex catch illeg access except ex shoul not happen throw kit init caus new illeg state except ex catch instanti except ex shoul not happen throw kit init caus new illeg state except ex return proxi invoc handler handler new invoc handler public object invok object proxi method method object arg return adapt invok cf target top scope method arg no instanc should be creat protect script runtim public static boolean is rhino runtim type class cl if cl is primit return cl charact type els return cl string class cl boolean class number class is assign from cl scriptabl class is assign from cl public static scriptabl object init standard object context cx scriptabl object scope boolean seal if scope null scope new nativ object scope associ valu librari scope kei scope new class cach associ scope base function init scope seal nativ object init scope seal scriptabl object proto scriptabl object get object prototyp scope function prototyp proto should be object prototyp scriptabl function proto scriptabl object get function prototyp scope function proto set prototyp object proto set the prototyp of the object pass in if need be if scope get prototyp null scope set prototyp object proto must preced nativ global sinc it s need therein nativ error init scope seal nativ global init cx scope seal nativ arrai init scope seal nativ string init scope seal nativ boolean init scope seal nativ number init scope seal nativ date init scope seal nativ math init scope seal nativ with init scope seal nativ call init scope seal nativ script init scope seal boolean with xml cx ha featur context featur e4x for int i 0 i lazili name length i 2 string top properti lazili name i string class name lazili name i 1 if with xml class name xml init class continu new lazili load ctor scope top properti class name seal continu init scope seal return scope public static scriptabl object get librari scope or null scriptabl scope scriptabl object lib scope lib scope scriptabl object scriptabl object get top scope valu scope librari scope kei return lib scope it is public so nativ reg exp can access it public static boolean isj line termin int c optim for faster check for eol charact thei do not have 0xdfd0 bit set if c 0xdfd0 0 return fals return c n c r c 0x2028 c 0x2029 public static boolean wrap boolean boolean b return b boolean true boolean fals public static integ wrap int int i return new integ i public static number wrap number doubl x if x x return script runtim na nobj return new doubl x convert the valu to a boolean see ecma 9 2 public static boolean to boolean object val for if val instanceof boolean return boolean val boolean valu if val null val undefin instanc return fals if val instanceof string return string val length 0 if val instanceof number doubl d number val doubl valu return d d d 0 0 if val instanceof scriptabl if context get context is versionecma1 pure ecma return true ecma extens val scriptabl val get default valu boolean class if val instanceof scriptabl throw error with class name msg primit expect val continu warn about nonj object val return true public static boolean to boolean object arg int index return index arg length to boolean arg index fals convert the valu to a number see ecma 9 3 public static doubl to number object val for if val instanceof number return number val doubl valu if val null return 0 0 if val undefin instanc return nan if val instanceof string return to number string val if val instanceof boolean return boolean val boolean valu 1 0 0 if val instanceof scriptabl val scriptabl val get default valu number class if val instanceof scriptabl throw error with class name msg primit expect val continu warn about nonj object val return nan public static doubl to number object arg int index return index arg length to number arg index nan static doubl string to number string s int start int radix char digit max 9 char lower case bound a char upper case bound a int len s length if radix 10 digit max char 0 radix 1 if radix 10 lower case bound char a radix 10 upper case bound char a radix 10 int end doubl sum 0 0 for end start end len end char c s char at end int new digit if 0 c c digit max new digit c 0 els if a c c lower case bound new digit c a 10 els if a c c upper case bound new digit c a 10 els break sum sum radix new digit if start end return nan if sum 9007199254740992 0 if radix 10 if we re accumul a decim number and the number is 2 53 then the result from the repeat multipli add abov mai be inaccur call java to get the correct answer try return doubl valu of s substr start end doubl valu catch number format except nfe return nan els if radix 2 radix 4 radix 8 radix 16 radix 32 the number mai also be inaccur for on of these base thi happen if the addit in valu radix digit caus a round down to an even least signific mantissa bit when the first drop bit is a on if ani of the follow digit in the number which haven t been ad in yet ar nonzero then the correct action would have been to round up instead of down an exampl of thi occur when read the number 0x1000000000000081 which round to 0x1000000000000000 instead of 0x1000000000000100 int bit shift in char 1 int digit 0 final int skip lead zero 0 final int first exact 53 bit 1 final int after bit 53 2 final int zero after 54 3 final int mix after 54 4 int state skip lead zero int exact bit limit 53 doubl factor 0 0 boolean bit53 fals bit54 is the 54th bit the first drop from the mantissa boolean bit54 fals for if bit shift in char 1 if start end break digit s char at start if 0 digit digit 9 digit 0 els if a digit digit z digit a 10 els digit a 10 bit shift in char radix bit shift in char 1 boolean bit digit bit shift in char 0 switch state case skip lead zero if bit exact bit limit sum 1 0 state first exact 53 bit break case first exact 53 bit sum 2 0 if bit sum 1 0 exact bit limit if exact bit limit 0 bit53 bit state after bit 53 break case after bit 53 bit54 bit factor 2 0 state zero after 54 break case zero after 54 if bit state mix after 54 fallthrough case mix after 54 factor 2 break switch state case skip lead zero sum 0 0 break case first exact 53 bit case after bit 53 do noth break case zero after 54 x1 1 x1 1 round up x0 1 x0 round down if bit54 bit53 sum 1 0 sum factor break case mix after 54 x 100 1 x 1 round up x 0anyth x round down if bit54 sum 1 0 sum factor break we don t worri about inaccur number for ani other base return sum to number appli to the string type see ecma 9 3 1 public static doubl to number string s int len s length int start 0 char start char for if start len empti or contain onli whitespac return 0 0 start char s char at start if charact is whitespac start char break start if start char 0 if start 2 len int c1 s char at start 1 if c1 x c1 x a hexadecim number return string to number s start 2 16 els if start char start char if start 3 len s char at start 1 0 int c2 s char at start 2 if c2 x c2 x a hexadecim number with sign doubl val string to number s start 3 16 return start char val val int end len 1 char end char while charact is whitespac end char s char at end end if end char y check for infin if start char start char start if start 7 end s region match start infin 0 8 return start char doubl neg infin doubl posit infin return nan a non hexadecim non infin number just try a normal float point convers string sub s substr start end 1 if msjvm bug workaround the ms jvm will accept non conform string rather than throw a number format except as it should for int i sub length 1 i 0 i char c sub char at i if 0 c c 9 c c e c e c c continu return nan try return doubl valu of sub doubl valu catch number format except ex return nan helper function for builtin object that us the vararg form ecma function formal argument ar undefin if not suppli thi function pad the argument arrai out to the expect length if necessari public static object pad argument object arg int count if count arg length return arg int i object result new object count for i 0 i arg length i result i arg i for i count i result i undefin instanc return result privat final static boolean msjvm bug workaround true public static string escap string string s return escap string s for escap string print by object and arrai liter not quit the same as escap public static string escap string string s char escap quot if escap quot escap quot kit code bug string buffer sb null for int i 0 l s length i l i int c s char at i if c c c escap quot c an ordinari print charact like c isprint and not or if sb null sb append char c continu if sb null sb new string buffer l 3 sb append s sb set length i int escap 1 switch c case b escap b break case f escap f break case n escap n break case r escap r break case t escap t break case 0xb escap v break java lack v case escap break case escap break if escap 0 an escap sort of charact sb append sb append char escap els if c escap quot sb append sb append escap quot els int hex size if c 256 2 digit hex sb append x hex size 2 els unicod sb append u hex size 4 append hexadecim form of c left pad with 0 for int shift hex size 1 4 shift 0 shift 4 int digit 0xf c shift int hc digit 10 0 digit a 10 digit sb append char hc return sb null s sb to string static boolean is valid identifi name string s int l s length if l 0 return fals if charact is java identifi start s char at 0 return fals for int i 1 i l i if charact is java identifi part s char at i return fals return token stream is keyword s convert the valu to a string see ecma 9 8 public static string to string object val for if val null return null if val undefin instanc return undefin if val instanceof string return string val if val instanceof number xxx should we just teach nativ number string valu about number return number to string number val doubl valu 10 if val instanceof scriptabl val scriptabl val get default valu string class if val instanceof scriptabl throw error with class name msg primit expect val continu return val to string static string default object to string scriptabl obj return object obj get class name public static string to string object arg int index return index arg length to string arg index undefin optim version of to string object for number public static string to string doubl val return number to string val 10 public static string number to string doubl d int base if d d return nan if d doubl posit infin return infin if d doubl neg infin return infin if d 0 0 return 0 if base 2 base 36 throw context report runtim error1 msg bad radix integ to string base if base 10 return d toa js dtobasestr base d els string buffer result new string buffer d toa js dtostr result d toa dtostr standard 0 d return result to string static string unev context cx scriptabl scope object valu if valu null return null if valu undefin instanc return undefin if valu instanceof string string escap escap string string valu string buffer sb new string buffer escap length 2 sb append sb append escap sb append return sb to string if valu instanceof number doubl d number valu doubl valu if d 0 1 d 0 return 0 return to string d if valu instanceof boolean return to string valu if valu instanceof scriptabl scriptabl obj scriptabl valu object v scriptabl object get properti obj to sourc if v instanceof function function f function v return to string f call cx scope obj empti arg return to string valu warn about nonj object valu return valu to string static string default object to sourc context cx scriptabl scope scriptabl thi obj object arg boolean toplevel iter if cx iter null toplevel true iter fals cx iter new obj to int map 31 els toplevel fals iter cx iter ha thi obj string buffer result new string buffer 128 if toplevel result append result append make sure cx iter is set to null when done so we don t leak memori try if iter cx iter intern thi obj stop recurs object id thi obj get id for int i 0 i id length i if i 0 result append object id id i object valu if id instanceof integ int int id integ id int valu valu thi obj get int id thi obj result append int id els string str id string id valu thi obj get str id thi obj if script runtim is valid identifi name str id result append str id els result append result append script runtim escap string str id result append result append result append script runtim unev cx scope valu final if toplevel cx iter null result append if toplevel result append return result to string public static scriptabl to object scriptabl scope object val if val instanceof scriptabl return scriptabl val return to object context get context scope val public static scriptabl to object or null context cx object obj if obj instanceof scriptabl return scriptabl obj els if obj null obj undefin instanc return to object cx get top call scope cx obj return null deprec us link to object scriptabl object instead public static scriptabl to object scriptabl scope object val class static class if val instanceof scriptabl return scriptabl val return to object context get context scope val convert the valu to an object see ecma 9 9 public static scriptabl to object context cx scriptabl scope object val if val instanceof scriptabl return scriptabl val if val null throw type error0 msg null to object if val undefin instanc throw type error0 msg undef to object string class name val instanceof string string val instanceof number number val instanceof boolean boolean null if class name null object arg val scope scriptabl object get top level scope scope return new object cx scope class name arg extens wrap as a live connect object object wrap cx get wrap factori wrap cx scope val null if wrap instanceof scriptabl return scriptabl wrap throw error with class name msg invalid type val deprec us link to object context scriptabl object instead public static scriptabl to object context cx scriptabl scope object val class static class return to object cx scope val deprec the method is onli present for compat public static object call context cx object fun object thi arg object arg scriptabl scope if fun instanceof function throw not function error to string fun function function function fun scriptabl thi obj to object or null cx thi arg if thi obj null throw undef call error thi obj function return function call cx scope thi obj arg public static scriptabl new object context cx scriptabl scope string constructor name object arg scope scriptabl object get top level scope scope function ctor get exist ctor cx scope constructor name if arg null arg script runtim empti arg return ctor construct cx scope arg see ecma 9 4 public static doubl to integ object val return to integ to number val conveni method public static doubl to integ doubl d if it s nan if d d return 0 0 if d 0 0 d doubl posit infin d doubl neg infin return d if d 0 0 return math floor d els return math ceil d public static doubl to integ object arg int index return index arg length to integ arg index 0 0 see ecma 9 5 public static int to int32 object val short circuit for common integ valu if val instanceof integ return integ val int valu return to int32 to number val public static int to int32 object arg int index return index arg length to int32 arg index 0 public static int to int32 doubl d int id int d if id d thi cover 0 0 as well return id if d d d doubl posit infin d doubl neg infin return 0 d d 0 math floor d math ceil d doubl two32 4294967296 0 d math iee eremaind d two32 doubl long d d should hold here long l long d return int d doe not work as d can be outsid int rang but the result must alwai be 32 lower bit of l return int l see ecma 9 6 return long valu repres 32 bit unsign integ public static long to uint32 doubl d long l long d if l d thi cover 0 0 as well return l 0xffffffffl if d d d doubl posit infin d doubl neg infin return 0 d d 0 math floor d math ceil d 0x100000000 give me a numer overflow doubl two32 4294967296 0 l long math iee eremaind d two32 return l 0xffffffffl public static long to uint32 object val return to uint32 to number val see ecma 9 7 public static char to uint16 object val doubl d to number val int i int d if i d return char i if d d d doubl posit infin d doubl neg infin return 0 d d 0 math floor d math ceil d int int16 0x10000 i int math iee eremaind d int16 return char i public static object set default namespac object namespac context cx scriptabl scope cx current activ call if scope null scope get top call scope cx xml lib xml lib currentxml lib cx object ns xml lib to default xml namespac cx namespac xxx thi should be in separ namesapc from scriptabl get put if scope ha default ns tag scope xxx thi is raci of caus scriptabl object defin properti scope default ns tag ns scriptabl object perman scriptabl object dontenum els scope put default ns tag scope ns return undefin instanc public static object search default namespac context cx scriptabl scope cx current activ call if scope null scope get top call scope cx object ns object for scriptabl parent scope get parent scope if parent null ns object scriptabl object get properti scope default ns tag if ns object scriptabl not found return null break ns object scope get default ns tag scope if ns object scriptabl not found break scope parent return ns object public static object get top level prop scriptabl scope string id scope scriptabl object get top level scope scope return scriptabl object get properti scope id static function get exist ctor context cx scriptabl scope string constructor name object ctor val scriptabl object get properti scope constructor name if ctor val instanceof function return function ctor val if ctor val scriptabl not found throw context report runtim error1 msg ctor not found constructor name els throw context report runtim error1 msg not ctor constructor name return 1l if str is not an index or the index valu as lower 32 bit of the result privat static long index from string string str the length of the decim string represent of integ max valu 2147483647 final int max valu length 10 int len str length if len 0 int i 0 boolean negat fals int c str char at 0 if c if len 1 c str char at 1 i 1 negat true c 0 if 0 c c 9 len negat max valu length 1 max valu length us neg number to accumul index to handl integ min valu that is greater by 1 in absolut valu then integ max valu int index c int old index 0 i if index 0 note that 00 01 000 etc ar not index while i len 0 c str char at i 0 c 9 old index index index 10 index c i make sure all charact were consum and that it couldn t have overflow if i len old index integ min valu 10 old index integ min valu 10 c negat integ min valu 10 integ max valu 10 return 0xffffffffl negat index index return 1l if str is a decim present of uint32 valu return it as long othewis return 1l public static long test uint32 string string str the length of the decim string represent of uint32 max valu 4294967296 final int max valu length 10 int len str length if 1 len len max valu length int c str char at 0 c 0 if c 0 note that 00 01 etc ar not valid uint32 present return len 1 0l 1l if 1 c c 9 long v c for int i 1 i len i c str char at i 0 if 0 c c 9 return 1 v 10 v c check for overflow if v 32 0 return v return 1 if s repres index then return index valu wrap as integ and othewis return s static object get index object string s long index test index from string s if index test 0 return new integ int index test return s if d is exact int valu return it valu wrap as integ and othewis return d convert to string static object get index object doubl d int i int d if doubl i d return new integ int i return to string d if to string id is a decim present of int32 valu then id is index in thi case return null and make the index avail as script runtim last index result cx otherwis return to string id static string to string id or index context cx object id if id instanceof number doubl d number id doubl valu int index int d if doubl index d store index result cx index return null return to string id els string s if id instanceof string s string id els s to string id long index test index from string s if index test 0 store index result cx int index test return null return s call obj get id public static object get object elem object obj object elem context cx scriptabl sobj to object or null cx obj if sobj null throw undef read error obj elem return get object elem sobj elem cx public static object get object elem scriptabl obj object elem context cx if obj instanceof xml object xml object xml object xml object obj return xml object ecma get cx elem object result string s to string id or index cx elem if s null int index last index result cx result scriptabl object get properti obj index els result scriptabl object get properti obj s if result scriptabl not found result undefin instanc return result version of get object elem when elem is a valid js identifi name public static object get object prop object obj string properti context cx scriptabl sobj to object or null cx obj if sobj null throw undef read error obj properti return get object prop sobj properti cx public static object get object prop scriptabl obj string properti context cx if obj instanceof xml object xml object xml object xml object obj return xml object ecma get cx properti object result scriptabl object get properti obj properti if result scriptabl not found result undefin instanc return result public static object get object index object obj doubl dbl index context cx scriptabl sobj to object or null cx obj if sobj null throw undef read error obj to string dbl index int index int dbl index if doubl index dbl index return get object index sobj index cx els string s to string dbl index return get object prop sobj s cx public static object get object index scriptabl obj int index context cx if obj instanceof xml object xml object xml object xml object obj return xml object ecma get cx new integ index object result scriptabl object get properti obj index if result scriptabl not found result undefin instanc return result public static object set object elem object obj object elem object valu context cx scriptabl sobj to object or null cx obj if sobj null throw undef write error obj elem valu return set object elem sobj elem valu cx public static object set object elem scriptabl obj object elem object valu context cx if obj instanceof xml object xml object xml object xml object obj xml object ecma put cx elem valu return valu string s to string id or index cx elem if s null int index last index result cx scriptabl object put properti obj index valu els scriptabl object put properti obj s valu return valu version of set object elem when elem is a valid js identifi name public static object set object prop object obj string properti object valu context cx scriptabl sobj to object or null cx obj if sobj null throw undef write error obj properti valu return set object prop sobj properti valu cx public static object set object prop scriptabl obj string properti object valu context cx if obj instanceof xml object xml object xml object xml object obj xml object ecma put cx properti valu els scriptabl object put properti obj properti valu return valu public static object set object index object obj doubl dbl index object valu context cx scriptabl sobj to object or null cx obj if sobj null throw undef write error obj string valu of dbl index valu int index int dbl index if doubl index dbl index return set object index sobj index valu cx els string s to string dbl index return set object prop sobj s valu cx public static object set object index scriptabl obj int index object valu context cx if obj instanceof xml object xml object xml object xml object obj xml object ecma put cx new integ index valu els scriptabl object put properti obj index valu return valu public static boolean delet object elem scriptabl target object elem context cx boolean result if target instanceof xml object xml object xml object xml object target result xml object ecma delet cx elem els string s to string id or index cx elem if s null int index last index result cx result scriptabl object delet properti target index els result scriptabl object delet properti target s return result public static boolean ha object elem scriptabl target object elem context cx boolean result if target instanceof xml object xml object xml object xml object target result xml object ecma ha cx elem els string s to string id or index cx elem if s null int index last index result cx result scriptabl object ha properti target index els result scriptabl object ha properti target s return result public static object ref get ref ref context cx return ref get cx public static object ref set ref ref object valu context cx return ref set cx valu public static object ref del ref ref context cx return wrap boolean ref delet cx static boolean is special properti string s return s equal proto s equal parent public static ref special ref object obj string special properti context cx return special ref creat special cx obj special properti the delet oper see ecma 11 4 1 in ecma 0 19 the descript of the delet oper 11 4 1 assum that the delet method return a valu howev the definit of the delet oper 8 6 2 5 doe not defin a return valu here we assum that the delet method doesn t return a valu public static object delet object obj object id context cx scriptabl sobj to object or null cx obj if sobj null string id str id null null id to string throw type error2 msg undef prop delet to string obj id str boolean result delet object elem sobj id cx return wrap boolean result look up a name in the scope chain and return it valu public static object name context cx scriptabl scope string name scriptabl parent scope get parent scope if parent null object result top scope name cx scope name if result scriptabl not found throw not found error scope name return result return name or function cx scope parent name fals privat static object name or function context cx scriptabl scope scriptabl parent scope string name boolean as function call object result scriptabl thi obj scope it is us onli if as function call true xml object firstxml object null for if scope instanceof nativ with scriptabl with obj scope get prototyp if with obj instanceof xml object xml object xml obj xml object with obj if xml obj ecma ha cx name function thi should be the target object of with thi obj xml obj result xml obj ecma get cx name break if firstxml object null firstxml object xml obj els result scriptabl object get properti with obj name if result scriptabl not found function thi should be the target object of with thi obj with obj break els if scope instanceof nativ call nativ call doe not prototyp chain and scriptabl get can be call directli result scope get name scope if result scriptabl not found if as function call ecma 262 requir that thi for nest funtion should be top scope thi obj scriptabl object get top level scope parent scope break els can happen if rhino embed decid that nest scope ar us for what ever reason result scriptabl object get properti scope name if result scriptabl not found thi obj scope break scope parent scope parent scope parent scope get parent scope if parent scope null result top scope name cx scope name if result scriptabl not found if firstxml object null as function call throw not found error scope name the name wa not found but we did find an xml object in the scope chain and we ar look for name not function the result should be an empti xml list in name context result firstxml object ecma get cx name for top scope thi obj for function is alwai scope itself thi obj scope break if as function call if result instanceof callabl throw not function error result name store scriptabl cx thi obj return result privat static object top scope name context cx scriptabl scope string name if cx us dynam scope scope check dynam scope cx top call scope scope return scriptabl object get properti scope name return the object in the scope chain that ha a given properti the order of evalu of an assign express involv evalu the lh to a refer evalu the rh and then modifi the refer with the rh valu thi method is us to bind the given name to an object contain that properti so that the side effect of evalu the rh do not affect which properti is modifi typic us in conjunct with set name see ecma 10 1 4 public static scriptabl bind context cx scriptabl scope string id scriptabl firstxml object null scriptabl parent scope get parent scope child scope check if parent null check for possibl nest with scope first while scope instanceof nativ with scriptabl with obj scope get prototyp if with obj instanceof xml object xml object xml object xml object with obj if xml object ecma ha cx id return xml object if firstxml object null firstxml object xml object els if scriptabl object ha properti with obj id return with obj scope parent parent parent get parent scope if parent null break child scope check for if scriptabl object ha properti scope id return scope scope parent parent parent get parent scope if parent null break child scope check scope here is top scope if cx us dynam scope scope check dynam scope cx top call scope scope if scriptabl object ha properti scope id return scope noth wa found but sinc xml object alwai bind return on if found return firstxml object public static object set name scriptabl bound object valu context cx scriptabl scope string id if bound null if bound instanceof xml object xml object xml object xml object bound xml object ecma put cx id valu els scriptabl object put properti bound id valu els newnam 7 where newnam ha not yet been defin creat a new properti in the top scope unless strict mode is specifi if cx ha featur context featur strict var throw context report runtim error1 msg assn creat strict id find the top scope by walk up the scope chain bound scriptabl object get top level scope scope if cx us dynam scope bound check dynam scope cx top call scope bound bound put id bound valu return valu public static object enum init object valu context cx boolean enum valu id enumer x new id enumer x obj to object or null cx valu if x obj null null or undefin do not caus error but rather lead to empti for in loop x enum valu enum valu enum init should read all initi id befor return or for a i in a would wrongli enumer i in a as well enum chang object x return x public static boolean enum next object enum obj opt thi could be more effici boolean result id enumer x id enumer enum obj for if x obj null result fals break if x index x id length x obj x obj get prototyp enum chang object x continu object id x id x index if x us null x us ha id continu if id instanceof string string str id string id if x obj ha str id x obj continu must have been delet x current id str id els int int id number id int valu if x obj ha int id x obj continu must have been delet x current id string valu of int id result true break return wrap boolean result public static object enum id object enum obj context cx id enumer x id enumer enum obj if x enum valu return x current id object result string s to string id or index cx x current id if s null int index last index result cx result x obj get index x obj els result x obj get s x obj return result privat static void enum chang object id enumer x object id null while x obj null id x obj get id if id length 0 break x obj x obj get prototyp if x obj null x id null object previou x id int l previou length if x us null x us new obj to int map l for int i 0 i l i x us intern previou i x id id x index 0 prepar for call name return function correspond to name and make current top scope avail as script runtim last store scriptabl for consumpt as thi obj the caller must call script runtim last store scriptabl immedi after call thi method public static callabl get name function and thi string name context cx scriptabl scope scriptabl parent scope get parent scope if parent null object result top scope name cx scope name if result instanceof callabl if result scriptabl not found throw not found error scope name els throw not function error result name top scope is not nativ with or nativ call thi obj scope scriptabl thi obj scope store scriptabl cx thi obj return callabl result name will call store scriptabl cx thi obj return callabl name or function cx scope parent name true prepar for call obj id return function correspond to obj id and make obj properli convert to scriptabl avail as script runtim last store scriptabl for consumpt as thi obj the caller must call script runtim last store scriptabl immedi after call thi method public static callabl get elem function and thi object obj object elem context cx string s to string id or index cx elem if s null return get prop function and thi obj s cx int index last index result cx scriptabl thi obj to object or null cx obj if thi obj null throw undef call error obj string valu of index object valu for ignor xml lookup as requr by ecma 357 11 2 2 1 valu scriptabl object get properti thi obj index if valu scriptabl not found break if thi obj instanceof xml object break xml object xml object xml object thi obj scriptabl extra xml object get extra method sourc cx if extra null break thi obj extra if valu instanceof callabl throw not function error valu elem store scriptabl cx thi obj return callabl valu prepar for call obj properti return function correspond to obj properti and make obj properli convert to scriptabl avail as script runtim last store scriptabl for consumpt as thi obj the caller must call script runtim last store scriptabl immedi after call thi method public static callabl get prop function and thi object obj string properti context cx scriptabl thi obj to object or null cx obj if thi obj null throw undef call error obj properti object valu for ignor xml lookup as requr by ecma 357 11 2 2 1 valu scriptabl object get properti thi obj properti if valu scriptabl not found break if thi obj instanceof xml object break xml object xml object xml object thi obj scriptabl extra xml object get extra method sourc cx if extra null break thi obj extra if valu instanceof callabl throw not function error valu properti store scriptabl cx thi obj return callabl valu prepar for call express return function correspond to express and make parent scope of the function avail as script runtim last store scriptabl for consumpt as thi obj the caller must call script runtim last store scriptabl immedi after call thi method public static callabl get valu function and thi object valu context cx if valu instanceof callabl throw not function error valu callabl f callabl valu scriptabl thi obj if f instanceof scriptabl thi obj scriptabl f get parent scope els if cx top call scope null throw new illeg state except thi obj cx top call scope if thi obj get parent scope null if thi obj instanceof nativ with function defin insid with should have with target as their thi obj els if thi obj instanceof nativ call nest function should have top scope as their thi obj thi obj scriptabl object get top level scope thi obj store scriptabl cx thi obj return f perform function call in refer context should alwai return valu that can be pass to link ref get object or link ref set object object arbitrari number of time the arg arrai refer should not be store in ani object that is can be gc reachabl after thi method return if thi is necessari store arg clone not arg arrai itself public static ref call ref callabl function scriptabl thi obj object arg context cx if function instanceof ref callabl ref callabl rfunction ref callabl function ref ref rfunction ref call cx thi obj arg if ref null throw new illeg state except rfunction get class get name ref call return null return ref no runtim support for now string msg get messag1 msg no ref from function to string function throw construct error refer error msg oper new see ecma 11 2 2 public static scriptabl new object object fun context cx scriptabl scope object arg if fun instanceof function throw not function error fun function function function fun return function construct cx scope arg public static object call special context cx callabl fun scriptabl thi obj object arg scriptabl scope scriptabl caller thi int call type string filenam int line number if call type node specialcal eval if nativ global is eval function fun return eval special cx scope caller thi arg filenam line number els if call type node specialcal with if nativ with is with function fun throw context report runtim error1 msg onli from new with els throw kit code bug return fun call cx scope thi obj arg public static object new special context cx object fun object arg scriptabl scope int call type if call type node specialcal eval if nativ global is eval function fun throw type error1 msg not ctor eval els if call type node specialcal with if nativ with is with function fun return nativ with new with special cx scope arg els throw kit code bug return new object fun cx scope arg function prototyp appli and function prototyp call see ecma 15 3 4 34 public static object appli or call boolean is appli context cx scriptabl scope scriptabl thi obj object arg int l arg length callabl function if thi obj instanceof callabl function callabl thi obj els object valu thi obj get default valu script runtim function class if valu instanceof callabl throw script runtim not function error valu thi obj function callabl valu scriptabl call thi null if l 0 call thi to object or null cx arg 0 if call thi null thi cover the case of arg 0 null undefin as well call thi get top call scope cx object call arg if is appli follow ecma 15 3 4 3 if l 1 call arg script runtim empti arg els object arg1 arg 1 if arg1 null arg1 undefin instanc call arg script runtim empti arg els if arg1 instanceof nativ arrai arg1 instanceof argument call arg cx get element scriptabl arg1 els throw script runtim type error0 msg arg isnt arrai els follow ecma 15 3 4 4 if l 1 call arg script runtim empti arg els call arg new object l 1 system arraycopi arg 1 call arg 0 l 1 return function call cx scope call thi call arg the eval function properti of the global object see ecma 15 1 2 1 public static object eval special context cx scriptabl scope object thi arg object arg string filenam int line number if arg length 1 return undefin instanc object x arg 0 if x instanceof string if cx ha featur context featur strict eval throw context report runtim error0 msg eval nonstr strict string messag script runtim get messag0 msg eval nonstr context report warn messag return x if filenam null int linep new int 1 filenam context get sourc posit from stack linep if filenam null line number linep 0 els filenam string sourc name script runtim make url for gener script true filenam line number error report report report default error report for eval cx get error report compil with explicit interpret instanc to forc interpret mode script script cx compil string string x new interpret report sourc name 1 null interpret function script idata eval script flag true callabl c callabl script return c call cx scope scriptabl thi arg script runtim empti arg the typeof oper public static string typeof object valu if valu null return object if valu undefin instanc return undefin if valu instanceof scriptabl if valu instanceof xml object return xml return valu instanceof callabl function object if valu instanceof string return string if valu instanceof number return number if valu instanceof boolean return boolean throw error with class name msg invalid type valu the typeof oper that correctli handl the undefin case public static string typeof name scriptabl scope string id context cx context get context scriptabl val bind cx scope id if val null return undefin return typeof get object prop val id cx public static object add object val1 object val2 context cx if val1 instanceof number val2 instanceof number return wrap number number val1 doubl valu number val2 doubl valu if val1 instanceof xml object object test xml object val1 add valu cx true val2 if test scriptabl not found return test if val2 instanceof xml object object test xml object val2 add valu cx fals val1 if test scriptabl not found return test if val1 instanceof scriptabl val1 scriptabl val1 get default valu null if val2 instanceof scriptabl val2 scriptabl val2 get default valu null if val1 instanceof string val2 instanceof string if val1 instanceof number val2 instanceof number return wrap number number val1 doubl valu number val2 doubl valu els return wrap number to number val1 to number val2 return to string val1 concat to string val2 public static object name incr decr scriptabl scope chain string id int incr decr mask scriptabl target object valu search do target scope chain do valu target get id scope chain if valu scriptabl not found break search target target get prototyp while target null scope chain scope chain get parent scope while scope chain null throw not found error scope chain id return do scriptabl incr decr target id scope chain valu incr decr mask public static object prop incr decr object obj string id context cx int incr decr mask scriptabl start to object or null cx obj if start null throw undef read error obj id scriptabl target start object valu search do valu target get id start if valu scriptabl not found break search target target get prototyp while target null start put id start na nobj return na nobj return do scriptabl incr decr target id start valu incr decr mask privat static object do scriptabl incr decr scriptabl target string id scriptabl proto chain start object valu int incr decr mask boolean post incr decr mask node post flag 0 doubl number if valu instanceof number number number valu doubl valu els number to number valu if post convert result to number valu wrap number number if incr decr mask node decr flag 0 number els number number result wrap number number target put id proto chain start result if post return valu els return result public static object elem incr decr object obj object index context cx int incr decr mask object valu get object elem obj index cx boolean post incr decr mask node post flag 0 doubl number if valu instanceof number number number valu doubl valu els number to number valu if post convert result to number valu wrap number number if incr decr mask node decr flag 0 number els number number result wrap number number set object elem obj index result cx if post return valu els return result public static object ref incr decr ref ref context cx int incr decr mask object valu ref get cx boolean post incr decr mask node post flag 0 doubl number if valu instanceof number number number valu doubl valu els number to number valu if post convert result to number valu wrap number number if incr decr mask node decr flag 0 number els number number result wrap number number ref set cx result if post return valu els return result privat static object to primit object val if val instanceof scriptabl return val scriptabl s scriptabl val object result s get default valu null if result instanceof scriptabl throw type error0 msg bad default valu return result equal see ecma 11 9 public static boolean eq object x object y if x null x undefin instanc if y null y undefin instanc return true if y instanceof scriptabl object object test scriptabl object y equival valu x if test scriptabl not found return boolean test boolean valu return fals els if x instanceof number return eq number number x doubl valu y els if x instanceof string return eq string string x y els if x instanceof boolean boolean b boolean x boolean valu if y instanceof boolean return b boolean y boolean valu if y instanceof scriptabl object object test scriptabl object y equival valu x if test scriptabl not found return boolean test boolean valu return eq number b 1 0 0 0 y els if x instanceof scriptabl if y instanceof scriptabl if x y return true if x instanceof scriptabl object object test scriptabl object x equival valu y if test scriptabl not found return boolean test boolean valu if y instanceof scriptabl object object test scriptabl object y equival valu x if test scriptabl not found return boolean test boolean valu if x instanceof wrapper y instanceof wrapper return wrapper x unwrap wrapper y unwrap return fals els if y instanceof boolean if x instanceof scriptabl object object test scriptabl object x equival valu y if test scriptabl not found return boolean test boolean valu doubl d boolean y boolean valu 1 0 0 0 return eq number d x els if y instanceof number return eq number number y doubl valu x els if y instanceof string return eq string string y x cover the case when y undefin instanc as well return fals els warn about nonj object x return x y static boolean eq number doubl x object y for if y null y undefin instanc return fals els if y instanceof number return x number y doubl valu els if y instanceof string return x to number y els if y instanceof boolean return x boolean y boolean valu 1 0 0 0 els if y instanceof scriptabl if y instanceof scriptabl object object xval wrap number x object test scriptabl object y equival valu xval if test scriptabl not found return boolean test boolean valu y to primit y els warn about nonj object y return fals privat static boolean eq string string x object y for if y null y undefin instanc return fals els if y instanceof string return x equal y els if y instanceof number return to number x number y doubl valu els if y instanceof boolean return to number x boolean y boolean valu 1 0 0 0 els if y instanceof scriptabl if y instanceof scriptabl object object test scriptabl object y equival valu x if test scriptabl not found return boolean test boolean valu y to primit y continu els warn about nonj object y return fals public static boolean shallow eq object x object y if x y if x instanceof number return true nan check doubl d number x doubl valu return d d if x null x undefin instanc return fals els if x instanceof number if y instanceof number return number x doubl valu number y doubl valu els if x instanceof string if y instanceof string return x equal y els if x instanceof boolean if y instanceof boolean return x equal y els if x instanceof scriptabl if x instanceof wrapper y instanceof wrapper return wrapper x unwrap wrapper y unwrap els warn about nonj object x return x y return fals the instanceof oper return a instanceof b public static boolean instanc of object a object b context cx check rh is an object if b instanceof scriptabl throw type error0 msg instanceof not object for primit valu on lh return fals xxx we mai want to chang thi so that 5 instanceof number true if a instanceof scriptabl return fals return scriptabl b ha instanc scriptabl a deleg to return true iff rh appear in lh proto chain protect static boolean js deleg to scriptabl lh scriptabl rh scriptabl proto lh get prototyp while proto null if proto equal rh return true proto proto get prototyp return fals the in oper thi is a new js 1 3 languag featur the in oper mirror the oper of the for in construct and test whether the rh ha the properti given by the lh it is differ from the for in construct in that br it doesn t perform to object on the right hand side br it return true for dont enum properti param a the left hand operand param b the right hand operand return true if properti name or element number a is a properti of b public static boolean in object a object b context cx if b instanceof scriptabl throw type error0 msg instanceof not object return ha object elem scriptabl b a cx public static boolean cmp lt object val1 object val2 doubl d1 d2 if val1 instanceof number val2 instanceof number d1 number val1 doubl valu d2 number val2 doubl valu els if val1 instanceof scriptabl val1 scriptabl val1 get default valu number class if val2 instanceof scriptabl val2 scriptabl val2 get default valu number class if val1 instanceof string val2 instanceof string return string val1 compar to string val2 0 d1 to number val1 d2 to number val2 return d1 d2 public static boolean cmp le object val1 object val2 doubl d1 d2 if val1 instanceof number val2 instanceof number d1 number val1 doubl valu d2 number val2 doubl valu els if val1 instanceof scriptabl val1 scriptabl val1 get default valu number class if val2 instanceof scriptabl val2 scriptabl val2 get default valu number class if val1 instanceof string val2 instanceof string return string val1 compar to string val2 0 d1 to number val1 d2 to number val2 return d1 d2 public static scriptabl object get global context cx final string global class org mozilla javascript tool shell global class global class kit class or null global class if global class null try class parm script runtim context class constructor global class ctor global class get constructor parm object arg cx return scriptabl object global class ctor new instanc arg catch except e fall through return new import top level cx public static boolean ha top call context cx return cx top call scope null public static scriptabl get top call scope context cx scriptabl scope cx top call scope if scope null throw new illeg state except return scope public static object do top call callabl callabl context cx scriptabl scope scriptabl thi obj object arg if scope null throw new illeg argument except if cx top call scope null throw new illeg state except object result cx top call scope scriptabl object get top level scope scope cx us dynam scope cx ha featur context featur dynam scope context factori f cx get factori try result f do top call callabl cx scope thi obj arg final cx top call scope null cleanup cach refer cx cachedxml lib null if cx current activ call null function should alwai call exit activ function if it creat activ record throw new illeg state except return result return tt possibl dynam scope tt if tt static top scope tt is present on it prototyp chain and return tt static top scope tt otherwis should onli be call when tt static top scope tt is top scope static scriptabl check dynam scope scriptabl possibl dynam scope scriptabl static top scope return cx top call scope if scope if possibl dynam scope static top scope return possibl dynam scope scriptabl proto possibl dynam scope for proto proto get prototyp if proto static top scope return possibl dynam scope if proto null return static top scope public static void init script nativ function fun obj scriptabl thi obj context cx scriptabl scope boolean eval script if cx top call scope null throw new illeg state except int var count fun obj get param and var count if var count 0 scriptabl var scope scope never defin ani variabl from var statement insid with object see bug 38590 while var scope instanceof nativ with var scope var scope get parent scope for int i var count i 0 string name fun obj get param or var name i don t overwrit exist def if alreadi defin in object or prototyp of object if scriptabl object ha properti scope name if eval script global var definit ar suppos to be dontdelet scriptabl object defin properti var scope name undefin instanc scriptabl object perman els var scope put name var scope undefin instanc public static scriptabl creat function activ nativ function fun obj scriptabl scope object arg return new nativ call fun obj scope arg public static void enter activ function context cx scriptabl activ if cx top call scope null throw new illeg state except nativ call call nativ call activ call parent activ call cx current activ call cx current activ call call public static void exit activ function context cx nativ call call cx current activ call cx current activ call call parent activ call call parent activ call null static nativ call find function activ context cx function f nativ call call cx current activ call while call null if call function f return call call call parent activ call return null public static scriptabl new catch scope throwabl t scriptabl last catch scope string except name context cx scriptabl scope object obj boolean cach obj get obj if t instanceof java script except cach obj fals obj java script except t get valu els cach obj true creat wrapper object unless it wa associ with the previou scope object if last catch scope null nativ object last nativ object last catch scope obj last get associ valu t if obj null kit code bug break get obj rhino except re string error name string error msg throwabl java except null if t instanceof ecma error ecma error ee ecma error t re ee error name ee get name error msg ee get error messag els if t instanceof wrap except wrap except we wrap except t re we java except we get wrap except error name java except error msg java except get class get name java except get messag els if t instanceof evalu except pure evalu except nor wrap except instanc evalu except ee evalu except t re ee error name intern error error msg ee get messag els script can catch onli instanc of java script except ecma error and evalu except throw kit code bug string sourc uri re sourc name if sourc uri null sourc uri int line re line number object arg if line 0 arg new object error msg sourc uri new integ line els arg new object error msg sourc uri scriptabl error object cx new object scope error name arg scriptabl object put properti error object name error name if java except null object wrap cx get wrap factori wrap cx scope java except null scriptabl object defin properti error object java except wrap scriptabl object perman scriptabl object readonli if re null object wrap cx get wrap factori wrap cx scope re null scriptabl object defin properti error object rhino except wrap scriptabl object perman scriptabl object readonli obj error object nativ object catch scope object new nativ object see ecma 12 4 catch scope object defin properti except name obj scriptabl object perman if cach obj catch scope object associ valu t obj return catch scope object public static scriptabl enter with object obj context cx scriptabl scope scriptabl sobj to object or null cx obj if sobj null throw type error1 msg undef with to string obj if sobj instanceof xml object xml object xml object xml object sobj return xml object enter with scope return new nativ with scope sobj public static scriptabl leav with scriptabl scope nativ with nw nativ with scope return nw get parent scope public static scriptabl enter dot queri object valu scriptabl scope if valu instanceof xml object throw not xml error valu xml object object xml object valu return object enter dot queri scope public static object updat dot queri boolean valu scriptabl scope return null to continu loop nativ with nw nativ with scope return nw updat dot queri valu public static scriptabl leav dot queri scriptabl scope nativ with nw nativ with scope return nw get parent scope public static void set function proto and parent base function fn scriptabl scope fn set parent scope scope fn set prototyp scriptabl object get function prototyp scope public static void set object proto and parent scriptabl object object scriptabl scope compar with function it alwai set the scope to top scope scope scriptabl object get top level scope scope object set parent scope scope scriptabl proto scriptabl object get class prototyp scope object get class name object set prototyp proto public static void init function context cx scriptabl scope nativ function function int type boolean from eval code if type function node function statement string name function get function name if name null name length 0 if from eval code ecma specifi that function defin in global and function scope outsid eval should have dontdelet set scriptabl object defin properti scope name function scriptabl object perman els scope put name scope function els if type function node function express statement string name function get function name if name null name length 0 alwai put function express statement into initi activ object ignor the with statement to follow spider monkei while scope instanceof nativ with scope scope get parent scope scope put name scope function els throw kit code bug public static scriptabl new arrai liter object object int skip indexc context cx scriptabl scope int count object length int skip count 0 if skip indexc null skip count skip indexc length int length count skip count integ length obj new integ length scriptabl arrai obj if the version is 120 then new arrai 4 mean creat a new arrai with 4 as the first element in thi case we have to set length properti manual if cx get languag version context version 1 2 arrai obj cx new object scope arrai script runtim empti arg scriptabl object put properti arrai obj length length obj els arrai obj cx new object scope arrai new object length obj int skip 0 for int i 0 j 0 i length i if skip skip count skip indexc skip i skip continu scriptabl object put properti arrai obj i object j j return arrai obj public static scriptabl new object liter object properti id object properti valu context cx scriptabl scope scriptabl object cx new object scope for int i 0 end properti id length i end i object id properti id i object valu properti valu i if id instanceof string scriptabl object put properti object string id valu els int index integ id int valu scriptabl object put properti object index valu return object public static boolean is arrai object object obj return obj instanceof nativ arrai obj instanceof argument public static object get arrai element scriptabl object context cx context get context long long len nativ arrai get length properti cx object if long len integ max valu arrai beyond max int is not in java in ani case throw new illeg argument except int len int long len if len 0 return script runtim empti arg els object result new object len for int i 0 i len i object elem scriptabl object get properti object i result i elem scriptabl not found undefin instanc elem return result static void check deprec context cx string name int version cx get languag version if version context version 1 4 version context version default string msg get messag1 msg deprec ctor name if version context version default context report warn msg els throw context report runtim error msg public static string get messag0 string messag id return get messag messag id null public static string get messag1 string messag id object arg1 object argument arg1 return get messag messag id argument public static string get messag2 string messag id object arg1 object arg2 object argument arg1 arg2 return get messag messag id argument public static string get messag3 string messag id object arg1 object arg2 object arg3 object argument arg1 arg2 arg3 return get messag messag id argument public static string get messag4 string messag id object arg1 object arg2 object arg3 object arg4 object argument arg1 arg2 arg3 arg4 return get messag messag id argument public static string get messag string messag id object argument final string default resourc org mozilla javascript resourc messag context cx context get current context local local cx null cx get local local get default resourc bundl doe cach resourc bundl rb resourc bundl get bundl default resourc local string format string try format string rb get string messag id catch java util miss resourc except mre throw new runtim except no messag resourc found for messag properti messag id it s ok to format the string even if argument is null we need to format it anywai to make doubl s collaps to singl s todo messag format is not avail on p java messag format formatt new messag format format string return formatt format argument public static ecma error construct error string error string messag int linep new int 1 string filenam context get sourc posit from stack linep return construct error error messag filenam linep 0 null 0 public static ecma error construct error string error string messag string sourc name int line number string line sourc int column number return new ecma error error messag sourc name line number line sourc column number public static ecma error type error string messag return construct error type error messag public static ecma error type error0 string messag id string msg get messag0 messag id return type error msg public static ecma error type error1 string messag id string arg1 string msg get messag1 messag id arg1 return type error msg public static ecma error type error2 string messag id string arg1 string arg2 string msg get messag2 messag id arg1 arg2 return type error msg public static ecma error type error3 string messag id string arg1 string arg2 string arg3 string msg get messag3 messag id arg1 arg2 arg3 return type error msg public static runtim except undef read error object object object id string id str id null null id to string return type error2 msg undef prop read to string object id str public static runtim except undef call error object object object id string id str id null null id to string return type error2 msg undef method call to string object id str public static runtim except undef write error object object object id object valu string id str id null null id to string string valu str valu instanceof scriptabl valu to string to string valu return type error3 msg undef prop write to string object id str valu str public static runtim except not found error scriptabl object string properti xxx us object to improv the error messag string msg get messag1 msg is not defin properti throw construct error refer error msg public static runtim except not function error object valu return not function error valu valu public static runtim except not function error object valu object messag helper xxx us valu for better error report string msg messag helper null null messag helper to string if valu scriptabl not found return type error1 msg function not found msg return type error2 msg isnt function msg valu null null valu get class get name privat static runtim except not xml error object valu throw type error1 msg isnt xml object script runtim to string valu privat static void warn about nonj object object nonj object string messag rhino usag warn miss context java toj convers n rhino runtim detect object nonj object of class nonj object get class get name where it expect string number boolean or scriptabl instanc pleas check your code for miss context java toj call context report warn messag just to be sure that it would be notic system err println messag public static reg exp proxi get reg exp proxi context cx return cx get reg exp proxi public static void set reg exp proxi context cx reg exp proxi proxi if proxi null throw new illeg argument except cx reg exp proxi proxi public static reg exp proxi check reg exp proxi context cx reg exp proxi result get reg exp proxi cx if result null throw context report runtim error0 msg no regexp return result privat static xml lib currentxml lib context cx script should be run to access thi if cx top call scope null throw new illeg state except xml lib xml lib cx cachedxml lib if xml lib null xml lib xml lib extract from scope cx top call scope if xml lib null throw new illeg state except cx cachedxml lib xml lib return xml lib escap the reserv charact in a valu of an attribut param valu unescap text return the escap text public static string escap attribut valu object valu context cx xml lib xml lib currentxml lib cx return xml lib escap attribut valu valu escap the reserv charact in a valu of a text node param valu unescap text return the escap text public static string escap text valu object valu context cx xml lib xml lib currentxml lib cx return xml lib escap text valu valu public static ref member ref object obj object elem context cx int member type flag if obj instanceof xml object throw not xml error obj xml object xml object xml object obj return xml object member ref cx elem member type flag public static ref member ref object obj object namespac object elem context cx int member type flag if obj instanceof xml object throw not xml error obj xml object xml object xml object obj return xml object member ref cx namespac elem member type flag public static ref name ref object name context cx scriptabl scope int member type flag xml lib xml lib currentxml lib cx return xml lib name ref cx name scope member type flag public static ref name ref object namespac object name context cx scriptabl scope int member type flag xml lib xml lib currentxml lib cx return xml lib name ref cx namespac name scope member type flag privat static void store index result context cx int index cx scratch index index static int last index result context cx return cx scratch index public static void store uint32 result context cx long valu if valu 32 0 throw new illeg argument except cx scratch uint32 valu public static long last uint32 result context cx long valu cx scratch uint32 if valu 32 0 throw new illeg state except return valu privat static void store scriptabl context cx scriptabl valu the previosli store scratch scriptabl should be consum if cx scratch scriptabl null throw new illeg state except cx scratch scriptabl valu public static scriptabl last store scriptabl context cx scriptabl result cx scratch scriptabl cx scratch scriptabl null return result static string make url for gener script boolean is eval string master script url int master script line if is eval return master script url master script line eval els return master script url master script line function static boolean is gener script string sourc url alert thi mai clash with a valid url contain eval or function return sourc url index of eval 0 sourc url index of function 0 privat static runtim except error with class name string msg object val return context report runtim error1 msg val get class get name implement gener class loader public defin class loader thi parent loader get class get class loader public defin class loader class loader parent loader thi parent loader parent loader public class defin class string name byte data return super defin class name data 0 data length public void link class class cl resolv class cl public class load class string name boolean resolv throw class not found except class cl find load class name if cl null if parent loader null cl parent loader load class name els cl find system class name if resolv resolv class cl return cl make glue object implement interfac cl that will call the suppli js function when call onli interfac were all method have the same signatur is support return the glue object or null if tt cl tt is not interfac or ha method with differ signatur static object creat context cx class cl callabl function if cl is interfac throw new illeg argument except scriptabl top scope script runtim get top call scope cx class cach cach class cach get top scope interfac adapt adapt adapt interfac adapt cach get interfac adapt cl context factori cf cx get factori if adapt null method method cl get method if method length 0 throw context report runtim error2 msg no empti interfac convers string valu of function cl get class get name boolean can call function fals can call function check class arg type method 0 get paramet type check that the rest of method ha the same signatur for int i 1 i method length i class type2 method i get paramet type if type2 length arg type length break can call function check for int j 0 j arg type length j if type2 j arg type j break can call function check can call function true if can call function throw context report runtim error2 msg no function interfac convers string valu of function cl get class get name adapt new interfac adapt cf cl cach cach interfac adapt cl adapt return vm bridg instanc new interfac proxi adapt proxi helper cf adapt function top scope privat interfac adapt context factori cf class cl thi proxi helper vm bridg instanc get interfac proxi helper cf new class cl public object invok context factori cf final object target final scriptabl top scope final method method final object arg context action action new context action public object run context cx return invok impl cx target top scope method arg return cf call action context action action new context action public object run context cx return invok impl cx target top scope method arg object invok impl context cx object target scriptabl top scope method method object arg int n arg null 0 arg length string method name method get name callabl function callabl target scriptabl thi obj top scope object jsarg new object n 1 jsarg n method get name if n 0 wrap factori wf cx get wrap factori for int i 0 i n i jsarg i wf wrap cx top scope arg i null object result function call cx top scope thi obj jsarg class java result type method get return type if java result type void type result null els result context js to java result java result type return result creat a deleg prototyp thi constructor should onli be us for creat prototyp object of deleg see org mozilla javascript deleg construct public deleg creat a new deleg that forward request to a delege scriptabl object param obj the delege see org mozilla javascript scriptabl public deleg scriptabl obj thi obj obj crete new deleg instanc the default implement call thi get class new instanc see construct context cx scriptabl scope object arg protect deleg new instanc try return deleg thi get class new instanc catch except ex throw context throw as script runtim ex ex retriev the delege return the delege public scriptabl get delege return obj set the delege param obj the delege see org mozilla javascript scriptabl public void set delege scriptabl obj thi obj obj see org mozilla javascript scriptabl get class name public string get class name return obj get class name see org mozilla javascript scriptabl get public object get string name scriptabl start return obj get name start see org mozilla javascript scriptabl get public object get int index scriptabl start return obj get index start see org mozilla javascript scriptabl ha public boolean ha string name scriptabl start return obj ha name start see org mozilla javascript scriptabl ha public boolean ha int index scriptabl start return obj ha index start see org mozilla javascript scriptabl put public void put string name scriptabl start object valu obj put name start valu see org mozilla javascript scriptabl put public void put int index scriptabl start object valu obj put index start valu see org mozilla javascript scriptabl delet public void delet string name obj delet name see org mozilla javascript scriptabl delet public void delet int index obj delet index see org mozilla javascript scriptabl get prototyp public scriptabl get prototyp return obj get prototyp see org mozilla javascript scriptabl set prototyp public void set prototyp scriptabl prototyp obj set prototyp prototyp see org mozilla javascript scriptabl get parent scope public scriptabl get parent scope return obj get parent scope see org mozilla javascript scriptabl set parent scope public void set parent scope scriptabl parent obj set parent scope parent see org mozilla javascript scriptabl get id public object get id return obj get id note that thi method doe not get forward to the delege if the code hint code paramet is null code script runtim scriptabl class code or code script runtim function class code instead the object itself is return param hint the type hint return the default valu see org mozilla javascript scriptabl get default valu public object get default valu class hint return hint null hint script runtim scriptabl class hint script runtim function class thi obj get default valu hint see org mozilla javascript scriptabl ha instanc public boolean ha instanc scriptabl instanc return obj ha instanc instanc see org mozilla javascript function call public object call context cx scriptabl scope scriptabl thi obj object arg return function obj call cx scope thi obj arg note that if the code delege code is code null code thi method creat a new instanc of the deleg itself rathert than forward the call to the code delege code thi permit the us of deleg prototyp param cx the current context for thi thread param scope an enclos scope of the caller except when the function is call from a closur param arg the arrai of argument return the alloc object see function construct context scriptabl object public scriptabl construct context cx scriptabl scope object arg if obj null thi littl trick allow us to declar prototyp object for deleg deleg n new instanc scriptabl delege if arg length 0 delege new nativ object els delege script runtim to object cx scope arg 0 n set delege delege return n els return function obj construct cx scope arg public class tool error report implement error report public tool error report boolean report warn thi report warn system err public tool error report boolean report warn print stream err thi report warn report warn thi err err look up the messag correspond to messag id in the org mozilla javascript tool shell resourc messag properti file for internation support public static string get messag string messag id return get messag messag id object null public static string get messag string messag id string argument object arg argument return get messag messag id arg public static string get messag string messag id object arg1 object arg2 object arg arg1 arg2 return get messag messag id arg public static string get messag string messag id object arg context cx context get current context local local cx null local get default cx get local resourc bundl doe cach resourc bundl rb resourc bundl get bundl org mozilla javascript tool resourc messag local string format string try format string rb get string messag id catch java util miss resourc except mre throw new runtim except no messag resourc found for messag properti messag id if arg null return format string els messag format formatt new messag format format string return formatt format arg privat static string get except messag rhino except ex string msg if ex instanceof java script except msg get messag msg uncaughtj except ex detail els if ex instanceof ecma error msg get messag msg uncaught ecma error ex detail els msg ex to string return msg public void warn string messag string sourc name int line string line sourc int line offset if report warn return report error messag messag sourc name line line sourc line offset true public void error string messag string sourc name int line string line sourc int line offset ha report error flag true report error messag messag sourc name line line sourc line offset fals public evalu except runtim error string messag string sourc name int line string line sourc int line offset error messag sourc name line line sourc line offset return new evalu except messag sourc name line line sourc line offset public boolean ha report error return ha report error flag public boolean is report warn return thi report warn public void set is report warn boolean report warn thi report warn report warn public static void report except error report er rhino except ex if er instanceof tool error report tool error report er report except ex els string msg get except messag ex er error msg ex sourc name ex line number ex line sourc ex column number public void report except rhino except ex if ex instanceof wrap except wrap except we wrap except ex we print stack trace err els string msg get except messag ex report error messag msg ex sourc name ex line number ex line sourc ex column number fals privat void report error messag string messag string sourc name int line string line sourc int line offset boolean just warn if line 0 string line str string valu of line if sourc name null object arg sourc name line str messag messag get messag msg format3 arg els object arg line str messag messag get messag msg format2 arg els object arg messag messag get messag msg format1 arg if just warn messag get messag msg warn messag err println messag prefix messag if null line sourc err println messag prefix line sourc err println messag prefix build indic line offset privat string build indic int offset string buffer sb new string buffer for int i 0 i offset 1 i sb append sb append return sb to string public static class iter iter obj to int map master thi master master final void init object kei int valu int kei count thi kei kei thi valu valu thi cursor 1 thi remain kei count public void start master init iter thi next public boolean done return remain 0 public void next if remain 1 kit code bug if remain 0 remain 1 cursor 1 els for cursor cursor object kei kei cursor if kei null kei delet remain break public object get kei object kei kei cursor if kei uniqu tag null valu kei null return kei public int get valu return valu cursor public void set valu int valu valu cursor valu public obj to int map thi 4 public obj to int map int kei count hint if kei count hint 0 kit code bug tabl grow when number of store kei 3 4 of max capac int minim capac kei count hint 4 3 int i for i 2 1 i minim capac i power i if check power 2 kit code bug public boolean is empti return kei count 0 public int size return kei count public boolean ha object kei if kei null kei uniqu tag null valu return 0 find index kei get integ valu assign with kei return kei integ valu or default valu if kei is absent public int get object kei int default valu if kei null kei uniqu tag null valu int index find index kei if 0 index return valu index return default valu get integ valu assign with kei return kei integ valu throw runtim except if kei doe not exist public int get exist object kei if kei null kei uniqu tag null valu int index find index kei if 0 index return valu index kei must exist kit code bug return 0 public void put object kei int valu if kei null kei uniqu tag null valu int index ensur index kei valu index valu if tabl alreadi contain a kei that equal to kei arg return that kei while set it valu to zero otherwis add kei arg with 0 valu to the tabl and return it public object intern object kei arg boolean null kei fals if kei arg null null kei true kei arg uniqu tag null valu int index ensur index kei arg valu index 0 return null kei null kei index public void remov object kei if kei null kei uniqu tag null valu int index find index kei if 0 index kei index delet kei count public void clear int i kei length while i 0 kei i null kei count 0 occupi count 0 public iter new iter return new iter thi from the iter inner class to workaround jdk 1 1 compil bug which gener code trigger verifi error on recent jv ms final void init iter iter i i init kei valu kei count return arrai of present kei public object get kei object arrai new object kei count get kei arrai 0 return arrai public void get kei object arrai int offset int count kei count for int i 0 count 0 i object kei kei i if kei null kei delet if kei uniqu tag null valu kei null arrai offset kei offset count privat static int tabl lookup step int fraction int mask int power int shift 32 2 power if shift 0 return fraction shift mask 1 els return fraction mask shift 1 privat int find index object kei if kei null int hash kei hash code int fraction hash a int index fraction 32 power object test kei index if test null int n 1 power if test kei valu n index hash test equal kei return index search in tabl after first fail attempt int mask n 1 int step tabl lookup step fraction mask power int n 0 for if check if n occupi count kit code bug n index index step mask test kei index if test null break if test kei valu n index hash test equal kei return index return 1 and enough free space privat int insert new kei object kei int hash if check occupi count kei count kit code bug if check kei count 1 power kit code bug int fraction hash a int index fraction 32 power int n 1 power if kei index null int mask n 1 int step tabl lookup step fraction mask power int first index index do if check kei index delet kit code bug index index step mask if check first index index kit code bug while kei index null kei index kei valu n index hash occupi count kei count return index privat void rehash tabl if kei null if check kei count 0 kit code bug if check occupi count 0 kit code bug int n 1 power kei new object n valu new int 2 n els check if remov delet entri would free enough space if kei count 2 occupi count need to grow less then half of delet entri power int n 1 power object old kei kei int old valu valu int oldn old kei length kei new object n valu new int 2 n int remain kei count occupi count kei count 0 for int i 0 remain 0 i object kei old kei i if kei null kei delet int kei hash old valu oldn i int index insert new kei kei kei hash valu index old valu i remain ensur kei index creat on if necessari privat int ensur index object kei int hash kei hash code int index 1 int first delet 1 if kei null int fraction hash a index fraction 32 power object test kei index if test null int n 1 power if test kei valu n index hash test equal kei return index if test delet first delet index search in tabl after first fail attempt int mask n 1 int step tabl lookup step fraction mask power int n 0 for if check if n occupi count kit code bug n index index step mask test kei index if test null break if test kei valu n index hash test equal kei return index if test delet first delet 0 first delet index insert of new kei if check kei null kei index null kit code bug if first delet 0 index first delet els need to consum empti entri check occup level if kei null occupi count 4 1 power 3 too litl unus entri rehash rehash tabl return insert new kei kei hash occupi count kei index kei valu 1 power index hash kei count return index privat void write object object output stream out throw io except out default write object int count kei count for int i 0 count 0 i object kei kei i if kei null kei delet count out write object kei out write int valu i privat void read object object input stream in throw io except class not found except in default read object int written kei count kei count if written kei count 0 kei count 0 int n 1 power kei new object n valu new int 2 n for int i 0 i written kei count i object kei in read object int hash kei hash code int index insert new kei kei hash valu index in read int prototyp valu id scriptabl object obj int max id if obj null throw new illeg argument except if max id 1 throw new illeg argument except thi obj obj thi max id max id final int get max id return max id final void init valu int id string name object valu int attribut if 1 id id max id throw new illeg argument except if name null throw new illeg argument except if valu not found throw new illeg argument except scriptabl object check valid attribut attribut if obj find prototyp id name id throw new illeg argument except name if id constructor id if valu instanceof id function object throw new illeg argument except consructor should be initi with id function object constructor id function object valu constructor attr short attribut return init slot id name valu attribut privat void init slot int id string name object valu int attribut object arrai valu arrai if arrai null throw new illeg state except if valu null valu uniqu tag null valu int index id 1 slot span synchron thi object valu2 arrai index valu slot if valu2 null arrai index valu slot valu arrai index name slot name attribut arrai id 1 short attribut els if name equal arrai index name slot throw new illeg state except final id function object creat precach constructor if constructor id 0 throw new illeg state except constructor id obj find prototyp id constructor if constructor id 0 throw new illeg state except no id for constructor properti obj init prototyp id constructor id if constructor null throw new illeg state except obj get class get name init prototyp id did not initi id constructor id constructor init function obj get class name scriptabl object get top level scope obj constructor mark as constructor obj return constructor final int find id string name object arrai valu arrai if arrai null return obj find prototyp id name int id last found id if name arrai id 1 slot span name slot return id id obj find prototyp id name if id 0 int name slot id 1 slot span name slot make cach to work arrai name slot name last found id id return id final boolean ha int id object arrai valu arrai if arrai null not yet initi assum all exist return true int valu slot id 1 slot span valu slot object valu arrai valu slot if valu null the particular entri ha not been yet initi return true return valu not found final object get int id object valu ensur id id if valu uniqu tag null valu valu null return valu final void set int id scriptabl start object valu if valu not found throw new illeg argument except ensur id id int attr attribut arrai id 1 if attr readonli 0 if start obj if valu null valu uniqu tag null valu int valu slot id 1 slot span valu slot synchron thi valu arrai valu slot valu els int name slot id 1 slot span name slot string name string valu arrai name slot start put name start valu final void delet int id ensur id id int attr attribut arrai id 1 if attr perman 0 int valu slot id 1 slot span valu slot synchron thi valu arrai valu slot not found attribut arrai id 1 empti final int get attribut int id ensur id id return attribut arrai id 1 final void set attribut int id int attribut scriptabl object check valid attribut attribut ensur id id synchron thi attribut arrai id 1 short attribut final object get name boolean get all object extra entri object name null int count 0 for int id 1 id max id id object valu ensur id id if get all attribut arrai id 1 dontenum 0 if valu not found int name slot id 1 slot span name slot string name string valu arrai name slot if name null name new object max id name count name if count 0 return extra entri els if extra entri null extra entri length 0 if count name length object tmp new object count system arraycopi name 0 tmp 0 count name tmp return name els int extra extra entri length object tmp new object extra count system arraycopi extra entri 0 tmp 0 extra system arraycopi name 0 tmp extra count return tmp privat object ensur id int id object arrai valu arrai if arrai null synchron thi arrai valu arrai if arrai null arrai new object max id slot span valu arrai arrai attribut arrai new short max id int valu slot id 1 slot span valu slot object valu arrai valu slot if valu null if id constructor id init slot constructor id constructor constructor constructor attr constructor null no need to refer it ani longer els obj init prototyp id id valu arrai valu slot if valu null throw new illeg state except obj get class get name init prototyp id int id did not initi id id return valu public id scriptabl object public id scriptabl object scriptabl scope scriptabl prototyp super scope prototyp protect final object default get string name return super get name thi protect final void default put string name object valu super put name thi valu public boolean ha string name scriptabl start int info find instanc id info name if info 0 int attr info 16 if attr perman 0 return true int id info 0xffff return not found get instanc id valu id if prototyp valu null int id prototyp valu find id name if id 0 return prototyp valu ha id return super ha name start public object get string name scriptabl start int info find instanc id info name if info 0 int id info 0xffff return get instanc id valu id if prototyp valu null int id prototyp valu find id name if id 0 return prototyp valu get id return super get name start public void put string name scriptabl start object valu int info find instanc id info name if info 0 if start thi is seal throw context report runtim error1 msg modifi seal name int attr info 16 if attr readonli 0 if start thi int id info 0xffff set instanc id valu id valu els start put name start valu return if prototyp valu null int id prototyp valu find id name if id 0 if start thi is seal throw context report runtim error1 msg modifi seal name prototyp valu set id start valu return super put name start valu public void delet string name int info find instanc id info name if info 0 let the super class to throw except for seal object if is seal int attr info 16 if attr perman 0 int id info 0xffff set instanc id valu id not found return if prototyp valu null int id prototyp valu find id name if id 0 if is seal prototyp valu delet id return super delet name public int get attribut string name int info find instanc id info name if info 0 int attr info 16 return attr if prototyp valu null int id prototyp valu find id name if id 0 return prototyp valu get attribut id return super get attribut name public void set attribut string name int attribut scriptabl object check valid attribut attribut int info find instanc id info name if info 0 int current attribut info 16 if attribut current attribut throw new runtim except chang of attribut for thi id is not support return if prototyp valu null int id prototyp valu find id name if id 0 prototyp valu set attribut id attribut return super set attribut name attribut object get id boolean get all object result super get id get all if prototyp valu null result prototyp valu get name get all result int max instanc id get max instanc id if max instanc id 0 object id null int count 0 for int id max instanc id id 0 id string name get instanc id name id int info find instanc id info name if info 0 int attr info 16 if attr perman 0 if not found get instanc id valu id continu if get all attr dontenum 0 if count 0 need extra room for no more then 1 id name id new object id id count name if count 0 if result length 0 id length count result id els object tmp new object result length count system arraycopi result 0 tmp 0 result length system arraycopi id 0 tmp result length count result tmp return result get maximum id find instanc id info can gener protect int get max instanc id return 0 protect static int instanc id info int attribut int id return attribut 16 id map name to id of instanc properti should return 0 if not found or the result of link instanc id info int int protect int find instanc id info string name return 0 map id back to properti name it defin protect string get instanc id name int id throw new illeg argument except string valu of id get id valu if id valu is constant descend can call cach id valu to store valu in the perman cach default implement creat id function object instanc for given id and cach it valu protect object get instanc id valu int id throw new illeg state except string valu of id set or delet id valu if valu not found the implement should make sure that the follow get instanc id valu return not found protect void set instanc id valu int id object valu throw new illeg state except string valu of id thi obj will be null if invok as constructor in which case instanc of scriptabl should be return public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg throw f unknown public final id function object export asj class int max prototyp id scriptabl scope boolean seal set scope and prototyp unless thi is top level scope itself if scope thi scope null set parent scope scope set prototyp get object prototyp scope activ prototyp map max prototyp id id function object ctor prototyp valu creat precach constructor if seal seal object fill constructor properti ctor if seal ctor seal object ctor export as scope properti return ctor public final boolean ha prototyp map return prototyp valu null public final void activ prototyp map int max prototyp id prototyp valu valu new prototyp valu thi max prototyp id synchron thi if prototyp valu null throw new illeg state except prototyp valu valu public final void init prototyp method object tag int id string name int ariti scriptabl scope scriptabl object get top level scope thi id function object f new id function tag id name ariti scope prototyp valu init valu id name f dontenum public final void init prototyp constructor id function object f int id prototyp valu constructor id if id 0 throw new illeg state except if f method id id throw new illeg argument except if is seal f seal object prototyp valu init valu id constructor f dontenum public final void init prototyp valu int id string name object valu int attribut prototyp valu init valu id name valu attribut protect void init prototyp id int id throw new illeg state except string valu of id protect int find prototyp id string name throw new illeg state except name protect void fill constructor properti id function object ctor protect void add id function properti scriptabl obj object tag int id string name int ariti scriptabl scope scriptabl object get top level scope obj id function object f new id function tag id name ariti scope f add as properti obj util method to construct type error to indic incompat call when convert script thi obj to a particular type is not possibl possibl usag would be to have a privat function like real thi pre privat static nativ someth real thi scriptabl thi obj id function object f if thi obj instanceof nativ someth throw incompat call error f return nativ someth thi obj pre note that although such function can be implement univers via java lang class is instanc it would be much more slower param read onli specifi if the function f doe not chang state of object return scriptabl object suitabl for a check by the instanceof oper throw runtim except if no more instanceof target can be found protect static ecma error incompat call error id function object f throw script runtim type error1 msg incompat call f get function name privat id function object new id function object tag int id string name int ariti scriptabl scope id function object f new id function object thi tag id name ariti scope if is seal f seal object return f privat void read object object input stream stream throw io except class not found except stream default read object int max prototyp id stream read int if max prototyp id 0 activ prototyp map max prototyp id privat void write object object output stream stream throw io except stream default write object int max prototyp id 0 if prototyp valu null max prototyp id prototyp valu get max id stream write int max prototyp id protect boolean ha featur context cx int featur index switch featur index case context featur strict var case context featur strict eval return strict mode return super ha featur cx featur index protect void on context creat context cx cx set languag version languag version cx set optim level optim level if error report null cx set error report error report super on context creat cx public void set strict mode boolean flag check not seal thi strict mode flag public void set languag version int version context check languag version version check not seal thi languag version version public void set optim level int optim level context check optim level optim level check not seal thi optim level optim level public void set error report error report error report if error report null throw new illeg argument except thi error report error report static final long serial versionuid 6948590651130498591l public nativ java object public nativ java object scriptabl scope object java object class static type thi parent scope thi java object java object thi static type static type init member protect void init member class dynam type if java object null dynam type java object get class els dynam type static type member java member lookup class parent dynam type static type field and method member get field and method object thi java object fals public boolean ha string name scriptabl start return member ha name fals public boolean ha int index scriptabl start return fals public object get string name scriptabl start if field and method null object result field and method get name if result null return result todo pass thi as the scope is bogu sinc it ha no parent scope return member get thi name java object fals public object get int index scriptabl start throw member report member not found integ to string index public void put string name scriptabl start object valu we could be ask to modifi the valu of a properti in the prototyp sinc we can t add a properti to a java object we modifi it in the prototyp rather than copi it down if prototyp null member ha name fals member put thi name java object valu fals els prototyp put name prototyp valu public void put int index scriptabl start object valu throw member report member not found integ to string index public boolean ha instanc scriptabl valu thi is an instanc of a java class so alwai return fals return fals public void delet string name public void delet int index public scriptabl get prototyp if prototyp null java object instanceof string return scriptabl object get class prototyp parent string return prototyp set the prototyp of the object public void set prototyp scriptabl m prototyp m return the parent enclos scope of the object public scriptabl get parent scope return parent set the parent enclos scope of the object public void set parent scope scriptabl m parent m public object get id return member get id fals deprec us link context get wrap factori togeth with call link wrap factori wrap context cx scriptabl scope object obj class public static object wrap scriptabl scope object obj class static type context cx context get context return cx get wrap factori wrap cx scope obj static type public object unwrap return java object public string get class name return java object public object get default valu class hint object valu if hint null if java object instanceof boolean hint script runtim boolean class if hint null hint script runtim string class valu java object to string els string convert name if hint script runtim boolean class convert name boolean valu els if hint script runtim number class convert name doubl valu els throw context report runtim error0 msg default valu object convert object get convert name thi if convert object instanceof function function f function convert object valu f call context get context f get parent scope thi script runtim empti arg els if hint script runtim number class java object instanceof boolean boolean b boolean java object boolean valu valu script runtim wrap number b 1 0 0 0 els valu java object to string return valu determin whether we can should convert between the given type and the desir on thi should be superced by a convers cost calcul function but for now i ll hide behind preced public static boolean can convert object from obj class to int weight get convers weight from obj to return weight convers none deriv a rank base on how natur the convers is the special valu convers none mean no convers is possibl and convers nontrivi signal that more type conform test is requir base on a href http www mozilla org js liveconnect lc3 method overload html prefer method convers from live connect 3 a static int get convers weight object from obj class to int from code getj type code from obj switch from code case jstype undefin if to script runtim string class to script runtim object class return 1 break case jstype null if to is primit return 1 break case jstype boolean boolean is 1 if to boolean type return 1 els if to script runtim boolean class return 2 els if to script runtim object class return 3 els if to script runtim string class return 4 break case jstype number if to is primit if to doubl type return 1 els if to boolean type return 1 get size rank to els if to script runtim string class nativ number ar 1 8 return 9 els if to script runtim object class return 10 els if script runtim number class is assign from to doubl is 1 return 2 break case jstype string if to script runtim string class return 1 els if to is instanc from obj return 2 els if to is primit if to charact type return 3 els if to boolean type return 4 break case jstype java class if to script runtim class class return 1 els if to script runtim object class return 3 els if to script runtim string class return 4 break case jstype java object case jstype java arrai object java obj from obj if java obj instanceof wrapper java obj wrapper java obj unwrap if to is instanc java obj return convers nontrivi if to script runtim string class return 2 els if to is primit to boolean type return from code jstype java arrai convers nontrivi 2 get size rank to break case jstype object other object take 1 3 spot if to from obj get class no convers requir return 1 if to is arrai if from obj instanceof nativ arrai thi is a nativ arrai convers to a java arrai arrai convers ar all equal and prefer to object and string convers per lc3 return 1 els if to script runtim object class return 2 els if to script runtim string class return 3 els if to script runtim date class if from obj instanceof nativ date thi is a nativ date to java date convers return 1 els if to is interfac if from obj instanceof function see comment in coerc type if to get method length 1 return 1 return 11 els if to is primit to boolean type return 3 get size rank to break return convers none static int get size rank class a type if a type doubl type return 1 els if a type float type return 2 els if a type long type return 3 els if a type integ type return 4 els if a type short type return 5 els if a type charact type return 6 els if a type byte type return 7 els if a type boolean type return convers none els return 8 privat static int getj type code object valu if valu null return jstype null els if valu undefin instanc return jstype undefin els if valu instanceof string return jstype string els if valu instanceof number return jstype number els if valu instanceof boolean return jstype boolean els if valu instanceof scriptabl if valu instanceof nativ java class return jstype java class els if valu instanceof nativ java arrai return jstype java arrai els if valu instanceof wrapper return jstype java object els return jstype object els if valu instanceof class return jstype java class els class valu class valu get class if valu class is arrai return jstype java arrai els return jstype java object not intend for public us caller should us the public api context to type see org mozilla javascript context js to java object class deprec as of 1 5 releas 4 public static object coerc type class type object valu return coerc type impl type valu type mung for field set and method invoc conform to lc3 specif static object coerc type impl class type object valu if valu null valu get class type return valu switch getj type code valu case jstype null rais error if type is primit if type is primit report convers error valu type return null case jstype undefin if type script runtim string class type script runtim object class return undefin els report convers error undefin type break case jstype boolean under lc3 onli js boolean can be coerc into a boolean valu if type boolean type type script runtim boolean class type script runtim object class return valu els if type script runtim string class return valu to string els report convers error valu type break case jstype number if type script runtim string class return script runtim to string valu els if type script runtim object class return coerc to number doubl type valu els if type is primit type boolean type script runtim number class is assign from type return coerc to number type valu els report convers error valu type break case jstype string if type script runtim string class type is instanc valu return valu els if type charact type type script runtim charact class special case for convert a singl char string to a charact place here becaus it appli onli to js string not other js object convert to string if string valu length 1 return new charact string valu char at 0 els return coerc to number type valu els if type is primit type boolean type script runtim number class is assign from type return coerc to number type valu els report convers error valu type break case jstype java class if valu instanceof wrapper valu wrapper valu unwrap if type script runtim class class type script runtim object class return valu els if type script runtim string class return valu to string els report convers error valu type break case jstype java object case jstype java arrai if type is primit if type boolean type report convers error valu type return coerc to number type valu els if valu instanceof wrapper valu wrapper valu unwrap if type script runtim string class return valu to string els if type is instanc valu return valu els report convers error valu type break case jstype object if type script runtim string class return script runtim to string valu els if type is primit if type boolean type report convers error valu type return coerc to number type valu els if type is instanc valu return valu els if type script runtim date class valu instanceof nativ date doubl time nativ date valu getj time valu xxx thi will replac nan by 0 return new date long time els if type is arrai valu instanceof nativ arrai make a new java arrai and coerc the js arrai compon to the target compon type nativ arrai arrai nativ arrai valu long length arrai get length class arrai type type get compon type object result arrai new instanc arrai type int length for int i 0 i length i try arrai set result i coerc type arrai type arrai get i arrai catch evalu except ee report convers error valu type return result els if valu instanceof wrapper valu wrapper valu unwrap if type is instanc valu return valu report convers error valu type els if type is interfac valu instanceof callabl try to us function as implement of java interfac xxx curent onli instanc of scriptabl object ar support sinc the result interfac proxi should be reus next time convers is made and gener callabl ha no storag for it weak refer can address it but for now us thi restrict if valu instanceof scriptabl object scriptabl object so scriptabl object valu object kei kit make hash kei from pair coerc interfac kei type object old so get associ valu kei if old null function wa alreadi wrap return old context cx context get context object glue interfac adapt creat cx type callabl valu store for later retriv glue so associ valu kei glue return glue report convers error valu type els report convers error valu type break return valu privat static object coerc to number class type object valu class valu class valu get class charact if type charact type type script runtim charact class if valu class script runtim charact class return valu return new charact char to integ valu script runtim charact class doubl charact min valu doubl charact max valu doubl float if type script runtim object class type script runtim doubl class type doubl type return valu class script runtim doubl class valu new doubl to doubl valu if type script runtim float class type float type if valu class script runtim float class return valu els doubl number to doubl valu if doubl is infinit number doubl is nan number number 0 0 return new float float number els doubl ab number math ab number if ab number doubl float min valu return new float number 0 0 0 0 0 0 els if ab number doubl float max valu return new float number 0 0 float posit infin float neg infin els return new float float number integ long short byte if type script runtim integ class type integ type if valu class script runtim integ class return valu els return new integ int to integ valu script runtim integ class doubl integ min valu doubl integ max valu if type script runtim long class type long type if valu class script runtim long class return valu els long valu cannot be express exactli in doubl we thu us the largest and smallest doubl valu that ha a valu express as a long valu we build these numer valu from their hexidecim represent to avoid ani problem caus by attempt to pars a decim represent final doubl max doubl long bit to doubl 0x43dfffffffffffffl final doubl min doubl long bit to doubl 0xc3e0000000000000l return new long to integ valu script runtim long class min max if type script runtim short class type short type if valu class script runtim short class return valu els return new short short to integ valu script runtim short class doubl short min valu doubl short max valu if type script runtim byte class type byte type if valu class script runtim byte class return valu els return new byte byte to integ valu script runtim byte class doubl byte min valu doubl byte max valu return new doubl to doubl valu privat static doubl to doubl object valu if valu instanceof number return number valu doubl valu els if valu instanceof string return script runtim to number string valu els if valu instanceof scriptabl if valu instanceof wrapper xxx optim tail recurs return to doubl wrapper valu unwrap els return script runtim to number valu els method meth try meth valu get class get method doubl valu null catch no such method except e meth null catch secur except e meth null if meth null try return number meth invok valu null doubl valu catch illeg access except e xxx ignor or error messag report convers error valu doubl type catch invoc target except e xxx ignor or error messag report convers error valu doubl type return script runtim to number valu to string privat static long to integ object valu class type doubl min doubl max doubl d to doubl valu if doubl is infinit d doubl is nan d convert to string first for more readabl messag report convers error script runtim to string valu type if d 0 0 d math floor d els d math ceil d if d min d max convert to string first for more readabl messag report convers error script runtim to string valu type return long d static void report convers error object valu class type it us string valu of valu not valu to string sinc valu can be null bug 282447 throw context report runtim error2 msg convers not allow string valu of valu java member java signatur type privat void write object object output stream out throw io except out default write object if java object null class jo class java object get class if jo class get name start with adapt out write boolean true if adapt write adapt object null throw new io except object arg java object out try adapt write adapt object invok null arg catch except ex throw new io except els out write boolean fals out write object java object els out write boolean fals out write object java object if static type null out write object static type get class get name els out write object null privat void read object object input stream in throw io except class not found except in default read object if in read boolean if adapt read adapt object null throw new class not found except object arg thi in try java object adapt read adapt object invok null arg catch except ex throw new io except els java object in read object string class name string in read object if class name null static type class for name class name els static type null init member static void init scriptabl scope boolean seal nativ arrai obj new nativ arrai obj export asj class max prototyp id scope seal zero paramet constructor just us to creat arrai prototyp privat nativ arrai dens null thi length 0 public nativ arrai long length int int length int length if int length length int length 0 if int length maximum dens length int length maximum dens length dens new object int length for int i 0 i int length i dens i not found thi length length public nativ arrai object arrai dens arrai thi length arrai length public string get class name return arrai max instanc id 1 protect int get max instanc id return max instanc id protect int find instanc id info string s if s equal length return instanc id info dontenum perman id length return super find instanc id info s protect string get instanc id name int id if id id length return length return super get instanc id name id protect object get instanc id valu int id if id id length return script runtim wrap number length return super get instanc id valu id protect void set instanc id valu int id object valu if id id length set length valu return super set instanc id valu id valu protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 0 s to string break case id to local string ariti 1 s to local string break case id to sourc ariti 0 s to sourc break case id join ariti 1 s join break case id revers ariti 0 s revers break case id sort ariti 1 s sort break case id push ariti 1 s push break case id pop ariti 1 s pop break case id shift ariti 1 s shift break case id unshift ariti 1 s unshift break case id splice ariti 1 s splice break case id concat ariti 1 s concat break case id slice ariti 1 s slice break case id index of ariti 1 s index of break case id last index of ariti 1 s last index of break case id everi ariti 1 s everi break case id filter ariti 1 s filter break case id for each ariti 1 s for each break case id map ariti 1 s map break case id some ariti 1 s some break default throw new illeg argument except string valu of id init prototyp method arrai tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag arrai tag return super exec id call f cx scope thi obj arg int id f method id switch id case id constructor boolean in new expr thi obj null if in new expr id function object construct will set up parent proto return f construct cx scope arg return js constructor cx scope arg case id to string return to string helper cx scope thi obj cx ha featur context featur to string as sourc fals case id to local string return to string helper cx scope thi obj fals true case id to sourc return to string helper cx scope thi obj true fals case id join return js join cx thi obj arg case id revers return js revers cx thi obj arg case id sort return js sort cx scope thi obj arg case id push return js push cx thi obj arg case id pop return js pop cx thi obj arg case id shift return js shift cx thi obj arg case id unshift return js unshift cx thi obj arg case id splice return js splice cx scope thi obj arg case id concat return js concat cx scope thi obj arg case id slice return js slice cx thi obj arg case id index of return index of helper cx thi obj arg fals case id last index of return index of helper cx thi obj arg true case id everi case id filter case id for each case id map case id some return iter method cx id scope thi obj arg throw new illeg argument except string valu of id public object get int index scriptabl start if dens null 0 index index dens length return dens index return super get index start public boolean ha int index scriptabl start if dens null 0 index index dens length return dens index not found return super ha index start otherwis return 1l privat static long to arrai index string id doubl d script runtim to number id if d d long index script runtim to uint32 d if index d index 4294967295l assum that script runtim to string index is the same as java lang long to string index for long if long to string index equal id return index return 1 public void put string id scriptabl start object valu super put id start valu if start thi if the object is seal super will throw except long index to arrai index id if index length length index 1 public void put int index scriptabl start object valu if start thi is seal dens null 0 index index dens length if start thi seal super will throw except dens index valu els super put index start valu if start thi onli set the arrai length if given an arrai index ecma 15 4 0 if thi length index avoid overflow index thi length long index 1 public void delet int index if is seal dens null 0 index index dens length dens index not found els super delet index public object get id object super id super get id if dens null return super id int n dens length long current length length if n current length n int current length if n 0 return super id int super length super id length object id new object n super length make a copi of dens to be immun to remov of arrai elem from other thread when calcul present count system arraycopi dens 0 id 0 n int present count 0 for int i 0 i n i replac exist element by their index if id i not found id present count new integ i present count if present count n dens contain delet elem need to shrink the result object tmp new object present count super length system arraycopi id 0 tmp 0 present count id tmp system arraycopi super id 0 id present count super length return id public object get default valu class hint if hint script runtim number class context cx context get context if cx get languag version context version 1 2 return new long length return super get default valu hint see ecma 15 4 1 2 privat static object js constructor context cx scriptabl scope object arg if arg length 0 return new nativ arrai onli us 1 arg as first element for version 1 2 for ani other version includ 1 3 follow ecma and us it as a length if cx get languag version context version 1 2 return new nativ arrai arg els object arg0 arg 0 if arg length 1 arg0 instanceof number return new nativ arrai arg els long len script runtim to uint32 arg0 if len number arg0 doubl valu throw context report runtim error0 msg arraylength bad return new nativ arrai len public long get length return length deprec us link get length instead public long js get length return get length privat void set length object val xxx do we satisfi thi 15 4 5 1 put p v 1 call the can put method of a with name p 2 if result 1 is fals return doubl d script runtim to number val long long val script runtim to uint32 d if long val d throw context report runtim error0 msg arraylength bad if long val length remov all properti between long val and length if length long val 0x1000 assum that the represent is spars object e get id will onli find in object itself for int i 0 i e length i object id e i if id instanceof string maxint will appear as string string str id string id long index to arrai index str id if index long val delet str id els int index integ id int valu if index long val delet index els assum a dens represent for long i long val i length i delet elem thi i length long val static long get length properti context cx scriptabl obj these will both give numer length within uint32 rang if obj instanceof nativ string return nativ string obj get length els if obj instanceof nativ arrai return nativ arrai obj get length els if obj instanceof scriptabl return 0 return script runtim to uint32 script runtim get object prop obj length cx privat static object set length properti context cx scriptabl target long length return script runtim set object prop target length script runtim wrap number length cx privat static void delet elem scriptabl target long index int i int index if i index target delet i els target delet long to string index privat static object get elem context cx scriptabl target long index if index integ max valu string id long to string index return script runtim get object prop target id cx els return script runtim get object index target int index cx privat static void set elem context cx scriptabl target long index object valu if index integ max valu string id long to string index script runtim set object prop target id valu cx els script runtim set object index target int index valu cx privat static string to string helper context cx scriptabl scope scriptabl thi obj boolean to sourc boolean to local it s probabl redund to handl long length in thi function string buffer ar limit to 2 31 in java long length get length properti cx thi obj string buffer result new string buffer 256 whether to return 4 unquot 5 or 4 quot 5 string separ if to sourc result append separ els separ boolean haslast fals long i 0 boolean toplevel iter if cx iter null toplevel true iter fals cx iter new obj to int map 31 els toplevel fals iter cx iter ha thi obj make sure cx iter is set to null when done so we don t leak memori try if iter cx iter put thi obj 0 stop recurs for i 0 i length i if i 0 result append separ object elem get elem cx thi obj i if elem null elem undefin instanc haslast fals continu haslast true if to sourc result append script runtim unev cx scope elem els if elem instanceof string string s string elem if to sourc result append result append script runtim escap string s result append els result append s els if to local elem undefin instanc elem null callabl fun scriptabl fun thi fun script runtim get prop function and thi elem to local string cx fun thi script runtim last store scriptabl cx elem fun call cx scope fun thi script runtim empti arg result append script runtim to string elem final if toplevel cx iter null if to sourc for length behavior we want to string to be symmetr if haslast i 0 result append els result append return result to string see ecma 15 4 4 3 privat static string js join context cx scriptabl thi obj object arg string separ long llength get length properti cx thi obj int length int llength if llength length throw context report runtim error1 msg arraylength too big string valu of llength if no arg us as separ if arg length 1 arg 0 undefin instanc separ els separ script runtim to string arg 0 if length 0 return string buf new string length int total size 0 for int i 0 i length i object temp get elem cx thi obj i if temp null temp undefin instanc string str script runtim to string temp total size str length buf i str total size length 1 separ length string buffer sb new string buffer total size for int i 0 i length i if i 0 sb append separ string str buf i if str null str null for undefin or null sb append str return sb to string see ecma 15 4 4 4 privat static scriptabl js revers context cx scriptabl thi obj object arg long len get length properti cx thi obj long half len 2 for long i 0 i half i long j len i 1 object temp1 get elem cx thi obj i object temp2 get elem cx thi obj j set elem cx thi obj i temp2 set elem cx thi obj j temp1 return thi obj see ecma 15 4 4 5 privat static scriptabl js sort context cx scriptabl scope scriptabl thi obj object arg long length get length properti cx thi obj if length 1 return thi obj object compar object cmp buf if arg length 0 undefin instanc arg 0 sort with given compar function compar arg 0 cmp buf new object 2 buffer for cmp argument els sort with default compar compar null cmp buf null should we us the extend sort function or the faster on if length integ max valu heapsort extend cx scope thi obj length compar cmp buf els int ilength int length copi the js arrai into a work arrai so it can be sort cheapli object work new object ilength for int i 0 i ilength i work i get elem cx thi obj i heapsort cx scope work ilength compar cmp buf copi the work arrai back into thi obj for int i 0 i ilength i set elem cx thi obj i work i return thi obj return true onli if x y privat static boolean is bigger context cx scriptabl scope object x object y object cmp object cmp buf if cmp null if cmp buf null kit code bug els if cmp buf null cmp buf length 2 kit code bug object undef undefin instanc sort undefin to end if undef y return fals x can not be bigger then undef els if undef x return true y undef here so x y if cmp null if no cmp function suppli sort lexicograph string a script runtim to string x string b script runtim to string y return a compar to b 0 els assembl arg and call suppli js cmp function cmp buf 0 x cmp buf 1 y callabl fun script runtim get valu function and thi cmp cx scriptabl fun thi script runtim last store scriptabl cx object ret fun call cx scope fun thi cmp buf doubl d script runtim to number ret xxx what to do when cmp function return nan ecma state that it s then not a consist compararison function but then what do we do back out and start over with the gener cmp function when we see a nan throw an error for now just ignor it return d 0 heapsort implement see introduct to algorithm by cormen leiserson rivest for detail adjust for zero base index privat static void heapsort context cx scriptabl scope object arrai int length object cmp object cmp buf if length 1 kit code bug build heap for int i length 2 i 0 i object pivot arrai i heapifi cx scope pivot arrai i length cmp cmp buf sort heap for int i length i 1 i object pivot arrai i arrai i arrai 0 heapifi cx scope pivot arrai 0 i cmp cmp buf pivot and child heap of i should be made into heap start at i origin arrai i is never us to have less arrai access dure sort privat static void heapifi context cx scriptabl scope object pivot object arrai int i int end object cmp object cmp buf for int child i 2 1 if child end break object child val arrai child if child 1 end object next val arrai child 1 if is bigger cx scope next val child val cmp cmp buf child child val next val if is bigger cx scope child val pivot cmp cmp buf break arrai i child val i child arrai i pivot version of heapsort that call get elem set elem on target to queri assign arrai element instead of java arrai access privat static void heapsort extend context cx scriptabl scope scriptabl target long length object cmp object cmp buf if length 1 kit code bug build heap for long i length 2 i 0 i object pivot get elem cx target i heapifi extend cx scope pivot target i length cmp cmp buf sort heap for long i length i 1 i object pivot get elem cx target i set elem cx target i get elem cx target 0 heapifi extend cx scope pivot target 0 i cmp cmp buf privat static void heapifi extend context cx scriptabl scope object pivot scriptabl target long i long end object cmp object cmp buf for long child i 2 1 if child end break object child val get elem cx target child if child 1 end object next val get elem cx target child 1 if is bigger cx scope next val child val cmp cmp buf child child val next val if is bigger cx scope child val pivot cmp cmp buf break set elem cx target i child val i child set elem cx target i pivot non ecma method privat static object js push context cx scriptabl thi obj object arg long length get length properti cx thi obj for int i 0 i arg length i set elem cx thi obj length i arg i length arg length object length obj set length properti cx thi obj length if js1 2 follow perl4 by return the last thing push otherwis return the new arrai length if cx get languag version context version 1 2 if js1 2 no argument return undefin return arg length 0 undefin instanc arg arg length 1 els return length obj privat static object js pop context cx scriptabl thi obj object arg object result long length get length properti cx thi obj if length 0 length get the to be delet properti s valu result get elem cx thi obj length we don t need to delet the last properti becaus set length doe that for us els result undefin instanc necessari to match js even when length 0 js pop will give a length properti to ani target it is call on set length properti cx thi obj length return result privat static object js shift context cx scriptabl thi obj object arg object result long length get length properti cx thi obj if length 0 long i 0 length get the to be delet properti s valu result get elem cx thi obj i slide down the arrai abov the first element leav i set to point to the last element if length 0 for i 1 i length i object temp get elem cx thi obj i set elem cx thi obj i 1 temp we don t need to delet the last properti becaus set length doe that for us els result undefin instanc set length properti cx thi obj length return result privat static object js unshift context cx scriptabl thi obj object arg object result long length get length properti cx thi obj int argc arg length if arg length 0 slide up the arrai to make room for arg at the bottom if length 0 for long last length 1 last 0 last object temp get elem cx thi obj last set elem cx thi obj last argc temp copi from argv to the bottom of the arrai for int i 0 i arg length i set elem cx thi obj i arg i follow perl by return the new arrai length length arg length return set length properti cx thi obj length return script runtim wrap number length privat static object js splice context cx scriptabl scope scriptabl thi obj object arg creat an empti arrai to return scope get top level scope scope object result script runtim new object cx scope arrai null int argc arg length if argc 0 return result long length get length properti cx thi obj convert the first argument into a start index long begin to slice index script runtim to integ arg 0 length argc convert the second argument into count long count if arg length 1 count length begin els doubl dcount script runtim to integ arg 1 if dcount 0 count 0 els if dcount length begin count length begin els count long dcount argc long end begin count if there ar element to remov put them into the return valu if count 0 if count 1 cx get languag version context version 1 2 js lack list context wherebi in perl on turn the singl scalar that s splice out into an arrai just by assign it to singl instead of singl or by us it as perl push s first argument for instanc js1 2 emul perl too close and return a non arrai for the singl splice out case requir caller to test and wrap in if necessari so js1 3 default and other version all return an arrai of length 1 for uniform result get elem cx thi obj begin els for long last begin last end last scriptabl result arrai scriptabl result object temp get elem cx thi obj last set elem cx result arrai last begin temp els if count 0 cx get languag version context version 1 2 emul c js1 2 if no element ar remov return undefin result undefin instanc find the direct up or down to copi and make wai for argv long delta argc count if delta 0 for long last length 1 last end last object temp get elem cx thi obj last set elem cx thi obj last delta temp els if delta 0 for long last end last length last object temp get elem cx thi obj last set elem cx thi obj last delta temp copi from argv into the hole to complet the splice int argoffset arg length argc for int i 0 i argc i set elem cx thi obj begin i arg i argoffset updat length in case we delet element from the end set length properti cx thi obj length delta return result privat static scriptabl js concat context cx scriptabl scope scriptabl thi obj object arg creat an empti arrai to return scope get top level scope scope function ctor script runtim get exist ctor cx scope arrai scriptabl result ctor construct cx scope script runtim empti arg long length long slot 0 put the target in the result arrai onli add it as an arrai if it look like on if script runtim instanc of thi obj ctor cx length get length properti cx thi obj copi from the target object into the result for slot 0 slot length slot object temp get elem cx thi obj slot set elem cx result slot temp els set elem cx result slot thi obj copi from the argument into the result if ani argument ha a numer length properti treat it as an arrai and add element separ otherwis just copi the argument for int i 0 i arg length i if script runtim instanc of arg i ctor cx script runtim instanc of instanceof scriptabl scriptabl arg scriptabl arg i length get length properti cx arg for long j 0 j length j slot object temp get elem cx arg j set elem cx result slot temp els set elem cx result slot arg i return result privat scriptabl js slice context cx scriptabl thi obj object arg scriptabl scope get top level scope thi scriptabl result script runtim new object cx scope arrai null long length get length properti cx thi obj long begin end if arg length 0 begin 0 end length els begin to slice index script runtim to integ arg 0 length if arg length 1 end length els end to slice index script runtim to integ arg 1 length for long slot begin slot end slot object temp get elem cx thi obj slot set elem cx result slot begin temp return result privat static long to slice index doubl valu long length long result if valu 0 0 if valu length 0 0 result 0 els result long valu length els if valu length result length els result long valu return result implement the method index of and last index of privat object index of helper context cx scriptabl thi obj object arg boolean is last object compar to arg length 0 arg 0 undefin instanc long length get length properti cx thi obj long start arg length 1 script runtim to int32 script runtim to number arg 1 is last length 0 if start 0 start length if start 0 start 0 if is last for long i start i 0 i if script runtim shallow eq get elem cx thi obj i compar to return new long i els for long i start i length i if script runtim shallow eq get elem cx thi obj i compar to return new long i return neg on implement the method everi filter for each map and some privat object iter method context cx int id scriptabl scope scriptabl thi obj object arg object callback arg arg length 0 arg 0 undefin instanc if callback arg null callback arg instanceof function throw script runtim not function error script runtim to string callback arg function f function callback arg scriptabl parent scriptabl object get top level scope f scriptabl thi arg arg length 1 arg 1 instanceof scriptabl scriptabl arg 1 parent long length get length properti cx thi obj scriptabl arrai null if id id filter arrai script runtim new object cx scope arrai null els if id id map alloc dens arrai for effici object ctor arg new long length arrai script runtim new object cx scope arrai ctor arg object inner arg new object 3 long j 0 for long i 0 i length i inner arg 0 get elem cx thi obj i inner arg 1 new long i inner arg 2 thi obj object result f call cx parent thi arg inner arg switch id case id everi if script runtim to boolean result return boolean fals break case id filter if script runtim to boolean result set elem cx arrai j inner arg 0 break case id for each break case id map set elem cx arrai j result break case id some if script runtim to boolean result return boolean true break switch id case id everi return boolean true case id filter case id map return arrai case id some return boolean fals case id for each default return undefin instanc protect int find prototyp id string s int id gener last updat 2005 09 26 15 47 42 edt l0 id 0 string x null int c l switch s length case 3 c s char at 0 if c m if s char at 2 p s char at 1 a id id map break l0 els if c p if s char at 2 p s char at 1 o id id pop break l0 break l case 4 switch s char at 2 case i x join id id join break l case m x some id id some break l case r x sort id id sort break l case s x push id id push break l break l case 5 c s char at 1 if c h x shift id id shift els if c l x slice id id slice els if c v x everi id id everi break l case 6 c s char at 0 if c c x concat id id concat els if c f x filter id id filter els if c s x splice id id splice break l case 7 switch s char at 0 case f x for each id id for each break l case i x index of id id index of break l case r x revers id id revers break l case u x unshift id id unshift break l break l case 8 c s char at 3 if c o x to sourc id id to sourc els if c t x to string id id to string break l case 11 c s char at 0 if c c x constructor id id constructor els if c l x last index of id id last index of break l case 14 x to local string id id to local string break l if x null x s x equal s id 0 gener return id creat a new synchron function from an exist on param obj the exist function public synchron scriptabl obj super obj see org mozilla javascript function call public object call context cx scriptabl scope scriptabl thi obj object arg synchron thi obj return function obj call cx scope thi obj arg static void init scriptabl scope boolean seal nativ date obj new nativ date set the valu of the prototyp date to nan invalid date obj date script runtim nan obj export asj class max prototyp id scope seal privat nativ date if thi time zone null j u time zone is synchron so set class static from it should be ok thi time zone java util time zone get default localtza thi time zone get raw offset public string get class name return date public object get default valu class type hint if type hint null type hint script runtim string class return super get default valu type hint doubl getj time valu return date protect void fill constructor properti id function object ctor add id function properti ctor date tag constructor id now now 0 add id function properti ctor date tag constructor id pars pars 1 add id function properti ctor date tag constructor id utc utc 1 super fill constructor properti ctor protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 0 s to string break case id to time string ariti 0 s to time string break case id to date string ariti 0 s to date string break case id to local string ariti 0 s to local string break case id to local time string ariti 0 s to local time string break case id to local date string ariti 0 s to local date string break case id toutc string ariti 0 s toutc string break case id to sourc ariti 0 s to sourc break case id valu of ariti 0 s valu of break case id get time ariti 0 s get time break case id get year ariti 0 s get year break case id get full year ariti 0 s get full year break case id getutc full year ariti 0 s getutc full year break case id get month ariti 0 s get month break case id getutc month ariti 0 s getutc month break case id get date ariti 0 s get date break case id getutc date ariti 0 s getutc date break case id get dai ariti 0 s get dai break case id getutc dai ariti 0 s getutc dai break case id get hour ariti 0 s get hour break case id getutc hour ariti 0 s getutc hour break case id get minut ariti 0 s get minut break case id getutc minut ariti 0 s getutc minut break case id get second ariti 0 s get second break case id getutc second ariti 0 s getutc second break case id get millisecond ariti 0 s get millisecond break case id getutc millisecond ariti 0 s getutc millisecond break case id get timezon offset ariti 0 s get timezon offset break case id set time ariti 1 s set time break case id set millisecond ariti 1 s set millisecond break case id setutc millisecond ariti 1 s setutc millisecond break case id set second ariti 2 s set second break case id setutc second ariti 2 s setutc second break case id set minut ariti 3 s set minut break case id setutc minut ariti 3 s setutc minut break case id set hour ariti 4 s set hour break case id setutc hour ariti 4 s setutc hour break case id set date ariti 1 s set date break case id setutc date ariti 1 s setutc date break case id set month ariti 2 s set month break case id setutc month ariti 2 s setutc month break case id set full year ariti 3 s set full year break case id setutc full year ariti 3 s setutc full year break case id set year ariti 1 s set year break default throw new illeg argument except string valu of id init prototyp method date tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag date tag return super exec id call f cx scope thi obj arg int id f method id switch id case constructor id now return script runtim wrap number now case constructor id pars string data str script runtim to string arg 0 return script runtim wrap number date pars string data str case constructor id utc return script runtim wrap number js static function utc arg case id constructor if call as a function just return a string repres the current time if thi obj null return date format now id to string return js constructor arg the rest of date prototyp method requir thi obj to be date if thi obj instanceof nativ date throw incompat call error f nativ date real thi nativ date thi obj doubl t real thi date switch id case id to string case id to time string case id to date string if t t return date format t id return js nan date str case id to local string case id to local time string case id to local date string if t t return to local helper t id return js nan date str case id toutc string if t t return js toutc string t return js nan date str case id to sourc return new date script runtim to string t case id valu of case id get time return script runtim wrap number t case id get year case id get full year case id getutc full year if t t if id id getutc full year t local time t t year from time t if id id get year if cx ha featur context featur non ecma get year if 1900 t t 2000 t 1900 els t 1900 return script runtim wrap number t case id get month case id getutc month if t t if id id get month t local time t t month from time t return script runtim wrap number t case id get date case id getutc date if t t if id id get date t local time t t date from time t return script runtim wrap number t case id get dai case id getutc dai if t t if id id get dai t local time t t week dai t return script runtim wrap number t case id get hour case id getutc hour if t t if id id get hour t local time t t hour from time t return script runtim wrap number t case id get minut case id getutc minut if t t if id id get minut t local time t t min from time t return script runtim wrap number t case id get second case id getutc second if t t if id id get second t local time t t sec from time t return script runtim wrap number t case id get millisecond case id getutc millisecond if t t if id id get millisecond t local time t t ms from time t return script runtim wrap number t case id get timezon offset if t t t t local time t ms per minut return script runtim wrap number t case id set time t time clip script runtim to number arg 0 real thi date t return script runtim wrap number t case id set millisecond case id setutc millisecond case id set second case id setutc second case id set minut case id setutc minut case id set hour case id setutc hour t make time t arg id real thi date t return script runtim wrap number t case id set date case id setutc date case id set month case id setutc month case id set full year case id setutc full year t make date t arg id real thi date t return script runtim wrap number t case id set year doubl year script runtim to number arg 0 if year year doubl is infinit year t script runtim nan els if t t t 0 els t local time t if year 0 year 99 year 1900 doubl dai make dai year month from time t date from time t t make date dai time within dai t t internalutc t t time clip t real thi date t return script runtim wrap number t default throw new illeg argument except string valu of id privat static final doubl ms per minut second per minut ms per second privat static doubl dai doubl t return math floor t ms per dai privat static doubl time within dai doubl t doubl result result t ms per dai if result 0 result ms per dai return result privat static boolean is leap year int year return year 4 0 year 100 0 year 400 0 privat static doubl dai from year doubl y return 365 y 1970 math floor y 1969 4 0 math floor y 1901 100 0 math floor y 1601 400 0 privat static doubl time from year doubl y return dai from year y ms per dai privat static int year from time doubl t int lo int math floor t ms per dai 366 1970 int hi int math floor t ms per dai 365 1970 int mid abov doesn t work for neg date if hi lo int temp lo lo hi hi temp us a simpl binari search algorithm to find the right year thi seem like brute forc but the comput of hi and lo year abov land within on year of the correct answer for year within a thousand year of 1970 the loop below onli requir six iter for year 270000 while hi lo mid hi lo 2 if time from year mid t hi mid 1 els lo mid 1 if time from year lo t return mid return lo privat static boolean in leap year doubl t return is leap year year from time t privat static doubl dai from month int m int year int dai m 30 if m 7 dai m 2 1 els if m 2 dai m 1 2 1 els dai m if m 2 is leap year year dai return dai privat static int month from time doubl t int year year from time t int d int dai t dai from year year d 31 28 if d 0 return d 28 0 1 if is leap year year if d 0 return 1 29 februari d d date count from 1 march int estim d 30 approx number of month sinc march int mstart switch estim case 0 return 2 case 1 mstart 31 break case 2 mstart 31 30 break case 3 mstart 31 30 31 break case 4 mstart 31 30 31 30 break case 5 mstart 31 30 31 30 31 break case 6 mstart 31 30 31 30 31 31 break case 7 mstart 31 30 31 30 31 31 30 break case 8 mstart 31 30 31 30 31 31 30 31 break case 9 mstart 31 30 31 30 31 31 30 31 30 break case 10 return 11 late decemb default throw kit code bug if d mstart then real month sinc march estim 1 return d mstart estim 2 estim 1 privat static int date from time doubl t int year year from time t int d int dai t dai from year year d 31 28 if d 0 return d 28 d 31 28 1 d 28 1 if is leap year year if d 0 return 29 29 februari d d date count from 1 march int mdai mstart switch d 30 approx number of month sinc march case 0 return d 1 case 1 mdai 31 mstart 31 break case 2 mdai 30 mstart 31 30 break case 3 mdai 31 mstart 31 30 31 break case 4 mdai 30 mstart 31 30 31 30 break case 5 mdai 31 mstart 31 30 31 30 31 break case 6 mdai 31 mstart 31 30 31 30 31 31 break case 7 mdai 30 mstart 31 30 31 30 31 31 30 break case 8 mdai 31 mstart 31 30 31 30 31 31 30 31 break case 9 mdai 30 mstart 31 30 31 30 31 31 30 31 30 break case 10 return d 31 30 31 30 31 31 30 31 30 1 late decemb default throw kit code bug d mstart if d 0 wrong estim sfhift to previou month d mdai return d 1 privat static int week dai doubl t doubl result result dai t 4 result result 7 if result 0 result 7 return int result privat static doubl now return doubl system current time milli privat final static boolean tzo workaround fals privat static doubl daylight savingta doubl t anoth workaround the jre doesn t seem to know about dst befor year 1 ad so we map to equival date for the purpos of find dst to be safe we do thi for year outsid 1970 2038 if t 0 0 t 2145916800000 0 int year equival year year from time t doubl dai make dai year month from time t date from time t t make date dai time within dai t if tzo workaround date date new date long t if thi time zone in daylight time date return ms per hour els return 0 els us get offset if in daylight time is broken becaus it seem to work accept we don t switch over to it entir becaus it requir expens explod date argument and the api make it imposs to handl dst changeov cleanli hardcod the assumpt that the changeov alwai happen at 2 00 am t localtza hour from time t 2 ms per hour 0 int year year from time t doubl offset thi time zone get offset year 0 1 0 year month from time t date from time t week dai t int time within dai t if offset localtza 0 return ms per hour els return 0 return offset localtza privat static int equival year int year int dai int dai from year year 4 dai dai 7 if dai 0 dai 7 year and leap year on which jan 1 is a sundai mondai etc if is leap year year switch dai case 0 return 1984 case 1 return 1996 case 2 return 1980 case 3 return 1992 case 4 return 1976 case 5 return 1988 case 6 return 1972 els switch dai case 0 return 1978 case 1 return 1973 case 2 return 1974 case 3 return 1975 case 4 return 1981 case 5 return 1971 case 6 return 1977 unreach throw kit code bug privat static doubl local time doubl t return t localtza daylight savingta t privat static doubl internalutc doubl t return t localtza daylight savingta t localtza privat static int hour from time doubl t doubl result result math floor t ms per hour hour per dai if result 0 result hour per dai return int result privat static int min from time doubl t doubl result result math floor t ms per minut minut per hour if result 0 result minut per hour return int result privat static int sec from time doubl t doubl result result math floor t ms per second second per minut if result 0 result second per minut return int result privat static int ms from time doubl t doubl result result t ms per second if result 0 result ms per second return int result privat static doubl make time doubl hour doubl min doubl sec doubl ms return hour minut per hour min second per minut sec ms per second ms privat static doubl make dai doubl year doubl month doubl date year math floor month 12 month month 12 if month 0 month 12 doubl yeardai math floor time from year year ms per dai doubl monthdai dai from month int month int year return yeardai monthdai date 1 privat static doubl make date doubl dai doubl time return dai ms per dai time privat static doubl time clip doubl d if d d d doubl posit infin d doubl neg infin math ab d half time domain return script runtim nan if d 0 0 return math floor d 0 els return math ceil d 0 find utc time from given date no 1900 correct privat static doubl date msec from date doubl year doubl mon doubl mdai doubl hour doubl min doubl sec doubl msec doubl dai doubl time doubl result dai make dai year mon mdai time make time hour min sec msec result make date dai time return result privat static final int maxarg 7 privat static doubl js static function utc object arg doubl arrai new doubl maxarg int loop doubl d for loop 0 loop maxarg loop if loop arg length d script runtim to number arg loop if d d doubl is infinit d return script runtim nan arrai loop script runtim to integ arg loop els arrai loop 0 adjust 2 digit year into the 20th centuri if arrai 0 0 arrai 0 99 arrai 0 1900 if we got a 0 for date which is out of rang pretend it s a 1 so date utc 1972 5 work if arrai 2 1 arrai 2 1 d date msec from date arrai 0 arrai 1 arrai 2 arrai 3 arrai 4 arrai 5 arrai 6 d time clip d return d privat static doubl date pars string string s int year 1 int mon 1 int mdai 1 int hour 1 int min 1 int sec 1 char c 0 char si 0 int i 0 int n 1 doubl tzoffset 1 char prevc 0 int limit 0 boolean seenplusminu fals limit s length while i limit c s char at i i if c c c if i limit si s char at i if c 0 si si 9 prevc c continu if c comment int depth 1 while i limit c s char at i i if c depth els if c if depth 0 break continu if 0 c c 9 n c 0 while i limit 0 c s char at i c 9 n n 10 c 0 i allow tza befor the year so wed nov 05 21 49 11 gmt 0800 1997 work us of seenplusminu allow in tza so java no timezon style of gmt 4 30 work if prevc prevc year 0 make case below chang tzoffset seenplusminu true offset if n 24 n n 60 eg gmt 3 els n n 100 n 100 60 eg gmt 0430 if prevc plu mean east of gmt n n if tzoffset 0 tzoffset 1 return script runtim nan tzoffset n els if n 70 prevc mon 0 mdai 0 year 0 if year 0 return script runtim nan els if c c c i limit year n 100 n 1900 n els return script runtim nan els if c if hour 0 hour byte n els if min 0 min byte n els return script runtim nan els if c if mon 0 mon byte n 1 els if mdai 0 mdai byte n els return script runtim nan els if i limit c c c return script runtim nan els if seenplusminu n 60 handl gmt 3 30 if tzoffset 0 tzoffset n els tzoffset n els if hour 0 min 0 min byte n els if min 0 sec 0 sec byte n els if mdai 0 mdai byte n els return script runtim nan prevc 0 els if c c c c prevc c els int st i 1 while i limit c s char at i if a c c z a c c z break i int letter count i st if letter count 2 return script runtim nan us port code from jsdate c rather than the local specif date pars code from java to keep js and rhino consist is thi the right strategi string wtb am pm mondai tuesdai wednesdai thursdai fridai saturdai sundai januari februari march april mai june juli august septemb octob novemb decemb gmt ut utc est edt cst cdt mst mdt pst pdt int index 0 for int wtb offset 0 int wtb next wtb index of wtb offset if wtb next 0 return script runtim nan if wtb region match true wtb offset s st letter count break wtb offset wtb next 1 index if index 2 am pm count 12 30 am as 00 30 12 30 pm as 12 30 instead of blindli ad 12 if pm if hour 12 hour 0 return script runtim nan els if index 0 am if hour 12 hour 0 els pm if hour 12 hour 12 els if index 2 7 ignor week dai els if index 7 12 month if mon 0 mon index els return script runtim nan els index 12 timezon switch index case 0 gmt tzoffset 0 break case 1 ut tzoffset 0 break case 2 utc tzoffset 0 break case 3 est tzoffset 5 60 break case 4 edt tzoffset 4 60 break case 5 cst tzoffset 6 60 break case 6 cdt tzoffset 5 60 break case 7 mst tzoffset 7 60 break case 8 mdt tzoffset 6 60 break case 9 pst tzoffset 8 60 break case 10 pdt tzoffset 7 60 break default kit code bug if year 0 mon 0 mdai 0 return script runtim nan if sec 0 sec 0 if min 0 min 0 if hour 0 hour 0 doubl msec date msec from date year mon mdai hour min sec 0 if tzoffset 1 no time zone specifi have to us local return internalutc msec els return msec tzoffset ms per minut privat static string date format doubl t int method id string buffer result new string buffer 60 doubl local local time t tue oct 31 09 41 40 gmt 0800 pst 2000 tue oct 31 2000 09 41 40 gmt 0800 pst if method id id to time string append week dai name result week dai local result append append month name result month from time local result append append0 pad uint result date from time local 2 result append int year year from time local if year 0 result append year year append0 pad uint result year 4 if method id id to date string result append if method id id to date string append0 pad uint result hour from time local 2 result append append0 pad uint result min from time local 2 result append append0 pad uint result sec from time local 2 offset from gmt in minut the offset includ daylight save if it appli int minut int math floor localtza daylight savingta t ms per minut map 510 minut to 0830 hour int offset minut 60 100 minut 60 if offset 0 result append gmt els result append gmt offset offset append0 pad uint result offset 4 if time zone formatt null time zone formatt new java text simpl date format zzz find an equival year befor get the timezon comment see daylight savingta if t 0 0 t 2145916800000 0 int equiv equival year year from time local doubl dai make dai equiv month from time t date from time t t make date dai time within dai t result append java util date date new date long t result append time zone formatt format date result append return result to string the javascript constructor privat static object js constructor object arg nativ date obj new nativ date if call as a constructor with no arg return a new date with the current time if arg length 0 obj date now return obj if call with just on arg if arg length 1 object arg0 arg 0 if arg0 instanceof scriptabl arg0 scriptabl arg0 get default valu null doubl date if arg0 instanceof string it s a string pars it date date pars string string arg0 els if it s not a string us it as a millisecond date date script runtim to number arg0 obj date time clip date return obj multipl argument year month dai etc doubl arrai new doubl maxarg int loop doubl d for loop 0 loop maxarg loop if loop arg length d script runtim to number arg loop if d d doubl is infinit d obj date script runtim nan return obj arrai loop script runtim to integ arg loop els arrai loop 0 adjust 2 digit year into the 20th centuri if arrai 0 0 arrai 0 99 arrai 0 1900 if we got a 0 for date which is out of rang pretend it s a 1 if arrai 2 1 arrai 2 1 doubl dai make dai arrai 0 arrai 1 arrai 2 doubl time make time arrai 3 arrai 4 arrai 5 arrai 6 time make date dai time time internalutc time obj date time clip time return obj privat static string to local helper doubl t int method id java text date format formatt switch method id case id to local string if local date time formatt null local date time formatt date format get date time instanc date format long date format long formatt local date time formatt break case id to local time string if local time formatt null local time formatt date format get time instanc date format long formatt local time formatt break case id to local date string if local date formatt null local date formatt date format get date instanc date format long formatt local date formatt break default formatt null unreach return formatt format new date long t privat static string js toutc string doubl date string buffer result new string buffer 60 append week dai name result week dai date result append append0 pad uint result date from time date 2 result append append month name result month from time date result append int year year from time date if year 0 result append year year append0 pad uint result year 4 result append append0 pad uint result hour from time date 2 result append append0 pad uint result min from time date 2 result append append0 pad uint result sec from time date 2 result append gmt return result to string privat static void append0 pad uint string buffer sb int i int min width if i 0 kit code bug int scale 1 min width if i 10 if i 1000 1000 1000 for int new scale scale 10 if i new scale break min width scale new scale els separ case not to check against 10 10 9 overflow min width 9 scale 1000 1000 1000 while min width 0 sb append 0 min width while scale 1 sb append char 0 i scale i scale scale 10 sb append char 0 i privat static void append month name string buffer sb int index take advantag of the fact that all month abbrevi have the same length to minim amount of string runtim ha to keep in memori string month jan feb mar apr mai jun jul aug sep oct nov dec index 3 for int i 0 i 3 i sb append month char at index i privat static void append week dai name string buffer sb int index string dai sun mon tue wed thu fri sat index 3 for int i 0 i 3 i sb append dai char at index i privat static doubl make time doubl date object arg int method id int maxarg boolean local true switch method id case id setutc millisecond local fals fallthrough case id set millisecond maxarg 1 break case id setutc second local fals fallthrough case id set second maxarg 2 break case id setutc minut local fals fallthrough case id set minut maxarg 3 break case id setutc hour local fals fallthrough case id set hour maxarg 4 break default kit code bug maxarg 0 int i doubl conv new doubl 4 doubl hour min sec msec doubl lorutim local or utc version of date doubl time doubl result just return nan if the date is alreadi nan if date date return date satisfi the ecma rule that if a function is call with fewer argument than the specifi formal argument the remain argument ar set to undefin seem like all the date set whatev function in ecma ar onli vararg beyond the first argument thi should be set to undefin if it s not given thi mean that d new date d set millisecond return nan blech if arg length 0 arg script runtim pad argument arg 1 for i 0 i arg length i maxarg i conv i script runtim to number arg i limit check that happen in make time in ecma if conv i conv i doubl is infinit conv i return script runtim nan conv i script runtim to integ conv i if local lorutim local time date els lorutim date i 0 int stop arg length if maxarg 4 i stop hour conv i els hour hour from time lorutim if maxarg 3 i stop min conv i els min min from time lorutim if maxarg 2 i stop sec conv i els sec sec from time lorutim if maxarg 1 i stop msec conv i els msec ms from time lorutim time make time hour min sec msec result make date dai lorutim time if local result internalutc result date time clip result return date privat static doubl make date doubl date object arg int method id int maxarg boolean local true switch method id case id setutc date local fals fallthrough case id set date maxarg 1 break case id setutc month local fals fallthrough case id set month maxarg 2 break case id setutc full year local fals fallthrough case id set full year maxarg 3 break default kit code bug maxarg 0 int i doubl conv new doubl 3 doubl year month dai doubl lorutim local or utc version of date doubl result see arg pad comment in make time if arg length 0 arg script runtim pad argument arg 1 for i 0 i arg length i maxarg i conv i script runtim to number arg i limit check that happen in make date in ecma if conv i conv i doubl is infinit conv i return script runtim nan conv i script runtim to integ conv i return nan if date is nan and we re not set the year if we ar us 0 as the time if date date if arg length 3 return script runtim nan els lorutim 0 els if local lorutim local time date els lorutim date i 0 int stop arg length if maxarg 3 i stop year conv i els year year from time lorutim if maxarg 2 i stop month conv i els month month from time lorutim if maxarg 1 i stop dai conv i els dai date from time lorutim dai make dai year month dai dai within year result make date dai time within dai lorutim if local result internalutc result date time clip result return date protect int find prototyp id string s int id gener last updat 2004 03 17 13 33 23 cet l0 id 0 string x null int c l switch s length case 6 x get dai id id get dai break l case 7 switch s char at 3 case d c s char at 0 if c g x get date id id get date els if c s x set date id id set date break l case t c s char at 0 if c g x get time id id get time els if c s x set time id id set time break l case y c s char at 0 if c g x get year id id get year els if c s x set year id id set year break l case u x valu of id id valu of break l break l case 8 switch s char at 3 case h c s char at 0 if c g x get hour id id get hour els if c s x set hour id id set hour break l case m c s char at 0 if c g x get month id id get month els if c s x set month id id set month break l case o x to sourc id id to sourc break l case t x to string id id to string break l break l case 9 x getutc dai id id getutc dai break l case 10 c s char at 3 if c m c s char at 0 if c g x get minut id id get minut els if c s x set minut id id set minut els if c s c s char at 0 if c g x get second id id get second els if c s x set second id id set second els if c u c s char at 0 if c g x getutc date id id getutc date els if c s x setutc date id id setutc date break l case 11 switch s char at 3 case f c s char at 0 if c g x get full year id id get full year els if c s x set full year id id set full year break l case m x togmt string id id togmt string break l case t x toutc string id id toutc string break l case u c s char at 0 if c g c s char at 9 if c r x getutc hour id id getutc hour els if c t x getutc month id id getutc month els if c s c s char at 9 if c r x setutc hour id id setutc hour els if c t x setutc month id id setutc month break l case s x constructor id id constructor break l break l case 12 c s char at 2 if c d x to date string id id to date string els if c t x to time string id id to time string break l case 13 c s char at 0 if c g c s char at 6 if c m x getutc minut id id getutc minut els if c s x getutc second id id getutc second els if c s c s char at 6 if c m x setutc minut id id setutc minut els if c s x setutc second id id setutc second break l case 14 c s char at 0 if c g x getutc full year id id getutc full year els if c s x setutc full year id id setutc full year els if c t x to local string id id to local string break l case 15 c s char at 0 if c g x get millisecond id id get millisecond els if c s x set millisecond id id set millisecond break l case 17 x get timezon offset id id get timezon offset break l case 18 c s char at 0 if c g x getutc millisecond id id getutc millisecond els if c s x setutc millisecond id id setutc millisecond els if c t c s char at 8 if c d x to local date string id id to local date string els if c t x to local time string id id to local time string break l if x null x s x equal s id 0 gener return id static void init scriptabl scope boolean seal nativ string obj new nativ string obj export asj class max prototyp id scope seal privat nativ string string s string s public string get class name return string max instanc id 1 protect int get max instanc id return max instanc id protect int find instanc id info string s if s equal length return instanc id info dontenum readonli perman id length return super find instanc id info s protect string get instanc id name int id if id id length return length return super get instanc id name id protect object get instanc id valu int id if id id length return script runtim wrap int string length return super get instanc id valu id protect void fill constructor properti id function object ctor add id function properti ctor string tag constructor id from char code from char code 1 super fill constructor properti ctor protect void init prototyp id int id string s int ariti switch id case id constructor ariti 1 s constructor break case id to string ariti 0 s to string break case id to sourc ariti 0 s to sourc break case id valu of ariti 0 s valu of break case id char at ariti 1 s char at break case id char code at ariti 1 s char code at break case id index of ariti 1 s index of break case id last index of ariti 1 s last index of break case id split ariti 2 s split break case id substr ariti 2 s substr break case id to lower case ariti 0 s to lower case break case id to upper case ariti 0 s to upper case break case id substr ariti 2 s substr break case id concat ariti 1 s concat break case id slice ariti 2 s slice break case id bold ariti 0 s bold break case id ital ariti 0 s ital break case id fix ariti 0 s fix break case id strike ariti 0 s strike break case id small ariti 0 s small break case id big ariti 0 s big break case id blink ariti 0 s blink break case id sup ariti 0 s sup break case id sub ariti 0 s sub break case id fontsiz ariti 0 s fontsiz break case id fontcolor ariti 0 s fontcolor break case id link ariti 0 s link break case id anchor ariti 0 s anchor break case id equal ariti 1 s equal break case id equal ignor case ariti 1 s equal ignor case break case id match ariti 1 s match break case id search ariti 1 s search break case id replac ariti 1 s replac break default throw new illeg argument except string valu of id init prototyp method string tag id s ariti public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag string tag return super exec id call f cx scope thi obj arg int id f method id switch id case constructor id from char code int n arg length if n 1 return string buffer sb new string buffer n for int i 0 i n i sb append script runtim to uint16 arg i return sb to string case id constructor string s arg length 1 script runtim to string arg 0 if thi obj null new string val creat a new string object return new nativ string s string val convert val to a string valu return s case id to string case id valu of ecma 15 5 4 2 the to string function is not gener return real thi thi obj f string case id to sourc string s real thi thi obj f string return new string script runtim escap string s case id char at case id char code at see ecma 15 5 4 4 5 string target script runtim to string thi obj doubl po script runtim to integ arg 0 if po 0 po target length if id id char at return els return script runtim na nobj char c target char at int po if id id char at return string valu of c els return script runtim wrap int c case id index of return script runtim wrap int js index of script runtim to string thi obj arg case id last index of return script runtim wrap int js last index of script runtim to string thi obj arg case id split return js split cx scope script runtim to string thi obj arg case id substr return js substr cx script runtim to string thi obj arg case id to lower case see ecma 15 5 4 11 return script runtim to string thi obj to lower case case id to upper case see ecma 15 5 4 12 return script runtim to string thi obj to upper case case id substr return js substr script runtim to string thi obj arg case id concat return js concat script runtim to string thi obj arg case id slice return js slice script runtim to string thi obj arg case id bold return tagifi thi obj b null null case id ital return tagifi thi obj i null null case id fix return tagifi thi obj tt null null case id strike return tagifi thi obj strike null null case id small return tagifi thi obj small null null case id big return tagifi thi obj big null null case id blink return tagifi thi obj blink null null case id sup return tagifi thi obj sup null null case id sub return tagifi thi obj sub null null case id fontsiz return tagifi thi obj font size arg case id fontcolor return tagifi thi obj font color arg case id link return tagifi thi obj a href arg case id anchor return tagifi thi obj a name arg case id equal case id equal ignor case string s1 script runtim to string thi obj string s2 script runtim to string arg 0 return script runtim wrap boolean id id equal s1 equal s2 s1 equal ignor case s2 case id match case id search case id replac int action type if id id match action type reg exp proxi ra match els if id id search action type reg exp proxi ra search els action type reg exp proxi ra replac return script runtim check reg exp proxi cx action cx scope thi obj arg action type throw new illeg argument except string valu of id privat static nativ string real thi scriptabl thi obj id function object f if thi obj instanceof nativ string throw incompat call error f return nativ string thi obj privat static string tagifi object thi obj string tag string attribut object arg string str script runtim to string thi obj string buffer result new string buffer result append result append tag if attribut null result append result append attribut result append result append script runtim to string arg 0 result append result append result append str result append result append tag result append return result to string public string to string return string public object get int index scriptabl start if 0 index index string length return string substr index index 1 return super get index start public void put int index scriptabl start object valu if 0 index index string length return super put index start valu privat static int js index of string target object arg string search script runtim to string arg 0 doubl begin script runtim to integ arg 1 if begin target length return 1 els if begin 0 begin 0 return target index of search int begin privat static int js last index of string target object arg string search script runtim to string arg 0 doubl end script runtim to number arg 1 if end end end target length end target length els if end 0 end 0 return target last index of search int end privat static int find split context cx scriptabl scope string target string separ int version reg exp proxi re proxi scriptabl re int ip int matchlen boolean match string parensp int i ip 0 int length target length perl4 special case for str split onli if the user ha select java script1 2 explicitli split on whitespac and skip lead w s strang but true appar model after awk if version context version 1 2 re null separ length 1 separ char at 0 skip lead whitespac if at front of str if i 0 while i length charact is whitespac target char at i i ip 0 i don t delimit whitespac at end of string if i length return 1 skip over the non whitespac char while i length charact is whitespac target char at i i now skip the next run of whitespac int j i while j length charact is whitespac target char at j j updat matchlen to count delimit char matchlen 0 j i return i stop if past end of string if at end of string we will return target length so that ab split new arrai ab and the result arrai convert back to the string ab for symmetri nb thi differ from perl which drop the trail empti substr if the limit argument is omit if i length return 1 match a regular express against the separ at or abov index i return 1 at end of string instead of try for a match so we don t get stuck in a loop if re null return re proxi find split cx scope target separ re ip matchlen match parensp deviat from ecma by never split an empti string by ani separ string into a non empti arrai an arrai of length 1 that contain the empti string if version context version default version context version 1 3 length 0 return 1 special case if sep is the empti string split str into on charact substr let our caller worri about whether to split onc at end of string into an empti substr for 1 2 compat at the end of the string we return the length as the result and set the separ length to 1 thi allow the caller to includ an addit null string at the end of the substr list if separ length 0 if version context version 1 2 if i length matchlen 0 1 return i return i 1 return i length 1 i 1 punt to j l s index of return target length if separ is not found if ip 0 length return length i target index of separ ip 0 return i 1 i length privat static object js split context cx scriptabl scope string target object arg creat an empti arrai to return scriptabl top get top level scope scope scriptabl result script runtim new object cx top arrai null return an arrai consist of the target if no separ given don t check against undefin becaus we want fooundefinedbar split void 0 to split to foo bar if arg length 1 result put 0 result target return result us the second argument as the split limit if given boolean limit arg length 1 arg 1 undefin instanc long limit 0 initi to avoid warn if limit clamp limit between 0 and 1 string length limit script runtim to uint32 arg 1 if limit target length limit 1 target length string separ null int matchlen new int 1 scriptabl re null reg exp proxi re proxi null if arg 0 instanceof scriptabl re proxi script runtim get reg exp proxi cx if re proxi null scriptabl test scriptabl arg 0 if re proxi is reg exp test re test if re null separ script runtim to string arg 0 matchlen 0 separ length split target with separ or re int ip 0 int match int len 0 boolean match fals string paren null int version cx get languag version while match find split cx scope target separ version re proxi re ip matchlen match paren 0 if limit len limit match target length break string substr if target length 0 substr target els substr target substr ip 0 match result put len result substr len imit perl s featur of includ parenthes substr that match part of the delimit in the new arrai after the split substr that wa delimit if re null match 0 true int size paren 0 length for int num 0 num size num if limit len limit break result put len result paren 0 num len match 0 fals ip 0 match matchlen 0 if version context version 1 3 version context version default deviat from ecma to imit perl which omit a final split unless a limit argument is given and big enough if limit ip 0 target length break return result privat static string js substr context cx string target object arg int length target length doubl start script runtim to integ arg 0 doubl end if start 0 start 0 els if start length start length if arg length 1 arg 1 undefin instanc end length els end script runtim to integ arg 1 if end 0 end 0 els if end length end length swap if end start if end start if cx get languag version context version 1 2 doubl temp start start end end temp els emul old jdk1 0 java lang string substr end start return target substr int start int end int get length return string length privat static string js substr string target object arg if arg length 1 return target doubl begin script runtim to integ arg 0 doubl end int length target length if begin 0 begin length if begin 0 begin 0 els if begin length begin length if arg length 1 end length els end script runtim to integ arg 1 if end 0 end 0 end begin if end length end length return target substr int begin int end privat static string js concat string target object arg int n arg length if n 0 return target els if n 1 string arg script runtim to string arg 0 return target concat arg find total capac for the final string to avoid unnecessari re alloc in string buffer int size target length string arg as string new string n for int i 0 i n i string s script runtim to string arg i arg as string i s size s length string buffer result new string buffer size result append target for int i 0 i n i result append arg as string i return result to string privat static string js slice string target object arg if arg length 0 doubl begin script runtim to integ arg 0 doubl end int length target length if begin 0 begin length if begin 0 begin 0 els if begin length begin length if arg length 1 end length els end script runtim to integ arg 1 if end 0 end length if end 0 end 0 els if end length end length if end begin end begin return target substr int begin int end return target protect int find prototyp id string s int id gener last updat 2004 03 17 13 44 29 cet l0 id 0 string x null int c l switch s length case 3 c s char at 2 if c b if s char at 0 s s char at 1 u id id sub break l0 els if c g if s char at 0 b s char at 1 i id id big break l0 els if c p if s char at 0 s s char at 1 u id id sup break l0 break l case 4 c s char at 0 if c b x bold id id bold els if c l x link id id link break l case 5 switch s char at 4 case d x fix id id fix break l case e x slice id id slice break l case h x match id id match break l case k x blink id id blink break l case l x small id id small break l case t x split id id split break l break l case 6 switch s char at 1 case e x search id id search break l case h x char at id id char at break l case n x anchor id id anchor break l case o x concat id id concat break l case q x equal id id equal break l case t x strike id id strike break l case u x substr id id substr break l break l case 7 switch s char at 1 case a x valu of id id valu of break l case e x replac id id replac break l case n x index of id id index of break l case t x ital id id ital break l break l case 8 c s char at 4 if c r x to string id id to string els if c s x fontsiz id id fontsiz els if c u x to sourc id id to sourc break l case 9 c s char at 0 if c f x fontcolor id id fontcolor els if c s x substr id id substr break l case 10 x char code at id id char code at break l case 11 switch s char at 2 case l x to lower case id id to lower case break l case u x to upper case id id to upper case break l case n x constructor id id constructor break l case s x last index of id id last index of break l break l case 16 x equal ignor case id id equal ignor case break l if x null x s x equal s id 0 gener return id class sub string public sub string public sub string string str index 0 char arrai str to char arrai length str length public sub string char sourc int start int len there must be a better wai of do thi index 0 length len char arrai new char len for int j 0 j len j char arrai j sourc start j public string to string return char arrai null new string char arrai index length creat a scriptabl input stream param in the input stream to read from param scope the top level scope to creat the object in public scriptabl input stream input stream in scriptabl scope throw io except super in thi scope scope enabl resolv object true context cx context get current context if cx null thi class loader cx get applic class loader protect class resolv class object stream class desc throw io except class not found except string name desc get name if class loader null try return class loader load class name catch class not found except ex fall through to default load return super resolv class desc protect object resolv object object obj throw io except if obj instanceof scriptabl output stream pend lookup string name scriptabl output stream pend lookup obj get name obj scriptabl output stream lookup qualifi name scope name if obj scriptabl not found throw new io except object name not found upon deseri els if obj instanceof uniqu tag obj uniqu tag obj read resolv els if obj instanceof undefin obj undefin obj read resolv return obj static void init scriptabl scope boolean seal nativ with obj new nativ with obj set parent scope scope obj set prototyp scriptabl object get object prototyp scope id function object ctor new id function object obj ftag id constructor with 0 scope ctor mark as constructor obj if seal ctor seal object ctor export as scope properti privat nativ with protect nativ with scriptabl parent scriptabl prototyp thi parent parent thi prototyp prototyp public string get class name return with public boolean ha string id scriptabl start return prototyp ha id prototyp public boolean ha int index scriptabl start return prototyp ha index prototyp public object get string id scriptabl start if start thi start prototyp return prototyp get id start public object get int index scriptabl start if start thi start prototyp return prototyp get index start public void put string id scriptabl start object valu if start thi start prototyp prototyp put id start valu public void put int index scriptabl start object valu if start thi start prototyp prototyp put index start valu public void delet string id prototyp delet id public void delet int index prototyp delet index public scriptabl get prototyp return prototyp public void set prototyp scriptabl prototyp thi prototyp prototyp public scriptabl get parent scope return parent public void set parent scope scriptabl parent thi parent parent public object get id return prototyp get id public object get default valu class type hint return prototyp get default valu type hint public boolean ha instanc scriptabl valu return prototyp ha instanc valu must return null to continu loop or the final collect result protect object updat dot queri boolean valu nativ with itself doe not support it throw new illeg state except public object exec id call id function object f context cx scriptabl scope scriptabl thi obj object arg if f ha tag ftag if f method id id constructor throw context report runtim error1 msg cant call indirect with throw f unknown static boolean is with function object function obj if function obj instanceof id function object id function object f id function object function obj return f ha tag ftag f method id id constructor return fals static object new with special context cx scriptabl scope object arg script runtim check deprec cx with scope scriptabl object get top level scope scope nativ with thi obj new nativ with thi obj set prototyp arg length 0 scriptabl object get class prototyp scope object script runtim to object cx scope arg 0 thi obj set parent scope scope return thi obj string script text i proxi int type thi type type public object run context cx if type process file process file cx arg els if type eval inlin script script script load script from sourc cx script text command 1 null if script null evalu script script cx get global els throw kit code bug return null public void quit context cx int exit code if type system exit system exit exit code return throw kit code bug main entri point process argument as would a normal java program also creat a new context and associ it with the current thread then set up the execut environ and begin to execut script public static void main string arg try if boolean get boolean rhino us java polici secur init java polici secur support catch secur except ex ex print stack trace system err int result exec arg if result 0 system exit result execut the given argument but don t system exit at the end public static int exec string orig arg error report new tool error report fals global get err shell context factori set error report error report string arg process option orig arg if process stdin file list add element null if global initi global init shell context factori i proxi iproxi new i proxi i proxi process file iproxi arg arg shell context factori call iproxi return exit code static void process file context cx string arg defin argument arrai in the top level object need to alloc new arrai sinc new arrai requir instanc of exactli object not object subclass object arrai new object arg length system arraycopi arg 0 arrai 0 arg length scriptabl arg obj cx new arrai global arrai global defin properti argument arg obj scriptabl object dontenum for int i 0 i file list size i process sourc cx string file list element at i public static global get global return global pars argument public static string process option string arg string usag error good usag for int i 0 i if i arg length return new string 0 string arg arg i if arg start with process stdin fals file list add element arg string result new string arg length i 1 system arraycopi arg i 1 result 0 arg length i 1 return result if arg equal version if i arg length usag error arg break good usag int version try version integ pars int arg i catch number format except ex usag error arg i break good usag if context is valid languag version version usag error arg i break good usag shell context factori set languag version version continu if arg equal opt arg equal o if i arg length usag error arg break good usag int opt try opt integ pars int arg i catch number format except ex usag error arg i break good usag if opt 2 compat with cocoon rhino fork opt 1 els if context is valid optim level opt usag error arg i break good usag shell context factori set optim level opt continu if arg equal strict shell context factori set strict mode true continu if arg equal e process stdin fals if i arg length usag error arg break good usag if global initi global init shell context factori i proxi iproxi new i proxi i proxi eval inlin script iproxi script text arg i shell context factori call iproxi continu if arg equal w error report set is report warn true continu if arg equal f process stdin fals if i arg length usag error arg break good usag file list add element arg i equal null arg i continu if arg equal sealedlib global set seal std lib true continu usag error arg break good usag print usag messag global get out println tool error report get messag msg shell usag usag error system exit 1 return null privat static void init java polici secur support throwabl ex obj try class cl class for name org mozilla javascript tool shell java polici secur secur impl secur proxi cl new instanc secur control init global secur impl return catch class not found except ex ex obj ex catch illeg access except ex ex obj ex catch instanti except ex ex obj ex catch linkag error ex ex obj ex throw kit init caus new illeg state except can not load secur support ex obj ex obj evalu java script sourc param cx the current context param filenam the name of the file to compil or null for interact mode public static void process sourc context cx string filenam if filenam null filenam equal print stream ps global get err if filenam null print implement version ps println cx get implement version us the interpret for interact input cx set optim level 1 buffer reader in new buffer reader new input stream reader global get in int lineno 1 boolean hiteof fals while hiteof int startlin lineno if filenam null ps print js ps flush string sourc collect line of sourc to compil while true string newlin try newlin in read line catch io except ioe ps println ioe to string break if newlin null hiteof true break sourc sourc newlin n lineno if cx string is compil unit sourc break script script load script from sourc cx sourc stdin lineno null if script null object result evalu script script cx global if result context get undefin valu try ps println context to string result catch rhino except rex tool error report report except cx get error report rex nativ arrai h global histori h put int h get length h sourc ps println els process file cx global filenam system gc public static void process file context cx scriptabl scope string filenam if secur impl null process file secur cx scope filenam null els secur impl call process file secur cx scope filenam static void process file secur context cx scriptabl scope string path object secur domain script script if path end with class script load compil script cx path secur domain els string sourc string read file or url path true if sourc null exit code exitcod file not found return support the execut script syntax if the first line begin with a treat the whole line as a comment if sourc length 0 sourc char at 0 for int i 1 i sourc length i int c sourc char at i if c n c r sourc sourc substr i break script load script from sourc cx sourc path 1 secur domain if script null evalu script script cx scope public static script load script from sourc context cx string script sourc string path int lineno object secur domain try return cx compil string script sourc path lineno secur domain catch evalu except ee alreadi print messag exit code exitcod runtim error catch rhino except rex tool error report report except cx get error report rex exit code exitcod runtim error catch virtual machin error ex treat stack overflow and out of memori as runtim error ex print stack trace string msg tool error report get messag msg uncaughtj except ex to string exit code exitcod runtim error context report error msg return null privat static script load compil script context cx string path object secur domain byte data byte read file or url path fals if data null exit code exitcod file not found return null xxx for now extract class name of compil script from path instead of pars class byte int name start path last index of if name start 0 name start 0 els name start int name end path last index of if name end name start doe not exist in path name end 0 or it come befor name start name end path length string name path substr name start name end try gener class loader loader secur control creat loader cx get applic class loader secur domain class clazz loader defin class name data loader link class clazz if script class is assign from clazz throw context report runtim error msg must implement script return script clazz new instanc catch rhino except rex tool error report report except cx get error report rex exit code exitcod runtim error catch illeg access except iaex exit code exitcod runtim error context report error iaex to string catch instanti except inex exit code exitcod runtim error context report error inex to string return null public static object evalu script script script context cx scriptabl scope try return script exec cx scope catch rhino except rex tool error report report except cx get error report rex exit code exitcod runtim error catch virtual machin error ex treat stack overflow and out of memori as runtim error ex print stack trace string msg tool error report get messag msg uncaughtj except ex to string exit code exitcod runtim error context report error msg return context get undefin valu public static input stream get in return get global get in public static void set in input stream in get global set in in public static print stream get out return get global get out public static void set out print stream out get global set out out public static print stream get err return get global get err public static void set err print stream err get global set err err read file or url specifi by tt path tt return file or url content as tt byte tt or as tt string tt if tt convert to string tt is true privat static object read file or url string path boolean convert to string url url null assum path is url if it contain dot and there ar at least 2 charact in the protocol part the later allow under window to interpret path with driver letter as file not url if path index of 2 try url new url path catch malformedurl except ex input stream is null int capac hint 0 if url null file file new file path capac hint int file length try is new file input stream file catch io except ex context report error tool error report get messag msg couldnt open path return null els try url connect uc url open connect is uc get input stream capac hint uc get content length ignor insan valu for content length if capac hint 1 20 capac hint 1 catch io except ex context report error tool error report get messag msg couldnt open url url to string ex to string return null if capac hint 0 capac hint 4096 byte data try try data kit read stream is capac hint final is close catch io except ex context report error ex to string return null object result if convert to string result data els convert to string us the default encod xxx us charset argument of content type if url result new string data return result public final void init script function context cx scriptabl scope script runtim set function proto and parent thi scope param indent how much to indent the decompil result param flag flag specifi format of decompil output final string decompil int indent int flag string encod sourc get encod sourc if encod sourc null return super decompil indent flag els uint map properti new uint map 1 properti put decompil initi indent prop indent return decompil decompil encod sourc flag properti public int get length int param count get param count if get languag version context version 1 2 return param count context cx context get context nativ call activ script runtim find function activ cx thi if activ null return param count return activ origin arg length public int get ariti return get param count deprec us link base function get function name instead for backward compat keep an old method name us by batik and possibl other public string js get name return get function name get encod sourc string public string get encod sourc return null public debugg script get debugg view return null protect abstract int get languag version protect abstract int get languag version get number of declar paramet it should be 0 for script protect abstract int get param count get number of declar paramet and variabl defin through var statement get paramet or variabl name if tt index link get param count tt then return the name of the correspond paramet otherwis returm the name of variabl privat final int tag id privat uniqu tag int tag id thi tag id tag id public object read resolv switch tag id case id not found return not found case id null valu return null valu case id doubl mark return doubl mark throw new illeg state except string valu of tag id overridden for better debug printout public string to string string name switch tag id case id not found name not found break case id null valu name null valu break case id doubl mark name doubl mark break default throw kit code bug return super to string name the method must not be public or protect static secur control global return global check if global link secur control wa alreadi instal see init global secur control control public static boolean ha global return global null initi global control that will be us for all secur relat oper the global control take preced over alreadi instal link context specif control and caus ani subsequ call to link context set secur control secur control to throw an except p the method can onli be call onc see ha global public static void init global secur control control if control null throw new illeg argument except if global null throw new secur except cannot overwrit alreadi instal global secur control global control get class loader like object that can be us to defin class with the given secur context param parent loader parent class loader to deleg search for class not defin by the class loader itself param secur domain some object specifi the secur context of the code that is defin by the return class loader public abstract gener class loader creat class loader creat link gener class loader with restrict impos by static domain and all current stack frame the method us the secur control instanc associ with the current link context to construct proper dynam domain and creat correspond class loader par if no secur control is associ with the current link context the method call link context creat class loader class loader parent param parent parent class loader if null link context get applic class loader will be us param static domain static secur domain public static gener class loader creat loader class loader parent object static domain context cx context get context if parent null parent cx get applic class loader secur control sc cx get secur control gener class loader loader if sc null loader cx creat class loader parent els object dynam domain sc get dynam secur domain static domain loader sc creat class loader parent dynam domain return loader get dynam secur domain that allow an action onli if it is allow by the current java stack and i secur domain i if i secur domain i is null return domain repres permiss allow by the current stack call link callabl call context cx scriptabl scope scriptabl thi obj object arg of i callabl i under restrict secur domain where an action is allow onli if it is allow accord to the java stack on the moment of the i exec with domain i call and i secur domain i ani call to link get dynam secur domain object dure execut of tt callabl call cx scope thi obj arg tt should return a domain incorpor restrict impos by i secur domain i and java stack on the moment of call with domain invoc p the method should alwai be overridden it is not declar abstract for compat reason public object call with domain object secur domain context cx final callabl callabl scriptabl scope final scriptabl thi obj final object arg return exec with domain cx scope new script public object exec context cx scriptabl scope return callabl call cx scope thi obj arg secur domain return exec with domain cx scope new script public object exec context cx scriptabl scope return callabl call cx scope thi obj arg deprec the applic should not overrid thi method and instead overrid link call with domain object secur domain context cx callabl callabl scriptabl scope scriptabl thi obj object arg public object exec with domain context cx scriptabl scope script script object secur domain throw new illeg state except call with domain should be overridden follow the art of comput program by donald e knuth public uint map thi 4 public uint map int initi capac if initi capac 0 kit code bug tabl grow when number of store kei 3 4 of max capac int minim capac initi capac 4 3 int i for i 2 1 i minim capac i power i if check power 2 kit code bug public boolean is empti return kei count 0 public int size return kei count public boolean ha int kei if kei 0 kit code bug return 0 find index kei get object valu assign with kei return kei object valu or null if kei is absent public object get object int kei if kei 0 kit code bug if valu null int index find index kei if 0 index return valu index return null get integ valu assign with kei return kei integ valu or default valu if kei is absent public int get int int kei int default valu if kei 0 kit code bug int index find index kei if 0 index if ivalu shift 0 return kei ivalu shift index return 0 return default valu get integ valu assign with kei return kei integ valu or default valu if kei doe not exist or doe not have int valu throw runtim except if kei doe not exist public int get exist int int kei if kei 0 kit code bug int index find index kei if 0 index if ivalu shift 0 return kei ivalu shift index return 0 kei must exist kit code bug return 0 set object valu of the kei if kei doe not exist also set it int valu to 0 public void put int kei object valu if kei 0 kit code bug int index ensur index kei fals if valu null valu new object 1 power valu index valu set int valu of the kei if kei doe not exist also set it object valu to null public void put int kei int valu if kei 0 kit code bug int index ensur index kei true if ivalu shift 0 int n 1 power kei length can be n 2 after clear which set ivalu shift to 0 if kei length n 2 int tmp new int n 2 system arraycopi kei 0 tmp 0 n kei tmp ivalu shift n kei ivalu shift index valu public void remov int kei if kei 0 kit code bug int index find index kei if 0 index kei index delet kei count allow to gc valu and make sure that new kei with the delet slot shall get proper default valu if valu null valu index null if ivalu shift 0 kei ivalu shift index 0 public void clear int n 1 power if kei null for int i 0 i n i kei i empti if valu null for int i 0 i n i valu i null ivalu shift 0 kei count 0 occupi count 0 return arrai of present kei public int get kei int kei thi kei int n kei count int result new int n for int i 0 n 0 i int entri kei i if entri empti entri delet result n entri return result privat static int tabl lookup step int fraction int mask int power int shift 32 2 power if shift 0 return fraction shift mask 1 els return fraction mask shift 1 privat int find index int kei int kei thi kei if kei null int fraction kei a int index fraction 32 power int entri kei index if entri kei return index if entri empti search in tabl after first fail attempt int mask 1 power 1 int step tabl lookup step fraction mask power int n 0 do if check if n occupi count kit code bug n index index step mask entri kei index if entri kei return index while entri empti return 1 and enough free space privat int insert new kei int kei if check occupi count kei count kit code bug if check kei count 1 power kit code bug int kei thi kei int fraction kei a int index fraction 32 power if kei index empti int mask 1 power 1 int step tabl lookup step fraction mask power int first index index do if check kei index delet kit code bug index index step mask if check first index index kit code bug while kei index empti kei index kei occupi count kei count return index privat void rehash tabl boolean ensur int space if kei null check if remov delet entri would free enough space if kei count 2 occupi count need to grow less then half of delet entri power int n 1 power int old kei int old shift ivalu shift if old shift 0 ensur int space kei new int n els ivalu shift n kei new int n 2 for int i 0 i n i kei i empti object old valu valu if old valu null valu new object n int old count kei count occupi count 0 if old count 0 kei count 0 for int i 0 remain old count remain 0 i int kei old i if kei empti kei delet int index insert new kei kei if old valu null valu index old valu i if old shift 0 kei ivalu shift index old old shift i remain ensur kei index creat on if necessari privat int ensur index int kei boolean int type int index 1 int first delet 1 int kei thi kei if kei null int fraction kei a index fraction 32 power int entri kei index if entri kei return index if entri empti if entri delet first delet index search in tabl after first fail attempt int mask 1 power 1 int step tabl lookup step fraction mask power int n 0 do if check if n occupi count kit code bug n index index step mask entri kei index if entri kei return index if entri delet first delet 0 first delet index while entri empti insert of new kei if check kei null kei index empti kit code bug if first delet 0 index first delet els need to consum empti entri check occup level if kei null occupi count 4 1 power 3 too litl unus entri rehash rehash tabl int type kei thi kei return insert new kei kei occupi count kei index kei kei count return index privat void write object object output stream out throw io except out default write object int count kei count if count 0 boolean ha int valu ivalu shift 0 boolean ha object valu valu null out write boolean ha int valu out write boolean ha object valu for int i 0 count 0 i int kei kei i if kei empti kei delet count out write int kei if ha int valu out write int kei ivalu shift i if ha object valu out write object valu i privat void read object object input stream in throw io except class not found except in default read object int written kei count kei count if written kei count 0 kei count 0 boolean ha int valu in read boolean boolean ha object valu in read boolean int n 1 power if ha int valu kei new int 2 n ivalu shift n els kei new int n for int i 0 i n i kei i empti if ha object valu valu new object n for int i 0 i written kei count i int kei in read int int index insert new kei kei if ha int valu int ivalu in read int kei ivalu shift index ivalu if ha object valu valu index in read object nativ java method member box method thi function name method 0 get name thi method method nativ java method member box method string name thi function name name thi method new member box method public nativ java method method method string name thi new member box method name public string get function name return function name static string script signatur object valu string buffer sig new string buffer for int i 0 i valu length i object valu valu i string s if valu null s null els if valu instanceof boolean s boolean els if valu instanceof string s string els if valu instanceof number s number els if valu instanceof scriptabl if valu instanceof undefin s undefin els if valu instanceof wrapper object wrap wrapper valu unwrap s wrap get class get name els if valu instanceof function s function els s object els s java member java signatur valu get class if i 0 sig append sig append s return sig to string string decompil int indent int flag string buffer sb new string buffer boolean justbodi 0 flag decompil onli bodi flag if justbodi sb append function sb append get function name sb append sb append n sb append to string sb append justbodi n n return sb to string public string to string string buffer sb new string buffer for int i 0 n method length i n i method method method i method sb append java member java signatur method get return type sb append sb append method get name sb append java member live connect signatur method i arg type sb append n return sb to string public object call context cx scriptabl scope scriptabl thi obj object arg find a method that match the type given if method length 0 throw new runtim except no method defin for call int index find function cx method arg if index 0 class c method 0 method get declar class string sig c get name get function name script signatur arg throw context report runtim error1 msg java no such method sig member box meth method index class arg type meth arg type first we marshal the arg object orig arg arg for int i 0 i arg length i object arg arg i object coerc context js to java arg arg type i if coerc arg if orig arg arg arg object arg clone arg i coerc object java object if meth is static java object null don t need an object els scriptabl o thi obj class c meth get declar class for if o null throw context report runtim error3 msg nonjava method get function name script runtim to string thi obj c get name if o instanceof wrapper java object wrapper o unwrap if c is instanc java object break o o get prototyp if debug print debug call meth arg object retval meth invok java object arg class static type meth method get return type if debug class actual type retval null null retval get class system err println return retval actual actual type expect static type object wrap cx get wrap factori wrap cx scope retval static type if debug class actual type wrap null null wrap get class system err println wrap as wrap class actual type if wrap null static type void type wrap undefin instanc return wrap find the index of the correct function to call given the set of method or constructor and the argument if no function can be found to call return 1 static int find function context cx member box method or ctor object arg if method or ctor length 0 return 1 els if method or ctor length 1 member box member method or ctor 0 class arg type member arg type int alength arg type length if alength arg length return 1 for int j 0 j alength j if nativ java object can convert arg j arg type j if debug print debug reject arg can t convert member arg return 1 if debug print debug found member arg return 0 int first best fit 1 int extra best fit null int extra best fit count 0 search for int i 0 i method or ctor length i member box member method or ctor i class arg type member arg type if arg type length arg length continu search for int j 0 j arg type length j if nativ java object can convert arg j arg type j if debug print debug reject arg can t convert member arg continu search if first best fit 0 if debug print debug found first applic member arg first best fit i els compar with all current fit method the loop start from 1 denot first best fit and proce until extra best fit count to avoid extra best fit alloc in the most common case of no ambigu int better count 0 number of time member wa prefer over best fit int wors count 0 number of time best fit were prefer over member for int j 1 j extra best fit count j int best fit index if j 1 best fit index first best fit els best fit index extra best fit j member box best fit method or ctor best fit index int prefer prefer signatur arg arg type best fit arg type if prefer prefer ambigu break els if prefer prefer first arg better count els if prefer prefer second arg wors count els if prefer prefer equal kit code bug thi should not happen in theori but on some jv ms class get method will return all static method of the class heirarchi even if a deriv class s paramet match exactli we want to call the dervi class s method if best fit is static best fit get declar class is assign from member get declar class on some jv ms class get method will return all static method of the class heirarchi even if a deriv class s paramet match exactli we want to call the dervi class s method if debug print debug substitut overridden static member arg if j 1 first best fit i els extra best fit j i els if debug print debug ignor same signatur member member arg continu search if better count 1 extra best fit count member wa prefer over all best fit if debug print debug new first applic member arg first best fit i extra best fit count 0 els if wors count 1 extra best fit count all best fit were prefer over member ignor it if debug print debug reject all current best better member arg els some ambigu wa present add member to best fit set if debug print debug ad to best fit set member arg if extra best fit null alloc maximum possibl arrai extra best fit new int method or ctor length 1 extra best fit extra best fit count i extra best fit count if first best fit 0 noth wa found return 1 els if extra best fit count 0 singl best fit return first best fit report remain ambigu string buffer buf new string buffer for int j 1 j extra best fit count j int best fit index if j 1 best fit index first best fit els best fit index extra best fit j buf append n buf append method or ctor best fit index to java declar member box first fit member method or ctor first best fit string member name first fit member get name string member class first fit member get declar class get name if method or ctor 0 is method throw context report runtim error3 msg constructor ambigu member name script signatur arg buf to string els throw context report runtim error4 msg method ambigu member class member name script signatur arg buf to string determin which of two signatur is the closer fit return on of prefer equal prefer first arg prefer second arg or prefer ambigu privat static int prefer signatur object arg class sig1 class sig2 int total prefer 0 for int j 0 j arg length j class type1 sig1 j class type2 sig2 j if type1 type2 continu object arg arg j determin which of type1 type2 is easier to convert from arg int rank1 nativ java object get convers weight arg type1 int rank2 nativ java object get convers weight arg type2 int prefer if rank1 rank2 prefer prefer first arg els if rank1 rank2 prefer prefer second arg els equal rank if rank1 nativ java object convers nontrivi if type1 is assign from type2 prefer prefer second arg els if type2 is assign from type1 prefer prefer first arg els prefer prefer ambigu els prefer prefer ambigu total prefer prefer if total prefer prefer ambigu break return total prefer privat static void print debug string msg member box member object arg if debug string buffer sb new string buffer sb append sb append msg sb append member get declar class get name sb append if member is method sb append member get name sb append java member live connect signatur member arg type sb append for argument sb append script signatur arg sb append system out println sb public interfac quit action public void quit context cx int exit code return an arrai of id for the properti of the object p all properti even those with attribut dont enum ar list thi allow the debugg to displai all properti of the object p return an arrai of java lang object with an entri for everi list properti properti access via an integ index will have a correspond integ entri in the return arrai properti access by a string will have a string entri in the return arrai call when execut is readi to start bytecod interpret for enter a particular function or script param cx current context for thi thread param activ the activ scope for the function or script param thi obj valu of the java script code thi code object param arg the arrai of argument public void on enter context cx scriptabl activ scriptabl thi obj object arg call when execut code reach new line in the sourc param cx current context for thi thread param line number current line number in the script sourc call when thrown except is handl by the function or script param cx current context for thi thread param ex except object call when the function or script for thi frame is about to return param cx current context for thi thread param by throw if true function will leav by throw except otherwis it will execut normal return param result or except function result in case of normal return or except object if about to throw except call when compil of a particular function or script into intern bytecod is done param cx current context for thi thread param fn or script object describ the function or script param sourc the function or script sourc void handl compil done context cx debugg script fn or script call when execut enter a particular function or script return implement of debug frame which receiv debug inform dure the function or script execut or null otherwis public interfac debugg script public boolean is top level public boolean is top level return true if thi is a function fals if it is a script public boolean is function get name of the function describ by thi script return null or an empti string if thi script is not function get number of declar paramet in function return 0 if thi script is not function see get param and var count see get param or var name int index get number of declar paramet and local variabl return number of declar global variabl if thi script is not function see get param count see get param or var name int index get name of a declar paramet or local variabl tt index tt should be less then link get param and var count if tt index nbsp lt nbsp link get param count tt return the name of the correspond paramet otherwis return the name of variabl if thi script is not function return the name of the declar global variabl get the name of the sourc usual filenam or url of the script return true if thi script or function were runtim gener from java script us tt eval tt function or tt function tt or tt script tt constructor get arrai contain the line number that that can be pass to code debug frame on line chang code note that line order in the result arrai is arbitrari public int get line number public int get function count public int get function count public debugg script get function int index public debugg script get function int index public debugg script get parent perform the call param cx the current context for thi thread param scope the scope to us to resolv properti param thi obj the java script code thi code object param arg the arrai of argument return the result of the call public object call context cx scriptabl scope scriptabl thi obj deprec rhino runtim never call the method public void context enter context cx public void context enter context cx deprec rhino runtim never call the method public void context exit context cx call the function note that the arrai of argument is not guarante to have length greater than 0 param cx the current context for thi thread param scope the scope to execut the function rel to thi is set to the valu return by get parent scope except when the function is call from a closur param thi obj the java script code thi code object param arg the arrai of argument return the result of the call public object call context cx scriptabl scope scriptabl thi obj call the function as a constructor thi method is invok by the runtim in order to satisfi a us of the java script code new code oper thi method is expect to creat a new object and return it param cx the current context for thi thread param scope an enclos scope of the caller except when the function is call from a closur param arg the arrai of argument return the alloc object unwrap the object by return the wrap valu return a wrap valu return true iff the java class with the given name should be expos to script p an embed mai filter which java class ar expos through live connect to java script script p due to the fact that there is no packag reflect in java thi method will also be call with packag name there is no wai for rhino to tell if packag a b is a packag name or a class that doesn t exist what rhino doe is attempt to load each segment of packag a b c it first attempt to load class a then attempt to load class a b then final attempt to load class a b c on a rhino instal without ani class shutter set and without ani of the abov class the express packag a b c will result in a java packag a b c and not an error p with class shutter suppli rhino will first call visibl to script befor attempt to look up the class name if visibl to script return fals the class name lookup is not perform and subsequ rhino execut assum the class is not present so for java lang system out println the lookup of java lang system is skip and thu rhino assum that java lang system doesn t exist so then for java lang system out rhino attempt to load the class java lang system out becaus it assum that java lang system is a packag name p param full class name the full name of the class includ the packag name with as a delimit for exampl the standard string class is java lang string return whether or not to reveal thi class to script thi obj will be null if invok as constructor in which case instanc of scriptabl should be return public object exec id call id function object f context cx scriptabl scope get the name of the set of object implement by thi java class thi correspond to the class oper in ecma and is us by object prototyp to string in ecma p see ecma 8 6 2 and 15 2 4 2 get a name properti from the object look properti up in thi object and return the associ valu if found return not found if not found note that thi method is not expect to travers the prototyp chain thi is differ from the ecma get oper depend on the properti selector the runtim will call thi method or the form of code get code that take an integ tabl tr th java script code th th java code th tr tr td a b td td a get b a td tr tr td a foo td td a get foo a td tr tr td a 3 td td a get 3 a td tr tr td a 3 td td a get 3 a td tr tr td a 3 0 td td a get 3 a td tr tr td a 3 0 td td a get 3 0 a td tr tr td a 1 1 td td a get 1 1 a td tr tr td a 4 td td a get 4 a td tr tabl p the valu that mai be return ar limit to the follow ul li java lang boolean object li li java lang string object li li java lang number object li li org mozilla javascript scriptabl object li li null li li the valu return by context get undefin valu li li not found li ul param name the name of the properti param start the object in which the lookup began return the valu of the properti mai be null or not found see org mozilla javascript context get undefin valu get a properti from the object select by an integr index ident to code get string scriptabl code except that an integr index is us to select the properti param index the numer index for the properti param start the object in which the lookup began return the valu of the properti mai be null or not found see org mozilla javascript scriptabl get string scriptabl indic whether or not a name properti is defin in an object doe not travers the prototyp chain p the properti is specifi by a string name as defin for the code get code method p param name the name of the properti param start the object in which the lookup began return true if and onli if the name properti is found in the object see org mozilla javascript scriptabl get see org mozilla javascript scriptabl object get properti indic whether or not an index properti is defin in an object doe not travers the prototyp chain p the properti is specifi by an integr index as defin for the code get code method p param index the numer index for the properti param start the object in which the lookup began return true if and onli if the index properti is found in the object see org mozilla javascript scriptabl get see org mozilla javascript scriptabl object get properti set a name properti in thi object p the properti is specifi by a string name as defin for code get code p the possibl valu that mai be pass in ar as defin for code get code a class that implement thi method mai choos to ignor call to set certain properti in which case those properti ar effect read onli p for properti defin in a prototyp chain us code put properti code in scriptabl object p note that if a properti i a i is defin in the prototyp i p i of an object i o i then evalu code o a 23 code will caus code set code to be call on the prototyp i p i with i o i as the i start i paramet to preserv java script semant it is the scriptabl object s respons to modifi i o i p thi design allow properti to be defin in prototyp and implement in term of getter and setter of java valu without consum slot in each instanc p p the valu that mai be set ar limit to the follow ul li java lang boolean object li li java lang string object li li java lang number object li li org mozilla javascript scriptabl object li li null li li the valu return by context get undefin valu li ul p arbitrari java object mai be wrap in a scriptabl by first call code context to object code thi allow the properti of a java script object to contain an arbitrari java object as a valu p note that code ha code will be call by the runtim first befor code set code is call to determin in which object the properti is defin note that thi method is not expect to travers the prototyp chain which is differ from the ecma put oper param name the name of the properti param start the object whose properti is be set param valu valu to set the properti to see org mozilla javascript scriptabl ha see org mozilla javascript scriptabl get see org mozilla javascript scriptabl object put properti see org mozilla javascript context to object set an index properti in thi object p the properti is specifi by an integr index as defin for code get code p ident to code put string scriptabl object code except that an integr index is us to select the properti param index the numer index for the properti param start the object whose properti is be set param valu valu to set the properti to see org mozilla javascript scriptabl ha see org mozilla javascript scriptabl get see org mozilla javascript scriptabl put string scriptabl object see org mozilla javascript scriptabl object put properti remov a properti from thi object thi oper correspond to the ecma delet except that the no result is return the runtim will guarante that thi method is call onli if the properti exist after thi method is call the runtim will call scriptabl ha to see if the properti ha been remov in order to determin the boolean result of the delet oper as defin by ecma 11 4 1 p a properti can be made perman by ignor call to remov it p the properti is specifi by a string name as defin for code get code p to delet properti defin in a prototyp chain see delet properti in scriptabl object param name the identifi for the properti see org mozilla javascript scriptabl get see org mozilla javascript scriptabl object delet properti remov a properti from thi object the properti is specifi by an integr index as defin for code get code p to delet properti defin in a prototyp chain see delet properti in scriptabl object ident to code delet string code except that an integr index is us to select the properti param index the numer index for the properti see org mozilla javascript scriptabl get see org mozilla javascript scriptabl object delet properti get the prototyp of the object return the prototyp set the prototyp of the object param prototyp the prototyp to set get the parent scope of the object return the parent scope set the parent scope of the object param parent the parent scope to set get an arrai of properti id not all properti id need be return those properti whose id ar not return ar consid non enumer return an arrai of object each entri in the arrai is either a java lang string or a java lang number get the default valu of the object with a given hint the hint ar string class for type string number class for type number scriptabl class for type object and boolean class for type boolean p a code hint code of null mean no hint see ecma 8 6 2 6 param hint the type hint return the default valu the instanceof oper p the java script code lh instanceof rh caus rh ha instanc lh to be call p the return valu is implement depend so that embed host object can return an appropri valu see the js 1 3 languag document for more detail p thi oper correspond to the propos emca ha instanc oper param instanc the valu that appear on the lh of the instanceof oper return an implement depend valu execut action us the suppli context instanc when rhino runtim call the method tt cx tt will be associ with the current thread as activ context see context call context action see context factori call context action public static final int ra search 3 public boolean is reg exp scriptabl obj public boolean is reg exp scriptabl obj public object compil reg exp context cx string sourc string flag public object compil reg exp context cx string sourc string flag public scriptabl wrap reg exp context cx scriptabl scope object compil object compil public object action context cx scriptabl scope scriptabl thi obj object arg int action type int action type public int find split context cx scriptabl scope string target string separ scriptabl re int ip int matchlen boolean match string parensp perform function call in refer context the arg arrai refer should not be store in ani object that is can be gc reachabl after thi method return if thi is necessari for exampl to implement link ref method then store arg clone not arg arrai itself param cx the current context for thi thread param thi obj the java script code thi code object param arg the arrai of argument execut the script p the script is execut in a particular runtim context which must be associ with the current thread the script is execut rel to a scope definit and us of global top level variabl and function will access properti of the scope object for compliant ecma program the scope must be an object that ha been initi as a global object us code context init standard object code p param cx the context associ with the current thread param scope the scope to execut rel to return the result of execut the script see org mozilla javascript context init standard object defin a new java class class creat via thi method should have the same class loader param name fulli qualifi class name param data class byte code return new class object link the given class param cl class instanc return from the previou call to link defin class string byte see java lang class loader resolv class class report a warn the implement class mai choos to ignor the warn if it desir param messag a string describ the warn param sourc name a string describ the java script sourc where the warn occur typic a filenam or url param line the line number associ with the warn param line sourc the text of the line mai be null param line offset the offset into line sourc where problem wa detect void warn string messag string sourc name int line report an error the implement class is free to throw an except if it desir if execut ha not yet begun the java script engin is free to find addit error rather than termin the translat it will not execut a script that had error howev param messag a string describ the error param sourc name a string describ the java script sourc where the error occur typic a filenam or url param line the line number associ with the error param line sourc the text of the line mai be null param line offset the offset into line sourc where problem wa detect void error string messag string sourc name int line creat an evalu except that mai be thrown runtim error unlik error will alwai termin the current script param messag a string describ the error param sourc name a string describ the java script sourc where the error occur typic a filenam or url param line the line number associ with the error param line sourc the text of the line mai be null param line offset the offset into line sourc where problem wa detect return an evalu except that will be thrown evalu except runtim error string messag string sourc name int line string line sourc