11#include <QtCore/qscopedvaluerollback.h>
28 a->setProtoFromNewTarget(newTarget);
30 if (argc == 1 && argv[0].
isNumber()) {
42 a->arrayPut(0, argv,
len);
44 a->setArrayLengthUnchecked(
len);
46 return a.asReturnedValue();
66 ->changeVTable(QV4::Object::staticVTable()));
70 defineDefaultProperty(
engine->id_toString(), method_toString, 0);
71 defineDefaultProperty(
engine->id_toLocaleString(), method_toLocaleString, 0);
75 defineDefaultProperty(
name, method_copyWithin, 2);
78 defineDefaultProperty(
name, method_entries, 0);
81 defineDefaultProperty(
name, method_fill, 1);
84 defineDefaultProperty(
name, method_find, 1);
87 defineDefaultProperty(
name, method_findIndex, 1);
90 defineDefaultProperty(
name, method_includes, 1);
94 defineDefaultProperty(
name, method_keys, 0);
97 defineDefaultProperty(
QStringLiteral(
"reverse"), method_reverse, 0);
101 defineDefaultProperty(
QStringLiteral(
"splice"), method_splice, 2);
102 defineDefaultProperty(
QStringLiteral(
"unshift"), method_unshift, 1);
103 defineDefaultProperty(
QStringLiteral(
"indexOf"), method_indexOf, 1);
104 defineDefaultProperty(
QStringLiteral(
"lastIndexOf"), method_lastIndexOf, 1);
107 defineDefaultProperty(
QStringLiteral(
"forEach"), method_forEach, 1);
109 defineDefaultProperty(
QStringLiteral(
"filter"), method_filter, 1);
110 defineDefaultProperty(
QStringLiteral(
"reduce"), method_reduce, 1);
111 defineDefaultProperty(
QStringLiteral(
"reduceRight"), method_reduceRight, 1);
116 defineDefaultProperty(valuesString,
values);
117 defineDefaultProperty(
engine->symbol_iterator(),
values);
119 defineReadonlyConfigurableProperty(
engine->symbol_unscopables(), unscopables);
133 if (ctor && ctor->isConstructor()) {
139 a = ctor->callAsConstructor(
argument, useLen ? 1 : 0);
149 Scope scope(builtin);
152 bool usingIterator =
false;
157 if (!
it->isNullOrUndefined()) {
161 usingIterator =
true;
166 Value *mapArguments =
nullptr;
171 mapArguments = scope.
alloc(2);
196 if (k > (
static_cast<qint64>(1) << 53) - 1) {
205 if (
done->toBoolean()) {
207 ao->setArrayLengthUnchecked(k);
212 return a.asReturnedValue();
217 mapArguments[0] = *nextValue;
219 mappedValue = mapfn->call(thisArg, mapArguments, 2);
223 mappedValue = *nextValue;
227 a->arraySet(k, mappedValue);
256 kValue = arrayLike->get(k);
261 mapArguments[0] = kValue;
263 mappedValue = mapfn->call(thisArg, mapArguments, 2);
266 mappedValue = kValue;
272 a->arraySet(k, mappedValue);
279 ao->setArrayLengthUnchecked(k);
284 return a.asReturnedValue();
291 Scope scope(builtin);
301 a->arraySet(k, argv[k]);
313 return a.asReturnedValue();
318 Scope scope(builtin);
337 uint len = instance->getLength();
348 for (
uint k = 0; k <
len; ++k) {
352 v = instance->get(k);
353 if (
v->isNullOrUndefined())
363 v =
function->call(valueAsObject,
nullptr, 0);
388 for (
int i = -1;
i < argc; ++
i) {
393 uint n = elt->getLength();
395 result->setArrayLengthUnchecked(newLen);
396 }
else if (eltAsObj && eltAsObj->isConcatSpreadable()) {
398 const uint len = eltAsObj->getLength();
403 bool hasProperty =
false;
404 entry = eltAsObj->get(
i, &hasProperty);
410 }
else if (eltAsObj && eltAsObj->isArrayLike()) {
412 for (
int i = 0,
len = eltAsObj->getLength();
i <
len; ++
i) {
432 double len = instance->getLength();
437 if (argc > 2 && !argv[2].isUndefined()) {
441 double relativeTarget =
target;
442 double relativeStart =
start;
443 double relativeEnd =
end;
447 if (relativeTarget < 0) {
448 to = std::max(
len+relativeTarget, 0.0);
450 to = std::min(relativeTarget,
len);
452 if (relativeStart < 0) {
453 from = std::max(
len+relativeStart, 0.0);
455 from = std::min(relativeStart,
len);
459 if (relativeEnd < 0) {
460 fin = std::max(
len+relativeEnd, 0.0);
462 fin = std::min(relativeEnd,
len);
464 double count = std::min(fin-from,
len-to);
466 if (from < to && to < from+
count) {
468 from = from +
count - 1;
473 bool fromPresent =
false;
474 ScopedValue fromVal(scope, instance->get(from, &fromPresent));
514 uint len = instance->getLength();
516 if (!argc || !argv[0].isFunctionObject())
525 for (
uint k = 0; k <
len; ++k) {
548 uint len = instance->getLength();
550 if (!argc || !argv[0].isFunctionObject())
559 for (
uint k = 0; k <
len; ++k) {
576 const Value *thisObject,
const Value *argv,
int argc)
578 Scope scope(functionObject);
597 if (
auto *arrayObject = instance->as<
ArrayObject>()) {
606 entry = arrayObject->get(
i);
608 if (!
entry->isNullOrUndefined())
616 if (!
value->isNullOrUndefined())
626 if (!
value->isNullOrUndefined())
641 uint len = instance->getLength();
644 if (!instance->isArrayObject())
655 if (instance->isArrayObject())
656 instance->setArrayLength(
len - 1);
661 return result->asReturnedValue();
671 instance->arrayCreate();
680 for (
int i = 0, ei = argc;
i < ei; ++
i) {
682 if (!instance->put(
s, argv[
i]))
685 double newLen = l + argc;
686 if (!instance->isArrayObject()) {
698 else if (!instance->protoHasArray() && instance->arrayData()->length() <=
len && instance->arrayData()->type == Heap::ArrayData::Simple) {
699 instance->arrayData()->vtable()->putArray(instance,
len, argv, argc);
700 len = instance->arrayData()->length();
702 for (
int i = 0, ei = argc;
i < ei; ++
i) {
703 if (!instance->put(
len +
i, argv[
i]))
708 if (instance->isArrayObject())
709 instance->setArrayLengthUnchecked(
len);
730 int lo = 0, hi =
length - 1;
734 for (; lo < hi; ++lo, --hi) {
735 bool loExists, hiExists;
736 lval = instance->get(lo, &loExists);
737 hval = instance->get(hi, &hiExists);
741 ok = instance->put(lo, hval);
746 ok = instance->put(hi, lval);
763 instance->arrayCreate();
766 uint len = instance->getLength();
769 if (!instance->isArrayObject())
776 if (!instance->protoHasArray() && !instance->arrayData()->attrs && instance->arrayData()->length() <=
len && instance->arrayData()->type != Heap::ArrayData::Custom) {
777 result = instance->arrayData()->vtable()->pop_front(instance);
783 for (
uint k = 1; k <
len; ++k) {
785 v = instance->get(k, &exists);
789 ok = instance->put(k - 1,
v);
800 if (instance->isArrayObject())
801 instance->setArrayLengthUnchecked(
len - 1);
808 return result->asReturnedValue();
829 if (argc > 1 && !argv[1].isUndefined()) {
843 v =
o->get(
i, &exists);
849 return result->asReturnedValue();
859 uint len = instance->getLength();
886 }
else if (argc > 1){
887 itemCount = argc - 2;
892 if (
len + itemCount - deleteCount > UINT_MAX - 1)
894 if (deleteCount > UINT_MAX - 1)
898 newArray->arrayReserve(deleteCount);
900 for (
uint i = 0;
i < deleteCount; ++
i) {
902 v = instance->get(
start +
i, &exists);
905 newArray->arrayPut(
i,
v);
907 newArray->setArrayLengthUnchecked(deleteCount);
910 if (itemCount < deleteCount) {
913 v = instance->get(k + deleteCount, &exists);
917 ok = instance->put(k + itemCount,
v);
923 for (
uint k =
len; k >
len - deleteCount + itemCount; --k) {
927 }
else if (itemCount > deleteCount) {
931 v = instance->get(k + deleteCount - 1, &exists);
935 ok = instance->put(k + itemCount - 1,
v);
944 for (
uint i = 0;
i < itemCount; ++
i)
945 instance->put(
start +
i, argv[
i + 2]);
960 instance->arrayCreate();
963 uint len = instance->getLength();
965 if (!instance->protoHasArray() && !instance->arrayData()->attrs && instance->arrayData()->length() <=
len &&
966 instance->arrayData()->type != Heap::ArrayData::Custom) {
967 instance->arrayData()->vtable()->push_front(instance, argv, argc);
970 for (
uint k =
len; k > 0; --k) {
972 v = instance->get(k - 1, &exists);
975 ok = instance->put(k + argc - 1,
v);
981 for (
int i = 0, ei = argc;
i < ei; ++
i) {
982 bool ok = instance->put(
i, argv[
i]);
989 if (instance->isArrayObject())
990 instance->setArrayLengthUnchecked(newLen);
1012 if (argc > 1 && !argv[1].isUndefined()) {
1028 val = instance->get(k);
1029 if (
val->sameValueZero(argv[0])) {
1045 uint len = instance->getLength();
1059 fromIndex = (
uint)
f;
1062 if (instance->isStringObject()) {
1064 for (
uint k = fromIndex; k <
len; ++k) {
1066 v = instance->get(k, &exists);
1076 (instance->arrayType() >= Heap::ArrayData::Sparse) || instance->protoHasArray()) {
1080 value = instance->get(
i, &exists);
1085 }
else if (!instance->arrayData()) {
1088 Q_ASSERT(instance->arrayType() == Heap::ArrayData::Simple);
1090 if (
len > sa->values.size)
1091 len = sa->values.size;
1092 uint idx = fromIndex;
1123 uint len = instance->getLength();
1131 searchValue = argv[0];
1145 fromIndex = (
uint)
f + 1;
1149 for (
uint k = fromIndex; k > 0;) {
1152 v = instance->get(k, &exists);
1167 uint len = instance->getLength();
1180 arguments[0] = instance->get(k, &exists);
1188 ok =
r->toBoolean();
1205 if (argc > 2 && !argv[2].isUndefined())
1211 if (relativeStart < 0) {
1212 if (relativeStart > -
len)
1215 k = std::min(relativeStart,
len);
1219 if (relativeEnd < 0) {
1220 if (relativeEnd > -
len)
1223 fin = std::min(relativeEnd,
len);
1230 for (; k < fin; ++k)
1243 uint len = instance->getLength();
1253 for (
uint k = 0; k <
len; ++k) {
1255 arguments[0] = instance->get(k, &exists);
1276 uint len = instance->getLength();
1285 for (
uint k = 0; k <
len; ++k) {
1287 arguments[0] = instance->get(k, &exists);
1311 if (
len > UINT_MAX - 1)
1315 a->arrayReserve(
len);
1316 a->setArrayLengthUnchecked(
len);
1323 for (
uint k = 0; k <
len; ++k) {
1325 arguments[0] = instance->get(k, &exists);
1333 a->arraySet(k, mapped);
1335 return a.asReturnedValue();
1345 uint len = instance->getLength();
1352 a->arrayReserve(
len);
1359 for (
uint k = 0; k <
len; ++k) {
1361 arguments[0] = instance->get(k, &exists);
1374 return a.asReturnedValue();
1384 uint len = instance->getLength();
1397 bool kPresent =
false;
1398 while (k <
len && !kPresent) {
1399 v = instance->get(k, &kPresent);
1412 v = instance->get(k, &kPresent);
1433 uint len = instance->getLength();
1451 bool kPresent =
false;
1452 while (k > 0 && !kPresent) {
1453 v = instance->get(k - 1, &kPresent);
1466 v = instance->get(k - 1, &kPresent);
QJSValue newObject()
Creates a JavaScript object of class Object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QSet< QString >::iterator it
QList< QVariant > arguments
\qmltype Particle \inqmlmodule QtQuick.Particles
Scoped< FunctionObject > ScopedFunctionObject
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
static int arrayLength(const QString &rawType)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLenum GLsizei GLsizei GLint * values
[15]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLsizei const GLchar *const * string
[0]
QLatin1StringView QLatin1String
#define QStringLiteral(str)
unsigned long long quint64
static ScopedObject createObjectFromCtorOrArray(Scope &scope, ScopedFunctionObject ctor, bool useLen, int len)
#define THROW_TYPE_ERROR()
#define CHECK_EXCEPTION()
#define RETURN_UNDEFINED()
#define DEFINE_OBJECT_VTABLE(classname)
static bool isNonStrictArgumentsObject(Managed *m)
static void sort(ExecutionEngine *engine, Object *thisObject, const Value &comparefn, uint dataLen)
static uint append(Object *obj, ArrayObject *otherObj, uint n)
static ReturnedValue method_lastIndexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_forEach(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_from(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_isArray(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_includes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_reduceRight(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_shift(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_indexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_find(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_of(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_reduce(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_reverse(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toLocaleString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_species(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_findIndex(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_every(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_concat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_values(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_entries(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_copyWithin(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_filter(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_unshift(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_some(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_push(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_join(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_pop(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_sort(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_fill(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_map(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_keys(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_splice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static constexpr ReturnedValue undefined()
Symbol * symbol_iterator() const
Heap::String * newString(const QString &s=QString())
ReturnedValue throwRangeError(const Value &value)
String * id_length() const
String * id_toLocaleString() const
Heap::ArrayObject * newArrayObject(int count=0)
Heap::Object * newArrayIteratorObject(Object *o)
ReturnedValue throwTypeError()
static Heap::FunctionObject * createBuiltinFunction(ExecutionEngine *engine, StringOrSymbol *nameOrSymbol, VTable::Call code, int argumentCount)
ReturnedValue call(const JSCallData &data) const
Heap::ExecutionContext * scope() const
void init(QV4::ExecutionContext *scope)
ReturnedValue asReturnedValue() const
const Value & data(uint index) const
ExecutionEngine * engine() const
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void defineDefaultProperty(StringOrSymbol *name, const Value &value, PropertyAttributes attributes=Attr_Data|Attr_NotEnumerable)
void defineReadonlyConfigurableProperty(const QString &name, const Value &value)
void defineReadonlyProperty(const QString &name, const Value &value)
static PropertyKey fromArrayIndex(uint idx)
static Bool strictEqual(const Value &x, const Value &y)
static ReturnedValue call(ExecutionEngine *, const Value &, int)
static ReturnedValue call(ExecutionEngine *, const Value &, const Value &)
static ReturnedValue call(ExecutionEngine *, const Value &, Value *)
Value * alloc(qint64 nValues) const =delete
bool hasException() const
QML_NEARLY_ALWAYS_INLINE ReturnedValue asReturnedValue() const
constexpr ReturnedValue asReturnedValue() const
static constexpr VTable::CallAsConstructor virtualCallAsConstructor
static constexpr VTable::Call virtualCall
static constexpr Value fromInt32(int i)
bool isFunctionObject() const
Heap::String * toString(ExecutionEngine *e) const
unsigned int toUInt32() const
static constexpr Value fromBoolean(bool b)
static constexpr Value undefinedValue()
static Value fromDouble(double d)
uint asArrayLength(bool *ok) const
QML_NEARLY_ALWAYS_INLINE Object * objectValue() const
static constexpr Value fromReturnedValue(ReturnedValue val)
Heap::Object * toObject(ExecutionEngine *e) const