コード例 #1
0
    /**
     * Array.prototype.reverse()
	 * TRANSFERABLE: Needs to support generic objects as well as Array objects
     */
	/*static*/ Atom ArrayClass::generic_reverse(Toplevel* toplevel, Atom thisAtom)
    {
        ArrayObject *a = isArray(toplevel, thisAtom);
	
		if (a && (a->isSimpleDense()))
		{
			a->m_denseArr.reverse();
			return thisAtom;
		}

		// generic object version
		if (!AvmCore::isObject(thisAtom))
			return thisAtom;

		ScriptObject *d = AvmCore::atomToScriptObject(thisAtom);
		uint32 j = getLengthHelper(toplevel, d);

		uint32 i = 0;
		if (j)
			j--;

		while (i < j) {
			Atom frontAtom = d->getUintProperty(i);
			Atom backAtom  = d->getUintProperty(j);

			d->setUintProperty(i++, backAtom);
			d->setUintProperty(j--, frontAtom);
		}

		return thisAtom;
	}
コード例 #2
0
	/**
     * Array.prototype.shift()
	 * TRANSFERABLE: Needs to support generic objects as well as Array objects
     */
	/*static*/ Atom ArrayClass::generic_shift(Toplevel* toplevel, Atom thisAtom)
	{
		ArrayObject *a = isArray(toplevel, thisAtom);

		if (a && a->isSimpleDense())
		{
			if (!a->m_length)
				return undefinedAtom;

			a->m_length--;
			return (a->m_denseArr.shift());
		}

		if (!AvmCore::isObject(thisAtom))
			return undefinedAtom;

		Atom outAtom;
		ScriptObject *d = AvmCore::atomToScriptObject(thisAtom);
		uint32 len = getLengthHelper(toplevel, d);

		if (len == 0)
		{
			// set len to 0 (ecmascript spec)
			setLengthHelper(toplevel, d, 0);
			outAtom = undefinedAtom;
		}
		else
		{
			// Get the 0th element to return
			outAtom = d->getUintProperty(0);

			// Move all of the elements down
			for (uint32 i=0; i<len-1; i++) {
				d->setUintProperty(i, d->getUintProperty(i+1));
			}
			
			d->delUintProperty (len - 1);
			setLengthHelper(toplevel, d, len - 1);
		}

		return outAtom;
	}