avmplus::AvmCore Class Reference

#include <AvmCore.h>

Inheritance diagram for avmplus::AvmCore:

MMgc::GCRoot avmshell::Shell axtam::AXTam List of all members.

interned constants

Constants used frequently in the VM; these are typically identifiers that are part of the core language semantics like "prototype" and "constructor". These are interned up front and held in AvmCore for easy reference.

 DRC (Stringp) kconstructor
 DRC (Stringp) kEmptyString
 DRC (Stringp) ktrue
 DRC (Stringp) kfalse
 DRC (Stringp) kundefined
 DRC (Stringp) knull
 DRC (Stringp) ktoString
 DRC (Stringp) ktoLocaleString
 DRC (Stringp) kvalueOf
 DRC (Stringp) klength
 DRC (Stringp) kobject
 DRC (Stringp) kfunction
 DRC (Stringp) kxml
 DRC (Stringp) kboolean
 DRC (Stringp) knumber
 DRC (Stringp) kstring
 DRC (Stringp) kuri
 DRC (Stringp) kprefix
 DRC (Stringp) kglobal
 DRC (Stringp) kcallee
 DRC (Stringp) kNeedsDxns
 DRC (Stringp) kAsterisk
 DRC (Stringp) kVersion
 DRC (Stringp) kVector
 DRC (Stringp) cachedChars[128]
Atom kNaN

Public Member Functions

void branchCheck (MethodEnv *env, bool interruptable, int go)
void setConsoleStream (OutputStream *stream)
virtual void presweep ()
virtual void postsweep ()
void SetMIREnabled (bool isEnabled)
bool IsMIREnabled () const
virtual void setStackBase ()
 DRC (Stringp) booleanStrings[2]
 DRC (Namespace *) publicNamespace
Atom handleActionPool (PoolObject *pool, DomainEnv *domainEnv, Toplevel *&toplevel, CodeContext *codeContext)
ScriptEnvprepareActionPool (PoolObject *pool, DomainEnv *domainEnv, Toplevel *&toplevel, CodeContext *codeContext)
void exportDefs (Traits *traits, ScriptEnv *scriptEnv)
PoolObjectparseActionBlock (ScriptBuffer code, int start, Toplevel *toplevel, Domain *domain, AbstractFunction *nativeMethods[], NativeClassInfop nativeClasses[], NativeScriptInfop nativeScripts[], List< Stringp > *include_versions=NULL)
Atom handleActionBlock (ScriptBuffer code, int start, DomainEnv *domainEnv, Toplevel *&toplevel, AbstractFunction *nativeMethods[], NativeClassInfop nativeClasses[], NativeScriptInfop nativeScripts[], CodeContext *codeContext)
void initNativeTables (NativeClassInfop classEntries, NativeScriptInfop scriptEntries, AbstractFunction *nativeMethods[], NativeClassInfop nativeClasses[], NativeScriptInfop nativeScripts[])
TraitsmakeParameterizedITraits (Stringp name, Namespace *ns, Traits *t)
TraitsmakeParameterizedCTraits (Stringp name, Namespace *ns, Traits *t)
Atom equals (Atom lhs, Atom rhs)
Atom compare (Atom lhs, Atom rhs)
Atom stricteq (Atom lhs, Atom rhs)
bool isFunction (Atom atom)
 AvmCore (MMgc::GC *gc)
 ~AvmCore ()
void initBuiltinPool ()
ToplevelinitTopLevel ()
virtual size_t getToplevelSize () const
virtual ToplevelcreateToplevel (VTable *vtable)
uint32 toUInt32 (Atom atom) const
double toInteger (Atom atom) const
int integer (Atom atom) const
Atom doubleToAtom (double n)
Atom intAtom (Atom atom)
Atom uintAtom (Atom atom)
int boolean (Atom atom)
Stringp string (Atom atom)
Stringp coerce_s (Atom atom)
Stringp intern (Atom atom)
NamespaceinternNamespace (Namespace *ns)
bool istype (Atom atom, Traits *itraits)
Atom istypeAtom (Atom atom, Traits *itraits)
void increment_d (Atom *atom, int delta)
void increment_i (Atom *atom, int delta)
Atom primitive (Atom atom)
Atom booleanAtom (Atom atom)
Atom numberAtom (Atom atom)
double number (Atom atom) const
Atom constant (const char *s)
Stringp constantString (const char *s)
virtual void interrupt (MethodEnv *env)=0
virtual void stackOverflow (MethodEnv *env)=0
void _stackOverflow (MethodEnv *env)
void throwAtom (Atom atom)
void throwException (Exception *exception)
void throwErrorV (ClassClosure *type, int errorID, Stringp arg1=0, Stringp arg2=0, Stringp arg3=0)
StringformatErrorMessageV (int errorID, Stringp arg1=0, Stringp arg2=0, Stringp arg3=0)
StringtoErrorString (int d)
StringtoErrorString (AbstractFunction *m)
StringtoErrorString (const Multiname *n)
StringtoErrorString (Namespace *ns)
StringtoErrorString (Traits *t)
StringtoErrorString (const char *s)
StringtoErrorString (const wchar *s)
StringatomToErrorString (Atom a)
virtual StringgetErrorMessage (int errorID)
CodeContextcodeContext () const
ExceptionHandlerfindExceptionHandler (MethodInfo *info, sintptr pc, Exception *exception)
ExceptionHandlerbeginCatch (ExceptionFrame *ef, MethodInfo *info, sintptr pc, Exception *exception)
ExceptionHandlerfindExceptionHandlerNoRethrow (MethodInfo *info, sintptr pc, Exception *exception)
bool isXML (Atom atm)
bool isDate (Atom atm)
bool isLetter (wchar c)
bool isDigit (wchar c)
bool isCombiningChar (wchar c)
bool isExtender (wchar c)
Stringp ToXMLString (Atom a)
Stringp EscapeElementValue (const Stringp s, bool removeLeadingTrailingWhitespace)
Stringp EscapeAttributeValue (Atom v)
E4XNodeatomToXML (Atom atm)
XMLObjectatomToXMLObject (Atom atm)
bool isXMLList (Atom atm)
XMLListObjectatomToXMLList (Atom atm)
bool isQName (Atom atm)
bool isDictionary (Atom atm)
bool isDictionaryLookup (Atom key, Atom obj)
bool isXMLName (Atom arg)
QNameObjectatomToQName (Atom atm)
Stringp _typeof (Atom arg)
Stringp internString (Stringp s)
Stringp internString (Atom atom)
Stringp internInt (int n)
Stringp internDouble (double d)
Stringp internUint32 (uint32 ui)
Stringp internAlloc (const wchar *s, int len)
Stringp internAllocUtf8 (const byte *s, int len)
bool getIndexFromAtom (Atom a, uint32 *result) const
ScriptBufferImplnewScriptBuffer (size_t size)
VTablenewVTable (Traits *traits, VTable *base, ScopeChain *scope, AbcEnv *abcEnv, Toplevel *toplevel)
RegExpObjectnewRegExp (RegExpClass *regExpClass, Stringp pattern, Stringp options)
ScriptObjectnewObject (VTable *ivtable, ScriptObject *delegate)
TraitsnewTraits (Traits *base, int nameCount, int interfaceCount, uint32 sizeofInstance)
NamespacenewNamespace (Atom prefix, Atom uri, Namespace::NamespaceType type=Namespace::NS_Public)
NamespacenewNamespace (Atom uri, Namespace::NamespaceType type=Namespace::NS_Public)
NamespacenewNamespace (Stringp uri, Namespace::NamespaceType type=Namespace::NS_Public)
NamespacenewPublicNamespace (Stringp uri)
NamespaceSetnewNamespaceSet (int nsCount)
Stringp newString (const char *str) const
Stringp newString (const wchar *str) const
Stringp newString (const char *str, int len) const
Stringp uintToString (uint32 i)
Stringp intToString (int i)
Stringp doubleToString (double d)
Stringp concatStrings (Stringp s1, Stringp s2) const
Atom uintToAtom (uint32 n)
Atom intToAtom (int n)
Atom allocDouble (double n)
void rehashStrings (int newlen)
void rehashNamespaces (int newlen)

Static Public Member Functions

static bool isObject (Atom atom)
static bool isPointer (Atom atom)
static bool isTraits (Atom type)
static bool isNamespace (Atom atom)
static bool isMethodBinding (Binding b)
static bool isAccessorBinding (Binding b)
static bool hasSetterBinding (Binding b)
static bool hasGetterBinding (Binding b)
static int bindingToGetterId (Binding b)
static int bindingToSetterId (Binding b)
static int bindingToMethodId (Binding b)
static int bindingToSlotId (Binding b)
static int isSlotBinding (Binding b)
static int isVarBinding (Binding b)
static int isConstBinding (Binding b)
static bool isDouble (Atom atom)
static bool isInteger (Atom atom)
static bool isNumber (Atom atom)
static bool isBoolean (Atom atom)
static bool isNull (Atom atom)
static bool isUndefined (Atom atom)
static bool isNullOrUndefined (Atom atom)
static int integer_i (Atom a)
static uint32 integer_u (Atom a)
static int integer_d (double d)
static double number_d (Atom a)
static bool isString (Atom atom)
static bool isName (Atom atom)
static int readS24 (const byte *pc)
static int calculateInstructionWidth (const byte *p)
static void readOperands (const byte *&pc, unsigned int &imm32, int &imm24, unsigned int &imm32b, int &imm8)
static uint32 readU30 (const byte *&p)
static int32_t readU16 (const byte *pc)
static NamespaceatomToNamespace (Atom atom)
static double atomToDouble (Atom atom)
static Stringp atomToString (Atom atom)
static ScriptObjectatomToScriptObject (const Atom atom)
static Atom gcObjectToAtom (const void *obj)
static const void * atomToGCObject (Atom a)
static bool isGCObject (Atom a)
static bool getIndexFromString (Stringp s, uint32 *result)
static void atomWriteBarrier (MMgc::GC *gc, const void *container, Atom *address, Atom atomNew)

Public Attributes

PrintWriter console
MMgc::GC *const gc
Config config
uintptr minstack
BuiltinTraits traits
PoolObjectbuiltinPool
DomainbuiltinDomain
Namespace *const * dxnsAddr
int interrupted
VTablenamespaceVTable
Hashtableresources
CallStackNode * callStack
CodeContextAtom codeContextAtom
ExceptionFrameexceptionFrame
ExceptionexceptionAddr
HashtablexmlEntities

Private Member Functions

void registerNatives (NativeTableEntryp nativeMap, AbstractFunction *nativeMethods[])
int findString (const wchar *s, int len)
int findNamespace (const Namespace *ns)
 DRC (Stringp)*strings
 DRC (Namespacep)*namespaces

Static Private Member Functions

static int doubleToInt32 (double d)

Private Attributes

int stringCount
int deletedCount
int nsCount
int numStrings
int numNamespaces
GCInterface gcInterface

Classes

class  GCInterface

Detailed Description

The main class of the AVM+ virtual machine. This is the main entry point to the VM for running ActionScript code.

Definition at line 157 of file AvmCore.h.


Constructor & Destructor Documentation

avmplus::AvmCore::AvmCore MMgc::GC gc  ) 
 

Constructor

Definition at line 103 of file AvmCore.cpp.

References AvmAssert, configure::config, avmplus::CONTEXT_NONE, DRC, MMgc::GC::GCV_AVMCORE, util::threadpool::i, and avmplus::MathUtils::nan().

00103                           : GCRoot(g), console(NULL), gc(g), 
00104 #ifdef AVMPLUS_MIR
00105         mirBuffers(g, 4), 
00106 #endif
00107         gcInterface(g)
00108 #ifdef FEATURE_SAMPLER
00109         ,_sampler(g)
00110 #endif
00111 #ifdef AVMPLUS_WORD_CODE
00112         , lookup_cache_timestamp(1)
00113 #endif
00114     {
00115         // sanity check for all our types
00116         AvmAssert (sizeof(int8) == 1);
00117         AvmAssert (sizeof(uint8) == 1);     
00118         AvmAssert (sizeof(int16) == 2);
00119         AvmAssert (sizeof(uint16) == 2);
00120         AvmAssert (sizeof(int32) == 4);
00121         AvmAssert (sizeof(uint32) == 4);
00122         AvmAssert (sizeof(int64) == 8);
00123         AvmAssert (sizeof(uint64) == 8);
00124         AvmAssert (sizeof(sintptr) == sizeof(void *));
00125         AvmAssert (sizeof(uintptr) == sizeof(void *));
00126         #ifdef AVMPLUS_64BIT
00127         AvmAssert (sizeof(sintptr) == 8);
00128         AvmAssert (sizeof(uintptr) == 8);       
00129         #else
00130         AvmAssert (sizeof(sintptr) == 4);
00131         AvmAssert (sizeof(uintptr) == 4);       
00132         #endif  
00133             
00134         // set default mode flags
00135         #ifdef AVMPLUS_VERBOSE
00136         config.verbose = false;
00137         config.verbose_addrs = false;
00138         #endif
00139 
00140         #ifdef AVMPLUS_ARM
00141         SetMIREnabled(false);
00142         #else
00143         SetMIREnabled(true);
00144         #endif
00145 
00146         #ifdef AVMPLUS_VERIFYALL
00147             config.verifyall = false;
00148         #endif
00149 
00150         #ifdef FEATURE_NANOJIT
00151             config.show_stats = false;
00152             config.tree_opt = false;
00153             config.verbose_live = false;;
00154             config.verbose_exits = false;
00155         #endif
00156 
00157         #ifdef AVMPLUS_MIR
00158             config.dceopt = true;
00159             #ifdef AVMPLUS_VERBOSE
00160             config.bbgraph = false;
00161             #endif
00162         #endif
00163 
00164         #if defined AVMPLUS_MIR || defined FEATURE_NANOJIT
00165             // jit flag forces use of MIR/LIR instead of interpreter
00166             config.jit = false;
00167             config.cseopt = true;
00168 
00169             #if defined(AVMPLUS_IA32) || defined(AVMPLUS_AMD64)
00170             config.sse2 = true;
00171             #endif
00172         #endif
00173 
00174     #ifdef VTUNE
00175             VTuneStatus = CheckVTuneStatus();
00176     #endif // VTUNE
00177 
00178         config.interrupts = false;
00179 
00180         gcInterface.SetCore(this);
00181         resources          = NULL;
00182         xmlEntities        = NULL;
00183         exceptionFrame     = NULL;
00184         exceptionAddr      = NULL;
00185         builtinPool        = NULL;
00186         builtinDomain      = NULL;
00187 
00188         GetGC()->SetGCContextVariable (MMgc::GC::GCV_AVMCORE, this);
00189 
00190         minstack           = 0;
00191 
00192 #ifdef FEATURE_SAMPLER
00193         _sampler.setCore(this);
00194 #endif
00195 
00196         #ifdef DEBUGGER
00197         langID             = -1;
00198         debugger           = NULL;
00199         profiler           = NULL;
00200         passAllExceptionsToDebugger = false;
00201         #endif /* DEBUGGER */
00202 
00203         callStack          = NULL;
00204 
00205 #ifdef FEATURE_SAMPLER
00206         MMgc::m_sampler = sampler();
00207 #endif
00208 
00209         interrupted        = false;
00210 
00211         codeContextAtom    = CONTEXT_NONE;
00212         dxnsAddr           = NULL;
00213         
00214         strings         = NULL;
00215         numStrings      = 0;
00216         namespaces      = NULL;
00217         numNamespaces   = 0;
00218         stringCount     = 0;
00219         deletedCount    = 0;
00220         nsCount         = 0;
00221 
00222         numStrings = 1024; // power of 2
00223         strings = new DRC(Stringp)[numStrings];
00224         memset(strings, 0, numStrings*sizeof(Stringp));
00225 
00226         numNamespaces = 1024;  // power of 2
00227         namespaces = new DRC(Namespacep)[numNamespaces];
00228         memset(namespaces, 0, numNamespaces*sizeof(Namespace*));
00229 
00230         console.setCore(this);
00231         
00232         kEmptyString = constantString("");
00233         kconstructor = constantString("constructor");
00234         kundefined = constantString("undefined");
00235         knull = constantString("null");
00236         ktrue = constantString("true");
00237         kfalse = constantString("false");
00238         ktoString = constantString("toString");
00239         ktoLocaleString = constantString("toLocaleString");
00240         kvalueOf = constantString("valueOf");
00241         klength = constantString("length");
00242 
00243         kobject = constantString("object");
00244         kboolean = constantString("boolean");
00245         knumber = constantString("number");
00246         kstring = constantString("string");
00247         kxml = constantString("xml");
00248         kfunction = constantString("function");
00249         kglobal = constantString("global");
00250         kcallee = constantString("callee");
00251 
00252         kuri = constantString("uri");
00253         kprefix = constantString("prefix");
00254         kNaN = doubleToAtom(MathUtils::nan());
00255         kNeedsDxns = constantString("NeedsDxns");
00256         kAsterisk = constantString("*");
00257         kVersion = constantString("Version");
00258         kVector = constantString("Vector.<");
00259 
00260 #ifdef AVMPLUS_VERBOSE
00261         knewline = newString("\n");
00262         krightbracket = newString("]");
00263         kleftbracket = newString("[");
00264         kcolon = newString(":");
00265         ktabat = newString("\tat ");
00266         kparens = newString("()");
00267 #endif
00268 #if defined AVMPLUS_VERBOSE || defined FEATURE_SAMPLER
00269         kanonymousFunc = newString("<anonymous>");
00270 #endif
00271         for (int i = 0; i < 128; i++)
00272         {
00273             char singleChar = (char)i;
00274             // call newString() with an explicit length of 1; required
00275             // when singleChar==0, because in that case we need a string
00276             // which is a single character with value 0
00277             cachedChars[i] = internString(newString(&singleChar, 1));
00278         }
00279 
00280         booleanStrings[0] = kfalse;
00281         booleanStrings[1] = ktrue;
00282 
00283 #ifdef AVMPLUS_INTERNINT_CACHE
00284         // See code in AvmCore::internInt
00285         for (int i=0 ; i < 256 ; i++ )
00286             index_strings[i] = NULL;
00287 #endif
00288 
00289         // create public namespace 
00290         publicNamespace = internNamespace(newNamespace(kEmptyString));
00291 
00292         #if defined AVMPLUS_MIR && defined(AVMPLUS_VERBOSE)
00293         codegenMethodNames = CodegenMIR::initMethodNames(this);
00294         #endif
00295 
00296         #ifdef FEATURE_JNI
00297         java = NULL;
00298         #endif
00299 #ifdef SUPERWORD_PROFILING
00300         swprofStart();
00301 #endif
00302     }

avmplus::AvmCore::~AvmCore  ) 
 

Destructor

Definition at line 304 of file AvmCore.cpp.

References gc, MMgc::GC::GCV_AVMCORE, and MMgc::GC::SetGCContextVariable().

00305     {       
00306         // Free the numbers and strings tables
00307         delete [] strings;
00308         if (gc) 
00309         {
00310             gc->SetGCContextVariable(GC::GCV_AVMCORE, NULL);
00311         }
00312 
00313         #if defined AVMPLUS_MIR && defined(AVMPLUS_VERBOSE)
00314         delete codegenMethodNames;
00315         #endif
00316 
00317         strings = NULL;
00318 
00319         delete [] namespaces;
00320         namespaces = NULL;
00321 
00322 #ifdef AVMPLUS_MIR
00323         // free all the mir buffers
00324         while(mirBuffers.size() > 0)
00325             mirBuffers.removeFirst()->free();
00326 #endif
00327 #ifdef SUPERWORD_PROFILING
00328         swprofStop();
00329 #endif
00330     }


Member Function Documentation

void avmplus::AvmCore::_stackOverflow MethodEnv env  )  [inline]
 

Definition at line 979 of file AvmCore.h.

References stackOverflow().

00979 { stackOverflow(env); }

Stringp avmplus::AvmCore::_typeof Atom  arg  ) 
 

Implementation of OP_typeof

Definition at line 2552 of file AvmCore.cpp.

References isFunction(), isNull(), isXML(), isXMLList(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, and avmplus::AtomConstants::kStringType.

02553     {
02554         if (!isNull(arg))
02555         {
02556             switch (arg&7)
02557             {
02558             default:
02559             case kObjectType:
02560                 if (isXML (arg) || isXMLList(arg))
02561                 {
02562                     return kxml;
02563                 }
02564                 else if (isFunction(arg))
02565                 {
02566                     return kfunction; // No special type code for functions, but we need to
02567                                     //  special case to return 'function' here.
02568                 }
02569                 else
02570                 {
02571                     return kobject;
02572                 }
02573 
02574             case kBooleanType:
02575                 return kboolean;
02576 
02577             case kIntegerType:
02578             case kDoubleType:
02579                 return knumber;
02580 
02581             case kSpecialType:
02582                 return kundefined;
02583 
02584             case kStringType:
02585                 return kstring;
02586 
02587             case kNamespaceType:
02588                 return kobject;
02589             }
02590         }
02591         else
02592         {
02593             // typeof(null) = "object"
02594             return kobject;
02595         }
02596     }

Atom avmplus::AvmCore::allocDouble double  n  )  [inline]
 

Definition at line 1347 of file AvmCore.h.

References MMgc::GC::Alloc(), MMgc::GCRoot::GetGC(), and avmplus::AtomConstants::kDoubleType.

Referenced by doubleToAtom(), intToAtom(), and uintToAtom().

01348         {
01349             union { 
01350                 double *d;
01351                 void *v;
01352             };
01353             v = GetGC()->Alloc(sizeof(double), 0);
01354             *d = n;
01355             return kDoubleType | (uintptr)v;
01356         }

static double avmplus::AvmCore::atomToDouble Atom  atom  )  [inline, static]
 

Definition at line 1226 of file AvmCore.h.

References AvmAssert, and avmplus::AtomConstants::kDoubleType.

Referenced by boolean(), booleanAtom(), equals(), increment_d(), increment_i(), integer_i(), integer_u(), intern(), istype(), number(), number_d(), stricteq(), and string().

01227         {
01228             AvmAssert((atom&7)==kDoubleType);
01229 
01230             double* obj = (double*)(atom&~7);
01231             return *obj;
01232         }

String * avmplus::AvmCore::atomToErrorString Atom  a  ) 
 

Definition at line 1077 of file AvmCore.cpp.

Referenced by avmplus::ArrayClass::sort().

01078     {
01079         String* out = NULL;
01080     #ifdef DEBUGGER
01081         out = this->format(a);
01082     #else 
01083         (void)a;
01084         out = kEmptyString;
01085     #endif /* DEBUGGER */
01086         return out;
01087     }

static const void* avmplus::AvmCore::atomToGCObject Atom  a  )  [inline, static]
 

Definition at line 1258 of file AvmCore.h.

Referenced by avmplus::ElementE4XNode::_getAt(), avmplus::MethodClosureClass::create(), avmplus::ElementE4XNode::getAttribute(), and avmplus::DictionaryObject::nextNameIndex().

01258 { return (const void*)(a&~7); }

static Namespace* avmplus::AvmCore::atomToNamespace Atom  atom  )  [inline, static]
 

Definition at line 1220 of file AvmCore.h.

References AvmAssert, and avmplus::AtomConstants::kNamespaceType.

Referenced by avmplus::ElementE4XNode::_addInScopeNamespace(), avmplus::XMLObject::addNamespace(), avmplus::E4XNode::BuildInScopeNamespaceList(), avmplus::QNameClass::construct(), equals(), avmplus::E4XNode::FindMatchingNamespace(), avmplus::E4XNode::FindNamespace(), avmplus::XMLObject::GenerateUniquePrefix(), avmplus::XMLObject::GetNamespace(), avmplus::XMLObject::getNamespace(), avmplus::MethodEnv::hasnext(), avmplus::MethodEnv::hasnextproto(), intern(), avmplus::MethodEnv::internRtns(), avmplus::XMLObject::namespaceDeclarations(), newNamespace(), avmplus::MethodEnv::nextname(), avmplus::MethodEnv::nextvalue(), number(), numberAtom(), avmplus::XMLObject::removeNamespace(), string(), avmplus::Toplevel::ToAttributeName(), avmplus::Toplevel::ToXMLName(), and avmplus::XMLObject::XMLObject().

01221         {
01222             AvmAssert((atom&7)==kNamespaceType);
01223             return (Namespace*)(atom&~7);
01224         }

QNameObject * avmplus::AvmCore::atomToQName Atom  atm  ) 
 

Converts an Atom to a QNameObject if its traits match. Otherwise, null is returned. (An exception is NOT thrown)

Definition at line 2544 of file AvmCore.cpp.

References atomToScriptObject(), and isQName().

Referenced by equals(), newNamespace(), avmplus::QNameObject::QNameObject(), avmplus::XMLObject::setLocalName(), avmplus::XMLObject::setName(), avmplus::Toplevel::ToAttributeName(), and avmplus::Toplevel::ToXMLName().

02545     {
02546         if (!isQName (atm))
02547             return 0;
02548 
02549         return (QNameObject*)(atomToScriptObject(atm));
02550     }

static ScriptObject* avmplus::AvmCore::atomToScriptObject const Atom  atom  )  [inline, static]
 

Definition at line 1248 of file AvmCore.h.

References AvmAssert, and avmplus::AtomConstants::kObjectType.

Referenced by avmplus::ObjectVectorObject::_spliceHelper(), avmplus::VectorClass::applyTypeArgs(), avmplus::ArraySort::ArraySort(), atomToQName(), atomToXML(), atomToXMLList(), atomToXMLObject(), avmplus::Toplevel::callproperty(), avmplus::MethodEnv::callsuper(), avmplus::Toplevel::coerce(), avmplus::MethodEnv::coerceAtom2SO(), avmplus::ArrayClass::concat(), avmplus::RegExpClass::construct(), avmplus::Toplevel::constructprop(), avmplus::FunctionClass::createEmptyFunction(), avmplus::ScriptObject::createInstance(), avmplus::MethodEnv::delproperty(), equals(), avmplus::Exception::Exception(), avmplus::MethodEnv::findWithProperty(), avmplus::ScriptObject::function_apply(), avmplus::MethodEnv::getdescendants(), avmplus::MethodEnv::getdescendantslate(), avmplus::DictionaryObject::getKeyFromObject(), avmplus::Toplevel::getproperty(), avmplus::MethodEnv::getpropertylate_i(), avmplus::MethodEnv::getpropertylate_u(), avmplus::MethodEnv::getsuper(), avmplus::MethodEnv::hasnext(), avmplus::MethodEnv::hasnextproto(), avmplus::ArrayClass::indexOf(), intern(), avmplus::ArrayClass::isArray(), isDate(), isDictionary(), isQName(), istype(), isXML(), avmplus::Toplevel::isXmlBase(), isXMLList(), avmplus::ArrayClass::lastIndexOf(), avmplus::ArrayClass::map(), avmplus::ClassClosure::newInstance(), avmplus::VectorClass::newVector(), avmplus::MethodEnv::nextname(), avmplus::MethodEnv::nextvalue(), number(), numberAtom(), avmplus::ObjectClass::objectHasOwnProperty(), avmplus::ObjectClass::objectPropertyIsEnumerable(), avmplus::ObjectClass::objectSetPropertyIsEnumerable(), avmplus::ObjectClass::objectToString(), avmplus::Toplevel::op_applytype(), avmplus::Toplevel::op_call(), avmplus::Toplevel::op_construct(), avmplus::ArrayClass::pop(), primitive(), avmplus::StringClass::replace(), avmplus::Toplevel::resolveBuiltinClass(), avmplus::ArrayClass::reverse(), avmplus::ArraySort::ScriptCompare(), avmplus::ClassClosure::set_prototype(), avmplus::ObjectVectorObject::set_type(), avmplus::Toplevel::setproperty_b(), avmplus::MethodEnv::setpropertylate_i(), avmplus::MethodEnv::setpropertylate_u(), avmplus::MethodEnv::setsuper(), avmplus::ArrayClass::slice(), avmplus::ArrayClass::sort(), avmplus::ArrayClass::sortOn(), avmplus::ArrayClass::splice(), string(), avmplus::MethodEnv::toClassITraits(), avmplus::ArraySort::toFieldObject(), avmplus::Toplevel::toPrototype(), avmplus::Toplevel::toTraits(), and avmplus::Toplevel::toVTable().

01249         {
01250             AvmAssert((atom&7)==kObjectType);
01251             return (ScriptObject*)(atom&~7);
01252         }

static Stringp avmplus::AvmCore::atomToString Atom  atom  )  [inline, static]
 

Convert an Atom of kStringType to a Stringp

Parameters:
atom atom to convert. Note that the Atom must be of kStringType

Definition at line 1239 of file AvmCore.h.

References AvmAssert, and avmplus::AtomConstants::kStringType.

Referenced by boolean(), booleanAtom(), avmplus::RegExpObject::call(), avmplus::ScriptObject::deleteAtomProperty(), equals(), avmplus::Hashtable::find(), avmplus::ScriptObject::getAtomProperty(), axtam::MSIDispatchConsumer::getAtomProperty(), axtam::IDispatchConsumer::getAtomProperty(), avmplus::ScriptObject::getAtomPropertyFromProtoChain(), avmplus::ScriptObject::getAtomPropertyIsEnumerable(), getIndexFromAtom(), avmplus::ScriptObject::hasAtomProperty(), avmplus::Namespace::hasPrefix(), internString(), isName(), newNamespace(), number(), numberAtom(), avmplus::ScriptObject::setAtomProperty(), avmplus::ScriptObject::setAtomPropertyIsEnumerable(), avmplus::Namespace::setPrefix(), string(), avmplus::XMLObject::toStringMethod(), and avmplus::XMLListObject::toStringMethod().

01240         {
01241             AvmAssert((atom&7)==kStringType);
01242             return (Stringp)(atom&~7);
01243         }

E4XNode * avmplus::AvmCore::atomToXML Atom  atm  ) 
 

Converts an Atom to a E4XNode if its traits match. Otherwise, null is returned. (An exception is NOT thrown)

Definition at line 2528 of file AvmCore.cpp.

References atomToScriptObject(), and isXML().

Referenced by avmplus::ElementE4XNode::_insert(), avmplus::ElementE4XNode::_replace(), avmplus::XMLObject::contains(), avmplus::XMLListObject::setMultinameProperty(), and stricteq().

02529     {
02530         if (!isXML (atm))
02531             return 0;
02532 
02533         return ((XMLObject*)(atomToScriptObject(atm)))->getNode();
02534     }

XMLListObject * avmplus::AvmCore::atomToXMLList Atom  atm  ) 
 

Converts an Atom to a XMLListObject if its traits match. Otherwise, null is returned. (An exception is NOT thrown)

Definition at line 2536 of file AvmCore.cpp.

References atomToScriptObject(), and isXMLList().

Referenced by avmplus::XMLListObject::_append(), avmplus::XMLListObject::_equals(), avmplus::ElementE4XNode::_insert(), avmplus::XMLListObject::_resolveValue(), avmplus::XMLObject::appendChild(), avmplus::XMLObject::attribute(), avmplus::XMLListObject::attribute(), avmplus::XMLObject::attributes(), avmplus::XMLListObject::attributes(), avmplus::XMLObject::callProperty(), avmplus::XMLListObject::callProperty(), avmplus::XMLObject::child(), avmplus::XMLObject::childChanges(), avmplus::XMLObject::children(), avmplus::XMLListObject::children(), avmplus::XMLObject::descendants(), avmplus::XMLListObject::descendants(), equals(), avmplus::XMLListObject::getDescendants(), avmplus::XMLObject::insertChildAfter(), avmplus::XMLObject::insertChildBefore(), avmplus::XMLObject::prependChild(), avmplus::XMLListObject::setMultinameProperty(), avmplus::XMLListObject::setUintProperty(), and ToXMLString().

02537     {
02538         if (!isXMLList (atm))
02539             return 0;
02540 
02541         return (XMLListObject*)(atomToScriptObject(atm));
02542     }

XMLObject * avmplus::AvmCore::atomToXMLObject Atom  atm  ) 
 

Converts an Atom to a XMLObject if its traits match. Otherwise, null is returned. (An exception is NOT thrown)

Definition at line 2520 of file AvmCore.cpp.

References atomToScriptObject(), and isXML().

Referenced by avmplus::XMLListObject::_getAt(), avmplus::XMLListObject::_resolveValue(), avmplus::XMLObject::appendChild(), avmplus::XMLClass::construct(), equals(), avmplus::XMLObject::insertChildAfter(), avmplus::XMLObject::insertChildBefore(), avmplus::XMLObject::prependChild(), avmplus::XMLObject::replace(), avmplus::XMLListObject::setUintProperty(), and ToXMLString().

02521     {
02522         if (!isXML (atm))
02523             return 0;
02524 
02525         return (XMLObject*)(atomToScriptObject(atm));
02526     }

void avmplus::AvmCore::atomWriteBarrier MMgc::GC gc,
const void *  container,
Atom address,
Atom  atomNew
[static]
 

Definition at line 3954 of file AvmCore.cpp.

References gc, isNull(), avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kStringType, and MMgc::GC::WriteBarrierNoSubstitute().

03955     { 
03956 #ifdef MMGC_DRC
03957         Atom atom = *address;
03958         if(!isNull(atom)) {
03959             switch(atom&7)
03960             {   
03961                 case kStringType:
03962                 case kObjectType:
03963                 case kNamespaceType:
03964                     MMgc::RCObject *obj = (MMgc::RCObject*)(atom&~7);
03965                     obj->DecrementRef();
03966                     break;
03967             }
03968         }
03969 #endif
03970 
03971         switch(atomNew&7)
03972         {
03973         case kStringType:
03974         case kObjectType:
03975         case kNamespaceType:
03976 #ifdef MMGC_DRC
03977             if(!isNull(atomNew))
03978                 ((MMgc::RCObject*)(atomNew&~7))->IncrementRef();
03979             // fall through
03980 #endif
03981         case kDoubleType:
03982             {
03983                 gc->WriteBarrierNoSubstitute(container, (const void*)atomNew);
03984             }
03985             break;  
03986 
03987         }
03988         *address = atomNew;
03989     }

ExceptionHandler * avmplus::AvmCore::beginCatch ExceptionFrame ef,
MethodInfo info,
sintptr  pc,
Exception exception
 

Definition at line 1654 of file AvmCore.cpp.

References avmplus::ExceptionFrame::beginCatch(), avmplus::ExceptionFrame::beginTry(), and findExceptionHandler().

01656     {
01657         ef->beginCatch();
01658         ExceptionHandler* handler = findExceptionHandler(info,pc,exception);
01659         ef->beginTry(this);
01660         return handler;
01661     }

static int avmplus::AvmCore::bindingToGetterId Binding  b  )  [inline, static]
 

Definition at line 465 of file AvmCore.h.

References AvmAssert, hasGetterBinding(), and avmplus::urshift().

Referenced by avmplus::Toplevel::callproperty(), avmplus::MethodEnv::callsuper(), avmplus::Toplevel::constructprop(), avmplus::Verifier::emitGetProperty(), avmplus::MethodEnv::getsuper(), and avmplus::Verifier::readBinding().

00466         {
00467             AvmAssert(hasGetterBinding(b));
00468             return urshift(b,3);
00469         }

static int avmplus::AvmCore::bindingToMethodId Binding  b  )  [inline, static]
 

Definition at line 477 of file AvmCore.h.

References AvmAssert, isMethodBinding(), and avmplus::urshift().

Referenced by avmplus::Toplevel::callproperty(), avmplus::MethodEnv::callsuper(), avmplus::Toplevel::constructprop(), avmplus::FunctionClass::createEmptyFunction(), avmplus::Verifier::findMathFunction(), avmplus::Verifier::findStringFunction(), avmplus::Toplevel::getproperty(), and avmplus::MethodEnv::getsuper().

00478         {
00479             AvmAssert(isMethodBinding(b));
00480             return urshift(b,3);
00481         }

static int avmplus::AvmCore::bindingToSetterId Binding  b  )  [inline, static]
 

Definition at line 471 of file AvmCore.h.

References AvmAssert, hasSetterBinding(), and avmplus::urshift().

Referenced by avmplus::Toplevel::setproperty_b(), and avmplus::MethodEnv::setsuper().

00472         {
00473             AvmAssert(hasSetterBinding(b));
00474             return 1+urshift(b,3);
00475         }

static int avmplus::AvmCore::bindingToSlotId Binding  b  )  [inline, static]
 

Definition at line 483 of file AvmCore.h.

References AvmAssert, isSlotBinding(), and avmplus::urshift().

Referenced by avmplus::Toplevel::callproperty(), avmplus::MethodEnv::callsuper(), avmplus::Toplevel::constructprop(), avmplus::Verifier::emitGetProperty(), avmplus::Toplevel::getproperty(), avmplus::MethodEnv::getsuper(), avmplus::Verifier::readBinding(), avmplus::Toplevel::setproperty_b(), and avmplus::MethodEnv::setsuper().

00484         {
00485             AvmAssert(isSlotBinding(b));
00486             return urshift(b,3);
00487         }

int avmplus::AvmCore::boolean Atom  atom  ) 
 

Converts the passed atom to a C++ bool. If the atom is already an E4 boolean, it is simply decoded. Otherwise, it is coerced to the boolean type and returned. [ed] 12/28/04 use int because bool is sometimes byte-wide.

Definition at line 1301 of file AvmCore.cpp.

References atomToDouble(), atomToString(), avmplus::NativeID::isNaN, isNull(), isNullOrUndefined(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kStringType, and avmplus::String::length().

Referenced by avmplus::MethodEnv::unbox1().

01302     {
01303         if (!AvmCore::isNullOrUndefined(atom))
01304         {
01305             switch (atom&7)
01306             {
01307             case kIntegerType:
01308             case kBooleanType:
01309                 return (atom & ~7) != 0;
01310             case kObjectType:
01311             case kNamespaceType:
01312                 return !isNull(atom);
01313             case kStringType:
01314                 return !isNull(atom) && atomToString(atom)->length() > 0;
01315             default:
01316                 {
01317                     double d = atomToDouble(atom);
01318                     return !MathUtils::isNaN(d) && d != 0.0;
01319                 }
01320             }
01321         }
01322         else
01323         {
01324             return false;
01325         }
01326     }

Atom avmplus::AvmCore::booleanAtom Atom  atom  ) 
 

OP_toboolean; ES3 ToBoolean()

Definition at line 1269 of file AvmCore.cpp.

References atomToDouble(), atomToString(), avmplus::AtomConstants::falseAtom, util::threadpool::i, avmplus::NativeID::isNaN, isNull(), isNullOrUndefined(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kStringType, length, avmplus::AtomConstants::trueAtom, and avmplus::urshift().

Referenced by avmplus::Toplevel::coerce(), and avmplus::BooleanClass::construct().

01270     {
01271         if (!AvmCore::isNullOrUndefined(atom))
01272         {
01273             switch (atom&7)
01274             {
01275             case kIntegerType:
01276                 {
01277                     Atom i = atom>>3;
01278                     return urshift(i|-i,28)&~7 | kBooleanType;
01279                 }
01280             case kBooleanType:
01281                 return atom;
01282             case kObjectType:
01283             case kNamespaceType:
01284                 return isNull(atom) ? falseAtom : trueAtom;
01285             case kStringType:
01286                 if (isNull(atom)) return falseAtom;
01287                 return (atomToString(atom)->length() > 0) ? trueAtom : falseAtom;
01288             default:
01289                 {
01290                     double d = atomToDouble(atom);
01291                     return !MathUtils::isNaN(d) && d != 0.0 ? trueAtom : falseAtom;
01292                 }
01293             }
01294         }
01295         else
01296         {
01297             return falseAtom;
01298         }
01299     }

void avmplus::AvmCore::branchCheck MethodEnv env,
bool  interruptable,
int  go
[inline]
 

Definition at line 197 of file AvmCore.h.

References interrupt(), and interrupted.

00198         {
00199             if(go < 0)
00200             {
00201 #ifdef DEBUGGER
00202                 sampleCheck();
00203 #endif
00204                 if (interruptable && interrupted)
00205                         interrupt(env);
00206             }
00207         }

static int avmplus::AvmCore::calculateInstructionWidth const byte p  )  [inline, static]
 

Returns the size of the instruction + all it's operands. For OP_lookupswitch the size will not include the size for the case targets.

Definition at line 808 of file AvmCore.h.

References readOperands().

00809         {
00810             int a, b;
00811             unsigned int c, d;
00812             const byte* p2 = p;
00813             readOperands(p2, c, a, d, b);
00814             return int(p2-p);
00815         }

CodeContext * avmplus::AvmCore::codeContext  )  const
 

Definition at line 3892 of file AvmCore.cpp.

References codeContextAtom, avmplus::CONTEXT_ENV, avmplus::CONTEXT_NONE, and avmplus::MethodEnv::vtable.

Referenced by avmshell::DomainClass::get_currentDomain(), handleActionBlock(), handleActionPool(), and prepareActionPool().

03893     {
03894         if (codeContextAtom == CONTEXT_NONE) {
03895             return NULL;
03896         } else if ((codeContextAtom&7) == CONTEXT_ENV) {
03897             MethodEnv *env = (MethodEnv*)(codeContextAtom&~7);
03898             return env->vtable->abcEnv->codeContext;
03899         } else {
03900             return (CodeContext*)(codeContextAtom&~7);
03901         }
03902     }

Stringp avmplus::AvmCore::coerce_s Atom  atom  ) 
 

Definition at line 1844 of file AvmCore.cpp.

References isNullOrUndefined(), and string().

01845     {
01846         if (isNullOrUndefined(atom))
01847             return NULL;
01848         return string(atom);
01849     }

Atom avmplus::AvmCore::compare Atom  lhs,
Atom  rhs
 

this is the abstract relational comparison algorithm according to ECMA 262 11.8.5

Parameters:
lhs 
rhs 
Returns:
trueAtom, falseAtom, or undefinedAtom

Definition at line 805 of file AvmCore.cpp.

References avmplus::AtomConstants::falseAtom, avmplus::MathUtils::isNaN(), isString(), avmplus::AtomConstants::kIntegerType, number(), primitive(), string(), avmplus::AtomConstants::trueAtom, and avmplus::AtomConstants::undefinedAtom.

00806     {
00807         // fixme - toprimitive must take number hint, so "7" becomes 7
00808         if ((lhs&7)==kIntegerType && (rhs&7)==kIntegerType)
00809         {
00810             // fast path for integers
00811             return lhs < rhs ? trueAtom : falseAtom;
00812         }
00813 
00814         lhs = primitive(lhs);
00815         rhs = primitive(rhs);
00816         
00817         if (isString(lhs) && isString(rhs))
00818         {
00819             // string compare. todo optimize!
00820             return *string(lhs) < *string(rhs) ? trueAtom : falseAtom;
00821         }
00822 
00823         // numeric compare
00824         double dx = number(lhs);
00825         double dy = number(rhs);
00826         if (MathUtils::isNaN(dx)) return undefinedAtom;
00827         if (MathUtils::isNaN(dy)) return undefinedAtom;
00828         return dx < dy ? trueAtom : falseAtom;
00829     }

Stringp avmplus::AvmCore::concatStrings Stringp  s1,
Stringp  s2
const
 

Definition at line 3461 of file AvmCore.cpp.

References avmplus::String::length().

Referenced by avmplus::Toplevel::add2(), avmplus::VectorClass::applyTypeArgs(), avmplus::Verifier::findMathFunction(), avmplus::Verifier::findStringFunction(), avmplus::NamespaceSet::format(), avmplus::Multiname::format(), getErrorMessage(), avmplus::getTraits(), avmplus::AbstractFunction::makeIntoPrototypeFunction(), avmplus::XMLObject::normalize(), avmplus::XMLListObject::normalize(), avmplus::ObjectClass::objectToString(), avmplus::AbcParser::parseClassInfos(), avmplus::AbcParser::parseScriptInfos(), avmshell::SystemClass::readLine(), avmplus::PoolObject::resolveParameterizedType(), avmplus::ErrorObject::stackTraceToString(), toErrorString(), avmplus::XMLObject::toString(), and avmplus::XMLListObject::toString().

03462     {
03463         if (!s1) s1 = knull;
03464         if (!s2) s2 = knull;
03465         if (s1->length() == 0) {
03466             return s2;
03467         } else if (s2->length() == 0) {
03468             return s1;
03469         }
03470         return new (GetGC()) String(s1, s2);
03471     }

Atom avmplus::AvmCore::constant const char *  s  )  [inline]
 

produce an atom from a string. used only for string constants.

Parameters:
s 
Returns:

Reimplemented in axtam::AXTam.

Definition at line 959 of file AvmCore.h.

References avmplus::String::atom(), and constantString().

Referenced by avmplus::QNameClass::QNameClass(), avmplus::RegExpClass::RegExpClass(), avmplus::XMLClass::XMLClass(), and avmplus::XMLParser::XMLParser().

00960         {
00961             return constantString(s)->atom();
00962         }

Stringp avmplus::AvmCore::constantString const char *  s  ) 
 

Reimplemented in axtam::AXTam.

Definition at line 2756 of file AvmCore.cpp.

References internString(), and newString().

Referenced by constant(), avmplus::BuiltinTraits::findCTraits(), avmplus::Verifier::findMathFunction(), avmplus::Verifier::findStringFunction(), avmplus::BuiltinTraits::initInstanceTypes(), avmplus::AbcParser::parseMetadataInfos(), and avmplus::XMLClass::XMLClass().

02757     {
02758         return internString(newString(s));
02759     }

Toplevel * avmplus::AvmCore::createToplevel VTable vtable  )  [virtual]
 

Reimplemented in avmshell::Shell.

Definition at line 2603 of file AvmCore.cpp.

References avmplus::VTable::getExtraSize(), and MMgc::GCRoot::GetGC().

Referenced by prepareActionPool().

02604     {
02605         return new (GetGC(), vtable->getExtraSize()) Toplevel(vtable, NULL);
02606     }

Atom avmplus::AvmCore::doubleToAtom double  n  ) 
 

Definition at line 3317 of file AvmCore.cpp.

References allocDouble(), avmplus::MathUtils::isNegZero(), avmplus::AtomConstants::kIntegerType, and avmplus::MathUtils::real2int().

Referenced by avmplus::Toplevel::add2(), avmplus::AbstractFunction::boxArgs(), avmplus::MethodEnv::endCoerce(), equals(), avmplus::ScriptObject::getSlotAtom(), increment_d(), and numberAtom().

03318     {
03319         // There is no need for special logic for NaN or +/-Inf since we don't
03320         // ever test for those values in coreplayer.  As far as we're concerned
03321         // they are regular numeric values.
03322 
03323         // handle integer values w/out allocation
03324         #if defined(WIN32) && !defined(_ARM_)
03325         #ifdef AVMPLUS_AMD64
03326         int id = _mm_cvttsd_si32(_mm_set_sd(n));
03327         #else
03328         // this logic rounds in the wrong direction for E3, but
03329         // we never use a rounded value, only cleanly converted values.
03330         int id;
03331         _asm {
03332             fld [n];
03333             fistp [id];
03334         }
03335         #endif
03336         #elif defined(_MAC) && (defined (AVMPLUS_IA32) || defined(AVMPLUS_AMD64))
03337         int id = _mm_cvttsd_si32(_mm_set_sd(n));
03338         #else
03339         int id = MathUtils::real2int(n);
03340         #endif
03341 
03342         // make sure n is integer value that fits in 29 bits
03343         if (((id<<3)>>3) == n)
03344         {
03345             // make sure its not -0
03346             if (id == 0 && MathUtils::isNegZero(n))
03347                 return allocDouble(n);
03348             else
03349             {
03350 #ifdef AVMPLUS_64BIT
03351                 return (id<<3) | kIntegerType;
03352 #else
03353                 return uint32((id<<3) | kIntegerType);
03354 #endif
03355             }
03356         }
03357         else
03358         {
03359             return allocDouble(n);
03360         }
03361     }

int avmplus::AvmCore::doubleToInt32 double  d  )  [static, private]
 

Definition at line 3602 of file AvmCore.cpp.

References avmplus::MathUtils::floor(), avmplus::MathUtils::isInfinite(), avmplus::MathUtils::isNaN(), avmplus::MathUtils::mod(), and avmplus::MathUtils::real2int().

Referenced by integer_d().

03603     {
03604         // From the ES3 spec, 9.5
03605         //  2.  If Result(1) is NaN, +0, -0, +Inf, or -Inf, return +0.
03606         //  3.  Compute sign(Result(1)) * floor(abs(Result(1))).
03607         //  4.  Compute Result(3) modulo 2^32; that is, a finite integer value k of Number 
03608         //  type with positive sign and less than 2^32 in magnitude such the mathematical 
03609         //  difference of Result(3) and k is mathematically an integer multiple of 2^32.
03610         //  5.  If Result(4) is greater than or equal to 2^31, return Result(4)- 2^32, 
03611         //  otherwise return Result(4).
03612 
03613         // step 2
03614         if (MathUtils::isNaN(d) || MathUtils::isInfinite(d) || d == 0) {
03615             return 0;
03616         }
03617 
03618         // step 3 (round towards 0)
03619         double ad = d < 0.0 ? MathUtils::floor(-d) : MathUtils::floor(d);
03620 
03621         // step 4
03622         if (ad > 4294967295.0)
03623             ad = MathUtils::mod(ad,4294967296.0); // ad %= 0x10000000
03624 
03625         // step 5
03626         if (ad >= (double)2147483648.0)
03627         {
03628             // This case is a large negative number that overflows back to a positive
03629             // number.  This code has been tweaked to work on both Mac and Windows.  Mac
03630             // is particularly sensitive to edge numbers such as 0x80000000 when converting
03631             // doubles to ints).
03632             if (d < 0.0)
03633             {
03634                 int intVal = MathUtils::real2int (ad - 2147483648.0);
03635                 return 0x80000000 - intVal;
03636             }
03637             // This case is a large positive number overflowing to negative.
03638             else
03639             {
03640                 int intVal = MathUtils::real2int (ad - 2147483648.0);
03641                 return 0x80000000 + intVal;
03642             }
03643         }
03644         else
03645         {
03646             return MathUtils::real2int(d < 0.0 ? -ad : ad);
03647         }
03648     }

Stringp avmplus::AvmCore::doubleToString double  d  ) 
 

Definition at line 3492 of file AvmCore.cpp.

References avmplus::MathUtils::convertDoubleToString(), avmplus::MathUtils::DTOSTR_NORMAL, and MMgc::GCRoot::GetGC().

Referenced by avmplus::NumberClass::numberToString(), and string().

03493     {
03494         // Bug 192033: Number.MAX_VALUE is 1.79e+308; size temp buffer accordingly
03495         wchar buffer[312];
03496         int len;
03497         MathUtils::convertDoubleToString(d, buffer, len, MathUtils::DTOSTR_NORMAL,15);
03498         return new (GetGC()) String(buffer, len);
03499     }

avmplus::AvmCore::DRC Namespacep   )  [private]
 

avmplus::AvmCore::DRC Stringp   )  [private]
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   ) 
 

avmplus::AvmCore::DRC Stringp   )  const
 

avmplus::AvmCore::DRC Namespace  ) 
 

The default namespace, "public", that all identifiers belong to

avmplus::AvmCore::DRC Stringp   ) 
 

Internal table of strings for boolean type ("true", "false")

Referenced by internAlloc(), rehashNamespaces(), and rehashStrings().

Atom avmplus::AvmCore::equals Atom  lhs,
Atom  rhs
 

Implementation of OP_equals

Definition at line 683 of file AvmCore.cpp.

References avmplus::E4XNode::_equals(), avmplus::XMLListObject::_equals(), atomToDouble(), atomToNamespace(), atomToQName(), atomToScriptObject(), atomToString(), atomToXMLList(), atomToXMLObject(), doubleToAtom(), avmplus::Namespace::EqualTo(), avmplus::AtomConstants::falseAtom, avmplus::XMLObject::getClass(), avmplus::QNameObject::getLocalName(), avmplus::XMLObject::getNode(), avmplus::QNameObject::getURI(), avmplus::XMLObject::hasSimpleContent(), isNull(), isNullOrUndefined(), isNumber(), isQName(), isString(), isXML(), isXMLList(), avmplus::E4XNode::kAttribute, avmplus::AtomConstants::kBooleanType, avmplus::E4XNode::kCDATA, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, avmplus::AtomConstants::kStringType, avmplus::E4XNode::kText, number(), string(), and avmplus::AtomConstants::trueAtom.

Referenced by avmplus::XMLListObject::_equals(), and avmplus::XMLListObject::contains().

00684     {
00685         if (isNull(lhs)) lhs = 0;
00686         if (isNull(rhs)) rhs = 0;
00687 
00688         int ltype = (int)(lhs & 7);
00689         int rtype = (int)(rhs & 7);
00690 
00691         // See E4X 11.5.1, pg 53.  
00692         if ((ltype == kObjectType) && (isXMLList(lhs)))
00693             return atomToXMLList (lhs)->_equals (rhs);
00694         else if ((rtype == kObjectType) && (isXMLList(rhs)))
00695             return atomToXMLList (rhs)->_equals (lhs);
00696 
00697         if (ltype == rtype)
00698         {
00699             // same type
00700             switch (ltype)
00701             {
00702             case 0:
00703             case kSpecialType:
00704                 return trueAtom;
00705             case kStringType:
00706                 if (lhs == rhs) return trueAtom;
00707                 return (*atomToString(lhs) == *atomToString(rhs)) ? trueAtom : falseAtom;
00708             case kBooleanType:
00709             case kIntegerType:
00710                 return lhs == rhs ? trueAtom : falseAtom;
00711             case kNamespaceType:
00712                 // E4X 11.5.1, pg 53
00713                 return atomToNamespace(lhs)->EqualTo(atomToNamespace(rhs))? trueAtom : falseAtom;
00714             case kObjectType:
00715             {
00716                 // E4X 11.5.1, pg 53
00717                 if (lhs == rhs)
00718                     return trueAtom;
00719                 if (isXML(lhs) && isXML(rhs))
00720                 {
00721                     XMLObject *x = atomToXMLObject (lhs);
00722                     XMLObject *y = atomToXMLObject (rhs);
00723                     if ((((x->getClass() & (E4XNode::kText | E4XNode::kCDATA | E4XNode::kAttribute))) && y->hasSimpleContent()) ||
00724                         (((y->getClass() & (E4XNode::kText | E4XNode::kCDATA | E4XNode::kAttribute))) && x->hasSimpleContent()))
00725                     {
00726                         return ((*string(lhs) == *string(rhs)) ? trueAtom : falseAtom);
00727                     }   
00728                     else
00729                     {
00730                         return x->getNode()->_equals (this, y->getNode());
00731                     }
00732                 }
00733                 else if (isQName(lhs) && isQName(rhs))
00734                 {
00735                     QNameObject *qn1 = atomToQName (lhs);
00736                     QNameObject *qn2 = atomToQName (rhs);
00737                     return (((qn1->getURI() == qn2->getURI()) && (qn1->getLocalName() == qn2->getLocalName()))? trueAtom : falseAtom);
00738                 }
00739                 else
00740                 {
00741                     return falseAtom;
00742                 }
00743             }
00744             case kDoubleType:
00745                 // C++ portability note -- if either arg is NaN, java == returns false, which matches ECMA.
00746                 return atomToDouble(lhs) == atomToDouble(rhs) ? trueAtom : falseAtom;
00747             }
00748         }
00749         else
00750         {
00751             if (isNullOrUndefined(lhs) && isNullOrUndefined(rhs))
00752                 return trueAtom;
00753             if (ltype == kIntegerType && rtype == kDoubleType)
00754                 return ((double)(lhs>>3)) == atomToDouble(rhs) ? trueAtom : falseAtom;
00755             if (ltype == kDoubleType && rtype == kIntegerType)
00756                 return atomToDouble(lhs) == ((double)(rhs>>3)) ? trueAtom : falseAtom;
00757 
00758             // 16. If Type(x) is Number and Type(y) is String,
00759             // return the result of the comparison x == ToNumber(y).
00760             if (isNumber(lhs) && isString(rhs))
00761                 return equals(lhs, doubleToAtom(number(rhs)));
00762             
00763             // 17. If Type(x) is String and Type(y) is Number,
00764             // return the result of the comparison ToNumber(x) == y.
00765             if (isString(lhs) && isNumber(rhs))
00766                 return equals(doubleToAtom(number(lhs)), rhs);
00767 
00768             // E4X 11.5.1, step 4.  Placed slightly lower then in the spec
00769             // to handle quicker cases earlier.  No cases above should be comparing
00770             // an object to a non-object
00771             if (((ltype == kObjectType) && isXML(lhs) && atomToXMLObject(lhs)->hasSimpleContent()) || 
00772                 ((rtype == kObjectType) && isXML(rhs) && atomToXMLObject(rhs)->hasSimpleContent()))
00773             {
00774                 return ((*string(lhs) == *string(rhs)) ? trueAtom : falseAtom);
00775             }
00776 
00777             // 18. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
00778             if (ltype == kBooleanType)
00779                 return equals(lhs&~7|kIntegerType, rhs);  // equal(toInteger(lhs), rhs)
00780             
00781             // 19. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
00782             if (rtype == kBooleanType)
00783                 return equals(lhs, rhs&~7|kIntegerType);  // equal(lhs, toInteger(rhs))
00784 
00785             // 20. If Type(x) is either String or Number and Type(y) is Object,
00786             // return the result of the comparison x == ToPrimitive(y).
00787 
00788             if ((isString(lhs) || isNumber(lhs)) && rtype == kObjectType)
00789                 return equals(lhs, atomToScriptObject(rhs)->defaultValue());
00790 
00791             // 21. If Type(x) is Object and Type(y) is either String or Number,
00792             // return the result of the comparison ToPrimitive(x) == y.
00793             if ((isString(rhs) || isNumber(rhs)) && ltype == kObjectType)
00794                 return equals(atomToScriptObject(lhs)->defaultValue(), rhs);
00795         }
00796         return falseAtom;
00797     }

Stringp avmplus::AvmCore::EscapeAttributeValue Atom  v  ) 
 

Definition at line 2484 of file AvmCore.cpp.

References avmplus::String::length(), and string().

02485     {
02486         StringBuffer output(this);
02487 
02488         Stringp s = string (v);
02489 
02490         for (int i = 0; i < s->length(); i++)
02491         {
02492             switch ((*s)[i])
02493             {
02494             case '"':
02495                 output << "&quot;";
02496                 break;
02497             case '<':
02498                 output << "&lt;";
02499                 break;
02500             case '&':
02501                 output << "&amp;";
02502                 break;
02503             case 0x000a:
02504                 output << "&#xA;";
02505                 break;
02506             case 0x000d:
02507                 output << "&#xD;";
02508                 break;
02509             case 0x0009:
02510                 output << "&#x9;";
02511                 break;
02512             default:
02513                 output << ((*s)[i]);
02514             }
02515         }
02516 
02517         return newString (output.c_str());
02518     }

Stringp avmplus::AvmCore::EscapeElementValue const Stringp  s,
bool  removeLeadingTrailingWhitespace
 

Definition at line 2433 of file AvmCore.cpp.

References avmplus::String::isSpace(), and avmplus::String::length().

Referenced by ToXMLString().

02434     {
02435         StringBuffer output(this);
02436 
02437         int i = 0;
02438         int last = s->length() - 1;
02439         if (removeLeadingTrailingWhitespace)
02440         {
02441             // finding trailing whitespace
02442             while (last >= 0)
02443             {
02444                 if (!String::isSpace ((*s)[last]))
02445                     break;
02446 
02447                 last--;
02448             }
02449 
02450             if (last < 0)
02451                 return kEmptyString;
02452 
02453             // skip leading whitespace
02454             for (i = 0; i <= last; i++)
02455             {
02456                 if (!String::isSpace ((*s)[i]))
02457                     break;
02458             }
02459         }
02460 
02461         while (i <= last)
02462         {
02463             switch ((*s)[i])
02464             {
02465             case '<':
02466                 output << "&lt;";
02467                 break;
02468             case '>':
02469                 output << "&gt;";
02470                 break;
02471             case '&':
02472                 output << "&amp;";
02473                 break;
02474             default:
02475                 output << ((*s)[i]);
02476             }
02477 
02478             i++;
02479         }
02480 
02481         return newString (output.c_str());
02482     }

void avmplus::AvmCore::exportDefs Traits traits,
ScriptEnv scriptEnv
 

Definition at line 503 of file AvmCore.cpp.

References avmplus::MethodEnv::abcEnv(), avmplus::DomainEnv::addNamedScript(), AvmAssert, console, avmplus::MethodEnv::domainEnv(), avmplus::DomainEnv::getNamedScript(), util::threadpool::i, avmplus::Namespace::isPrivate(), avmplus::MultinameHashtable::keyAt(), avmplus::MultinameHashtable::next(), and avmplus::MultinameHashtable::nsAt().

Referenced by prepareActionPool().

00504     {
00505         DomainEnv* domainEnv = scriptEnv->domainEnv();
00506         AbcEnv* abcEnv = scriptEnv->abcEnv();
00507 
00508         // iterate thru each of the definitions exported by this script
00509         int i=0;
00510         while((i=scriptTraits->next(i)) != 0)
00511         {
00512             // don't need to check for DELETED because we never remove trait bindings
00513             AvmAssert(scriptTraits->keyAt(i) != NULL);
00514             Stringp name = scriptTraits->keyAt(i);
00515             Namespace* ns = scriptTraits->nsAt(i);
00516                 
00517             // not already in the table then export it 
00518             // otherwise we keep the first one that was encountered.
00519             if (!ns->isPrivate())
00520             {               
00521                 if (!domainEnv->getNamedScript(name, ns))
00522                 {
00523                     // add ns/name to global table
00524                     // ISSUE should we filter out Object traits and/or private members?
00525                     #ifdef AVMPLUS_VERBOSE
00526                     if (scriptTraits->pool->verbose)
00527                         console << "exporting " << ns << "::" << name << "\n";
00528                     #endif
00529                     domainEnv->addNamedScript(name, ns, (Binding)scriptEnv);
00530                 }
00531             }
00532             else
00533             {
00534                 if (!abcEnv->privateScriptEnvs.get(name, ns))
00535                 {
00536                     abcEnv->privateScriptEnvs.add(name, ns, (Binding) scriptEnv);
00537                 }
00538             }
00539         }
00540 #ifdef AVMPLUS_WORD_CODE
00541         // Adding scripts to a domain always invalidates the lookup cache.
00542         invalidateLookupCache();
00543 #endif
00544     }

ExceptionHandler * avmplus::AvmCore::findExceptionHandler MethodInfo info,
sintptr  pc,
Exception exception
 

Searches the exception handler table of info for a try/catch block that contains the instruction at pc and matches the type of exception.

Parameters:
info the method to search the exception handler table of
pc the program counter at the point where the exception occurred; either a pointer into bytecode or into native compiled code
exception the exception object that was thrown; used to match the type.
Returns:
ExceptionHandler object for the exception handler that matches, or re-throws the passed-in exception if no handler is found.

Definition at line 1663 of file AvmCore.cpp.

References findExceptionHandlerNoRethrow(), and throwException().

Referenced by beginCatch().

01666     {
01667         ExceptionHandler* handler = findExceptionHandlerNoRethrow(info, pc, exception);
01668         if (handler)
01669             return handler;
01670 
01671         // We don't have a matching exception.
01672         throwException(exception);
01673         return NULL;// not reached
01674     }

ExceptionHandler * avmplus::AvmCore::findExceptionHandlerNoRethrow MethodInfo info,
sintptr  pc,
Exception exception
 

Just like findExceptionHandler(), except that this function returns NULL if it can't find an exception handler, whereas findExceptionHandler() re-throws the passed-in exception if it can't find a handler.

Definition at line 1676 of file AvmCore.cpp.

References avmplus::Exception::atom, AvmAssert, config, console, avmplus::ExceptionHandlerTable::exception_count, avmplus::ExceptionHandlerTable::exceptions, avmplus::MethodInfo::exceptions, avmplus::Exception::EXIT_EXCEPTION, avmplus::Exception::flags, avmplus::ExceptionHandler::from, avmplus::AbstractFunction::impl32, avmplus::AbstractFunction::implN, avmplus::interp32(), avmplus::interpN(), istype(), and avmplus::ExceptionHandler::traits.

Referenced by findExceptionHandler().

01679     {
01680         // If this exception is an EXIT_EXCEPTION, it cannot
01681         // be caught by AS code.  Exit immediately.
01682         if (exception->flags & Exception::EXIT_EXCEPTION)
01683         {
01684             return NULL;
01685         }
01686         
01687         // Search the exception table for a catch clause
01688         // such that pc is between "from" and "to" and
01689         // the thrown atom matches the required type.
01690 
01691         // if no handler found, re-throw the exception from here
01692 
01693         //[ed] we only call this from methods with catch blocks, when exceptions != NULL
01694         AvmAssert(info->exceptions != NULL);
01695 #ifdef AVMPLUS_WORD_CODE
01696         // This is hacky and will go away.  If the target method was not jitted, use
01697         // word_code.exceptions, otherwise use info->exceptions.  methods may or may
01698         // not be JITted based on memory, configuration, or heuristics.
01699 
01700         ExceptionHandlerTable* exceptions;
01701         if (info->impl32 == avmplus::interp32 || info->implN == avmplus::interpN)
01702             exceptions = info->word_code.exceptions;
01703         else
01704             exceptions = info->exceptions;
01705         AvmAssert(exceptions != NULL);
01706 #else
01707         ExceptionHandlerTable* exceptions = info->exceptions;
01708 #endif
01709         
01710         int exception_count = exceptions->exception_count;
01711         ExceptionHandler* handler = exceptions->exceptions;
01712         Atom atom = exception->atom;
01713         
01714         while (--exception_count >= 0) 
01715         {
01716             if (pc >= handler->from &&
01717                 pc <  handler->to)
01718             {
01719                 // verifier makes sure type is valid, resolves to Traits*
01720                 if (istype(atom, handler->traits)) 
01721                 {
01722                     #ifdef AVMPLUS_VERBOSE
01723                     if (config.verbose)
01724                     {
01725                         console << "enter " << info << " catch " << handler->traits << '\n';
01726                     }
01727                     #endif // DEBUGGER
01728 
01729                     return handler;
01730                 }
01731             }
01732             handler++;
01733         }
01734 
01735         // We don't have a matching exception.
01736         return NULL;
01737     }

int avmplus::AvmCore::findNamespace const Namespace ns  )  [private]
 

search the namespace intern table

Definition at line 2733 of file AvmCore.cpp.

References avmplus::Namespace::getURI(), build::dependparser::m, avmplus::Namespace::m_uri, nsCount, numNamespaces, and rehashNamespaces().

Referenced by rehashNamespaces().

02734     {
02735         int m = numNamespaces;
02736         // 80% load factor
02737         if (nsCount*5 >= 4*m) {
02738             rehashNamespaces(m = m << 1);
02739         }
02740 
02741         // compute the hash function
02742         int hashCode = (int)(((uintptr)ns->getURI())>>3);
02743 
02744         int bitMask = m - 1;
02745 
02746         // find the slot to use
02747         int i = (hashCode&0x7FFFFFFF) & bitMask;
02748         int n = 7;
02749         Namespace* k;
02750         while ((k=namespaces[i]) != NULL && k->m_uri != ns->m_uri ) {
02751             i = (i + (n++)) & bitMask; // quadratic probe
02752         }
02753         return i;
02754     }

int avmplus::AvmCore::findString const wchar s,
int  len
[private]
 

search the string intern table

Definition at line 2676 of file AvmCore.cpp.

References deletedCount, avmplus::String::FastEquals(), avmplus::hashString(), build::dependparser::m, numStrings, rehashStrings(), and stringCount.

Referenced by internAlloc(), internAllocUtf8(), and internString().

02677     {
02678         int m = numStrings;
02679         // 80% load factor
02680         if (5*(stringCount+deletedCount+1) > 4*m) {
02681             if (2*stringCount > m) // 50%
02682                 rehashStrings(m = m << 1);
02683             else
02684                 rehashStrings(m);
02685         }
02686 
02687         // compute the hash function
02688         int hashCode = hashString(s, len);
02689 
02690         int bitMask = m - 1;
02691 
02692         // find the slot to use
02693         int i = (hashCode&0x7FFFFFFF) & bitMask;
02694         int n = 7;
02695         Stringp k;
02696         if (!deletedCount)
02697         {
02698             while ((k=strings[i]) != NULL && !k->FastEquals(s,len)) {
02699                 i = (i + (n++)) & bitMask; // quadratic probe
02700             }
02701         }
02702         else
02703         {
02704             int iFirstDeletedSlot = -1;
02705             while ((k=strings[i]) != NULL)
02706             {
02707                 if (k == AVMPLUS_STRING_DELETED)
02708                 {
02709                     if (iFirstDeletedSlot == -1)
02710                     {
02711                         iFirstDeletedSlot = i;
02712                     }
02713                 }
02714                 else if (k->FastEquals (s, len))
02715                 {
02716                     return i;
02717                 }
02718                 i = (i + (n++)) & bitMask; // quadratic probe
02719             }
02720 
02721             if ((k == NULL) && (iFirstDeletedSlot != -1))
02722                 return iFirstDeletedSlot;
02723 
02724         }
02725         return i;
02726     }

String * avmplus::AvmCore::formatErrorMessageV int  errorID,
Stringp  arg1 = 0,
Stringp  arg2 = 0,
Stringp  arg3 = 0
 

formatErrorMessageV is a convenience function for assembling an error message with varags.

Definition at line 1215 of file AvmCore.cpp.

References AvmAssertMsg, buffer, avmplus::UTF8String::c_str(), getErrorMessage(), newString(), and avmplus::String::toUTF8String().

Referenced by throwErrorV().

01216     {
01217         Stringp out = NULL;
01218 
01219         Stringp errorMessage = getErrorMessage(errorID);
01220         if (errorMessage)
01221         {
01222             #ifdef DEBUGGER
01223             UTF8String *errorUTF8 = errorMessage->toUTF8String();       
01224             const char *format = errorUTF8->c_str();
01225             
01226             // This block is enclosed in {} to force
01227             // StringBuffer destructor to unwind.
01228             {
01229                 StringBuffer buffer(this);
01230                 buffer.formatP( format, arg1, arg2, arg3);
01231                 out = newString(buffer.c_str());
01232             }
01233             #else   
01234 
01238             (void)arg1; 
01239             (void)arg2; 
01240             (void)arg3; 
01241             out = errorMessage;
01242             #endif /* DEBUGGER*/
01243         }
01244         else
01245         {
01246             AvmAssertMsg(errorMessage != NULL, "contract with getErrorMessage() broken, we should always get a string!");
01247             out = kEmptyString;
01248         }
01249         return out;
01250     }

Atom avmplus::AvmCore::gcObjectToAtom const void *  obj  )  [static]
 

Definition at line 3991 of file AvmCore.cpp.

References AvmAssert, gc, MMgc::GC::GetGC(), MMgc::GC::IsRCObject(), and avmplus::AtomConstants::kDoubleType.

Referenced by avmplus::ElementE4XNode::_append(), avmplus::WeakValueHashtable::add(), avmplus::ElementE4XNode::addAttribute(), avmplus::ElementE4XNode::convertToAtomArray(), avmplus::MethodClosureClass::create(), avmplus::WeakKeyHashtable::getKey(), avmplus::ElementE4XNode::insertChild(), and avmplus::ElementE4XNode::setChildAt().

03992     {
03993 #ifdef _DEBUG
03994         // We get a null obj here through ElementE4XNode::_insert
03995         if (obj)
03996         {
03997             GC* gc = GC::GetGC(obj);
03998             AvmAssert(!gc->IsRCObject(obj));
03999         }
04000 #endif      
04001         // return a non-RC atom, makes atomWriteBarrier do the right thing
04002         return (Atom)obj|kDoubleType;
04003     }

String * avmplus::AvmCore::getErrorMessage int  errorID  )  [virtual]
 

getErrorMessage returns the format string for an errorID. Override to provide format strings for additional implementation-dependent error strings.

Definition at line 1053 of file AvmCore.cpp.

References AvmAssertMsg, buffer, concatStrings(), internInt(), and newString().

Referenced by formatErrorMessageV(), avmplus::ErrorClass::getErrorMessage(), and avmplus::NativeID::shell_toplevel_a2a_oii_opti2_thunkc().

01054     {
01055         Stringp buffer = newString("Error #");
01056         buffer = concatStrings(buffer, internInt(errorID));
01057 
01058         #ifdef DEBUGGER
01059         Stringp out = findErrorMessage(errorID,
01060                                        errorMappingTable,
01061                                        errorConstants[determineLanguage()],
01062                                        kNumErrorConstants);
01063         if (out) 
01064         {
01065             buffer = concatStrings(buffer, newString(": "));
01066             buffer = concatStrings(buffer, out);
01067         }
01068         else
01069         {
01070             AvmAssertMsg(0, "errorID not found in the message table; check ErrorConstants.cpp you may need to regenerate it");
01071         }
01072         #endif
01073 
01074         return buffer;
01075     }

bool avmplus::AvmCore::getIndexFromAtom Atom  a,
uint32 result
const [inline]
 

Definition at line 1295 of file AvmCore.h.

References atomToString(), AvmAssert, getIndexFromString(), isInteger(), and isString().

Referenced by avmplus::ArrayObject::checkForSparseToDenseConversion(), avmplus::ArrayObject::getAtomProperty(), avmshell::ByteArrayObject::getAtomProperty(), axtam::ByteArrayObject::getAtomProperty(), avmplus::VectorBaseObject::getVectorIndex(), avmplus::ArrayObject::setAtomProperty(), avmshell::ByteArrayObject::setAtomProperty(), and axtam::ByteArrayObject::setAtomProperty().

01296         {
01297             if (AvmCore::isInteger(a))
01298             {
01299                 *result = uint32(a >> 3);
01300                 return true;
01301             }
01302             else
01303             {
01304                 AvmAssert (AvmCore::isString(a));
01305                 return AvmCore::getIndexFromString (atomToString (a), result); 
01306             }
01307         }

bool avmplus::AvmCore::getIndexFromString Stringp  s,
uint32 result
[static]
 

Definition at line 3827 of file AvmCore.cpp.

References avmplus::String::c_str(), avmplus::String::Compare(), avmplus::String::length(), and runtests::res.

Referenced by avmplus::XMLObject::child(), avmplus::XMLObject::deleteMultinameProperty(), avmplus::XMLListObject::deleteMultinameProperty(), avmplus::String::generateIntegerEquivalent(), getIndexFromAtom(), avmplus::XMLObject::getMultinameProperty(), avmplus::XMLListObject::getMultinameProperty(), avmplus::XMLObject::hasMultinameProperty(), avmplus::XMLListObject::hasMultinameProperty(), avmplus::XMLObject::setMultinameProperty(), and avmplus::XMLListObject::setMultinameProperty().

03828     {
03829         int len = s->length();
03830         if (!len)
03831             return false;
03832 
03833         // Don't support 000000 as 0.
03834         // We don't support 0x1234 as 1234 in hex since string(1234) doesn't equal '0x1234')
03835         // No leading zeros are supported
03836 
03837         // Single 0 is ok
03838         const wchar *c = s->c_str();
03839         if (*c == '0')
03840         {
03841             if (len == 1)
03842             {
03843                 *result = 0;
03844                 return true;
03845             }
03846             else
03847             {
03848                 return false;
03849             }
03850         }
03851         else if ((*c < '0') || (*c > '9'))
03852         {
03853             return false;
03854         }
03855 
03856         // A string that is more than 10 digits (and does not start with 0) 
03857         // will always be greater than 2^32-1 (4294967295) or not a numeric string
03858         if (len > 10)
03859         {
03860             return false;
03861         }
03862 
03863         uint32 res = 0;
03864         int i = 0;
03865         while (i < len)
03866         {
03867             wchar ch = c[i];
03868             if (ch < '0' || ch > '9')
03869                 return false;
03870 
03871             res = res * 10 + (ch - '0');
03872             i++;
03873         }
03874 
03875         *result = res;
03876         // Our input string length is less then 10 digits so we now
03877         // our output is in the valid range up to 999,999,999.
03878         if (len < 10)
03879         {
03880             return true;
03881         }
03882 
03883         // At this point we know our string is 10 characters long and is all numeric 
03884         // characters.  We need to check it to see if it overflows 2^32 and whether it equals
03885         // 2^32-1.  This string comparison works as a numeric comparison since we know our input
03886         // string is also ten numeric digits.
03887 
03888         int comp = String::Compare (c, "4294967295", 10);
03889         return (comp > 0);
03890     }

size_t avmplus::AvmCore::getToplevelSize  )  const [virtual]
 

Reimplemented in avmshell::Shell.

Definition at line 2598 of file AvmCore.cpp.

Referenced by prepareActionPool().

02599     {
02600         return sizeof(Toplevel);
02601     }

Atom avmplus::AvmCore::handleActionBlock ScriptBuffer  code,
int  start,
DomainEnv domainEnv,
Toplevel *&  toplevel,
AbstractFunction nativeMethods[],
NativeClassInfop  nativeClasses[],
NativeScriptInfop  nativeScripts[],
CodeContext codeContext
 

Execute the ABC block starting at offset start in code.

Parameters:
code buffer holding the ABC block to execute
start zero-indexed offset, in bytes, into the buffer where the code begins
toplevel the Toplevel object to execute against, or NULL if a Toplevel should be created.
nativeMethods the NATIVE_METHOD table
nativeClasses the NATIVE_CLASS table
nativeScripts the NATIVE_SCRIPT table
Exceptions:
Exception If an error occurs, an Exception object will be thrown using the AVM+ exceptions mechanism. Calls to handleActionBlock should be bracketed in TRY/CATCH.

Definition at line 574 of file AvmCore.cpp.

References builtinDomain, codeContext(), avmplus::Hashtable::get(), avmplus::DomainEnv::getDomain(), MMgc::GCRoot::GetGC(), handleActionPool(), parseActionBlock(), avmplus::Hashtable::put(), resources, toplevel, and avmplus::AtomConstants::undefinedAtom.

Referenced by avmshell::DomainObject::loadBytes(), and axtam::DomainObject::loadBytes().

00582     {
00583         resources = new (GetGC()) Hashtable(GetGC());
00584 
00585         // have we parsed this before?
00586         PoolObject* pool;
00587         Atom resourceAtom = resources->get(start+1);
00588         if (resourceAtom != undefinedAtom) 
00589         {
00590             pool = (PoolObject*) resourceAtom;
00591         } 
00592         else 
00593         {
00594             Domain* domain = domainEnv ? domainEnv->getDomain() : builtinDomain;
00595             
00596             // parse constants and attributes.
00597             pool = parseActionBlock(code,
00598                                     start,
00599                                     toplevel,
00600                                     domain,
00601                                     nativeMethods,
00602                                     nativeClasses,
00603                                     nativeScripts);
00604             if (pool != NULL)
00605             {
00606                 resources->put(start+1, pool);
00607             }
00608         }
00609 
00610         return handleActionPool(pool, domainEnv, toplevel, codeContext);
00611     }

Atom avmplus::AvmCore::handleActionPool PoolObject pool,
DomainEnv domainEnv,
Toplevel *&  toplevel,
CodeContext codeContext
 

Execute an ABC file that has been parsed into a PoolObject.

Parameters:
pool PoolObject containing the ABC file to execute
domainEnv The DomainEnv object to execute against, or NULL if a new DomainEnv should be created
toplevel the Toplevel object to execute against, or NULL if a Toplevel should be created.
Exceptions:
Exception If an error occurs, an Exception object will be thrown using the AVM+ exceptions mechanism. Calls to handleActionBlock should be bracketed in TRY/CATCH.

Definition at line 469 of file AvmCore.cpp.

References CATCH, codeContext(), END_CATCH, END_TRY, truntests::main, prepareActionPool(), throwException(), toplevel, and TRY.

Referenced by handleActionBlock(), and initTopLevel().

00473     {
00474         bool createdToplevel = (toplevel == NULL);
00475 
00476         ScriptEnv* main = prepareActionPool(pool, domainEnv, toplevel, codeContext);
00477 
00478         if (!createdToplevel)
00479         {
00480             main->initGlobal();
00481         }
00482         
00483         Atom result = 0; // init to zero to make GCC happy
00484         #ifndef DEBUGGER
00485         result = main->coerceEnter(main->global->atom());
00486         #else
00487         TRY(this, kCatchAction_Rethrow)
00488         {
00489             result = main->coerceEnter(main->global->atom());
00490         }
00491         CATCH(Exception *exception)
00492         {
00493             // Re-throw exception
00494             throwException(exception);
00495         }
00496         END_CATCH
00497         END_TRY
00498         #endif
00499 
00500         return result;
00501     }

static bool avmplus::AvmCore::hasGetterBinding Binding  b  )  [inline, static]
 

Definition at line 460 of file AvmCore.h.

References avmplus::AtomConstants::BIND_GET.

Referenced by bindingToGetterId(), avmplus::Verifier::emitGetProperty(), and avmplus::Traits::getOverride().

00461         {
00462             return (b&5) == BIND_GET;
00463         }

static bool avmplus::AvmCore::hasSetterBinding Binding  b  )  [inline, static]
 

Definition at line 455 of file AvmCore.h.

References avmplus::AtomConstants::BIND_SET.

Referenced by bindingToSetterId(), and avmplus::Traits::getOverride().

00456         {
00457             return (b&6) == BIND_SET;
00458         }

void avmplus::AvmCore::increment_d Atom atom,
int  delta
 

implementation of OP_increg, decreg, increment, decrement which correspond to ++ and -- operators in AS.

Definition at line 1739 of file AvmCore.cpp.

References atomToDouble(), AvmAssert, doubleToAtom(), intToAtom(), isInteger(), and isNumber().

01740     {
01741         AvmAssert(isNumber(*ap));
01742         if (isInteger(*ap))
01743             *ap = intToAtom(delta+((sint32)((sintptr)*ap>>3)));
01744         else
01745             *ap = doubleToAtom(atomToDouble(*ap)+delta);
01746     }

void avmplus::AvmCore::increment_i Atom atom,
int  delta
 

implementation of OP_increg, decreg, increment, decrement which correspond to ++ and -- operators in AS.

Definition at line 1748 of file AvmCore.cpp.

References atomToDouble(), integer(), intToAtom(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, and avmplus::AtomConstants::kIntegerType.

01749     {
01750         switch (*ap & 7)
01751         {
01752         case kBooleanType:
01753         case kIntegerType:
01754             *ap = intToAtom(delta+(sint32((sintptr)*ap>>3)));
01755             return;
01756         case kDoubleType:
01757             *ap = intToAtom((int)((sint32)atomToDouble(*ap)+delta));
01758             return;
01759         default:
01760             *ap = intToAtom(integer(*ap)+delta);
01761             return;
01762         }
01763     }

void avmplus::AvmCore::initBuiltinPool  ) 
 

Parses builtin.abc into a PoolObject, to be executed later for each new Toplevel

Definition at line 332 of file AvmCore.cpp.

References avmplus::NativeID::builtin_abc_class_count, avmplus::NativeID::builtin_abc_data, avmplus::NativeID::builtin_abc_length, avmplus::NativeID::builtin_abc_method_count, avmplus::NativeID::builtin_abc_script_count, builtinDomain, builtinPool, avmplus::PoolObject::cinits, MMgc::GCRoot::GetGC(), util::threadpool::i, initNativeTables(), avmplus::PoolObject::methods, avmplus::AbstractFunction::NON_INTERRUPTABLE, parseActionBlock(), avmplus::PoolObject::scripts, avmplus::List< T, kElementType >::size(), and MMgc::GCRoot::size.

00333     {
00334         using namespace NativeID;
00335 
00336         // stack allocated array of pointers
00337         AbstractFunction* nativeMethods[builtin_abc_method_count];
00338         NativeClassInfop nativeClasses[builtin_abc_class_count];
00339         NativeScriptInfop nativeScripts[builtin_abc_script_count];
00340 
00341         memset(nativeMethods, 0, sizeof(AbstractFunction*)*builtin_abc_method_count);
00342         memset(nativeClasses, 0, sizeof(NativeClassInfop)*builtin_abc_class_count);
00343         memset(nativeScripts, 0, sizeof(NativeScriptInfop)*builtin_abc_script_count);
00344 
00345         initNativeTables(classEntries, scriptEntries,
00346             nativeMethods, nativeClasses, nativeScripts);
00347 
00348         ScriptBuffer code = ScriptBuffer(new (GetGC()) ReadOnlyScriptBufferImpl (builtin_abc_data, builtin_abc_length));
00349 
00350         builtinDomain = new (GetGC()) Domain(this, NULL);
00351         
00352         builtinPool = parseActionBlock(code, 0, NULL,
00353                                        builtinDomain,
00354                                        nativeMethods,
00355                                        nativeClasses,
00356                                        nativeScripts);
00357 
00358         // whack the the non-interruptable bit on all builtin functions
00359         for(int i=0, size=builtinPool->methods.size(); i<size; i++)
00360             builtinPool->methods[i]->flags |= AbstractFunction::NON_INTERRUPTABLE;
00361 
00362         for(int i=0, size=builtinPool->cinits.size(); i<size; i++)
00363             builtinPool->cinits[i]->flags |= AbstractFunction::NON_INTERRUPTABLE;
00364 
00365         for(int i=0, size=builtinPool->scripts.size(); i<size; i++)
00366             builtinPool->scripts[i]->flags |= AbstractFunction::NON_INTERRUPTABLE;
00367 
00368 #ifdef FEATURE_SAMPLER
00369         // sampling can begin now, requires builtinPool
00370         _sampler.initSampling();
00371 #endif
00372     }

void avmplus::AvmCore::initNativeTables NativeClassInfop  classEntries,
NativeScriptInfop  scriptEntries,
AbstractFunction nativeMethods[],
NativeClassInfop  nativeClasses[],
NativeScriptInfop  nativeScripts[]
 

Initializes the native table with the specified class/script entries.

Definition at line 1906 of file AvmCore.cpp.

References avmplus::NativeClassInfo::class_id, avmplus::NativeScriptInfo::nativeMap, avmplus::NativeClassInfo::nativeMap, registerNatives(), and avmplus::NativeScriptInfo::script_id.

Referenced by initBuiltinPool().

01911     {
01912         while (classEntry->class_id != -1)
01913         {
01914             nativeClasses[classEntry->class_id] = classEntry;
01915             registerNatives(classEntry->nativeMap, nativeMethods);
01916             classEntry++;
01917         }
01918 
01919         while (scriptEntry->script_id != -1)
01920         {
01921             nativeScripts[scriptEntry->script_id] = scriptEntry;
01922             registerNatives(scriptEntry->nativeMap, nativeMethods);
01923             scriptEntry++;
01924         }
01925     }

Toplevel * avmplus::AvmCore::initTopLevel  ) 
 

Initializes the specified Toplevel object by running builtin.abc

Definition at line 374 of file AvmCore.cpp.

References builtinPool, handleActionPool(), and toplevel.

Referenced by avmshell::Shell::initShellBuiltins().

00375     {
00376         Toplevel* toplevel = NULL;
00377         handleActionPool(builtinPool, NULL, toplevel, NULL);
00378         return toplevel;
00379     }

Atom avmplus::AvmCore::intAtom Atom  atom  )  [inline]
 

intAtom is similar to the integer method, but returns an atom instead of a C++ int.

Definition at line 736 of file AvmCore.h.

References integer(), and intToAtom().

Referenced by avmplus::Toplevel::coerce(), and avmplus::IntClass::construct().

00737         {
00738             return intToAtom(integer(atom));
00739         }

int avmplus::AvmCore::integer Atom  atom  )  const
 

Converts the passed atom to a 32-bit signed integer. If the atom is already an integer, it is simply decoded. Otherwise, it is coerced to the int type and returned. This is ToInt32() from E3 section 9.5

Definition at line 3533 of file AvmCore.cpp.

References integer_d(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kIntegerType, and number().

Referenced by avmplus::StringClass::fromCharCode(), increment_i(), intAtom(), avmshell::ByteArrayObject::setAtomProperty(), axtam::ByteArrayObject::setAtomProperty(), avmplus::ArrayClass::sort(), avmplus::ArrayClass::sortOn(), toUInt32(), and avmplus::MethodEnv::unbox1().

03534     {
03535         if ((atom & 7) == kIntegerType || (atom&7) == kBooleanType) {
03536             return (int32_t)(atom >> 3);
03537         } else {
03538             // TODO optimize the code below.
03539             double d = number(atom);
03540             return (int32_t)integer_d(d);
03541         }
03542     }

int avmplus::AvmCore::integer_d double  d  )  [static]
 

Definition at line 3547 of file AvmCore.cpp.

References doubleToInt32(), and avmplus::MathUtils::real2int().

Referenced by integer(), and avmplus::ArrayClass::splice().

03548     {
03549         // Try a simple case first to see if we have a in-range float value
03550 
03551 #ifdef WIN32 // should be any intel build
03552         // WIN32's real2int returns 0x80000000 if d is not in a valid integer range
03553         int id = MathUtils::real2int (d);
03554         if (id != 0x80000000) 
03555             return id;
03556 #elif AVMPLUS_SPARC
03557         int id = MathUtils::real2int (d);
03558         if (id != 0x7fffffff && id != 0x80000000)
03559             return id;
03560 #endif
03561 
03562         return doubleToInt32(d);
03563     }

static int avmplus::AvmCore::integer_i Atom  a  )  [inline, static]
 

Definition at line 678 of file AvmCore.h.

References atomToDouble(), avmplus::AtomConstants::kIntegerType, and avmplus::MathUtils::real2int().

Referenced by avmplus::interp32(), and avmplus::ScriptObject::setSlotAtom().

00679         {
00680             if ((a&7) == kIntegerType)
00681                 return int(a>>3);
00682             else
00683                 // TODO since we know value is legal int, use faster d->i
00684                 return MathUtils::real2int(atomToDouble(a));
00685         }

static uint32 avmplus::AvmCore::integer_u Atom  a  )  [inline, static]
 

Definition at line 688 of file AvmCore.h.

References atomToDouble(), and avmplus::AtomConstants::kIntegerType.

Referenced by avmplus::interp32(), and avmplus::ScriptObject::setSlotAtom().

00689         {
00690             if ((a&7) == kIntegerType)
00691             {
00692                 return uint32(a>>3);
00693             }
00694             else
00695             {
00696                 // TODO figure out real2int for unsigned
00697                 return (uint32) atomToDouble(a);
00698             }
00699         }

Stringp avmplus::AvmCore::intern Atom  atom  ) 
 

an interned atom is canonicalized in this way: boolean -> "true" or "false" number -> intern'ed string value string -> intern'ed string value object -> intern'ed result of toString()

this way, interned atoms are suitable to be used as map keys and can be compared using ==.

Parameters:
atom 
Returns:

Definition at line 1410 of file AvmCore.cpp.

References atomToDouble(), atomToNamespace(), atomToScriptObject(), avmplus::Namespace::getURI(), internDouble(), internInt(), internString(), isNull(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, and avmplus::AtomConstants::kStringType.

Referenced by avmplus::VectorClass::applyTypeArgs(), avmplus::MethodEnv::in(), avmplus::XMLObject::setLocalName(), and avmplus::XMLObject::xmlPropertyIsEnumerable().

01411     {
01412         if (!isNull(atom))
01413         {
01414             switch (atom&7)
01415             {
01416             case kBooleanType:
01417                 return booleanStrings[atom>>3];
01418             case kStringType:
01419                 return internString(atom);
01420             case kNamespaceType:
01421                 return atomToNamespace(atom)->getURI();
01422             case kSpecialType:
01423                 return kundefined;
01424             case kObjectType:
01425                 return intern(atomToScriptObject(atom)->toString());
01426             case kIntegerType:
01427                 return internInt((int)(atom>>3));
01428             case kDoubleType:
01429             default: // number
01430                 return internDouble(atomToDouble(atom));
01431             }
01432         }
01433         else
01434         {
01435             return knull;
01436         }
01437     }

Stringp avmplus::AvmCore::internAlloc const wchar s,
int  len
 

intern the given string and allocate it on the heap if necessary

Parameters:
s 
Returns:

Definition at line 2958 of file AvmCore.cpp.

References AvmAssert, AVMPLUS_STRING_DELETED, deletedCount, DRC(), findString(), MMgc::GCRoot::GetGC(), avmplus::String::setInterned(), and stringCount.

Referenced by avmplus::ElementE4XNode::CopyAttributesAndNamespaces(), avmplus::E4XNode::FindNamespace(), internDouble(), internInt(), and avmplus::XMLObject::XMLObject().

02959     {
02960         int i = findString(s, len);
02961         Stringp other;
02962         if ((other=strings[i]) <= AVMPLUS_STRING_DELETED)
02963         {
02964             if (other == AVMPLUS_STRING_DELETED)
02965             {
02966                 deletedCount--;
02967                 AvmAssert(deletedCount >= 0);
02968             }
02969             
02970 #ifdef DEBUGGER         
02971             DRC(Stringp) *oldStrings = strings;
02972 #endif
02973 
02974             other = new (GetGC()) String(s,len);
02975             
02976 #ifdef DEBUGGER
02977             // re-find if String ctor caused rehash
02978             if(strings != oldStrings)
02979                 i = findString(s, len);
02980 #endif
02981             strings[i] = other;
02982             stringCount++;
02983             other->setInterned(this);
02984         }
02985         return other;
02986     }

Stringp avmplus::AvmCore::internAllocUtf8 const byte s,
int  len
 

Definition at line 2916 of file AvmCore.cpp.

References AvmAssert, AVMPLUS_STRING_DELETED, avmplus::String::c_str(), deletedCount, findString(), MMgc::GCRoot::GetGC(), avmplus::String::setInterned(), stringCount, avmplus::UnicodeUtils::Utf8Count(), and avmplus::UnicodeUtils::Utf8ToUtf16().

02917     {
02918         int len16 = UnicodeUtils::Utf8Count((const uint8*)cs, len8);
02919         // use alloca to avoid heap allocations where possible
02920         wchar *buffer = 0;
02921         if (len16 < 1024)
02922             buffer = (wchar*) alloca((len16+1)*sizeof(wchar));
02923         
02924         Stringp s = NULL;
02925         if(!buffer) {
02926             s = new (GetGC()) String((const char *)cs, len8, len16);
02927             buffer = (wchar*)s->c_str();
02928         } else {
02929             UnicodeUtils::Utf8ToUtf16((const uint8 *)cs, len8, buffer, len16);
02930             buffer[len16] = 0;
02931         }
02932 
02933         int i = findString(buffer, len16);
02934         Stringp other;
02935         if ((other=strings[i]) <= AVMPLUS_STRING_DELETED)
02936         {
02937             if (other == AVMPLUS_STRING_DELETED)
02938             {
02939                 deletedCount--;
02940                 AvmAssert(deletedCount >= 0);
02941             }
02942 
02943             stringCount++;
02944             if(!s)
02945                 s = new (GetGC()) String(buffer, len16);
02946             strings[i] = s;
02947             s->setInterned(this);
02948             return s;
02949         }
02950         else
02951         {
02952             // we know the internal buf has not yet been aliased, so it's safe to explicitly free here.
02953             delete s;
02954             return other;
02955         }
02956     }

Stringp avmplus::AvmCore::internDouble double  d  ) 
 

Definition at line 2883 of file AvmCore.cpp.

References avmplus::MathUtils::convertDoubleToString(), and internAlloc().

Referenced by intern(), and internUint32().

02884     {
02885         // Bug 192033: Number.MAX_VALUE is 1.79e+308; size temp buffer accordingly
02886         wchar buffer[312];
02887         int len;
02888         MathUtils::convertDoubleToString(d, buffer, len);
02889         return internAlloc(buffer, len);
02890     }

Stringp avmplus::AvmCore::internInt int  n  ) 
 

Definition at line 2798 of file AvmCore.cpp.

References avmplus::MathUtils::convertIntegerToString(), MMgc::GCRoot::GetGC(), internAlloc(), and avmplus::UnicodeUtils::Utf8ToUtf16().

Referenced by getErrorMessage(), avmplus::MethodEnv::getpropertylate_i(), intern(), internUint32(), avmplus::XMLObject::nextName(), avmplus::XMLListObject::nextName(), and avmplus::MethodEnv::setpropertylate_i().

02799     {
02800 #ifdef AVMPLUS_INTERNINT_CACHE
02801         // This simple cache of interned strings representing integers greatly benefits
02802         // array-heavy code in the interpreter, at least for the time being (2008-08-13).
02803         // But it would be better not to intern integers at all.
02804         //
02805         // #ifdeffed out on 2008-09-15 because the integer lookup optimizations in the
02806         // interpreter ought to make it unnecessary; code should be removed later if it
02807         // is not re-enabled.
02808         
02809         int index = value & 255;
02810         if (value >= 0 && index_strings[index] != NULL && index_strings[index]->value == value)
02811             return index_strings[index]->string;
02812 #endif  
02813         wchar buffer[65];
02814         int len;
02815         MathUtils::convertIntegerToString(value, buffer, len);
02816         Stringp s = internAlloc(buffer, len);
02817 
02818 #ifdef AVMPLUS_INTERNINT_CACHE
02819         if (value >= 0) {
02820             if (index_strings[index] == NULL)
02821                 index_strings[index] = new (GetGC()) IndexString;
02822             index_strings[index]->value = value;
02823             index_strings[index]->string = s;
02824         }
02825 #endif
02826 
02827         return s;
02828 
02829         // This optimized routine below works fine and is faster than calling
02830         // convertIntegerToString but with our support of integer keys in our
02831         // HashTables, this routine is no longer on a critical path.  Save some
02832         // code by leaving it disabled unless we can show a performance gain by
02833         // using it.
02834 #if 0
02835         // optimized case of MathUtils;:convertIntegerToString
02836 
02837         if ((uint32)value == 0x80000000) // MathUtils::convertIntegerToString doesn't deal with this number because you can't negate it.
02838         {
02839             UnicodeUtils::Utf8ToUtf16((uint8*)"-2147483648", 12, buffer, 24);
02840             return internAlloc(buffer, 11);
02841         }
02842 
02843         wchar *src = &buffer[39];
02844         *src-- = '\0';
02845 
02846         if (value == 0)
02847         {
02848             *src-- = '0';
02849         }
02850         else
02851         {
02852             uint32 uVal;
02853             bool negative = (value < 0);
02854             if (negative)
02855                 value = -value;
02856 
02857             uVal = (uint32)value;
02858 
02859             while (uVal != 0)
02860             {
02861                 uint32 j = uVal;
02862                 uVal = uVal / 10;
02863                 j -= (uVal * 10);
02864 
02865                 *src-- = (j + '0');
02866             }
02867 
02868             if (negative)
02869                 *src-- = '-';
02870         }
02871 
02872         return internAlloc(src + 1, &buffer[39] - src - 1);
02873 #endif
02874     }

Namespace * avmplus::AvmCore::internNamespace Namespace ns  ) 
 

Definition at line 1439 of file AvmCore.cpp.

References avmplus::Namespace::isPrivate().

Referenced by avmplus::MethodEnv::internRtns(), and avmplus::XMLObject::XMLObject().

01440     {
01441         if (ns->isPrivate())
01442         {
01443             // only intern namespaces with interned uri's.  this means anonymous
01444             // namespaces with null prefixes are always unique and can't be shared.
01445             return ns;
01446         }
01447 
01448         int i = findNamespace(ns);
01449         if (namespaces[i] == NULL)
01450         {
01451             // first time we've seen this namespace.  intern int
01452             nsCount++;
01453             namespaces[i] = ns;
01454             return ns;
01455         }
01456 
01457         // found the namespace, indexing by URI. return the interned copy.
01458         return namespaces[i];
01459     }

Stringp avmplus::AvmCore::internString Atom  atom  ) 
 

Definition at line 2791 of file AvmCore.cpp.

References atomToString(), AvmAssert, internString(), avmplus::String::isInterned(), and isString().

02792     {
02793         AvmAssert(isString(atom));
02794         Stringp s = atomToString(atom);
02795         return s->isInterned() ? s : internString(s);
02796     }

Stringp avmplus::AvmCore::internString Stringp  s  ) 
 

intern the given string atom which has already been allocated

Parameters:
atom 
Returns:

Definition at line 2766 of file AvmCore.cpp.

References AvmAssert, AVMPLUS_STRING_DELETED, deletedCount, findString(), configure::o, and stringCount.

Referenced by avmplus::VectorClass::applyTypeArgs(), constantString(), axtam::AXTam::constantString(), avmplus::Verifier::findMathFunction(), avmplus::Verifier::findStringFunction(), avmplus::XMLObject::getNamespace(), avmplus::getTraits(), intern(), internString(), avmplus::AbstractFunction::makeIntoPrototypeFunction(), newNamespace(), avmplus::ObjectClass::objectHasOwnProperty(), avmplus::ObjectClass::objectPropertyIsEnumerable(), avmplus::ObjectClass::objectSetPropertyIsEnumerable(), avmplus::MethodEnv::op_newobject(), avmplus::AbcParser::parseClassInfos(), avmplus::PoolObject::resolveParameterizedType(), avmplus::ArrayClass::sortOn(), avmplus::XMLClass::XMLClass(), avmplus::XMLObject::XMLObject(), and avmplus::XMLObject::xmlPropertyIsEnumerable().

02767     {
02768         if (o->isInterned())
02769             return o;
02770 
02771         int i = findString(o->c_str(), o->length());
02772         Stringp other;
02773         if ((other=strings[i]) <= AVMPLUS_STRING_DELETED)
02774         {
02775             if (other == AVMPLUS_STRING_DELETED)
02776             {
02777                 deletedCount--;
02778                 AvmAssert(deletedCount >= 0);
02779             }
02780             stringCount++;
02781             strings[i] = o;
02782             o->setInterned(this);
02783             return o;
02784         }
02785         else
02786         {
02787             return other;
02788         }
02789     }

Stringp avmplus::AvmCore::internUint32 uint32  ui  ) 
 

Definition at line 2875 of file AvmCore.cpp.

References internDouble(), and internInt().

Referenced by avmplus::ScriptObject::delUintProperty(), avmplus::MethodEnv::getpropertylate_u(), avmplus::ScriptObject::getUintProperty(), avmplus::ScriptObject::hasUintProperty(), and avmplus::ScriptObject::setUintProperty().

02876     { 
02877         if (ui & 0x80000000)
02878             return internDouble(ui);
02879         else
02880             return internInt((int)ui);  
02881     } 

virtual void avmplus::AvmCore::interrupt MethodEnv env  )  [pure virtual]
 

The interrupt method is called from executing code when the interrupted flag is set.

Implemented in axtam::AXTam, and avmshell::Shell.

Referenced by branchCheck(), and avmplus::MethodEnv::interrupt().

Atom avmplus::AvmCore::intToAtom int  n  ) 
 

Definition at line 3191 of file AvmCore.cpp.

References allocDouble(), and avmplus::AtomConstants::kIntegerType.

Referenced by avmplus::AbstractFunction::boxArgs(), avmplus::MethodEnv::endCoerce(), avmplus::ArrayObject::getAtomProperty(), avmshell::ByteArrayObject::getAtomProperty(), axtam::ByteArrayObject::getAtomProperty(), avmplus::ScriptObject::getSlotAtom(), increment_d(), increment_i(), intAtom(), avmplus::VectorBaseObject::nextName(), avmplus::ArrayObject::nextName(), avmplus::XMLListObject::normalize(), axtam::COMErrorClass::throwError(), throwErrorV(), and avmplus::XMLParser::XMLParser().

03192     {
03193 #ifdef AVMPLUS_64BIT
03194         // We can always fi t the value in an Atom
03195         return (((Atom)n)<<3) | kIntegerType;
03196 #else
03197         // handle integer values w/out allocation
03198         int i29 = n << 3;
03199         if ((i29>>3) == n)
03200         {
03201             return uint32(i29 | kIntegerType);;
03202         }
03203         else 
03204         {
03205             return allocDouble(n);
03206         }
03207 #endif
03208     }

Stringp avmplus::AvmCore::intToString int  i  ) 
 

Definition at line 3473 of file AvmCore.cpp.

References avmplus::MathUtils::convertIntegerToString(), and MMgc::GCRoot::GetGC().

Referenced by avmplus::AbstractFunction::makeIntoPrototypeFunction(), and string().

03474     {
03475         wchar buffer[65];
03476         int len;
03477         MathUtils::convertIntegerToString(value, buffer, len);
03478         return new (GetGC()) String(buffer, len);
03479     }

static bool avmplus::AvmCore::isAccessorBinding Binding  b  )  [inline, static]
 

Definition at line 450 of file AvmCore.h.

References avmplus::AtomConstants::BIND_GET.

00451         {
00452             return (b&7) >= BIND_GET;
00453         }

static bool avmplus::AvmCore::isBoolean Atom  atom  )  [inline, static]
 

Helper method; returns true if atom's type is boolean

Definition at line 533 of file AvmCore.h.

References avmplus::AtomConstants::kBooleanType.

Referenced by avmplus::AbstractFunction::resolveSignature().

00534         {
00535             return (atom&7) == kBooleanType;
00536         }

bool avmplus::AvmCore::isCombiningChar wchar  c  ) 
 

Definition at line 2293 of file AvmCore.cpp.

Referenced by isXMLName().

02294     {
02295         int x = sizeof(combiningCharTable) / (sizeof(wchar));
02296         for (int i = 0; i < x; i += 2)
02297         {
02298             if (c >= combiningCharTable[i] && c <= combiningCharTable[i+1])
02299                 return true;
02300         }
02301         return false;
02302     }

static int avmplus::AvmCore::isConstBinding Binding  b  )  [inline, static]
 

true only if b is a const

Definition at line 502 of file AvmCore.h.

References avmplus::AtomConstants::BIND_CONST.

00503         {
00504             return (b&7)==BIND_CONST;
00505         }

bool avmplus::AvmCore::isDate Atom  atm  ) 
 

Definition at line 1937 of file AvmCore.cpp.

References atomToScriptObject(), AvmAssert, avmplus::BuiltinTraits::date_itraits, avmplus::Traits::final, isObject(), avmplus::ScriptObject::traits(), and traits.

Referenced by avmplus::Toplevel::add2().

01938     {
01939         if (!isObject(atm))
01940             return false;
01941 
01942         AvmAssert (!traits.date_itraits || traits.date_itraits->final);
01943         Traits *lhs = atomToScriptObject(atm)->traits();
01944         return (lhs == traits.date_itraits);
01945     }

bool avmplus::AvmCore::isDictionary Atom  atm  ) 
 

Returns true if the passed atom is a Dictionary object, as defined in the E4X Specification.

Definition at line 1967 of file AvmCore.cpp.

References atomToScriptObject(), avmplus::Traits::isDictionary, isObject(), avmplus::VTable::traits, and avmplus::ScriptObject::vtable.

Referenced by isDictionaryLookup().

01968     {
01969         return isObject(atm) && atomToScriptObject(atm)->vtable->traits->isDictionary;
01970     }

bool avmplus::AvmCore::isDictionaryLookup Atom  key,
Atom  obj
[inline]
 

Definition at line 1172 of file AvmCore.h.

References isDictionary(), and isObject().

Referenced by avmplus::MethodEnv::in().

01173         {
01174             return isObject(key) && isDictionary(obj);
01175         }

bool avmplus::AvmCore::isDigit wchar  c  ) 
 

Definition at line 2322 of file AvmCore.cpp.

Referenced by isXMLName().

02323     {
02324         int x = sizeof(digitTable) / (sizeof(wchar));
02325         for (int i = 0; i < x; i += 2)
02326         {
02327             if (c >= digitTable[i] && c <= digitTable[i+1])
02328                 return true;
02329         }
02330         return false;
02331     }

static bool avmplus::AvmCore::isDouble Atom  atom  )  [inline, static]
 

Helper method; returns true if atom's type is double

Definition at line 514 of file AvmCore.h.

References avmplus::AtomConstants::kDoubleType.

Referenced by avmplus::AbstractFunction::resolveSignature().

00515         {
00516             return (atom&7) == kDoubleType;
00517         }

bool avmplus::AvmCore::isExtender wchar  c  ) 
 

Definition at line 2345 of file AvmCore.cpp.

Referenced by isXMLName().

02346     {
02347         int x = sizeof(extenderTable) / (sizeof(wchar));
02348         for (int i = 0; i < x; i += 2)
02349         {
02350             if (c >= extenderTable[i] && c <= extenderTable[i+1])
02351                 return true;
02352         }
02353         return false;
02354     }

bool avmplus::AvmCore::isFunction Atom  atom  )  [inline]
 

Helper method; returns true if atom is an Function

Definition at line 508 of file AvmCore.h.

References avmplus::BuiltinTraits::function_itraits, istype(), and traits.

Referenced by _typeof().

00509         {
00510             return istype(atom, traits.function_itraits);
00511         }

static bool avmplus::AvmCore::isGCObject Atom  a  )  [inline, static]
 

Definition at line 1259 of file AvmCore.h.

References avmplus::AtomConstants::kDoubleType.

Referenced by avmplus::WeakValueHashtable::getValue(), avmplus::DictionaryObject::nextName(), avmplus::DictionaryObject::nextNameIndex(), and avmplus::WeakKeyHashtable::prune().

01259 { return (a&7)==kDoubleType; }

static bool avmplus::AvmCore::isInteger Atom  atom  )  [inline, static]
 

Helper method; returns true if atom's type is int

Definition at line 520 of file AvmCore.h.

References avmplus::AtomConstants::kIntegerType.

Referenced by getIndexFromAtom(), increment_d(), and avmplus::AbstractFunction::resolveSignature().

00521         {
00522             return (atom&7) == kIntegerType;
00523         }

bool avmplus::AvmCore::isLetter wchar  c  ) 
 

Definition at line 2184 of file AvmCore.cpp.

Referenced by isXMLName().

02185     {
02186         int x = sizeof(letterTable) / (sizeof(wchar));
02187         for (int i = 0; i < x; i += 2)
02188         {
02189             if (c >= letterTable[i] && c <= letterTable[i+1])
02190                 return true;
02191         }
02192         return false;
02193     }

static bool avmplus::AvmCore::isMethodBinding Binding  b  )  [inline, static]
 

Definition at line 445 of file AvmCore.h.

References avmplus::AtomConstants::BIND_METHOD.

Referenced by bindingToMethodId(), avmplus::MethodEnv::delproperty(), avmplus::Verifier::findMathFunction(), avmplus::Verifier::findStringFunction(), and avmplus::Traits::getOverride().

00446         {
00447             return (b&7) == BIND_METHOD;
00448         }

bool avmplus::AvmCore::IsMIREnabled  )  const [inline]
 

Definition at line 257 of file AvmCore.h.

References config, and avmplus::Config::turbo.

Referenced by avmplus::MethodInfo::verify().

00258         {
00259             return config.turbo;
00260         }

static bool avmplus::AvmCore::isName Atom  atom  )  [inline, static]
 

Definition at line 772 of file AvmCore.h.

References atomToString(), avmplus::String::isInterned(), and isString().

Referenced by avmplus::Namespace::hasPrefix(), avmplus::Namespace::Namespace(), and avmplus::Namespace::setPrefix().

00773         {
00774             return isString(atom) && atomToString(atom)->isInterned();
00775         }

static bool avmplus::AvmCore::isNamespace Atom  atom  )  [inline, static]
 

Definition at line 440 of file AvmCore.h.

References isNull(), and avmplus::AtomConstants::kNamespaceType.

Referenced by avmplus::XMLObject::addNamespace(), avmplus::QNameClass::construct(), newNamespace(), avmplus::XMLObject::removeNamespace(), and avmplus::AbstractFunction::resolveSignature().

00441         {
00442             return (atom&7) == kNamespaceType && !isNull(atom);
00443         }

static bool avmplus::AvmCore::isNull Atom  atom  )  [inline, static]
 

Helper method; returns true if atom's type is null

Definition at line 539 of file AvmCore.h.

References ISNULL.

Referenced by avmplus::XMLListObject::_resolveValue(), _typeof(), atomWriteBarrier(), boolean(), booleanAtom(), avmplus::QNameClass::construct(), avmplus::ClassClosure::construct(), axtam::DomainObject::constructFromDomain(), equals(), avmplus::ArrayClass::every(), avmplus::ArrayClass::filter(), avmplus::MethodEnv::findproperty(), avmplus::ArrayClass::forEach(), intern(), avmplus::MethodEnv::internRtns(), isNamespace(), isObject(), isString(), istype(), newNamespace(), number(), numberAtom(), avmplus::AbstractFunction::resolveSignature(), avmplus::XMLListObject::setMultinameProperty(), avmplus::XMLObject::setName(), avmplus::XMLListObject::setUintProperty(), avmplus::ArrayClass::some(), stricteq(), string(), avmplus::MethodEnv::toClassITraits(), and ToXMLString().

00540         {
00541             return ISNULL(atom);
00542         }

static bool avmplus::AvmCore::isNullOrUndefined Atom  atom  )  [inline, static]
 

Definition at line 550 of file AvmCore.h.

References avmplus::AtomConstants::kSpecialType.

Referenced by boolean(), booleanAtom(), avmplus::XMLListClass::call(), avmplus::XMLClass::call(), avmplus::ObjectClass::call(), avmplus::ClassClosure::call(), avmplus::ClassClosure::call_this(), avmplus::ClassClosure::call_this_a(), avmplus::Toplevel::coerce(), coerce_s(), avmplus::MethodEnv::coerceAtom2SO(), avmplus::XMLListClass::construct(), avmplus::XMLClass::construct(), avmplus::ObjectClass::construct(), equals(), avmplus::ScriptObject::function_apply(), avmplus::MethodEnv::hasnext(), avmplus::MethodEnv::hasnextproto(), isXMLName(), avmplus::MethodClosure::MethodClosure(), avmplus::Namespace::Namespace(), avmplus::ScriptObject::nextName(), avmplus::ScriptObject::nextValue(), avmplus::MethodEnv::nullcheck(), avmplus::ObjectClass::objectIsPrototypeOf(), avmplus::ClassClosure::set_prototype(), avmplus::TraceClass::setListener(), avmplus::Namespace::setPrefix(), avmplus::Toplevel::ToAttributeName(), avmplus::Toplevel::toPrototype(), avmplus::Toplevel::toTraits(), avmplus::Toplevel::toVTable(), avmplus::XMLClass::ToXML(), avmplus::XMLListClass::ToXMLList(), and avmplus::Toplevel::ToXMLName().

00551         {
00552             return ((uintptr)atom) <= (uintptr)kSpecialType;
00553         }

static bool avmplus::AvmCore::isNumber Atom  atom  )  [inline, static]
 

Helper method; returns true if atom's type is Number

Definition at line 526 of file AvmCore.h.

References avmplus::AtomConstants::kIntegerType.

Referenced by avmplus::Toplevel::add2(), equals(), increment_d(), number_d(), and avmplus::ArrayClass::sort().

00527         {
00528             // accept kIntegerType(6) or kDoubleType(7)
00529             return (atom&6) == kIntegerType;
00530         }

static bool avmplus::AvmCore::isObject Atom  atom  )  [inline, static]
 

Helper method; returns true if the atom is a tagged ScriptObject pointer. The actual type of the object is indicated by ScriptObject->vtable->traits.

Definition at line 425 of file AvmCore.h.

References isNull(), and avmplus::AtomConstants::kObjectType.

Referenced by avmplus::ArraySort::ArraySort(), avmplus::QNameClass::call(), CActiveScript::callEngineRawVA(), avmplus::Toplevel::callproperty(), avmplus::ScriptObject::callProperty(), avmplus::ArrayClass::concat(), avmplus::QNameClass::construct(), avmplus::ClassClosure::construct(), avmplus::ScriptObject::createInstance(), avmplus::DictionaryObject::deleteAtomProperty(), avmplus::MethodEnv::delproperty(), avmplus::ArrayClass::every(), avmplus::ArrayClass::filter(), avmplus::ArrayClass::forEach(), avmplus::DictionaryObject::getAtomProperty(), avmplus::MethodEnv::getdescendants(), avmplus::MethodEnv::getdescendantslate(), avmplus::DictionaryObject::getKeyFromObject(), avmplus::DictionaryObject::hasAtomProperty(), avmplus::ArrayClass::indexOf(), isDate(), isDictionary(), isDictionaryLookup(), isQName(), isXML(), avmplus::Toplevel::isXmlBase(), isXMLList(), avmplus::ArrayClass::lastIndexOf(), avmplus::ArrayClass::map(), newNamespace(), avmplus::Toplevel::op_applytype(), avmplus::Toplevel::op_call(), avmplus::Toplevel::op_construct(), avmplus::ArrayClass::pop(), primitive(), avmplus::ArrayClass::reverse(), avmplus::ClassClosure::set_prototype(), avmplus::DictionaryObject::setAtomProperty(), avmplus::Toplevel::setproperty_b(), avmplus::MethodEnv::setpropertylate_i(), avmplus::MethodEnv::setpropertylate_u(), avmplus::ArrayClass::slice(), avmplus::ArrayClass::some(), avmplus::ArrayClass::sort(), avmplus::ArrayClass::sortOn(), and avmplus::ArrayClass::splice().

00426         {
00427             return (atom&7) == kObjectType && !isNull(atom);
00428         }

static bool avmplus::AvmCore::isPointer Atom  atom  )  [inline, static]
 

Definition at line 430 of file AvmCore.h.

References avmplus::AtomConstants::kDoubleType, and avmplus::AtomConstants::kSpecialType.

Referenced by avmplus::WeakValueHashtable::add(), avmplus::WeakKeyHashtable::getKey(), and avmplus::WeakValueHashtable::prune().

00431         {
00432             return (atom&7) < kSpecialType || (atom&7) == kDoubleType;
00433         }

bool avmplus::AvmCore::isQName Atom  atm  ) 
 

Returns true if the passed atom is a QName object, as defined in the E4X Specification.

Definition at line 1957 of file AvmCore.cpp.

References atomToScriptObject(), AvmAssert, avmplus::Traits::final, isObject(), avmplus::BuiltinTraits::qName_itraits, avmplus::ScriptObject::traits(), and traits.

Referenced by atomToQName(), equals(), newNamespace(), avmplus::QNameObject::QNameObject(), avmplus::XMLObject::setName(), avmplus::Toplevel::ToAttributeName(), and avmplus::Toplevel::ToXMLName().

01958     {
01959         if (!isObject(atm))
01960             return false;
01961 
01962         AvmAssert (!traits.qName_itraits || traits.qName_itraits->final);
01963         Traits *lhs = atomToScriptObject(atm)->traits();
01964         return (lhs == traits.qName_itraits);
01965     }

static int avmplus::AvmCore::isSlotBinding Binding  b  )  [inline, static]
 

true if b is a var or a const

Definition at line 490 of file AvmCore.h.

References AvmAssert, avmplus::AtomConstants::BIND_CONST, and avmplus::AtomConstants::BIND_VAR.

Referenced by bindingToSlotId(), and avmplus::Verifier::emitGetProperty().

00491         {
00492             AvmAssert((BIND_CONST&6)==BIND_VAR);
00493             return (b&6)==BIND_VAR;
00494         }

static bool avmplus::AvmCore::isString Atom  atom  )  [inline, static]
 

Returns true if the passed atom is of string type.

Definition at line 767 of file AvmCore.h.

References isNull(), and avmplus::AtomConstants::kStringType.

Referenced by avmplus::Toplevel::add2(), compare(), avmplus::DateClass::construct(), equals(), avmplus::Hashtable::find(), axtam::MSIDispatchConsumer::getAtomProperty(), axtam::IDispatchConsumer::getAtomProperty(), getIndexFromAtom(), internString(), isName(), avmplus::MethodEnv::op_newobject(), avmplus::AbstractFunction::resolveSignature(), and avmplus::Namespace::setPrefix().

00768         {
00769             return (atom&0x7) == kStringType && !isNull(atom);
00770         }

static bool avmplus::AvmCore::isTraits Atom  type  )  [inline, static]
 

Definition at line 435 of file AvmCore.h.

00436         {
00437             return type != 0 && (type&7) == 0;
00438         }

bool avmplus::AvmCore::istype Atom  atom,
Traits itraits
 

this is the implementation of the actionscript "is" operator. similar to java's instanceof. returns true/false according to AS rules. in particular, it will return false if value==null.

Definition at line 1765 of file AvmCore.cpp.

References atomToDouble(), atomToScriptObject(), AvmAssert, avmplus::BuiltinTraits::boolean_itraits, avmplus::Traits::containsInterface(), avmplus::BuiltinTraits::int_itraits, isNull(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, avmplus::AtomConstants::kStringType, avmplus::BuiltinTraits::namespace_itraits, avmplus::BuiltinTraits::null_itraits, avmplus::BuiltinTraits::number_itraits, avmplus::MathUtils::real2int(), avmplus::BuiltinTraits::string_itraits, avmplus::ScriptObject::traits(), traits, avmplus::BuiltinTraits::uint_itraits, and avmplus::BuiltinTraits::void_itraits.

Referenced by avmplus::MethodEnv::astype(), avmplus::QNameClass::call(), avmplus::ArrayClass::concat(), avmplus::QNameClass::construct(), avmplus::RegExpClass::construct(), avmplus::Toplevel::constructprop(), findExceptionHandlerNoRethrow(), avmplus::ScriptObject::function_apply(), avmplus::Toplevel::instanceof(), isFunction(), axtam::CActiveScriptError::isSyntaxError(), istypeAtom(), avmplus::StringClass::match(), avmplus::ObjectClass::objectToString(), avmplus::StringClass::replace(), avmplus::StringClass::search(), avmplus::TraceClass::setListener(), avmplus::XMLObject::setNotification(), and avmplus::ArrayClass::sortOn().

01766     {
01767         if (!itraits)
01768             return true;
01769 
01770         if (isNull(atom))
01771             return itraits == traits.null_itraits;
01772 
01773         Traits* lhs;
01774 
01775         switch (atom&7)
01776         {
01777         case kNamespaceType:
01778             lhs = traits.namespace_itraits;
01779             break;
01780 
01781         case kStringType:
01782             lhs = traits.string_itraits;
01783             break;
01784 
01785         case kBooleanType:
01786             lhs = traits.boolean_itraits;
01787             break;
01788 
01789         case kIntegerType:
01790             // ISSUE need special support for number value ranges
01791             if (itraits == traits.number_itraits)
01792                 return true;
01793 
01794             lhs = traits.int_itraits;
01795             if (itraits == traits.uint_itraits)
01796             {
01797                 return (atom>>3) >= 0;
01798             }
01799 #ifdef AVMPLUS_64BIT
01800             if (itraits == traits.int_itraits)
01801             {
01802                 // this might be a uint
01803                 if ((int64)(atom>>3)!=(int)(atom>>3))
01804                     return false;
01805             }
01806 #endif
01807             break;
01808 
01809         case kDoubleType:
01810             lhs = traits.number_itraits;
01811             // ISSUE there must be a better way...
01812             if (itraits == traits.int_itraits)
01813             {
01814                 double d = atomToDouble(atom);
01815                 int i = MathUtils::real2int(d);
01816                 return d == (double)i;
01817             }
01818             if (itraits == traits.uint_itraits)
01819             {
01820                 double d = atomToDouble(atom);
01821                 // ISSUE use real2int?
01822                 unsigned i = (unsigned)d;
01823                 return d == (double)i;
01824             }
01825             break;
01826 
01827         case kSpecialType:
01828             return itraits == traits.void_itraits;
01829 
01830         case kObjectType: {
01831             lhs = atomToScriptObject(atom)->traits();
01832             break;
01833         }
01834 
01835         default:
01836             // unexpected atom type
01837             AvmAssert(false);
01838             return false;
01839         }
01840 
01841         return lhs->containsInterface(itraits)!=0;
01842     }

Atom avmplus::AvmCore::istypeAtom Atom  atom,
Traits itraits
[inline]
 

this is the implementation of the actionscript "is" operator. similar to java's instanceof. returns true/false according to AS rules. in particular, it will return false if value==null.

Definition at line 922 of file AvmCore.h.

References avmplus::AtomConstants::falseAtom, istype(), and avmplus::AtomConstants::trueAtom.

00922                                                     { 
00923             return istype(atom, itraits) ? trueAtom : falseAtom; 
00924         }

static bool avmplus::AvmCore::isUndefined Atom  atom  )  [inline, static]
 

Helper method; returns true if atom's type is undefined

Definition at line 545 of file AvmCore.h.

References avmplus::AtomConstants::undefinedAtom.

00546         {
00547             return (atom == undefinedAtom);
00548         }

static int avmplus::AvmCore::isVarBinding Binding  b  )  [inline, static]
 

true only if b is a var

Definition at line 497 of file AvmCore.h.

References avmplus::AtomConstants::BIND_VAR.

00498         {
00499             return (b&7)==BIND_VAR;
00500         }

bool avmplus::AvmCore::isXML Atom  atm  ) 
 

Returns true if the passed atom is an XML object, as defined in the E4X Specification.

Definition at line 1927 of file AvmCore.cpp.

References atomToScriptObject(), AvmAssert, avmplus::Traits::final, isObject(), avmplus::ScriptObject::traits(), traits, and avmplus::BuiltinTraits::xml_itraits.

Referenced by avmplus::XMLListObject::_resolveValue(), _typeof(), avmplus::XMLObject::appendChild(), atomToXML(), atomToXMLObject(), avmplus::XMLObject::childChanges(), avmplus::XMLClass::construct(), avmplus::XMLObject::contains(), equals(), avmplus::XMLObject::insertChildAfter(), avmplus::XMLObject::insertChildBefore(), avmplus::XMLObject::prependChild(), avmplus::XMLObject::replace(), avmplus::XMLListObject::setMultinameProperty(), avmplus::XMLListObject::setUintProperty(), stricteq(), avmplus::XMLClass::ToXML(), and ToXMLString().

01928     {
01929         if (!isObject(atm))
01930             return false;
01931 
01932         AvmAssert (!traits.xml_itraits || traits.xml_itraits->final);
01933         Traits *lhs = atomToScriptObject(atm)->traits();
01934         return (lhs == traits.xml_itraits);
01935     }

bool avmplus::AvmCore::isXMLList Atom  atm  ) 
 

Returns true if the passed atom is a XMLList object, as defined in the E4X Specification.

Definition at line 1947 of file AvmCore.cpp.

References atomToScriptObject(), AvmAssert, avmplus::Traits::final, isObject(), avmplus::ScriptObject::traits(), traits, and avmplus::BuiltinTraits::xmlList_itraits.

Referenced by avmplus::XMLListObject::_append(), avmplus::XMLListObject::_equals(), _typeof(), avmplus::XMLObject::appendChild(), atomToXMLList(), avmplus::XMLObject::callProperty(), avmplus::XMLListObject::callProperty(), avmplus::XMLObject::childChanges(), avmplus::XMLListClass::construct(), avmplus::XMLClass::construct(), equals(), avmplus::initMultinameNoXMLList(), avmplus::XMLObject::insertChildAfter(), avmplus::XMLObject::insertChildBefore(), avmplus::XMLObject::prependChild(), avmplus::XMLListObject::setMultinameProperty(), avmplus::XMLListObject::setUintProperty(), avmplus::XMLListClass::ToXMLList(), and ToXMLString().

01948     {
01949         if (!isObject(atm))
01950             return false;
01951 
01952         AvmAssert (!traits.xmlList_itraits || traits.xmlList_itraits->final);
01953         Traits *lhs = atomToScriptObject(atm)->traits();
01954         return (lhs == traits.xmlList_itraits);
01955     }

bool avmplus::AvmCore::isXMLName Atom  arg  ) 
 

Returns true if the passed atom is a valid XML name, as defined in the E4X Specification.

Definition at line 2356 of file AvmCore.cpp.

References isCombiningChar(), isDigit(), isExtender(), isLetter(), isNullOrUndefined(), avmplus::String::length(), and string().

Referenced by avmplus::Toplevel::isXMLName(), newNamespace(), and avmplus::XMLObject::setLocalName().

02357     {
02358         if (isNullOrUndefined(arg))
02359             return false;
02360 
02361         Stringp p = string(arg);
02362 
02363         // http://www.w3.org/TR/2004/REC-xml-20040204/#NT-NameChar
02364 
02365         // Name is (Letter | _ or :) followed by arbitrary number of NameChar
02366 
02367         if (!p->length())
02368             return false;
02369 
02370         // According to the Mozilla testcase...
02371         // e4x excludes ':'
02372 
02373         wchar c = (*p)[0];
02374         if (!isLetter (c) && c != '_' /*&& c != ':'*/)
02375             return false;       
02376 
02377         for (int i = 1; i < p->length(); i++)
02378         {
02379             wchar c = (*p)[i];
02380 
02381             if (isDigit(c) || isLetter(c) || (c == '.') || (c == '-') || (c == '_') || /*(c != ':') ||*/
02382                 isCombiningChar (c) || isExtender(c))
02383                 continue;
02384 
02385             return false;
02386         }
02387 
02388         return true;
02389     }

Traits * avmplus::AvmCore::makeParameterizedCTraits Stringp  name,
Namespace ns,
Traits t
 

Definition at line 624 of file AvmCore.cpp.

References avmplus::Traits::methodCount, avmplus::Traits::needsHashtable, newTraits(), avmplus::Traits::sizeofInstance, and avmplus::Traits::slotCount.

Referenced by avmplus::VectorClass::applyTypeArgs().

00625     {
00626         Traits* newtraits = newTraits(t->base, 0, 0, t->sizeofInstance);
00627         newtraits->name = name;
00628         newtraits->ns = ns;
00629         newtraits->slotCount = t->base->slotCount;
00630         newtraits->methodCount = t->base->methodCount;
00631         newtraits->needsHashtable = t->needsHashtable;
00632         return newtraits;
00633     }

Traits * avmplus::AvmCore::makeParameterizedITraits Stringp  name,
Namespace ns,
Traits t
 

Creates a new traits with the given name & ns, copied from the traits* t Used for instantiating new parameterized types on the fly.

Definition at line 613 of file AvmCore.cpp.

References avmplus::Traits::methodCount, avmplus::Traits::needsHashtable, newTraits(), avmplus::Traits::sizeofInstance, and avmplus::Traits::slotCount.

Referenced by avmplus::PoolObject::resolveParameterizedType().

00614     {
00615         Traits* newtraits = newTraits(t, 0, 0, t->sizeofInstance);
00616         newtraits->name = name;
00617         newtraits->ns = ns;
00618         newtraits->slotCount = t->slotCount;
00619         newtraits->methodCount = t->methodCount;
00620         newtraits->needsHashtable = t->needsHashtable;
00621         return newtraits;
00622     }

Namespace * avmplus::AvmCore::newNamespace Stringp  uri,
Namespace::NamespaceType  type = Namespace::NS_Public
 

Definition at line 3163 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC(), internString(), prefix, and avmplus::AtomConstants::undefinedAtom.

03164     {
03165         uri = internString(uri);
03166         Atom prefix = (uri == kEmptyString) ? kEmptyString->atom() : undefinedAtom;
03167         return new (GetGC()) Namespace(prefix, uri, type);
03168     }

Namespace * avmplus::AvmCore::newNamespace Atom  uri,
Namespace::NamespaceType  type = Namespace::NS_Public
 

Definition at line 3141 of file AvmCore.cpp.

References atomToNamespace(), atomToQName(), atomToString(), MMgc::GCRoot::GetGC(), avmplus::Namespace::getPrefix(), avmplus::Namespace::getURI(), internString(), isNamespace(), isNull(), isObject(), isQName(), prefix, string(), and avmplus::AtomConstants::undefinedAtom.

03142     {
03143         // prefix and uri must be interned!
03144         // E4X - this is 13.2.2, step 3 - "prefix not specified"
03145 
03146         if (isNamespace (uri))
03147         {
03148             Namespace *ns = atomToNamespace (uri);
03149             return new (GetGC()) Namespace (ns->getPrefix(), ns->getURI(), type);
03150         }
03151         else if (isObject(uri) && isQName (uri) && !isNull(atomToQName (uri)->getURI()))
03152         {
03153             return new (GetGC()) Namespace (undefinedAtom, atomToString(atomToQName (uri)->getURI()), type);
03154         }
03155         else
03156         {
03157             Stringp u = internString (string (uri));
03158             Atom prefix = (u == kEmptyString) ? kEmptyString->atom() : undefinedAtom;
03159             return new (GetGC()) Namespace (prefix, u, type);
03160         }
03161     }

Namespace * avmplus::AvmCore::newNamespace Atom  prefix,
Atom  uri,
Namespace::NamespaceType  type = Namespace::NS_Public
 

Definition at line 3098 of file AvmCore.cpp.

References atomToQName(), atomToString(), internString(), isNull(), isQName(), isXMLName(), length, string(), and avmplus::AtomConstants::undefinedAtom.

Referenced by avmplus::QNameClass::construct(), avmplus::NamespaceClass::construct(), axtam::DomainObject::constructFromDomain(), avmplus::ElementE4XNode::CopyAttributesAndNamespaces(), newPublicNamespace(), prepareActionPool(), avmplus::XMLObject::removeNamespace(), avmplus::XMLObject::setNamespace(), avmplus::Toplevel::ToXMLName(), avmplus::XMLClass::XMLClass(), and avmplus::XMLObject::XMLObject().

03099     {
03100         // E4X - this is 13.2.3, step 3 - prefix IS specified
03101 
03102         Atom p;
03103         Stringp u;
03104         if (isQName (uri) && !isNull(atomToQName (uri)->getURI()))
03105         {
03106             u = atomToString(atomToQName (uri)->getURI());
03107         }
03108         else
03109         {
03110             u = internString (string (uri));
03111         }
03112         if (u == kEmptyString)
03113         {
03114             if (prefix == undefinedAtom)
03115                 p = kEmptyString->atom();
03116             else if (!string (prefix)->length())
03117                 p = kEmptyString->atom();
03118             else
03119             {
03120                 // !!@ throw correct type error
03121                 //typeErrorClass()->throwError(kConvertUndefinedToObjectError);
03122                 return NULL;
03123             }
03124         }
03125         else if (prefix == undefinedAtom)
03126         {
03127             p = undefinedAtom;
03128         }
03129         else if (prefix != kEmptyString->atom() && !isXMLName (prefix))
03130         {
03131             p = undefinedAtom;
03132         }
03133         else
03134         {
03135             p = internString (string (prefix))->atom();
03136         }
03137 
03138         return new (GetGC()) Namespace(p, u, type);
03139     }

NamespaceSet * avmplus::AvmCore::newNamespaceSet int  nsCount  ) 
 

Definition at line 3170 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC().

03171     {
03172         size_t extra = (nsCount >= 1 ? nsCount-1 : 0)*sizeof(Atom);
03173         return new (GetGC(), extra) NamespaceSet(nsCount);
03174     }

ScriptObject * avmplus::AvmCore::newObject VTable ivtable,
ScriptObject delegate
 

Definition at line 3093 of file AvmCore.cpp.

References avmplus::VTable::getExtraSize(), and MMgc::GCRoot::GetGC().

Referenced by avmplus::ObjectClass::construct(), avmplus::ScriptEnv::initGlobal(), and avmplus::MethodEnv::newcatch().

03094     {
03095         return new (GetGC(), vtable->getExtraSize()) ScriptObject(vtable, delegate);
03096     }

Namespace* avmplus::AvmCore::newPublicNamespace Stringp  uri  )  [inline]
 

Definition at line 1331 of file AvmCore.h.

References newNamespace().

01331 { return newNamespace(uri); }

RegExpObject * avmplus::AvmCore::newRegExp RegExpClass regExpClass,
Stringp  pattern,
Stringp  options
 

Definition at line 3085 of file AvmCore.cpp.

References avmplus::VTable::getExtraSize(), MMgc::GCRoot::GetGC(), and avmplus::ClassClosure::ivtable().

Referenced by avmplus::StringClass::match(), and avmplus::StringClass::search().

03088     {
03089         return new (GetGC(), regexpClass->ivtable()->getExtraSize()) RegExpObject(regexpClass,
03090                                                          pattern, options);
03091     }

ScriptBufferImpl * avmplus::AvmCore::newScriptBuffer size_t  size  ) 
 

Definition at line 3073 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC().

Referenced by avmshell::DomainObject::loadBytes(), and axtam::DomainObject::loadBytes().

03074     {
03075         return new (GetGC(), size) BasicScriptBufferImpl(size);
03076     }

Stringp avmplus::AvmCore::newString const char *  str,
int  len
const
 

Definition at line 3449 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC(), and avmplus::UnicodeUtils::Utf8ToUtf16().

03450     {
03451         int utf16len = UnicodeUtils::Utf8ToUtf16((const uint8*)s, len, NULL, 0);
03452         return new (GetGC()) String(s, len, utf16len);
03453     }

Stringp avmplus::AvmCore::newString const wchar str  )  const
 

Definition at line 3455 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC(), and avmplus::String::Length().

03456     {
03457         int len = String::Length(s);
03458         return new (GetGC()) String(s, len);
03459     }

Stringp avmplus::AvmCore::newString const char *  str  )  const
 

Definition at line 3442 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC(), avmplus::String::Length(), and avmplus::UnicodeUtils::Utf8ToUtf16().

Referenced by avmplus::VectorClass::applyTypeArgs(), avmplus::ArrayClass::ArrayClass(), constantString(), axtam::AXTam::constantString(), avmplus::XMLListClass::construct(), avmplus::NamespaceSet::format(), avmplus::Multiname::format(), avmplus::Traits::formatClassName(), formatErrorMessageV(), avmshell::SystemClass::getArgv(), getErrorMessage(), avmplus::getTraits(), avmplus::AbstractFunction::makeIntoPrototypeFunction(), avmplus::ObjectClass::objectToString(), avmplus::AbcParser::parseClassInfos(), avmplus::AbcParser::parseScriptInfos(), avmshell::SystemClass::readLine(), avmplus::RegExpObject::RegExpObject(), avmplus::RegExpObject::replace(), avmplus::PoolObject::resolveParameterizedType(), avmplus::RegExpObject::split(), avmplus::ErrorObject::stackTraceToString(), avmplus::RegExpObject::stringFromUTF8(), toErrorString(), avmplus::XMLObject::toXMLString(), avmplus::XMLListObject::toXMLString(), avmplus::XMLClass::XMLClass(), avmplus::XMLObject::XMLObject(), and avmplus::XMLObject::xmlPropertyIsEnumerable().

03443     {
03444         int len = String::Length(s);
03445         int utf16len = UnicodeUtils::Utf8ToUtf16((const uint8*)s, len, NULL, 0);
03446         return new (GetGC()) String(s, len, utf16len);
03447     }

Traits * avmplus::AvmCore::newTraits Traits base,
int  nameCount,
int  interfaceCount,
uint32  sizeofInstance
 

traits with base traits (inheritance)

Definition at line 3424 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC(), avmplus::Traits::interfaceCount, avmplus::MathUtils::nextPowerOfTwo(), and traits.

Referenced by avmplus::BuiltinTraits::initInstanceTypes(), avmplus::AbstractFunction::makeIntoPrototypeFunction(), makeParameterizedCTraits(), makeParameterizedITraits(), avmplus::Verifier::parseExceptionHandlers(), and avmplus::AbcParser::parseTraits().

03428     {
03429         int interfaceCount = interfaceDelta;
03430         if (base)
03431             interfaceCount += base->interfaceCount+1; // +1 b/c base is added
03432         int interfaceCapacity = MathUtils::nextPowerOfTwo((5*interfaceCount >> 2) + 1);
03433         size_t extra = interfaceCapacity*sizeof(Traits*);
03434         Traits* traits = new (GetGC(), extra) Traits(this, base,
03435                                               nameCount,
03436                                               interfaceCount,
03437                                               interfaceCapacity,
03438                                               objectSize);
03439         return traits;
03440     }

VTable * avmplus::AvmCore::newVTable Traits traits,
VTable base,
ScopeChain scope,
AbcEnv abcEnv,
Toplevel toplevel
 

Definition at line 3078 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC(), toplevel, and traits.

Referenced by avmplus::VectorClass::applyTypeArgs(), axtam::DomainObject::constructFromDomain(), avmplus::MethodEnv::MethodEnv(), avmplus::MethodEnv::newcatch(), and prepareActionPool().

03080     {
03081         size_t extraSize = sizeof(MethodEnv*)*(traits->methodCount > 0 ? traits->methodCount-1 : 0);
03082         return new (GetGC(), extraSize) VTable(traits, base, scope, abcEnv, toplevel);
03083     }

double avmplus::AvmCore::number Atom  atom  )  const
 

ES3's internal ToNumber() function for internal use

Definition at line 1377 of file AvmCore.cpp.

References atomToDouble(), atomToNamespace(), atomToScriptObject(), atomToString(), isNull(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, kNaN, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, avmplus::AtomConstants::kStringType, avmplus::String::toNumber(), and avmplus::AtomConstants::trueAtom.

Referenced by avmplus::Toplevel::add2(), compare(), avmplus::DateClass::construct(), equals(), avmplus::ArraySort::FieldCompare(), integer(), numberAtom(), avmplus::ArraySort::NumericCompare(), stricteq(), toInteger(), avmplus::MethodEnv::unbox1(), avmplus::DateClass::UTC(), and avmplus::XMLListObject::xmlListPropertyIsEnumerable().

01378     {
01379         int kind = atom&7;
01380 
01381         if (kind == kIntegerType)
01382             return (double) ((sintptr)atom>>3);
01383         if (kind == kDoubleType)
01384             return atomToDouble(atom);
01385 
01386         if (!isNull(atom))
01387         {
01388             switch (kind)
01389             {
01390             case kStringType:
01391                 return atomToString(atom)->toNumber();
01392             case kSpecialType:
01393                 return atomToDouble(kNaN);
01394             case kBooleanType:
01395                 return atom == trueAtom ? 1.0 : 0.0;
01396             case kNamespaceType:
01397                 return number(atomToNamespace(atom)->getURI()->atom());
01398             default: // number
01399             case kObjectType:
01400                 return number(atomToScriptObject(atom)->defaultValue());
01401             }
01402         }
01403         else
01404         {
01405             // ES3 9.3, toNumber(null) == 0
01406             return 0.0;
01407         }
01408     }

static double avmplus::AvmCore::number_d Atom  a  )  [inline, static]
 

Definition at line 722 of file AvmCore.h.

References atomToDouble(), AvmAssert, isNumber(), and avmplus::AtomConstants::kIntegerType.

Referenced by avmplus::interpN(), avmplus::AbstractFunction::resolveSignature(), and avmplus::ScriptObject::setSlotAtom().

00723         {
00724             AvmAssert(isNumber(a));
00725 
00726             if ((a&7) == kIntegerType)
00727                 return (int)(a>>3);
00728             else
00729                 return atomToDouble(a);
00730         }

Atom avmplus::AvmCore::numberAtom Atom  atom  ) 
 

OP_tonumber; ES3 ToNumber

Definition at line 1342 of file AvmCore.cpp.

References atomToNamespace(), atomToScriptObject(), atomToString(), AvmAssert, doubleToAtom(), isNull(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, kNaN, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, avmplus::AtomConstants::kStringType, number(), and avmplus::String::toNumber().

Referenced by avmplus::Toplevel::coerce(), and avmplus::NumberClass::construct().

01343     {
01344         if (!isNull(atom))
01345         {
01346             double value;
01347             switch (atom&7)
01348             {
01349             case kSpecialType:
01350                 return kNaN;
01351             case kStringType:
01352                 value = atomToString(atom)->toNumber();
01353                 break;
01354             default:
01355                 AvmAssert(false);
01356             case kBooleanType:
01357                 return (atom&~7) | kIntegerType;
01358             case kDoubleType:
01359             case kIntegerType:
01360                 return atom;
01361             case kNamespaceType:
01362                 // return ToNumber(namespace->uri)
01363                 value = number(atomToNamespace(atom)->getURI()->atom());
01364                 break;
01365             case kObjectType:
01366                 value = number(atomToScriptObject(atom)->defaultValue());
01367                 break;
01368             }
01369             return doubleToAtom(value);
01370         }
01371         else
01372         {
01373             return 0 | kIntegerType;
01374         }
01375     }

PoolObject * avmplus::AvmCore::parseActionBlock ScriptBuffer  code,
int  start,
Toplevel toplevel,
Domain domain,
AbstractFunction nativeMethods[],
NativeClassInfop  nativeClasses[],
NativeScriptInfop  nativeScripts[],
List< Stringp > *  include_versions = NULL
 

Parse the ABC block starting at offset start in code.

Parameters:
code buffer holding the ABC block to parse
start zero-indexed offset, in bytes, into the buffer where the code begins
toplevel the Toplevel object to execute against, or NULL if a Toplevel should be created.
nativeMethods the NATIVE_METHOD table
nativeClasses the NATIVE_CLASS table
nativeScriptss the NATIVE_SCRIPT table
Exceptions:
Exception If an error occurs, an Exception object will be thrown using the AVM+ exceptions mechanism. Calls to handleActionBlock should be bracketed in TRY/CATCH.

Definition at line 546 of file AvmCore.cpp.

References avmplus::AbcParser::decodeAbc(), and toplevel.

Referenced by handleActionBlock(), and initBuiltinPool().

00554     {
00555         // parse constants and attributes.
00556         PoolObject* pool = AbcParser::decodeAbc(this,
00557                                                 code,
00558                                                 toplevel,
00559                                                 domain,
00560                                                 nativeMethods,
00561                                                 nativeClasses,
00562                                                 nativeScripts,
00563                                                 include_versions);
00564 
00565         #ifdef DEBUGGER
00566         if (debugger) {
00567             debugger->processAbc(pool, code);
00568         }
00569         #endif /* DEBUGGER */
00570 
00571         return pool;
00572     }

void avmplus::AvmCore::postsweep  )  [virtual]
 

Definition at line 2647 of file AvmCore.cpp.

02648     {
02649 #ifdef FEATURE_SAMPLER
02650         _sampler.postsweep();
02651 #endif
02652     }

ScriptEnv * avmplus::AvmCore::prepareActionPool PoolObject pool,
DomainEnv domainEnv,
Toplevel *&  toplevel,
CodeContext codeContext
 

Definition at line 381 of file AvmCore.cpp.

References AvmAssert, builtinDomain, avmplus::AbcEnv::calcExtra(), avmplus::BuiltinTraits::class_itraits, codeContext(), avmplus::ScopeChain::create(), createToplevel(), exportDefs(), avmplus::BuiltinTraits::function_itraits, MMgc::GCRoot::GetGC(), getToplevelSize(), util::threadpool::i, avmplus::ErrorConstants::kMissingEntryPointError, truntests::main, newNamespace(), newVTable(), avmplus::BuiltinTraits::object_itraits, avmplus::Traits::resolveSignatures(), avmplus::VTable::resolveSignatures(), avmplus::PoolObject::scriptCount, avmplus::PoolObject::scripts, avmplus::DomainEnv::setToplevel(), avmplus::Traits::sizeofInstance, toplevel, and traits.

Referenced by handleActionPool().

00385     {
00386         AvmAssert(pool != NULL);
00387 
00388         // get the main entry point and its global traits
00389         if (pool->scriptCount == 0)
00390         {
00391             toplevel->verifyErrorClass()->throwError(kMissingEntryPointError);
00392         }
00393 
00394         if (domainEnv == NULL)
00395         {
00396             // create a new DomainEnv based on the builtinDomain
00397             domainEnv = new (GetGC()) DomainEnv(this, builtinDomain, NULL);
00398         }
00399 
00400         AbcEnv* abcEnv = new (GetGC(), AbcEnv::calcExtra(pool)) AbcEnv(pool, domainEnv, codeContext);
00401 
00402         // entry point is the last script in the file
00403         Traits* mainTraits = pool->scripts[pool->scriptCount-1]->declaringTraits;
00404 
00405         // ISSUE can we just make this the public namespace?
00406         ScopeChain* emptyScope = ScopeChain::create(GetGC(), mainTraits->scope, NULL, newNamespace(kEmptyString));
00407 
00408         VTable* object_vtable;
00409         if (toplevel == NULL)
00410         {
00411             // create a temp object vtable to use, since the real one isn't created yet
00412             // later, in OP_newclass, we'll replace with the real Object vtable, so methods
00413             // of Object and Class have the right scope.
00414 
00415             object_vtable = newVTable(traits.object_itraits, NULL, emptyScope, abcEnv, NULL);
00416             object_vtable->resolveSignatures();
00417             mainTraits->sizeofInstance = (uint32_t)getToplevelSize();
00418         }
00419         else
00420         {
00421             object_vtable = toplevel->object_vtable;
00422         }
00423 
00424         // global objects are subclasses of Object
00425         VTable* mainVTable = newVTable(mainTraits, object_vtable, emptyScope, abcEnv, toplevel);
00426         ScriptEnv* main = new (GetGC()) ScriptEnv(mainTraits->init, mainVTable);
00427         mainVTable->init = main;
00428 
00429         if (toplevel == NULL)
00430         {
00431             mainVTable->resolveSignatures();
00432             main->global = toplevel = createToplevel(mainVTable);
00433 
00434             // save toplevel since it was initially null 
00435             mainVTable->toplevel = toplevel;
00436             object_vtable->toplevel = toplevel;
00437             domainEnv->setToplevel(toplevel);
00438 
00439             // create temporary vtable for Class, so we have something for OP_newclass
00440             // to use when it creates Object$ and Class$.  once that happens, we replace
00441             // with the real Class$ vtable.
00442             toplevel->class_vtable = newVTable(traits.class_itraits, 
00443                 object_vtable, emptyScope, abcEnv, toplevel);
00444             toplevel->class_vtable->resolveSignatures();
00445 
00446             traits.function_itraits->resolveSignatures(toplevel);
00447         }
00448 
00449         exportDefs(mainTraits, main);
00450 
00451         // prepare the remaining scriptEnv's
00452         for (int i=0, n=pool->scriptCount-1; i < n; i++)
00453         {
00454             AbstractFunction* script = pool->scripts[i];
00455 
00456             Traits* scriptTraits = script->declaringTraits;
00457             // [ed] 3/24/06 why do we really care if a script is dynamic or not?
00458             //AvmAssert(scriptTraits->needsHashtable);
00459 
00460             VTable* scriptVTable = newVTable(scriptTraits, object_vtable, emptyScope, abcEnv, toplevel);
00461             ScriptEnv* scriptEnv = new (GetGC()) ScriptEnv(scriptTraits->init, scriptVTable);
00462             scriptVTable->init = scriptEnv;
00463             exportDefs(scriptTraits, scriptEnv);
00464         }
00465 
00466         return main;
00467     }

void avmplus::AvmCore::presweep  )  [virtual]
 

GCCallback functions

Definition at line 2608 of file AvmCore.cpp.

References AVMPLUS_STRING_DELETED, deletedCount, MMgc::GCRoot::GetGC(), numStrings, and stringCount.

02609     {
02610         // clear out the string table
02611         {
02612             for (int i=0, n=numStrings; i < n; i++)
02613             {
02614                 if (strings[i] > AVMPLUS_STRING_DELETED && !GetGC()->GetMark(strings[i]))
02615                 {
02616                     strings[i] = AVMPLUS_STRING_DELETED;
02617                     deletedCount++;
02618                     stringCount--;
02619                 }
02620             }
02621         }
02622 
02623 
02624         // do the same for the namespaces
02625         {
02626             bool rehashFlag = false;
02627             for (int i=0, n=numNamespaces; i < n; i++)
02628             {
02629                 if (namespaces[i] != NULL && !GetGC()->GetMark(namespaces[i]))
02630                 {
02631                     rehashFlag = true;
02632                     namespaces[i] = NULL;
02633                 }
02634             }
02635 
02636             // if any interned strings were freed, rehash the intern table
02637             // todo - make this less aggressive
02638             if (rehashFlag)
02639                 rehashNamespaces(numNamespaces);
02640         }
02641 
02642 #ifdef FEATURE_SAMPLER
02643         _sampler.presweep();
02644 #endif
02645     }

Atom avmplus::AvmCore::primitive Atom  atom  ) 
 

ES3's internal ToPrimitive() function

Definition at line 1337 of file AvmCore.cpp.

References atomToScriptObject(), avmplus::ScriptObject::defaultValue(), and isObject().

Referenced by compare().

01338     {
01339         return isObject(atom) ? atomToScriptObject(atom)->defaultValue() : atom;
01340     }

static void avmplus::AvmCore::readOperands const byte *&  pc,
unsigned int &  imm32,
int &  imm24,
unsigned int &  imm32b,
int &  imm8
[inline, static]
 

Read in some operands for the instruction located at *pc. Returns the size of the instruction, but will not read in all the case targets for an OP_lookupswitch, since there will be a variable number of them.

Definition at line 822 of file AvmCore.h.

References avmplus::ActionBlockConstants::OP_debug, avmplus::ActionBlockConstants::OP_ifnlt, avmplus::ActionBlockConstants::OP_lookupswitch, avmplus::ActionBlockConstants::OP_pushbyte, avmplus::ActionBlockConstants::opOperandCount, avmplus::readS24(), and avmplus::readU30().

Referenced by calculateInstructionWidth().

00823         {
00824             AbcOpcode opcode = (AbcOpcode)*pc++;
00825             int op_count = opOperandCount[opcode];
00826 
00827             imm8 = pc[0];
00828             if( opcode == OP_pushbyte || opcode == OP_debug )
00829             {
00830                 // these two operands have a byte as their first operand, which is not encoded
00831                 // with the variable length encoding scheme for bigger numbers, because it will
00832                 // never be larger than a byte.
00833                 --op_count;
00834                 pc++;
00835             }
00836 
00837             if( op_count > 0 )
00838             {
00839                 if( opcode >= OP_ifnlt && opcode <= OP_lookupswitch )
00840                 {
00841                     imm24 = AvmCore::readS24(pc);
00842                     pc += 3;
00843                 }
00844                 else
00845                 {
00846                     imm32 = AvmCore::readU30(pc);
00847                 }
00848 
00849                 if( opcode == OP_debug )
00850                 {
00851                     --op_count; //OP_debug has a third operand of a byte
00852                     pc++;
00853                 }
00854                 if( op_count > 1 )
00855                 {
00856                     imm32b = AvmCore::readU30(pc);
00857                 }
00858             }
00859         }

static int avmplus::AvmCore::readS24 const byte pc  )  [inline, static]
 

Helper function; reads a signed 24-bit integer from pc

Definition at line 794 of file AvmCore.h.

00795         {
00796             #ifdef AVMPLUS_UNALIGNED_ACCESS
00797                 // unaligned short access still faster than 2 byte accesses
00798                 return ((uint16_t*)pc)[0] | ((int8_t*)pc)[2]<<16;
00799             #else
00800                 return pc[0] | pc[1]<<8 | ((int8_t*)pc)[2]<<16;
00801             #endif
00802         }

static int32_t avmplus::AvmCore::readU16 const byte pc  )  [inline, static]
 

Helper function; reads an unsigned 16-bit integer from pc

Definition at line 900 of file AvmCore.h.

Referenced by avmplus::AbcParser::AbcParser(), avmplus::AbcParser::decodeAbc(), and avmplus::PoolObject::PoolObject().

00901         {
00902             #ifdef AVMPLUS_UNALIGNED_ACCESS
00903                 // unaligned short access still faster than 2 byte accesses
00904                 return *((uint16_t*)pc);
00905             #else
00906                 return pc[0] | pc[1]<<8;
00907             #endif
00908         }

static uint32 avmplus::AvmCore::readU30 const byte *&  p  )  [inline, static]
 

Helper function; reads an unsigned 32-bit integer from pc See AbcParser::readS32 for more explanation of the variable length encoding scheme.

2nd argument is set to the actual size, in bytes, of the number read in, and third argument is the version of the ABC

Definition at line 868 of file AvmCore.h.

Referenced by avmplus::PoolObject::parseMultiname(), and avmplus::PoolObject::resolveTraits().

00869         {
00870             unsigned int result = p[0];
00871             if (!(result & 0x00000080))
00872             {
00873                 p++;
00874                 return result;
00875             }
00876             result = (result & 0x0000007f) | p[1]<<7;
00877             if (!(result & 0x00004000))
00878             {
00879                 p += 2;
00880                 return result;
00881             }
00882             result = (result & 0x00003fff) | p[2]<<14;
00883             if (!(result & 0x00200000))
00884             {
00885                 p += 3;
00886                 return result;
00887             }
00888             result = (result & 0x001fffff) | p[3]<<21;
00889             if (!(result & 0x10000000))
00890             {
00891                 p += 4;
00892                 return result;
00893             }
00894             result = (result & 0x0fffffff) | p[4]<<28;
00895             p += 5;
00896             return result;
00897         }

void avmplus::AvmCore::registerNatives NativeTableEntryp  nativeMap,
AbstractFunction nativeMethods[]
[private]
 

Definition at line 1889 of file AvmCore.cpp.

References AvmAssert, avmplus::NativeTableEntry::cookie, runtests::f, avmplus::NativeTableEntry::flags, MMgc::GCRoot::GetGC(), avmplus::NativeTableEntry::handler, and avmplus::NativeTableEntry::method_id.

Referenced by initNativeTables().

01890     {
01891         while (nativeMap->method_id != -1)
01892         {
01893 #ifdef AVMTHUNK_VERSION
01894             AbstractFunction* f = new (GetGC()) NativeMethod(*nativeMap);
01895 #else
01896             AbstractFunction* f = new (GetGC()) NativeMethod(nativeMap->flags, (NativeMethod::Handler)nativeMap->handler, nativeMap->cookie);
01897 #endif
01898                             
01899             // if we overwrite a native method mapping, something is hosed
01900             AvmAssert(nativeMethods[nativeMap->method_id]==NULL);
01901             nativeMethods[nativeMap->method_id] = f;
01902             nativeMap++;
01903         }
01904     }

void avmplus::AvmCore::rehashNamespaces int  newlen  ) 
 

Definition at line 3051 of file AvmCore.cpp.

References DRC(), findNamespace(), numNamespaces, and configure::o.

Referenced by findNamespace().

03052     {
03053         // rehash
03054 
03055         DRC(Namespacep) *old = namespaces;
03056         int oldCount = numNamespaces;
03057 
03058         namespaces = new DRC(Namespacep)[newlen];
03059         memset(namespaces, 0, newlen*sizeof(Namespace*));
03060         numNamespaces = newlen;
03061         
03062         for (int i=0; i < oldCount; i++)
03063         {
03064             Namespace* o = old[i];
03065             if (o != NULL)
03066                 namespaces[findNamespace(o)] = o;
03067         }
03068 
03069         // Clear old namespaces table so it can be collected.
03070         delete [] old;
03071     }

void avmplus::AvmCore::rehashStrings int  newlen  ) 
 

Definition at line 2988 of file AvmCore.cpp.

References AVMPLUS_STRING_DELETED, deletedCount, DRC(), avmplus::hashString(), build::dependparser::m, numStrings, and configure::o.

Referenced by findString().

02989     {
02990         // rehash
02991 
02992         DRC(Stringp) *oldStrings = strings;
02993         int oldStringCount = numStrings;
02994 
02995         strings = new DRC(Stringp)[newlen];
02996         memset(strings, 0, newlen*sizeof(Stringp));
02997         numStrings = newlen;
02998 
02999 #ifdef _DEBUG // debug sanity checks
03000         int oldDeletedCount = deletedCount;
03001         int computedDeleteCount = 0;
03002         int computedStringCount = 0;
03003 #endif
03004 
03005         deletedCount = 0;
03006 
03007         // Inlined and optimized our findString routine.  We know that there
03008         // are no duplicated strings in our intern string table so we don't 
03009         // need to call Equals.  All we need to do is find the first blank
03010         // spot available.
03011         int m = numStrings;
03012         int bitMask = m - 1;
03013 
03014         for (int i=0; i < oldStringCount; i++)
03015         {
03016             Stringp o = oldStrings[i];
03017             if (o > AVMPLUS_STRING_DELETED)
03018             {
03019                 // compute the hash function
03020                 int hashCode = hashString(o->c_str(), o->length());
03021 
03022                 // find the slot to use
03023                 int j = (hashCode&0x7FFFFFFF) & bitMask;
03024                 int n = 7;
03025                 while (strings[j] != NULL) {
03026                     j = (j + (n++)) & bitMask; // quadratic probe
03027                 }
03028 
03029                 strings[j] = o;
03030 #ifdef _DEBUG
03031                 computedStringCount++;
03032 #endif
03033             }
03034 #ifdef _DEBUG
03035             else if (o == AVMPLUS_STRING_DELETED)
03036             {
03037                 computedDeleteCount++;
03038             }
03039 #endif
03040         }
03041 
03042 #ifdef _DEBUG
03043         AvmAssert(computedStringCount == stringCount);
03044         AvmAssert(oldDeletedCount == computedDeleteCount);
03045 #endif
03046 
03047         // Clear oldStrings so it can be collected.
03048         delete [] oldStrings;
03049     }

void avmplus::AvmCore::setConsoleStream OutputStream stream  ) 
 

Redirects the standard output of the VM to the specified output stream. Output from print() statements and error messages will be sent here.

Parameters:
stream output stream to use for console output

Definition at line 1884 of file AvmCore.cpp.

References console, and avmplus::PrintWriter::setOutputStream().

01885     {
01886         console.setOutputStream(stream);
01887     }

void avmplus::AvmCore::SetMIREnabled bool  isEnabled  )  [inline]
 

Definition at line 252 of file AvmCore.h.

References config, and avmplus::Config::turbo.

00253         {
00254             config.turbo = isEnabled;
00255         }

virtual void avmplus::AvmCore::setStackBase  )  [inline, virtual]
 

This method will be invoked when the first exception frame is set up. This will be a good point to set minstack.

Definition at line 274 of file AvmCore.h.

Referenced by avmplus::ExceptionFrame::beginTry().

00274 {}

virtual void avmplus::AvmCore::stackOverflow MethodEnv env  )  [pure virtual]
 

This is called when the stack overflows (when the machine stack pointer is about to go below minstack)

Implemented in axtam::AXTam, and avmshell::Shell.

Referenced by _stackOverflow(), avmplus::interp(), and avmplus::MethodEnv::stkover().

Atom avmplus::AvmCore::stricteq Atom  lhs,
Atom  rhs
 

Implementation of OP_strictequals

Definition at line 831 of file AvmCore.cpp.

References atomToDouble(), atomToXML(), avmplus::AtomConstants::falseAtom, isNull(), isXML(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, avmplus::AtomConstants::kStringType, number(), string(), and avmplus::AtomConstants::trueAtom.

Referenced by avmplus::ArrayClass::indexOf(), and avmplus::ArrayClass::lastIndexOf().

00832     {
00833         if (isNull(lhs)) return isNull(rhs) ? trueAtom : falseAtom;
00834         if (isNull(rhs)) return falseAtom; // We already know that lhs is not null
00835 
00836         int ltype = lhs & 7;
00837         int rtype = rhs & 7;
00838         if (ltype == rtype)
00839         {
00840             // same type
00841             switch (ltype)
00842             {
00843             case kSpecialType:
00844                 return trueAtom; // undefined is the only kSpecialType atom 
00845             case kStringType:
00846                 return (lhs==rhs || *string(lhs) == *string(rhs)) ? trueAtom : falseAtom;
00847             case kBooleanType:
00848             case kIntegerType:
00849             case kNamespaceType:
00850                 return lhs == rhs ? trueAtom : falseAtom;
00851             case kObjectType:
00852             {
00853                 if (lhs == rhs)
00854                     return trueAtom;
00855                 if (isXML(lhs) && isXML(rhs))
00856                 {
00857                     E4XNode *lhn = atomToXML (lhs);
00858                     E4XNode *rhn = atomToXML (rhs);
00859                     return ((lhn == rhn) ? trueAtom : falseAtom);
00860                 }
00861                 return falseAtom;
00862             }   
00863             case kDoubleType:
00864                 // C++ portability note -- if either arg is NaN, java == returns false, which matches ECMA.
00865                 return atomToDouble(lhs) == atomToDouble(rhs) ? trueAtom : falseAtom;
00866             }
00867         }
00868         // Sometimes ints can hide in double atoms (neg zero for one)
00869         else if ((ltype == kIntegerType) && (rtype == kDoubleType) || 
00870             (rtype == kIntegerType) && (ltype == kDoubleType))
00871         {
00872             return number(lhs) == number(rhs) ? trueAtom : falseAtom;
00873         }
00874 
00875         return falseAtom;
00876     }

Stringp avmplus::AvmCore::string Atom  atom  ) 
 

Returns the passed atom's string representation. If the passed atom is not a string, it is coerced to type string using the ECMAScript coercion rules.

Definition at line 1851 of file AvmCore.cpp.

References atomToDouble(), atomToNamespace(), atomToScriptObject(), atomToString(), doubleToString(), avmplus::Namespace::getURI(), intToString(), isNull(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, and avmplus::AtomConstants::kStringType.

Referenced by avmplus::Toplevel::add2(), avmplus::RegExpObject::call(), avmplus::XMLObject::callProperty(), avmplus::ArraySort::CaseInsensitiveStringCompare(), avmplus::XMLObject::child(), avmplus::Toplevel::coerce(), coerce_s(), compare(), avmplus::StringClass::construct(), avmplus::NamespaceClass::construct(), avmplus::DateClass::construct(), equals(), EscapeAttributeValue(), avmplus::ArraySort::FieldCompare(), avmplus::VectorBaseObject::getAtomProperty(), avmplus::XMLObject::getNamespace(), isXMLName(), avmplus::StringClass::match(), newNamespace(), avmplus::XMLObject::NodeNameEquals(), avmplus::DateClass::parse(), avmplus::RegExpObject::replace(), avmplus::StringClass::search(), avmplus::ErrorObject::stackTraceToString(), stricteq(), avmplus::ArraySort::StringCompare(), avmplus::Toplevel::ToAttributeName(), avmplus::XMLObject::toString(), avmplus::XMLListObject::toString(), avmplus::ScriptObject::toString(), avmplus::Toplevel::ToXMLName(), ToXMLString(), and avmplus::XMLObject::XMLObject().

01852     {
01853         if (!isNull(atom))
01854         {
01855             switch (atom&7)
01856             {
01857             case kNamespaceType:
01858                 return atomToNamespace(atom)->getURI();
01859             case kObjectType:
01860                 return string(atomToScriptObject(atom)->toString());
01861             case kStringType:
01862                 return atomToString(atom);
01863             case kSpecialType:
01864                 return kundefined;
01865             case kBooleanType:
01866                 return booleanStrings[atom>>3];
01867             case kIntegerType:
01868 #ifdef AVMPLUS_64BIT
01869                 return intToString (int(intptr_t(atom)>>3));
01870 #else
01871                 return intToString (int(sint32(atom)>>3));
01872 #endif
01873             case kDoubleType:
01874             default: // number
01875                 return doubleToString(atomToDouble(atom));
01876             }
01877         }
01878         else
01879         {
01880             return knull;
01881         }
01882     }

void avmplus::AvmCore::throwAtom Atom  atom  ) 
 

Throws an exception. Constructs an Exception object and calls throwException.

Definition at line 925 of file AvmCore.cpp.

References MMgc::GCRoot::GetGC(), and throwException().

Referenced by axtam::COMErrorClass::throwError(), and throwErrorV().

00926     {
00927         throwException(new (GetGC()) Exception(atom
00928 #ifdef DEBUGGER
00929             , this
00930 #endif
00931             ));
00932     }

void avmplus::AvmCore::throwErrorV ClassClosure type,
int  errorID,
Stringp  arg1 = 0,
Stringp  arg2 = 0,
Stringp  arg3 = 0
 

throwErrorV is a convenience function for throwing an exception with a formatted error message,

Definition at line 1252 of file AvmCore.cpp.

References runtests::args, avmplus::String::atom(), console, avmplus::ClassClosure::construct(), formatErrorMessageV(), intToAtom(), avmplus::AtomConstants::nullObjectAtom, and throwAtom().

Referenced by avmplus::ErrorClass::throwError(), and avmplus::Verifier::verifyFailed().

01253     {
01254         Stringp out = formatErrorMessageV( errorID, arg1, arg2, arg3);
01255 
01256         #ifdef DEBUGGER
01257         if (type == NULL)
01258         {
01259             // print the error message, because we're still bootstrapping
01260             // and the exception type is not yet defined
01261             console << out << "\n";
01262         }
01263         #endif
01264 
01265         Atom args[3] = { nullObjectAtom, out->atom(), intToAtom(errorID) };
01266         throwAtom(type->construct(2, args));
01267     }

void avmplus::AvmCore::throwException Exception exception  ) 
 

The AVM+ equivalent of the C++ "throw" statement. Throws an exception, transferring control to the nearest CATCH block.

Definition at line 883 of file AvmCore.cpp.

References AvmAssert, exceptionFrame, avmplus::Exception::flags, and avmplus::ExceptionFrame::throwException().

Referenced by findExceptionHandler(), handleActionPool(), avmplus::XMLObject::issueNotifications(), avmplus::AbcParser::parse(), throwAtom(), avmplus::NativeMethod::verify(), and avmplus::MethodInfo::verify().

00884     {
00885         #ifdef DEBUGGER
00886         if (debugger && !(exception->flags & Exception::SEEN_BY_DEBUGGER))
00887         {
00888             // I'm going to set the SEEN_BY_DEBUGGER flag now, before calling
00889             // filterException(), just to avoid reentrancy problems (we don't
00890             // want to end up back here with the same Exception object and get
00891             // stuck in an infinite loop).
00892             exception->flags |= Exception::SEEN_BY_DEBUGGER;
00893 
00894             bool willBeCaught = willExceptionBeCaught(exception);
00895 
00896             if (passAllExceptionsToDebugger || !willBeCaught)
00897             {
00898                 // filterException() returns 'true' if it somehow let the user know
00899                 // about the exception, 'false' if it ignored the exception.
00900                 if (debugger->filterException(exception, willBeCaught))
00901                     exception->flags |= Exception::SEEN_BY_DEBUGGER;
00902                 else
00903                     exception->flags &= ~Exception::SEEN_BY_DEBUGGER;
00904             }
00905             else
00906             {
00907                 exception->flags &= ~Exception::SEEN_BY_DEBUGGER;
00908             }
00909         }
00910         #endif
00911 
00912         // exceptionFrame should not be NULL; if it is,
00913         // you are missing a TRY/CATCH block around
00914         // a call to an AVM+ method that throws an
00915         // exception.
00916         AvmAssert(exceptionFrame != NULL);
00917         exceptionFrame->throwException(exception);
00918     }

String * avmplus::AvmCore::toErrorString const wchar s  ) 
 

Definition at line 1122 of file AvmCore.cpp.

References newString().

01123     {
01124         String* out = NULL;
01125     #ifdef DEBUGGER
01126         if (s)
01127             out = this->newString(s);
01128         else
01129             out = kEmptyString;
01130     #else
01131         out = kEmptyString;
01132         (void)s;
01133     #endif /* DEBUGGER */
01134         return out;
01135     }

String * avmplus::AvmCore::toErrorString const char *  s  ) 
 

Definition at line 1107 of file AvmCore.cpp.

References newString().

01108     {
01109         String* out = NULL;
01110     #ifdef DEBUGGER
01111         if (s)
01112             out = this->newString(s);
01113         else
01114             out = kEmptyString;
01115     #else
01116         out = kEmptyString;
01117         (void)s;
01118     #endif /* DEBUGGER */
01119         return out;
01120     }

String * avmplus::AvmCore::toErrorString Traits t  ) 
 

Definition at line 1182 of file AvmCore.cpp.

References avmplus::BuiltinTraits::class_itraits, concatStrings(), avmplus::Traits::itraits, newString(), toErrorString(), and traits.

01183     {
01184         #ifndef DEBUGGER
01185         (void)t;
01186         return kEmptyString;
01187         #else
01188         if (!t)
01189         {
01190             return newString("*");
01191         }
01192 
01193         String* s = NULL;
01194         if (t->base == traits.class_itraits)
01195         {
01196             t = t->itraits;
01197             s = newString("class ");
01198         }
01199         else
01200         {
01201             s = kEmptyString;
01202         }
01203 
01204         if (t->ns != NULL && t->ns != publicNamespace)
01205             s = concatStrings(s, concatStrings(toErrorString(t->ns), newString("."))); 
01206 
01207         if (t->name)
01208             s = concatStrings(s, t->name);
01209         else
01210             s = concatStrings(s, newString("(null)"));
01211         return s;
01212         #endif /* DEBUGGER */
01213     }

String * avmplus::AvmCore::toErrorString Namespace ns  ) 
 

Definition at line 1167 of file AvmCore.cpp.

References avmplus::Namespace::format().

01168     {
01169         String* s = NULL;
01170     #ifdef DEBUGGER
01171         if (ns) 
01172             s = ns->format(this);
01173         else
01174             s = kEmptyString;
01175     #else
01176         s = kEmptyString;
01177         (void)ns;
01178     #endif /* DEBUGGER */
01179         return s;
01180     }

String * avmplus::AvmCore::toErrorString const Multiname n  ) 
 

Definition at line 1152 of file AvmCore.cpp.

References avmplus::Multiname::format(), and avmplus::Multiname::MULTI_FORMAT_NAME_ONLY.

01153     {
01154         String* s = NULL;
01155     #ifdef DEBUGGER
01156         if (n) 
01157             s = n->format(this, Multiname::MULTI_FORMAT_NAME_ONLY);
01158         else
01159             s = kEmptyString;
01160     #else
01161         s = kEmptyString;
01162         (void)n;
01163     #endif /* DEBUGGER */
01164         return s;
01165     }

String * avmplus::AvmCore::toErrorString AbstractFunction m  ) 
 

Definition at line 1137 of file AvmCore.cpp.

References build::dependparser::m.

01138     {
01139         String* s = NULL;
01140     #ifdef DEBUGGER
01141         if (m) 
01142             s = m->format(this);
01143         else
01144             s = kEmptyString;
01145     #else
01146         s = kEmptyString;
01147         (void)m;
01148     #endif /* DEBUGGER */
01149         return s;
01150     }

String * avmplus::AvmCore::toErrorString int  d  ) 
 

Convenience methods for converting various objects into value strings used for error message output.

Definition at line 1089 of file AvmCore.cpp.

References buffer, avmplus::MathUtils::convertIntegerToString(), and newString().

Referenced by avmplus::ClassClosure::call(), avmplus::ClassClosure::call_this(), avmplus::ClassClosure::call_this_a(), avmplus::Verifier::checkClassInfo(), avmplus::Verifier::checkCpoolOperand(), avmplus::Verifier::checkDispId(), avmplus::Verifier::checkEarlyMethodBinding(), avmplus::Verifier::checkEarlySlotBinding(), avmplus::Verifier::checkLocal(), avmplus::Verifier::checkMethodInfo(), avmplus::Verifier::checkSlot(), avmplus::Verifier::checkTarget(), avmplus::Verifier::checkTypeName(), avmplus::Toplevel::coerceobj(), avmplus::Toplevel::constructprop(), avmplus::NumberClass::convert(), avmplus::AbcParser::decodeAbc(), avmplus::Toplevel::decodeURI(), avmplus::Toplevel::decodeURIComponent(), avmplus::ScriptObject::defaultValue(), avmplus::Verifier::emitCoerceArgs(), avmplus::Verifier::emitCoerceSuper(), avmplus::Verifier::emitGetGlobalScope(), avmplus::Verifier::emitGetOuterScope(), avmplus::Toplevel::encodeURI(), avmplus::Toplevel::encodeURIComponent(), avmplus::Verifier::findCommonBase(), avmplus::E4XNode::FindNamespace(), avmplus::initMultinameNoXMLList(), avmshell::DomainObject::loadBytes(), axtam::DomainObject::loadBytes(), avmplus::NumberClass::numberToString(), avmplus::AbcParser::parseInstanceInfos(), avmplus::AbcParser::parseMethodBodies(), avmplus::AbcParser::parseNsRef(), avmplus::AbcParser::parseScriptInfos(), avmplus::Verifier::peekType(), avmplus::AbcParser::resolveMethodInfo(), avmplus::PoolObject::resolveQName(), avmplus::AbcParser::resolveQName(), avmplus::PoolObject::resolveTraits(), avmplus::PoolObject::resolveTypeName(), avmplus::AbcParser::resolveUtf8(), avmplus::TraceClass::setListener(), avmplus::ArrayClass::sort(), avmplus::MethodEnv::startCoerce(), toErrorString(), and avmplus::ScriptObject::toString().

01090     {
01091         String* s = NULL;
01092     #ifdef DEBUGGER
01093         wchar buffer[256];
01094         buffer[255] = '\0';
01095         int len;
01096         if (MathUtils::convertIntegerToString(d, buffer, len)) 
01097             s = this->newString(buffer);
01098         else
01099             s = kEmptyString;
01100     #else
01101         s = kEmptyString;
01102         (void)d;
01103     #endif /* DEBUGGER */
01104         return s;
01105     }

double avmplus::AvmCore::toInteger Atom  atom  )  const [inline]
 

toInteger is the ToInteger algorithm from ECMA-262 section 9.4, used in many of the native core objects

Definition at line 654 of file AvmCore.h.

References avmplus::AtomConstants::kIntegerType, number(), and avmplus::MathUtils::toInt().

Referenced by avmplus::ArraySort::ScriptCompare(), and avmplus::ArrayClass::splice().

00655         {
00656             if ((atom & 7) == kIntegerType) {
00657                 return (double) (atom>>3);
00658             } else {
00659                 return MathUtils::toInt(number(atom));
00660             }
00661         }

uint32 avmplus::AvmCore::toUInt32 Atom  atom  )  const [inline]
 

toUInt32 is the ToUInt32 algorithm from ECMA-262 section 9.6, used in many of the native core objects

Definition at line 644 of file AvmCore.h.

References integer().

Referenced by axtam::COMErrorObject::getHRESULT(), avmplus::ArrayClass::getLengthHelper(), avmplus::ArrayObject::setAtomProperty(), uintAtom(), and avmplus::MethodEnv::unbox1().

00645         {
00646             return (uint32)integer(atom);
00647         }

Stringp avmplus::AvmCore::ToXMLString Atom  a  ) 
 

Definition at line 2391 of file AvmCore.cpp.

References atomToXMLList(), atomToXMLObject(), EscapeElementValue(), isNull(), isXML(), isXMLList(), avmplus::AtomConstants::kBooleanType, avmplus::AtomConstants::kDoubleType, avmplus::AtomConstants::kIntegerType, avmplus::AtomConstants::kNamespaceType, avmplus::AtomConstants::kObjectType, avmplus::AtomConstants::kSpecialType, avmplus::AtomConstants::kStringType, string(), avmplus::XMLListObject::toXMLString(), and avmplus::XMLObject::toXMLString().

02392     {
02393         if (!isNull(a))
02394         {
02395             switch (a&7)
02396             {
02397             case kStringType:
02398                 return EscapeElementValue (string(a), true);
02399             case kObjectType:
02400             case kNamespaceType:
02401                 if (isXML(a))
02402                 {
02403                     XMLObject *x = atomToXMLObject (a);
02404                     return x->toXMLString();
02405                 }
02406                 else if (isXMLList(a))
02407                 {
02408                     XMLListObject *x = atomToXMLList (a);
02409                     return x->toXMLString();
02410                 }
02411                 else
02412                 {
02413                     // !!@ to primitive (hint string first)
02414                     // !!@ namespace case falls into this as well
02415                     return EscapeElementValue (string(a), true);
02416                 }
02417                 break;
02418             case kSpecialType:
02419                 return kundefined;
02420             case kIntegerType:
02421             case kBooleanType:
02422             case kDoubleType:
02423             default:
02424                 return string(a);
02425             }
02426         }
02427         else
02428         {
02429             return knull;
02430         }
02431     }

Atom avmplus::AvmCore::uintAtom Atom  atom  )  [inline]
 

Definition at line 741 of file AvmCore.h.

References toUInt32(), and uintToAtom().

Referenced by avmplus::Toplevel::coerce(), and avmplus::UIntClass::construct().

00742         {
00743             return uintToAtom(toUInt32(atom));
00744         }

Atom avmplus::AvmCore::uintToAtom uint32  n  ) 
 

Definition at line 3176 of file AvmCore.cpp.

References allocDouble(), and avmplus::AtomConstants::kIntegerType.

Referenced by avmplus::AbstractFunction::boxArgs(), avmplus::ScriptObject::delUintProperty(), avmplus::MethodEnv::endCoerce(), avmplus::VectorBaseObject::filter(), avmplus::ScriptObject::getSlotAtom(), avmplus::ScriptObject::getUintProperty(), avmplus::ScriptObject::hasUintProperty(), avmplus::VectorBaseObject::map(), avmplus::ArrayClass::map(), avmplus::RegExpObject::replace(), avmplus::ArrayClass::setLengthHelper(), avmplus::ScriptObject::setUintProperty(), and uintAtom().

03177     {
03178 #ifdef AVMPLUS_64BIT
03179         // We can always fit the value in an Atom
03180         return (((Atom)n)<<3) | kIntegerType;
03181 #else
03182         // As kIntegerType is signed, we can only represent a 28-bit uint in it
03183         if (!(n&0xF0000000)) {
03184             return uint32((n<<3) | kIntegerType);
03185         } else {
03186             return allocDouble(n);
03187         }
03188 #endif
03189     }

Stringp avmplus::AvmCore::uintToString uint32  i  ) 
 

Definition at line 3481 of file AvmCore.cpp.

References avmplus::MathUtils::convertDoubleToString(), avmplus::MathUtils::convertIntegerToString(), and MMgc::GCRoot::GetGC().

03482     {
03483         wchar buffer[65];
03484         int len;
03485         if (value <= 0x7FFFFFFF)
03486             MathUtils::convertIntegerToString(value, buffer, len);
03487         else
03488             MathUtils::convertDoubleToString(value, buffer, len);
03489         return new (GetGC()) String(buffer, len);
03490     }


Member Data Documentation

Domain* avmplus::AvmCore::builtinDomain
 

Domain for built-in classes

Definition at line 286 of file AvmCore.h.

Referenced by avmshell::DomainObject::constructFromDomain(), axtam::DomainObject::constructFromDomain(), handleActionBlock(), initBuiltinPool(), and prepareActionPool().

PoolObject* avmplus::AvmCore::builtinPool
 

PoolObject for built-in classes

Definition at line 283 of file AvmCore.h.

Referenced by initBuiltinPool(), initTopLevel(), and avmplus::Toplevel::resolveBuiltinClass().

CallStackNode* avmplus::AvmCore::callStack
 

The call stack of currently executing code.

Definition at line 1062 of file AvmCore.h.

Referenced by avmplus::ExceptionFrame::beginCatch(), and avmplus::ExceptionFrame::beginTry().

CodeContextAtom avmplus::AvmCore::codeContextAtom
 

Definition at line 1076 of file AvmCore.h.

Referenced by avmplus::ExceptionFrame::beginCatch(), avmplus::ExceptionFrame::beginTry(), codeContext(), avmplus::ExceptionFrame::endTry(), avmplus::EnterCodeContext::finish(), avmplus::EnterCodeContext::initialize(), and avmplus::interp().

Config avmplus::AvmCore::config
 

Definition at line 240 of file AvmCore.h.

Referenced by avmplus::AbcParser::decodeAbc(), findExceptionHandlerNoRethrow(), IsMIREnabled(), avmplus::AbcParser::parseCpool(), avmplus::AbcParser::parseScriptInfos(), and SetMIREnabled().

PrintWriter avmplus::AvmCore::console
 

The console object. Text to be displayed to the developer or end-user can be directed to console, much like the cout object in C++ iostreams.

The console object is a wrapper around the console output stream specified by the setConsoleStream method. Programs embedding AVM+ will typically implement the OutputStream interface and pass it in via setConsoleStream.

Definition at line 171 of file AvmCore.h.

Referenced by avmplus::Toplevel::callproperty(), avmplus::MethodEnv::callsuper(), avmplus::Traits::checkOverride(), avmplus::Toplevel::constructprop(), avmplus::AbcParser::decodeAbc(), avmplus::Verifier::emitGetGlobalScope(), avmplus::Verifier::emitGetOuterScope(), avmplus::Verifier::emitGetProperty(), exportDefs(), findExceptionHandlerNoRethrow(), avmplus::Traits::getOverride(), avmplus::Toplevel::getproperty(), avmplus::interp(), avmplus::VTable::makeMethodEnv(), avmplus::AbstractFunction::makeMethodOf(), avmplus::MethodEnv::MethodEnv(), avmplus::AbcParser::parseClassInfos(), avmplus::AbcParser::parseCpool(), avmplus::Verifier::parseExceptionHandlers(), avmplus::AbcParser::parseInstanceInfos(), avmplus::AbcParser::parseMetadataInfos(), avmplus::AbcParser::parseMethodBodies(), avmplus::AbcParser::parseMethodInfos(), avmplus::AbcParser::parseScriptInfos(), avmplus::AbcParser::parseTraits(), avmplus::VTable::resolveSignatures(), setConsoleStream(), avmplus::Toplevel::setproperty_b(), avmplus::MethodEnv::setsuper(), and throwErrorV().

int avmplus::AvmCore::deletedCount [private]
 

number of deleted entries in our String table

Definition at line 1209 of file AvmCore.h.

Referenced by findString(), internAlloc(), internAllocUtf8(), internString(), presweep(), and rehashStrings().

Namespace* const* avmplus::AvmCore::dxnsAddr
 

The location of the currently active defaultNamespace

Definition at line 289 of file AvmCore.h.

Referenced by avmplus::ExceptionFrame::beginCatch(), avmplus::ExceptionFrame::beginTry(), avmplus::Toplevel::getDefaultNamespace(), avmplus::interp(), avmplus::MethodEnv::newclass(), and avmplus::MethodEnv::newfunction().

Exception* avmplus::AvmCore::exceptionAddr
 

Definition at line 1083 of file AvmCore.h.

Referenced by avmplus::ExceptionFrame::throwException().

ExceptionFrame* avmplus::AvmCore::exceptionFrame
 

env of the highest catch handler on the call stack, or NULL

Definition at line 1081 of file AvmCore.h.

Referenced by avmplus::ExceptionFrame::beginCatch(), avmplus::ExceptionFrame::beginTry(), avmplus::ExceptionFrame::endTry(), and throwException().

MMgc::GC* const avmplus::AvmCore::gc
 

The GC used by this AVM instance

Reimplemented from MMgc::GCRoot.

Definition at line 186 of file AvmCore.h.

Referenced by atomWriteBarrier(), avmplus::NewObjectSampleClass::createInstance(), avmplus::SampleClass::createInstance(), gcObjectToAtom(), and ~AvmCore().

GCInterface avmplus::AvmCore::gcInterface [private]
 

Definition at line 1413 of file AvmCore.h.

int avmplus::AvmCore::interrupted
 

If this flag is set, an interrupt is in progress. This must be type int, not bool, since it will be checked by generated code.

Definition at line 296 of file AvmCore.h.

Referenced by avmshell::alarmProc(), and branchCheck().

Atom avmplus::AvmCore::kNaN
 

Definition at line 612 of file AvmCore.h.

Referenced by number(), and numberAtom().

uintptr avmplus::AvmCore::minstack
 

If this is set to a nonzero value, executing code will check the stack pointer to make sure it doesn't go below this value.

Definition at line 267 of file AvmCore.h.

Referenced by avmplus::interp().

VTable* avmplus::AvmCore::namespaceVTable
 

Definition at line 303 of file AvmCore.h.

int avmplus::AvmCore::nsCount [private]
 

size of interned Namespace table

Definition at line 1213 of file AvmCore.h.

Referenced by findNamespace().

int avmplus::AvmCore::numNamespaces [private]
 

Definition at line 1216 of file AvmCore.h.

Referenced by findNamespace(), and rehashNamespaces().

int avmplus::AvmCore::numStrings [private]
 

Definition at line 1215 of file AvmCore.h.

Referenced by findString(), presweep(), and rehashStrings().

Hashtable* avmplus::AvmCore::resources
 

The resources table tracks what ABC's have been decoded, and avoids decoding the same one multiple times.

Definition at line 566 of file AvmCore.h.

Referenced by handleActionBlock().

int avmplus::AvmCore::stringCount [private]
 

size of interned String table

Definition at line 1206 of file AvmCore.h.

Referenced by findString(), internAlloc(), internAllocUtf8(), internString(), and presweep().

BuiltinTraits avmplus::AvmCore::traits
 

Container object for traits of built-in classes

Definition at line 280 of file AvmCore.h.

Referenced by avmplus::QNameClass::call(), avmplus::Traits::checkOverride(), avmplus::QNameClass::construct(), axtam::DomainObject::constructFromDomain(), avmplus::PrintWriter::formatTypeName(), avmplus::MethodEnv::getdescendantslate(), avmplus::DictionaryObject::getKeyFromObject(), avmplus::initMultiname(), avmplus::Toplevel::instanceof(), isDate(), isFunction(), avmplus::Traits::isMachineCompatible(), isQName(), istype(), isXML(), avmplus::Toplevel::isXmlBase(), isXMLList(), avmplus::AbstractFunction::makeIntoPrototypeFunction(), avmplus::StringClass::match(), avmplus::MethodEnv::newcatch(), newTraits(), newVTable(), avmplus::AbcParser::parse(), prepareActionPool(), avmplus::StringClass::replace(), avmplus::PoolObject::resolveParameterizedType(), avmplus::StringClass::search(), avmplus::TraceClass::setListener(), avmplus::XMLObject::setNotification(), avmplus::ArrayClass::sort(), toErrorString(), and avmplus::Toplevel::toTraits().

Hashtable* avmplus::AvmCore::xmlEntities
 

The XML entities table, used by E4X

Definition at line 1193 of file AvmCore.h.

Referenced by avmplus::XMLParser::XMLParser().


The documentation for this class was generated from the following files:
Generated on Sun Oct 12 18:51:05 2008 for Tamarin by  doxygen 1.4.6