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();
59 ctor->defineReadonlyProperty(
engine->id_prototype(), (
o =
this));
60 ctor->defineDefaultProperty(
QStringLiteral(
"isArray"), method_isArray, 1);
62 ctor->defineDefaultProperty(
QStringLiteral(
"from"), method_from, 1);
63 ctor->addSymbolSpecies();
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) {
204 if (
done->toBoolean()) {
206 ao->setArrayLengthUnchecked(k);
211 return a.asReturnedValue();
216 mapArguments[0] = *nextValue;
218 mappedValue = mapfn->call(thisArg, mapArguments, 2);
222 mappedValue = *nextValue;
226 a->arraySet(k, mappedValue);
253 kValue = arrayLike->get(k);
258 mapArguments[0] = kValue;
260 mappedValue = mapfn->call(thisArg, mapArguments, 2);
263 mappedValue = kValue;
269 a->arraySet(k, mappedValue);
276 ao->setArrayLengthUnchecked(k);
281 return a.asReturnedValue();
288 Scope scope(builtin);
298 a->arraySet(k, argv[k]);
310 return a.asReturnedValue();
315 Scope scope(builtin);
345 for (
uint k = 0; k <
len; ++k) {
349 v = instance->
get(k);
350 if (
v->isNullOrUndefined())
360 v = function->call(valueAsObject,
nullptr, 0);
385 for (
int i = -1;
i < argc; ++
i) {
390 uint n = elt->getLength();
392 result->setArrayLengthUnchecked(newLen);
393 }
else if (eltAsObj && eltAsObj->isConcatSpreadable()) {
395 const uint len = eltAsObj->getLength();
400 bool hasProperty =
false;
401 entry = eltAsObj->get(
i, &hasProperty);
407 }
else if (eltAsObj && eltAsObj->isArrayLike()) {
409 for (
int i = 0,
len = eltAsObj->getLength();
i <
len; ++
i) {
419 return result.asReturnedValue();
434 if (argc > 2 && !argv[2].isUndefined()) {
438 double relativeTarget =
target;
439 double relativeStart =
start;
440 double relativeEnd =
end;
444 if (relativeTarget < 0) {
445 to = std::max(
len+relativeTarget, 0.0);
447 to = std::min(relativeTarget,
len);
449 if (relativeStart < 0) {
450 from = std::max(
len+relativeStart, 0.0);
452 from = std::min(relativeStart,
len);
456 if (relativeEnd < 0) {
457 fin = std::max(
len+relativeEnd, 0.0);
459 fin = std::min(relativeEnd,
len);
461 double count = std::min(fin-from,
len-to);
463 if (from < to && to < from+
count) {
465 from = from +
count - 1;
470 bool fromPresent =
false;
501 return ao->asReturnedValue();
513 if (!argc || !argv[0].isFunctionObject())
522 for (
uint k = 0; k <
len; ++k) {
547 if (!argc || !argv[0].isFunctionObject())
556 for (
uint k = 0; k <
len; ++k) {
573 const Value *thisObject,
const Value *argv,
int argc)
575 Scope scope(functionObject);
589 const quint32 genericLength = scopedLength->isUndefined() ? 0 : scopedLength->toUInt32();
603 entry = arrayObject->get(
i);
605 if (!
entry->isNullOrUndefined())
613 if (!
value->isNullOrUndefined())
623 if (!
value->isNullOrUndefined())
658 return result->asReturnedValue();
677 for (
int i = 0, ei = argc;
i < ei; ++
i) {
679 if (!instance->
put(
s, argv[
i]))
682 double newLen = l + argc;
696 instance->
arrayData()->vtable()->putArray(instance,
len, argv, argc);
699 for (
int i = 0, ei = argc;
i < ei; ++
i) {
700 if (!instance->
put(
len +
i, argv[
i]))
727 int lo = 0, hi =
length - 1;
731 for (; lo < hi; ++lo, --hi) {
732 bool loExists, hiExists;
733 lval = instance->
get(lo, &loExists);
734 hval = instance->
get(hi, &hiExists);
738 ok = instance->
put(lo, hval);
743 ok = instance->
put(hi, lval);
780 for (
uint k = 1; k <
len; ++k) {
782 v = instance->
get(k, &exists);
786 ok = instance->
put(k - 1,
v);
805 return result->asReturnedValue();
826 if (argc > 1 && !argv[1].isUndefined()) {
840 v =
o->get(
i, &exists);
846 return result->asReturnedValue();
883 }
else if (argc > 1){
884 itemCount = argc - 2;
889 if (
len + itemCount - deleteCount > UINT_MAX - 1)
891 if (deleteCount > UINT_MAX - 1)
895 newArray->arrayReserve(deleteCount);
897 for (
uint i = 0;
i < deleteCount; ++
i) {
902 newArray->arrayPut(
i,
v);
904 newArray->setArrayLengthUnchecked(deleteCount);
907 if (itemCount < deleteCount) {
910 v = instance->
get(k + deleteCount, &exists);
914 ok = instance->
put(k + itemCount,
v);
920 for (
uint k =
len; k >
len - deleteCount + itemCount; --k) {
924 }
else if (itemCount > deleteCount) {
928 v = instance->
get(k + deleteCount - 1, &exists);
932 ok = instance->
put(k + itemCount - 1,
v);
941 for (
uint i = 0;
i < itemCount; ++
i)
947 return newArray->asReturnedValue();
963 instance->
arrayData()->type != Heap::ArrayData::Custom) {
964 instance->
arrayData()->vtable()->push_front(instance, argv, argc);
967 for (
uint k =
len; k > 0; --k) {
969 v = instance->
get(k - 1, &exists);
972 ok = instance->
put(k + argc - 1,
v);
978 for (
int i = 0, ei = argc;
i < ei; ++
i) {
979 bool ok = instance->
put(
i, argv[
i]);
1009 if (argc > 1 && !argv[1].isUndefined()) {
1025 val = instance->
get(k);
1026 if (val->sameValueZero(argv[0])) {
1056 fromIndex = (
uint)
f;
1061 for (
uint k = fromIndex; k <
len; ++k) {
1063 v = instance->
get(k, &exists);
1087 if (
len > sa->values.size)
1088 len = sa->values.size;
1089 uint idx = fromIndex;
1091 value = sa->data(idx);
1110 return ao->asReturnedValue();
1128 searchValue = argv[0];
1142 fromIndex = (
uint)
f + 1;
1146 for (
uint k = fromIndex; k > 0;) {
1149 v = instance->
get(k, &exists);
1185 ok =
r->toBoolean();
1202 if (argc > 2 && !argv[2].isUndefined())
1208 if (relativeStart < 0) {
1209 if (relativeStart > -
len)
1212 k = std::min(relativeStart,
len);
1216 if (relativeEnd < 0) {
1217 if (relativeEnd > -
len)
1220 fin = std::min(relativeEnd,
len);
1227 for (; k < fin; ++k)
1250 for (
uint k = 0; k <
len; ++k) {
1282 for (
uint k = 0; k <
len; ++k) {
1308 if (
len > UINT_MAX - 1)
1312 a->arrayReserve(
len);
1313 a->setArrayLengthUnchecked(
len);
1320 for (
uint k = 0; k <
len; ++k) {
1330 a->arraySet(k, mapped);
1332 return a.asReturnedValue();
1349 a->arrayReserve(
len);
1356 for (
uint k = 0; k <
len; ++k) {
1371 return a.asReturnedValue();
1394 bool kPresent =
false;
1395 while (k <
len && !kPresent) {
1396 v = instance->
get(k, &kPresent);
1409 v = instance->
get(k, &kPresent);
1420 return acc->asReturnedValue();
1448 bool kPresent =
false;
1449 while (k > 0 && !kPresent) {
1450 v = instance->
get(k - 1, &kPresent);
1463 v = instance->
get(k - 1, &kPresent);
1474 return acc->asReturnedValue();
1486 return ao->asReturnedValue();
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
Scoped< FunctionObject > ScopedFunctionObject
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
Scoped< String > ScopedString
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
ReturnedValue throwRangeError(const Value &value)
String * id_length() const
String * id_toLocaleString() const
Heap::String * newString(char16_t c)
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 Value *thisObject, const Value *argv, int argc) const
void init(QV4::ExecutionEngine *engine)
ReturnedValue asReturnedValue() const
bool isStringObject() const
bool isArrayObject() const
ExecutionEngine * engine() const
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
bool setArrayLength(uint newLen)
bool deleteProperty(PropertyKey id)
Heap::ArrayData * arrayData() const
bool setIndexed(uint idx, const Value &v, ThrowOnFailure shouldThrow)
ArrayData::Type arrayType() const
bool put(StringOrSymbol *name, const Value &v, Value *receiver=nullptr)
void setArrayLengthUnchecked(uint l)
ReturnedValue get(StringOrSymbol *name, bool *hasProperty=nullptr, const Value *receiver=nullptr) const
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 &)
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
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