// this = argv[0] (ignored) // arg1 = argv[1] // argN = argv[argc] Atom NamespaceClass::construct(int argc, Atom* argv) { AvmCore* core = this->core(); // See E4X 13.2.2, pg 65 if (argc < 1) return core->newNamespace(core->kEmptyString->atom())->atom(); else if (argc == 1) return core->newNamespace(argv[1])->atom(); else { // Rhino throws an error when prefix is specified and uri is not a valid string String *p = core->string (argv[1]); String *u = core->string (argv[2]); if (p->length() && !u->length()) { toplevel()->throwTypeError(kXMLNamespaceWithPrefixAndNoURI, p); } return core->newNamespace(argv[1], argv[2])->atom(); } }
ClassClosure* DomainObject::getClass(Stringp name) { AvmCore *core = this->core(); if (name == NULL) { toplevel()->throwArgumentError(kNullArgumentError, core->toErrorString("name")); } // Search for a dot from the end. int dot = name->lastIndexOf(core->cachedChars[(int)'.']); // If there is a '.', this is a fully-qualified // class name in a package. Must turn it into // a namespace-qualified multiname. Namespace* ns; Stringp className; if (dot >= 0) { Stringp uri = core->internString(name->substring(0, dot)); ns = core->internNamespace(core->newNamespace(uri)); className = core->internString(name->substring(dot+1, name->length())); } else { ns = core->publicNamespace; className = core->internString(name); } Multiname multiname(ns, className); // OOO: In the distribution, we search core->codeContext()->domainEnv rather than // our own domainEnv, which is surely a bug? ScriptObject *container = finddef(multiname, domainEnv); if (!container) { toplevel()->throwTypeError(kClassNotFoundError, core->toErrorString(&multiname)); } Atom atom = toplevel()->getproperty(container->atom(), &multiname, container->vtable); if (!AvmCore::istype(atom, core->traits.class_itraits)) { toplevel()->throwTypeError(kClassNotFoundError, core->toErrorString(&multiname)); } return (ClassClosure*)AvmCore::atomToScriptObject(atom); }
// E4X 13.3.2, page 67 Atom QNameClass::construct(int argc, Atom* argv) { AvmCore* core = this->core(); if (argc == 0) return (new (core->GetGC(), ivtable()->getExtraSize()) QNameObject(this, undefinedAtom))->atom(); if (argc == 1) { if (core->isObject(argv[1]) && AvmCore::istype(argv[1], core->traits.qName_itraits)) return argv[1]; return (new (core->GetGC(), ivtable()->getExtraSize()) QNameObject(this, argv[1]))->atom(); } else { Atom a = argv[1]; if (a == undefinedAtom) { // ns undefined same as unspecified return (new (core->GetGC(), ivtable()->getExtraSize()) QNameObject(this, argv[2]))->atom(); } else { Namespace* ns; if (AvmCore::isNull(a)) ns = NULL; // It's important to preserve the incoming namespace because it's type // may not be public. I.E... // namespace ns; // q = new QName(ns, "name"); // ns is a NS_PackageInternal ns // If we ever use this QName as a multiname, we need to preserve the exact ns else if (core->isNamespace(a)) ns = core->atomToNamespace(a); else ns = core->newNamespace (a); return (new (core->GetGC(), ivtable()->getExtraSize()) QNameObject(this, ns, argv[2]))->atom(); } } }