Atom VectorBaseObject::filter(ScriptObject *callback, Atom thisObject) { AvmCore* core = this->core(); VectorBaseObject *r = newVector(); if (!callback) return r->atom(); ScriptObject *d = this; uint32 len = m_length; // If thisObject is null, the call function will substitute the global object Atom args[4] = { thisObject, nullObjectAtom, nullObjectAtom, this->atom() }; for (uint32 i = 0, k = 0; i < len; i++) { args[1] = d->getUintProperty (i); // element args[2] = core->uintToAtom (i); // index Atom result = callback->call(3, args); if (result == trueAtom) { r->setUintProperty (k++, args[1]); } } return r->atom(); }
Atom VectorBaseObject::filter(ScriptObject *callback, Atom thisObject) { AvmCore* core = this->core(); VectorBaseObject *r = newVector(); if (!callback) return r->atom(); ScriptObject *d = this; uint32 len = m_length; for (uint32 i = 0, k = 0; i < len; i++) { // If thisObject is null, the call function will substitute the global object // args are modified in place by callee Atom element = d->getUintProperty(i); Atom args[4] = { thisObject, element, core->uintToAtom(i), // index this->atom() }; Atom result = callback->call(3, args); if (result == trueAtom) r->setUintProperty(k++, element); } return r->atom(); }
void ScriptObject::setLengthProperty(uint32_t newLen) { Toplevel* toplevel = this->toplevel(); AvmCore* core = toplevel->core(); Multiname mname(core->getAnyPublicNamespace(), core->klength); Atom lenAtm = core->uintToAtom(newLen); toplevel->setproperty(this->atom(), &mname, lenAtm, this->vtable); }
Atom ScriptObject::getUintProperty(uint32_t i) const { // N.B.: a key present in ScriptObject must be interned string; // thus uninterned implies absent (cf. bugzilla 556023). AvmCore* core = this->core(); if (!(i&MAX_INTEGER_MASK)) { if (!traits()->needsHashtable()) { Stringp interned; bool present = core->isInternedUint(i, &interned); if (present) { Atom name = interned->atom(); return getAtomPropertyFromProtoChain(name, delegate, traits()); } else { return undefinedAtom; } } else { // dynamic lookup on this object Atom name = core->uintToAtom (i); const ScriptObject *o = this; do { // ensure prototype is dynamic if (!o->vtable->traits->getHashtableOffset()) continue; Atom const value = o->getTable()->getNonEmpty(name); if (!InlineHashtable::isEmpty(value)) return value; } while ((o = o->delegate) != NULL); return undefinedAtom; } } else { Stringp interned; bool present; present = core->isInternedUint(i, &interned); if (present) { return getAtomProperty(interned->atom()); } else { return undefinedAtom; } } }
Stringp StringClass::_replace(Stringp subject, Atom pattern, Atom replacementAtom) { AvmCore* core = this->core(); ScriptObject *replaceFunction = NULL; Stringp replacement = NULL; if (AvmCore::istype(replacementAtom, core->traits.function_itraits)) { replaceFunction = AvmCore::atomToScriptObject(replacementAtom); } else { replacement = core->string(replacementAtom); } if (AvmCore::istype(pattern, core->traits.regexp_itraits)) { // RegExp mode RegExpObject *reObj = (RegExpObject*) core->atomToScriptObject(pattern); if (replaceFunction) { return core->string(reObj->replace(subject, replaceFunction)); } else { return core->string(reObj->replace(subject, replacement)); } } else { // String replace mode Stringp searchString = core->string(pattern); int index = subject->indexOf(searchString); if (index == -1) { // Search string not found; return input unchanged. return subject; } if (replaceFunction) { // Invoke the replacement function to figure out the // replacement string Atom argv[4] = { undefinedAtom, searchString->atom(), core->uintToAtom(index), subject->atom() }; replacement = core->string(toplevel()->op_call(replaceFunction->atom(), 3, argv)); } Stringp out = subject->substring(0, index); out = String::concatStrings(out, replacement); out = String::concatStrings(out, subject->substring(index + searchString->length(), subject->length())); return out; } }
bool ScriptObject::hasUintProperty(uint32_t i) const { AvmCore* core = this->core(); if (!(i&MAX_INTEGER_MASK)) { Atom name = core->uintToAtom (i); if (traits()->needsHashtable()) { return getTable()->contains(name); } else { // ISSUE should this walk the proto chain? return false; } } else { return hasAtomProperty(core->internUint32(i)->atom()); } }
bool ScriptObject::delUintProperty(uint32_t i) { AvmCore* core = this->core(); if (!(i&MAX_INTEGER_MASK)) { Atom name = core->uintToAtom (i); if (traits()->needsHashtable()) { getTable()->remove(name); return true; } else { return false; } } else { return deleteAtomProperty(core->internUint32(i)->atom()); } }
void ScriptObject::setUintProperty(uint32_t i, Atom value) { AvmCore* core = this->core(); if (!(i&MAX_INTEGER_MASK)) { Atom name = core->uintToAtom (i); if (traits()->needsHashtable()) { MMGC_MEM_TYPE(this); getTable()->add(name, value); MMGC_MEM_TYPE(NULL); } else { throwWriteSealedError(core->internUint32(i)->atom()); } } else { setAtomProperty(core->internUint32(i)->atom(), value); } }